Use busybox error handling functions wherever possible.
This commit is contained in:
@@ -69,20 +69,16 @@ int dmesg_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (cmd == 8) {
|
||||
n = klogctl(cmd, NULL, level);
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
}
|
||||
if (klogctl(cmd, NULL, level) < 0)
|
||||
perror_msg_and_die("klogctl");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (bufsize < 4096)
|
||||
bufsize = 4096;
|
||||
buf = (char *) xmalloc(bufsize);
|
||||
n = klogctl(cmd, buf, bufsize);
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
}
|
||||
if ((n = klogctl(cmd, buf, bufsize)) < 0)
|
||||
perror_msg_and_die("klogctl");
|
||||
|
||||
lastc = '\n';
|
||||
for (i = 0; i < n; i++) {
|
||||
@@ -102,7 +98,4 @@ int dmesg_main(int argc, char **argv)
|
||||
end:
|
||||
usage(dmesg_usage);
|
||||
return EXIT_FAILURE;
|
||||
klogctl_error:
|
||||
perror("klogctl");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@@ -33,8 +33,6 @@
|
||||
#include <ctype.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#define PERROR(ctx) do { perror(ctx); exit(1); } while(0)
|
||||
|
||||
#define DEFAULTFBDEV "/dev/fb0"
|
||||
#define DEFAULTFBMODE "/etc/fb.modes"
|
||||
|
||||
@@ -198,7 +196,7 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn,
|
||||
char *p = buf;
|
||||
|
||||
if ((f = fopen(fn, "r")) == NULL)
|
||||
PERROR("readmode(fopen)");
|
||||
perror_msg_and_die("readmode(fopen)");
|
||||
while (!feof(f)) {
|
||||
fgets(buf, sizeof(buf), f);
|
||||
if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
|
||||
@@ -428,9 +426,9 @@ extern int fbset_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if ((fh = open(fbdev, O_RDONLY)) < 0)
|
||||
PERROR("fbset(open)");
|
||||
perror_msg_and_die("fbset(open)");
|
||||
if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
|
||||
PERROR("fbset(ioctl)");
|
||||
perror_msg_and_die("fbset(ioctl)");
|
||||
if (g_options & OPT_READMODE) {
|
||||
if (!readmode(&var, modefile, mode)) {
|
||||
error_msg("Unknown video mode `%s'\n", mode);
|
||||
@@ -441,7 +439,7 @@ extern int fbset_main(int argc, char **argv)
|
||||
setmode(&var, &varset);
|
||||
if (g_options & OPT_CHANGE)
|
||||
if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
|
||||
PERROR("fbset(ioctl)");
|
||||
perror_msg_and_die("fbset(ioctl)");
|
||||
showmode(&var);
|
||||
/* Don't close the file, as exiting will take care of that */
|
||||
/* close(fh); */
|
||||
|
@@ -31,26 +31,16 @@
|
||||
|
||||
extern int fdflush_main(int argc, char **argv)
|
||||
{
|
||||
int value;
|
||||
int fd;
|
||||
|
||||
if (argc <= 1 || **(++argv) == '-')
|
||||
usage(fdflush_usage);
|
||||
|
||||
fd = open(*argv, 0);
|
||||
if (fd < 0) {
|
||||
perror(*argv);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if ((fd = open(*argv, 0)) < 0)
|
||||
perror_msg_and_die("%s", *argv);
|
||||
|
||||
value = ioctl(fd, FDFLUSH, 0);
|
||||
/* Don't bother closing. Exit does
|
||||
* that, so we can save a few bytes */
|
||||
/* close(fd); */
|
||||
if (ioctl(fd, FDFLUSH, 0))
|
||||
perror_msg_and_die("%s", *argv);
|
||||
|
||||
if (value) {
|
||||
perror(*argv);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@@ -329,11 +329,8 @@ static int get_size(const char *file)
|
||||
int fd;
|
||||
long size;
|
||||
|
||||
fd = open(file, O_RDWR);
|
||||
if (fd < 0) {
|
||||
perror(file);
|
||||
exit(1);
|
||||
}
|
||||
if ((fd = open(file, O_RDWR)) < 0)
|
||||
perror_msg_and_die("%s", file);
|
||||
if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
|
||||
close(fd);
|
||||
return (size * 512);
|
||||
|
@@ -260,11 +260,8 @@ static long get_size(const char *file)
|
||||
int fd;
|
||||
long size;
|
||||
|
||||
fd = open(file, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror(file);
|
||||
exit(1);
|
||||
}
|
||||
if ((fd = open(file, O_RDONLY)) < 0)
|
||||
perror_msg_and_die("%s", file);
|
||||
if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
|
||||
int sectors_per_page = pagesize / 512;
|
||||
|
||||
@@ -367,10 +364,8 @@ int mkswap_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
DEV = open(device_name, O_RDWR);
|
||||
if (DEV < 0 || fstat(DEV, &statbuf) < 0) {
|
||||
perror(device_name);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (DEV < 0 || fstat(DEV, &statbuf) < 0)
|
||||
perror_msg_and_die("%s", device_name);
|
||||
if (!S_ISBLK(statbuf.st_mode))
|
||||
check = 0;
|
||||
else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
|
||||
|
@@ -383,7 +383,7 @@ extern int mount_main(int argc, char **argv)
|
||||
}
|
||||
endmntent(mountTable);
|
||||
} else {
|
||||
perror(mtab_file);
|
||||
perror_msg_and_die("%s", mtab_file);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@@ -48,10 +48,8 @@ static void swap_enable_disable(char *device)
|
||||
else
|
||||
status = swapoff(device);
|
||||
|
||||
if (status != 0) {
|
||||
perror(applet_name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (status != 0)
|
||||
perror_msg_and_die(applet_name);
|
||||
}
|
||||
|
||||
static void do_em_all()
|
||||
@@ -59,10 +57,8 @@ static void do_em_all()
|
||||
struct mntent *m;
|
||||
FILE *f = setmntent("/etc/fstab", "r");
|
||||
|
||||
if (f == NULL) {
|
||||
perror("/etc/fstab");
|
||||
exit(FALSE);
|
||||
}
|
||||
if (f == NULL)
|
||||
perror_msg_and_die("/etc/fstab");
|
||||
while ((m = getmntent(f)) != NULL) {
|
||||
if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) {
|
||||
swap_enable_disable(m->mnt_fsname);
|
||||
|
@@ -216,7 +216,7 @@ static int umount_all(int useMtab)
|
||||
if (status != 0) {
|
||||
/* Don't bother retrying the umount on busy devices */
|
||||
if (errno == EBUSY) {
|
||||
perror(mountpt);
|
||||
perror_msg("%s", mountpt);
|
||||
continue;
|
||||
}
|
||||
status = do_umount(mountpt, useMtab);
|
||||
@@ -280,7 +280,6 @@ extern int umount_main(int argc, char **argv)
|
||||
}
|
||||
if (do_umount(*argv, useMtab) == TRUE)
|
||||
return EXIT_SUCCESS;
|
||||
perror("umount");
|
||||
return EXIT_FAILURE;
|
||||
perror_msg_and_die("%s", *argv);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user