aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/crond.c21
-rw-r--r--miscutils/crontab.c36
-rw-r--r--miscutils/devfsd.c8
-rw-r--r--miscutils/hdparm.c16
-rw-r--r--miscutils/last.c10
-rw-r--r--miscutils/less.c54
-rw-r--r--miscutils/makedevs.c13
-rw-r--r--miscutils/mountpoint.c6
-rw-r--r--miscutils/mt.c6
-rw-r--r--miscutils/rx.c16
-rw-r--r--miscutils/watchdog.c9
11 files changed, 49 insertions, 146 deletions
diff --git a/miscutils/crond.c b/miscutils/crond.c
index 3f60468de..3e12fedc8 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -13,22 +13,7 @@
#define VERSION "2.3.2"
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <signal.h>
-#include <getopt.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/resource.h>
+#include <sys/syslog.h>
#define arysize(ary) (sizeof(ary)/sizeof((ary)[0]))
@@ -193,7 +178,7 @@ int crond_main(int ac, char **av)
* change directory
*/
- bb_xchdir(CDir);
+ xchdir(CDir);
signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
* version - his died. ;(
*/
@@ -208,7 +193,7 @@ int crond_main(int ac, char **av)
/* reexec for vfork() do continue parent */
vfork_daemon_rexec(1, 0, ac, av, "-f");
#else
- bb_xdaemon(1, 0);
+ xdaemon(1, 0);
#endif
}
diff --git a/miscutils/crontab.c b/miscutils/crontab.c
index 0ed59b0dc..a8e650c60 100644
--- a/miscutils/crontab.c
+++ b/miscutils/crontab.c
@@ -11,22 +11,6 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <signal.h>
-#include <getopt.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/resource.h>
#ifndef CRONTABS
#define CRONTABS "/var/spool/cron/crontabs"
@@ -47,8 +31,7 @@ static void EditFile(const char *user, const char *file);
static int GetReplaceStream(const char *user, const char *file);
static int ChangeUser(const char *user, short dochdir);
-int
-crontab_main(int ac, char **av)
+int crontab_main(int ac, char **av)
{
enum { NONE, EDIT, LIST, REPLACE, DELETE } option = NONE;
const struct passwd *pas;
@@ -147,7 +130,7 @@ crontab_main(int ac, char **av)
* Change directory to our crontab directory
*/
- bb_xchdir(CDir);
+ xchdir(CDir);
/*
* Handle options as appropriate
@@ -177,7 +160,7 @@ crontab_main(int ac, char **av)
char buf[1024];
snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid());
- fd = bb_xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600);
+ fd = xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600);
chown(tmp, getuid(), getgid());
if ((fi = fopen(pas->pw_name, "r"))) {
while ((n = fread(buf, 1, sizeof(buf), fi)) > 0)
@@ -244,8 +227,7 @@ crontab_main(int ac, char **av)
return 0;
}
-static int
-GetReplaceStream(const char *user, const char *file)
+static int GetReplaceStream(const char *user, const char *file)
{
int filedes[2];
int pid;
@@ -284,7 +266,7 @@ GetReplaceStream(const char *user, const char *file)
exit(0);
bb_default_error_retval = 0;
- fd = bb_xopen3(file, O_RDONLY, 0);
+ fd = xopen3(file, O_RDONLY, 0);
buf[0] = 0;
write(filedes[1], buf, 1);
while ((n = read(fd, buf, sizeof(buf))) > 0) {
@@ -293,8 +275,7 @@ GetReplaceStream(const char *user, const char *file)
exit(0);
}
-static void
-EditFile(const char *user, const char *file)
+static void EditFile(const char *user, const char *file)
{
int pid;
@@ -324,8 +305,7 @@ EditFile(const char *user, const char *file)
wait4(pid, NULL, 0, NULL);
}
-static int
-ChangeUser(const char *user, short dochdir)
+static int ChangeUser(const char *user, short dochdir)
{
struct passwd *pas;
@@ -349,7 +329,7 @@ ChangeUser(const char *user, short dochdir)
if (dochdir) {
if (chdir(pas->pw_dir) < 0) {
bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir);
- bb_xchdir(TMPDIR);
+ xchdir(TMPDIR);
}
}
return(pas->pw_uid);
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c
index 39f04780a..0f36970f9 100644
--- a/miscutils/devfsd.c
+++ b/miscutils/devfsd.c
@@ -475,7 +475,7 @@ int devfsd_main (int argc, char **argv)
if (chdir (mount_point) != 0)
devfsd_perror_msg_and_die(mount_point);
- fd = bb_xopen (".devfsd", O_RDONLY);
+ fd = xopen (".devfsd", O_RDONLY);
if (fcntl (fd, F_SETFD, FD_CLOEXEC) != 0)
devfsd_perror_msg_and_die("FD_CLOEXEC");
@@ -704,7 +704,7 @@ static void process_config_line (const char *line, unsigned long *event_mask)
num_args -= 3;
for (count = 0; count < num_args; ++count)
- new->u.execute.argv[count] = bb_xstrdup (p[count]);
+ new->u.execute.argv[count] = xstrdup (p[count]);
new->u.execute.argv[num_args] = NULL;
break;
@@ -714,8 +714,8 @@ static void process_config_line (const char *line, unsigned long *event_mask)
if (num_args != 2)
goto process_config_line_err; /* missing path and function in line */
- new->u.copy.source = bb_xstrdup (p[0]);
- new->u.copy.destination = bb_xstrdup (p[1]);
+ new->u.copy.source = xstrdup (p[0]);
+ new->u.copy.destination = xstrdup (p[1]);
break;
case 8: /* IGNORE */
/* FALLTROUGH */
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index 925644e1f..aea96d622 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -13,22 +13,8 @@
*/
#include "busybox.h"
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <ctype.h>
-#include <sys/ioctl.h>
-#include <sys/sysmacros.h>
-#include <sys/times.h>
-#include <sys/mman.h>
-#include <linux/types.h>
#include <linux/hdreg.h>
-#if BB_BIG_ENDIAN && !defined(__USE_XOPEN)
-# define __USE_XOPEN
-#endif
-#include <unistd.h>
-
/* device types */
/* ------------ */
#define NO_DEV 0xffff
@@ -1619,7 +1605,7 @@ static void process_dev(char *devname)
unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
const char *fmt = " %s\t= %2ld";
- fd = bb_xopen(devname, O_RDONLY|O_NONBLOCK);
+ fd = xopen(devname, O_RDONLY|O_NONBLOCK);
printf("\n%s:\n", devname);
if (set_readahead)
diff --git a/miscutils/last.c b/miscutils/last.c
index 47c18ffa0..6e35879f3 100644
--- a/miscutils/last.c
+++ b/miscutils/last.c
@@ -8,15 +8,7 @@
*/
#include "busybox.h"
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
#include <utmp.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <time.h>
#ifndef SHUTDOWN_TIME
# define SHUTDOWN_TIME 254
@@ -43,7 +35,7 @@ int last_main(int argc, char **argv)
if (argc > 1) {
bb_show_usage();
}
- file = bb_xopen(bb_path_wtmp_file, O_RDONLY);
+ file = xopen(bb_path_wtmp_file, O_RDONLY);
printf("%-10s %-14s %-18s %-12.12s %s\n", "USER", "TTY", "HOST", "LOGIN", "TIME");
while ((n = safe_read(file, (void*)&ut, sizeof(struct utmp))) != 0) {
diff --git a/miscutils/less.c b/miscutils/less.c
index 596490483..9dd9b9e56 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -31,12 +31,6 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-#include <ctype.h>
#ifdef CONFIG_FEATURE_LESS_REGEXP
#include "xregex.h"
@@ -196,7 +190,7 @@ static void add_linenumbers(void)
for (i = 0; i <= num_flines; i++) {
safe_strncpy(current_line, flines[i], 256);
- flines[i] = bb_xasprintf("%5d %s", i + 1, current_line);
+ flines[i] = xasprintf("%5d %s", i + 1, current_line);
}
}
@@ -206,15 +200,15 @@ static void data_readlines(void)
char current_line[256];
FILE *fp;
- fp = (inp_stdin) ? stdin : bb_xfopen(filename, "r");
+ fp = (inp_stdin) ? stdin : xfopen(filename, "r");
flines = NULL;
for (i = 0; (feof(fp)==0) && (i <= MAXLINES); i++) {
strcpy(current_line, "");
fgets(current_line, 256, fp);
if (fp != stdin)
- bb_xferror(fp, filename);
+ xferror(fp, filename);
flines = xrealloc(flines, (i+1) * sizeof(char *));
- flines[i] = bb_xstrdup(current_line);
+ flines[i] = xstrdup(current_line);
}
num_flines = i - 2;
@@ -226,7 +220,7 @@ static void data_readlines(void)
fclose(fp);
if (inp == NULL)
- inp = (inp_stdin) ? bb_xfopen(CURRENT_TTY, "r") : stdin;
+ inp = (inp_stdin) ? xfopen(CURRENT_TTY, "r") : stdin;
if (flags & FLAG_N)
add_linenumbers();
@@ -357,12 +351,12 @@ static void buffer_init(void)
/* Fill the buffer until the end of the file or the
end of the buffer is reached */
for (i = 0; (i < (height - 1)) && (i <= num_flines); i++) {
- buffer[i] = bb_xstrdup(flines[i]);
+ buffer[i] = xstrdup(flines[i]);
}
/* If the buffer still isn't full, fill it with blank lines */
for (; i < (height - 1); i++) {
- buffer[i] = bb_xstrdup("");
+ buffer[i] = xstrdup("");
}
}
@@ -376,7 +370,7 @@ static void buffer_down(int nlines)
line_pos += nlines;
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
}
}
else {
@@ -386,7 +380,7 @@ static void buffer_down(int nlines)
line_pos += 1;
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
}
}
}
@@ -407,7 +401,7 @@ static void buffer_up(int nlines)
line_pos -= nlines;
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
}
}
else {
@@ -417,7 +411,7 @@ static void buffer_up(int nlines)
line_pos -= 1;
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
}
}
}
@@ -439,10 +433,10 @@ static void buffer_up(int nlines)
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
if (i < tilde_line - nlines + 1)
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
else {
if (line_pos >= num_flines - height + 2)
- buffer[i] = bb_xstrdup("~\n");
+ buffer[i] = xstrdup("~\n");
}
}
}
@@ -461,7 +455,7 @@ static void buffer_line(int linenum)
else if (linenum < (num_flines - height - 2)) {
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[linenum + i]);
+ buffer[i] = xstrdup(flines[linenum + i]);
}
line_pos = linenum;
buffer_print();
@@ -470,9 +464,9 @@ static void buffer_line(int linenum)
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
if (linenum + i < num_flines + 2)
- buffer[i] = bb_xstrdup(flines[linenum + i]);
+ buffer[i] = xstrdup(flines[linenum + i]);
else
- buffer[i] = bb_xstrdup((flags & FLAG_TILDE) ? "\n" : "~\n");
+ buffer[i] = xstrdup((flags & FLAG_TILDE) ? "\n" : "~\n");
}
line_pos = linenum;
/* Set past_eof so buffer_down and buffer_up act differently */
@@ -508,7 +502,7 @@ static void examine_file(void)
newline_offset = strlen(filename) - 1;
filename[newline_offset] = '\0';
- files[num_files] = bb_xstrdup(filename);
+ files[num_files] = xstrdup(filename);
current_file = num_files + 1;
num_files++;
@@ -612,7 +606,7 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
char *growline = "";
regmatch_t match_structs;
- line2 = bb_xstrdup(line);
+ line2 = xstrdup(line);
match_found = 0;
match_status = regexec(pattern, line2, 1, &match_structs, 0);
@@ -622,17 +616,17 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
match_found = 1;
if (action) {
- growline = bb_xasprintf("%s%.*s%s%.*s%s", growline, match_structs.rm_so, line2, HIGHLIGHT, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so, NORMAL);
+ growline = xasprintf("%s%.*s%s%.*s%s", growline, match_structs.rm_so, line2, HIGHLIGHT, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so, NORMAL);
}
else {
- growline = bb_xasprintf("%s%.*s%.*s", growline, match_structs.rm_so - 4, line2, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so);
+ growline = xasprintf("%s%.*s%.*s", growline, match_structs.rm_so - 4, line2, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so);
}
line2 += match_structs.rm_eo;
match_status = regexec(pattern, line2, 1, &match_structs, REG_NOTBOL);
}
- growline = bb_xasprintf("%s%s", growline, line2);
+ growline = xasprintf("%s%s", growline, line2);
return (match_found ? growline : line);
@@ -679,7 +673,7 @@ static void regex_process(void)
/* Get rid of all the highlights we added previously */
for (i = 0; i <= num_flines; i++) {
current_line = process_regex_on_line(flines[i], &old_pattern, 0);
- flines[i] = bb_xstrdup(current_line);
+ flines[i] = xstrdup(current_line);
}
}
old_pattern = pattern;
@@ -693,7 +687,7 @@ static void regex_process(void)
/* Run the regex on each line of the current file here */
for (i = 0; i <= num_flines; i++) {
current_line = process_regex_on_line(flines[i], &pattern, 1);
- flines[i] = bb_xstrdup(current_line);
+ flines[i] = xstrdup(current_line);
if (match_found) {
match_lines = xrealloc(match_lines, (j + 1) * sizeof(int));
match_lines[j] = i;
@@ -864,7 +858,7 @@ static void save_input_to_file(void)
fgets(current_line, 256, inp);
current_line[strlen(current_line) - 1] = '\0';
if (strlen(current_line) > 1) {
- fp = bb_xfopen(current_line, "w");
+ fp = xfopen(current_line, "w");
for (i = 0; i < num_flines; i++)
fprintf(fp, "%s", flines[i]);
fclose(fp);
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c
index 776bcaa8d..0ebb0538f 100644
--- a/miscutils/makedevs.c
+++ b/miscutils/makedevs.c
@@ -8,15 +8,6 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <time.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/sysmacros.h> /* major() and minor() */
#ifdef CONFIG_FEATURE_MAKEDEVS_LEAF
int makedevs_main(int argc, char **argv)
@@ -88,13 +79,13 @@ int makedevs_main(int argc, char **argv)
unsigned long flags;
flags = bb_getopt_ulflags(argc, argv, "d:", &line);
if (line)
- table = bb_xfopen(line, "r");
+ table = xfopen(line, "r");
if (optind >= argc || (rootdir=argv[optind])==NULL) {
bb_error_msg_and_die("root directory not specified");
}
- bb_xchdir(rootdir);
+ xchdir(rootdir);
umask(0);
diff --git a/miscutils/mountpoint.c b/miscutils/mountpoint.c
index 6265a20e1..3e5fb4b46 100644
--- a/miscutils/mountpoint.c
+++ b/miscutils/mountpoint.c
@@ -10,10 +10,6 @@
*/
#include "busybox.h"
-#include <sys/stat.h>
-#include <errno.h> /* errno */
-#include <string.h> /* strerror */
-#include <getopt.h> /* optind */
int mountpoint_main(int argc, char **argv)
{
@@ -46,7 +42,7 @@ int mountpoint_main(int argc, char **argv)
if (S_ISDIR(st.st_mode)) {
dev_t st_dev = st.st_dev;
ino_t st_ino = st.st_ino;
- char *p = bb_xasprintf("%s/..", arg);
+ char *p = xasprintf("%s/..", arg);
if (stat(p, &st) == 0) {
short ret = (st_dev != st.st_dev) ||
diff --git a/miscutils/mt.c b/miscutils/mt.c
index 2720f7eab..f562a91a2 100644
--- a/miscutils/mt.c
+++ b/miscutils/mt.c
@@ -4,11 +4,7 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include <sys/mtio.h>
-#include <fcntl.h>
struct mt_opcodes {
char *name;
@@ -105,7 +101,7 @@ int mt_main(int argc, char **argv)
break;
}
- fd = bb_xopen3(file, mode, 0);
+ fd = xopen3(file, mode, 0);
switch (code->value) {
case MTTELL:
diff --git a/miscutils/rx.c b/miscutils/rx.c
index 41673b60e..4cc4913e6 100644
--- a/miscutils/rx.c
+++ b/miscutils/rx.c
@@ -21,18 +21,6 @@
*/
#include "busybox.h"
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <termios.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-
#define SOH 0x01
#define STX 0x02
@@ -274,8 +262,8 @@ int rx_main(int argc, char **argv)
bb_show_usage();
fn = argv[1];
- ttyfd = bb_xopen3(CURRENT_TTY, O_RDWR, 0);
- filefd = bb_xopen3(fn, O_RDWR|O_CREAT|O_TRUNC, 0666);
+ ttyfd = xopen3(CURRENT_TTY, O_RDWR, 0);
+ filefd = xopen3(fn, O_RDWR|O_CREAT|O_TRUNC, 0666);
if (tcgetattr(ttyfd, &tty) < 0)
bb_error_msg_and_die("%s: tcgetattr failed: %m\n", argv[0]);
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c
index ddd349d9b..ebbab2df3 100644
--- a/miscutils/watchdog.c
+++ b/miscutils/watchdog.c
@@ -9,11 +9,6 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <signal.h>
#define OPT_FOREGROUND 0x01
#define OPT_TIMER 0x02
@@ -47,13 +42,13 @@ int watchdog_main(int argc, char **argv)
if (!(opts & OPT_FOREGROUND))
vfork_daemon_rexec(0, 1, argc, argv, "-F");
#else
- bb_xdaemon(0, 1);
+ xdaemon(0, 1);
#endif
signal(SIGHUP, watchdog_shutdown);
signal(SIGINT, watchdog_shutdown);
- fd = bb_xopen(argv[argc - 1], O_WRONLY);
+ fd = xopen(argv[argc - 1], O_WRONLY);
while (1) {
/*