Skip to contentSkip to conversation

samples: pidfd: Fix compile error seen if __NR_pidfd_send_signal is undefined

PATCH In review Guenter Roeck 2 participants 6 messages May 30, 2019 Pidfd API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 samples: pidfd: Fix compile error seen if __NR_pidfd_send_signal is undefined

To make pidfd-metadata compile on all arches, irrespective of whether or not syscall numbers are assigned, define the syscall number to -1 if it isn't to cause the kernel to return -ENOSYS.

Fixes 43c6afee48d4 ("samples: show race-free pidfd metadata access")
Cc Christian Brauner <[email protected]>
---
 samples/pidfd/pidfd-metadata.c | 4 ++++
 1 file changed, 4 insertions(+)
samples/pidfd/pidfd-metadata.c +4 -0
index 640f5f757c57..1e125ddde268 100644
@@ -21,6 +21,10 @@
 #define CLONE_PIDFD 0x00001000
 #endif
 
+#ifndef __NR_pidfd_send_signal
+#define __NR_pidfd_send_signal	-1
+#endif
+
 static int do_child(void *args)
 {
 	printf("%d\n", getpid());
Signature · 1 line
2.7.4
#1 lore raw
Quoted 17 lines · Guenter Roeck

To make pidfd-metadata compile on all arches, irrespective of whether or not syscall numbers are assigned, define the syscall number to -1 if it isn't to cause the kernel to return -ENOSYS.

Fixes 43c6afee48d4 ("samples: show race-free pidfd metadata access")
Cc Christian Brauner <[email protected]>

---
samples/pidfd/pidfd-metadata.c | 4 ++++

1 file changed, 4 insertions(+)
samples/pidfd/pidfd-metadata.c +0 -0
index 640f5f757c57..1e125ddde268 100644

samples/pidfd/pidfd-metadata.c line 30

Quoted 10 lines
samples/pidfd/pidfd-metadata.c +4 -0
@@ -21,6 +21,10 @@
 #define CLONE_PIDFD 0x00001000
 #endif
 
+#ifndef __NR_pidfd_send_signal
+#define __NR_pidfd_send_signal	-1
+#endif
+
 static int do_child(void *args)
 {
 	printf("%d\n", getpid());

Couldn't you just use the actual syscall number? That should still fail if the kernel is to old and still work on kernels that support it but for whatever reason the unistd.h h header doesn't have it defined.

Thanks!
Christian

#2 lore raw
Quoted 21 lines · Christian Brauner
Quoted 20 lines · Guenter Roeck

To make pidfd-metadata compile on all arches, irrespective of whether or not syscall numbers are assigned, define the syscall number to -1 if it isn't to cause the kernel to return -ENOSYS.

Fixes 43c6afee48d4 ("samples: show race-free pidfd metadata access")
Cc Christian Brauner <[email protected]>

---
samples/pidfd/pidfd-metadata.c | 4 ++++

1 file changed, 4 insertions(+)
samples/pidfd/pidfd-metadata.c +0 -0
index 640f5f757c57..1e125ddde268 100644
@@ -21,6 +21,10 @@
 #define CLONE_PIDFD 0x00001000
 #endif
 
Quoted 14 lines

samples/pidfd/pidfd-metadata.c line 30

Quoted 7 lines
samples/pidfd/pidfd-metadata.c +4 -0
+#ifndef __NR_pidfd_send_signal
+#define __NR_pidfd_send_signal	-1
+#endif
+
 static int do_child(void *args)
 {
 	printf("%d\n", getpid());

Couldn't you just use the actual syscall number? That should still fail if the kernel is to old and still work on kernels that support it but for whatever reason the unistd.h h header doesn't have it defined.

syscall numbers can differ from architecture to architecture, and the provided solution is used in other test code. Please feel free to submit a different patch, though - I am only interested in a fix, which doesn't have to be mine.

Note that this fails in mips builds.

Thanks,
Guenter

#3 lore raw
Quoted 47 lines · Guenter Roeck
Quoted 1 line · Christian Brauner

On May 30, 2019 1:40:47 PM GMT+02:00, Guenter Roeck

Quoted 1 line · <[email protected]> wrote:
Quoted 1 line

To make pidfd-metadata compile on all arches, irrespective of

whether

Quoted 4 lines
Quoted 4 lines

or not syscall numbers are assigned, define the syscall number to -1 if it isn't to cause the kernel to return -ENOSYS.

Fixes 43c6afee48d4 ("samples: show race-free pidfd metadata

access")

Quoted 15 lines
Quoted 15 lines
Cc Christian Brauner <[email protected]>

---
samples/pidfd/pidfd-metadata.c | 4 ++++

1 file changed, 4 insertions(+)
samples/pidfd/pidfd-metadata.c +0 -0
index 640f5f757c57..1e125ddde268 100644
@@ -21,6 +21,10 @@
 #define CLONE_PIDFD 0x00001000
 #endif
 
Quoted 14 lines

samples/pidfd/pidfd-metadata.c line 30

Quoted 7 lines
samples/pidfd/pidfd-metadata.c +4 -0
+#ifndef __NR_pidfd_send_signal
+#define __NR_pidfd_send_signal	-1
+#endif
+
 static int do_child(void *args)
 {
 	printf("%d\n", getpid());

Couldn't you just use the actual syscall number? That should still fail if the kernel is to old and still work on kernels that support it but for whatever reason the unistd.h h header doesn't have it defined.

syscall numbers can differ from architecture to architecture, and the provided solution is used in other test code. Please feel free to submit
a different patch, though - I am only interested in a fix, which doesn't
have to be mine.

Quoted 4 lines

Note that this fails in mips builds.

Thanks,
Guenter

The syscall number is the same on all arches for this syscall. It's been added after the syscall numbering
work by Arnd.

Christian

#4 lore raw
Quoted 48 lines · Christian Brauner
Quoted 47 lines · Guenter Roeck
Quoted 1 line · Christian Brauner

On May 30, 2019 1:40:47 PM GMT+02:00, Guenter Roeck

Quoted 1 line · <[email protected]> wrote:
Quoted 1 line

To make pidfd-metadata compile on all arches, irrespective of

whether

Quoted 4 lines
Quoted 4 lines

or not syscall numbers are assigned, define the syscall number to -1 if it isn't to cause the kernel to return -ENOSYS.

Fixes 43c6afee48d4 ("samples: show race-free pidfd metadata

access")

Quoted 15 lines
Quoted 15 lines
Cc Christian Brauner <[email protected]>

---
samples/pidfd/pidfd-metadata.c | 4 ++++

1 file changed, 4 insertions(+)
samples/pidfd/pidfd-metadata.c +0 -0
index 640f5f757c57..1e125ddde268 100644
@@ -21,6 +21,10 @@
 #define CLONE_PIDFD 0x00001000
 #endif
 
Quoted 14 lines

samples/pidfd/pidfd-metadata.c line 30

Quoted 7 lines
samples/pidfd/pidfd-metadata.c +4 -0
+#ifndef __NR_pidfd_send_signal
+#define __NR_pidfd_send_signal	-1
+#endif
+
 static int do_child(void *args)
 {
 	printf("%d\n", getpid());

Couldn't you just use the actual syscall number? That should still fail if the kernel is to old and still work on kernels that support it but for whatever reason the unistd.h h header doesn't have it defined.

syscall numbers can differ from architecture to architecture, and the provided solution is used in other test code. Please feel free to submit
a different patch, though - I am only interested in a fix, which doesn't
have to be mine.

Quoted 9 lines
Quoted 4 lines

Note that this fails in mips builds.

Thanks,
Guenter

The syscall number is the same on all arches for this syscall. It's been added after the syscall numbering
work by Arnd.

As I suggested, please feel free to submit a different patch to fix the problem. What you are saying may be correct, but I would not personally want to rely on it or create a hard assumption that it will always be the case.

Thanks,
Guenter

maintainer Acked-by
#5 lore raw
Quoted 62 lines · Guenter Roeck
Quoted 1 line · Christian Brauner

On May 30, 2019 1:50:31 PM GMT+02:00, Guenter Roeck

Quoted 6 lines · <[email protected]> wrote:
Quoted 6 lines · Christian Brauner
Quoted 1 line

On May 30, 2019 1:40:47 PM GMT+02:00, Guenter Roeck

Quoted 1 line · <[email protected]> wrote:
Quoted 1 line

To make pidfd-metadata compile on all arches, irrespective of

whether

Quoted 1 line
Quoted 1 line

or not syscall numbers are assigned, define the syscall number to

-1

Quoted 34 lines
Quoted 34 lines
Quoted 3 lines
Quoted 3 lines

if it isn't to cause the kernel to return -ENOSYS.

Fixes 43c6afee48d4 ("samples: show race-free pidfd metadata

access")

Quoted 29 lines
Quoted 12 lines
Cc Christian Brauner <[email protected]>

---
samples/pidfd/pidfd-metadata.c | 4 ++++

1 file changed, 4 insertions(+)
samples/pidfd/pidfd-metadata.c +0 -0
index 640f5f757c57..1e125ddde268 100644

samples/pidfd/pidfd-metadata.c line 30

Quoted 10 lines
samples/pidfd/pidfd-metadata.c +4 -0
@@ -21,6 +21,10 @@
 #define CLONE_PIDFD 0x00001000
 #endif
 
+#ifndef __NR_pidfd_send_signal
+#define __NR_pidfd_send_signal	-1
+#endif
+
 static int do_child(void *args)
 {
 	printf("%d\n", getpid());

Couldn't you just use the actual syscall number? That should still fail if the kernel is to old and still work on kernels that support it but for whatever reason the unistd.h h header doesn't have it defined.

Quoted 1 line
Quoted 1 line

syscall numbers can differ from architecture to architecture, and

the

Quoted 6 lines
Quoted 6 lines

provided solution is used in other test code. Please feel free to submit
a different patch, though - I am only interested in a fix, which doesn't
have to be mine.

Quoted 9 lines
Quoted 4 lines

Note that this fails in mips builds.

Thanks,
Guenter

The syscall number is the same on all arches for this syscall. It's been added after the syscall numbering
work by Arnd.

Quoted 8 lines

As I suggested, please feel free to submit a different patch to fix the problem.
What you are saying may be correct, but I would not personally want to rely on it
or create a hard assumption that it will always be the case.

Thanks,
Guenter

I'll pick this patch up.