diff options
author | Matt Kraai <kraai@debian.org> | 2000-12-22 04:48:07 +0300 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2000-12-22 04:48:07 +0300 |
commit | a9819b290848e0a760f3805d5937fa050235d707 (patch) | |
tree | b8cb8d939032c0806d62161b01e5836cb808dc3f | |
parent | e9f07fb6e83b75a50760599a5d31f494841eddf7 (diff) |
Use busybox error handling functions wherever possible.
-rw-r--r-- | archival/gzip.c | 27 | ||||
-rw-r--r-- | console-tools/deallocvt.c | 12 | ||||
-rw-r--r-- | console-tools/loadacm.c | 47 | ||||
-rw-r--r-- | coreutils/mkfifo.c | 6 | ||||
-rw-r--r-- | coreutils/mknod.c | 2 | ||||
-rw-r--r-- | coreutils/sleep.c | 6 | ||||
-rw-r--r-- | coreutils/uname.c | 4 | ||||
-rw-r--r-- | deallocvt.c | 12 | ||||
-rw-r--r-- | dmesg.c | 15 | ||||
-rw-r--r-- | editors/sed.c | 6 | ||||
-rw-r--r-- | fbset.c | 10 | ||||
-rw-r--r-- | fdflush.c | 18 | ||||
-rw-r--r-- | findutils/xargs.c | 6 | ||||
-rw-r--r-- | gzip.c | 27 | ||||
-rw-r--r-- | hostname.c | 13 | ||||
-rw-r--r-- | insmod.c | 10 | ||||
-rw-r--r-- | lash.c | 10 | ||||
-rw-r--r-- | loadacm.c | 47 | ||||
-rw-r--r-- | miscutils/mt.c | 12 | ||||
-rw-r--r-- | mkfifo.c | 6 | ||||
-rw-r--r-- | mkfs_minix.c | 7 | ||||
-rw-r--r-- | mknod.c | 2 | ||||
-rw-r--r-- | mkswap.c | 13 | ||||
-rw-r--r-- | modutils/insmod.c | 10 | ||||
-rw-r--r-- | modutils/rmmod.c | 8 | ||||
-rw-r--r-- | mount.c | 2 | ||||
-rw-r--r-- | mt.c | 12 | ||||
-rw-r--r-- | mtab.c | 6 | ||||
-rw-r--r-- | networking/hostname.c | 13 | ||||
-rw-r--r-- | networking/ping.c | 30 | ||||
-rw-r--r-- | ping.c | 30 | ||||
-rw-r--r-- | rmmod.c | 8 | ||||
-rw-r--r-- | rpmunpack.c | 39 | ||||
-rw-r--r-- | sed.c | 6 | ||||
-rw-r--r-- | sh.c | 10 | ||||
-rw-r--r-- | shell/lash.c | 10 | ||||
-rw-r--r-- | sleep.c | 6 | ||||
-rw-r--r-- | swaponoff.c | 12 | ||||
-rw-r--r-- | umount.c | 5 | ||||
-rw-r--r-- | uname.c | 4 | ||||
-rw-r--r-- | util-linux/dmesg.c | 15 | ||||
-rw-r--r-- | util-linux/fbset.c | 10 | ||||
-rw-r--r-- | util-linux/fdflush.c | 18 | ||||
-rw-r--r-- | util-linux/mkfs_minix.c | 7 | ||||
-rw-r--r-- | util-linux/mkswap.c | 13 | ||||
-rw-r--r-- | util-linux/mount.c | 2 | ||||
-rw-r--r-- | util-linux/swaponoff.c | 12 | ||||
-rw-r--r-- | util-linux/umount.c | 5 | ||||
-rw-r--r-- | utility.c | 52 | ||||
-rw-r--r-- | xargs.c | 6 |
50 files changed, 244 insertions, 425 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index ca0c177d4..09260929e 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -1867,18 +1867,13 @@ int gzip_main(int argc, char **argv) usage(gzip_usage); strncpy(ifname, *argv, MAX_PATH_LEN); - /* Open input fille */ + /* Open input file */ inFileNum = open(ifname, O_RDONLY); - if (inFileNum < 0) { - perror(ifname); - exit(WARNING); - } + if (inFileNum < 0) + perror_msg_and_die("%s", ifname); /* Get the time stamp on the input file. */ - result = stat(ifname, &statBuf); - if (result < 0) { - perror(ifname); - exit(WARNING); - } + if (stat(ifname, &statBuf) < 0) + perror_msg_and_die("%s", ifname); time_stamp = statBuf.st_ctime; ifile_size = statBuf.st_size; } @@ -1909,10 +1904,8 @@ int gzip_main(int argc, char **argv) #else outFileNum = open(ofname, O_RDWR | O_CREAT | O_EXCL); #endif - if (outFileNum < 0) { - perror(ofname); - exit(WARNING); - } + if (outFileNum < 0) + perror_msg_and_die("%s", ofname); SET_BINARY_MODE(outFileNum); /* Set permissions on the file */ fchmod(outFileNum, statBuf.st_mode); @@ -1930,10 +1923,8 @@ int gzip_main(int argc, char **argv) else delFileName = ofname; - if (unlink(delFileName) < 0) { - perror(delFileName); - exit(EXIT_FAILURE); - } + if (unlink(delFileName) < 0) + perror_msg_and_die("%s", delFileName); } return(exit_code); diff --git a/console-tools/deallocvt.c b/console-tools/deallocvt.c index b128c3fae..3dd90c0e9 100644 --- a/console-tools/deallocvt.c +++ b/console-tools/deallocvt.c @@ -25,10 +25,8 @@ int deallocvt_main(int argc, char *argv[]) if (argc == 1) { /* deallocate all unused consoles */ - if (ioctl(fd, VT_DISALLOCATE, 0)) { - perror("VT_DISALLOCATE"); - return EXIT_FAILURE; - } + if (ioctl(fd, VT_DISALLOCATE, 0)) + perror_msg_and_die("VT_DISALLOCATE"); } else { for (i = 1; i < argc; i++) { num = atoi(argv[i]); @@ -36,10 +34,8 @@ int deallocvt_main(int argc, char *argv[]) error_msg("0: illegal VT number\n"); else if (num == 1) error_msg("VT 1 cannot be deallocated\n"); - else if (ioctl(fd, VT_DISALLOCATE, num)) { - perror("VT_DISALLOCATE"); - error_msg_and_die("could not deallocate console %d\n", num); - } + else if (ioctl(fd, VT_DISALLOCATE, num)) + perror_msg_and_die("VT_DISALLOCATE"); } } diff --git a/console-tools/loadacm.c b/console-tools/loadacm.c index 52702bf6d..040062cf8 100644 --- a/console-tools/loadacm.c +++ b/console-tools/loadacm.c @@ -60,7 +60,7 @@ int screen_map_load(int fd, FILE * fp) int is_unicode; if (fstat(fileno(fp), &stbuf)) - perror("Cannot stat map file"), exit(1); + perror_msg_and_die("Cannot stat map file"); /* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */ if (! @@ -70,15 +70,13 @@ int screen_map_load(int fd, FILE * fp) if (parse_failed) { if (-1 == fseek(fp, 0, SEEK_SET)) { if (errno == ESPIPE) - error_msg("16bit screen-map MUST be a regular file.\n"), - exit(1); + error_msg_and_die("16bit screen-map MUST be a regular file.\n"); else - perror("fseek failed reading binary 16bit screen-map"), - exit(1); + perror_msg_and_die("fseek failed reading binary 16bit screen-map"); } if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) - perror("Cannot read [new] map from file"), exit(1); + perror_msg_and_die("Cannot read [new] map from file"); #if 0 else error_msg("Input screen-map is binary.\n"); @@ -89,7 +87,7 @@ int screen_map_load(int fd, FILE * fp) /* same if it was binary, ie. if parse_failed */ if (parse_failed || is_unicode) { if (ioctl(fd, PIO_UNISCRNMAP, wbuf)) - perror("PIO_UNISCRNMAP ioctl"), exit(1); + perror_msg_and_die("PIO_UNISCRNMAP ioctl"); else return 0; } @@ -101,7 +99,7 @@ int screen_map_load(int fd, FILE * fp) error_msg("Assuming 8bit screen-map - MUST be a regular file.\n"), exit(1); else - perror("fseek failed assuming 8bit screen-map"), exit(1); + perror_msg_and_die("fseek failed assuming 8bit screen-map"); } /* ... and try an old 8-bit screen-map */ @@ -111,14 +109,13 @@ int screen_map_load(int fd, FILE * fp) if (-1 == fseek(fp, 0, SEEK_SET)) { if (errno == ESPIPE) /* should not - it succedeed above */ - error_msg("fseek() returned ESPIPE !\n"), - exit(1); + error_msg_and_die("fseek() returned ESPIPE !\n"); else - perror("fseek for binary 8bit screen-map"), exit(1); + perror_msg_and_die("fseek for binary 8bit screen-map"); } if (fread(buf, E_TABSZ, 1, fp) != 1) - perror("Cannot read [old] map from file"), exit(1); + perror_msg_and_die("Cannot read [old] map from file"); #if 0 else error_msg("Input screen-map is binary.\n"); @@ -126,7 +123,7 @@ int screen_map_load(int fd, FILE * fp) } if (ioctl(fd, PIO_SCRNMAP, buf)) - perror("PIO_SCRNMAP ioctl"), exit(1); + perror_msg_and_die("PIO_SCRNMAP ioctl"); else return 0; } @@ -174,10 +171,8 @@ int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode) if (NULL == fgets(buffer, sizeof(buffer), fp)) { if (feof(fp)) break; - else { - perror("uni_screen_map_read_ascii() can't read line"); - exit(2); - } + else + perror_msg_and_die("uni_screen_map_read_ascii() can't read line"); } /* get "charset-relative charcode", stripping leading spaces */ @@ -317,12 +312,11 @@ void saveoldmap(int fd, char *omfil) int is_old_map = 0; if (ioctl(fd, GIO_UNISCRNMAP, xbuf)) { - perror("GIO_UNISCRNMAP ioctl error"); + perror_msg("GIO_UNISCRNMAP ioctl error"); #endif - if (ioctl(fd, GIO_SCRNMAP, buf)) { - perror("GIO_SCRNMAP ioctl error"); - exit(1); - } else + if (ioctl(fd, GIO_SCRNMAP, buf)) + perror_msg_and_die("GIO_SCRNMAP ioctl error"); + else is_old_map = 1; #ifdef GIO_UNISCRNMAP } @@ -332,14 +326,11 @@ void saveoldmap(int fd, char *omfil) #ifdef GIO_UNISCRNMAP if (is_old_map) { #endif - if (fwrite(buf, E_TABSZ, 1, fp) != 1) { - perror("Error writing map to file"); - exit(1); - } + if (fwrite(buf, E_TABSZ, 1, fp) != 1) + perror_msg_and_die("Error writing map to file"); #ifdef GIO_UNISCRNMAP } else if (fwrite(xbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) { - perror("Error writing map to file"); - exit(1); + perror_msg_and_die("Error writing map to file"); } #endif diff --git a/coreutils/mkfifo.c b/coreutils/mkfifo.c index ef4a5256f..728e1ec2f 100644 --- a/coreutils/mkfifo.c +++ b/coreutils/mkfifo.c @@ -53,9 +53,7 @@ extern int mkfifo_main(int argc, char **argv) } if (argc < 1 || *argv[0] == '-') usage(mkfifo_usage); - if (mkfifo(*argv, mode) < 0) { - perror("mkfifo"); - return EXIT_FAILURE; - } + if (mkfifo(*argv, mode) < 0) + perror_msg_and_die("mkfifo"); return EXIT_SUCCESS; } diff --git a/coreutils/mknod.c b/coreutils/mknod.c index 022ab8571..4d8c598ea 100644 --- a/coreutils/mknod.c +++ b/coreutils/mknod.c @@ -84,7 +84,7 @@ int mknod_main(int argc, char **argv) mode |= perm; if (mknod(argv[0], mode, dev) != 0) - error_msg_and_die("%s: %s\n", argv[0], strerror(errno)); + perror_msg_and_die("%s", argv[0]); return EXIT_SUCCESS; } diff --git a/coreutils/sleep.c b/coreutils/sleep.c index ad92b106d..10eca593e 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c @@ -30,9 +30,7 @@ extern int sleep_main(int argc, char **argv) usage(sleep_usage); } - if (sleep(atoi(*(++argv))) != 0) { - perror("sleep"); - return EXIT_FAILURE; - } + if (sleep(atoi(*(++argv))) != 0) + perror_msg_and_die("sleep"); return EXIT_SUCCESS; } diff --git a/coreutils/uname.c b/coreutils/uname.c index 2781b80b3..e7e9ff331 100644 --- a/coreutils/uname.c +++ b/coreutils/uname.c @@ -114,11 +114,11 @@ int uname_main(int argc, char **argv) toprint = PRINT_SYSNAME; if (uname(&name) == -1) - perror("cannot get system name"); + perror_msg("cannot get system name"); #if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE) if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1) - perror("cannot get processor type"); + perror_msg("cannot get processor type"); } #else diff --git a/deallocvt.c b/deallocvt.c index b128c3fae..3dd90c0e9 100644 --- a/deallocvt.c +++ b/deallocvt.c @@ -25,10 +25,8 @@ int deallocvt_main(int argc, char *argv[]) if (argc == 1) { /* deallocate all unused consoles */ - if (ioctl(fd, VT_DISALLOCATE, 0)) { - perror("VT_DISALLOCATE"); - return EXIT_FAILURE; - } + if (ioctl(fd, VT_DISALLOCATE, 0)) + perror_msg_and_die("VT_DISALLOCATE"); } else { for (i = 1; i < argc; i++) { num = atoi(argv[i]); @@ -36,10 +34,8 @@ int deallocvt_main(int argc, char *argv[]) error_msg("0: illegal VT number\n"); else if (num == 1) error_msg("VT 1 cannot be deallocated\n"); - else if (ioctl(fd, VT_DISALLOCATE, num)) { - perror("VT_DISALLOCATE"); - error_msg_and_die("could not deallocate console %d\n", num); - } + else if (ioctl(fd, VT_DISALLOCATE, num)) + perror_msg_and_die("VT_DISALLOCATE"); } } @@ -69,20 +69,16 @@ int dmesg_main(int argc, char **argv) } if (cmd == 8) { - n = klogctl(cmd, NULL, level); - if (n < 0) { - goto klogctl_error; - } + if (klogctl(cmd, NULL, level) < 0) + perror_msg_and_die("klogctl"); return EXIT_SUCCESS; } if (bufsize < 4096) bufsize = 4096; buf = (char *) xmalloc(bufsize); - n = klogctl(cmd, buf, bufsize); - if (n < 0) { - goto klogctl_error; - } + if ((n = klogctl(cmd, buf, bufsize)) < 0) + perror_msg_and_die("klogctl"); lastc = '\n'; for (i = 0; i < n; i++) { @@ -102,7 +98,4 @@ int dmesg_main(int argc, char **argv) end: usage(dmesg_usage); return EXIT_FAILURE; - klogctl_error: - perror("klogctl"); - return EXIT_FAILURE; } diff --git a/editors/sed.c b/editors/sed.c index a7152e52a..341924d6b 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -709,10 +709,8 @@ extern int sed_main(int argc, char **argv) #ifdef BB_FEATURE_CLEAN_UP /* destroy command strings on exit */ - if (atexit(destroy_cmd_strs) == -1) { - perror("sed"); - exit(1); - } + if (atexit(destroy_cmd_strs) == -1) + perror_msg_and_die("atexit"); #endif /* do normal option parsing */ @@ -33,8 +33,6 @@ #include <ctype.h> #include <sys/ioctl.h> -#define PERROR(ctx) do { perror(ctx); exit(1); } while(0) - #define DEFAULTFBDEV "/dev/fb0" #define DEFAULTFBMODE "/etc/fb.modes" @@ -198,7 +196,7 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn, char *p = buf; if ((f = fopen(fn, "r")) == NULL) - PERROR("readmode(fopen)"); + perror_msg_and_die("readmode(fopen)"); while (!feof(f)) { fgets(buf, sizeof(buf), f); if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) { @@ -428,9 +426,9 @@ extern int fbset_main(int argc, char **argv) } if ((fh = open(fbdev, O_RDONLY)) < 0) - PERROR("fbset(open)"); + perror_msg_and_die("fbset(open)"); if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) - PERROR("fbset(ioctl)"); + perror_msg_and_die("fbset(ioctl)"); if (g_options & OPT_READMODE) { if (!readmode(&var, modefile, mode)) { error_msg("Unknown video mode `%s'\n", mode); @@ -441,7 +439,7 @@ extern int fbset_main(int argc, char **argv) setmode(&var, &varset); if (g_options & OPT_CHANGE) if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) - PERROR("fbset(ioctl)"); + perror_msg_and_die("fbset(ioctl)"); showmode(&var); /* Don't close the file, as exiting will take care of that */ /* close(fh); */ @@ -31,26 +31,16 @@ extern int fdflush_main(int argc, char **argv) { - int value; int fd; if (argc <= 1 || **(++argv) == '-') usage(fdflush_usage); - fd = open(*argv, 0); - if (fd < 0) { - perror(*argv); - return EXIT_FAILURE; - } + if ((fd = open(*argv, 0)) < 0) + perror_msg_and_die("%s", *argv); - value = ioctl(fd, FDFLUSH, 0); - /* Don't bother closing. Exit does - * that, so we can save a few bytes */ - /* close(fd); */ + if (ioctl(fd, FDFLUSH, 0)) + perror_msg_and_die("%s", *argv); - if (value) { - perror(*argv); - return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/findutils/xargs.c b/findutils/xargs.c index c5f7b208c..ddfbe9230 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c @@ -81,10 +81,8 @@ int xargs_main(int argc, char **argv) strcat(execstr, cmd_to_be_executed); strcat(execstr, file_to_act_on); cmd_output = popen(execstr, "r"); - if (cmd_output == NULL) { - perror("popen"); - exit(1); - } + if (cmd_output == NULL) + perror_msg_and_die("popen"); /* harvest the output */ while ((output_line = get_line_from_file(cmd_output)) != NULL) { @@ -1867,18 +1867,13 @@ int gzip_main(int argc, char **argv) usage(gzip_usage); strncpy(ifname, *argv, MAX_PATH_LEN); - /* Open input fille */ + /* Open input file */ inFileNum = open(ifname, O_RDONLY); - if (inFileNum < 0) { - perror(ifname); - exit(WARNING); - } + if (inFileNum < 0) + perror_msg_and_die("%s", ifname); /* Get the time stamp on the input file. */ - result = stat(ifname, &statBuf); - if (result < 0) { - perror(ifname); - exit(WARNING); - } + if (stat(ifname, &statBuf) < 0) + perror_msg_and_die("%s", ifname); time_stamp = statBuf.st_ctime; ifile_size = statBuf.st_size; } @@ -1909,10 +1904,8 @@ int gzip_main(int argc, char **argv) #else outFileNum = open(ofname, O_RDWR | O_CREAT | O_EXCL); #endif - if (outFileNum < 0) { - perror(ofname); - exit(WARNING); - } + if (outFileNum < 0) + perror_msg_and_die("%s", ofname); SET_BINARY_MODE(outFileNum); /* Set permissions on the file */ fchmod(outFileNum, statBuf.st_mode); @@ -1930,10 +1923,8 @@ int gzip_main(int argc, char **argv) else delFileName = ofname; - if (unlink(delFileName) < 0) { - perror(delFileName); - exit(EXIT_FAILURE); - } + if (unlink(delFileName) < 0) + perror_msg_and_die("%s", delFileName); } return(exit_code); diff --git a/hostname.c b/hostname.c index 13e52c41d..c64d1602b 100644 --- a/hostname.c +++ b/hostname.c @@ -1,6 +1,6 @@ /* vi: set sw=4 ts=4: */ /* - * $Id: hostname.c,v 1.16 2000/12/07 19:56:48 markw Exp $ + * $Id: hostname.c,v 1.17 2000/12/22 01:48:07 kraai Exp $ * Mini hostname implementation for busybox * * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> @@ -40,10 +40,9 @@ void do_sethostname(char *s, int isfile) if (!isfile) { if (sethostname(s, strlen(s)) < 0) { if (errno == EPERM) - error_msg("you must be root to change the hostname\n"); + error_msg_and_die("you must be root to change the hostname\n"); else - perror("sethostname"); - exit(1); + perror_msg_and_die("sethostname"); } } else { f = xfopen(s, "r"); @@ -51,10 +50,8 @@ void do_sethostname(char *s, int isfile) fclose(f); if (buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = 0; - if (sethostname(buf, strlen(buf)) < 0) { - perror("sethostname"); - exit(1); - } + if (sethostname(buf, strlen(buf)) < 0) + perror_msg_and_die("sethostname"); } } @@ -78,7 +78,7 @@ #ifndef MODUTILS_MODULE_H #define MODUTILS_MODULE_H 1 -#ident "$Id: insmod.c,v 1.33 2000/12/18 03:57:16 kraai Exp $" +#ident "$Id: insmod.c,v 1.34 2000/12/22 01:48:07 kraai Exp $" /* This file contains the structures used by the 2.0 and 2.1 kernels. We do not use the kernel headers directly because we do not wish @@ -284,7 +284,7 @@ int delete_module(const char *); #ifndef MODUTILS_OBJ_H #define MODUTILS_OBJ_H 1 -#ident "$Id: insmod.c,v 1.33 2000/12/18 03:57:16 kraai Exp $" +#ident "$Id: insmod.c,v 1.34 2000/12/22 01:48:07 kraai Exp $" /* The relocatable object is manipulated using elfin types. */ @@ -2952,10 +2952,8 @@ extern int insmod_main( int argc, char **argv) memcpy(m_filename, *argv, strlen(*argv)); - if ((f = obj_load(fp)) == NULL) { - perror("Could not load the module\n"); - return EXIT_FAILURE; - } + if ((f = obj_load(fp)) == NULL) + perror_msg_and_die("Could not load the module"); if (get_modinfo_value(f, "kernel_version") == NULL) m_has_modinfo = 0; @@ -344,7 +344,7 @@ static int builtin_fg_bg(struct child_prog *child) /* Make this job the foreground job */ /* suppress messages when run from /linuxrc mag@sysgo.de */ if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY) - perror("tcsetpgrp"); + perror_msg("tcsetpgrp"); child->family->job_list->fg = job; } @@ -683,7 +683,7 @@ static void checkjobs(struct jobset *job_list) } if (childpid == -1 && errno != ECHILD) - perror("waitpid"); + perror_msg("waitpid"); } /* squirrel != NULL means we squirrel away copies of stdin, stdout, @@ -1422,7 +1422,7 @@ static void insert_job(struct job *newjob, int inbg) /* move the new process group into the foreground */ /* suppress messages when run from /linuxrc mag@sysgo.de */ if (tcsetpgrp(0, newjob->pgrp) && errno != ENOTTY) - perror("tcsetpgrp"); + perror_msg("tcsetpgrp"); } } @@ -1612,7 +1612,7 @@ static int busy_loop(FILE * input) /* move the shell to the foreground */ /* suppress messages when run from /linuxrc mag@sysgo.de */ if (tcsetpgrp(0, getpid()) && errno != ENOTTY) - perror("tcsetpgrp"); + perror_msg("tcsetpgrp"); } } } @@ -1620,7 +1620,7 @@ static int busy_loop(FILE * input) /* return controlling TTY back to parent process group before exiting */ if (tcsetpgrp(0, parent_pgrp)) - perror("tcsetpgrp"); + perror_msg("tcsetpgrp"); /* return exit status if called with "-c" */ if (input == NULL && WIFEXITED(status)) @@ -60,7 +60,7 @@ int screen_map_load(int fd, FILE * fp) int is_unicode; if (fstat(fileno(fp), &stbuf)) - perror("Cannot stat map file"), exit(1); + perror_msg_and_die("Cannot stat map file"); /* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */ if (! @@ -70,15 +70,13 @@ int screen_map_load(int fd, FILE * fp) if (parse_failed) { if (-1 == fseek(fp, 0, SEEK_SET)) { if (errno == ESPIPE) - error_msg("16bit screen-map MUST be a regular file.\n"), - exit(1); + error_msg_and_die("16bit screen-map MUST be a regular file.\n"); else - perror("fseek failed reading binary 16bit screen-map"), - exit(1); + perror_msg_and_die("fseek failed reading binary 16bit screen-map"); } if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) - perror("Cannot read [new] map from file"), exit(1); + perror_msg_and_die("Cannot read [new] map from file"); #if 0 else error_msg("Input screen-map is binary.\n"); @@ -89,7 +87,7 @@ int screen_map_load(int fd, FILE * fp) /* same if it was binary, ie. if parse_failed */ if (parse_failed || is_unicode) { if (ioctl(fd, PIO_UNISCRNMAP, wbuf)) - perror("PIO_UNISCRNMAP ioctl"), exit(1); + perror_msg_and_die("PIO_UNISCRNMAP ioctl"); else return 0; } @@ -101,7 +99,7 @@ int screen_map_load(int fd, FILE * fp) error_msg("Assuming 8bit screen-map - MUST be a regular file.\n"), exit(1); else - perror("fseek failed assuming 8bit screen-map"), exit(1); + perror_msg_and_die("fseek failed assuming 8bit screen-map"); } /* ... and try an old 8-bit screen-map */ @@ -111,14 +109,13 @@ int screen_map_load(int fd, FILE * fp) if (-1 == fseek(fp, 0, SEEK_SET)) { if (errno == ESPIPE) /* should not - it succedeed above */ - error_msg("fseek() returned ESPIPE !\n"), - exit(1); + error_msg_and_die("fseek() returned ESPIPE !\n"); else - perror("fseek for binary 8bit screen-map"), exit(1); + perror_msg_and_die("fseek for binary 8bit screen-map"); } if (fread(buf, E_TABSZ, 1, fp) != 1) - perror("Cannot read [old] map from file"), exit(1); + perror_msg_and_die("Cannot read [old] map from file"); #if 0 else error_msg("Input screen-map is binary.\n"); @@ -126,7 +123,7 @@ int screen_map_load(int fd, FILE * fp) } if (ioctl(fd, PIO_SCRNMAP, buf)) - perror("PIO_SCRNMAP ioctl"), exit(1); + perror_msg_and_die("PIO_SCRNMAP ioctl"); else return 0; } @@ -174,10 +171,8 @@ int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode) if (NULL == fgets(buffer, sizeof(buffer), fp)) { if (feof(fp)) break; - else { - perror("uni_screen_map_read_ascii() can't read line"); - exit(2); - } + else + perror_msg_and_die("uni_screen_map_read_ascii() can't read line"); } /* get "charset-relative charcode", stripping leading spaces */ @@ -317,12 +312,11 @@ void saveoldmap(int fd, char *omfil) int is_old_map = 0; if (ioctl(fd, GIO_UNISCRNMAP, xbuf)) { - perror("GIO_UNISCRNMAP ioctl error"); + perror_msg("GIO_UNISCRNMAP ioctl error"); #endif - if (ioctl(fd, GIO_SCRNMAP, buf)) { - perror("GIO_SCRNMAP ioctl error"); - exit(1); - } else + if (ioctl(fd, GIO_SCRNMAP, buf)) + perror_msg_and_die("GIO_SCRNMAP ioctl error"); + else is_old_map = 1; #ifdef GIO_UNISCRNMAP } @@ -332,14 +326,11 @@ void saveoldmap(int fd, char *omfil) #ifdef GIO_UNISCRNMAP if (is_old_map) { #endif - if (fwrite(buf, E_TABSZ, 1, fp) != 1) { - perror("Error writing map to file"); - exit(1); - } + if (fwrite(buf, E_TABSZ, 1, fp) != 1) + perror_msg_and_die("Error writing map to file"); #ifdef GIO_UNISCRNMAP } else if (fwrite(xbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) { - perror("Error writing map to file"); - exit(1); + perror_msg_and_die("Error writing map to file"); } #endif diff --git a/miscutils/mt.c b/miscutils/mt.c index 2d35c7c22..70d03cca4 100644 --- a/miscutils/mt.c +++ b/miscutils/mt.c @@ -85,15 +85,11 @@ extern int mt_main(int argc, char **argv) else op.mt_count = 1; /* One, not zero, right? */ - if ((fd = open(file, O_RDONLY, 0)) < 0) { - perror(file); - return EXIT_FAILURE; - } + if ((fd = open(file, O_RDONLY, 0)) < 0) + perror_msg_and_die("%s", file); - if (ioctl(fd, MTIOCTOP, &op) != 0) { - perror(file); - return EXIT_FAILURE; - } + if (ioctl(fd, MTIOCTOP, &op) != 0) + perror_msg_and_die("%s", file); return EXIT_SUCCESS; } @@ -53,9 +53,7 @@ extern int mkfifo_main(int argc, char **argv) } if (argc < 1 || *argv[0] == '-') usage(mkfifo_usage); - if (mkfifo(*argv, mode) < 0) { - perror("mkfifo"); - return EXIT_FAILURE; - } + if (mkfifo(*argv, mode) < 0) + perror_msg_and_die("mkfifo"); return EXIT_SUCCESS; } diff --git a/mkfs_minix.c b/mkfs_minix.c index 95815fd4d..e1ede6caa 100644 --- a/mkfs_minix.c +++ b/mkfs_minix.c @@ -329,11 +329,8 @@ static int get_size(const char *file) int fd; long size; - fd = open(file, O_RDWR); - if (fd < 0) { - perror(file); - exit(1); - } + if ((fd = open(file, O_RDWR)) < 0) + perror_msg_and_die("%s", file); if (ioctl(fd, BLKGETSIZE, &size) >= 0) { close(fd); return (size * 512); @@ -84,7 +84,7 @@ int mknod_main(int argc, char **argv) mode |= perm; if (mknod(argv[0], mode, dev) != 0) - error_msg_and_die("%s: %s\n", argv[0], strerror(errno)); + perror_msg_and_die("%s", argv[0]); return EXIT_SUCCESS; } @@ -260,11 +260,8 @@ static long get_size(const char *file) int fd; long size; - fd = open(file, O_RDONLY); - if (fd < 0) { - perror(file); - exit(1); - } + if ((fd = open(file, O_RDONLY)) < 0) + perror_msg_and_die("%s", file); if (ioctl(fd, BLKGETSIZE, &size) >= 0) { int sectors_per_page = pagesize / 512; @@ -367,10 +364,8 @@ int mkswap_main(int argc, char **argv) } DEV = open(device_name, O_RDWR); - if (DEV < 0 || fstat(DEV, &statbuf) < 0) { - perror(device_name); - return EXIT_FAILURE; - } + if (DEV < 0 || fstat(DEV, &statbuf) < 0) + perror_msg_and_die("%s", device_name); if (!S_ISBLK(statbuf.st_mode)) check = 0; else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) diff --git a/modutils/insmod.c b/modutils/insmod.c index cbe00c2b4..7391b4fb2 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c @@ -78,7 +78,7 @@ #ifndef MODUTILS_MODULE_H #define MODUTILS_MODULE_H 1 -#ident "$Id: insmod.c,v 1.33 2000/12/18 03:57:16 kraai Exp $" +#ident "$Id: insmod.c,v 1.34 2000/12/22 01:48:07 kraai Exp $" /* This file contains the structures used by the 2.0 and 2.1 kernels. We do not use the kernel headers directly because we do not wish @@ -284,7 +284,7 @@ int delete_module(const char *); #ifndef MODUTILS_OBJ_H #define MODUTILS_OBJ_H 1 -#ident "$Id: insmod.c,v 1.33 2000/12/18 03:57:16 kraai Exp $" +#ident "$Id: insmod.c,v 1.34 2000/12/22 01:48:07 kraai Exp $" /* The relocatable object is manipulated using elfin types. */ @@ -2952,10 +2952,8 @@ extern int insmod_main( int argc, char **argv) memcpy(m_filename, *argv, strlen(*argv)); - if ((f = obj_load(fp)) == NULL) { - perror("Could not load the module\n"); - return EXIT_FAILURE; - } + if ((f = obj_load(fp)) == NULL) + perror_msg_and_die("Could not load the module"); if (get_modinfo_value(f, "kernel_version") == NULL) m_has_modinfo = 0; diff --git a/modutils/rmmod.c b/modutils/rmmod.c index f5d7d359a..52adc7bcd 100644 --- a/modutils/rmmod.c +++ b/modutils/rmmod.c @@ -45,10 +45,8 @@ extern int rmmod_main(int argc, char **argv) switch (**argv) { case 'a': /* Unload _all_ unused modules via NULL delete_module() call */ - if (delete_module(NULL)) { - perror("rmmod"); - return EXIT_FAILURE; - } + if (delete_module(NULL)) + perror_msg_and_die("rmmod"); return EXIT_SUCCESS; default: usage(rmmod_usage); @@ -58,7 +56,7 @@ extern int rmmod_main(int argc, char **argv) while (argc-- > 0) { if (delete_module(*argv) < 0) { - perror(*argv); + perror_msg("%s", *argv); ret = EXIT_FAILURE; } argv++; @@ -383,7 +383,7 @@ extern int mount_main(int argc, char **argv) } endmntent(mountTable); } else { - perror(mtab_file); + perror_msg_and_die("%s", mtab_file); } return EXIT_SUCCESS; } @@ -85,15 +85,11 @@ extern int mt_main(int argc, char **argv) else op.mt_count = 1; /* One, not zero, right? */ - if ((fd = open(file, O_RDONLY, 0)) < 0) { - perror(file); - return EXIT_FAILURE; - } + if ((fd = open(file, O_RDONLY, 0)) < 0) + perror_msg_and_die("%s", file); - if (ioctl(fd, MTIOCTOP, &op) != 0) { - perror(file); - return EXIT_FAILURE; - } + if (ioctl(fd, MTIOCTOP, &op) != 0) + perror_msg_and_die("%s", file); return EXIT_SUCCESS; } @@ -27,7 +27,7 @@ void erase_mtab(const char *name) /* Bummer. fall back on trying the /proc filesystem */ && (mountTable = setmntent("/proc/mounts", "r")) == 0) { #endif - perror(mtab_file); + perror_msg("%s", mtab_file); return; } @@ -55,7 +55,7 @@ void erase_mtab(const char *name) } endmntent(mountTable); } else if (errno != EROFS) - perror(mtab_file); + perror_msg("%s", mtab_file); } void write_mtab(char *blockDevice, char *directory, @@ -65,7 +65,7 @@ void write_mtab(char *blockDevice, char *directory, struct mntent m; if (mountTable == 0) { - perror(mtab_file); + perror_msg("%s", mtab_file); return; } if (mountTable) { diff --git a/networking/hostname.c b/networking/hostname.c index 13e52c41d..c64d1602b 100644 --- a/networking/hostname.c +++ b/networking/hostname.c @@ -1,6 +1,6 @@ /* vi: set sw=4 ts=4: */ /* - * $Id: hostname.c,v 1.16 2000/12/07 19:56:48 markw Exp $ + * $Id: hostname.c,v 1.17 2000/12/22 01:48:07 kraai Exp $ * Mini hostname implementation for busybox * * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> @@ -40,10 +40,9 @@ void do_sethostname(char *s, int isfile) if (!isfile) { if (sethostname(s, strlen(s)) < 0) { if (errno == EPERM) - error_msg("you must be root to change the hostname\n"); + error_msg_and_die("you must be root to change the hostname\n"); else - perror("sethostname"); - exit(1); + perror_msg_and_die("sethostname"); } } else { f = xfopen(s, "r"); @@ -51,10 +50,8 @@ void do_sethostname(char *s, int isfile) fclose(f); if (buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = 0; - if (sethostname(buf, strlen(buf)) < 0) { - perror("sethostname"); - exit(1); - } + if (sethostname(buf, strlen(buf)) < 0) + perror_msg_and_die("sethostname"); } } diff --git a/networking/ping.c b/networking/ping.c index 4be2120c8..e9242e9b7 100644 --- a/networking/ping.c +++ b/networking/ping.c @@ -1,6 +1,6 @@ /* vi: set sw=4 ts=4: */ /* - * $Id: ping.c,v 1.29 2000/12/18 03:57:16 kraai Exp $ + * $Id: ping.c,v 1.30 2000/12/22 01:48:07 kraai Exp $ * Mini ping implementation for busybox * * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> @@ -190,10 +190,8 @@ static void ping(const char *host) int pingsock, c; char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; - if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) { /* 1 == ICMP */ - perror("ping: creating a raw socket"); - exit(1); - } + if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) /* 1 == ICMP */ + perror_msg_and_die("creating a raw socket"); /* drop root privs if running setuid */ setuid(getuid()); @@ -216,12 +214,8 @@ static void ping(const char *host) c = sendto(pingsock, packet, sizeof(packet), 0, (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in)); - if (c < 0 || c != sizeof(packet)) { - if (c < 0) - perror("ping: sendto"); - error_msg("write incomplete\n"); - exit(1); - } + if (c < 0 || c != sizeof(packet)) + perror_msg_and_die("sendto"); signal(SIGALRM, noresp); alarm(5); /* give the host 5000ms to respond */ @@ -234,7 +228,7 @@ static void ping(const char *host) (struct sockaddr *) &from, &fromlen)) < 0) { if (errno == EINTR) continue; - perror("ping: recvfrom"); + perror_msg("recvfrom"); continue; } if (c >= 76) { /* ip + icmp */ @@ -439,12 +433,10 @@ static void ping(const char *host) * proto->p_proto to have the correct value for "icmp" */ if ((pingsock = socket(AF_INET, SOCK_RAW, (proto ? proto->p_proto : 1))) < 0) { /* 1 == ICMP */ - if (errno == EPERM) { - error_msg("permission denied. (are you root?)\n"); - } else { - perror("ping: creating a raw socket"); - } - exit(1); + if (errno == EPERM) + error_msg_and_die("permission denied. (are you root?)\n"); + else + perror_msg_and_die("creating a raw socket"); } /* drop root privs if running setuid */ @@ -498,7 +490,7 @@ static void ping(const char *host) (struct sockaddr *) &from, &fromlen)) < 0) { if (errno == EINTR) continue; - perror("ping: recvfrom"); + perror_msg("recvfrom"); continue; } unpack(packet, c, &from); @@ -1,6 +1,6 @@ /* vi: set sw=4 ts=4: */ /* - * $Id: ping.c,v 1.29 2000/12/18 03:57:16 kraai Exp $ + * $Id: ping.c,v 1.30 2000/12/22 01:48:07 kraai Exp $ * Mini ping implementation for busybox * * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> @@ -190,10 +190,8 @@ static void ping(const char *host) int pingsock, c; char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; - if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) { /* 1 == ICMP */ - perror("ping: creating a raw socket"); - exit(1); - } + if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) /* 1 == ICMP */ + perror_msg_and_die("creating a raw socket"); /* drop root privs if running setuid */ setuid(getuid()); @@ -216,12 +214,8 @@ static void ping(const char *host) c = sendto(pingsock, packet, sizeof(packet), 0, (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in)); - if (c < 0 || c != sizeof(packet)) { - if (c < 0) - perror("ping: sendto"); - error_msg("write incomplete\n"); - exit(1); - } + if (c < 0 || c != sizeof(packet)) + perror_msg_and_die("sendto"); signal(SIGALRM, noresp); alarm(5); /* give the host 5000ms to respond */ @@ -234,7 +228,7 @@ static void ping(const char *host) (struct sockaddr *) &from, &fromlen)) < 0) { if (errno == EINTR) continue; - perror("ping: recvfrom"); + perror_msg("recvfrom"); continue; } if (c >= 76) { /* ip + icmp */ @@ -439,12 +433,10 @@ static void ping(const char *host) * proto->p_proto to have the correct value for "icmp" */ if ((pingsock = socket(AF_INET, SOCK_RAW, (proto ? proto->p_proto : 1))) < 0) { /* 1 == ICMP */ - if (errno == EPERM) { - error_msg("permission denied. (are you root?)\n"); - } else { - perror("ping: creating a raw socket"); - } - exit(1); + if (errno == EPERM) + error_msg_and_die("permission denied. (are you root?)\n"); + else + perror_msg_and_die("creating a raw socket"); } /* drop root privs if running setuid */ @@ -498,7 +490,7 @@ static void ping(const char *host) (struct sockaddr *) &from, &fromlen)) < 0) { if (errno == EINTR) continue; - perror("ping: recvfrom"); + perror_msg("recvfrom"); continue; } unpack(packet, c, &from); @@ -45,10 +45,8 @@ extern int rmmod_main(int argc, char **argv) switch (**argv) { case 'a': /* Unload _all_ unused modules via NULL delete_module() call */ - if (delete_module(NULL)) { - perror("rmmod"); - return EXIT_FAILURE; - } + if (delete_module(NULL)) + perror_msg_and_die("rmmod"); return EXIT_SUCCESS; default: usage(rmmod_usage); @@ -58,7 +56,7 @@ extern int rmmod_main(int argc, char **argv) while (argc-- > 0) { if (delete_module(*argv) < 0) { - perror(*argv); + perror_msg("%s", *argv); ret = EXIT_FAILURE; } argv++; diff --git a/rpmunpack.c b/rpmunpack.c index 2178a247d..249d223c0 100644 --- a/rpmunpack.c +++ b/rpmunpack.c @@ -40,10 +40,9 @@ static void myread(int num) if ((err = read(infile, buffer, num)) != num) { if (err < 0) - perror(progname); + perror_msg_and_die(progname); else - fprintf(stderr, "Unexpected end of input file!\n"); - exit(1); + error_msg_and_die("Unexpected end of input file!\n"); } } @@ -68,10 +67,8 @@ int rpmunpack_main(int argc, char **argv) /* Open input file */ if (argc == 1) infile = STDIN_FILENO; - else if ((infile = open(argv[1], O_RDONLY)) < 0) { - perror(progname); - exit(1); - } + else if ((infile = open(argv[1], O_RDONLY)) < 0) + perror_msg_and_die("%s", argv[1]); /* Read magic ID and output filename */ myread(4); @@ -87,10 +84,8 @@ int rpmunpack_main(int argc, char **argv) strcat(buffer, ".cpio.gz"); if (infile == STDIN_FILENO) outfile = STDOUT_FILENO; - else if ((outfile = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { - perror(progname); - exit(1); - } + else if ((outfile = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) + perror_msg_and_die("%s", buffer); /* * Now search for the GZIP signature. This is rather awkward, but I don't @@ -114,23 +109,15 @@ int rpmunpack_main(int argc, char **argv) } buffer[0] = GZ_MAGIC_1; buffer[1] = GZ_MAGIC_2; - if (write(outfile, buffer, 2) < 0) { - perror(progname); - exit(1); - } + if (write(outfile, buffer, 2) < 0) + perror_msg_and_die("write"); /* Now simply copy the GZIP archive into the output file */ while ((len = read(infile, buffer, BUFSIZE)) > 0) { - if (write(outfile, buffer, len) < 0) { - perror(progname); - exit(1); - } - } - if (len < 0) { - perror(progname); - exit(1); + if (write(outfile, buffer, len) < 0) + perror_msg_and_die("write"); } - close(outfile); - close(infile); - exit(0); + if (len < 0) + perror_msg_and_die("read"); + return EXIT_SUCCESS; } @@ -709,10 +709,8 @@ extern int sed_main(int argc, char **argv) #ifdef BB_FEATURE_CLEAN_UP /* destroy command strings on exit */ - if (atexit(destroy_cmd_strs) == -1) { - perror("sed"); - exit(1); - } + if (atexit(destroy_cmd_strs) == -1) + perror_msg_and_die("atexit"); #endif /* do normal option parsing */ @@ -344,7 +344,7 @@ static int builtin_fg_bg(struct child_prog *child) /* Make this job the foreground job */ /* suppress messages when run from /linuxrc mag@sysgo.de */ if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY) - perror("tcsetpgrp"); + perror_msg("tcsetpgrp"); child->family->job_list->fg = job; } @@ -683,7 +683,7 @@ static void checkjobs(struct jobset *job_list) } if (childpid == -1 && errno != ECHILD) - perror("waitpid"); + perror_msg("waitpid"); } /* squirrel != NULL means we squirrel away copies of stdin, stdout, @@ -1422,7 +1422,7 @@ static void insert_job(struct job *newjob, int inbg) /* move the new process group into the foreground */ /* suppress messages when run from /linuxrc mag@sysgo.de */ if (tcsetpgrp(0, newjob->pgrp) && errno != ENOTTY) - perror("tcsetpgrp"); + perror_msg("tcsetpgrp"); } } @@ -1612,7 +1612,7 @@ static int busy_loop(FILE * input) /* move the shell to the foreground */ /* suppress messages when run from /linuxrc mag@sysgo.de */ if (tcsetpgrp(0, getpid()) && errno != ENOTTY) - perror("tcsetpgrp"); + perror_msg("tcsetpgrp"); } } } @@ -1620,7 +1620,7 @@ static int busy_loop(FILE * input) /* return controlling TTY back to parent process group before exiting */ if (tcsetpgrp(0, parent_pgrp)) - perror("tcsetpgrp"); + perror_msg("tcsetpgrp"); /* return exit status if called with "-c" */ if (input == NULL && WIFEXITED(status)) diff --git a/shell/lash.c b/shell/lash.c index 22a696785..a47ff5ca2 100644 --- a/shell/lash.c +++ b/shell/lash.c @@ -344,7 +344,7 @@ static int builtin_fg_bg(struct child_prog *child) /* Make this job the foreground job */ /* suppress messages when run from /linuxrc mag@sysgo.de */ if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY) - perror("tcsetpgrp"); + perror_msg("tcsetpgrp"); child->family->job_list->fg = job; } @@ -683,7 +683,7 @@ static void checkjobs(struct jobset *job_list) } if (childpid == -1 && errno != ECHILD) - perror("waitpid"); + perror_msg("waitpid"); } /* squirrel != NULL means we squirrel away copies of stdin, stdout, @@ -1422,7 +1422,7 @@ static void insert_job(struct job *newjob, int inbg) /* move the new process group into the foreground */ /* suppress messages when run from /linuxrc mag@sysgo.de */ if (tcsetpgrp(0, newjob->pgrp) && errno != ENOTTY) - perror("tcsetpgrp"); + perror_msg("tcsetpgrp"); } } @@ -1612,7 +1612,7 @@ static int busy_loop(FILE * input) /* move the shell to the foreground */ /* suppress messages when run from /linuxrc mag@sysgo.de */ if (tcsetpgrp(0, getpid()) && errno != ENOTTY) - perror("tcsetpgrp"); + perror_msg("tcsetpgrp"); } } } @@ -1620,7 +1620,7 @@ static int busy_loop(FILE * input) /* return controlling TTY back to parent process group before exiting */ if (tcsetpgrp(0, parent_pgrp)) - perror("tcsetpgrp"); + perror_msg("tcsetpgrp"); /* return exit status if called with "-c" */ if (input == NULL && WIFEXITED(status)) @@ -30,9 +30,7 @@ extern int sleep_main(int argc, char **argv) usage(sleep_usage); } - if (sleep(atoi(*(++argv))) != 0) { - perror("sleep"); - return EXIT_FAILURE; - } + if (sleep(atoi(*(++argv))) != 0) + perror_msg_and_die("sleep"); return EXIT_SUCCESS; } diff --git a/swaponoff.c b/swaponoff.c index e40d169dd..85f338932 100644 --- a/swaponoff.c +++ b/swaponoff.c @@ -48,10 +48,8 @@ static void swap_enable_disable(char *device) else status = swapoff(device); - if (status != 0) { - perror(applet_name); - exit(EXIT_FAILURE); - } + if (status != 0) + perror_msg_and_die(applet_name); } static void do_em_all() @@ -59,10 +57,8 @@ static void do_em_all() struct mntent *m; FILE *f = setmntent("/etc/fstab", "r"); - if (f == NULL) { - perror("/etc/fstab"); - exit(FALSE); - } + if (f == NULL) + perror_msg_and_die("/etc/fstab"); while ((m = getmntent(f)) != NULL) { if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) { swap_enable_disable(m->mnt_fsname); @@ -216,7 +216,7 @@ static int umount_all(int useMtab) if (status != 0) { /* Don't bother retrying the umount on busy devices */ if (errno == EBUSY) { - perror(mountpt); + perror_msg("%s", mountpt); continue; } status = do_umount(mountpt, useMtab); @@ -280,7 +280,6 @@ extern int umount_main(int argc, char **argv) } if (do_umount(*argv, useMtab) == TRUE) return EXIT_SUCCESS; - perror("umount"); - return EXIT_FAILURE; + perror_msg_and_die("%s", *argv); } @@ -114,11 +114,11 @@ int uname_main(int argc, char **argv) toprint = PRINT_SYSNAME; if (uname(&name) == -1) - perror("cannot get system name"); + perror_msg("cannot get system name"); #if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE) if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1) - perror("cannot get processor type"); + perror_msg("cannot get processor type"); } #else diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c index 1d33b7641..c220d9018 100644 --- a/util-linux/dmesg.c +++ b/util-linux/dmesg.c @@ -69,20 +69,16 @@ int dmesg_main(int argc, char **argv) } if (cmd == 8) { - n = klogctl(cmd, NULL, level); - if (n < 0) { - goto klogctl_error; - } + if (klogctl(cmd, NULL, level) < 0) + perror_msg_and_die("klogctl"); return EXIT_SUCCESS; } if (bufsize < 4096) bufsize = 4096; buf = (char *) xmalloc(bufsize); - n = klogctl(cmd, buf, bufsize); - if (n < 0) { - goto klogctl_error; - } + if ((n = klogctl(cmd, buf, bufsize)) < 0) + perror_msg_and_die("klogctl"); lastc = '\n'; for (i = 0; i < n; i++) { @@ -102,7 +98,4 @@ int dmesg_main(int argc, char **argv) end: usage(dmesg_usage); return EXIT_FAILURE; - klogctl_error: - perror("klogctl"); - return EXIT_FAILURE; } diff --git a/util-linux/fbset.c b/util-linux/fbset.c index 86f7733c9..40a907b07 100644 --- a/util-linux/fbset.c +++ b/util-linux/fbset.c @@ -33,8 +33,6 @@ #include <ctype.h> #include <sys/ioctl.h> -#define PERROR(ctx) do { perror(ctx); exit(1); } while(0) - #define DEFAULTFBDEV "/dev/fb0" #define DEFAULTFBMODE "/etc/fb.modes" @@ -198,7 +196,7 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn, char *p = buf; if ((f = fopen(fn, "r")) == NULL) - PERROR("readmode(fopen)"); + perror_msg_and_die("readmode(fopen)"); while (!feof(f)) { fgets(buf, sizeof(buf), f); if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) { @@ -428,9 +426,9 @@ extern int fbset_main(int argc, char **argv) } if ((fh = open(fbdev, O_RDONLY)) < 0) - PERROR("fbset(open)"); + perror_msg_and_die("fbset(open)"); if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) - PERROR("fbset(ioctl)"); + perror_msg_and_die("fbset(ioctl)"); if (g_options & OPT_READMODE) { if (!readmode(&var, modefile, mode)) { error_msg("Unknown video mode `%s'\n", mode); @@ -441,7 +439,7 @@ extern int fbset_main(int argc, char **argv) setmode(&var, &varset); if (g_options & OPT_CHANGE) if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) - PERROR("fbset(ioctl)"); + perror_msg_and_die("fbset(ioctl)"); showmode(&var); /* Don't close the file, as exiting will take care of that */ /* close(fh); */ diff --git a/util-linux/fdflush.c b/util-linux/fdflush.c index 380015dde..5eb93ddd7 100644 --- a/util-linux/fdflush.c +++ b/util-linux/fdflush.c @@ -31,26 +31,16 @@ extern int fdflush_main(int argc, char **argv) { - int value; int fd; if (argc <= 1 || **(++argv) == '-') usage(fdflush_usage); - fd = open(*argv, 0); - if (fd < 0) { - perror(*argv); - return EXIT_FAILURE; - } + if ((fd = open(*argv, 0)) < 0) + perror_msg_and_die("%s", *argv); - value = ioctl(fd, FDFLUSH, 0); - /* Don't bother closing. Exit does - * that, so we can save a few bytes */ - /* close(fd); */ + if (ioctl(fd, FDFLUSH, 0)) + perror_msg_and_die("%s", *argv); - if (value) { - perror(*argv); - return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c index 95815fd4d..e1ede6caa 100644 --- a/util-linux/mkfs_minix.c +++ b/util-linux/mkfs_minix.c @@ -329,11 +329,8 @@ static int get_size(const char *file) int fd; long size; - fd = open(file, O_RDWR); - if (fd < 0) { - perror(file); - exit(1); - } + if ((fd = open(file, O_RDWR)) < 0) + perror_msg_and_die("%s", file); if (ioctl(fd, BLKGETSIZE, &size) >= 0) { close(fd); return (size * 512); diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c index 60ae2864d..e7fab4e07 100644 --- a/util-linux/mkswap.c +++ b/util-linux/mkswap.c @@ -260,11 +260,8 @@ static long get_size(const char *file) int fd; long size; - fd = open(file, O_RDONLY); - if (fd < 0) { - perror(file); - exit(1); - } + if ((fd = open(file, O_RDONLY)) < 0) + perror_msg_and_die("%s", file); if (ioctl(fd, BLKGETSIZE, &size) >= 0) { int sectors_per_page = pagesize / 512; @@ -367,10 +364,8 @@ int mkswap_main(int argc, char **argv) } DEV = open(device_name, O_RDWR); - if (DEV < 0 || fstat(DEV, &statbuf) < 0) { - perror(device_name); - return EXIT_FAILURE; - } + if (DEV < 0 || fstat(DEV, &statbuf) < 0) + perror_msg_and_die("%s", device_name); if (!S_ISBLK(statbuf.st_mode)) check = 0; else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) diff --git a/util-linux/mount.c b/util-linux/mount.c index 8240b99aa..97b60abbd 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -383,7 +383,7 @@ extern int mount_main(int argc, char **argv) } endmntent(mountTable); } else { - perror(mtab_file); + perror_msg_and_die("%s", mtab_file); } return EXIT_SUCCESS; } diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index e40d169dd..85f338932 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c @@ -48,10 +48,8 @@ static void swap_enable_disable(char *device) else status = swapoff(device); - if (status != 0) { - perror(applet_name); - exit(EXIT_FAILURE); - } + if (status != 0) + perror_msg_and_die(applet_name); } static void do_em_all() @@ -59,10 +57,8 @@ static void do_em_all() struct mntent *m; FILE *f = setmntent("/etc/fstab", "r"); - if (f == NULL) { - perror("/etc/fstab"); - exit(FALSE); - } + if (f == NULL) + perror_msg_and_die("/etc/fstab"); while ((m = getmntent(f)) != NULL) { if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) { swap_enable_disable(m->mnt_fsname); diff --git a/util-linux/umount.c b/util-linux/umount.c index e76e0521f..0867118c0 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c @@ -216,7 +216,7 @@ static int umount_all(int useMtab) if (status != 0) { /* Don't bother retrying the umount on busy devices */ if (errno == EBUSY) { - perror(mountpt); + perror_msg("%s", mountpt); continue; } status = do_umount(mountpt, useMtab); @@ -280,7 +280,6 @@ extern int umount_main(int argc, char **argv) } if (do_umount(*argv, useMtab) == TRUE) return EXIT_SUCCESS; - perror("umount"); - return EXIT_FAILURE; + perror_msg_and_die("%s", *argv); } @@ -153,7 +153,7 @@ extern int get_kernel_revision(void) int major = 0, minor = 0, patch = 0; if (uname(&name) == -1) { - perror("cannot get system information"); + perror_msg("cannot get system information"); return (0); } major = atoi(strtok(name.release, ".")); @@ -341,7 +341,7 @@ copy_file(const char *srcName, const char *destName, status = lstat(srcName, &srcStatBuf); if (status < 0) { - perror(srcName); + perror_msg("%s", srcName); return FALSE; } @@ -367,7 +367,7 @@ copy_file(const char *srcName, const char *destName, /* Make sure the directory is writable */ status = mkdir(destName, 0777777 ^ umask(0)); if (status < 0 && errno != EEXIST) { - perror(destName); + perror_msg("%s", destName); return FALSE; } } else if (S_ISLNK(srcStatBuf.st_mode)) { @@ -378,13 +378,13 @@ copy_file(const char *srcName, const char *destName, /* Warning: This could possibly truncate silently, to BUFSIZ chars */ link_size = readlink(srcName, &link_val[0], BUFSIZ); if (link_size < 0) { - perror(srcName); + perror_msg("%s", srcName); return FALSE; } link_val[link_size] = '\0'; status = symlink(link_val, destName); if (status < 0) { - perror(destName); + perror_msg("%s", destName); return FALSE; } #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) @@ -397,28 +397,28 @@ copy_file(const char *srcName, const char *destName, } else if (S_ISFIFO(srcStatBuf.st_mode)) { //fprintf(stderr, "copying fifo %s to %s\n", srcName, destName); if (mkfifo(destName, 0644) < 0) { - perror(destName); + perror_msg("%s", destName); return FALSE; } } else if (S_ISBLK(srcStatBuf.st_mode) || S_ISCHR(srcStatBuf.st_mode) || S_ISSOCK(srcStatBuf.st_mode)) { //fprintf(stderr, "copying soc, blk, or chr %s to %s\n", srcName, destName); if (mknod(destName, srcStatBuf.st_mode, srcStatBuf.st_rdev) < 0) { - perror(destName); + perror_msg("%s", destName); return FALSE; } } else if (S_ISREG(srcStatBuf.st_mode)) { //fprintf(stderr, "copying regular file %s to %s\n", srcName, destName); rfd = open(srcName, O_RDONLY); if (rfd < 0) { - perror(srcName); + perror_msg("%s", srcName); return FALSE; } wfd = open(destName, O_WRONLY | O_CREAT | O_TRUNC, srcStatBuf.st_mode); if (wfd < 0) { - perror(destName); + perror_msg("%s", destName); close(rfd); return FALSE; } @@ -434,26 +434,20 @@ copy_file(const char *srcName, const char *destName, if (setModes == TRUE) { /* This is fine, since symlinks never get here */ - if (chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0) { - perror(destName); - exit(EXIT_FAILURE); - } - if (chmod(destName, srcStatBuf.st_mode) < 0) { - perror(destName); - exit(EXIT_FAILURE); - } + if (chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0) + perror_msg_and_die("%s", destName); + if (chmod(destName, srcStatBuf.st_mode) < 0) + perror_msg_and_die("%s", destName); times.actime = srcStatBuf.st_atime; times.modtime = srcStatBuf.st_mtime; - if (utime(destName, ×) < 0) { - perror(destName); - exit(EXIT_FAILURE); - } + if (utime(destName, ×) < 0) + perror_msg_and_die("%s", destName); } return TRUE; error_exit: - perror(destName); + perror_msg("%s", destName); close(rfd); close(wfd); @@ -745,7 +739,7 @@ extern int create_path(const char *name, int mode) *cpOld = '\0'; retVal = mkdir(buf, cp ? 0777 : mode); if (retVal != 0 && errno != EEXIST) { - perror(buf); + perror_msg("%s", buf); return FALSE; } *cpOld = '/'; @@ -1450,11 +1444,11 @@ extern int del_loop(const char *device) int fd; if ((fd = open(device, O_RDONLY)) < 0) { - perror(device); + perror_msg("%s", device); return (FALSE); } if (ioctl(fd, LOOP_CLR_FD, 0) < 0) { - perror("ioctl: LOOP_CLR_FD"); + perror_msg("ioctl: LOOP_CLR_FD"); return (FALSE); } close(fd); @@ -1470,12 +1464,12 @@ extern int set_loop(const char *device, const char *file, int offset, mode = *loopro ? O_RDONLY : O_RDWR; if ((ffd = open(file, mode)) < 0 && !*loopro && (errno != EROFS || (ffd = open(file, mode = O_RDONLY)) < 0)) { - perror(file); + perror_msg("%s", file); return 1; } if ((fd = open(device, mode)) < 0) { close(ffd); - perror(device); + perror_msg("%s", device); return 1; } *loopro = (mode == O_RDONLY); @@ -1488,14 +1482,14 @@ extern int set_loop(const char *device, const char *file, int offset, loopinfo.lo_encrypt_key_size = 0; if (ioctl(fd, LOOP_SET_FD, ffd) < 0) { - perror("ioctl: LOOP_SET_FD"); + perror_msg("ioctl: LOOP_SET_FD"); close(fd); close(ffd); return 1; } if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) { (void) ioctl(fd, LOOP_CLR_FD, 0); - perror("ioctl: LOOP_SET_STATUS"); + perror_msg("ioctl: LOOP_SET_STATUS"); close(fd); close(ffd); return 1; @@ -81,10 +81,8 @@ int xargs_main(int argc, char **argv) strcat(execstr, cmd_to_be_executed); strcat(execstr, file_to_act_on); cmd_output = popen(execstr, "r"); - if (cmd_output == NULL) { - perror("popen"); - exit(1); - } + if (cmd_output == NULL) + perror_msg_and_die("popen"); /* harvest the output */ while ((output_line = get_line_from_file(cmd_output)) != NULL) { |