hush: move msh/lash config into hush.c, no code changes
[oweals/busybox.git] / runit / chpst.c
index 43e8d5f3e5534e5333cc8138c4465fd8939d2c1f..ad0811294619b30850e058dab028195c04cf9970 100644 (file)
@@ -92,7 +92,8 @@ enum {
        OPT_2 = (1 << 20) * ENABLE_CHPST,
 };
 
-static void edir(const char *directory_name)
+/* TODO: use recursive_action? */
+static NOINLINE void edir(const char *directory_name)
 {
        int wdir;
        DIR *dir;
@@ -101,9 +102,7 @@ static void edir(const char *directory_name)
 
        wdir = xopen(".", O_RDONLY | O_NDELAY);
        xchdir(directory_name);
-       dir = opendir(".");
-       if (!dir)
-               bb_perror_msg_and_die("opendir %s", directory_name);
+       dir = xopendir(".");
        for (;;) {
                char buf[256];
                char *tail;
@@ -200,11 +199,11 @@ int chpst_main(int argc UNUSED_PARAM, char **argv)
                // if yes -> getopt converts strings to numbers for us
                opt_complementary = "-1:a+:c+:d+:f+:l+:m+:o+:p+:r+:s+:t+";
                opt = getopt32(argv, "+a:c:d:f:l:m:o:p:r:s:t:u:U:e:"
-                       USE_CHPST("/:n:vP012"),
+                       IF_CHPST("/:n:vP012"),
                        &limita, &limitc, &limitd, &limitf, &limitl,
                        &limitm, &limito, &limitp, &limitr, &limits, &limitt,
                        &set_user, &env_user, &env_dir
-                       USE_CHPST(, &root, &nicestr));
+                       IF_CHPST(, &root, &nicestr));
                argv += optind;
                if (opt & OPT_m) { // -m means -asld
                        limita = limits = limitl = limitd = limitm;
@@ -213,6 +212,8 @@ int chpst_main(int argc UNUSED_PARAM, char **argv)
        } else {
                option_mask32 = opt = 0;
                argv++;
+               if (!*argv)
+                       bb_show_usage();
        }
 
        // envdir?
@@ -222,7 +223,7 @@ int chpst_main(int argc UNUSED_PARAM, char **argv)
        }
 
        // setuidgid?
-       if (ENABLE_SETUIDGID && applet_name[0] == 's') {
+       if (ENABLE_SETUIDGID && applet_name[1] == 'e') {
                set_user = *argv++;
                opt |= OPT_u;
        }
@@ -381,6 +382,5 @@ int chpst_main(int argc UNUSED_PARAM, char **argv)
        if (opt & OPT_2)
                close(STDERR_FILENO);
 
-       BB_EXECVP(argv[0], argv);
-       bb_perror_msg_and_die("exec %s", argv[0]);
+       BB_EXECVP_or_die(argv);
 }