diff options
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/adjtimex.c | 6 | ||||
-rw-r--r-- | miscutils/crond.c | 10 | ||||
-rw-r--r-- | miscutils/crontab.c | 28 | ||||
-rw-r--r-- | miscutils/dc.c | 10 | ||||
-rw-r--r-- | miscutils/dutmp.c | 95 | ||||
-rw-r--r-- | miscutils/makedevs.c | 8 | ||||
-rw-r--r-- | miscutils/mt.c | 12 | ||||
-rw-r--r-- | miscutils/strings.c | 4 | ||||
-rw-r--r-- | miscutils/time.c | 16 | ||||
-rw-r--r-- | miscutils/update.c | 4 | ||||
-rw-r--r-- | miscutils/watchdog.c | 4 |
11 files changed, 108 insertions, 89 deletions
diff --git a/miscutils/adjtimex.c b/miscutils/adjtimex.c index 848f7340e..d541848f0 100644 --- a/miscutils/adjtimex.c +++ b/miscutils/adjtimex.c @@ -87,7 +87,7 @@ void usage(char *prog) "Usage: %s [ -q ] [ -o offset ] [ -f frequency ] [ -p timeconstant ] [ -t tick ]\n", prog); } -#define show_usage() usage(argv[0]) +#define bb_show_usage() usage(argv[0]) #endif int main(int argc, char ** argv) @@ -121,12 +121,12 @@ int main(int argc, char ** argv) txc.modes |= ADJ_TICK; break; default: - show_usage(); + bb_show_usage(); exit(1); } } if (argc != optind) { /* no valid non-option parameters */ - show_usage(); + bb_show_usage(); exit(1); } diff --git a/miscutils/crond.c b/miscutils/crond.c index 8ae54a536..cbb4ffc58 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -154,7 +154,7 @@ crond_main(int ac, char **av) if (*optarg != 0) CDir = optarg; break; default: /* parse error */ - show_usage(); + bb_show_usage(); } } @@ -163,7 +163,7 @@ crond_main(int ac, char **av) */ if (chdir(CDir) != 0) - perror_msg_and_die("chdir"); + bb_perror_msg_and_die("chdir"); /* * close stdin and stdout, stderr. @@ -173,7 +173,7 @@ crond_main(int ac, char **av) if (ForegroundOpt == 0) { if(daemon(1, 0) < 0) - perror_msg_and_die("daemon"); + bb_perror_msg_and_die("daemon"); } (void)startlogger(); /* need if syslog mode selected */ @@ -268,7 +268,7 @@ vlog(int level, int MLOG_LEVEL, const char *ctl, va_list va) close(logfd); } else #ifdef FEATURE_DEBUG_OPT - perror_msg("Can't open log file") + bb_perror_msg("Can't open log file") #endif ; } @@ -385,7 +385,7 @@ startlogger(void) int logfd; if (LoggerOpt == 0) - openlog(applet_name, LOG_CONS|LOG_PID,LOG_CRON); + openlog(bb_applet_name, LOG_CONS|LOG_PID,LOG_CRON); else { /* test logfile */ if ((logfd = open(LogFile,O_WRONLY|O_CREAT|O_APPEND,600)) >= 0) diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 5bd7db6e5..c6c33ace9 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c @@ -61,7 +61,7 @@ crontab_main(int ac, char **av) UserId = getuid(); if ((pas = getpwuid(UserId)) == NULL) - perror_msg_and_die("getpwuid"); + bb_perror_msg_and_die("getpwuid"); strncpy(caller, pas->pw_name, sizeof(caller)); @@ -105,10 +105,10 @@ crontab_main(int ac, char **av) if (pas) { UserId = pas->pw_uid; } else { - error_msg_and_die("user %s unknown", av[i]); + bb_error_msg_and_die("user %s unknown", av[i]); } } else { - error_msg_and_die("only the superuser may specify a user"); + bb_error_msg_and_die("only the superuser may specify a user"); } } break; @@ -116,7 +116,7 @@ crontab_main(int ac, char **av) if (getuid() == geteuid()) { CDir = (*ptr) ? ptr : av[++i]; } else { - error_msg_and_die("-c option: superuser only"); + bb_error_msg_and_die("-c option: superuser only"); } break; default: @@ -125,14 +125,14 @@ crontab_main(int ac, char **av) } } if (i != ac || option == NONE) - show_usage(); + bb_show_usage(); /* * Get password entry */ if ((pas = getpwuid(UserId)) == NULL) - perror_msg_and_die("getpwuid"); + bb_perror_msg_and_die("getpwuid"); /* * If there is a replacement file, obtain a secure descriptor to it. @@ -141,7 +141,7 @@ crontab_main(int ac, char **av) if (repFile) { repFd = GetReplaceStream(caller, repFile); if (repFd < 0) - error_msg_and_die("unable to read replacement file"); + bb_error_msg_and_die("unable to read replacement file"); } /* @@ -149,7 +149,7 @@ crontab_main(int ac, char **av) */ if (chdir(CDir) < 0) - perror_msg_and_die("cannot change dir to %s", CDir); + bb_perror_msg_and_die("cannot change dir to %s", CDir); /* * Handle options as appropriate @@ -166,7 +166,7 @@ crontab_main(int ac, char **av) fputs(buf, stdout); fclose(fi); } else { - error_msg("no crontab for %s", pas->pw_name); + bb_error_msg("no crontab for %s", pas->pw_name); } } break; @@ -190,7 +190,7 @@ crontab_main(int ac, char **av) lseek(fd, 0L, 0); repFd = fd; } else { - error_msg_and_die("unable to create %s", tmp); + bb_error_msg_and_die("unable to create %s", tmp); } } @@ -211,7 +211,7 @@ crontab_main(int ac, char **av) close(fd); rename(path, pas->pw_name); } else { - error_msg("unable to create %s/%s", CDir, path); + bb_error_msg("unable to create %s/%s", CDir, path); } close(repFd); } @@ -244,7 +244,7 @@ crontab_main(int ac, char **av) /* loop */ } if (fo == NULL) { - error_msg("unable to append to %s/%s", CDir, CRONUPDATE); + bb_error_msg("unable to append to %s/%s", CDir, CRONUPDATE); } } return 0; @@ -291,7 +291,7 @@ GetReplaceStream(const char *user, const char *file) fd = open(file, O_RDONLY); if (fd < 0) { - error_msg("unable to open %s", file); + bb_error_msg("unable to open %s", file); exit(0); } buf[0] = 0; @@ -328,7 +328,7 @@ EditFile(const char *user, const char *file) /* * PARENT - failure */ - perror_msg_and_die("fork"); + bb_perror_msg_and_die("fork"); } wait4(pid, NULL, 0, NULL); } diff --git a/miscutils/dc.c b/miscutils/dc.c index c7b43ea0a..5e367fe68 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c @@ -16,14 +16,14 @@ static unsigned char base; static void push(double a) { if (pointer >= (sizeof(stack) / sizeof(*stack))) - error_msg_and_die("stack overflow"); + bb_error_msg_and_die("stack overflow"); stack[pointer++] = a; } static double pop(void) { if (pointer == 0) - error_msg_and_die("stack underflow"); + bb_error_msg_and_die("stack underflow"); return stack[--pointer]; } @@ -154,7 +154,7 @@ static void stack_machine(const char *argument) } o++; } - error_msg_and_die("%s: syntax error.", argument); + bb_error_msg_and_die("%s: syntax error.", argument); } /* return pointer to next token in buffer and set *buffer to one char @@ -191,7 +191,7 @@ int dc_main(int argc, char **argv) char *line = NULL; char *cursor = NULL; char *token = NULL; - while ((line = get_line_from_file(stdin))) { + while ((line = bb_get_chomped_line_from_file(stdin))) { cursor = line; len = number_of_tokens(line); for (i = 0; i < len; i++) { @@ -203,7 +203,7 @@ int dc_main(int argc, char **argv) } } else { if (*argv[1]=='-') - show_usage(); + bb_show_usage(); while (argc >= 2) { stack_machine(argv[1]); argv++; diff --git a/miscutils/dutmp.c b/miscutils/dutmp.c index 19e09fbb0..113f850fe 100644 --- a/miscutils/dutmp.c +++ b/miscutils/dutmp.c @@ -8,57 +8,76 @@ * versions of 'who', 'last', etc. IP Addr is output in hex, * little endian on x86. * - * Modified to support all sorts of libcs by - * Erik Andersen <andersen@lineo.com> */ -#include <sys/types.h> -#include <fcntl.h> -#include <errno.h> -#include <utmp.h> +/* Mar 13, 2003 Manuel Novoa III + * + * 1) Added proper error checking. + * 2) Allow '-' arg for stdin. + * 3) For modern libcs, take into account that utmp char[] members + * need not be nul-terminated. + */ + #include <stdlib.h> #include <unistd.h> -#include <time.h> +#include <fcntl.h> +#include <utmp.h> #include "busybox.h" +/* Grr... utmp char[] members do not have to be nul-terminated. + * Do what we can while still keeping this reasonably small. + * Note: We are assuming the ut_id[] size is fixed at 4. */ + +#if __GNU_LIBRARY__ < 5 +#warning the format string needs to be changed +#else +#if (UT_LINESIZE != 32) || (UT_NAMESIZE != 32) || (UT_HOSTSIZE != 256) +#error struct utmp member char[] size(s) have changed! +#endif +#endif + extern int dutmp_main(int argc, char **argv) { - - int file; + int file = STDIN_FILENO; + ssize_t n; struct utmp ut; - if (argc<2) { - file = fileno(stdin); - } else if (*argv[1] == '-' ) { - show_usage(); - } else { - file = open(argv[1], O_RDONLY); - if (file < 0) { - error_msg_and_die(io_error, argv[1]); - } + if (argc > 2) { + bb_show_usage(); + } + ++argv; + if ((argc == 2) && ((argv[0][0] != '-') || argv[0][1])) { + file = bb_xopen(*argv, O_RDONLY); } -/* Kludge around the fact that the binary format for utmp has changed. */ + + while ((n = safe_read(file, (void*)&ut, sizeof(struct utmp))) != 0) { + + if (n != sizeof(struct utmp)) { + bb_perror_msg_and_die("short read"); + } + + /* Kludge around the fact that the binary format for utmp has changed. */ #if __GNU_LIBRARY__ < 5 - /* Linux libc5 */ - while (read(file, (void*)&ut, sizeof(struct utmp))) { - printf("%d|%d|%s|%s|%s|%s|%s|%lx\n", - ut.ut_type, ut.ut_pid, ut.ut_line, - ut.ut_id, ut.ut_user, ut.ut_host, - ctime(&(ut.ut_time)), - (long)ut.ut_addr); - } + /* Linux libc5 */ + + bb_printf("%d|%d|%s|%s|%s|%s|%s|%lx\n", + ut.ut_type, ut.ut_pid, ut.ut_line, + ut.ut_id, ut.ut_user, ut.ut_host, + ctime(&(ut.ut_time)), + (long)ut.ut_addr); #else - /* Glibc, uClibc, etc. */ - while (read(file, (void*)&ut, sizeof(struct utmp))) { - printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n", - ut.ut_type, ut.ut_pid, ut.ut_line, - ut.ut_id, ut.ut_user, ut.ut_host, - ut.ut_exit.e_termination, ut.ut_exit.e_exit, - ut.ut_session, - ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, - ut.ut_addr); - } + /* Glibc, uClibc, etc. */ + + bb_printf("%d|%d|%.32s|%.4s|%.32s|%.256s|%d|%d|%ld|%ld|%ld|%x\n", + ut.ut_type, ut.ut_pid, ut.ut_line, + ut.ut_id, ut.ut_user, ut.ut_host, + ut.ut_exit.e_termination, ut.ut_exit.e_exit, + ut.ut_session, + ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, + ut.ut_addr); #endif - return EXIT_SUCCESS; + } + + bb_fflush_stdout_and_exit(EXIT_SUCCESS); } diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index 67b28b534..308d651ae 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c @@ -22,7 +22,7 @@ int makedevs_main(int argc, char **argv) int major, Sminor, S, E; if (argc < 7 || *argv[1]=='-') - show_usage(); + bb_show_usage(); basedev = argv[1]; type = argv[2]; @@ -45,7 +45,7 @@ int makedevs_main(int argc, char **argv) mode |= S_IFIFO; break; default: - show_usage(); + bb_show_usage(); } while (S <= E) { @@ -53,12 +53,12 @@ int makedevs_main(int argc, char **argv) sz = snprintf(buf, sizeof(buf), "%s%d", basedev, S); if(sz<0 || sz>=sizeof(buf)) /* libc different */ - error_msg_and_die("%s too large", basedev); + bb_error_msg_and_die("%s too large", basedev); /* if mode != S_IFCHR and != S_IFBLK third param in mknod() ignored */ if (mknod(nodname, mode, major | Sminor)) - error_msg("Failed to create: %s", nodname); + bb_error_msg("Failed to create: %s", nodname); if (nodname == basedev) /* ex. /dev/hda - to /dev/hda1 ... */ nodname = buf; diff --git a/miscutils/mt.c b/miscutils/mt.c index 49dc70ac6..e79954552 100644 --- a/miscutils/mt.c +++ b/miscutils/mt.c @@ -59,12 +59,12 @@ extern int mt_main(int argc, char **argv) int fd, mode; if (argc < 2) { - show_usage(); + bb_show_usage(); } if (strcmp(argv[1], "-f") == 0) { if (argc < 4) { - show_usage(); + bb_show_usage(); } file = argv[2]; argv += 2; @@ -78,7 +78,7 @@ extern int mt_main(int argc, char **argv) } if (code->name == 0) { - error_msg("unrecognized opcode %s.", argv[1]); + bb_error_msg("unrecognized opcode %s.", argv[1]); return EXIT_FAILURE; } @@ -102,18 +102,18 @@ extern int mt_main(int argc, char **argv) } if ((fd = open(file, mode, 0)) < 0) - perror_msg_and_die("%s", file); + bb_perror_msg_and_die("%s", file); switch (code->value) { case MTTELL: if (ioctl(fd, MTIOCPOS, &position) < 0) - perror_msg_and_die("%s", file); + bb_perror_msg_and_die("%s", file); printf ("At block %d.\n", (int) position.mt_blkno); break; default: if (ioctl(fd, MTIOCTOP, &op) != 0) - perror_msg_and_die("%s", file); + bb_perror_msg_and_die("%s", file); break; } diff --git a/miscutils/strings.c b/miscutils/strings.c index 8d08b3f23..2413c3f2d 100644 --- a/miscutils/strings.c +++ b/miscutils/strings.c @@ -57,7 +57,7 @@ int strings_main(int argc, char **argv) n = bb_xgetlarg(optarg, 10, 1, LONG_MAX); break; default: - show_usage(); + bb_show_usage(); } argc -= optind; @@ -118,7 +118,7 @@ pipe: } else { - perror_msg("%s",argv[a]); + bb_perror_msg("%s",argv[a]); status=EXIT_FAILURE; } } diff --git a/miscutils/time.c b/miscutils/time.c index fa352a899..c30ef4311 100644 --- a/miscutils/time.c +++ b/miscutils/time.c @@ -141,7 +141,7 @@ static void fprintargv (FILE *fp, char *const *argv, const char *filler) fputs (*av, fp); } if (ferror (fp)) - error_msg_and_die("write error"); + bb_error_msg_and_die("write error"); } /* Return the number of kilobytes corresponding to a number of pages PAGES. @@ -416,12 +416,12 @@ static void summarize (FILE *fp, const char *fmt, char **command, resource_t *re } if (ferror (fp)) - error_msg_and_die("write error"); + bb_error_msg_and_die("write error"); } putc ('\n', fp); if (ferror (fp)) - error_msg_and_die("write error"); + bb_error_msg_and_die("write error"); } /* Run command CMD and return statistics on it. @@ -434,13 +434,13 @@ static void run_command (char *const *cmd, resource_t *resp) gettimeofday (&resp->start, (struct timezone *) 0); pid = fork (); /* Run CMD as child process. */ if (pid < 0) - error_msg_and_die("cannot fork"); + bb_error_msg_and_die("cannot fork"); else if (pid == 0) { /* If child. */ /* Don't cast execvp arguments; that causes errors on some systems, versus merely warnings if the cast is left off. */ execvp (cmd[0], cmd); - error_msg("cannot run %s", cmd[0]); + bb_error_msg("cannot run %s", cmd[0]); _exit (errno == ENOENT ? 127 : 126); } @@ -449,7 +449,7 @@ static void run_command (char *const *cmd, resource_t *resp) quit_signal = signal (SIGQUIT, SIG_IGN); if (resuse_end (pid, resp) == 0) - error_msg("error waiting for child process"); + bb_error_msg("error waiting for child process"); /* Re-enable signals. */ signal (SIGINT, interrupt_signal); @@ -477,7 +477,7 @@ extern int time_main (int argc, char **argv) output_format = posix_format; break; default: - show_usage(); + bb_show_usage(); } argc--; argv++; @@ -486,7 +486,7 @@ extern int time_main (int argc, char **argv) } if (argv == NULL || *argv == NULL) - show_usage(); + bb_show_usage(); run_command (argv, &res); summarize (stdout, output_format, argv, &res); diff --git a/miscutils/update.c b/miscutils/update.c index 27a04ddee..48ea02deb 100644 --- a/miscutils/update.c +++ b/miscutils/update.c @@ -62,12 +62,12 @@ extern int update_main(int argc, char **argv) flush_duration = atoi(optarg); break; default: - show_usage(); + bb_show_usage(); } } if (daemon(0, 1) < 0) - perror_msg_and_die("daemon"); + bb_perror_msg_and_die("daemon"); #ifdef OPEN_MAX for (pid = 0; pid < OPEN_MAX; pid++) close(pid); diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index f0b0ebd0e..cfe19abc3 100644 --- a/miscutils/watchdog.c +++ b/miscutils/watchdog.c @@ -33,11 +33,11 @@ extern int watchdog_main(int argc, char **argv) int fd; if (argc != 2) { - show_usage(); + bb_show_usage(); } if ((fd=open(argv[1], O_WRONLY)) == -1) { - perror_msg_and_die(argv[1]); + bb_perror_msg_and_die(argv[1]); } while (1) { |