aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorkraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277>2000-12-22 01:48:07 +0000
committerkraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277>2000-12-22 01:48:07 +0000
commit2230e04b24d58710b30d25f032c1996a143ba261 (patch)
treeb8cb8d939032c0806d62161b01e5836cb808dc3f /util-linux
parent3c7e7e11b41d4a421bcf42fd1bf72a537e051d4a (diff)
downloadbusybox-w32-2230e04b24d58710b30d25f032c1996a143ba261.tar.gz
busybox-w32-2230e04b24d58710b30d25f032c1996a143ba261.tar.bz2
busybox-w32-2230e04b24d58710b30d25f032c1996a143ba261.zip
Use busybox error handling functions wherever possible.
git-svn-id: svn://busybox.net/trunk/busybox@1489 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/dmesg.c15
-rw-r--r--util-linux/fbset.c10
-rw-r--r--util-linux/fdflush.c18
-rw-r--r--util-linux/mkfs_minix.c7
-rw-r--r--util-linux/mkswap.c13
-rw-r--r--util-linux/mount.c2
-rw-r--r--util-linux/swaponoff.c12
-rw-r--r--util-linux/umount.c5
8 files changed, 25 insertions, 57 deletions
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
32extern int fdflush_main(int argc, char **argv) 32extern 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
57static void do_em_all() 55static 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