fix posix_spawn interaction with fork and abort by taking lock
[musl.git] / src / process / posix_spawn_file_actions_addopen.c
blob368922c76b5259944059bad15d1c1d9d8e79fce5
1 #include <spawn.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include "fdop.h"
7 int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *restrict fa, int fd, const char *restrict path, int flags, mode_t mode)
9 struct fdop *op = malloc(sizeof *op + strlen(path) + 1);
10 if (!op) return ENOMEM;
11 op->cmd = FDOP_OPEN;
12 op->fd = fd;
13 op->oflag = flags;
14 op->mode = mode;
15 strcpy(op->path, path);
16 if ((op->next = fa->__actions)) op->next->prev = op;
17 op->prev = 0;
18 fa->__actions = op;
19 return 0;