Use busybox error handling functions wherever possible.
authorMatt Kraai <kraai@debian.org>
Fri, 22 Dec 2000 01:48:07 +0000 (01:48 -0000)
committerMatt Kraai <kraai@debian.org>
Fri, 22 Dec 2000 01:48:07 +0000 (01:48 -0000)
50 files changed:
archival/gzip.c
console-tools/deallocvt.c
console-tools/loadacm.c
coreutils/mkfifo.c
coreutils/mknod.c
coreutils/sleep.c
coreutils/uname.c
deallocvt.c
dmesg.c
editors/sed.c
fbset.c
fdflush.c
findutils/xargs.c
gzip.c
hostname.c
insmod.c
lash.c
loadacm.c
miscutils/mt.c
mkfifo.c
mkfs_minix.c
mknod.c
mkswap.c
modutils/insmod.c
modutils/rmmod.c
mount.c
mt.c
mtab.c
networking/hostname.c
networking/ping.c
ping.c
rmmod.c
rpmunpack.c
sed.c
sh.c
shell/lash.c
sleep.c
swaponoff.c
umount.c
uname.c
util-linux/dmesg.c
util-linux/fbset.c
util-linux/fdflush.c
util-linux/mkfs_minix.c
util-linux/mkswap.c
util-linux/mount.c
util-linux/swaponoff.c
util-linux/umount.c
utility.c
xargs.c

index ca0c177d47152e7aa861eee264d5ad4ed5c5703b..09260929e8c16d9e900b41ae9324f9aa225b2b41 100644 (file)
@@ -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);
index b128c3fae562d63b179bd9bf2a9f17cae139f081..3dd90c0e989254a3d62310d0f55a312b154010d8 100644 (file)
@@ -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");
                }
        }
 
index 52702bf6d98c0852bac39d27cd2a8376644adb62..040062cf8ce69140343d67302a4f285a9ee92b8e 100644 (file)
@@ -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
 
index ef4a5256f4ec0327469160ea58eb128c732d7771..728e1ec2f44d7a01d1278a2698ff46ca49cb7fb7 100644 (file)
@@ -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;
 }
index 022ab8571421c99ead06d61921d2996ab50825fd..4d8c598ead16c7eeaf5cbcf7792f5fe459ba538e 100644 (file)
@@ -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;
 }
 
index ad92b106d36abdb30ed5f8c3bc9a50e40e85585c..10eca593e0f180f546645d17fe149729a8d6b201 100644 (file)
@@ -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;
 }
index 2781b80b3c82a5962b3b93b423bdf07d3db15ce7..e7e9ff331517f223d6bdfaef653fd5488624c960 100644 (file)
@@ -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
index b128c3fae562d63b179bd9bf2a9f17cae139f081..3dd90c0e989254a3d62310d0f55a312b154010d8 100644 (file)
@@ -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/dmesg.c b/dmesg.c
index 1d33b7641f9ed10957b5c0c4f0d83934c03218ff..c220d90184f9e76d06a3401d1fd2e0dfde67ab10 100644 (file)
--- a/dmesg.c
+++ b/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;
 }
index a7152e52a038b9b7e7f0cd4d0a655fc92154ef24..341924d6b42e75545e77e3309ec8e86773a27603 100644 (file)
@@ -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 */
diff --git a/fbset.c b/fbset.c
index 86f7733c9afbc160967c53ec61019eaa8a134b0a..40a907b072a4addbeeeca6c977f4bb8f32f5dc3b 100644 (file)
--- a/fbset.c
+++ b/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); */
index 380015ddec2567f8b46e8de383e37c160ace3443..5eb93ddd7d7aa44494e9fb8bd17051b2b71c14f3 100644 (file)
--- a/fdflush.c
+++ b/fdflush.c
 
 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;
 }
