about summary refs log tree commit diff
path: root/src/process
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2019-08-30 16:21:36 -0400
committerRich Felker <dalias@aerifal.cx>2019-08-30 16:21:36 -0400
commit74244e5b3ed4a61d99c5fc0967b69e5c9a753456 (patch)
tree5951d09c6a630f738fedd84566289b89b81fa099 /src/process
parentf76e183111bc4491ee575c3e2fcc793412acff4e (diff)
downloadmusl-74244e5b3ed4a61d99c5fc0967b69e5c9a753456.tar.gz
musl-74244e5b3ed4a61d99c5fc0967b69e5c9a753456.tar.xz
musl-74244e5b3ed4a61d99c5fc0967b69e5c9a753456.zip
add posix_spawn [f]chdir file actions
these are presently extensions, thus named with _np to match glibc and
other implementations that provide them; however they are likely to be
standardized in the future without the _np suffix as a result of
Austin Group issue 1208. if so, both names will be kept as aliases.
Diffstat (limited to 'src/process')
-rw-r--r--src/process/fdop.h2
-rw-r--r--src/process/posix_spawn.c8
-rw-r--r--src/process/posix_spawn_file_actions_addchdir.c18
-rw-r--r--src/process/posix_spawn_file_actions_addfchdir.c17
4 files changed, 45 insertions, 0 deletions
diff --git a/src/process/fdop.h b/src/process/fdop.h
index 00b87514..5adf1443 100644
--- a/src/process/fdop.h
+++ b/src/process/fdop.h
@@ -1,6 +1,8 @@
 #define FDOP_CLOSE 1
 #define FDOP_DUP2 2
 #define FDOP_OPEN 3
+#define FDOP_CHDIR 4
+#define FDOP_FCHDIR 5
 
 struct fdop {
 	struct fdop *next, *prev;
diff --git a/src/process/posix_spawn.c b/src/process/posix_spawn.c
index 306faa05..29652197 100644
--- a/src/process/posix_spawn.c
+++ b/src/process/posix_spawn.c
@@ -125,6 +125,14 @@ static int child(void *args_vp)
 					__syscall(SYS_close, fd);
 				}
 				break;
+			case FDOP_CHDIR:
+				ret = __syscall(SYS_chdir, op->path);
+				if (ret<0) goto fail;
+				break;
+			case FDOP_FCHDIR:
+				ret = __syscall(SYS_fchdir, op->fd);
+				if (ret<0) goto fail;
+				break;
 			}
 		}
 	}
diff --git a/src/process/posix_spawn_file_actions_addchdir.c b/src/process/posix_spawn_file_actions_addchdir.c
new file mode 100644
index 00000000..7f2590ae
--- /dev/null
+++ b/src/process/posix_spawn_file_actions_addchdir.c
@@ -0,0 +1,18 @@
+#include <spawn.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "fdop.h"
+
+int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *restrict fa, const char *restrict path)
+{
+	struct fdop *op = malloc(sizeof *op + strlen(path) + 1);
+	if (!op) return ENOMEM;
+	op->cmd = FDOP_CHDIR;
+	op->fd = -1;
+	strcpy(op->path, path);
+	if ((op->next = fa->__actions)) op->next->prev = op;
+	op->prev = 0;
+	fa->__actions = op;
+	return 0;
+}
diff --git a/src/process/posix_spawn_file_actions_addfchdir.c b/src/process/posix_spawn_file_actions_addfchdir.c
new file mode 100644
index 00000000..436c683d
--- /dev/null
+++ b/src/process/posix_spawn_file_actions_addfchdir.c
@@ -0,0 +1,17 @@
+#include <spawn.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "fdop.h"
+
+int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *fa, int fd)
+{
+	struct fdop *op = malloc(sizeof *op);
+	if (!op) return ENOMEM;
+	op->cmd = FDOP_FCHDIR;
+	op->fd = fd;
+	if ((op->next = fa->__actions)) op->next->prev = op;
+	op->prev = 0;
+	fa->__actions = op;
+	return 0;
+}