aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-04-24 18:19:49 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-04-24 18:19:49 +0200
commite1d426fd65c00a6d01a10d85edf8a294ae8a2d2b (patch)
treebd6a4871e80f30e6a38974d64d8fcdc2c92e45e3
parent4ab372d49a6e82b0bf097dedb96d26330c5f2d5f (diff)
downloadbusybox-w32-e1d426fd65c00a6d01a10d85edf8a294ae8a2d2b.tar.gz
busybox-w32-e1d426fd65c00a6d01a10d85edf8a294ae8a2d2b.tar.bz2
busybox-w32-e1d426fd65c00a6d01a10d85edf8a294ae8a2d2b.zip
flock: fix -c; improve error handling of fork+exec
function old new delta flock_main 254 334 +80 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util-linux/flock.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/util-linux/flock.c b/util-linux/flock.c
index 05a747f72..539a835b7 100644
--- a/util-linux/flock.c
+++ b/util-linux/flock.c
@@ -57,7 +57,6 @@ int flock_main(int argc UNUSED_PARAM, char **argv)
57 /* If it is "flock FILE -c PROG", then -c isn't caught by getopt32: 57 /* If it is "flock FILE -c PROG", then -c isn't caught by getopt32:
58 * we use "+" in order to support "flock -opt FILE PROG -with-opts", 58 * we use "+" in order to support "flock -opt FILE PROG -with-opts",
59 * we need to remove -c by hand. 59 * we need to remove -c by hand.
60 * TODO: in upstream, -c 'PROG ARGS' means "run sh -c 'PROG ARGS'"
61 */ 60 */
62 if (argv[0] 61 if (argv[0]
63 && argv[0][0] == '-' 62 && argv[0][0] == '-'
@@ -66,6 +65,9 @@ int flock_main(int argc UNUSED_PARAM, char **argv)
66 ) 65 )
67 ) { 66 ) {
68 argv++; 67 argv++;
68 if (argv[1])
69 bb_error_msg_and_die("-c takes only one argument");
70 opt |= OPT_c;
69 } 71 }
70 72
71 if (OPT_s == LOCK_SH && OPT_x == LOCK_EX && OPT_n == LOCK_NB && OPT_u == LOCK_UN) { 73 if (OPT_s == LOCK_SH && OPT_x == LOCK_EX && OPT_n == LOCK_NB && OPT_u == LOCK_UN) {
@@ -90,8 +92,21 @@ int flock_main(int argc UNUSED_PARAM, char **argv)
90 bb_perror_nomsg_and_die(); 92 bb_perror_nomsg_and_die();
91 } 93 }
92 94
93 if (argv[0]) 95 if (argv[0]) {
96 if (!(opt & OPT_c)) {
97 int rc = spawn_and_wait(argv);
98 if (rc < 0)
99 bb_simple_perror_msg(argv[0]);
100 return rc;
101 }
102 /* -c 'PROG ARGS' means "run sh -c 'PROG ARGS'" */
103 argv -= 2;
104 argv[0] = (char*)get_shell_name();
105 argv[1] = (char*)"-c";
106 /* argv[2] = "PROG ARGS"; */
107 /* argv[3] = NULL; */
94 return spawn_and_wait(argv); 108 return spawn_and_wait(argv);
109 }
95 110
96 return EXIT_SUCCESS; 111 return EXIT_SUCCESS;
97} 112}