* [Xenomai] [Xenomai-forge] [PATCH] Silence unused_result warning from write()
@ 2013-11-07 9:22 Gernot Hillier
2013-11-07 18:01 ` Gilles Chanteperdrix
0 siblings, 1 reply; 8+ messages in thread
From: Gernot Hillier @ 2013-11-07 9:22 UTC (permalink / raw)
To: xenomai
Some glibc versions mark write() with attribute warn_unused_result (found in
Ubuntu 12.04 / eglibc 2.15 / gcc 4.6.3), so we need to silence this warning,
especially when building with -Werror.
Signed-off-by: Gernot Hillier <gernot.hillier@siemens.com>
---
lib/cobalt/init.c | 4 +++-
testsuite/latency/latency.c | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/cobalt/init.c b/lib/cobalt/init.c
index 101a2bd..568f9d0 100644
--- a/lib/cobalt/init.c
+++ b/lib/cobalt/init.c
@@ -53,7 +53,9 @@ int __rtdm_fd_start = INT_MAX;
static void sigill_handler(int sig)
{
const char m[] = "no Xenomai support in kernel?\n";
- write(2, m, sizeof(m) - 1);
+ if (write(2, m, sizeof(m) - 1) < 1) {
+ /* Silence unused_result warning. No handling in error case, though. */
+ }
exit(EXIT_FAILURE);
}
diff --git a/testsuite/latency/latency.c b/testsuite/latency/latency.c
index 7c5099b..b9e1f00 100644
--- a/testsuite/latency/latency.c
+++ b/testsuite/latency/latency.c
@@ -507,7 +507,9 @@ static void sigdebug(int sig, siginfo_t *si, void *context)
case SIGDEBUG_WATCHDOG:
n = snprintf(buffer, sizeof(buffer), "%s\n",
reason_str[reason]);
- write(STDERR_FILENO, buffer, n);
+ if (write(STDERR_FILENO, buffer, n) < 1) {
+ /* Silence unused_result warning. No handling in error case, though. */
+ }
exit(EXIT_FAILURE);
}
--
1.8.1.2
--
Regards,
Gernot Hillier
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [Xenomai] [Xenomai-forge] [PATCH] Silence unused_result warning from write()
2013-11-07 9:22 [Xenomai] [Xenomai-forge] [PATCH] Silence unused_result warning from write() Gernot Hillier
@ 2013-11-07 18:01 ` Gilles Chanteperdrix
2013-11-08 5:55 ` Gernot Hillier
0 siblings, 1 reply; 8+ messages in thread
From: Gilles Chanteperdrix @ 2013-11-07 18:01 UTC (permalink / raw)
To: Gernot Hillier; +Cc: xenomai
On 11/07/2013 10:22 AM, Gernot Hillier wrote:
> Some glibc versions mark write() with attribute warn_unused_result (found in
> Ubuntu 12.04 / eglibc 2.15 / gcc 4.6.3), so we need to silence this warning,
> especially when building with -Werror.
Why not casting write result to void, it does not work?
--
Gilles.
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [Xenomai] [Xenomai-forge] [PATCH] Silence unused_result warning from write()
2013-11-07 18:01 ` Gilles Chanteperdrix
@ 2013-11-08 5:55 ` Gernot Hillier
2013-11-08 17:23 ` Gilles Chanteperdrix
0 siblings, 1 reply; 8+ messages in thread
From: Gernot Hillier @ 2013-11-08 5:55 UTC (permalink / raw)
To: Gilles Chanteperdrix; +Cc: xenomai
Am 07.11.2013 19:01, schrieb Gilles Chanteperdrix:
> On 11/07/2013 10:22 AM, Gernot Hillier wrote:
>> Some glibc versions mark write() with attribute warn_unused_result (found in
>> Ubuntu 12.04 / eglibc 2.15 / gcc 4.6.3), so we need to silence this warning,
>> especially when building with -Werror.
>
> Why not casting write result to void, it does not work?
>
No, it doesn't. For rationale, please see
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509.
--
Gernot
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Xenomai] [Xenomai-forge] [PATCH] Silence unused_result warning from write()
2013-11-08 5:55 ` Gernot Hillier
@ 2013-11-08 17:23 ` Gilles Chanteperdrix
2013-11-08 18:18 ` Jan Kiszka
2014-01-14 12:28 ` [Xenomai] [Xenomai-forge] [PATCH v2] " Gernot Hillier
0 siblings, 2 replies; 8+ messages in thread
From: Gilles Chanteperdrix @ 2013-11-08 17:23 UTC (permalink / raw)
To: Gernot Hillier; +Cc: xenomai
On 11/08/2013 06:55 AM, Gernot Hillier wrote:
> Am 07.11.2013 19:01, schrieb Gilles Chanteperdrix:
>> On 11/07/2013 10:22 AM, Gernot Hillier wrote:
>>> Some glibc versions mark write() with attribute warn_unused_result (found in
>>> Ubuntu 12.04 / eglibc 2.15 / gcc 4.6.3), so we need to silence this warning,
>>> especially when building with -Werror.
>>
>> Why not casting write result to void, it does not work?
>>
>
> No, it doesn't. For rationale, please see
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509.
>
Ok, but I do not like your patch anyway:
- it compares directly the function result, which no other code in
Xenomai sources does, we always store the result in a variable and test
the variable
- it opens and closes braces for no good reason.
I believe you still can do:
rc = write
(void)rc
The link you sent also indicates that the warning can be disabled with
-Wno-unused-result
Can you not compile with this option on distributions with this behaviour?
--
Gilles.
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [Xenomai] [Xenomai-forge] [PATCH] Silence unused_result warning from write()
2013-11-08 17:23 ` Gilles Chanteperdrix
@ 2013-11-08 18:18 ` Jan Kiszka
2013-11-11 8:36 ` dietmar.schindler
2014-01-14 12:28 ` [Xenomai] [Xenomai-forge] [PATCH v2] " Gernot Hillier
1 sibling, 1 reply; 8+ messages in thread
From: Jan Kiszka @ 2013-11-08 18:18 UTC (permalink / raw)
To: Gilles Chanteperdrix, Gernot Hillier; +Cc: xenomai
On 2013-11-08 18:23, Gilles Chanteperdrix wrote:
> On 11/08/2013 06:55 AM, Gernot Hillier wrote:
>> Am 07.11.2013 19:01, schrieb Gilles Chanteperdrix:
>>> On 11/07/2013 10:22 AM, Gernot Hillier wrote:
>>>> Some glibc versions mark write() with attribute warn_unused_result (found in
>>>> Ubuntu 12.04 / eglibc 2.15 / gcc 4.6.3), so we need to silence this warning,
>>>> especially when building with -Werror.
>>>
>>> Why not casting write result to void, it does not work?
>>>
>>
>> No, it doesn't. For rationale, please see
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509.
>>
> Ok, but I do not like your patch anyway:
> - it compares directly the function result, which no other code in
> Xenomai sources does, we always store the result in a variable and test
> the variable
> - it opens and closes braces for no good reason.
>
> I believe you still can do:
>
> rc = write
> (void)rc
Yep, that's what other projects do as well when there is really no use
for the return code.
>
> The link you sent also indicates that the warning can be disabled with
> -Wno-unused-result
>
> Can you not compile with this option on distributions with this behaviour?
Let's fix this in our source code, not in the ./configure command line.
I expect the warning to become more frequent with recent compilers
and/or distros.
Jan
--
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Xenomai] [Xenomai-forge] [PATCH] Silence unused_result warning from write()
2013-11-08 18:18 ` Jan Kiszka
@ 2013-11-11 8:36 ` dietmar.schindler
2013-11-11 10:00 ` Gernot Hillier
0 siblings, 1 reply; 8+ messages in thread
From: dietmar.schindler @ 2013-11-11 8:36 UTC (permalink / raw)
Cc: xenomai
> Von: Jan Kiszka
> Gesendet: Freitag, 8. November 2013 19:18
>
> On 2013-11-08 18:23, Gilles Chanteperdrix wrote:
> > On 11/08/2013 06:55 AM, Gernot Hillier wrote:
> >> Am 07.11.2013 19:01, schrieb Gilles Chanteperdrix:
> >>> On 11/07/2013 10:22 AM, Gernot Hillier wrote:
> >>>> Some glibc versions mark write() with attribute warn_unused_result (found in
> >>>> Ubuntu 12.04 / eglibc 2.15 / gcc 4.6.3), so we need to silence this warning,
> >>>> especially when building with -Werror.
> >>>
> >>> Why not casting write result to void, it does not work?
> >>>
> >>
> >> No, it doesn't. For rationale, please see
> >> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509.
> >>
> > ...
> >
> > I believe you still can do:
> >
> > rc = write
> > (void)rc
>
> Yep, that's what other projects do as well when there is really no use
> for the return code.
>
> >
> > The link you sent also indicates that the warning can be disabled with
> > -Wno-unused-result
> >
> > Can you not compile with this option on distributions with this behaviour?
>
> Let's fix this in our source code, not in the ./configure command line.
> I expect the warning to become more frequent with recent compilers
> and/or distros.
Since this has been recognized as a bug http://sourceware.org/bugzilla/show_bug.cgi?id=11959 in glibc and fixed, it should become less frequent with recent
distros. I think, source code shouldn't be cluttered with silly workarounds.
--
Best regards,
Dietmar Schindler
________________________________________
manroland web systems GmbH -- Managing Director: Eckhard Hoerner-Marass
Registered Office: Augsburg -- Trade Register: AG Augsburg -- HRB-No. 26816 -- VAT: DE281389840
Confidentiality note:
This eMail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient, you are hereby notified that any use or dissemination of this communication is strictly prohibited. If you have received this eMail in error, then please delete this eMail.
! Please consider your environmental responsibility before printing this eMail
________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Xenomai] [Xenomai-forge] [PATCH] Silence unused_result warning from write()
2013-11-11 8:36 ` dietmar.schindler
@ 2013-11-11 10:00 ` Gernot Hillier
0 siblings, 0 replies; 8+ messages in thread
From: Gernot Hillier @ 2013-11-11 10:00 UTC (permalink / raw)
To: xenomai
Hi!
Am 11.11.2013 09:36, schrieb dietmar.schindler@manroland-web.com:
>> Von: Jan Kiszka
>> Gesendet: Freitag, 8. November 2013 19:18
>>
>> On 2013-11-08 18:23, Gilles Chanteperdrix wrote:
>>> On 11/08/2013 06:55 AM, Gernot Hillier wrote:
>>>> Am 07.11.2013 19:01, schrieb Gilles Chanteperdrix:
>>>>> On 11/07/2013 10:22 AM, Gernot Hillier wrote:
>>>>>> Some glibc versions mark write() with attribute warn_unused_result (found in
>>>>>> Ubuntu 12.04 / eglibc 2.15 / gcc 4.6.3), so we need to silence this warning,
>>>>>> especially when building with -Werror.
>>>>>
>>>>> Why not casting write result to void, it does not work?
>>>>>
>>>>
>>>> No, it doesn't. For rationale, please see
>>>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509.
>>>>
>>> ...
>>>
>>> I believe you still can do:
>>>
>>> rc = write
>>> (void)rc
>>
>> Yep, that's what other projects do as well when there is really no use
>> for the return code.
>>
>>>
>>> The link you sent also indicates that the warning can be disabled with
>>> -Wno-unused-result
>>>
>>> Can you not compile with this option on distributions with this behaviour?
>>
>> Let's fix this in our source code, not in the ./configure command line.
>> I expect the warning to become more frequent with recent compilers
>> and/or distros.
>
> Since this has been recognized as a bug
> http://sourceware.org/bugzilla/show_bug.cgi?id=11959 in glibc and
> fixed, it should become less frequent with recent distros. I think,
> source code shouldn't be cluttered with silly workarounds.
The glibc bug is about fwrite(), not write(). And one argument for removing
__wur in fwrite() was that errors can be checked explicitely with ferror() -
which is not true for write(). _wur is still here:
https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/unistd.h;h=178223d7555702d133a51eaf8deaff7bfc5327aa;hb=HEAD
And even if we would file another bug for removing __wur from write(), I
seriously suspect that this will be accepted quickly and we'll see this
behaviour go away in recent distros anytime soon.
What do you think about this? Looks a bit more concise to me:
diff --git a/lib/cobalt/init.c b/lib/cobalt/init.c
index 101a2bd..11c2a3a 100644
--- a/lib/cobalt/init.c
+++ b/lib/cobalt/init.c
@@ -53,7 +53,8 @@ int __rtdm_fd_start = INT_MAX;
static void sigill_handler(int sig)
{
const char m[] = "no Xenomai support in kernel?\n";
- write(2, m, sizeof(m) - 1);
+ ssize_t rc __attribute__ ((unused));
+ rc = write(2, m, sizeof(m) - 1);
exit(EXIT_FAILURE);
}
diff --git a/testsuite/latency/latency.c b/testsuite/latency/latency.c
index 7c5099b..32e59b5 100644
--- a/testsuite/latency/latency.c
+++ b/testsuite/latency/latency.c
@@ -507,7 +507,7 @@ static void sigdebug(int sig, siginfo_t *si, void *context)
case SIGDEBUG_WATCHDOG:
n = snprintf(buffer, sizeof(buffer), "%s\n",
reason_str[reason]);
- write(STDERR_FILENO, buffer, n);
+ n = write(STDERR_FILENO, buffer, n);
exit(EXIT_FAILURE);
}
--
Gernot
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Xenomai] [Xenomai-forge] [PATCH v2] Silence unused_result warning from write()
2013-11-08 17:23 ` Gilles Chanteperdrix
2013-11-08 18:18 ` Jan Kiszka
@ 2014-01-14 12:28 ` Gernot Hillier
1 sibling, 0 replies; 8+ messages in thread
From: Gernot Hillier @ 2014-01-14 12:28 UTC (permalink / raw)
To: Gilles Chanteperdrix; +Cc: xenomai
Some glibc versions mark write() with attribute warn_unused_result (found in
Ubuntu 12.04 / eglibc 2.15 / gcc 4.6.3), so we need to silence this warning,
especially because we're building with -Werror.
Signed-off-by: Gernot Hillier <gernot.hillier@siemens.com>
---
lib/cobalt/init.c | 3 ++-
testsuite/latency/latency.c | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
Sorry for late self follow-up, but I was a bit offline due to parental
leave...
This is a friendly reminder to v2 of the patch (already posted on
2013-11-11), adressing your comments from 2013-11-08, Gilles. I also
rebased patch to today's master.
The "attribute unused" style was adopted from
testsuite/latency/latency.c. We still think fixing the warning in the
source code is better than in the configure command line.
diff --git a/lib/cobalt/init.c b/lib/cobalt/init.c
index 0c2b29a..c3086a9 100644
--- a/lib/cobalt/init.c
+++ b/lib/cobalt/init.c
@@ -54,7 +54,8 @@ int __rtdm_fd_start = INT_MAX;
static void sigill_handler(int sig)
{
const char m[] = "no Xenomai support in kernel?\n";
- write(2, m, sizeof(m) - 1);
+ ssize_t rc __attribute__ ((unused));
+ rc = write(2, m, sizeof(m) - 1);
exit(EXIT_FAILURE);
}
diff --git a/testsuite/latency/latency.c b/testsuite/latency/latency.c
index 6325672..12b90a9 100644
--- a/testsuite/latency/latency.c
+++ b/testsuite/latency/latency.c
@@ -507,7 +507,7 @@ static void sigdebug(int sig, siginfo_t *si, void *context)
case SIGDEBUG_WATCHDOG:
n = snprintf(buffer, sizeof(buffer), "%s\n",
reason_str[reason]);
- write(STDERR_FILENO, buffer, n);
+ n = write(STDERR_FILENO, buffer, n);
exit(EXIT_FAILURE);
}
--
1.8.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-01-14 12:28 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-07 9:22 [Xenomai] [Xenomai-forge] [PATCH] Silence unused_result warning from write() Gernot Hillier
2013-11-07 18:01 ` Gilles Chanteperdrix
2013-11-08 5:55 ` Gernot Hillier
2013-11-08 17:23 ` Gilles Chanteperdrix
2013-11-08 18:18 ` Jan Kiszka
2013-11-11 8:36 ` dietmar.schindler
2013-11-11 10:00 ` Gernot Hillier
2014-01-14 12:28 ` [Xenomai] [Xenomai-forge] [PATCH v2] " Gernot Hillier
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.