index c5f7b208c425cb2cebc7c168a5c7cca045779655..ddfbe9230dc411363266adc98dea663c177e8248 100644 (file)
@@ -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) {
diff --git a/gzip.c b/gzip.c
index ca0c177d47152e7aa861eee264d5ad4ed5c5703b..09260929e8c16d9e900b41ae9324f9aa225b2b41 100644 (file)
--- a/gzip.c
+++ b/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);
index 13e52c41d33ed3b5404005e0ac5e2abe33d43f63..c64d1602b987abc9ab94c5bf0811baf857333369 100644 (file)
@@ -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");
        }
 }
 
index cbe00c2b4c6ef38d6d13db3317817378c986abb1..7391b4fb2a37f10428ebc8928ecbf8f65c7d16ec 100644 (file)
--- a/insmod.c
+++ b/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/lash.c b/lash.c
index 22a696785ac9a60d0d69d9e91c03e93143fbbce2..a47ff5ca211c56d4b0b57c7c28d523d8d189c6d6 100644 (file)
--- a/lash.c
+++ b/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))
index 52702bf6d98c0852bac39d27cd2a8376644adb62..040062cf8ce69140343d67302a4f285a9ee92b8e 100644 (file)
--- a/loadacm.c
+++ b/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
 
index 2d35c7c22c4f80050edf0feae7d0254dd7a17370..70d03cca40177f3f02d9ca29d26faab33423f8f0 100644 (file)
@@ -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;
 }
index ef4a5256f4ec0327469160ea58eb128c732d7771..728e1ec2f44d7a01d1278a2698ff46ca49cb7fb7 100644 (file)
--- a/mkfifo.c
+++ b/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;
 }
index 95815fd4dce66fc5a0b2de0b44016c2727e9e0bf..e1ede6caa3357ba3c8ec4920aceb39498d5f7677 100644 (file)
@@ -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/mknod.c b/mknod.c
index 022ab8571421c99ead06d61921d2996ab50825fd..4d8c598ead16c7eeaf5cbcf7792f5fe459ba538e 100644 (file)
--- a/mknod.c
+++ b/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;
 }
 
index 60ae2864d1c5e29b5d498687200f5ba8904297b1..e7fab4e0733517a2d02cacd9dfce8d718976359d 100644 (file)
--- a/mkswap.c
+++ b/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)
index cbe00c2b4c6ef38d6d13db3317817378c986abb1..7391b4fb2a37f10428ebc8928ecbf8f65c7d16ec 100644 (file)
@@ -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;
index f5d7d359a2f889521e1814dabf4d30b68e6a8c79..52adc7bcd85edc65d33b56e557c5aef7a013fc5b 100644 (file)
@@ -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/mount.c b/mount.c
index 8240b99aaf7d129a4a67b790ec9606b254f5c754..97b60abbd732542d70c9c4519c0d22ab1f180c02 100644 (file)
--- a/mount.c
+++ b/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/mt.c b/mt.c
index 2d35c7c22c4f80050edf0feae7d0254dd7a17370..70d03cca40177f3f02d9ca29d26faab33423f8f0 100644 (file)
--- a/mt.c
+++ b/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;
 }
diff --git a/mtab.c b/mtab.c
index 1f2083709f9612a4fe00ca41504eaafb07461138..ab805e9c18d316c71c53dbba05b5c9f90f5587c5 100644 (file)
--- a/mtab.c
+++ b/mtab.c
@@ -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) {
index 13e52c41d33ed3b5404005e0ac5e2abe33d43f63..c64d1602b987abc9ab94c5bf0811baf857333369 100644 (file)
@@ -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");
        }
 }
 
index 4be2120c8be8c248a03e594a4c7a51344acd0eda..e9242e9b7f349228dd2c7f4a3e15bc7eae743f63 100644 (file)
@@ -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);
diff --git a/ping.c b/ping.c
index 4be2120c8be8c248a03e594a4c7a51344acd0eda..e9242e9b7f349228dd2c7f4a3e15bc7eae743f63 100644 (file)
--- a/ping.c
+++ b/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);
diff --git a/rmmod.c b/rmmod.c
index f5d7d359a2f889521e1814dabf4d30b68e6a8c79..52adc7bcd85edc65d33b56e557c5aef7a013fc5b 100644 (file)
--- a/rmmod.c
+++ b/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++;
index 2178a247dd72a27ecc611d2931b8050c353be833..249d223c08a2bb8dad562f83bafe120cf4b41db2 100644 (file)
@@ -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;
 }
