aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0038-have-posix_spawnattr_setflags-check-for-supported-fl.patch
blob: 3c2e944bbb4859ce546425055cc231cde1d9f87f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
From f9f686b7721e2cc35e20fa5c6df6da2dc4ac3f50 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Sat, 22 Apr 2017 20:45:16 -0400
Subject: [PATCH] have posix_spawnattr_setflags check for supported flags

per POSIX, EINVAL is not a mandatory error, only an optional one. but
reporting unsupported flags allows an application to fallback
gracefully when a requested feature is not supported. this is not
helpful now, but it may be in the future if additional flags are
added.

had this checking been present before, applications would have been
able to check for the newly-added POSIX_SPAWN_SETSID feature (added in
commit bb439bb17108b67f3df9c9af824d3a607b5b059d) at runtime.
---
 src/process/posix_spawnattr_setflags.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/process/posix_spawnattr_setflags.c b/src/process/posix_spawnattr_setflags.c
index f750c040..68780992 100644
--- a/src/process/posix_spawnattr_setflags.c
+++ b/src/process/posix_spawnattr_setflags.c
@@ -1,7 +1,18 @@
 #include <spawn.h>
+#include <errno.h>
 
 int posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags)
 {
+	const unsigned all_flags =
+		POSIX_SPAWN_RESETIDS |
+		POSIX_SPAWN_SETPGROUP |
+		POSIX_SPAWN_SETSIGDEF |
+		POSIX_SPAWN_SETSIGMASK |
+		POSIX_SPAWN_SETSCHEDPARAM |
+		POSIX_SPAWN_SETSCHEDULER |
+		POSIX_SPAWN_USEVFORK |
+		POSIX_SPAWN_SETSID;
+	if (flags & ~all_flags) return EINVAL;
 	attr->__flags = flags;
 	return 0;
 }
-- 
2.13.0