diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-09 21:32:30 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-09 21:32:30 +0000 |
commit | cd7001f7055c3fc2d6298ab9e3befe91e951c652 (patch) | |
tree | b9509ed21e0a7af26128b796a66a3294ae4dc5b0 /findutils/xargs.c | |
parent | 1b4b2cb20e5291c319ce0c7721e64445e2749b10 (diff) | |
download | busybox-w32-cd7001f7055c3fc2d6298ab9e3befe91e951c652.tar.gz busybox-w32-cd7001f7055c3fc2d6298ab9e3befe91e951c652.tar.bz2 busybox-w32-cd7001f7055c3fc2d6298ab9e3befe91e951c652.zip |
factor out NOFORK/NOEXEC code from find. Use it for xargs too.
Diffstat (limited to 'findutils/xargs.c')
-rw-r--r-- | findutils/xargs.c | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c index ea7c22060..b4dd9f876 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
@@ -48,47 +48,32 @@ | |||
48 | This function has special algorithm. | 48 | This function has special algorithm. |
49 | Don't use fork and include to main! | 49 | Don't use fork and include to main! |
50 | */ | 50 | */ |
51 | static int xargs_exec(char *const *args) | 51 | static int xargs_exec(char **args) |
52 | { | 52 | { |
53 | pid_t p; | ||
54 | volatile int exec_errno = 0; /* shared vfork stack */ | ||
55 | int status; | 53 | int status; |
56 | 54 | ||
57 | p = vfork(); | 55 | status = spawn_and_wait(args); |
58 | if (p < 0) | 56 | if (status < 0) { |
59 | bb_perror_msg_and_die("vfork"); | ||
60 | |||
61 | if (p == 0) { | ||
62 | /* vfork -- child */ | ||
63 | BB_EXECVP(args[0], args); | ||
64 | exec_errno = errno; /* set error to shared stack */ | ||
65 | _exit(1); | ||
66 | } | ||
67 | |||
68 | /* vfork -- parent */ | ||
69 | while (wait(&status) == (pid_t) -1) | ||
70 | if (errno != EINTR) | ||
71 | break; | ||
72 | if (exec_errno) { | ||
73 | errno = exec_errno; | ||
74 | bb_perror_msg("%s", args[0]); | 57 | bb_perror_msg("%s", args[0]); |
75 | return exec_errno == ENOENT ? 127 : 126; | 58 | return errno == ENOENT ? 127 : 126; |
76 | } | 59 | } |
77 | if (WEXITSTATUS(status) == 255) { | 60 | if (status == 255) { |
78 | bb_error_msg("%s: exited with status 255; aborting", args[0]); | 61 | bb_error_msg("%s: exited with status 255; aborting", args[0]); |
79 | return 124; | 62 | return 124; |
80 | } | 63 | } |
64 | /* Huh? I think we won't see this, ever. We don't wait with WUNTRACED! | ||
81 | if (WIFSTOPPED(status)) { | 65 | if (WIFSTOPPED(status)) { |
82 | bb_error_msg("%s: stopped by signal %d", | 66 | bb_error_msg("%s: stopped by signal %d", |
83 | args[0], WSTOPSIG(status)); | 67 | args[0], WSTOPSIG(status)); |
84 | return 125; | 68 | return 125; |
85 | } | 69 | } |
86 | if (WIFSIGNALED(status)) { | 70 | */ |
71 | if (status >= 1000) { | ||
87 | bb_error_msg("%s: terminated by signal %d", | 72 | bb_error_msg("%s: terminated by signal %d", |
88 | args[0], WTERMSIG(status)); | 73 | args[0], status - 1000); |
89 | return 125; | 74 | return 125; |
90 | } | 75 | } |
91 | if (WEXITSTATUS(status)) | 76 | if (status) |
92 | return 123; | 77 | return 123; |
93 | return 0; | 78 | return 0; |
94 | } | 79 | } |