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