fix backwards posix_spawn file action order
authorRich Felker <dalias@aerifal.cx>
Sun, 29 May 2011 16:58:02 +0000 (12:58 -0400)
committerRich Felker <dalias@aerifal.cx>
Sun, 29 May 2011 16:58:02 +0000 (12:58 -0400)
src/process/fdop.h
src/process/posix_spawn.c
src/process/posix_spawn_file_actions_addclose.c
src/process/posix_spawn_file_actions_adddup2.c
src/process/posix_spawn_file_actions_addopen.c

index 72f9b5fee5ed2ddc69b251fecee5fe9c3d123805..02ff83c53f9d387cc5ee1e4fef1d2c9d16a02150 100644 (file)
@@ -3,7 +3,7 @@
 #define FDOP_OPEN 3
 
 struct fdop {
-       struct fdop *next;
+       struct fdop *next, *prev;
        int cmd, fd, newfd, oflag;
        mode_t mode;
        char path[];
index 59f4a8bba2479b8749ccb69e0345f8bceecccc4b..b1a9fbde52c9aafc8fe8a8725bc4439b3018a311 100644 (file)
@@ -51,10 +51,11 @@ int __posix_spawnx(pid_t *res, const char *path,
                __syscall(SYS_setuid, __syscall(SYS_getuid)) ))
                _exit(127);
 
-       if (fa) {
+       if (fa && fa->__actions) {
                struct fdop *op;
                int ret, fd;
-               for (op = fa->__actions; op; op = op->next) {
+               for (op = fa->__actions; op->next; op = op->next);
+               for (; op; op = op->prev) {
                        switch(op->cmd) {
                        case FDOP_CLOSE:
                                ret = __syscall(SYS_close, op->fd);
index 44c6314fcb69090da8b4dbec1336318dd692ff39..cdda5979916dd1437cc1e0249617847291fcd3e9 100644 (file)
@@ -9,7 +9,8 @@ int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *fa, int fd)
        if (!op) return ENOMEM;
        op->cmd = FDOP_CLOSE;
        op->fd = fd;
-       op->next = fa->__actions;
+       if ((op->next = fa->__actions)) op->next->prev = op;
+       op->prev = 0;
        fa->__actions = op;
        return 0;
 }
index 9209ee7c2e84fa78460db6a9cc7cd541c43ab3bf..26f2c5cc87e1402a6c7a3b4cd491278fa9b230db 100644 (file)
@@ -10,7 +10,8 @@ int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, int fd, int
        op->cmd = FDOP_DUP2;
        op->fd = fd;
        op->newfd = newfd;
-       op->next = fa->__actions;
+       if ((op->next = fa->__actions)) op->next->prev = op;
+       op->prev = 0;
        fa->__actions = op;
        return 0;
 }
index 5e2c86d9b12e93da3472be052cce0b1b6bd57a9c..af3ca604fe0ee8125d9677e9028ae0e58f4d0b40 100644 (file)
@@ -13,7 +13,8 @@ int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *fa, int fd, con
        op->oflag = flags;
        op->mode = mode;
        strcpy(op->path, path);
-       op->next = fa->__actions;
+       if ((op->next = fa->__actions)) op->next->prev = op;
+       op->prev = 0;
        fa->__actions = op;
        return 0;
 }