aboutsummaryrefslogtreecommitdiff
path: root/util-linux/flock.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/flock.c')
-rw-r--r--util-linux/flock.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/util-linux/flock.c b/util-linux/flock.c
index 05a747f72..1f7ade7c4 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]) {
94 return spawn_and_wait(argv); 96 int rc;
97 if (opt & OPT_c) {
98 /* -c 'PROG ARGS' means "run sh -c 'PROG ARGS'" */
99 argv -= 2;
100 argv[0] = (char*)get_shell_name();
101 argv[1] = (char*)"-c";
102 /* argv[2] = "PROG ARGS"; */
103 /* argv[3] = NULL; */
104 }
105 rc = spawn_and_wait(argv);
106 if (rc < 0)
107 bb_simple_perror_msg(argv[0]);
108 return rc;
109 }
95 110
96 return EXIT_SUCCESS; 111 return EXIT_SUCCESS;
97} 112}