Re: Clean up some signal usage mainly related to Windows

From: "Tristan Partin" <tristan(at)neon(dot)tech>
To: "Nathan Bossart" <nathandbossart(at)gmail(dot)com>, "Peter Eisentraut" <peter(at)eisentraut(dot)org>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Clean up some signal usage mainly related to Windows
Date: 2023-12-06 16:28:49
Message-ID: CXHE5M1YJ97P.3N4VA08G6LH6R@neon.tech
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed Dec 6, 2023 at 10:18 AM CST, Nathan Bossart wrote:
> On Wed, Dec 06, 2023 at 10:23:52AM +0100, Peter Eisentraut wrote:
> > Ok, I have committed your 0001 patch.
>
> My compiler is unhappy about this one:
>
> ../postgresql/src/bin/pg_test_fsync/pg_test_fsync.c:605:2: error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]
> 605 | write(STDOUT_FILENO, "\n", 1);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Some glibc source:

> /* If fortification mode, we warn about unused results of certain
> function calls which can lead to problems. */
> #if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__)
> # define __attribute_warn_unused_result__ \
> __attribute__ ((__warn_unused_result__))
> # if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
> # define __wur __attribute_warn_unused_result__
> # endif
> #else
> # define __attribute_warn_unused_result__ /* empty */
> #endif
> #ifndef __wur
> # define __wur /* Ignore */
> #endif

> extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur
> __attr_access ((__read_only__, 2, 3));

According to my setup, I am hitting the /* Ignore */ variant of __wur.
I am guessing that Fedora doesn't add fortification to the default
CFLAGS. What distro are you using? But yes, something like what you
proposed sounds good to me. Sorry for leaving this out!

Makes me wonder if setting -D_FORTIFY_SOURCE=2 in debug builds at least
would make sense, if not all builds. According to the OpenSSF[0], level
2 is only supposed to impact runtime performance by 0.1%.

[0]: https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html#performance-implications

--
Tristan Partin
Neon (https://neon.tech)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2023-12-06 16:28:59 Re: Emitting JSON to file using COPY TO
Previous Message Sehrope Sarkuni 2023-12-06 16:28:33 Re: Emitting JSON to file using COPY TO