diff options
author | Matt Kraai <kraai@debian.org> | 2000-12-22 01:48:07 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2000-12-22 01:48:07 +0000 |
commit | a9819b290848e0a760f3805d5937fa050235d707 (patch) | |
tree | b8cb8d939032c0806d62161b01e5836cb808dc3f | |
parent | e9f07fb6e83b75a50760599a5d31f494841eddf7 (diff) | |
download | busybox-w32-a9819b290848e0a760f3805d5937fa050235d707.tar.gz busybox-w32-a9819b290848e0a760f3805d5937fa050235d707.tar.bz2 busybox-w32-a9819b290848e0a760f3805d5937fa050235d707.zip |
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) | |||
1867 | usage(gzip_usage); | 1867 | usage(gzip_usage); |
1868 | strncpy(ifname, *argv, MAX_PATH_LEN); | 1868 | strncpy(ifname, *argv, MAX_PATH_LEN); |
1869 | 1869 | ||
1870 | /* Open input fille */ | 1870 | /* Open input file */ |
1871 | inFileNum = open(ifname, O_RDONLY); | 1871 | inFileNum = open(ifname, O_RDONLY); |
1872 | if (inFileNum < 0) { | 1872 | if (inFileNum < 0) |
1873 | perror(ifname); | 1873 | perror_msg_and_die("%s", ifname); |
1874 | exit(WARNING); | ||
1875 | } | ||
1876 | /* Get the time stamp on the input file. */ | 1874 | /* Get the time stamp on the input file. */ |
1877 | result = stat(ifname, &statBuf); | 1875 | if (stat(ifname, &statBuf) < 0) |
1878 | if (result < 0) { | 1876 | perror_msg_and_die("%s", ifname); |
1879 | perror(ifname); | ||
1880 | exit(WARNING); | ||
1881 | } | ||
1882 | time_stamp = statBuf.st_ctime; | 1877 | time_stamp = statBuf.st_ctime; |
1883 | ifile_size = statBuf.st_size; | 1878 | ifile_size = statBuf.st_size; |
1884 | } | 1879 | } |
@@ -1909,10 +1904,8 @@ int gzip_main(int argc, char **argv) | |||
1909 | #else | 1904 | #else |
1910 | outFileNum = open(ofname, O_RDWR | O_CREAT | O_EXCL); | 1905 | outFileNum = open(ofname, O_RDWR | O_CREAT | O_EXCL); |
1911 | #endif | 1906 | #endif |
1912 | if (outFileNum < 0) { | 1907 | if (outFileNum < 0) |
1913 | perror(ofname); | 1908 | perror_msg_and_die("%s", ofname); |
1914 | exit(WARNING); | ||
1915 | } | ||
1916 | SET_BINARY_MODE(outFileNum); | 1909 | SET_BINARY_MODE(outFileNum); |
1917 | /* Set permissions on the file */ | 1910 | /* Set permissions on the file */ |
1918 | fchmod(outFileNum, statBuf.st_mode); | 1911 | fchmod(outFileNum, statBuf.st_mode); |
@@ -1930,10 +1923,8 @@ int gzip_main(int argc, char **argv) | |||
1930 | else | 1923 | else |
1931 | delFileName = ofname; | 1924 | delFileName = ofname; |
1932 | 1925 | ||
1933 | if (unlink(delFileName) < 0) { | 1926 | if (unlink(delFileName) < 0) |
1934 | perror(delFileName); | 1927 | perror_msg_and_die("%s", delFileName); |
1935 | exit(EXIT_FAILURE); | ||
1936 | } | ||
1937 | } | 1928 | } |
1938 | 1929 | ||
1939 | return(exit_code); | 1930 | 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[]) | |||
25 | 25 | ||
26 | if (argc == 1) { | 26 | if (argc == 1) { |
27 | /* deallocate all unused consoles */ | 27 | /* deallocate all unused consoles */ |
28 | if (ioctl(fd, VT_DISALLOCATE, 0)) { | 28 | if (ioctl(fd, VT_DISALLOCATE, 0)) |
29 | perror("VT_DISALLOCATE"); | 29 | perror_msg_and_die("VT_DISALLOCATE"); |
30 | return EXIT_FAILURE; | ||
31 | } | ||
32 | } else { | 30 | } else { |
33 | for (i = 1; i < argc; i++) { | 31 | for (i = 1; i < argc; i++) { |
34 | num = atoi(argv[i]); | 32 | num = atoi(argv[i]); |
@@ -36,10 +34,8 @@ int deallocvt_main(int argc, char *argv[]) | |||
36 | error_msg("0: illegal VT number\n"); | 34 | error_msg("0: illegal VT number\n"); |
37 | else if (num == 1) | 35 | else if (num == 1) |
38 | error_msg("VT 1 cannot be deallocated\n"); | 36 | error_msg("VT 1 cannot be deallocated\n"); |
39 | else if (ioctl(fd, VT_DISALLOCATE, num)) { | 37 | else if (ioctl(fd, VT_DISALLOCATE, num)) |
40 | perror("VT_DISALLOCATE"); | 38 | perror_msg_and_die("VT_DISALLOCATE"); |
41 | error_msg_and_die("could not deallocate console %d\n", num); | ||
42 | } | ||
43 | } | 39 | } |
44 | } | 40 | } |
45 | 41 | ||
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) | |||
60 | int is_unicode; | 60 | int is_unicode; |
61 | 61 | ||
62 | if (fstat(fileno(fp), &stbuf)) | 62 | if (fstat(fileno(fp), &stbuf)) |
63 | perror("Cannot stat map file"), exit(1); | 63 | perror_msg_and_die("Cannot stat map file"); |
64 | 64 | ||
65 | /* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */ | 65 | /* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */ |
66 | if (! | 66 | if (! |
@@ -70,15 +70,13 @@ int screen_map_load(int fd, FILE * fp) | |||
70 | if (parse_failed) { | 70 | if (parse_failed) { |
71 | if (-1 == fseek(fp, 0, SEEK_SET)) { | 71 | if (-1 == fseek(fp, 0, SEEK_SET)) { |
72 | if (errno == ESPIPE) | 72 | if (errno == ESPIPE) |
73 | error_msg("16bit screen-map MUST be a regular file.\n"), | 73 | error_msg_and_die("16bit screen-map MUST be a regular file.\n"); |
74 | exit(1); | ||
75 | else | 74 | else |
76 | perror("fseek failed reading binary 16bit screen-map"), | 75 | perror_msg_and_die("fseek failed reading binary 16bit screen-map"); |
77 | exit(1); | ||
78 | } | 76 | } |
79 | 77 | ||
80 | if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) | 78 | if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) |
81 | perror("Cannot read [new] map from file"), exit(1); | 79 | perror_msg_and_die("Cannot read [new] map from file"); |
82 | #if 0 | 80 | #if 0 |
83 | else | 81 | else |
84 | error_msg("Input screen-map is binary.\n"); | 82 | error_msg("Input screen-map is binary.\n"); |
@@ -89,7 +87,7 @@ int screen_map_load(int fd, FILE * fp) | |||
89 | /* same if it was binary, ie. if parse_failed */ | 87 | /* same if it was binary, ie. if parse_failed */ |
90 | if (parse_failed || is_unicode) { | 88 | if (parse_failed || is_unicode) { |
91 | if (ioctl(fd, PIO_UNISCRNMAP, wbuf)) | 89 | if (ioctl(fd, PIO_UNISCRNMAP, wbuf)) |
92 | perror("PIO_UNISCRNMAP ioctl"), exit(1); | 90 | perror_msg_and_die("PIO_UNISCRNMAP ioctl"); |
93 | else | 91 | else |
94 | return 0; | 92 | return 0; |
95 | } | 93 | } |
@@ -101,7 +99,7 @@ int screen_map_load(int fd, FILE * fp) | |||
101 | error_msg("Assuming 8bit screen-map - MUST be a regular file.\n"), | 99 | error_msg("Assuming 8bit screen-map - MUST be a regular file.\n"), |
102 | exit(1); | 100 | exit(1); |
103 | else | 101 | else |
104 | perror("fseek failed assuming 8bit screen-map"), exit(1); | 102 | perror_msg_and_die("fseek failed assuming 8bit screen-map"); |
105 | } | 103 | } |
106 | 104 | ||
107 | /* ... and try an old 8-bit screen-map */ | 105 | /* ... and try an old 8-bit screen-map */ |
@@ -111,14 +109,13 @@ int screen_map_load(int fd, FILE * fp) | |||
111 | if (-1 == fseek(fp, 0, SEEK_SET)) { | 109 | if (-1 == fseek(fp, 0, SEEK_SET)) { |
112 | if (errno == ESPIPE) | 110 | if (errno == ESPIPE) |
113 | /* should not - it succedeed above */ | 111 | /* should not - it succedeed above */ |
114 | error_msg("fseek() returned ESPIPE !\n"), | 112 | error_msg_and_die("fseek() returned ESPIPE !\n"); |
115 | exit(1); | ||
116 | else | 113 | else |
117 | perror("fseek for binary 8bit screen-map"), exit(1); | 114 | perror_msg_and_die("fseek for binary 8bit screen-map"); |
118 | } | 115 | } |
119 | 116 | ||
120 | if (fread(buf, E_TABSZ, 1, fp) != 1) | 117 | if (fread(buf, E_TABSZ, 1, fp) != 1) |
121 | perror("Cannot read [old] map from file"), exit(1); | 118 | perror_msg_and_die("Cannot read [old] map from file"); |
122 | #if 0 | 119 | #if 0 |
123 | else | 120 | else |
124 | error_msg("Input screen-map is binary.\n"); | 121 | error_msg("Input screen-map is binary.\n"); |
@@ -126,7 +123,7 @@ int screen_map_load(int fd, FILE * fp) | |||
126 | } | 123 | } |
127 | 124 | ||
128 | if (ioctl(fd, PIO_SCRNMAP, buf)) | 125 | if (ioctl(fd, PIO_SCRNMAP, buf)) |
129 | perror("PIO_SCRNMAP ioctl"), exit(1); | 126 | perror_msg_and_die("PIO_SCRNMAP ioctl"); |
130 | else | 127 | else |
131 | return 0; | 128 | return 0; |
132 | } | 129 | } |
@@ -174,10 +171,8 @@ int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode) | |||
174 | if (NULL == fgets(buffer, sizeof(buffer), fp)) { | 171 | if (NULL == fgets(buffer, sizeof(buffer), fp)) { |
175 | if (feof(fp)) | 172 | if (feof(fp)) |
176 | break; | 173 | break; |
177 | else { | 174 | else |
178 | perror("uni_screen_map_read_ascii() can't read line"); | 175 | perror_msg_and_die("uni_screen_map_read_ascii() can't read line"); |
179 | exit(2); | ||
180 | } | ||
181 | } | 176 | } |
182 | 177 | ||
183 | /* get "charset-relative charcode", stripping leading spaces */ | 178 | /* get "charset-relative charcode", stripping leading spaces */ |
@@ -317,12 +312,11 @@ void saveoldmap(int fd, char *omfil) | |||
317 | int is_old_map = 0; | 312 | int is_old_map = 0; |
318 | 313 | ||
319 | if (ioctl(fd, GIO_UNISCRNMAP, xbuf)) { | 314 | if (ioctl(fd, GIO_UNISCRNMAP, xbuf)) { |
320 | perror("GIO_UNISCRNMAP ioctl error"); | 315 | perror_msg("GIO_UNISCRNMAP ioctl error"); |
321 | #endif | 316 | #endif |
322 | if (ioctl(fd, GIO_SCRNMAP, buf)) { | 317 | if (ioctl(fd, GIO_SCRNMAP, buf)) |
323 | perror("GIO_SCRNMAP ioctl error"); | 318 | perror_msg_and_die("GIO_SCRNMAP ioctl error"); |
324 | exit(1); | 319 | else |
325 | } else | ||
326 | is_old_map = 1; | 320 | is_old_map = 1; |
327 | #ifdef GIO_UNISCRNMAP | 321 | #ifdef GIO_UNISCRNMAP |
328 | } | 322 | } |
@@ -332,14 +326,11 @@ void saveoldmap(int fd, char *omfil) | |||
332 | #ifdef GIO_UNISCRNMAP | 326 | #ifdef GIO_UNISCRNMAP |
333 | if (is_old_map) { | 327 | if (is_old_map) { |
334 | #endif | 328 | #endif |
335 | if (fwrite(buf, E_TABSZ, 1, fp) != 1) { | 329 | if (fwrite(buf, E_TABSZ, 1, fp) != 1) |
336 | perror("Error writing map to file"); | 330 | perror_msg_and_die("Error writing map to file"); |
337 | exit(1); | ||
338 | } | ||
339 | #ifdef GIO_UNISCRNMAP | 331 | #ifdef GIO_UNISCRNMAP |
340 | } else if (fwrite(xbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) { | 332 | } else if (fwrite(xbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) { |
341 | perror("Error writing map to file"); | 333 | perror_msg_and_die("Error writing map to file"); |
342 | exit(1); | ||
343 | } | 334 | } |
344 | #endif | 335 | #endif |
345 | 336 | ||
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) | |||
53 | } | 53 | } |
54 | if (argc < 1 || *argv[0] == '-') | 54 | if (argc < 1 || *argv[0] == '-') |
55 | usage(mkfifo_usage); | 55 | usage(mkfifo_usage); |
56 | if (mkfifo(*argv, mode) < 0) { | 56 | if (mkfifo(*argv, mode) < 0) |
57 | perror("mkfifo"); | 57 | perror_msg_and_die("mkfifo"); |
58 | return EXIT_FAILURE; | ||
59 | } | ||
60 | return EXIT_SUCCESS; | 58 | return EXIT_SUCCESS; |
61 | } | 59 | } |
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) | |||
84 | mode |= perm; | 84 | mode |= perm; |
85 | 85 | ||
86 | if (mknod(argv[0], mode, dev) != 0) | 86 | if (mknod(argv[0], mode, dev) != 0) |
87 | error_msg_and_die("%s: %s\n", argv[0], strerror(errno)); | 87 | perror_msg_and_die("%s", argv[0]); |
88 | return EXIT_SUCCESS; | 88 | return EXIT_SUCCESS; |
89 | } | 89 | } |
90 | 90 | ||
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) | |||
30 | usage(sleep_usage); | 30 | usage(sleep_usage); |
31 | } | 31 | } |
32 | 32 | ||
33 | if (sleep(atoi(*(++argv))) != 0) { | 33 | if (sleep(atoi(*(++argv))) != 0) |
34 | perror("sleep"); | 34 | perror_msg_and_die("sleep"); |
35 | return EXIT_FAILURE; | ||
36 | } | ||
37 | return EXIT_SUCCESS; | 35 | return EXIT_SUCCESS; |
38 | } | 36 | } |
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) | |||
114 | toprint = PRINT_SYSNAME; | 114 | toprint = PRINT_SYSNAME; |
115 | 115 | ||
116 | if (uname(&name) == -1) | 116 | if (uname(&name) == -1) |
117 | perror("cannot get system name"); | 117 | perror_msg("cannot get system name"); |
118 | 118 | ||
119 | #if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE) | 119 | #if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE) |
120 | if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1) | 120 | if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1) |
121 | perror("cannot get processor type"); | 121 | perror_msg("cannot get processor type"); |
122 | } | 122 | } |
123 | 123 | ||
124 | #else | 124 | #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[]) | |||
25 | 25 | ||
26 | if (argc == 1) { | 26 | if (argc == 1) { |
27 | /* deallocate all unused consoles */ | 27 | /* deallocate all unused consoles */ |
28 | if (ioctl(fd, VT_DISALLOCATE, 0)) { | 28 | if (ioctl(fd, VT_DISALLOCATE, 0)) |
29 | perror("VT_DISALLOCATE"); | 29 | perror_msg_and_die("VT_DISALLOCATE"); |
30 | return EXIT_FAILURE; | ||
31 | } | ||
32 | } else { | 30 | } else { |
33 | for (i = 1; i < argc; i++) { | 31 | for (i = 1; i < argc; i++) { |
34 | num = atoi(argv[i]); | 32 | num = atoi(argv[i]); |
@@ -36,10 +34,8 @@ int deallocvt_main(int argc, char *argv[]) | |||
36 | error_msg("0: illegal VT number\n"); | 34 | error_msg("0: illegal VT number\n"); |
37 | else if (num == 1) | 35 | else if (num == 1) |
38 | error_msg("VT 1 cannot be deallocated\n"); | 36 | error_msg("VT 1 cannot be deallocated\n"); |
39 | else if (ioctl(fd, VT_DISALLOCATE, num)) { | 37 | else if (ioctl(fd, VT_DISALLOCATE, num)) |
40 | perror("VT_DISALLOCATE"); | 38 | perror_msg_and_die("VT_DISALLOCATE"); |
41 | error_msg_and_die("could not deallocate console %d\n", num); | ||
42 | } | ||
43 | } | 39 | } |
44 | } | 40 | } |
45 | 41 | ||
@@ -69,20 +69,16 @@ int dmesg_main(int argc, char **argv) | |||
69 | } | 69 | } |
70 | 70 | ||
71 | if (cmd == 8) { | 71 | if (cmd == 8) { |
72 | n = klogctl(cmd, NULL, level); | 72 | if (klogctl(cmd, NULL, level) < 0) |
73 | if (n < 0) { | 73 | perror_msg_and_die("klogctl"); |
74 | goto klogctl_error; | ||
75 | } | ||
76 | return EXIT_SUCCESS; | 74 | return EXIT_SUCCESS; |
77 | } | 75 | } |
78 | 76 | ||
79 | if (bufsize < 4096) | 77 | if (bufsize < 4096) |
80 | bufsize = 4096; | 78 | bufsize = 4096; |
81 | buf = (char *) xmalloc(bufsize); | 79 | buf = (char *) xmalloc(bufsize); |
82 | n = klogctl(cmd, buf, bufsize); | 80 | if ((n = klogctl(cmd, buf, bufsize)) < 0) |
83 | if (n < 0) { | 81 | perror_msg_and_die("klogctl"); |
84 | goto klogctl_error; | ||
85 | } | ||
86 | 82 | ||
87 | lastc = '\n'; | 83 | lastc = '\n'; |
88 | for (i = 0; i < n; i++) { | 84 | for (i = 0; i < n; i++) { |
@@ -102,7 +98,4 @@ int dmesg_main(int argc, char **argv) | |||
102 | end: | 98 | end: |
103 | usage(dmesg_usage); | 99 | usage(dmesg_usage); |
104 | return EXIT_FAILURE; | 100 | return EXIT_FAILURE; |
105 | klogctl_error: | ||
106 | perror("klogctl"); | ||
107 | return EXIT_FAILURE; | ||
108 | } | 101 | } |
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) | |||
709 | 709 | ||
710 | #ifdef BB_FEATURE_CLEAN_UP | 710 | #ifdef BB_FEATURE_CLEAN_UP |
711 | /* destroy command strings on exit */ | 711 | /* destroy command strings on exit */ |
712 | if (atexit(destroy_cmd_strs) == -1) { | 712 | if (atexit(destroy_cmd_strs) == -1) |
713 | perror("sed"); | 713 | perror_msg_and_die("atexit"); |
714 | exit(1); | ||
715 | } | ||
716 | #endif | 714 | #endif |
717 | 715 | ||
718 | /* do normal option parsing */ | 716 | /* do normal option parsing */ |
@@ -33,8 +33,6 @@ | |||
33 | #include <ctype.h> | 33 | #include <ctype.h> |
34 | #include <sys/ioctl.h> | 34 | #include <sys/ioctl.h> |
35 | 35 | ||
36 | #define PERROR(ctx) do { perror(ctx); exit(1); } while(0) | ||
37 | |||
38 | #define DEFAULTFBDEV "/dev/fb0" | 36 | #define DEFAULTFBDEV "/dev/fb0" |
39 | #define DEFAULTFBMODE "/etc/fb.modes" | 37 | #define DEFAULTFBMODE "/etc/fb.modes" |
40 | 38 | ||
@@ -198,7 +196,7 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn, | |||
198 | char *p = buf; | 196 | char *p = buf; |
199 | 197 | ||
200 | if ((f = fopen(fn, "r")) == NULL) | 198 | if ((f = fopen(fn, "r")) == NULL) |
201 | PERROR("readmode(fopen)"); | 199 | perror_msg_and_die("readmode(fopen)"); |
202 | while (!feof(f)) { | 200 | while (!feof(f)) { |
203 | fgets(buf, sizeof(buf), f); | 201 | fgets(buf, sizeof(buf), f); |
204 | if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) { | 202 | if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) { |
@@ -428,9 +426,9 @@ extern int fbset_main(int argc, char **argv) | |||
428 | } | 426 | } |
429 | 427 | ||
430 | if ((fh = open(fbdev, O_RDONLY)) < 0) | 428 | if ((fh = open(fbdev, O_RDONLY)) < 0) |
431 | PERROR("fbset(open)"); | 429 | perror_msg_and_die("fbset(open)"); |
432 | if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) | 430 | if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) |
433 | PERROR("fbset(ioctl)"); | 431 | perror_msg_and_die("fbset(ioctl)"); |
434 | if (g_options & OPT_READMODE) { | 432 | if (g_options & OPT_READMODE) { |
435 | if (!readmode(&var, modefile, mode)) { | 433 | if (!readmode(&var, modefile, mode)) { |
436 | error_msg("Unknown video mode `%s'\n", mode); | 434 | error_msg("Unknown video mode `%s'\n", mode); |
@@ -441,7 +439,7 @@ extern int fbset_main(int argc, char **argv) | |||
441 | setmode(&var, &varset); | 439 | setmode(&var, &varset); |
442 | if (g_options & OPT_CHANGE) | 440 | if (g_options & OPT_CHANGE) |
443 | if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) | 441 | if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) |
444 | PERROR("fbset(ioctl)"); | 442 | perror_msg_and_die("fbset(ioctl)"); |
445 | showmode(&var); | 443 | showmode(&var); |
446 | /* Don't close the file, as exiting will take care of that */ | 444 | /* Don't close the file, as exiting will take care of that */ |
447 | /* close(fh); */ | 445 | /* close(fh); */ |
@@ -31,26 +31,16 @@ | |||
31 | 31 | ||
32 | extern int fdflush_main(int argc, char **argv) | 32 | extern int fdflush_main(int argc, char **argv) |
33 | { | 33 | { |
34 | int value; | ||
35 | int fd; | 34 | int fd; |
36 | 35 | ||
37 | if (argc <= 1 || **(++argv) == '-') | 36 | if (argc <= 1 || **(++argv) == '-') |
38 | usage(fdflush_usage); | 37 | usage(fdflush_usage); |
39 | 38 | ||
40 | fd = open(*argv, 0); | 39 | if ((fd = open(*argv, 0)) < 0) |
41 | if (fd < 0) { | 40 | perror_msg_and_die("%s", *argv); |
42 | perror(*argv); | ||
43 | return EXIT_FAILURE; | ||
44 | } | ||
45 | 41 | ||
46 | value = ioctl(fd, FDFLUSH, 0); | 42 | if (ioctl(fd, FDFLUSH, 0)) |
47 | /* Don't bother closing. Exit does | 43 | perror_msg_and_die("%s", *argv); |
48 | * that, so we can save a few bytes */ | ||
49 | /* close(fd); */ | ||
50 | 44 | ||
51 | if (value) { | ||
52 | perror(*argv); | ||
53 | return EXIT_FAILURE; | ||
54 | } | ||
55 | return EXIT_SUCCESS; | 45 | return EXIT_SUCCESS; |
56 | } | 46 | } |
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) | |||
81 | strcat(execstr, cmd_to_be_executed); | 81 | strcat(execstr, cmd_to_be_executed); |
82 | strcat(execstr, file_to_act_on); | 82 | strcat(execstr, file_to_act_on); |
83 | cmd_output = popen(execstr, "r"); | 83 | cmd_output = popen(execstr, "r"); |
84 | if (cmd_output == NULL) { | 84 | if (cmd_output == NULL) |
85 | perror("popen"); | 85 | perror_msg_and_die("popen"); |
86 | exit(1); | ||
87 | } | ||
88 | 86 | ||
89 | /* harvest the output */ | 87 | /* harvest the output */ |
90 | while ((output_line = get_line_from_file(cmd_output)) != NULL) { | 88 | while ((output_line = get_line_from_file(cmd_output)) != NULL) { |
@@ -1867,18 +1867,13 @@ int gzip_main(int argc, char **argv) | |||
1867 | usage(gzip_usage); | 1867 | usage(gzip_usage); |
1868 | strncpy(ifname, *argv, MAX_PATH_LEN); | 1868 | strncpy(ifname, *argv, MAX_PATH_LEN); |
1869 | 1869 | ||
1870 | /* Open input fille */ | 1870 | /* Open input file */ |
1871 | inFileNum = open(ifname, O_RDONLY); | 1871 | inFileNum = open(ifname, O_RDONLY); |
1872 | if (inFileNum < 0) { | 1872 | if (inFileNum < 0) |
1873 | perror(ifname); | 1873 | perror_msg_and_die("%s", ifname); |
1874 | exit(WARNING); | ||
1875 | } | ||
1876 | /* Get the time stamp on the input file. */ | 1874 | /* Get the time stamp on the input file. */ |
1877 | result = stat(ifname, &statBuf); | 1875 | if (stat(ifname, &statBuf) < 0) |
1878 | if (result < 0) { | 1876 | perror_msg_and_die("%s", ifname); |
1879 | perror(ifname); | ||
1880 | exit(WARNING); | ||
1881 | } | ||
1882 | time_stamp = statBuf.st_ctime; | 1877 | time_stamp = statBuf.st_ctime; |
1883 | ifile_size = statBuf.st_size; | 1878 | ifile_size = statBuf.st_size; |
1884 | } | 1879 | } |
@@ -1909,10 +1904,8 @@ int gzip_main(int argc, char **argv) | |||
1909 | #else | 1904 | #else |
1910 | outFileNum = open(ofname, O_RDWR | O_CREAT | O_EXCL); | 1905 | outFileNum = open(ofname, O_RDWR | O_CREAT | O_EXCL); |
1911 | #endif | 1906 | #endif |
1912 | if (outFileNum < 0) { | 1907 | if (outFileNum < 0) |
1913 | perror(ofname); | 1908 | perror_msg_and_die("%s", ofname); |
1914 | exit(WARNING); | ||
1915 | } | ||
1916 | SET_BINARY_MODE(outFileNum); | 1909 | SET_BINARY_MODE(outFileNum); |
1917 | /* Set permissions on the file */ | 1910 | /* Set permissions on the file */ |
1918 | fchmod(outFileNum, statBuf.st_mode); | 1911 | fchmod(outFileNum, statBuf.st_mode); |
@@ -1930,10 +1923,8 @@ int gzip_main(int argc, char **argv) | |||
1930 | else | 1923 | else |
1931 | delFileName = ofname; | 1924 | delFileName = ofname; |
1932 | 1925 | ||
1933 | if (unlink(delFileName) < 0) { | 1926 | if (unlink(delFileName) < 0) |
1934 | perror(delFileName); | 1927 | perror_msg_and_die("%s", delFileName); |
1935 | exit(EXIT_FAILURE); | ||
1936 | } | ||
1937 | } | 1928 | } |
1938 | 1929 | ||
1939 | return(exit_code); | 1930 | 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 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * $Id: hostname.c,v 1.16 2000/12/07 19:56:48 markw Exp $ | 3 | * $Id: hostname.c,v 1.17 2000/12/22 01:48:07 kraai Exp $ |
4 | * Mini hostname implementation for busybox | 4 | * Mini hostname implementation for busybox |
5 | * | 5 | * |
6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
@@ -40,10 +40,9 @@ void do_sethostname(char *s, int isfile) | |||
40 | if (!isfile) { | 40 | if (!isfile) { |
41 | if (sethostname(s, strlen(s)) < 0) { | 41 | if (sethostname(s, strlen(s)) < 0) { |
42 | if (errno == EPERM) | 42 | if (errno == EPERM) |
43 | error_msg("you must be root to change the hostname\n"); | 43 | error_msg_and_die("you must be root to change the hostname\n"); |
44 | else | 44 | else |
45 | perror("sethostname"); | 45 | perror_msg_and_die("sethostname"); |
46 | exit(1); | ||
47 | } | 46 | } |
48 | } else { | 47 | } else { |
49 | f = xfopen(s, "r"); | 48 | f = xfopen(s, "r"); |
@@ -51,10 +50,8 @@ void do_sethostname(char *s, int isfile) | |||
51 | fclose(f); | 50 | fclose(f); |
52 | if (buf[strlen(buf) - 1] == '\n') | 51 | if (buf[strlen(buf) - 1] == '\n') |
53 | buf[strlen(buf) - 1] = 0; | 52 | buf[strlen(buf) - 1] = 0; |
54 | if (sethostname(buf, strlen(buf)) < 0) { | 53 | if (sethostname(buf, strlen(buf)) < 0) |
55 | perror("sethostname"); | 54 | perror_msg_and_die("sethostname"); |
56 | exit(1); | ||
57 | } | ||
58 | } | 55 | } |
59 | } | 56 | } |
60 | 57 | ||
@@ -78,7 +78,7 @@ | |||
78 | #ifndef MODUTILS_MODULE_H | 78 | #ifndef MODUTILS_MODULE_H |
79 | #define MODUTILS_MODULE_H 1 | 79 | #define MODUTILS_MODULE_H 1 |
80 | 80 | ||
81 | #ident "$Id: insmod.c,v 1.33 2000/12/18 03:57:16 kraai Exp $" | 81 | #ident "$Id: insmod.c,v 1.34 2000/12/22 01:48:07 kraai Exp $" |
82 | 82 | ||
83 | /* This file contains the structures used by the 2.0 and 2.1 kernels. | 83 | /* This file contains the structures used by the 2.0 and 2.1 kernels. |
84 | We do not use the kernel headers directly because we do not wish | 84 | We do not use the kernel headers directly because we do not wish |
@@ -284,7 +284,7 @@ int delete_module(const char *); | |||
284 | #ifndef MODUTILS_OBJ_H | 284 | #ifndef MODUTILS_OBJ_H |
285 | #define MODUTILS_OBJ_H 1 | 285 | #define MODUTILS_OBJ_H 1 |
286 | 286 | ||
287 | #ident "$Id: insmod.c,v 1.33 2000/12/18 03:57:16 kraai Exp $" | 287 | #ident "$Id: insmod.c,v 1.34 2000/12/22 01:48:07 kraai Exp $" |
288 | 288 | ||
289 | /* The relocatable object is manipulated using elfin types. */ | 289 | /* The relocatable object is manipulated using elfin types. */ |
290 | 290 | ||
@@ -2952,10 +2952,8 @@ extern int insmod_main( int argc, char **argv) | |||
2952 | memcpy(m_filename, *argv, strlen(*argv)); | 2952 | memcpy(m_filename, *argv, strlen(*argv)); |
2953 | 2953 | ||
2954 | 2954 | ||
2955 | if ((f = obj_load(fp)) == NULL) { | 2955 | if ((f = obj_load(fp)) == NULL) |
2956 | perror("Could not load the module\n"); | 2956 | perror_msg_and_die("Could not load the module"); |
2957 | return EXIT_FAILURE; | ||
2958 | } | ||
2959 | 2957 | ||
2960 | if (get_modinfo_value(f, "kernel_version") == NULL) | 2958 | if (get_modinfo_value(f, "kernel_version") == NULL) |
2961 | m_has_modinfo = 0; | 2959 | m_has_modinfo = 0; |
@@ -344,7 +344,7 @@ static int builtin_fg_bg(struct child_prog *child) | |||
344 | /* Make this job the foreground job */ | 344 | /* Make this job the foreground job */ |
345 | /* suppress messages when run from /linuxrc mag@sysgo.de */ | 345 | /* suppress messages when run from /linuxrc mag@sysgo.de */ |
346 | if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY) | 346 | if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY) |
347 | perror("tcsetpgrp"); | 347 | perror_msg("tcsetpgrp"); |
348 | child->family->job_list->fg = job; | 348 | child->family->job_list->fg = job; |
349 | } | 349 | } |
350 | 350 | ||
@@ -683,7 +683,7 @@ static void checkjobs(struct jobset *job_list) | |||
683 | } | 683 | } |
684 | 684 | ||
685 | if (childpid == -1 && errno != ECHILD) | 685 | if (childpid == -1 && errno != ECHILD) |
686 | perror("waitpid"); | 686 | perror_msg("waitpid"); |
687 | } | 687 | } |
688 | 688 | ||
689 | /* squirrel != NULL means we squirrel away copies of stdin, stdout, | 689 | /* squirrel != NULL means we squirrel away copies of stdin, stdout, |
@@ -1422,7 +1422,7 @@ static void insert_job(struct job *newjob, int inbg) | |||
1422 | /* move the new process group into the foreground */ | 1422 | /* move the new process group into the foreground */ |
1423 | /* suppress messages when run from /linuxrc mag@sysgo.de */ | 1423 | /* suppress messages when run from /linuxrc mag@sysgo.de */ |
1424 | if (tcsetpgrp(0, newjob->pgrp) && errno != ENOTTY) | 1424 | if (tcsetpgrp(0, newjob->pgrp) && errno != ENOTTY) |
1425 | perror("tcsetpgrp"); | 1425 | perror_msg("tcsetpgrp"); |
1426 | } | 1426 | } |
1427 | } | 1427 | } |
1428 | 1428 | ||
@@ -1612,7 +1612,7 @@ static int busy_loop(FILE * input) | |||
1612 | /* move the shell to the foreground */ | 1612 | /* move the shell to the foreground */ |
1613 | /* suppress messages when run from /linuxrc mag@sysgo.de */ | 1613 | /* suppress messages when run from /linuxrc mag@sysgo.de */ |
1614 | if (tcsetpgrp(0, getpid()) && errno != ENOTTY) | 1614 | if (tcsetpgrp(0, getpid()) && errno != ENOTTY) |
1615 | perror("tcsetpgrp"); | 1615 | perror_msg("tcsetpgrp"); |
1616 | } | 1616 | } |
1617 | } | 1617 | } |
1618 | } | 1618 | } |
@@ -1620,7 +1620,7 @@ static int busy_loop(FILE * input) | |||
1620 | 1620 | ||
1621 | /* return controlling TTY back to parent process group before exiting */ | 1621 | /* return controlling TTY back to parent process group before exiting */ |
1622 | if (tcsetpgrp(0, parent_pgrp)) | 1622 | if (tcsetpgrp(0, parent_pgrp)) |
1623 | perror("tcsetpgrp"); | 1623 | perror_msg("tcsetpgrp"); |
1624 | 1624 | ||
1625 | /* return exit status if called with "-c" */ | 1625 | /* return exit status if called with "-c" */ |
1626 | if (input == NULL && WIFEXITED(status)) | 1626 | if (input == NULL && WIFEXITED(status)) |
@@ -60,7 +60,7 @@ int screen_map_load(int fd, FILE * fp) | |||
60 | int is_unicode; | 60 | int is_unicode; |
61 | 61 | ||
62 | if (fstat(fileno(fp), &stbuf)) | 62 | if (fstat(fileno(fp), &stbuf)) |
63 | perror("Cannot stat map file"), exit(1); | 63 | perror_msg_and_die("Cannot stat map file"); |
64 | 64 | ||
65 | /* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */ | 65 | /* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */ |
66 | if (! | 66 | if (! |
@@ -70,15 +70,13 @@ int screen_map_load(int fd, FILE * fp) | |||
70 | if (parse_failed) { | 70 | if (parse_failed) { |
71 | if (-1 == fseek(fp, 0, SEEK_SET)) { | 71 | if (-1 == fseek(fp, 0, SEEK_SET)) { |
72 | if (errno == ESPIPE) | 72 | if (errno == ESPIPE) |
73 | error_msg("16bit screen-map MUST be a regular file.\n"), | 73 | error_msg_and_die("16bit screen-map MUST be a regular file.\n"); |
74 | exit(1); | ||
75 | else | 74 | else |
76 | perror("fseek failed reading binary 16bit screen-map"), | 75 | perror_msg_and_die("fseek failed reading binary 16bit screen-map"); |
77 | exit(1); | ||
78 | } | 76 | } |
79 | 77 | ||
80 | if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) | 78 | if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) |
81 | perror("Cannot read [new] map from file"), exit(1); | 79 | perror_msg_and_die("Cannot read [new] map from file"); |
82 | #if 0 | 80 | #if 0 |
83 | else | 81 | else |
84 | error_msg("Input screen-map is binary.\n"); | 82 | error_msg("Input screen-map is binary.\n"); |
@@ -89,7 +87,7 @@ int screen_map_load(int fd, FILE * fp) | |||
89 | /* same if it was binary, ie. if parse_failed */ | 87 | /* same if it was binary, ie. if parse_failed */ |
90 | if (parse_failed || is_unicode) { | 88 | if (parse_failed || is_unicode) { |
91 | if (ioctl(fd, PIO_UNISCRNMAP, wbuf)) | 89 | if (ioctl(fd, PIO_UNISCRNMAP, wbuf)) |
92 | perror("PIO_UNISCRNMAP ioctl"), exit(1); | 90 | perror_msg_and_die("PIO_UNISCRNMAP ioctl"); |
93 | else | 91 | else |
94 | return 0; | 92 | return 0; |
95 | } | 93 | } |
@@ -101,7 +99,7 @@ int screen_map_load(int fd, FILE * fp) | |||
101 | error_msg("Assuming 8bit screen-map - MUST be a regular file.\n"), | 99 | error_msg("Assuming 8bit screen-map - MUST be a regular file.\n"), |
102 | exit(1); | 100 | exit(1); |
103 | else | 101 | else |
104 | perror("fseek failed assuming 8bit screen-map"), exit(1); | 102 | perror_msg_and_die("fseek failed assuming 8bit screen-map"); |
105 | } | 103 | } |
106 | 104 | ||
107 | /* ... and try an old 8-bit screen-map */ | 105 | /* ... and try an old 8-bit screen-map */ |
@@ -111,14 +109,13 @@ int screen_map_load(int fd, FILE * fp) | |||
111 | if (-1 == fseek(fp, 0, SEEK_SET)) { | 109 | if (-1 == fseek(fp, 0, SEEK_SET)) { |
112 | if (errno == ESPIPE) | 110 | if (errno == ESPIPE) |
113 | /* should not - it succedeed above */ | 111 | /* should not - it succedeed above */ |
114 | error_msg("fseek() returned ESPIPE !\n"), | 112 | error_msg_and_die("fseek() returned ESPIPE !\n"); |
115 | exit(1); | ||
116 | else | 113 | else |
117 | perror("fseek for binary 8bit screen-map"), exit(1); | 114 | perror_msg_and_die("fseek for binary 8bit screen-map"); |
118 | } | 115 | } |
119 | 116 | ||
120 | if (fread(buf, E_TABSZ, 1, fp) != 1) | 117 | if (fread(buf, E_TABSZ, 1, fp) != 1) |
121 | perror("Cannot read [old] map from file"), exit(1); | 118 | perror_msg_and_die("Cannot read [old] map from file"); |
122 | #if 0 | 119 | #if 0 |
123 | else | 120 | else |
124 | error_msg("Input screen-map is binary.\n"); | 121 | error_msg("Input screen-map is binary.\n"); |
@@ -126,7 +123,7 @@ int screen_map_load(int fd, FILE * fp) | |||
126 | } | 123 | } |
127 | 124 | ||
128 | if (ioctl(fd, PIO_SCRNMAP, buf)) | 125 | if (ioctl(fd, PIO_SCRNMAP, buf)) |
129 | perror("PIO_SCRNMAP ioctl"), exit(1); | 126 | perror_msg_and_die("PIO_SCRNMAP ioctl"); |
130 | else | 127 | else |
131 | return 0; | 128 | return 0; |
132 | } | 129 | } |
@@ -174,10 +171,8 @@ int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode) | |||
174 | if (NULL == fgets(buffer, sizeof(buffer), fp)) { | 171 | if (NULL == fgets(buffer, sizeof(buffer), fp)) { |
175 | if (feof(fp)) | 172 | if (feof(fp)) |
176 | break; | 173 | break; |
177 | else { | 174 | else |
178 | perror("uni_screen_map_read_ascii() can't read line"); | 175 | perror_msg_and_die("uni_screen_map_read_ascii() can't read line"); |
179 | exit(2); | ||
180 | } | ||
181 | } | 176 | } |
182 | 177 | ||
183 | /* get "charset-relative charcode", stripping leading spaces */ | 178 | /* get "charset-relative charcode", stripping leading spaces */ |
@@ -317,12 +312,11 @@ void saveoldmap(int fd, char *omfil) | |||
317 | int is_old_map = 0; | 312 | int is_old_map = 0; |
318 | 313 | ||
319 | if (ioctl(fd, GIO_UNISCRNMAP, xbuf)) { | 314 | if (ioctl(fd, GIO_UNISCRNMAP, xbuf)) { |
320 | perror("GIO_UNISCRNMAP ioctl error"); | 315 | perror_msg("GIO_UNISCRNMAP ioctl error"); |
321 | #endif | 316 | #endif |
322 | if (ioctl(fd, GIO_SCRNMAP, buf)) { | 317 | if (ioctl(fd, GIO_SCRNMAP, buf)) |
323 | perror("GIO_SCRNMAP ioctl error"); | 318 | perror_msg_and_die("GIO_SCRNMAP ioctl error"); |
324 | exit(1); | 319 | else |
325 | } else | ||
326 | is_old_map = 1; | 320 | is_old_map = 1; |
327 | #ifdef GIO_UNISCRNMAP | 321 | #ifdef GIO_UNISCRNMAP |
328 | } | 322 | } |
@@ -332,14 +326,11 @@ void saveoldmap(int fd, char *omfil) | |||
332 | #ifdef GIO_UNISCRNMAP | 326 | #ifdef GIO_UNISCRNMAP |
333 | if (is_old_map) { | 327 | if (is_old_map) { |
334 | #endif | 328 | #endif |
335 | if (fwrite(buf, E_TABSZ, 1, fp) != 1) { | 329 | if (fwrite(buf, E_TABSZ, 1, fp) != 1) |
336 | perror("Error writing map to file"); | 330 | perror_msg_and_die("Error writing map to file"); |
337 | exit(1); | ||
338 | } | ||
339 | #ifdef GIO_UNISCRNMAP | 331 | #ifdef GIO_UNISCRNMAP |
340 | } else if (fwrite(xbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) { | 332 | } else if (fwrite(xbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) { |
341 | perror("Error writing map to file"); | 333 | perror_msg_and_die("Error writing map to file"); |
342 | exit(1); | ||
343 | } | 334 | } |
344 | #endif | 335 | #endif |
345 | 336 | ||
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) | |||
85 | else | 85 | else |
86 | op.mt_count = 1; /* One, not zero, right? */ | 86 | op.mt_count = 1; /* One, not zero, right? */ |
87 | 87 | ||
88 | if ((fd = open(file, O_RDONLY, 0)) < 0) { | 88 | if ((fd = open(file, O_RDONLY, 0)) < 0) |
89 | perror(file); | 89 | perror_msg_and_die("%s", file); |
90 | return EXIT_FAILURE; | ||
91 | } | ||
92 | 90 | ||
93 | if (ioctl(fd, MTIOCTOP, &op) != 0) { | 91 | if (ioctl(fd, MTIOCTOP, &op) != 0) |
94 | perror(file); | 92 | perror_msg_and_die("%s", file); |
95 | return EXIT_FAILURE; | ||
96 | } | ||
97 | 93 | ||
98 | return EXIT_SUCCESS; | 94 | return EXIT_SUCCESS; |
99 | } | 95 | } |
@@ -53,9 +53,7 @@ extern int mkfifo_main(int argc, char **argv) | |||
53 | } | 53 | } |
54 | if (argc < 1 || *argv[0] == '-') | 54 | if (argc < 1 || *argv[0] == '-') |
55 | usage(mkfifo_usage); | 55 | usage(mkfifo_usage); |
56 | if (mkfifo(*argv, mode) < 0) { | 56 | if (mkfifo(*argv, mode) < 0) |
57 | perror("mkfifo"); | 57 | perror_msg_and_die("mkfifo"); |
58 | return EXIT_FAILURE; | ||
59 | } | ||
60 | return EXIT_SUCCESS; | 58 | return EXIT_SUCCESS; |
61 | } | 59 | } |
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) | |||
329 | int fd; | 329 | int fd; |
330 | long size; | 330 | long size; |
331 | 331 | ||
332 | fd = open(file, O_RDWR); | 332 | if ((fd = open(file, O_RDWR)) < 0) |
333 | if (fd < 0) { | 333 | perror_msg_and_die("%s", file); |
334 | perror(file); | ||
335 | exit(1); | ||
336 | } | ||
337 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { | 334 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { |
338 | close(fd); | 335 | close(fd); |
339 | return (size * 512); | 336 | return (size * 512); |
@@ -84,7 +84,7 @@ int mknod_main(int argc, char **argv) | |||
84 | mode |= perm; | 84 | mode |= perm; |
85 | 85 | ||
86 | if (mknod(argv[0], mode, dev) != 0) | 86 | if (mknod(argv[0], mode, dev) != 0) |
87 | error_msg_and_die("%s: %s\n", argv[0], strerror(errno)); | 87 | perror_msg_and_die("%s", argv[0]); |
88 | return EXIT_SUCCESS; | 88 | return EXIT_SUCCESS; |
89 | } | 89 | } |
90 | 90 | ||
@@ -260,11 +260,8 @@ static long get_size(const char *file) | |||
260 | int fd; | 260 | int fd; |
261 | long size; | 261 | long size; |
262 | 262 | ||
263 | fd = open(file, O_RDONLY); | 263 | if ((fd = open(file, O_RDONLY)) < 0) |
264 | if (fd < 0) { | 264 | perror_msg_and_die("%s", file); |
265 | perror(file); | ||
266 | exit(1); | ||
267 | } | ||
268 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { | 265 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { |
269 | int sectors_per_page = pagesize / 512; | 266 | int sectors_per_page = pagesize / 512; |
270 | 267 | ||
@@ -367,10 +364,8 @@ int mkswap_main(int argc, char **argv) | |||
367 | } | 364 | } |
368 | 365 | ||
369 | DEV = open(device_name, O_RDWR); | 366 | DEV = open(device_name, O_RDWR); |
370 | if (DEV < 0 || fstat(DEV, &statbuf) < 0) { | 367 | if (DEV < 0 || fstat(DEV, &statbuf) < 0) |
371 | perror(device_name); | 368 | perror_msg_and_die("%s", device_name); |
372 | return EXIT_FAILURE; | ||
373 | } | ||
374 | if (!S_ISBLK(statbuf.st_mode)) | 369 | if (!S_ISBLK(statbuf.st_mode)) |
375 | check = 0; | 370 | check = 0; |
376 | else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) | 371 | 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 @@ | |||
78 | #ifndef MODUTILS_MODULE_H | 78 | #ifndef MODUTILS_MODULE_H |
79 | #define MODUTILS_MODULE_H 1 | 79 | #define MODUTILS_MODULE_H 1 |
80 | 80 | ||
81 | #ident "$Id: insmod.c,v 1.33 2000/12/18 03:57:16 kraai Exp $" | 81 | #ident "$Id: insmod.c,v 1.34 2000/12/22 01:48:07 kraai Exp $" |
82 | 82 | ||
83 | /* This file contains the structures used by the 2.0 and 2.1 kernels. | 83 | /* This file contains the structures used by the 2.0 and 2.1 kernels. |
84 | We do not use the kernel headers directly because we do not wish | 84 | We do not use the kernel headers directly because we do not wish |
@@ -284,7 +284,7 @@ int delete_module(const char *); | |||
284 | #ifndef MODUTILS_OBJ_H | 284 | #ifndef MODUTILS_OBJ_H |
285 | #define MODUTILS_OBJ_H 1 | 285 | #define MODUTILS_OBJ_H 1 |
286 | 286 | ||
287 | #ident "$Id: insmod.c,v 1.33 2000/12/18 03:57:16 kraai Exp $" | 287 | #ident "$Id: insmod.c,v 1.34 2000/12/22 01:48:07 kraai Exp $" |
288 | 288 | ||
289 | /* The relocatable object is manipulated using elfin types. */ | 289 | /* The relocatable object is manipulated using elfin types. */ |
290 | 290 | ||
@@ -2952,10 +2952,8 @@ extern int insmod_main( int argc, char **argv) | |||
2952 | memcpy(m_filename, *argv, strlen(*argv)); | 2952 | memcpy(m_filename, *argv, strlen(*argv)); |
2953 | 2953 | ||
2954 | 2954 | ||
2955 | if ((f = obj_load(fp)) == NULL) { | 2955 | if ((f = obj_load(fp)) == NULL) |
2956 | perror("Could not load the module\n"); | 2956 | perror_msg_and_die("Could not load the module"); |
2957 | return EXIT_FAILURE; | ||
2958 | } | ||
2959 | 2957 | ||
2960 | if (get_modinfo_value(f, "kernel_version") == NULL) | 2958 | if (get_modinfo_value(f, "kernel_version") == NULL) |
2961 | m_has_modinfo = 0; | 2959 | 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) | |||
45 | switch (**argv) { | 45 | switch (**argv) { |
46 | case 'a': | 46 | case 'a': |
47 | /* Unload _all_ unused modules via NULL delete_module() call */ | 47 | /* Unload _all_ unused modules via NULL delete_module() call */ |
48 | if (delete_module(NULL)) { | 48 | if (delete_module(NULL)) |
49 | perror("rmmod"); | 49 | perror_msg_and_die("rmmod"); |
50 | return EXIT_FAILURE; | ||
51 | } | ||
52 | return EXIT_SUCCESS; | 50 | return EXIT_SUCCESS; |
53 | default: | 51 | default: |
54 | usage(rmmod_usage); | 52 | usage(rmmod_usage); |
@@ -58,7 +56,7 @@ extern int rmmod_main(int argc, char **argv) | |||
58 | 56 | ||
59 | while (argc-- > 0) { | 57 | while (argc-- > 0) { |
60 | if (delete_module(*argv) < 0) { | 58 | if (delete_module(*argv) < 0) { |
61 | perror(*argv); | 59 | perror_msg("%s", *argv); |
62 | ret = EXIT_FAILURE; | 60 | ret = EXIT_FAILURE; |
63 | } | 61 | } |
64 | argv++; | 62 | argv++; |
@@ -383,7 +383,7 @@ extern int mount_main(int argc, char **argv) | |||
383 | } | 383 | } |
384 | endmntent(mountTable); | 384 | endmntent(mountTable); |
385 | } else { | 385 | } else { |
386 | perror(mtab_file); | 386 | perror_msg_and_die("%s", mtab_file); |
387 | } | 387 | } |
388 | return EXIT_SUCCESS; | 388 | return EXIT_SUCCESS; |
389 | } | 389 | } |
@@ -85,15 +85,11 @@ extern int mt_main(int argc, char **argv) | |||
85 | else | 85 | else |
86 | op.mt_count = 1; /* One, not zero, right? */ | 86 | op.mt_count = 1; /* One, not zero, right? */ |
87 | 87 | ||
88 | if ((fd = open(file, O_RDONLY, 0)) < 0) { | 88 | if ((fd = open(file, O_RDONLY, 0)) < 0) |
89 | perror(file); | 89 | perror_msg_and_die("%s", file); |
90 | return EXIT_FAILURE; | ||
91 | } | ||
92 | 90 | ||
93 | if (ioctl(fd, MTIOCTOP, &op) != 0) { | 91 | if (ioctl(fd, MTIOCTOP, &op) != 0) |
94 | perror(file); | 92 | perror_msg_and_die("%s", file); |
95 | return EXIT_FAILURE; | ||
96 | } | ||
97 | 93 | ||
98 | return EXIT_SUCCESS; | 94 | return EXIT_SUCCESS; |
99 | } | 95 | } |
@@ -27,7 +27,7 @@ void erase_mtab(const char *name) | |||
27 | /* Bummer. fall back on trying the /proc filesystem */ | 27 | /* Bummer. fall back on trying the /proc filesystem */ |
28 | && (mountTable = setmntent("/proc/mounts", "r")) == 0) { | 28 | && (mountTable = setmntent("/proc/mounts", "r")) == 0) { |
29 | #endif | 29 | #endif |
30 | perror(mtab_file); | 30 | perror_msg("%s", mtab_file); |
31 | return; | 31 | return; |
32 | } | 32 | } |
33 | 33 | ||
@@ -55,7 +55,7 @@ void erase_mtab(const char *name) | |||
55 | } | 55 | } |
56 | endmntent(mountTable); | 56 | endmntent(mountTable); |
57 | } else if (errno != EROFS) | 57 | } else if (errno != EROFS) |
58 | perror(mtab_file); | 58 | perror_msg("%s", mtab_file); |
59 | } | 59 | } |
60 | 60 | ||
61 | void write_mtab(char *blockDevice, char *directory, | 61 | void write_mtab(char *blockDevice, char *directory, |
@@ -65,7 +65,7 @@ void write_mtab(char *blockDevice, char *directory, | |||
65 | struct mntent m; | 65 | struct mntent m; |
66 | 66 | ||
67 | if (mountTable == 0) { | 67 | if (mountTable == 0) { |
68 | perror(mtab_file); | 68 | perror_msg("%s", mtab_file); |
69 | return; | 69 | return; |
70 | } | 70 | } |
71 | if (mountTable) { | 71 | 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 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * $Id: hostname.c,v 1.16 2000/12/07 19:56:48 markw Exp $ | 3 | * $Id: hostname.c,v 1.17 2000/12/22 01:48:07 kraai Exp $ |
4 | * Mini hostname implementation for busybox | 4 | * Mini hostname implementation for busybox |
5 | * | 5 | * |
6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
@@ -40,10 +40,9 @@ void do_sethostname(char *s, int isfile) | |||
40 | if (!isfile) { | 40 | if (!isfile) { |
41 | if (sethostname(s, strlen(s)) < 0) { | 41 | if (sethostname(s, strlen(s)) < 0) { |
42 | if (errno == EPERM) | 42 | if (errno == EPERM) |
43 | error_msg("you must be root to change the hostname\n"); | 43 | error_msg_and_die("you must be root to change the hostname\n"); |
44 | else | 44 | else |
45 | perror("sethostname"); | 45 | perror_msg_and_die("sethostname"); |
46 | exit(1); | ||
47 | } | 46 | } |
48 | } else { | 47 | } else { |
49 | f = xfopen(s, "r"); | 48 | f = xfopen(s, "r"); |
@@ -51,10 +50,8 @@ void do_sethostname(char *s, int isfile) | |||
51 | fclose(f); | 50 | fclose(f); |
52 | if (buf[strlen(buf) - 1] == '\n') | 51 | if (buf[strlen(buf) - 1] == '\n') |
53 | buf[strlen(buf) - 1] = 0; | 52 | buf[strlen(buf) - 1] = 0; |
54 | if (sethostname(buf, strlen(buf)) < 0) { | 53 | if (sethostname(buf, strlen(buf)) < 0) |
55 | perror("sethostname"); | 54 | perror_msg_and_die("sethostname"); |
56 | exit(1); | ||
57 | } | ||
58 | } | 55 | } |
59 | } | 56 | } |
60 | 57 | ||
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 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * $Id: ping.c,v 1.29 2000/12/18 03:57:16 kraai Exp $ | 3 | * $Id: ping.c,v 1.30 2000/12/22 01:48:07 kraai Exp $ |
4 | * Mini ping implementation for busybox | 4 | * Mini ping implementation for busybox |
5 | * | 5 | * |
6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
@@ -190,10 +190,8 @@ static void ping(const char *host) | |||
190 | int pingsock, c; | 190 | int pingsock, c; |
191 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; | 191 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; |
192 | 192 | ||
193 | if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) { /* 1 == ICMP */ | 193 | if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) /* 1 == ICMP */ |
194 | perror("ping: creating a raw socket"); | 194 | perror_msg_and_die("creating a raw socket"); |
195 | exit(1); | ||
196 | } | ||
197 | 195 | ||
198 | /* drop root privs if running setuid */ | 196 | /* drop root privs if running setuid */ |
199 | setuid(getuid()); | 197 | setuid(getuid()); |
@@ -216,12 +214,8 @@ static void ping(const char *host) | |||
216 | c = sendto(pingsock, packet, sizeof(packet), 0, | 214 | c = sendto(pingsock, packet, sizeof(packet), 0, |
217 | (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in)); | 215 | (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in)); |
218 | 216 | ||
219 | if (c < 0 || c != sizeof(packet)) { | 217 | if (c < 0 || c != sizeof(packet)) |
220 | if (c < 0) | 218 | perror_msg_and_die("sendto"); |
221 | perror("ping: sendto"); | ||
222 | error_msg("write incomplete\n"); | ||
223 | exit(1); | ||
224 | } | ||
225 | 219 | ||
226 | signal(SIGALRM, noresp); | 220 | signal(SIGALRM, noresp); |
227 | alarm(5); /* give the host 5000ms to respond */ | 221 | alarm(5); /* give the host 5000ms to respond */ |
@@ -234,7 +228,7 @@ static void ping(const char *host) | |||
234 | (struct sockaddr *) &from, &fromlen)) < 0) { | 228 | (struct sockaddr *) &from, &fromlen)) < 0) { |
235 | if (errno == EINTR) | 229 | if (errno == EINTR) |
236 | continue; | 230 | continue; |
237 | perror("ping: recvfrom"); | 231 | perror_msg("recvfrom"); |
238 | continue; | 232 | continue; |
239 | } | 233 | } |
240 | if (c >= 76) { /* ip + icmp */ | 234 | if (c >= 76) { /* ip + icmp */ |
@@ -439,12 +433,10 @@ static void ping(const char *host) | |||
439 | * proto->p_proto to have the correct value for "icmp" */ | 433 | * proto->p_proto to have the correct value for "icmp" */ |
440 | if ((pingsock = socket(AF_INET, SOCK_RAW, | 434 | if ((pingsock = socket(AF_INET, SOCK_RAW, |
441 | (proto ? proto->p_proto : 1))) < 0) { /* 1 == ICMP */ | 435 | (proto ? proto->p_proto : 1))) < 0) { /* 1 == ICMP */ |
442 | if (errno == EPERM) { | 436 | if (errno == EPERM) |
443 | error_msg("permission denied. (are you root?)\n"); | 437 | error_msg_and_die("permission denied. (are you root?)\n"); |
444 | } else { | 438 | else |
445 | perror("ping: creating a raw socket"); | 439 | perror_msg_and_die("creating a raw socket"); |
446 | } | ||
447 | exit(1); | ||
448 | } | 440 | } |
449 | 441 | ||
450 | /* drop root privs if running setuid */ | 442 | /* drop root privs if running setuid */ |
@@ -498,7 +490,7 @@ static void ping(const char *host) | |||
498 | (struct sockaddr *) &from, &fromlen)) < 0) { | 490 | (struct sockaddr *) &from, &fromlen)) < 0) { |
499 | if (errno == EINTR) | 491 | if (errno == EINTR) |
500 | continue; | 492 | continue; |
501 | perror("ping: recvfrom"); | 493 | perror_msg("recvfrom"); |
502 | continue; | 494 | continue; |
503 | } | 495 | } |
504 | unpack(packet, c, &from); | 496 | unpack(packet, c, &from); |
@@ -1,6 +1,6 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * $Id: ping.c,v 1.29 2000/12/18 03:57:16 kraai Exp $ | 3 | * $Id: ping.c,v 1.30 2000/12/22 01:48:07 kraai Exp $ |
4 | * Mini ping implementation for busybox | 4 | * Mini ping implementation for busybox |
5 | * | 5 | * |
6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
@@ -190,10 +190,8 @@ static void ping(const char *host) | |||
190 | int pingsock, c; | 190 | int pingsock, c; |
191 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; | 191 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; |
192 | 192 | ||
193 | if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) { /* 1 == ICMP */ | 193 | if ((pingsock = socket(AF_INET, SOCK_RAW, 1)) < 0) /* 1 == ICMP */ |
194 | perror("ping: creating a raw socket"); | 194 | perror_msg_and_die("creating a raw socket"); |
195 | exit(1); | ||
196 | } | ||
197 | 195 | ||
198 | /* drop root privs if running setuid */ | 196 | /* drop root privs if running setuid */ |
199 | setuid(getuid()); | 197 | setuid(getuid()); |
@@ -216,12 +214,8 @@ static void ping(const char *host) | |||
216 | c = sendto(pingsock, packet, sizeof(packet), 0, | 214 | c = sendto(pingsock, packet, sizeof(packet), 0, |
217 | (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in)); | 215 | (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in)); |
218 | 216 | ||
219 | if (c < 0 || c != sizeof(packet)) { | 217 | if (c < 0 || c != sizeof(packet)) |
220 | if (c < 0) | 218 | perror_msg_and_die("sendto"); |
221 | perror("ping: sendto"); | ||
222 | error_msg("write incomplete\n"); | ||
223 | exit(1); | ||
224 | } | ||
225 | 219 | ||
226 | signal(SIGALRM, noresp); | 220 | signal(SIGALRM, noresp); |
227 | alarm(5); /* give the host 5000ms to respond */ | 221 | alarm(5); /* give the host 5000ms to respond */ |
@@ -234,7 +228,7 @@ static void ping(const char *host) | |||
234 | (struct sockaddr *) &from, &fromlen)) < 0) { | 228 | (struct sockaddr *) &from, &fromlen)) < 0) { |
235 | if (errno == EINTR) | 229 | if (errno == EINTR) |
236 | continue; | 230 | continue; |
237 | perror("ping: recvfrom"); | 231 | perror_msg("recvfrom"); |
238 | continue; | 232 | continue; |
239 | } | 233 | } |
240 | if (c >= 76) { /* ip + icmp */ | 234 | if (c >= 76) { /* ip + icmp */ |
@@ -439,12 +433,10 @@ static void ping(const char *host) | |||
439 | * proto->p_proto to have the correct value for "icmp" */ | 433 | * proto->p_proto to have the correct value for "icmp" */ |
440 | if ((pingsock = socket(AF_INET, SOCK_RAW, | 434 | if ((pingsock = socket(AF_INET, SOCK_RAW, |
441 | (proto ? proto->p_proto : 1))) < 0) { /* 1 == ICMP */ | 435 | (proto ? proto->p_proto : 1))) < 0) { /* 1 == ICMP */ |
442 | if (errno == EPERM) { | 436 | if (errno == EPERM) |
443 | error_msg("permission denied. (are you root?)\n"); | 437 | error_msg_and_die("permission denied. (are you root?)\n"); |
444 | } else { | 438 | else |
445 | perror("ping: creating a raw socket"); | 439 | perror_msg_and_die("creating a raw socket"); |
446 | } | ||
447 | exit(1); | ||
448 | } | 440 | } |
449 | 441 | ||
450 | /* drop root privs if running setuid */ | 442 | /* drop root privs if running setuid */ |
@@ -498,7 +490,7 @@ static void ping(const char *host) | |||
498 | (struct sockaddr *) &from, &fromlen)) < 0) { | 490 | (struct sockaddr *) &from, &fromlen)) < 0) { |
499 | if (errno == EINTR) | 491 | if (errno == EINTR) |
500 | continue; | 492 | continue; |
501 | perror("ping: recvfrom"); | 493 | perror_msg("recvfrom"); |
502 | continue; | 494 | continue; |
503 | } | 495 | } |
504 | unpack(packet, c, &from); | 496 | unpack(packet, c, &from); |
@@ -45,10 +45,8 @@ extern int rmmod_main(int argc, char **argv) | |||
45 | switch (**argv) { | 45 | switch (**argv) { |
46 | case 'a': | 46 | case 'a': |
47 | /* Unload _all_ unused modules via NULL delete_module() call */ | 47 | /* Unload _all_ unused modules via NULL delete_module() call */ |
48 | if (delete_module(NULL)) { | 48 | if (delete_module(NULL)) |
49 | perror("rmmod"); | 49 | perror_msg_and_die("rmmod"); |
50 | return EXIT_FAILURE; | ||
51 | } | ||
52 | return EXIT_SUCCESS; | 50 | return EXIT_SUCCESS; |
53 | default: | 51 | default: |
54 | usage(rmmod_usage); | 52 | usage(rmmod_usage); |
@@ -58,7 +56,7 @@ extern int rmmod_main(int argc, char **argv) | |||
58 | 56 | ||
59 | while (argc-- > 0) { | 57 | while (argc-- > 0) { |
60 | if (delete_module(*argv) < 0) { | 58 | if (delete_module(*argv) < 0) { |
61 | perror(*argv); | 59 | perror_msg("%s", *argv); |
62 | ret = EXIT_FAILURE; | 60 | ret = EXIT_FAILURE; |
63 | } | 61 | } |
64 | argv++; | 62 | 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) | |||
40 | 40 | ||
41 | if ((err = read(infile, buffer, num)) != num) { | 41 | if ((err = read(infile, buffer, num)) != num) { |
42 | if (err < 0) | 42 | if (err < 0) |
43 | perror(progname); | 43 | perror_msg_and_die(progname); |
44 | else | 44 | else |
45 | fprintf(stderr, "Unexpected end of input file!\n"); | 45 | error_msg_and_die("Unexpected end of input file!\n"); |
46 | exit(1); | ||
47 | } | 46 | } |
48 | } | 47 | } |
49 | 48 | ||
@@ -68,10 +67,8 @@ int rpmunpack_main(int argc, char **argv) | |||
68 | /* Open input file */ | 67 | /* Open input file */ |
69 | if (argc == 1) | 68 | if (argc == 1) |
70 | infile = STDIN_FILENO; | 69 | infile = STDIN_FILENO; |
71 | else if ((infile = open(argv[1], O_RDONLY)) < 0) { | 70 | else if ((infile = open(argv[1], O_RDONLY)) < 0) |
72 | perror(progname); | 71 | perror_msg_and_die("%s", argv[1]); |
73 | exit(1); | ||
74 | } | ||
75 | 72 | ||
76 | /* Read magic ID and output filename */ | 73 | /* Read magic ID and output filename */ |
77 | myread(4); | 74 | myread(4); |
@@ -87,10 +84,8 @@ int rpmunpack_main(int argc, char **argv) | |||
87 | strcat(buffer, ".cpio.gz"); | 84 | strcat(buffer, ".cpio.gz"); |
88 | if (infile == STDIN_FILENO) | 85 | if (infile == STDIN_FILENO) |
89 | outfile = STDOUT_FILENO; | 86 | outfile = STDOUT_FILENO; |
90 | else if ((outfile = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { | 87 | else if ((outfile = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) |
91 | perror(progname); | 88 | perror_msg_and_die("%s", buffer); |
92 | exit(1); | ||
93 | } | ||
94 | 89 | ||
95 | /* | 90 | /* |
96 | * Now search for the GZIP signature. This is rather awkward, but I don't | 91 | * 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) | |||
114 | } | 109 | } |
115 | buffer[0] = GZ_MAGIC_1; | 110 | buffer[0] = GZ_MAGIC_1; |
116 | buffer[1] = GZ_MAGIC_2; | 111 | buffer[1] = GZ_MAGIC_2; |
117 | if (write(outfile, buffer, 2) < 0) { | 112 | if (write(outfile, buffer, 2) < 0) |
118 | perror(progname); | 113 | perror_msg_and_die("write"); |
119 | exit(1); | ||
120 | } | ||
121 | 114 | ||
122 | /* Now simply copy the GZIP archive into the output file */ | 115 | /* Now simply copy the GZIP archive into the output file */ |
123 | while ((len = read(infile, buffer, BUFSIZE)) > 0) { | 116 | while ((len = read(infile, buffer, BUFSIZE)) > 0) { |
124 | if (write(outfile, buffer, len) < 0) { | 117 | if (write(outfile, buffer, len) < 0) |
125 | perror(progname); | 118 | perror_msg_and_die("write"); |
126 | exit(1); | ||
127 | } | ||
128 | } | ||
129 | if (len < 0) { | ||
130 | perror(progname); | ||
131 | exit(1); | ||
132 | } | 119 | } |
133 | close(outfile); | 120 | if (len < 0) |
134 | close(infile); | 121 | perror_msg_and_die("read"); |
135 | exit(0); | 122 | return EXIT_SUCCESS; |
136 | } | 123 | } |
@@ -709,10 +709,8 @@ extern int sed_main(int argc, char **argv) | |||
709 | 709 | ||
710 | #ifdef BB_FEATURE_CLEAN_UP | 710 | #ifdef BB_FEATURE_CLEAN_UP |
711 | /* destroy command strings on exit */ | 711 | /* destroy command strings on exit */ |
712 | if (atexit(destroy_cmd_strs) == -1) { | 712 | if (atexit(destroy_cmd_strs) == -1) |
713 | perror("sed"); | 713 | perror_msg_and_die("atexit"); |
714 | exit(1); | ||
715 | } | ||
716 | #endif | 714 | #endif |
717 | 715 | ||
718 | /* do normal option parsing */ | 716 | /* do normal option parsing */ |
@@ -344,7 +344,7 @@ static int builtin_fg_bg(struct child_prog *child) | |||
344 | /* Make this job the foreground job */ | 344 | /* Make this job the foreground job */ |
345 | /* suppress messages when run from /linuxrc mag@sysgo.de */ | 345 | /* suppress messages when run from /linuxrc mag@sysgo.de */ |
346 | if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY) | 346 | if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY) |
347 | perror("tcsetpgrp"); | 347 | perror_msg("tcsetpgrp"); |
348 | child->family->job_list->fg = job; | 348 | child->family->job_list->fg = job; |
349 | } | 349 | } |
350 | 350 | ||
@@ -683,7 +683,7 @@ static void checkjobs(struct jobset *job_list) | |||
683 | } | 683 | } |
684 | 684 | ||
685 | if (childpid == -1 && errno != ECHILD) | 685 | if (childpid == -1 && errno != ECHILD) |
686 | perror("waitpid"); | 686 | perror_msg("waitpid"); |
687 | } | 687 | } |
688 | 688 | ||
689 | /* squirrel != NULL means we squirrel away copies of stdin, stdout, | 689 | /* squirrel != NULL means we squirrel away copies of stdin, stdout, |
@@ -1422,7 +1422,7 @@ static void insert_job(struct job *newjob, int inbg) | |||
1422 | /* move the new process group into the foreground */ | 1422 | /* move the new process group into the foreground */ |
1423 | /* suppress messages when run from /linuxrc mag@sysgo.de */ | 1423 | /* suppress messages when run from /linuxrc mag@sysgo.de */ |
1424 | if (tcsetpgrp(0, newjob->pgrp) && errno != ENOTTY) | 1424 | if (tcsetpgrp(0, newjob->pgrp) && errno != ENOTTY) |
1425 | perror("tcsetpgrp"); | 1425 | perror_msg("tcsetpgrp"); |
1426 | } | 1426 | } |
1427 | } | 1427 | } |
1428 | 1428 | ||
@@ -1612,7 +1612,7 @@ static int busy_loop(FILE * input) | |||
1612 | /* move the shell to the foreground */ | 1612 | /* move the shell to the foreground */ |
1613 | /* suppress messages when run from /linuxrc mag@sysgo.de */ | 1613 | /* suppress messages when run from /linuxrc mag@sysgo.de */ |
1614 | if (tcsetpgrp(0, getpid()) && errno != ENOTTY) | 1614 | if (tcsetpgrp(0, getpid()) && errno != ENOTTY) |
1615 | perror("tcsetpgrp"); | 1615 | perror_msg("tcsetpgrp"); |
1616 | } | 1616 | } |
1617 | } | 1617 | } |
1618 | } | 1618 | } |
@@ -1620,7 +1620,7 @@ static int busy_loop(FILE * input) | |||
1620 | 1620 | ||
1621 | /* return controlling TTY back to parent process group before exiting */ | 1621 | /* return controlling TTY back to parent process group before exiting */ |
1622 | if (tcsetpgrp(0, parent_pgrp)) | 1622 | if (tcsetpgrp(0, parent_pgrp)) |
1623 | perror("tcsetpgrp"); | 1623 | perror_msg("tcsetpgrp"); |
1624 | 1624 | ||
1625 | /* return exit status if called with "-c" */ | 1625 | /* return exit status if called with "-c" */ |
1626 | if (input == NULL && WIFEXITED(status)) | 1626 | 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) | |||
344 | /* Make this job the foreground job */ | 344 | /* Make this job the foreground job */ |
345 | /* suppress messages when run from /linuxrc mag@sysgo.de */ | 345 | /* suppress messages when run from /linuxrc mag@sysgo.de */ |
346 | if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY) | 346 | if (tcsetpgrp(0, job->pgrp) && errno != ENOTTY) |
347 | perror("tcsetpgrp"); | 347 | perror_msg("tcsetpgrp"); |
348 | child->family->job_list->fg = job; | 348 | child->family->job_list->fg = job; |
349 | } | 349 | } |
350 | 350 | ||
@@ -683,7 +683,7 @@ static void checkjobs(struct jobset *job_list) | |||
683 | } | 683 | } |
684 | 684 | ||
685 | if (childpid == -1 && errno != ECHILD) | 685 | if (childpid == -1 && errno != ECHILD) |
686 | perror("waitpid"); | 686 | perror_msg("waitpid"); |
687 | } | 687 | } |
688 | 688 | ||
689 | /* squirrel != NULL means we squirrel away copies of stdin, stdout, | 689 | /* squirrel != NULL means we squirrel away copies of stdin, stdout, |
@@ -1422,7 +1422,7 @@ static void insert_job(struct job *newjob, int inbg) | |||
1422 | /* move the new process group into the foreground */ | 1422 | /* move the new process group into the foreground */ |
1423 | /* suppress messages when run from /linuxrc mag@sysgo.de */ | 1423 | /* suppress messages when run from /linuxrc mag@sysgo.de */ |
1424 | if (tcsetpgrp(0, newjob->pgrp) && errno != ENOTTY) | 1424 | if (tcsetpgrp(0, newjob->pgrp) && errno != ENOTTY) |
1425 | perror("tcsetpgrp"); | 1425 | perror_msg("tcsetpgrp"); |
1426 | } | 1426 | } |
1427 | } | 1427 | } |
1428 | 1428 | ||
@@ -1612,7 +1612,7 @@ static int busy_loop(FILE * input) | |||
1612 | /* move the shell to the foreground */ | 1612 | /* move the shell to the foreground */ |
1613 | /* suppress messages when run from /linuxrc mag@sysgo.de */ | 1613 | /* suppress messages when run from /linuxrc mag@sysgo.de */ |
1614 | if (tcsetpgrp(0, getpid()) && errno != ENOTTY) | 1614 | if (tcsetpgrp(0, getpid()) && errno != ENOTTY) |
1615 | perror("tcsetpgrp"); | 1615 | perror_msg("tcsetpgrp"); |
1616 | } | 1616 | } |
1617 | } | 1617 | } |
1618 | } | 1618 | } |
@@ -1620,7 +1620,7 @@ static int busy_loop(FILE * input) | |||
1620 | 1620 | ||
1621 | /* return controlling TTY back to parent process group before exiting */ | 1621 | /* return controlling TTY back to parent process group before exiting */ |
1622 | if (tcsetpgrp(0, parent_pgrp)) | 1622 | if (tcsetpgrp(0, parent_pgrp)) |
1623 | perror("tcsetpgrp"); | 1623 | perror_msg("tcsetpgrp"); |
1624 | 1624 | ||
1625 | /* return exit status if called with "-c" */ | 1625 | /* return exit status if called with "-c" */ |
1626 | if (input == NULL && WIFEXITED(status)) | 1626 | if (input == NULL && WIFEXITED(status)) |
@@ -30,9 +30,7 @@ extern int sleep_main(int argc, char **argv) | |||
30 | usage(sleep_usage); | 30 | usage(sleep_usage); |
31 | } | 31 | } |
32 | 32 | ||
33 | if (sleep(atoi(*(++argv))) != 0) { | 33 | if (sleep(atoi(*(++argv))) != 0) |
34 | perror("sleep"); | 34 | perror_msg_and_die("sleep"); |
35 | return EXIT_FAILURE; | ||
36 | } | ||
37 | return EXIT_SUCCESS; | 35 | return EXIT_SUCCESS; |
38 | } | 36 | } |
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) | |||
48 | else | 48 | else |
49 | status = swapoff(device); | 49 | status = swapoff(device); |
50 | 50 | ||
51 | if (status != 0) { | 51 | if (status != 0) |
52 | perror(applet_name); | 52 | perror_msg_and_die(applet_name); |
53 | exit(EXIT_FAILURE); | ||
54 | } | ||
55 | } | 53 | } |
56 | 54 | ||
57 | static void do_em_all() | 55 | static void do_em_all() |
@@ -59,10 +57,8 @@ static void do_em_all() | |||
59 | struct mntent *m; | 57 | struct mntent *m; |
60 | FILE *f = setmntent("/etc/fstab", "r"); | 58 | FILE *f = setmntent("/etc/fstab", "r"); |
61 | 59 | ||
62 | if (f == NULL) { | 60 | if (f == NULL) |
63 | perror("/etc/fstab"); | 61 | perror_msg_and_die("/etc/fstab"); |
64 | exit(FALSE); | ||
65 | } | ||
66 | while ((m = getmntent(f)) != NULL) { | 62 | while ((m = getmntent(f)) != NULL) { |
67 | if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) { | 63 | if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) { |
68 | swap_enable_disable(m->mnt_fsname); | 64 | swap_enable_disable(m->mnt_fsname); |
@@ -216,7 +216,7 @@ static int umount_all(int useMtab) | |||
216 | if (status != 0) { | 216 | if (status != 0) { |
217 | /* Don't bother retrying the umount on busy devices */ | 217 | /* Don't bother retrying the umount on busy devices */ |
218 | if (errno == EBUSY) { | 218 | if (errno == EBUSY) { |
219 | perror(mountpt); | 219 | perror_msg("%s", mountpt); |
220 | continue; | 220 | continue; |
221 | } | 221 | } |
222 | status = do_umount(mountpt, useMtab); | 222 | status = do_umount(mountpt, useMtab); |
@@ -280,7 +280,6 @@ extern int umount_main(int argc, char **argv) | |||
280 | } | 280 | } |
281 | if (do_umount(*argv, useMtab) == TRUE) | 281 | if (do_umount(*argv, useMtab) == TRUE) |
282 | return EXIT_SUCCESS; | 282 | return EXIT_SUCCESS; |
283 | perror("umount"); | 283 | perror_msg_and_die("%s", *argv); |
284 | return EXIT_FAILURE; | ||
285 | } | 284 | } |
286 | 285 | ||
@@ -114,11 +114,11 @@ int uname_main(int argc, char **argv) | |||
114 | toprint = PRINT_SYSNAME; | 114 | toprint = PRINT_SYSNAME; |
115 | 115 | ||
116 | if (uname(&name) == -1) | 116 | if (uname(&name) == -1) |
117 | perror("cannot get system name"); | 117 | perror_msg("cannot get system name"); |
118 | 118 | ||
119 | #if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE) | 119 | #if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE) |
120 | if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1) | 120 | if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1) |
121 | perror("cannot get processor type"); | 121 | perror_msg("cannot get processor type"); |
122 | } | 122 | } |
123 | 123 | ||
124 | #else | 124 | #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) | |||
69 | } | 69 | } |
70 | 70 | ||
71 | if (cmd == 8) { | 71 | if (cmd == 8) { |
72 | n = klogctl(cmd, NULL, level); | 72 | if (klogctl(cmd, NULL, level) < 0) |
73 | if (n < 0) { | 73 | perror_msg_and_die("klogctl"); |
74 | goto klogctl_error; | ||
75 | } | ||
76 | return EXIT_SUCCESS; | 74 | return EXIT_SUCCESS; |
77 | } | 75 | } |
78 | 76 | ||
79 | if (bufsize < 4096) | 77 | if (bufsize < 4096) |
80 | bufsize = 4096; | 78 | bufsize = 4096; |
81 | buf = (char *) xmalloc(bufsize); | 79 | buf = (char *) xmalloc(bufsize); |
82 | n = klogctl(cmd, buf, bufsize); | 80 | if ((n = klogctl(cmd, buf, bufsize)) < 0) |
83 | if (n < 0) { | 81 | perror_msg_and_die("klogctl"); |
84 | goto klogctl_error; | ||
85 | } | ||
86 | 82 | ||
87 | lastc = '\n'; | 83 | lastc = '\n'; |
88 | for (i = 0; i < n; i++) { | 84 | for (i = 0; i < n; i++) { |
@@ -102,7 +98,4 @@ int dmesg_main(int argc, char **argv) | |||
102 | end: | 98 | end: |
103 | usage(dmesg_usage); | 99 | usage(dmesg_usage); |
104 | return EXIT_FAILURE; | 100 | return EXIT_FAILURE; |
105 | klogctl_error: | ||
106 | perror("klogctl"); | ||
107 | return EXIT_FAILURE; | ||
108 | } | 101 | } |
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 @@ | |||
33 | #include <ctype.h> | 33 | #include <ctype.h> |
34 | #include <sys/ioctl.h> | 34 | #include <sys/ioctl.h> |
35 | 35 | ||
36 | #define PERROR(ctx) do { perror(ctx); exit(1); } while(0) | ||
37 | |||
38 | #define DEFAULTFBDEV "/dev/fb0" | 36 | #define DEFAULTFBDEV "/dev/fb0" |
39 | #define DEFAULTFBMODE "/etc/fb.modes" | 37 | #define DEFAULTFBMODE "/etc/fb.modes" |
40 | 38 | ||
@@ -198,7 +196,7 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn, | |||
198 | char *p = buf; | 196 | char *p = buf; |
199 | 197 | ||
200 | if ((f = fopen(fn, "r")) == NULL) | 198 | if ((f = fopen(fn, "r")) == NULL) |
201 | PERROR("readmode(fopen)"); | 199 | perror_msg_and_die("readmode(fopen)"); |
202 | while (!feof(f)) { | 200 | while (!feof(f)) { |
203 | fgets(buf, sizeof(buf), f); | 201 | fgets(buf, sizeof(buf), f); |
204 | if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) { | 202 | if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) { |
@@ -428,9 +426,9 @@ extern int fbset_main(int argc, char **argv) | |||
428 | } | 426 | } |
429 | 427 | ||
430 | if ((fh = open(fbdev, O_RDONLY)) < 0) | 428 | if ((fh = open(fbdev, O_RDONLY)) < 0) |
431 | PERROR("fbset(open)"); | 429 | perror_msg_and_die("fbset(open)"); |
432 | if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) | 430 | if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) |
433 | PERROR("fbset(ioctl)"); | 431 | perror_msg_and_die("fbset(ioctl)"); |
434 | if (g_options & OPT_READMODE) { | 432 | if (g_options & OPT_READMODE) { |
435 | if (!readmode(&var, modefile, mode)) { | 433 | if (!readmode(&var, modefile, mode)) { |
436 | error_msg("Unknown video mode `%s'\n", mode); | 434 | error_msg("Unknown video mode `%s'\n", mode); |
@@ -441,7 +439,7 @@ extern int fbset_main(int argc, char **argv) | |||
441 | setmode(&var, &varset); | 439 | setmode(&var, &varset); |
442 | if (g_options & OPT_CHANGE) | 440 | if (g_options & OPT_CHANGE) |
443 | if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) | 441 | if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) |
444 | PERROR("fbset(ioctl)"); | 442 | perror_msg_and_die("fbset(ioctl)"); |
445 | showmode(&var); | 443 | showmode(&var); |
446 | /* Don't close the file, as exiting will take care of that */ | 444 | /* Don't close the file, as exiting will take care of that */ |
447 | /* close(fh); */ | 445 | /* 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 @@ | |||
31 | 31 | ||
32 | extern int fdflush_main(int argc, char **argv) | 32 | extern int fdflush_main(int argc, char **argv) |
33 | { | 33 | { |
34 | int value; | ||
35 | int fd; | 34 | int fd; |
36 | 35 | ||
37 | if (argc <= 1 || **(++argv) == '-') | 36 | if (argc <= 1 || **(++argv) == '-') |
38 | usage(fdflush_usage); | 37 | usage(fdflush_usage); |
39 | 38 | ||
40 | fd = open(*argv, 0); | 39 | if ((fd = open(*argv, 0)) < 0) |
41 | if (fd < 0) { | 40 | perror_msg_and_die("%s", *argv); |
42 | perror(*argv); | ||
43 | return EXIT_FAILURE; | ||
44 | } | ||
45 | 41 | ||
46 | value = ioctl(fd, FDFLUSH, 0); | 42 | if (ioctl(fd, FDFLUSH, 0)) |
47 | /* Don't bother closing. Exit does | 43 | perror_msg_and_die("%s", *argv); |
48 | * that, so we can save a few bytes */ | ||
49 | /* close(fd); */ | ||
50 | 44 | ||
51 | if (value) { | ||
52 | perror(*argv); | ||
53 | return EXIT_FAILURE; | ||
54 | } | ||
55 | return EXIT_SUCCESS; | 45 | return EXIT_SUCCESS; |
56 | } | 46 | } |
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) | |||
329 | int fd; | 329 | int fd; |
330 | long size; | 330 | long size; |
331 | 331 | ||
332 | fd = open(file, O_RDWR); | 332 | if ((fd = open(file, O_RDWR)) < 0) |
333 | if (fd < 0) { | 333 | perror_msg_and_die("%s", file); |
334 | perror(file); | ||
335 | exit(1); | ||
336 | } | ||
337 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { | 334 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { |
338 | close(fd); | 335 | close(fd); |
339 | return (size * 512); | 336 | 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) | |||
260 | int fd; | 260 | int fd; |
261 | long size; | 261 | long size; |
262 | 262 | ||
263 | fd = open(file, O_RDONLY); | 263 | if ((fd = open(file, O_RDONLY)) < 0) |
264 | if (fd < 0) { | 264 | perror_msg_and_die("%s", file); |
265 | perror(file); | ||
266 | exit(1); | ||
267 | } | ||
268 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { | 265 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { |
269 | int sectors_per_page = pagesize / 512; | 266 | int sectors_per_page = pagesize / 512; |
270 | 267 | ||
@@ -367,10 +364,8 @@ int mkswap_main(int argc, char **argv) | |||
367 | } | 364 | } |
368 | 365 | ||
369 | DEV = open(device_name, O_RDWR); | 366 | DEV = open(device_name, O_RDWR); |
370 | if (DEV < 0 || fstat(DEV, &statbuf) < 0) { | 367 | if (DEV < 0 || fstat(DEV, &statbuf) < 0) |
371 | perror(device_name); | 368 | perror_msg_and_die("%s", device_name); |
372 | return EXIT_FAILURE; | ||
373 | } | ||
374 | if (!S_ISBLK(statbuf.st_mode)) | 369 | if (!S_ISBLK(statbuf.st_mode)) |
375 | check = 0; | 370 | check = 0; |
376 | else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) | 371 | 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) | |||
383 | } | 383 | } |
384 | endmntent(mountTable); | 384 | endmntent(mountTable); |
385 | } else { | 385 | } else { |
386 | perror(mtab_file); | 386 | perror_msg_and_die("%s", mtab_file); |
387 | } | 387 | } |
388 | return EXIT_SUCCESS; | 388 | return EXIT_SUCCESS; |
389 | } | 389 | } |
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) | |||
48 | else | 48 | else |
49 | status = swapoff(device); | 49 | status = swapoff(device); |
50 | 50 | ||
51 | if (status != 0) { | 51 | if (status != 0) |
52 | perror(applet_name); | 52 | perror_msg_and_die(applet_name); |
53 | exit(EXIT_FAILURE); | ||
54 | } | ||
55 | } | 53 | } |
56 | 54 | ||
57 | static void do_em_all() | 55 | static void do_em_all() |
@@ -59,10 +57,8 @@ static void do_em_all() | |||
59 | struct mntent *m; | 57 | struct mntent *m; |
60 | FILE *f = setmntent("/etc/fstab", "r"); | 58 | FILE *f = setmntent("/etc/fstab", "r"); |
61 | 59 | ||
62 | if (f == NULL) { | 60 | if (f == NULL) |
63 | perror("/etc/fstab"); | 61 | perror_msg_and_die("/etc/fstab"); |
64 | exit(FALSE); | ||
65 | } | ||
66 | while ((m = getmntent(f)) != NULL) { | 62 | while ((m = getmntent(f)) != NULL) { |
67 | if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) { | 63 | if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) { |
68 | swap_enable_disable(m->mnt_fsname); | 64 | 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) | |||
216 | if (status != 0) { | 216 | if (status != 0) { |
217 | /* Don't bother retrying the umount on busy devices */ | 217 | /* Don't bother retrying the umount on busy devices */ |
218 | if (errno == EBUSY) { | 218 | if (errno == EBUSY) { |
219 | perror(mountpt); | 219 | perror_msg("%s", mountpt); |
220 | continue; | 220 | continue; |
221 | } | 221 | } |
222 | status = do_umount(mountpt, useMtab); | 222 | status = do_umount(mountpt, useMtab); |
@@ -280,7 +280,6 @@ extern int umount_main(int argc, char **argv) | |||
280 | } | 280 | } |
281 | if (do_umount(*argv, useMtab) == TRUE) | 281 | if (do_umount(*argv, useMtab) == TRUE) |
282 | return EXIT_SUCCESS; | 282 | return EXIT_SUCCESS; |
283 | perror("umount"); | 283 | perror_msg_and_die("%s", *argv); |
284 | return EXIT_FAILURE; | ||
285 | } | 284 | } |
286 | 285 | ||
@@ -153,7 +153,7 @@ extern int get_kernel_revision(void) | |||
153 | int major = 0, minor = 0, patch = 0; | 153 | int major = 0, minor = 0, patch = 0; |
154 | 154 | ||
155 | if (uname(&name) == -1) { | 155 | if (uname(&name) == -1) { |
156 | perror("cannot get system information"); | 156 | perror_msg("cannot get system information"); |
157 | return (0); | 157 | return (0); |
158 | } | 158 | } |
159 | major = atoi(strtok(name.release, ".")); | 159 | major = atoi(strtok(name.release, ".")); |
@@ -341,7 +341,7 @@ copy_file(const char *srcName, const char *destName, | |||
341 | status = lstat(srcName, &srcStatBuf); | 341 | status = lstat(srcName, &srcStatBuf); |
342 | 342 | ||
343 | if (status < 0) { | 343 | if (status < 0) { |
344 | perror(srcName); | 344 | perror_msg("%s", srcName); |
345 | return FALSE; | 345 | return FALSE; |
346 | } | 346 | } |
347 | 347 | ||
@@ -367,7 +367,7 @@ copy_file(const char *srcName, const char *destName, | |||
367 | /* Make sure the directory is writable */ | 367 | /* Make sure the directory is writable */ |
368 | status = mkdir(destName, 0777777 ^ umask(0)); | 368 | status = mkdir(destName, 0777777 ^ umask(0)); |
369 | if (status < 0 && errno != EEXIST) { | 369 | if (status < 0 && errno != EEXIST) { |
370 | perror(destName); | 370 | perror_msg("%s", destName); |
371 | return FALSE; | 371 | return FALSE; |
372 | } | 372 | } |
373 | } else if (S_ISLNK(srcStatBuf.st_mode)) { | 373 | } else if (S_ISLNK(srcStatBuf.st_mode)) { |
@@ -378,13 +378,13 @@ copy_file(const char *srcName, const char *destName, | |||
378 | /* Warning: This could possibly truncate silently, to BUFSIZ chars */ | 378 | /* Warning: This could possibly truncate silently, to BUFSIZ chars */ |
379 | link_size = readlink(srcName, &link_val[0], BUFSIZ); | 379 | link_size = readlink(srcName, &link_val[0], BUFSIZ); |
380 | if (link_size < 0) { | 380 | if (link_size < 0) { |
381 | perror(srcName); | 381 | perror_msg("%s", srcName); |
382 | return FALSE; | 382 | return FALSE; |
383 | } | 383 | } |
384 | link_val[link_size] = '\0'; | 384 | link_val[link_size] = '\0'; |
385 | status = symlink(link_val, destName); | 385 | status = symlink(link_val, destName); |
386 | if (status < 0) { | 386 | if (status < 0) { |
387 | perror(destName); | 387 | perror_msg("%s", destName); |
388 | return FALSE; | 388 | return FALSE; |
389 | } | 389 | } |
390 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) | 390 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) |
@@ -397,28 +397,28 @@ copy_file(const char *srcName, const char *destName, | |||
397 | } else if (S_ISFIFO(srcStatBuf.st_mode)) { | 397 | } else if (S_ISFIFO(srcStatBuf.st_mode)) { |
398 | //fprintf(stderr, "copying fifo %s to %s\n", srcName, destName); | 398 | //fprintf(stderr, "copying fifo %s to %s\n", srcName, destName); |
399 | if (mkfifo(destName, 0644) < 0) { | 399 | if (mkfifo(destName, 0644) < 0) { |
400 | perror(destName); | 400 | perror_msg("%s", destName); |
401 | return FALSE; | 401 | return FALSE; |
402 | } | 402 | } |
403 | } else if (S_ISBLK(srcStatBuf.st_mode) || S_ISCHR(srcStatBuf.st_mode) | 403 | } else if (S_ISBLK(srcStatBuf.st_mode) || S_ISCHR(srcStatBuf.st_mode) |
404 | || S_ISSOCK(srcStatBuf.st_mode)) { | 404 | || S_ISSOCK(srcStatBuf.st_mode)) { |
405 | //fprintf(stderr, "copying soc, blk, or chr %s to %s\n", srcName, destName); | 405 | //fprintf(stderr, "copying soc, blk, or chr %s to %s\n", srcName, destName); |
406 | if (mknod(destName, srcStatBuf.st_mode, srcStatBuf.st_rdev) < 0) { | 406 | if (mknod(destName, srcStatBuf.st_mode, srcStatBuf.st_rdev) < 0) { |
407 | perror(destName); | 407 | perror_msg("%s", destName); |
408 | return FALSE; | 408 | return FALSE; |
409 | } | 409 | } |
410 | } else if (S_ISREG(srcStatBuf.st_mode)) { | 410 | } else if (S_ISREG(srcStatBuf.st_mode)) { |
411 | //fprintf(stderr, "copying regular file %s to %s\n", srcName, destName); | 411 | //fprintf(stderr, "copying regular file %s to %s\n", srcName, destName); |
412 | rfd = open(srcName, O_RDONLY); | 412 | rfd = open(srcName, O_RDONLY); |
413 | if (rfd < 0) { | 413 | if (rfd < 0) { |
414 | perror(srcName); | 414 | perror_msg("%s", srcName); |
415 | return FALSE; | 415 | return FALSE; |
416 | } | 416 | } |
417 | 417 | ||
418 | wfd = open(destName, O_WRONLY | O_CREAT | O_TRUNC, | 418 | wfd = open(destName, O_WRONLY | O_CREAT | O_TRUNC, |
419 | srcStatBuf.st_mode); | 419 | srcStatBuf.st_mode); |
420 | if (wfd < 0) { | 420 | if (wfd < 0) { |
421 | perror(destName); | 421 | perror_msg("%s", destName); |
422 | close(rfd); | 422 | close(rfd); |
423 | return FALSE; | 423 | return FALSE; |
424 | } | 424 | } |
@@ -434,26 +434,20 @@ copy_file(const char *srcName, const char *destName, | |||
434 | 434 | ||
435 | if (setModes == TRUE) { | 435 | if (setModes == TRUE) { |
436 | /* This is fine, since symlinks never get here */ | 436 | /* This is fine, since symlinks never get here */ |
437 | if (chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0) { | 437 | if (chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0) |
438 | perror(destName); | 438 | perror_msg_and_die("%s", destName); |
439 | exit(EXIT_FAILURE); | 439 | if (chmod(destName, srcStatBuf.st_mode) < 0) |
440 | } | 440 | perror_msg_and_die("%s", destName); |
441 | if (chmod(destName, srcStatBuf.st_mode) < 0) { | ||
442 | perror(destName); | ||
443 | exit(EXIT_FAILURE); | ||
444 | } | ||
445 | times.actime = srcStatBuf.st_atime; | 441 | times.actime = srcStatBuf.st_atime; |
446 | times.modtime = srcStatBuf.st_mtime; | 442 | times.modtime = srcStatBuf.st_mtime; |
447 | if (utime(destName, ×) < 0) { | 443 | if (utime(destName, ×) < 0) |
448 | perror(destName); | 444 | perror_msg_and_die("%s", destName); |
449 | exit(EXIT_FAILURE); | ||
450 | } | ||
451 | } | 445 | } |
452 | 446 | ||
453 | return TRUE; | 447 | return TRUE; |
454 | 448 | ||
455 | error_exit: | 449 | error_exit: |
456 | perror(destName); | 450 | perror_msg("%s", destName); |
457 | close(rfd); | 451 | close(rfd); |
458 | close(wfd); | 452 | close(wfd); |
459 | 453 | ||
@@ -745,7 +739,7 @@ extern int create_path(const char *name, int mode) | |||
745 | *cpOld = '\0'; | 739 | *cpOld = '\0'; |
746 | retVal = mkdir(buf, cp ? 0777 : mode); | 740 | retVal = mkdir(buf, cp ? 0777 : mode); |
747 | if (retVal != 0 && errno != EEXIST) { | 741 | if (retVal != 0 && errno != EEXIST) { |
748 | perror(buf); | 742 | perror_msg("%s", buf); |
749 | return FALSE; | 743 | return FALSE; |
750 | } | 744 | } |
751 | *cpOld = '/'; | 745 | *cpOld = '/'; |
@@ -1450,11 +1444,11 @@ extern int del_loop(const char *device) | |||
1450 | int fd; | 1444 | int fd; |
1451 | 1445 | ||
1452 | if ((fd = open(device, O_RDONLY)) < 0) { | 1446 | if ((fd = open(device, O_RDONLY)) < 0) { |
1453 | perror(device); | 1447 | perror_msg("%s", device); |
1454 | return (FALSE); | 1448 | return (FALSE); |
1455 | } | 1449 | } |
1456 | if (ioctl(fd, LOOP_CLR_FD, 0) < 0) { | 1450 | if (ioctl(fd, LOOP_CLR_FD, 0) < 0) { |
1457 | perror("ioctl: LOOP_CLR_FD"); | 1451 | perror_msg("ioctl: LOOP_CLR_FD"); |
1458 | return (FALSE); | 1452 | return (FALSE); |
1459 | } | 1453 | } |
1460 | close(fd); | 1454 | close(fd); |
@@ -1470,12 +1464,12 @@ extern int set_loop(const char *device, const char *file, int offset, | |||
1470 | mode = *loopro ? O_RDONLY : O_RDWR; | 1464 | mode = *loopro ? O_RDONLY : O_RDWR; |
1471 | if ((ffd = open(file, mode)) < 0 && !*loopro | 1465 | if ((ffd = open(file, mode)) < 0 && !*loopro |
1472 | && (errno != EROFS || (ffd = open(file, mode = O_RDONLY)) < 0)) { | 1466 | && (errno != EROFS || (ffd = open(file, mode = O_RDONLY)) < 0)) { |
1473 | perror(file); | 1467 | perror_msg("%s", file); |
1474 | return 1; | 1468 | return 1; |
1475 | } | 1469 | } |
1476 | if ((fd = open(device, mode)) < 0) { | 1470 | if ((fd = open(device, mode)) < 0) { |
1477 | close(ffd); | 1471 | close(ffd); |
1478 | perror(device); | 1472 | perror_msg("%s", device); |
1479 | return 1; | 1473 | return 1; |
1480 | } | 1474 | } |
1481 | *loopro = (mode == O_RDONLY); | 1475 | *loopro = (mode == O_RDONLY); |
@@ -1488,14 +1482,14 @@ extern int set_loop(const char *device, const char *file, int offset, | |||
1488 | 1482 | ||
1489 | loopinfo.lo_encrypt_key_size = 0; | 1483 | loopinfo.lo_encrypt_key_size = 0; |
1490 | if (ioctl(fd, LOOP_SET_FD, ffd) < 0) { | 1484 | if (ioctl(fd, LOOP_SET_FD, ffd) < 0) { |
1491 | perror("ioctl: LOOP_SET_FD"); | 1485 | perror_msg("ioctl: LOOP_SET_FD"); |
1492 | close(fd); | 1486 | close(fd); |
1493 | close(ffd); | 1487 | close(ffd); |
1494 | return 1; | 1488 | return 1; |
1495 | } | 1489 | } |
1496 | if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) { | 1490 | if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) { |
1497 | (void) ioctl(fd, LOOP_CLR_FD, 0); | 1491 | (void) ioctl(fd, LOOP_CLR_FD, 0); |
1498 | perror("ioctl: LOOP_SET_STATUS"); | 1492 | perror_msg("ioctl: LOOP_SET_STATUS"); |
1499 | close(fd); | 1493 | close(fd); |
1500 | close(ffd); | 1494 | close(ffd); |
1501 | return 1; | 1495 | return 1; |
@@ -81,10 +81,8 @@ int xargs_main(int argc, char **argv) | |||
81 | strcat(execstr, cmd_to_be_executed); | 81 | strcat(execstr, cmd_to_be_executed); |
82 | strcat(execstr, file_to_act_on); | 82 | strcat(execstr, file_to_act_on); |
83 | cmd_output = popen(execstr, "r"); | 83 | cmd_output = popen(execstr, "r"); |
84 | if (cmd_output == NULL) { | 84 | if (cmd_output == NULL) |
85 | perror("popen"); | 85 | perror_msg_and_die("popen"); |
86 | exit(1); | ||
87 | } | ||
88 | 86 | ||
89 | /* harvest the output */ | 87 | /* harvest the output */ |
90 | while ((output_line = get_line_from_file(cmd_output)) != NULL) { | 88 | while ((output_line = get_line_from_file(cmd_output)) != NULL) { |