diff mbox series

[1/6] lapi: Add TEMP_FAILURE_RETRY definition

Message ID 20181018112433.9554-1-pvorel@suse.cz
State Accepted
Delegated to: Petr Vorel
Headers show
Series [1/6] lapi: Add TEMP_FAILURE_RETRY definition | expand

Commit Message

Petr Vorel Oct. 18, 2018, 11:24 a.m. UTC
and use it in realtime to fix pi-tests.
This fixes build failure on libc missing it (e.g. musl, bionic):

test-skeleton.c:112:12: warning: implicit declaration of function ‘TEMP_FAILURE_RETRY’ [-Wimplicit-function-declaration]
  termpid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0));
            ^~~~~~~~~~~~~~~~~~
make[5]: *** [<builtin>: testpi-6] Error 1

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 include/lapi/unistd.h                          | 18 ++++++++++++++++++
 .../realtime/func/pi-tests/test-skeleton.c     |  1 +
 2 files changed, 19 insertions(+)
 create mode 100644 include/lapi/unistd.h

Comments

Cyril Hrubis Oct. 19, 2018, 12:49 p.m. UTC | #1
Hi!
> and use it in realtime to fix pi-tests.
> This fixes build failure on libc missing it (e.g. musl, bionic):
> 
> test-skeleton.c:112:12: warning: implicit declaration of function ???TEMP_FAILURE_RETRY??? [-Wimplicit-function-declaration]
>   termpid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0));
>             ^~~~~~~~~~~~~~~~~~
> make[5]: *** [<builtin>: testpi-6] Error 1

I had no idea glibc has macro like this. I do wonder if it worth a
fallback definition if we have exactly one use in the source code tree.
Maybe we should just replace the macro with the while loop instead.
Petr Vorel Oct. 19, 2018, 2:57 p.m. UTC | #2
Hi Cyril,

> Hi!
> > and use it in realtime to fix pi-tests.
> > This fixes build failure on libc missing it (e.g. musl, bionic):

> > test-skeleton.c:112:12: warning: implicit declaration of function ???TEMP_FAILURE_RETRY??? [-Wimplicit-function-declaration]
> >   termpid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0));
> >             ^~~~~~~~~~~~~~~~~~
> > make[5]: *** [<builtin>: testpi-6] Error 1

> I had no idea glibc has macro like this. I do wonder if it worth a
> fallback definition if we have exactly one use in the source code tree.
> Maybe we should just replace the macro with the while loop instead.

Replaced and the rest pushed with your ack.
Thanks for your review!


Kind regards,
Petr
diff mbox series

Patch

diff --git a/include/lapi/unistd.h b/include/lapi/unistd.h
new file mode 100644
index 000000000..7ddc60e9a
--- /dev/null
+++ b/include/lapi/unistd.h
@@ -0,0 +1,18 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+ */
+#ifndef LAPI_UNISTD_H__
+#define LAPI_UNISTD_H__
+
+/* glibc unistd.h */
+#ifndef TEMP_FAILURE_RETRY
+# define TEMP_FAILURE_RETRY(expression) \
+  (__extension__							      \
+    ({ long int __result;						      \
+       do __result = (long int) (expression);				      \
+       while (__result == -1L && errno == EINTR);			      \
+       __result; }))
+#endif
+
+#endif /* LAPI_UNISTD_H__ */
diff --git a/testcases/realtime/func/pi-tests/test-skeleton.c b/testcases/realtime/func/pi-tests/test-skeleton.c
index 326a8ab56..7ad4804c8 100644
--- a/testcases/realtime/func/pi-tests/test-skeleton.c
+++ b/testcases/realtime/func/pi-tests/test-skeleton.c
@@ -42,6 +42,7 @@ 
 #include <sys/wait.h>
 #include <time.h>
 #include <librttest.h>
+#include "lapi/unistd.h"
 
 void usage(void)
 {