diff options
Diffstat (limited to 'toys/posix')
-rw-r--r-- | toys/posix/false.c | 2 | ||||
-rw-r--r-- | toys/posix/kill.c | 17 | ||||
-rw-r--r-- | toys/posix/pwd.c | 18 | ||||
-rw-r--r-- | toys/posix/time.c | 23 | ||||
-rw-r--r-- | toys/posix/true.c | 4 |
5 files changed, 29 insertions, 35 deletions
diff --git a/toys/posix/false.c b/toys/posix/false.c index 2476e826..e9337996 100644 --- a/toys/posix/false.c +++ b/toys/posix/false.c @@ -4,7 +4,7 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/false.html -USE_FALSE(NEWTOY(false, NULL, TOYFLAG_BIN|TOYFLAG_NOHELP)) +USE_FALSE(NEWTOY(false, NULL, TOYFLAG_BIN|TOYFLAG_NOHELP|TOYFLAG_MAYFORK)) config FALSE bool "false" diff --git a/toys/posix/kill.c b/toys/posix/kill.c index c9de98ea..3c129b04 100644 --- a/toys/posix/kill.c +++ b/toys/posix/kill.c @@ -11,7 +11,7 @@ * * No Standard -USE_KILL(NEWTOY(kill, "?ls: ", TOYFLAG_BIN)) +USE_KILL(NEWTOY(kill, "?ls: ", TOYFLAG_BIN|TOYFLAG_MAYFORK)) USE_KILLALL5(NEWTOY(killall5, "?o*ls: [!lo][!ls]", TOYFLAG_SBIN)) config KILL @@ -65,12 +65,13 @@ void kill_main(void) if (FLAG(l)) { if (*args) { int signum = sig_to_num(*args); - char *s = NULL; + char *s = 0; if (signum>=0) s = num_to_sig(signum&127); if (isdigit(**args)) puts(s ? s : "UNKNOWN"); else printf("%d\n", signum); } else list_signals(); + return; } @@ -80,6 +81,7 @@ void kill_main(void) if (TT.s) { char *arg; int i = strtol(TT.s, &arg, 10); + if (!*arg) arg = num_to_sig(i); else arg = TT.s; @@ -106,7 +108,10 @@ void kill_main(void) sid = getsid(pid = getpid()); - if (!(dp = opendir("/proc"))) perror_exit("/proc"); + if (!(dp = opendir("/proc"))) { + free(olist); + perror_exit("/proc"); + } while ((entry = readdir(dp))) { int count, procpid, procsid; @@ -128,10 +133,8 @@ void kill_main(void) kill(procpid, signum); } - if (CFG_TOYBOX_FREE) { - closedir(dp); - free(olist); - } + closedir(dp); + free(olist); // is it kill? } else { diff --git a/toys/posix/pwd.c b/toys/posix/pwd.c index 4c6ae99b..c7dc78f7 100644 --- a/toys/posix/pwd.c +++ b/toys/posix/pwd.c @@ -4,7 +4,7 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/pwd.html -USE_PWD(NEWTOY(pwd, ">0LP[-LP]", TOYFLAG_BIN)) +USE_PWD(NEWTOY(pwd, ">0LP[-LP]", TOYFLAG_BIN|TOYFLAG_MAYFORK)) config PWD bool "pwd" @@ -26,7 +26,7 @@ void pwd_main(void) char *s, *pwd = getcwd(0, 0), *PWD; // Only use $PWD if it's an absolute path alias for cwd with no "." or ".." - if (!(toys.optflags & FLAG_P) && (s = PWD = getenv("PWD"))) { + if (!FLAG(P) && (s = PWD = getenv("PWD"))) { struct stat st1, st2; while (*s == '/') { @@ -37,18 +37,16 @@ void pwd_main(void) while (*s && *s != '/') s++; } if (!*s && s != PWD) s = PWD; - else s = NULL; + else s = 0; // If current directory exists, make sure it matches. if (s && pwd) if (stat(pwd, &st1) || stat(PWD, &st2) || st1.st_ino != st2.st_ino || - st1.st_dev != st2.st_dev) s = NULL; - } else s = NULL; + st1.st_dev != st2.st_dev) s = 0; + } else s = 0; // If -L didn't give us a valid path, use cwd. - if (!s && !(s = pwd)) perror_exit("xgetcwd"); - - xprintf("%s\n", s); - - if (CFG_TOYBOX_FREE) free(pwd); + if (s || (s = pwd)) puts(s); + free(pwd); + if (!s) perror_exit("xgetcwd"); } diff --git a/toys/posix/time.c b/toys/posix/time.c index f51a3b95..3d7d2ba7 100644 --- a/toys/posix/time.c +++ b/toys/posix/time.c @@ -4,7 +4,7 @@ * * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/time.html -USE_TIME(NEWTOY(time, "<1^pv", TOYFLAG_USR|TOYFLAG_BIN)) +USE_TIME(NEWTOY(time, "<1^pv", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_MAYFORK)) config TIME bool "time" @@ -45,20 +45,13 @@ void time_main(void) r = (tv2.tv_sec-tv.tv_sec)+((tv2.tv_usec-tv.tv_usec)/1000000.0); u = ru.ru_utime.tv_sec+(ru.ru_utime.tv_usec/1000000.0); s = ru.ru_stime.tv_sec+(ru.ru_stime.tv_usec/1000000.0); - if (FLAG(v)) { - fprintf(stderr, "Real time (s): %f\n" - "System time (s): %f\n" - "User time (s): %f\n" - "Max RSS (KiB): %ld\n" - "Major faults: %ld\n" - "Minor faults: %ld\n" - "File system inputs: %ld\n" - "File system outputs: %ld\n" - "Voluntary context switches: %ld\n" - "Involuntary context switches: %ld\n", r, s, u, - ru.ru_maxrss, ru.ru_majflt, ru.ru_minflt, ru.ru_inblock, - ru.ru_oublock, ru.ru_nvcsw, ru.ru_nivcsw); - } else fprintf(stderr, "real %f\nuser %f\nsys %f\n", r, u, s); + if (FLAG(v)) fprintf(stderr, "Real time (s): %f\nSystem time (s): %f\n" + "User time (s): %f\nMax RSS (KiB): %ld\nMajor faults: %ld\n" + "Minor faults: %ld\nFile system inputs: %ld\nFile system outputs: %ld\n" + "Voluntary context switches: %ld\nInvoluntary context switches: %ld\n", + r, s, u, ru.ru_maxrss, ru.ru_majflt, ru.ru_minflt, ru.ru_inblock, + ru.ru_oublock, ru.ru_nvcsw, ru.ru_nivcsw); + else fprintf(stderr, "real %f\nuser %f\nsys %f\n", r, u, s); toys.exitval = WIFEXITED(stat) ? WEXITSTATUS(stat) : WTERMSIG(stat); } } diff --git a/toys/posix/true.c b/toys/posix/true.c index 5e443212..b92d9c3a 100644 --- a/toys/posix/true.c +++ b/toys/posix/true.c @@ -4,8 +4,8 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/true.html -USE_TRUE(NEWTOY(true, NULL, TOYFLAG_BIN|TOYFLAG_NOHELP)) -USE_TRUE(OLDTOY(:, true, TOYFLAG_NOFORK|TOYFLAG_NOHELP)) +USE_TRUE(NEWTOY(true, NULL, TOYFLAG_BIN|TOYFLAG_NOHELP|TOYFLAG_MAYFORK)) +USE_TRUE(OLDTOY(:, true, TOYFLAG_NOFORK|TOYFLAG_NOHELP|TOYFLAG_MAYFORK)) config TRUE bool "true" |