chiark / gitweb /
[PATCH] PATCH udev close on exec
[elogind.git] / namedev.c
index e86f88f43340300b926f4f654d6e599bf2647cfc..fe7dddaf55bafa0138562a731d67d4738c310906 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -433,9 +433,9 @@ static int execute_program(char *path, char *value, int len)
                                /* don't separate if in apostrophes */
                                pos++;
                                argv[i] = strsep(&pos, "\'");
-                               while (pos[0] == ' ')
+                               while (pos && pos[0] == ' ')
                                        pos++;
-               } else {
+                       } else {
                                argv[i] = strsep(&pos, " ");
                        }
                        dbg("arg[%i] '%s'", i, argv[i]);
@@ -454,10 +454,8 @@ static int execute_program(char *path, char *value, int len)
        switch(pid) {
        case 0:
                /* child */
-               close(STDOUT_FILENO);
-
-               /* dup write side of pipe to STDOUT */
-               dup(fds[1]);
+               /* dup2 write side of pipe to STDOUT */
+               dup2(fds[1], STDOUT_FILENO);
                if (argv[0] !=  NULL) {
                        dbg("execute '%s' with given arguments", argv[0]);
                        retval = execv(argv[0], argv);