diff --git a/sed.c b/sed.c
index a7152e52a038b9b7e7f0cd4d0a655fc92154ef24..341924d6b42e75545e77e3309ec8e86773a27603 100644 (file)
--- a/sed.c
+++ b/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 */
diff --git a/sh.c b/sh.c
index 22a696785ac9a60d0d69d9e91c03e93143fbbce2..a47ff5ca211c56d4b0b57c7c28d523d8d189c6d6 100644 (file)
--- a/sh.c
+++ b/sh.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))
index 22a696785ac9a60d0d69d9e91c03e93143fbbce2..a47ff5ca211c56d4b0b57c7c28d523d8d189c6d6 100644 (file)
@@ -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/sleep.c b/sleep.c
index ad92b106d36abdb30ed5f8c3bc9a50e40e85585c..10eca593e0f180f546645d17fe149729a8d6b201 100644 (file)
--- a/sleep.c
+++ b/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;
 }
index e40d169dde442c9fff1c250fd5e09786f5d91a57..85f338932c0aee9d51b0ff95867df3528f9ccb82 100644 (file)
@@ -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);
index e76e0521f261bbe6067ccc6ae1ff5dd8125b9c9f..0867118c0afd91339cd881f95ab9aeb029ea6ce1 100644 (file)
--- a/umount.c
+++ b/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);
 }
 
diff --git a/uname.c b/uname.c
index 2781b80b3c82a5962b3b93b423bdf07d3db15ce7..e7e9ff331517f223d6bdfaef653fd5488624c960 100644 (file)
--- a/uname.c
+++ b/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
index 1d33b7641f9ed10957b5c0c4f0d83934c03218ff..c220d90184f9e76d06a3401d1fd2e0dfde67ab10 100644 (file)
@@ -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;
 }
index 86f7733c9afbc160967c53ec61019eaa8a134b0a..40a907b072a4addbeeeca6c977f4bb8f32f5dc3b 100644 (file)
@@ -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); */
index 380015ddec2567f8b46e8de383e37c160ace3443..5eb93ddd7d7aa44494e9fb8bd17051b2b71c14f3 100644 (file)
 
 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;
 }
index 95815fd4dce66fc5a0b2de0b44016c2727e9e0bf..e1ede6caa3357ba3c8ec4920aceb39498d5f7677 100644 (file)
@@ -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);
index 60ae2864d1c5e29b5d498687200f5ba8904297b1..e7fab4e0733517a2d02cacd9dfce8d718976359d 100644 (file)
@@ -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)
index 8240b99aaf7d129a4a67b790ec9606b254f5c754..97b60abbd732542d70c9c4519c0d22ab1f180c02 100644 (file)
@@ -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;
        }
index e40d169dde442c9fff1c250fd5e09786f5d91a57..85f338932c0aee9d51b0ff95867df3528f9ccb82 100644 (file)
@@ -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);
index e76e0521f261bbe6067ccc6ae1ff5dd8125b9c9f..0867118c0afd91339cd881f95ab9aeb029ea6ce1 100644 (file)
@@ -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);
 }
 
index b06abf4648da8df16d50e6250ac7ae2585b397af..f222518950b2c114f01d6cda0cfd560ef3809e51 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -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, &times) < 0) {
-                       perror(destName);
-                       exit(EXIT_FAILURE);
-               }
+               if (utime(destName, &times) < 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;
diff --git a/xargs.c b/xargs.c
index c5f7b208c425cb2cebc7c168a5c7cca045779655..ddfbe9230dc411363266adc98dea663c177e8248 100644 (file)
--- a/xargs.c
+++ b/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) {