Compare commits
6
Commits
master
...
1_10_stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9f8b2f830 | ||
|
|
49b78fc1a8 | ||
|
|
a3087ca749 | ||
|
|
0abe9d96ee | ||
|
|
378481ed1e | ||
|
|
fc9fc1f929 |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 10
|
||||
SUBLEVEL = 0
|
||||
SUBLEVEL = 4
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
* "tar: A lone zero block at N", where N = kilobyte
|
||||
* where EOF was met (not EOF block, actual EOF!),
|
||||
* and tar will exit with error code 0.
|
||||
* We will mimic exit(0), although we will not mimic
|
||||
* We will mimic exit(EXIT_SUCCESS), although we will not mimic
|
||||
* the message and we don't check whether we indeed
|
||||
* saw zero block directly before this. */
|
||||
if (i == 0)
|
||||
@@ -112,7 +112,7 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
archive_handle->offset += 512;
|
||||
|
||||
/* If there is no filename its an empty header */
|
||||
if (tar.name[0] == 0) {
|
||||
if (tar.name[0] == 0 && tar.prefix[0] == 0) {
|
||||
if (end) {
|
||||
/* This is the second consecutive empty header! End of archive!
|
||||
* Read until the end to empty the pipe from gz or bz2
|
||||
@@ -138,12 +138,12 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
/* tar gz/bz autodetect: check for gz/bz2 magic.
|
||||
* If it is the very first block, and we see the magic,
|
||||
* we can switch to get_header_tar_gz/bz2/lzma().
|
||||
* Needs seekable fd. I wish recv(MSG_PEEK) would work
|
||||
* Needs seekable fd. I wish recv(MSG_PEEK) works
|
||||
* on any fd... */
|
||||
if (not_first)
|
||||
goto err;
|
||||
#if ENABLE_FEATURE_TAR_GZIP
|
||||
if (tar.name[0] == 0x1f && tar.name[1] == 0x8b) { /* gzip */
|
||||
if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */
|
||||
get_header_ptr = get_header_tar_gz;
|
||||
} else
|
||||
#endif
|
||||
@@ -211,15 +211,16 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
/* getOctal trashes subsequent field, therefore we call it
|
||||
* on fields in reverse order */
|
||||
if (tar.devmajor[0]) {
|
||||
char t = tar.prefix[0];
|
||||
/* we trash prefix[0] here, but we DO need it later! */
|
||||
unsigned minor = GET_OCTAL(tar.devminor);
|
||||
unsigned major = GET_OCTAL(tar.devmajor);
|
||||
file_header->device = makedev(major, minor);
|
||||
tar.prefix[0] = t;
|
||||
}
|
||||
file_header->link_target = NULL;
|
||||
if (!linkname && parse_names && tar.linkname[0]) {
|
||||
/* we trash magic[0] here, it's ok */
|
||||
tar.linkname[sizeof(tar.linkname)] = '\0';
|
||||
file_header->link_target = xstrdup(tar.linkname);
|
||||
file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname));
|
||||
/* FIXME: what if we have non-link object with link_target? */
|
||||
/* Will link_target be free()ed? */
|
||||
}
|
||||
@@ -237,10 +238,12 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
file_header->name = NULL;
|
||||
if (!longname && parse_names) {
|
||||
/* we trash mode[0] here, it's ok */
|
||||
tar.name[sizeof(tar.name)] = '\0';
|
||||
//tar.name[sizeof(tar.name)] = '\0'; - gcc 4.3.0 would complain
|
||||
tar.mode[0] = '\0';
|
||||
if (tar.prefix[0]) {
|
||||
/* and padding[0] */
|
||||
tar.prefix[sizeof(tar.prefix)] = '\0';
|
||||
//tar.prefix[sizeof(tar.prefix)] = '\0'; - gcc 4.3.0 would complain
|
||||
tar.padding[0] = '\0';
|
||||
file_header->name = concat_path_file(tar.prefix, tar.name);
|
||||
} else
|
||||
file_header->name = xstrdup(tar.name);
|
||||
|
||||
+9
-7
@@ -27,10 +27,8 @@
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
/* argc is unused, but removing it precludes compiler from
|
||||
* using call -> jump optimization */
|
||||
/* NB: can be used by shell even if not enabled as applet */
|
||||
|
||||
int echo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int echo_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
const char *arg;
|
||||
@@ -110,15 +108,19 @@ int echo_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
}
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
/* SUSv3 specifies that octal escapes must begin with '0'. */
|
||||
if ( (((unsigned char)*arg) - '1') >= 7)
|
||||
if ( ((int)(unsigned char)(*arg) - '0') >= 8) /* '8' or bigger */
|
||||
#endif
|
||||
{
|
||||
/* Since SUSv3 mandates a first digit of 0, 4-digit octals
|
||||
* of the form \0### are accepted. */
|
||||
if (*arg == '0' && ((unsigned char)(arg[1]) - '0') < 8) {
|
||||
arg++;
|
||||
if (*arg == '0') {
|
||||
/* NB: don't turn "...\0" into "...\" */
|
||||
if (arg[1] && ((unsigned char)(arg[1]) - '0') < 8) {
|
||||
arg++;
|
||||
}
|
||||
}
|
||||
/* bb_process_escape_sequence can handle nul correctly */
|
||||
/* bb_process_escape_sequence handles NUL correctly
|
||||
* ("...\" case). */
|
||||
c = bb_process_escape_sequence(&arg);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-13
@@ -163,8 +163,6 @@ int tail_main(int argc, char **argv)
|
||||
fmt = header_fmt + 1; /* Skip header leading newline on first output. */
|
||||
i = 0;
|
||||
do {
|
||||
off_t current;
|
||||
|
||||
if (nfiles > header_threshhold) {
|
||||
tail_xprint_header(fmt, argv[i]);
|
||||
fmt = header_fmt;
|
||||
@@ -173,19 +171,17 @@ int tail_main(int argc, char **argv)
|
||||
/* Optimizing count-bytes case if the file is seekable.
|
||||
* Beware of backing up too far.
|
||||
* Also we exclude files with size 0 (because of /proc/xxx) */
|
||||
current = lseek(fds[i], 0, SEEK_END);
|
||||
if (current > 0) {
|
||||
if (!from_top) {
|
||||
if (COUNT_BYTES && !from_top) {
|
||||
off_t current = lseek(fds[i], 0, SEEK_END);
|
||||
if (current > 0) {
|
||||
if (count == 0)
|
||||
continue; /* showing zero lines is easy :) */
|
||||
if (COUNT_BYTES) {
|
||||
current -= count;
|
||||
if (current < 0)
|
||||
current = 0;
|
||||
xlseek(fds[i], current, SEEK_SET);
|
||||
bb_copyfd_size(fds[i], STDOUT_FILENO, count);
|
||||
continue;
|
||||
}
|
||||
current -= count;
|
||||
if (current < 0)
|
||||
current = 0;
|
||||
xlseek(fds[i], current, SEEK_SET);
|
||||
bb_copyfd_size(fds[i], STDOUT_FILENO, count);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
/* NB: we have a problem here with /proc/NN/exe usage, similar to
|
||||
* one fixed in killall/pidof */
|
||||
|
||||
#include <getopt.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
/* Override ENABLE_FEATURE_PIDFILE */
|
||||
@@ -33,6 +32,7 @@ struct globals {
|
||||
int user_id;
|
||||
smallint quiet;
|
||||
smallint signal_nr;
|
||||
struct stat execstat;
|
||||
};
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define found (G.found )
|
||||
@@ -43,6 +43,7 @@ struct globals {
|
||||
#define user_id (G.user_id )
|
||||
#define quiet (G.quiet )
|
||||
#define signal_nr (G.signal_nr )
|
||||
#define execstat (G.execstat )
|
||||
#define INIT_G() \
|
||||
do { \
|
||||
user_id = -1; \
|
||||
@@ -50,25 +51,21 @@ struct globals {
|
||||
} while (0)
|
||||
|
||||
|
||||
static int pid_is_exec(pid_t pid, const char *name)
|
||||
static int pid_is_exec(pid_t pid)
|
||||
{
|
||||
struct stat st;
|
||||
char buf[sizeof("/proc//exe") + sizeof(int)*3];
|
||||
char *execbuf;
|
||||
int n;
|
||||
|
||||
sprintf(buf, "/proc/%u/exe", pid);
|
||||
n = strlen(name) + 1;
|
||||
execbuf = xzalloc(n + 1);
|
||||
readlink(buf, execbuf, n);
|
||||
/* if readlink fails because link target is longer than strlen(name),
|
||||
* execbuf still contains "", and strcmp will return !0. */
|
||||
n = strcmp(execbuf, name);
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(execbuf);
|
||||
return !n; /* nonzero (true) if execbuf == name */
|
||||
if (stat(buf, &st) < 0)
|
||||
return 0;
|
||||
if (st.st_dev == execstat.st_dev
|
||||
&& st.st_ino == execstat.st_ino)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pid_is_user(int pid, int uid)
|
||||
static int pid_is_user(int pid)
|
||||
{
|
||||
struct stat sb;
|
||||
char buf[sizeof("/proc/") + sizeof(int)*3];
|
||||
@@ -76,42 +73,39 @@ static int pid_is_user(int pid, int uid)
|
||||
sprintf(buf, "/proc/%u", pid);
|
||||
if (stat(buf, &sb) != 0)
|
||||
return 0;
|
||||
return (sb.st_uid == uid);
|
||||
return (sb.st_uid == user_id);
|
||||
}
|
||||
|
||||
static int pid_is_cmd(pid_t pid, const char *name)
|
||||
static int pid_is_cmd(pid_t pid)
|
||||
{
|
||||
char fname[sizeof("/proc//stat") + sizeof(int)*3];
|
||||
char *buf;
|
||||
int r = 0;
|
||||
char buf[256]; /* is it big enough? */
|
||||
char *p, *pe;
|
||||
|
||||
sprintf(fname, "/proc/%u/stat", pid);
|
||||
buf = xmalloc_open_read_close(fname, NULL);
|
||||
if (buf) {
|
||||
char *p = strchr(buf, '(');
|
||||
if (p) {
|
||||
char *pe = strrchr(++p, ')');
|
||||
if (pe) {
|
||||
*pe = '\0';
|
||||
r = !strcmp(p, name);
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
return r;
|
||||
sprintf(buf, "/proc/%u/stat", pid);
|
||||
if (open_read_close(buf, buf, sizeof(buf) - 1) < 0)
|
||||
return 0;
|
||||
buf[sizeof(buf) - 1] = '\0'; /* paranoia */
|
||||
p = strchr(buf, '(');
|
||||
if (!p)
|
||||
return 0;
|
||||
pe = strrchr(++p, ')');
|
||||
if (!pe)
|
||||
return 0;
|
||||
*pe = '\0';
|
||||
return !strcmp(p, cmdname);
|
||||
}
|
||||
|
||||
static void check(int pid)
|
||||
{
|
||||
struct pid_list *p;
|
||||
|
||||
if (execname && !pid_is_exec(pid, execname)) {
|
||||
if (execname && !pid_is_exec(pid)) {
|
||||
return;
|
||||
}
|
||||
if (userspec && !pid_is_user(pid, user_id)) {
|
||||
if (userspec && !pid_is_user(pid)) {
|
||||
return;
|
||||
}
|
||||
if (cmdname && !pid_is_cmd(pid, cmdname)) {
|
||||
if (cmdname && !pid_is_cmd(pid)) {
|
||||
return;
|
||||
}
|
||||
p = xmalloc(sizeof(*p));
|
||||
@@ -148,9 +142,16 @@ static void do_procinit(void)
|
||||
procdir = xopendir("/proc");
|
||||
|
||||
pid = 0;
|
||||
while ((entry = readdir(procdir)) != NULL) {
|
||||
while(1) {
|
||||
errno = 0; /* clear any previous error */
|
||||
entry = readdir(procdir);
|
||||
// TODO: check for exact errno(s) which mean that we got stale entry
|
||||
if (errno) /* Stale entry, process has died after opendir */
|
||||
continue;
|
||||
if (!entry) /* EOF, no more entries */
|
||||
break;
|
||||
pid = bb_strtou(entry->d_name, NULL, 10);
|
||||
if (errno)
|
||||
if (errno) /* NaN */
|
||||
continue;
|
||||
check(pid);
|
||||
}
|
||||
@@ -165,8 +166,6 @@ static int do_stop(void)
|
||||
struct pid_list *p;
|
||||
int killed = 0;
|
||||
|
||||
do_procinit();
|
||||
|
||||
if (cmdname) {
|
||||
if (ENABLE_FEATURE_CLEAN_UP) what = xstrdup(cmdname);
|
||||
if (!ENABLE_FEATURE_CLEAN_UP) what = cmdname;
|
||||
@@ -251,7 +250,7 @@ enum {
|
||||
};
|
||||
|
||||
int start_stop_daemon_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int start_stop_daemon_main(int argc, char **argv)
|
||||
int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
unsigned opt;
|
||||
char *signame;
|
||||
@@ -293,7 +292,7 @@ int start_stop_daemon_main(int argc, char **argv)
|
||||
// if (retry_arg)
|
||||
// retries = xatoi_u(retry_arg);
|
||||
// )
|
||||
argc -= optind;
|
||||
//argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (userspec) {
|
||||
@@ -301,14 +300,16 @@ int start_stop_daemon_main(int argc, char **argv)
|
||||
if (errno)
|
||||
user_id = xuname2uid(userspec);
|
||||
}
|
||||
if (execname)
|
||||
xstat(execname, &execstat);
|
||||
|
||||
do_procinit(); /* Both start and stop needs to know current processes */
|
||||
|
||||
if (opt & CTX_STOP) {
|
||||
int i = do_stop();
|
||||
return (opt & OPT_OKNODO) ? 0 : (i <= 0);
|
||||
}
|
||||
|
||||
do_procinit();
|
||||
|
||||
if (found) {
|
||||
if (!quiet)
|
||||
printf("%s already running\n%d\n", execname, found->pid);
|
||||
|
||||
+20
-20
@@ -288,20 +288,20 @@ enum {
|
||||
* SIGSYS Bad argument to routine
|
||||
* SIGTRAP Trace/breakpoint trap
|
||||
*/
|
||||
BB_FATAL_SIGS = 0
|
||||
+ (1 << SIGHUP)
|
||||
+ (1 << SIGINT)
|
||||
+ (1 << SIGTERM)
|
||||
+ (1 << SIGPIPE) // Write to pipe with no readers
|
||||
+ (1 << SIGQUIT) // Quit from keyboard
|
||||
+ (1 << SIGABRT) // Abort signal from abort(3)
|
||||
+ (1 << SIGALRM) // Timer signal from alarm(2)
|
||||
+ (1 << SIGVTALRM) // Virtual alarm clock
|
||||
+ (1 << SIGXCPU) // CPU time limit exceeded
|
||||
+ (1 << SIGXFSZ) // File size limit exceeded
|
||||
+ (1 << SIGUSR1) // Yes kids, these are also fatal!
|
||||
+ (1 << SIGUSR2)
|
||||
+ 0,
|
||||
BB_FATAL_SIGS = (int)(0
|
||||
+ (1LL << SIGHUP)
|
||||
+ (1LL << SIGINT)
|
||||
+ (1LL << SIGTERM)
|
||||
+ (1LL << SIGPIPE) // Write to pipe with no readers
|
||||
+ (1LL << SIGQUIT) // Quit from keyboard
|
||||
+ (1LL << SIGABRT) // Abort signal from abort(3)
|
||||
+ (1LL << SIGALRM) // Timer signal from alarm(2)
|
||||
+ (1LL << SIGVTALRM) // Virtual alarm clock
|
||||
+ (1LL << SIGXCPU) // CPU time limit exceeded
|
||||
+ (1LL << SIGXFSZ) // File size limit exceeded
|
||||
+ (1LL << SIGUSR1) // Yes kids, these are also fatal!
|
||||
+ (1LL << SIGUSR2)
|
||||
+ 0),
|
||||
};
|
||||
void bb_signals(int sigs, void (*f)(int));
|
||||
/* Unlike signal() and bb_signals, sets handler with sigaction()
|
||||
@@ -995,16 +995,16 @@ extern int update_passwd(const char *filename, const char *username,
|
||||
/* NB: typically you want to pass fd 0, not 1. Think 'applet | grep something' */
|
||||
int get_terminal_width_height(int fd, int *width, int *height);
|
||||
|
||||
int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
|
||||
void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
|
||||
int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
|
||||
void ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
|
||||
#if ENABLE_IOCTL_HEX2STR_ERROR
|
||||
int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name);
|
||||
void bb_xioctl(int fd, int request, void *argp, const char *ioctl_name);
|
||||
int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name);
|
||||
void bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name);
|
||||
#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp,#request)
|
||||
#define xioctl(fd,request,argp) bb_xioctl(fd,request,argp,#request)
|
||||
#else
|
||||
int bb_ioctl_or_warn(int fd, int request, void *argp);
|
||||
void bb_xioctl(int fd, int request, void *argp);
|
||||
int bb_ioctl_or_warn(int fd, unsigned request, void *argp);
|
||||
void bb_xioctl(int fd, unsigned request, void *argp);
|
||||
#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp)
|
||||
#define xioctl(fd,request,argp) bb_xioctl(fd,request,argp)
|
||||
#endif
|
||||
|
||||
+8
-4
@@ -1613,27 +1613,31 @@
|
||||
" # ifenslave -c bond0 eth0\n" \
|
||||
|
||||
#define ifup_trivial_usage \
|
||||
"[-ahinv] ifaces..."
|
||||
"[-ain"USE_FEATURE_IFUPDOWN_MAPPING("m")"vf] ifaces..."
|
||||
#define ifup_full_usage \
|
||||
"Options:" \
|
||||
"\n -a De/configure all interfaces automatically" \
|
||||
"\n -i FILE Use FILE for interface definitions" \
|
||||
"\n -n Print out what would happen, but don't do it" \
|
||||
USE_FEATURE_IFUPDOWN_MAPPING( \
|
||||
"\n (note: doesn't disable mappings)" \
|
||||
"\n -v Print out what would happen before doing it" \
|
||||
"\n -m Don't run any mappings" \
|
||||
) \
|
||||
"\n -v Print out what would happen before doing it" \
|
||||
"\n -f Force de/configuration" \
|
||||
|
||||
#define ifdown_trivial_usage \
|
||||
"[-ahinv] ifaces..."
|
||||
"[-ain"USE_FEATURE_IFUPDOWN_MAPPING("m")"vf] ifaces..."
|
||||
#define ifdown_full_usage \
|
||||
"Options:" \
|
||||
"\n -a De/configure all interfaces automatically" \
|
||||
"\n -i FILE Use FILE for interface definitions" \
|
||||
"\n -n Print out what would happen, but don't do it" \
|
||||
USE_FEATURE_IFUPDOWN_MAPPING( \
|
||||
"\n (note: doesn't disable mappings)" \
|
||||
"\n -v Print out what would happen before doing it" \
|
||||
"\n -m Don't run any mappings" \
|
||||
) \
|
||||
"\n -v Print out what would happen before doing it" \
|
||||
"\n -f Force de/configuration" \
|
||||
|
||||
#define inetd_trivial_usage \
|
||||
|
||||
+26
-21
@@ -33,14 +33,15 @@
|
||||
#endif
|
||||
|
||||
/* Allowed init action types */
|
||||
#define SYSINIT 0x001
|
||||
#define RESPAWN 0x002
|
||||
#define ASKFIRST 0x004
|
||||
#define WAIT 0x008
|
||||
#define ONCE 0x010
|
||||
#define CTRLALTDEL 0x020
|
||||
#define SHUTDOWN 0x040
|
||||
#define RESTART 0x080
|
||||
#define SYSINIT 0x01
|
||||
#define RESPAWN 0x02
|
||||
/* like respawn, but wait for <Enter> to be pressed on tty: */
|
||||
#define ASKFIRST 0x04
|
||||
#define WAIT 0x08
|
||||
#define ONCE 0x10
|
||||
#define CTRLALTDEL 0x20
|
||||
#define SHUTDOWN 0x40
|
||||
#define RESTART 0x80
|
||||
|
||||
#define STR_SYSINIT "\x01"
|
||||
#define STR_RESPAWN "\x02"
|
||||
@@ -372,7 +373,10 @@ static pid_t run(const struct init_action *a)
|
||||
sigemptyset(&nmask);
|
||||
sigaddset(&nmask, SIGCHLD);
|
||||
sigprocmask(SIG_BLOCK, &nmask, &omask);
|
||||
pid = vfork();
|
||||
if (BB_MMU && (a->action_type & ASKFIRST))
|
||||
pid = fork();
|
||||
else
|
||||
pid = vfork();
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
|
||||
if (pid < 0)
|
||||
@@ -447,7 +451,8 @@ static pid_t run(const struct init_action *a)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* NB: on NOMMU we can't wait for input in child */
|
||||
/* NB: on NOMMU we can't wait for input in child, so
|
||||
* "askfirst" will work the same as "respawn". */
|
||||
if (BB_MMU && (a->action_type & ASKFIRST)) {
|
||||
static const char press_enter[] ALIGN1 =
|
||||
#ifdef CUSTOMIZED_BANNER
|
||||
@@ -499,7 +504,7 @@ static void run_actions(int action_type)
|
||||
|
||||
for (a = init_action_list; a; a = tmp) {
|
||||
tmp = a->next;
|
||||
if (a->action_type == action_type) {
|
||||
if (a->action_type & action_type) {
|
||||
// Pointless: run() will error out if open of device fails.
|
||||
///* a->terminal of "" means "init's console" */
|
||||
//if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) {
|
||||
@@ -784,6 +789,7 @@ static void parse_inittab(void)
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_USE_INITTAB
|
||||
static void reload_signal(int sig ATTRIBUTE_UNUSED)
|
||||
{
|
||||
struct init_action *a, *tmp;
|
||||
@@ -827,8 +833,9 @@ static void reload_signal(int sig ATTRIBUTE_UNUSED)
|
||||
delete_init_action(a);
|
||||
}
|
||||
}
|
||||
run_actions(RESPAWN);
|
||||
run_actions(RESPAWN | ASKFIRST);
|
||||
}
|
||||
#endif
|
||||
|
||||
int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int init_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
@@ -952,18 +959,16 @@ int init_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
run_actions(ONCE);
|
||||
|
||||
/* Redefine SIGHUP to reread /etc/inittab */
|
||||
if (ENABLE_FEATURE_USE_INITTAB)
|
||||
signal(SIGHUP, reload_signal);
|
||||
else
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
#if ENABLE_FEATURE_USE_INITTAB
|
||||
signal(SIGHUP, reload_signal);
|
||||
#else
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
#endif
|
||||
|
||||
/* Now run the looping stuff for the rest of forever */
|
||||
while (1) {
|
||||
/* run the respawn stuff */
|
||||
run_actions(RESPAWN);
|
||||
|
||||
/* run the askfirst stuff */
|
||||
run_actions(ASKFIRST);
|
||||
/* run the respawn/askfirst stuff */
|
||||
run_actions(RESPAWN | ASKFIRST);
|
||||
|
||||
/* Don't consume all CPU time -- sleep a bit */
|
||||
sleep(1);
|
||||
|
||||
+11
-8
@@ -518,8 +518,8 @@ static void exe_n_cwd_tab_completion(char *command, int type)
|
||||
|
||||
for (i = 0; i < npaths; i++) {
|
||||
dir = opendir(paths[i]);
|
||||
if (!dir) /* Don't print an error */
|
||||
continue;
|
||||
if (!dir)
|
||||
continue; /* don't print an error */
|
||||
|
||||
while ((next = readdir(dir)) != NULL) {
|
||||
int len1;
|
||||
@@ -529,18 +529,21 @@ static void exe_n_cwd_tab_completion(char *command, int type)
|
||||
if (strncmp(str_found, pfind, strlen(pfind)))
|
||||
continue;
|
||||
/* not see .name without .match */
|
||||
if (*str_found == '.' && *pfind == 0) {
|
||||
if (*str_found == '.' && *pfind == '\0') {
|
||||
if (NOT_LONE_CHAR(paths[i], '/') || str_found[1])
|
||||
continue;
|
||||
str_found = ""; /* only "/" */
|
||||
}
|
||||
found = concat_path_file(paths[i], str_found);
|
||||
/* hmm, remover in progress? */
|
||||
if (lstat(found, &st) < 0)
|
||||
/* hmm, remove in progress? */
|
||||
/* NB: stat() first so that we see is it a directory;
|
||||
* but if that fails, use lstat() so that
|
||||
* we still match dangling links */
|
||||
if (stat(found, &st) && lstat(found, &st))
|
||||
goto cont;
|
||||
/* find with dirs? */
|
||||
if (paths[i] != dirbuf)
|
||||
strcpy(found, next->d_name); /* only name */
|
||||
strcpy(found, next->d_name); /* only name */
|
||||
|
||||
len1 = strlen(found);
|
||||
found = xrealloc(found, len1 + 2);
|
||||
@@ -548,7 +551,7 @@ static void exe_n_cwd_tab_completion(char *command, int type)
|
||||
found[len1+1] = '\0';
|
||||
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
/* name is directory */
|
||||
/* name is a directory */
|
||||
if (found[len1-1] != '/') {
|
||||
found[len1] = '/';
|
||||
}
|
||||
@@ -566,7 +569,7 @@ static void exe_n_cwd_tab_completion(char *command, int type)
|
||||
closedir(dir);
|
||||
}
|
||||
if (paths != path1) {
|
||||
free(paths[0]); /* allocated memory only in first member */
|
||||
free(paths[0]); /* allocated memory is only in first member */
|
||||
free(paths);
|
||||
}
|
||||
#undef dirbuf
|
||||
|
||||
+1
-1
@@ -258,7 +258,7 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags)
|
||||
&sp->start_time,
|
||||
&vsz,
|
||||
&rss);
|
||||
if (n != 10)
|
||||
if (n != 11)
|
||||
break;
|
||||
/* vsz is in bytes and we want kb */
|
||||
sp->vsz = vsz >> 10;
|
||||
|
||||
+11
-6
@@ -36,11 +36,12 @@ send_to_from(int fd, void *buf, size_t len, int flags,
|
||||
#else
|
||||
struct iovec iov[1];
|
||||
struct msghdr msg;
|
||||
char cbuf[sizeof(struct in_pktinfo)
|
||||
union {
|
||||
char cmsg[CMSG_SPACE(sizeof(struct in_pktinfo))];
|
||||
#if ENABLE_FEATURE_IPV6 && defined(IPV6_PKTINFO)
|
||||
| sizeof(struct in6_pktinfo) /* (a|b) is poor man's max(a,b) */
|
||||
char cmsg6[CMSG_SPACE(sizeof(struct in6_pktinfo))];
|
||||
#endif
|
||||
];
|
||||
} u;
|
||||
struct cmsghdr* cmsgptr;
|
||||
|
||||
if (from->sa_family != AF_INET
|
||||
@@ -57,15 +58,15 @@ send_to_from(int fd, void *buf, size_t len, int flags,
|
||||
iov[0].iov_base = buf;
|
||||
iov[0].iov_len = len;
|
||||
|
||||
memset(cbuf, 0, sizeof(cbuf));
|
||||
memset(&u, 0, sizeof(u));
|
||||
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.msg_name = (void *)(struct sockaddr *)to; /* or compiler will annoy us */
|
||||
msg.msg_namelen = tolen;
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_control = cbuf;
|
||||
msg.msg_controllen = sizeof(cbuf);
|
||||
msg.msg_control = &u;
|
||||
msg.msg_controllen = sizeof(u);
|
||||
msg.msg_flags = flags;
|
||||
|
||||
cmsgptr = CMSG_FIRSTHDR(&msg);
|
||||
@@ -89,6 +90,8 @@ send_to_from(int fd, void *buf, size_t len, int flags,
|
||||
pktptr->ipi6_addr = ((struct sockaddr_in6*)from)->sin6_addr;
|
||||
}
|
||||
#endif
|
||||
msg.msg_controllen = cmsgptr->cmsg_len;
|
||||
|
||||
return sendmsg(fd, &msg, flags);
|
||||
#endif
|
||||
}
|
||||
@@ -109,7 +112,9 @@ recv_from_to(int fd, void *buf, size_t len, int flags,
|
||||
struct iovec iov[1];
|
||||
union {
|
||||
char cmsg[CMSG_SPACE(sizeof(struct in_pktinfo))];
|
||||
#if ENABLE_FEATURE_IPV6 && defined(IPV6_PKTINFO)
|
||||
char cmsg6[CMSG_SPACE(sizeof(struct in6_pktinfo))];
|
||||
#endif
|
||||
} u;
|
||||
struct cmsghdr *cmsgptr;
|
||||
struct msghdr msg;
|
||||
|
||||
+6
-6
@@ -704,7 +704,7 @@ int get_terminal_width_height(int fd, int *width, int *height)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...)
|
||||
void ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...)
|
||||
{
|
||||
va_list p;
|
||||
|
||||
@@ -717,7 +717,7 @@ void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,..
|
||||
}
|
||||
}
|
||||
|
||||
int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...)
|
||||
int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...)
|
||||
{
|
||||
va_list p;
|
||||
int ret = ioctl(fd, request, argp);
|
||||
@@ -731,7 +731,7 @@ int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...)
|
||||
}
|
||||
|
||||
#if ENABLE_IOCTL_HEX2STR_ERROR
|
||||
int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name)
|
||||
int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -740,13 +740,13 @@ int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name)
|
||||
bb_simple_perror_msg(ioctl_name);
|
||||
return ret;
|
||||
}
|
||||
void bb_xioctl(int fd, int request, void *argp, const char *ioctl_name)
|
||||
void bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name)
|
||||
{
|
||||
if (ioctl(fd, request, argp) < 0)
|
||||
bb_simple_perror_msg_and_die(ioctl_name);
|
||||
}
|
||||
#else
|
||||
int bb_ioctl_or_warn(int fd, int request, void *argp)
|
||||
int bb_ioctl_or_warn(int fd, unsigned request, void *argp)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -755,7 +755,7 @@ int bb_ioctl_or_warn(int fd, int request, void *argp)
|
||||
bb_perror_msg("ioctl %#x failed", request);
|
||||
return ret;
|
||||
}
|
||||
void bb_xioctl(int fd, int request, void *argp)
|
||||
void bb_xioctl(int fd, unsigned request, void *argp)
|
||||
{
|
||||
if (ioctl(fd, request, argp) < 0)
|
||||
bb_perror_msg_and_die("ioctl %#x failed", request);
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ int last_main(int argc, char **argv ATTRIBUTE_UNUSED)
|
||||
ut.ut_type = SHUTDOWN_TIME;
|
||||
else if (strncmp(ut.ut_user, "reboot", 6) == 0)
|
||||
ut.ut_type = BOOT_TIME;
|
||||
else if (strncmp(ut.ut_user, "runlevel", 7) == 0)
|
||||
else if (strncmp(ut.ut_user, "runlevel", 8) == 0)
|
||||
ut.ut_type = RUN_LVL;
|
||||
} else {
|
||||
if (ut.ut_name[0] == '\0' || strcmp(ut.ut_name, "LOGIN") == 0) {
|
||||
|
||||
+5
-6
@@ -384,6 +384,10 @@ static void read_lines(void)
|
||||
linepos = 0;
|
||||
} /* end of "read lines until we reach cur_fline" loop */
|
||||
fill_match_lines(old_max_fline);
|
||||
#if ENABLE_FEATURE_LESS_REGEXP
|
||||
/* prevent us from being stuck in search for a match */
|
||||
wanted_match = -1;
|
||||
#endif
|
||||
#undef readbuf
|
||||
}
|
||||
|
||||
@@ -904,13 +908,8 @@ static void goto_match(int match)
|
||||
match = 0;
|
||||
/* Try to find next match if eof isn't reached yet */
|
||||
if (match >= num_matches && eof_error > 0) {
|
||||
wanted_match = match;
|
||||
wanted_match = match; /* "I want to read until I see N'th match" */
|
||||
read_lines();
|
||||
if (wanted_match >= num_matches) {
|
||||
/* We still failed to find it. Prevent future
|
||||
* read_lines() from trying... */
|
||||
wanted_match = num_matches - 1;
|
||||
}
|
||||
}
|
||||
if (num_matches) {
|
||||
normalize_match_pos(match);
|
||||
|
||||
+8
-1
@@ -50,6 +50,11 @@ int taskset_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
char *pid_str;
|
||||
char *aff = aff; /* for compiler */
|
||||
|
||||
/* NB: we mimic util-linux's taskset: -p does not take
|
||||
* an argument, i.e., "-pN" is NOT valid, only "-p N"!
|
||||
* Indeed, util-linux-2.13-pre7 uses:
|
||||
* getopt_long(argc, argv, "+pchV", ...), not "...p:..." */
|
||||
|
||||
opt_complementary = "-1"; /* at least 1 arg */
|
||||
opt_p = getopt32(argv, "+p");
|
||||
argv += optind;
|
||||
@@ -89,8 +94,10 @@ int taskset_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
unsigned i;
|
||||
/* Do not allow zero mask: */
|
||||
unsigned long long m = xstrtoull_range(aff, 0, 1, ULLONG_MAX);
|
||||
enum { CNT_BIT = CPU_SETSIZE < sizeof(m)*8 ? CPU_SETSIZE : sizeof(m)*8 };
|
||||
|
||||
CPU_ZERO(&mask);
|
||||
for (i = 0; i < CPU_SETSIZE; i++) {
|
||||
for (i = 0; i < CNT_BIT; i++) {
|
||||
unsigned long long bit = (1ULL << i);
|
||||
if (bit & m)
|
||||
CPU_SET(i, &mask);
|
||||
|
||||
+5
-3
@@ -194,7 +194,8 @@ static int table_lookup(uint16_t type, uint8_t * as, uint8_t * qs)
|
||||
for (i = 1; i <= (int)(d->name[0]); i++)
|
||||
if (tolower(qs[i]) != d->name[i])
|
||||
break;
|
||||
if (i > (int)(d->name[0])) {
|
||||
if (i > (int)(d->name[0]) ||
|
||||
(d->name[0] == 1 && d->name[1] == '*')) {
|
||||
strcpy((char *)as, d->ip);
|
||||
#if DEBUG
|
||||
fprintf(stderr, " OK as:%s\n", as);
|
||||
@@ -202,7 +203,8 @@ static int table_lookup(uint16_t type, uint8_t * as, uint8_t * qs)
|
||||
return 0;
|
||||
}
|
||||
} else if (type == REQ_PTR) { /* search by IP-address */
|
||||
if (!strncmp((char*)&d->rip[1], (char*)&qs[1], strlen(d->rip)-1)) {
|
||||
if ((d->name[0] != 1 || d->name[1] != '*') &&
|
||||
!strncmp((char*)&d->rip[1], (char*)&qs[1], strlen(d->rip)-1)) {
|
||||
strcpy((char *)as, d->name);
|
||||
return 0;
|
||||
}
|
||||
@@ -401,7 +403,7 @@ int dnsd_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
r = process_packet(buf);
|
||||
if (r <= 0)
|
||||
continue;
|
||||
send_to_from(udps, buf, r, 0, &to->u.sa, &from->u.sa, lsa->len);
|
||||
send_to_from(udps, buf, r, 0, &from->u.sa, &to->u.sa, lsa->len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1457,6 +1457,11 @@ static void send_cgi_and_exit(
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* restore default signal dispositions for CGI process */
|
||||
signal(SIGCHLD, SIG_DFL);
|
||||
signal(SIGPIPE, SIG_DFL);
|
||||
signal(SIGHUP, SIG_DFL);
|
||||
|
||||
execv(fullpath, argv);
|
||||
if (verbose)
|
||||
bb_perror_msg("exec %s", fullpath);
|
||||
|
||||
@@ -223,7 +223,7 @@ static char *UNSPEC_print(unsigned char *ptr)
|
||||
char *pos;
|
||||
unsigned int i;
|
||||
|
||||
if (!buff);
|
||||
if (!buff)
|
||||
buff = xmalloc(sizeof(struct sockaddr) * 3 + 1);
|
||||
pos = buff;
|
||||
for (i = 0; i < sizeof(struct sockaddr); i++) {
|
||||
|
||||
@@ -113,7 +113,7 @@ int fakeidentd_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
strncpy(bogouser, argv[optind], sizeof(bogouser));
|
||||
|
||||
/* Daemonize if no -f and no -i and no -w */
|
||||
if (!(opt & OPT_fiw));
|
||||
if (!(opt & OPT_fiw))
|
||||
bb_daemonize_or_rexec(0, argv);
|
||||
|
||||
/* Where to log in inetd modes? "Classic" inetd
|
||||
|
||||
@@ -54,7 +54,7 @@ char **ip_parse_common_args(char **argv)
|
||||
break;
|
||||
}
|
||||
}
|
||||
arg = index_in_strings(ip_common_commands, opt);
|
||||
arg = index_in_substrings(ip_common_commands, opt);
|
||||
if (arg < 0)
|
||||
bb_show_usage();
|
||||
if (arg == ARG_oneline) {
|
||||
|
||||
+29
-17
@@ -5,6 +5,7 @@
|
||||
* Written 2000 by Andi Kleen.
|
||||
* Busybox port 2002 by Nick Fedchik <nick@fedchik.org.ua>
|
||||
* Glenn McGrath
|
||||
* Extended matching support 2008 by Nico Erfurth <masta@perlgolf.de>
|
||||
*
|
||||
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||
*/
|
||||
@@ -93,12 +94,10 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector)
|
||||
found_selector++;
|
||||
} else {
|
||||
#endif
|
||||
lmac = ether_aton(selector + (strncmp(selector, "mac=", 4) == 0 ? 4 : 0));
|
||||
/* Check ascii selector, convert and copy to *mac */
|
||||
if (lmac == NULL)
|
||||
lmac = xmalloc(ETH_ALEN);
|
||||
ch->mac = ether_aton_r(selector + (strncmp(selector, "mac=", 4) ? 0 : 4), lmac);
|
||||
if (ch->mac == NULL)
|
||||
bb_error_msg_and_die("cannot parse %s", selector);
|
||||
ch->mac = xmalloc(ETH_ALEN);
|
||||
memcpy(ch->mac, lmac, ETH_ALEN);
|
||||
#if ENABLE_FEATURE_NAMEIF_EXTENDED
|
||||
found_selector++;
|
||||
};
|
||||
@@ -115,7 +114,7 @@ static void prepend_new_eth_table(ethtable_t **clist, char *ifname, char *select
|
||||
if (strlen(ifname) >= IF_NAMESIZE)
|
||||
bb_error_msg_and_die("interface name '%s' too long", ifname);
|
||||
ch = xzalloc(sizeof(*ch));
|
||||
ch->ifname = ifname;
|
||||
ch->ifname = xstrdup(ifname);
|
||||
nameif_parse_selector(ch, selector);
|
||||
ch->next = *clist;
|
||||
if (*clist)
|
||||
@@ -123,6 +122,21 @@ static void prepend_new_eth_table(ethtable_t **clist, char *ifname, char *select
|
||||
*clist = ch;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_CLEAN_UP
|
||||
static void delete_eth_table(ethtable_t *ch)
|
||||
{
|
||||
free(ch->ifname);
|
||||
#if ENABLE_FEATURE_NAMEIF_EXTENDED
|
||||
free(ch->bus_info);
|
||||
free(ch->driver);
|
||||
#endif
|
||||
free(ch->mac);
|
||||
free(ch);
|
||||
};
|
||||
#else
|
||||
void delete_eth_table(ethtable_t *ch);
|
||||
#endif
|
||||
|
||||
int nameif_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int nameif_main(int argc, char **argv)
|
||||
{
|
||||
@@ -156,14 +170,13 @@ int nameif_main(int argc, char **argv)
|
||||
char *next;
|
||||
|
||||
line_ptr = skip_whitespace(line);
|
||||
if ((line_ptr[0] == '#') || (line_ptr[0] == '\n')) {
|
||||
free(line);
|
||||
continue;
|
||||
}
|
||||
if ((line_ptr[0] == '#') || (line_ptr[0] == '\n'))
|
||||
goto read_next_line;
|
||||
next = skip_non_whitespace(line_ptr);
|
||||
if (*next)
|
||||
*next++ = '\0';
|
||||
prepend_new_eth_table(&clist, line_ptr, next);
|
||||
read_next_line:
|
||||
free(line);
|
||||
}
|
||||
fclose(ifh);
|
||||
@@ -187,7 +200,7 @@ int nameif_main(int argc, char **argv)
|
||||
|
||||
/* Find the current interface name and copy it to ifr.ifr_name */
|
||||
line_ptr = skip_whitespace(line);
|
||||
*skip_non_whitespace(line_ptr) = '\0';
|
||||
*strpbrk(line_ptr, " \t\n:") = '\0';
|
||||
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
strncpy(ifr.ifr_name, line_ptr, sizeof(ifr.ifr_name));
|
||||
@@ -230,16 +243,15 @@ int nameif_main(int argc, char **argv)
|
||||
else
|
||||
clist = ch->next;
|
||||
if (ch->next != NULL)
|
||||
ch->next->prev = ch->prev;
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
free(ch->ifname);
|
||||
free(ch->mac);
|
||||
free(ch);
|
||||
}
|
||||
ch->next->prev = ch->prev;
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
delete_eth_table(ch);
|
||||
next_line:
|
||||
free(line);
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
for (ch = clist; ch; ch = ch->next)
|
||||
delete_eth_table(ch);
|
||||
fclose(ifh);
|
||||
};
|
||||
|
||||
|
||||
+4
-3
@@ -29,10 +29,11 @@
|
||||
* - don't know how to retrieve ORIGDST for udp.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
#include <linux/netfilter_ipv4.h> /* wants <limits.h> */
|
||||
|
||||
#include "libbb.h"
|
||||
/* Wants <limits.h> etc, thus included after libbb.h: */
|
||||
#include <linux/types.h> /* for __be32 etc */
|
||||
#include <linux/netfilter_ipv4.h>
|
||||
|
||||
// TODO: move into this file:
|
||||
#include "tcpudp_perhost.h"
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
*/
|
||||
|
||||
#include <features.h>
|
||||
#include <asm/types.h>
|
||||
#if (defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION)
|
||||
#include <netpacket/packet.h>
|
||||
#include <net/ethernet.h>
|
||||
#else
|
||||
#include <asm/types.h>
|
||||
#include <linux/if_packet.h>
|
||||
#include <linux/if_ether.h>
|
||||
#endif
|
||||
@@ -76,7 +76,7 @@ int raw_socket(int ifindex)
|
||||
BPF_STMT(BPF_LD|BPF_W|BPF_IND, 0),
|
||||
BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, SERVER_AND_CLIENT_PORTS, 0, 1), /* L3, L4 */
|
||||
/* returns */
|
||||
BPF_STMT(BPF_RET|BPF_K, (~(uint32_t)0) ), /* L3: pass */
|
||||
BPF_STMT(BPF_RET|BPF_K, 0x0fffffff), /* L3: pass */
|
||||
BPF_STMT(BPF_RET|BPF_K, 0), /* L4: reject */
|
||||
};
|
||||
static const struct sock_fprog filter_prog = {
|
||||
|
||||
+8
-8
@@ -57,11 +57,11 @@ static int file_to_dev_inode(const char *filename, dev_t *dev, ino_t *inode)
|
||||
|
||||
static char *parse_net_arg(const char *arg, unsigned *port)
|
||||
{
|
||||
char path[12], tproto[5];
|
||||
char path[20], tproto[5];
|
||||
|
||||
if (sscanf(arg, "%u/%4s", port, tproto) != 2)
|
||||
return NULL;
|
||||
sprintf(path, "net/%s", tproto);
|
||||
sprintf(path, "/proc/net/%s", tproto);
|
||||
if (access(path, R_OK) != 0)
|
||||
return NULL;
|
||||
return xstrdup(tproto);
|
||||
@@ -99,7 +99,7 @@ static inode_list *add_inode(inode_list *ilist, dev_t dev, ino_t inode)
|
||||
static inode_list *scan_proc_net(const char *proto,
|
||||
unsigned port, inode_list *ilist)
|
||||
{
|
||||
char path[12], line[MAX_LINE + 1];
|
||||
char path[20], line[MAX_LINE + 1];
|
||||
char addr[128];
|
||||
ino_t tmp_inode;
|
||||
dev_t tmp_dev;
|
||||
@@ -109,7 +109,7 @@ static inode_list *scan_proc_net(const char *proto,
|
||||
|
||||
tmp_dev = find_socket_dev();
|
||||
|
||||
sprintf(path, "net/%s", proto);
|
||||
sprintf(path, "/proc/net/%s", proto);
|
||||
f = fopen(path, "r");
|
||||
if (!f)
|
||||
return ilist;
|
||||
@@ -208,6 +208,7 @@ static pid_list *scan_dir_links(const char *dname, pid_t pid,
|
||||
return plist;
|
||||
}
|
||||
|
||||
/* NB: does chdir internally */
|
||||
static pid_list *scan_proc_pids(inode_list *ilist)
|
||||
{
|
||||
DIR *d;
|
||||
@@ -215,7 +216,8 @@ static pid_list *scan_proc_pids(inode_list *ilist)
|
||||
pid_t pid;
|
||||
pid_list *plist;
|
||||
|
||||
d = opendir(".");
|
||||
xchdir("/proc");
|
||||
d = opendir("/proc");
|
||||
if (!d)
|
||||
return NULL;
|
||||
|
||||
@@ -314,8 +316,6 @@ Find processes which use FILEs or PORTs
|
||||
opt = getopt32(argv, OPTION_STRING);
|
||||
argv += optind;
|
||||
|
||||
xchdir("/proc");
|
||||
|
||||
ilist = NULL;
|
||||
pp = argv;
|
||||
while (*pp) {
|
||||
@@ -331,7 +331,7 @@ Find processes which use FILEs or PORTs
|
||||
pp++;
|
||||
}
|
||||
|
||||
plist = scan_proc_pids(ilist);
|
||||
plist = scan_proc_pids(ilist); /* changes dir to "/proc" */
|
||||
|
||||
if (!plist)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
+6
-1
@@ -861,17 +861,22 @@ int top_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
#else
|
||||
qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0]));
|
||||
#endif /* FEATURE_TOP_CPU_USAGE_PERCENTAGE */
|
||||
} else { /* TOPMEM */
|
||||
}
|
||||
#if ENABLE_FEATURE_TOPMEM
|
||||
else { /* TOPMEM */
|
||||
qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort);
|
||||
}
|
||||
#endif
|
||||
count = lines;
|
||||
if (OPT_BATCH_MODE || count > ntop) {
|
||||
count = ntop;
|
||||
}
|
||||
if (scan_mask == TOP_MASK)
|
||||
display_process_list(count, col);
|
||||
#if ENABLE_FEATURE_TOPMEM
|
||||
else
|
||||
display_topmem_process_list(count, col);
|
||||
#endif
|
||||
clearmems();
|
||||
if (iterations >= 0 && !--iterations)
|
||||
break;
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ check_libc_is_glibc() {
|
||||
#if defined(__GLIBC__) && !defined(__UCLIBC__)
|
||||
syntax error here
|
||||
#endif
|
||||
" >"$tempname"
|
||||
" >"$tempname".c
|
||||
if $CC "$tempname".c -c -o "$tempname".o >/dev/null 2>&1; then
|
||||
echo "$2";
|
||||
else
|
||||
|
||||
+13
-11
@@ -699,9 +699,18 @@ static const struct built_in_command bltins[] = {
|
||||
BLTIN(NULL, NULL, NULL)
|
||||
};
|
||||
|
||||
/* Signals are grouped, we handle them in batches */
|
||||
static void set_misc_sighandler(void (*handler)(int))
|
||||
{
|
||||
bb_signals(0
|
||||
+ (1 << SIGINT)
|
||||
+ (1 << SIGQUIT)
|
||||
+ (1 << SIGTERM)
|
||||
, handler);
|
||||
}
|
||||
|
||||
#if ENABLE_HUSH_JOB
|
||||
|
||||
/* Signals are grouped, we handle them in batches */
|
||||
static void set_fatal_sighandler(void (*handler)(int))
|
||||
{
|
||||
bb_signals(0
|
||||
@@ -725,14 +734,6 @@ static void set_jobctrl_sighandler(void (*handler)(int))
|
||||
+ (1 << SIGTTOU)
|
||||
, handler);
|
||||
}
|
||||
static void set_misc_sighandler(void (*handler)(int))
|
||||
{
|
||||
bb_signals(0
|
||||
+ (1 << SIGINT)
|
||||
+ (1 << SIGQUIT)
|
||||
+ (1 << SIGTERM)
|
||||
, handler);
|
||||
}
|
||||
/* SIGCHLD is special and handled separately */
|
||||
|
||||
static void set_every_sighandler(void (*handler)(int))
|
||||
@@ -815,7 +816,6 @@ static void hush_exit(int exitcode)
|
||||
|
||||
#define set_fatal_sighandler(handler) ((void)0)
|
||||
#define set_jobctrl_sighandler(handler) ((void)0)
|
||||
#define set_misc_sighandler(handler) ((void)0)
|
||||
#define hush_exit(e) exit(e)
|
||||
|
||||
#endif /* JOB */
|
||||
@@ -3907,8 +3907,10 @@ int hush_main(int argc, char **argv)
|
||||
/* give up */
|
||||
interactive_fd = 0;
|
||||
}
|
||||
if (interactive_fd)
|
||||
if (interactive_fd) {
|
||||
fcntl(interactive_fd, F_SETFD, FD_CLOEXEC);
|
||||
set_misc_sighandler(SIG_IGN);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+46
-40
@@ -92,17 +92,17 @@ static char *itoa(int n)
|
||||
#ifdef MSHDEBUG
|
||||
static int mshdbg = MSHDEBUG;
|
||||
|
||||
#define DBGPRINTF(x) if (mshdbg>0) printf x
|
||||
#define DBGPRINTF0(x) if (mshdbg>0) printf x
|
||||
#define DBGPRINTF1(x) if (mshdbg>1) printf x
|
||||
#define DBGPRINTF2(x) if (mshdbg>2) printf x
|
||||
#define DBGPRINTF3(x) if (mshdbg>3) printf x
|
||||
#define DBGPRINTF4(x) if (mshdbg>4) printf x
|
||||
#define DBGPRINTF5(x) if (mshdbg>5) printf x
|
||||
#define DBGPRINTF6(x) if (mshdbg>6) printf x
|
||||
#define DBGPRINTF7(x) if (mshdbg>7) printf x
|
||||
#define DBGPRINTF8(x) if (mshdbg>8) printf x
|
||||
#define DBGPRINTF9(x) if (mshdbg>9) printf x
|
||||
#define DBGPRINTF(x) if (mshdbg > 0) printf x
|
||||
#define DBGPRINTF0(x) if (mshdbg > 0) printf x
|
||||
#define DBGPRINTF1(x) if (mshdbg > 1) printf x
|
||||
#define DBGPRINTF2(x) if (mshdbg > 2) printf x
|
||||
#define DBGPRINTF3(x) if (mshdbg > 3) printf x
|
||||
#define DBGPRINTF4(x) if (mshdbg > 4) printf x
|
||||
#define DBGPRINTF5(x) if (mshdbg > 5) printf x
|
||||
#define DBGPRINTF6(x) if (mshdbg > 6) printf x
|
||||
#define DBGPRINTF7(x) if (mshdbg > 7) printf x
|
||||
#define DBGPRINTF8(x) if (mshdbg > 8) printf x
|
||||
#define DBGPRINTF9(x) if (mshdbg > 9) printf x
|
||||
|
||||
static int mshdbg_rc = 0;
|
||||
|
||||
@@ -124,7 +124,7 @@ static int mshdbg_rc = 0;
|
||||
|
||||
#define RCPRINTF(x) ((void)0)
|
||||
|
||||
#endif /* MSHDEBUG */
|
||||
#endif /* MSHDEBUG */
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_EDITING_FANCY_PROMPT
|
||||
@@ -141,13 +141,13 @@ static int mshdbg_rc = 0;
|
||||
* shell
|
||||
*/
|
||||
|
||||
#define LINELIM 2100
|
||||
#define NPUSH 8 /* limit to input nesting */
|
||||
#define LINELIM 2100
|
||||
#define NPUSH 8 /* limit to input nesting */
|
||||
|
||||
#undef NOFILE
|
||||
#define NOFILE 20 /* Number of open files */
|
||||
#define NUFILE 10 /* Number of user-accessible files */
|
||||
#define FDBASE 10 /* First file usable by Shell */
|
||||
#define NOFILE 20 /* Number of open files */
|
||||
#define NUFILE 10 /* Number of user-accessible files */
|
||||
#define FDBASE 10 /* First file usable by Shell */
|
||||
|
||||
/*
|
||||
* values returned by wait
|
||||
@@ -159,7 +159,7 @@ static int mshdbg_rc = 0;
|
||||
/*
|
||||
* library and system definitions
|
||||
*/
|
||||
typedef void xint; /* base type of jmp_buf, for not broken compilers */
|
||||
typedef void xint; /* base type of jmp_buf, for not broken compilers */
|
||||
|
||||
/*
|
||||
* shell components
|
||||
@@ -588,14 +588,13 @@ static const struct builtincmd builtincmds[] = {
|
||||
{ NULL , NULL },
|
||||
};
|
||||
|
||||
static struct op *scantree(struct op *);
|
||||
static struct op *dowholefile(int /*, int*/);
|
||||
|
||||
|
||||
/* Globals */
|
||||
static char **dolv;
|
||||
static int dolc;
|
||||
static int exstat;
|
||||
static uint8_t exstat;
|
||||
static smallint gflg; /* (seems to be a parse error indicator) */
|
||||
static smallint interactive; /* Is this an interactive shell */
|
||||
static smallint execflg;
|
||||
@@ -726,7 +725,7 @@ static void print_tree(struct op *head)
|
||||
return;
|
||||
}
|
||||
|
||||
DBGPRINTF(("NODE: %p, left %p, right %p\n", head, head->left,
|
||||
DBGPRINTF(("NODE: %p, left %p, right %p\n", head, head->left,
|
||||
head->right));
|
||||
|
||||
if (head->left)
|
||||
@@ -744,7 +743,7 @@ static void print_tree(struct op *head)
|
||||
static void prs(const char *s)
|
||||
{
|
||||
if (*s)
|
||||
write(2, s, strlen(s));
|
||||
write(STDERR_FILENO, s, strlen(s));
|
||||
}
|
||||
|
||||
static void prn(unsigned u)
|
||||
@@ -807,7 +806,8 @@ static void warn(const char *s)
|
||||
{
|
||||
if (*s) {
|
||||
prs(s);
|
||||
exstat = -1;
|
||||
if (!exstat)
|
||||
exstat = 255;
|
||||
}
|
||||
prs("\n");
|
||||
if (FLAG['e'])
|
||||
@@ -1278,6 +1278,7 @@ static int newfile(char *s)
|
||||
}
|
||||
|
||||
|
||||
#ifdef UNUSED
|
||||
struct op *scantree(struct op *head)
|
||||
{
|
||||
struct op *dotnode;
|
||||
@@ -1309,6 +1310,7 @@ struct op *scantree(struct op *head)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void onecommand(void)
|
||||
@@ -2740,7 +2742,7 @@ static int forkexec(struct op *t, int *pin, int *pout, int no_fork, char **wp)
|
||||
// longjmps away (at "Run builtin" below), leaving t->op_words clobbered!
|
||||
// See http://bugs.busybox.net/view.php?id=846.
|
||||
// Now we do not touch t->op_words, but separately pass wp as param list
|
||||
// to builtins
|
||||
// to builtins
|
||||
DBGPRINTF(("FORKEXEC: bltin %p, no_fork %d, owp %p\n", bltin,
|
||||
no_fork, owp));
|
||||
/* Don't fork if it is a lone builtin (not in pipe)
|
||||
@@ -2854,7 +2856,7 @@ static int forkexec(struct op *t, int *pin, int *pout, int no_fork, char **wp)
|
||||
if (t->op_type == TPAREN)
|
||||
_exit(execute(t->left, NOPIPE, NOPIPE, /* no_fork: */ 1));
|
||||
if (wp[0] == NULL)
|
||||
_exit(0);
|
||||
_exit(EXIT_SUCCESS);
|
||||
|
||||
cp = rexecve(wp[0], wp, makenv(0, NULL));
|
||||
prs(wp[0]);
|
||||
@@ -3006,7 +3008,7 @@ static int waitfor(int lastpid, int canintr)
|
||||
prs(" - core dumped");
|
||||
if (rv >= ARRAY_SIZE(signame) || signame[rv])
|
||||
prs("\n");
|
||||
rv = -1;
|
||||
rv |= 0x80;
|
||||
} else
|
||||
rv = WAITVAL(s);
|
||||
}
|
||||
@@ -3070,8 +3072,6 @@ static const char *rexecve(char *c, char **v, char **envp)
|
||||
if (tp != global_env.linep)
|
||||
*tp++ = '/';
|
||||
strcpy(tp, c);
|
||||
//for (i = 0; (*tp++ = c[i++]) != '\0';)
|
||||
// continue;
|
||||
|
||||
DBGPRINTF3(("REXECVE: global_env.linep is %s\n", global_env.linep));
|
||||
|
||||
@@ -3079,10 +3079,13 @@ static const char *rexecve(char *c, char **v, char **envp)
|
||||
|
||||
switch (errno) {
|
||||
case ENOEXEC:
|
||||
/* File is executable but file format isnt recognized */
|
||||
/* Run it as a shell script */
|
||||
/* (execve above didnt do it itself, unlike execvp) */
|
||||
*v = global_env.linep;
|
||||
v--;
|
||||
tp = *v;
|
||||
*v = global_env.linep;
|
||||
*v = (char*)DEFAULT_SHELL;
|
||||
execve(DEFAULT_SHELL, v, envp);
|
||||
*v = tp;
|
||||
return "no shell";
|
||||
@@ -3094,7 +3097,12 @@ static const char *rexecve(char *c, char **v, char **envp)
|
||||
return "argument list too long";
|
||||
}
|
||||
}
|
||||
return errno == ENOENT ? "not found" : "cannot execute";
|
||||
if (errno == ENOENT) {
|
||||
exstat = 127; /* standards require this */
|
||||
return "not found";
|
||||
}
|
||||
exstat = 126; /* mimic bash */
|
||||
return "cannot execute";
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3383,7 +3391,7 @@ static int doread(struct op *t ATTRIBUTE_UNUSED, char **args)
|
||||
}
|
||||
for (wp = args + 1; *wp; wp++) {
|
||||
for (cp = global_env.linep; !nl && cp < elinep - 1; cp++) {
|
||||
nb = nonblock_safe_read(0, cp, sizeof(*cp));
|
||||
nb = nonblock_safe_read(STDIN_FILENO, cp, sizeof(*cp));
|
||||
if (nb != sizeof(*cp))
|
||||
break;
|
||||
nl = (*cp == '\n');
|
||||
@@ -4206,7 +4214,7 @@ static int grave(int quoted)
|
||||
prs(argument_list[0]);
|
||||
prs(": ");
|
||||
err(cp);
|
||||
_exit(1);
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
@@ -4308,9 +4316,7 @@ static void globname(char *we, char *pp)
|
||||
dname[NAME_MAX] = '\0';
|
||||
while ((de = readdir(dirp)) != NULL) {
|
||||
/* XXX Hmmm... What this could be? (abial) */
|
||||
/*
|
||||
if (ent[j].d_ino == 0)
|
||||
continue;
|
||||
/* if (ent[j].d_ino == 0) continue;
|
||||
*/
|
||||
strncpy(dname, de->d_name, NAME_MAX);
|
||||
if (dname[0] == '.')
|
||||
@@ -4521,7 +4527,7 @@ static int readc(void)
|
||||
static void ioecho(char c)
|
||||
{
|
||||
if (FLAG['v'])
|
||||
write(2, &c, sizeof c);
|
||||
write(STDERR_FILENO, &c, sizeof c);
|
||||
}
|
||||
|
||||
static void pushio(struct ioarg *argp, int (*fn) (struct ioarg *))
|
||||
@@ -4732,7 +4738,7 @@ static int filechar(struct ioarg *ap)
|
||||
while (size == 0 || position >= size) {
|
||||
size = read_line_input(current_prompt, filechar_cmdbuf, BUFSIZ, line_input_state);
|
||||
if (size < 0) /* Error/EOF */
|
||||
exit(0);
|
||||
exit(EXIT_SUCCESS);
|
||||
position = 0;
|
||||
/* if Ctrl-C, size == 0 and loop will repeat */
|
||||
}
|
||||
@@ -4817,7 +4823,7 @@ static int linechar(struct ioarg *ap)
|
||||
}
|
||||
|
||||
/*
|
||||
* remap fd into Shell's fd space
|
||||
* Remap fd into shell's fd space
|
||||
*/
|
||||
static int remap(int fd)
|
||||
{
|
||||
@@ -5203,7 +5209,7 @@ int msh_main(int argc, char **argv)
|
||||
|
||||
/* Shell is non-interactive, activate printf-based debug */
|
||||
#ifdef MSHDEBUG
|
||||
mshdbg = (int) (((char) (mshdbg_var->value[0])) - '0');
|
||||
mshdbg = mshdbg_var->value[0] - '0';
|
||||
if (mshdbg < 0)
|
||||
mshdbg = 0;
|
||||
#endif
|
||||
@@ -5211,7 +5217,7 @@ int msh_main(int argc, char **argv)
|
||||
|
||||
name = *++argv;
|
||||
if (newfile(name))
|
||||
exit(1); /* Exit on error */
|
||||
exit(EXIT_FAILURE); /* Exit on error */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -347,10 +347,11 @@ static void log_locally(time_t now, char *msg)
|
||||
sprintf(newFile, "%s.%d", G.logFilePath, i);
|
||||
if (i == 0) break;
|
||||
sprintf(oldFile, "%s.%d", G.logFilePath, --i);
|
||||
xrename(oldFile, newFile);
|
||||
/* ignore errors - file might be missing */
|
||||
rename(oldFile, newFile);
|
||||
}
|
||||
/* newFile == "f.0" now */
|
||||
xrename(G.logFilePath, newFile);
|
||||
rename(G.logFilePath, newFile);
|
||||
fl.l_type = F_UNLCK;
|
||||
fcntl(G.logFD, F_SETLKW, &fl);
|
||||
close(G.logFD);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[ -n "$d" ] || d=..
|
||||
tail -n 2 "$d/README" > logfile.gnu
|
||||
busybox tail -n 2 "$d/README" > logfile.bb
|
||||
cmp logfile.gnu logfile.bb
|
||||
echo -ne "abc\ndef\n123\n" >input
|
||||
echo -ne "def\n123\n" >logfile.ok
|
||||
busybox tail -n 2 input > logfile.bb
|
||||
cmp logfile.ok logfile.bb
|
||||
@@ -1,4 +1,4 @@
|
||||
[ -n "$d" ] || d=..
|
||||
tail -n 2 "$d/README" > logfile.gnu
|
||||
busybox tail -n 2 "$d/README" > logfile.bb
|
||||
cmp logfile.gnu logfile.bb
|
||||
echo -ne "abc\ndef\n123\n" >input
|
||||
echo -ne "def\n123\n" >logfile.ok
|
||||
busybox tail -2 input > logfile.bb
|
||||
cmp logfile.ok logfile.bb
|
||||
@@ -7,8 +7,8 @@
|
||||
a="taskset"
|
||||
|
||||
# testing "test name" "opts" "expected result" "file inp" "stdin"
|
||||
testing "taskset (get from pid 1)" "$a -p1 >/dev/null;echo \$?" "0\n" "" ""
|
||||
testing "taskset (invalid pid)" "$a -p0 >/dev/null 2>&1;echo \$?" "1\n" "" ""
|
||||
testing "taskset (get from pid 1)" "$a -p 1 >/dev/null;echo \$?" "0\n" "" ""
|
||||
testing "taskset (invalid pid)" "$a -p 0 >/dev/null 2>&1;echo \$?" "1\n" "" ""
|
||||
testing "taskset (set_aff, needs CAP_SYS_NICE)" \
|
||||
"$a 0x1 $SHELL -c $a\ -p\ \$$\|grep\ \"current\ affinity\ mask:\ 1\" >/dev/null;echo \$?" \
|
||||
"0\n" "" ""
|
||||
|
||||
+199
-156
@@ -12,6 +12,8 @@
|
||||
#include "libbb.h"
|
||||
#include "xregex.h"
|
||||
|
||||
#define ENABLE_FEATURE_MDEV_RENAME_REGEXP 1
|
||||
|
||||
struct globals {
|
||||
int root_major, root_minor;
|
||||
};
|
||||
@@ -21,7 +23,21 @@ struct globals {
|
||||
|
||||
#define MAX_SYSFS_DEPTH 3 /* prevent infinite loops in /sys symlinks */
|
||||
|
||||
/* We use additional 64+ bytes in make_device() */
|
||||
#define SCRATCH_SIZE 80
|
||||
|
||||
static char *next_field(char *s)
|
||||
{
|
||||
char *end = skip_non_whitespace(s);
|
||||
s = skip_whitespace(end);
|
||||
*end = '\0';
|
||||
if (*s == '\0')
|
||||
s = NULL;
|
||||
return s;
|
||||
}
|
||||
|
||||
/* mknod in /dev based on a path like "/sys/block/hda/hda1" */
|
||||
/* NB: "mdev -s" may call us many times, do not leak memory/fds! */
|
||||
static void make_device(char *path, int delete)
|
||||
{
|
||||
const char *device_name;
|
||||
@@ -29,7 +45,7 @@ static void make_device(char *path, int delete)
|
||||
int mode = 0660;
|
||||
uid_t uid = 0;
|
||||
gid_t gid = 0;
|
||||
char *temp = path + strlen(path);
|
||||
char *dev_maj_min = path + strlen(path);
|
||||
char *command = NULL;
|
||||
char *alias = NULL;
|
||||
|
||||
@@ -42,156 +58,185 @@ static void make_device(char *path, int delete)
|
||||
* also depend on path having writeable space after it.
|
||||
*/
|
||||
if (!delete) {
|
||||
strcat(path, "/dev");
|
||||
len = open_read_close(path, temp + 1, 64);
|
||||
*temp++ = 0;
|
||||
strcpy(dev_maj_min, "/dev");
|
||||
len = open_read_close(path, dev_maj_min + 1, 64);
|
||||
*dev_maj_min++ = '\0';
|
||||
if (len < 1) {
|
||||
if (ENABLE_FEATURE_MDEV_EXEC)
|
||||
/* no "dev" file, so just try to run script */
|
||||
*temp = 0;
|
||||
else
|
||||
if (!ENABLE_FEATURE_MDEV_EXEC)
|
||||
return;
|
||||
/* no "dev" file, so just try to run script */
|
||||
*dev_maj_min = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine device name, type, major and minor */
|
||||
device_name = bb_basename(path);
|
||||
type = (path[5] == 'c' ? S_IFCHR : S_IFBLK);
|
||||
/* http://kernel.org/doc/pending/hotplug.txt says that only
|
||||
* "/sys/block/..." is for block devices. "/sys/bus" etc is not!
|
||||
* Since kernel 2.6.25 block devices are also in /sys/class/block. */
|
||||
/* TODO: would it be acceptable to just use strstr(path, "/block/")? */
|
||||
if (strncmp(&path[5], "class/block/"+6, 6) != 0
|
||||
&& strncmp(&path[5], "class/block/", 12) != 0)
|
||||
type = S_IFCHR;
|
||||
else
|
||||
type = S_IFBLK;
|
||||
|
||||
if (ENABLE_FEATURE_MDEV_CONF) {
|
||||
FILE *fp;
|
||||
char *line, *vline;
|
||||
char *line, *val, *next;
|
||||
unsigned lineno = 0;
|
||||
|
||||
/* If we have a config file, look up the user settings */
|
||||
/* If we have config file, look up user settings */
|
||||
fp = fopen_or_warn("/etc/mdev.conf", "r");
|
||||
if (!fp)
|
||||
goto end_parse;
|
||||
|
||||
while ((vline = line = xmalloc_getline(fp)) != NULL) {
|
||||
int field;
|
||||
|
||||
/* A pristine copy for command execution. */
|
||||
char *orig_line;
|
||||
if (ENABLE_FEATURE_MDEV_EXEC)
|
||||
orig_line = xstrdup(line);
|
||||
while ((line = xmalloc_getline(fp)) != NULL) {
|
||||
regmatch_t off[1+9*ENABLE_FEATURE_MDEV_RENAME_REGEXP];
|
||||
|
||||
++lineno;
|
||||
trim(line);
|
||||
if (!line[0])
|
||||
goto next_line;
|
||||
|
||||
/* Three fields: regex, uid:gid, mode */
|
||||
for (field = 0; field < (3 + ENABLE_FEATURE_MDEV_RENAME + ENABLE_FEATURE_MDEV_EXEC); ++field) {
|
||||
/* Fields: regex uid:gid mode [alias] [cmd] */
|
||||
|
||||
/* Find a non-empty field */
|
||||
char *val;
|
||||
do {
|
||||
val = strtok(vline, " \t");
|
||||
vline = NULL;
|
||||
} while (val && !*val);
|
||||
if (!val) {
|
||||
if (field)
|
||||
break;
|
||||
else
|
||||
goto next_line;
|
||||
}
|
||||
/* 1st field: regex to match this device */
|
||||
next = next_field(line);
|
||||
{
|
||||
regex_t match;
|
||||
int result;
|
||||
|
||||
if (field == 0) {
|
||||
/* Is this it? */
|
||||
xregcomp(&match, line, REG_EXTENDED);
|
||||
result = regexec(&match, device_name, ARRAY_SIZE(off), off, 0);
|
||||
regfree(&match);
|
||||
|
||||
/* Regex to match this device */
|
||||
regex_t match;
|
||||
regmatch_t off;
|
||||
int result;
|
||||
//bb_error_msg("matches:");
|
||||
//for (int i = 0; i < ARRAY_SIZE(off); i++) {
|
||||
// if (off[i].rm_so < 0) continue;
|
||||
// bb_error_msg("match %d: '%.*s'\n", i,
|
||||
// (int)(off[i].rm_eo - off[i].rm_so),
|
||||
// device_name + off[i].rm_so);
|
||||
//}
|
||||
|
||||
/* Is this it? */
|
||||
xregcomp(&match, val, REG_EXTENDED);
|
||||
result = regexec(&match, device_name, 1, &off, 0);
|
||||
regfree(&match);
|
||||
/* If not this device, skip rest of line */
|
||||
/* (regexec returns whole pattern as "range" 0) */
|
||||
if (result || off[0].rm_so || off[0].rm_eo != strlen(device_name))
|
||||
goto next_line;
|
||||
}
|
||||
|
||||
/* If not this device, skip rest of line */
|
||||
if (result || off.rm_so || off.rm_eo != strlen(device_name))
|
||||
goto next_line;
|
||||
/* This line matches: stop parsing the file
|
||||
* after parsing the rest of fields */
|
||||
|
||||
} else if (field == 1) {
|
||||
/* 2nd field: uid:gid - device ownership */
|
||||
if (!next) /* field must exist */
|
||||
bb_error_msg_and_die("bad line %u", lineno);
|
||||
val = next;
|
||||
next = next_field(val);
|
||||
{
|
||||
struct passwd *pass;
|
||||
struct group *grp;
|
||||
char *str_uid = val;
|
||||
char *str_gid = strchrnul(val, ':');
|
||||
|
||||
/* uid:gid device ownership */
|
||||
struct passwd *pass;
|
||||
struct group *grp;
|
||||
if (*str_gid)
|
||||
*str_gid++ = '\0';
|
||||
/* Parse UID */
|
||||
pass = getpwnam(str_uid);
|
||||
if (pass)
|
||||
uid = pass->pw_uid;
|
||||
else
|
||||
uid = strtoul(str_uid, NULL, 10);
|
||||
/* Parse GID */
|
||||
grp = getgrnam(str_gid);
|
||||
if (grp)
|
||||
gid = grp->gr_gid;
|
||||
else
|
||||
gid = strtoul(str_gid, NULL, 10);
|
||||
}
|
||||
|
||||
char *str_uid = val;
|
||||
char *str_gid = strchr(val, ':');
|
||||
if (str_gid)
|
||||
*str_gid = '\0', ++str_gid;
|
||||
/* 3rd field: mode - device permissions */
|
||||
if (!next) /* field must exist */
|
||||
bb_error_msg_and_die("bad line %u", lineno);
|
||||
val = next;
|
||||
next = next_field(val);
|
||||
mode = strtoul(val, NULL, 8);
|
||||
|
||||
/* Parse UID */
|
||||
pass = getpwnam(str_uid);
|
||||
if (pass)
|
||||
uid = pass->pw_uid;
|
||||
else
|
||||
uid = strtoul(str_uid, NULL, 10);
|
||||
/* 4th field (opt): >alias */
|
||||
if (ENABLE_FEATURE_MDEV_RENAME) {
|
||||
if (!next)
|
||||
break;
|
||||
if (*next == '>') {
|
||||
#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
|
||||
char *s, *p;
|
||||
unsigned i, n;
|
||||
#endif
|
||||
val = next;
|
||||
next = next_field(val);
|
||||
#if ENABLE_FEATURE_MDEV_RENAME_REGEXP
|
||||
/* substitute %1..9 with off[1..9], if any */
|
||||
n = 0;
|
||||
s = val;
|
||||
while (*s)
|
||||
if (*s++ == '%')
|
||||
n++;
|
||||
|
||||
/* parse GID */
|
||||
grp = getgrnam(str_gid);
|
||||
if (grp)
|
||||
gid = grp->gr_gid;
|
||||
else
|
||||
gid = strtoul(str_gid, NULL, 10);
|
||||
|
||||
} else if (field == 2) {
|
||||
|
||||
/* Mode device permissions */
|
||||
mode = strtoul(val, NULL, 8);
|
||||
|
||||
} else if (ENABLE_FEATURE_MDEV_RENAME && field == 3) {
|
||||
|
||||
if (*val != '>')
|
||||
++field;
|
||||
else
|
||||
alias = xstrdup(val + 1);
|
||||
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_MDEV_EXEC && field == 3 + ENABLE_FEATURE_MDEV_RENAME) {
|
||||
|
||||
/* Optional command to run */
|
||||
const char *s = "@$*";
|
||||
const char *s2 = strchr(s, *val);
|
||||
|
||||
if (!s2) {
|
||||
/* Force error */
|
||||
field = 1;
|
||||
break;
|
||||
p = alias = xzalloc(strlen(val) + n * strlen(device_name));
|
||||
s = val + 1;
|
||||
while (*s) {
|
||||
*p = *s;
|
||||
if ('%' == *s) {
|
||||
i = (s[1] - '0');
|
||||
if (i <= 9 && off[i].rm_so >= 0) {
|
||||
n = off[i].rm_eo - off[i].rm_so;
|
||||
strncpy(p, device_name + off[i].rm_so, n);
|
||||
p += n - 1;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
s++;
|
||||
}
|
||||
|
||||
/* Correlate the position in the "@$*" with the delete
|
||||
* step so that we get the proper behavior.
|
||||
*/
|
||||
if ((s2 - s + 1) & (1 << delete))
|
||||
command = xstrdup(orig_line + (val + 1 - line));
|
||||
#else
|
||||
alias = xstrdup(val + 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Did everything parse happily? */
|
||||
if (field <= 2)
|
||||
bb_error_msg_and_die("bad line %u", lineno);
|
||||
/* The rest (opt): command to run */
|
||||
if (!next)
|
||||
break;
|
||||
val = next;
|
||||
if (ENABLE_FEATURE_MDEV_EXEC) {
|
||||
const char *s = "@$*";
|
||||
const char *s2 = strchr(s, *val);
|
||||
|
||||
if (!s2)
|
||||
bb_error_msg_and_die("bad line %u", lineno);
|
||||
|
||||
/* Correlate the position in the "@$*" with the delete
|
||||
* step so that we get the proper behavior:
|
||||
* @cmd: run on create
|
||||
* $cmd: run on delete
|
||||
* *cmd: run on both
|
||||
*/
|
||||
if ((s2 - s + 1) /*1/2/3*/ & /*1/2*/ (1 + delete)) {
|
||||
command = xstrdup(val + 1);
|
||||
}
|
||||
}
|
||||
/* end of field parsing */
|
||||
break; /* we found matching line, stop */
|
||||
next_line:
|
||||
free(line);
|
||||
if (ENABLE_FEATURE_MDEV_EXEC)
|
||||
free(orig_line);
|
||||
}
|
||||
} /* end of "while line is read from /etc/mdev.conf" */
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
fclose(fp);
|
||||
|
||||
end_parse: /* nothing */ ;
|
||||
free(line); /* in case we used "break" to get here */
|
||||
fclose(fp);
|
||||
}
|
||||
end_parse:
|
||||
|
||||
if (!delete) {
|
||||
if (sscanf(temp, "%d:%d", &major, &minor) != 2) {
|
||||
if (ENABLE_FEATURE_MDEV_EXEC)
|
||||
goto skip_creation;
|
||||
else
|
||||
return;
|
||||
}
|
||||
if (!delete && sscanf(dev_maj_min, "%u:%u", &major, &minor) == 2) {
|
||||
|
||||
if (ENABLE_FEATURE_MDEV_RENAME)
|
||||
unlink(device_name);
|
||||
@@ -208,39 +253,44 @@ static void make_device(char *path, int delete)
|
||||
if (ENABLE_FEATURE_MDEV_RENAME && alias) {
|
||||
char *dest;
|
||||
|
||||
temp = strrchr(alias, '/');
|
||||
if (temp) {
|
||||
if (temp[1] != '\0')
|
||||
/* given a file name, so rename it */
|
||||
*temp = '\0';
|
||||
/* ">bar/": rename to bar/device_name */
|
||||
/* ">bar[/]baz": rename to bar[/]baz */
|
||||
dest = strrchr(alias, '/');
|
||||
if (dest) { /* ">bar/[baz]" ? */
|
||||
*dest = '\0'; /* mkdir bar */
|
||||
bb_make_directory(alias, 0755, FILEUTILS_RECUR);
|
||||
dest = concat_path_file(alias, device_name);
|
||||
} else
|
||||
dest = alias;
|
||||
*dest = '/';
|
||||
if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */
|
||||
dest = alias;
|
||||
alias = concat_path_file(alias, device_name);
|
||||
free(dest);
|
||||
}
|
||||
}
|
||||
|
||||
rename(device_name, dest); // TODO: xrename?
|
||||
symlink(dest, device_name);
|
||||
/* recreate device_name as a symlink to moved device node */
|
||||
if (rename(device_name, alias) == 0) {
|
||||
symlink(alias, device_name);
|
||||
}
|
||||
|
||||
if (alias != dest)
|
||||
free(alias);
|
||||
free(dest);
|
||||
free(alias);
|
||||
}
|
||||
}
|
||||
skip_creation: /* nothing */ ;
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_MDEV_EXEC && command) {
|
||||
/* setenv will leak memory, so use putenv */
|
||||
/* setenv will leak memory, use putenv/unsetenv/free */
|
||||
char *s = xasprintf("MDEV=%s", device_name);
|
||||
putenv(s);
|
||||
if (system(command) == -1)
|
||||
bb_perror_msg_and_die("cannot run %s", command);
|
||||
bb_perror_msg_and_die("can't run '%s'", command);
|
||||
s[4] = '\0';
|
||||
unsetenv(s);
|
||||
free(s);
|
||||
free(command);
|
||||
}
|
||||
|
||||
if (delete)
|
||||
remove_file(device_name, FILEUTILS_FORCE);
|
||||
unlink(device_name);
|
||||
}
|
||||
|
||||
/* File callback for /sys/ traversal */
|
||||
@@ -249,14 +299,15 @@ static int fileAction(const char *fileName,
|
||||
void *userData,
|
||||
int depth ATTRIBUTE_UNUSED)
|
||||
{
|
||||
size_t len = strlen(fileName) - 4;
|
||||
size_t len = strlen(fileName) - 4; /* can't underflow */
|
||||
char *scratch = userData;
|
||||
|
||||
if (strcmp(fileName + len, "/dev"))
|
||||
/* len check is for paranoid reasons */
|
||||
if (strcmp(fileName + len, "/dev") || len >= PATH_MAX)
|
||||
return FALSE;
|
||||
|
||||
strcpy(scratch, fileName);
|
||||
scratch[len] = 0;
|
||||
scratch[len] = '\0';
|
||||
make_device(scratch, 0);
|
||||
|
||||
return TRUE;
|
||||
@@ -287,12 +338,6 @@ static void load_firmware(const char *const firmware, const char *const sysfs_pa
|
||||
int cnt;
|
||||
int firmware_fd, loading_fd, data_fd;
|
||||
|
||||
/* check for $FIRMWARE from kernel */
|
||||
/* XXX: dont bother: open(NULL) works same as open("no-such-file")
|
||||
* if (!firmware)
|
||||
* return;
|
||||
*/
|
||||
|
||||
/* check for /lib/firmware/$FIRMWARE */
|
||||
xchdir("/lib/firmware");
|
||||
firmware_fd = xopen(firmware, O_RDONLY);
|
||||
@@ -304,16 +349,15 @@ static void load_firmware(const char *const firmware, const char *const sysfs_pa
|
||||
xchdir(sysfs_path);
|
||||
for (cnt = 0; cnt < 30; ++cnt) {
|
||||
loading_fd = open("loading", O_WRONLY);
|
||||
if (loading_fd == -1)
|
||||
sleep(1);
|
||||
else
|
||||
break;
|
||||
if (loading_fd != -1)
|
||||
goto loading;
|
||||
sleep(1);
|
||||
}
|
||||
if (loading_fd == -1)
|
||||
goto out;
|
||||
goto out;
|
||||
|
||||
loading:
|
||||
/* tell kernel we're loading by `echo 1 > /sys/$DEVPATH/loading` */
|
||||
if (write(loading_fd, "1", 1) != 1)
|
||||
if (full_write(loading_fd, "1", 1) != 1)
|
||||
goto out;
|
||||
|
||||
/* load firmware by `cat /lib/firmware/$FIRMWARE > /sys/$DEVPATH/data */
|
||||
@@ -324,9 +368,9 @@ static void load_firmware(const char *const firmware, const char *const sysfs_pa
|
||||
|
||||
/* tell kernel result by `echo [0|-1] > /sys/$DEVPATH/loading` */
|
||||
if (cnt > 0)
|
||||
write(loading_fd, "0", 1);
|
||||
full_write(loading_fd, "0", 1);
|
||||
else
|
||||
write(loading_fd, "-1", 2);
|
||||
full_write(loading_fd, "-1", 2);
|
||||
|
||||
out:
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
@@ -341,16 +385,14 @@ int mdev_main(int argc, char **argv)
|
||||
{
|
||||
char *action;
|
||||
char *env_path;
|
||||
RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
|
||||
RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE);
|
||||
|
||||
xchdir("/dev");
|
||||
|
||||
if (argc == 2 && !strcmp(argv[1],"-s")) {
|
||||
|
||||
if (argc == 2 && !strcmp(argv[1], "-s")) {
|
||||
/* Scan:
|
||||
* mdev -s
|
||||
*/
|
||||
|
||||
struct stat st;
|
||||
|
||||
xstat("/", &st);
|
||||
@@ -366,26 +408,27 @@ int mdev_main(int argc, char **argv)
|
||||
fileAction, dirAction, temp, 0);
|
||||
|
||||
} else {
|
||||
|
||||
/* Hotplug:
|
||||
* env ACTION=... DEVPATH=... mdev
|
||||
* ACTION can be "add" or "remove"
|
||||
* DEVPATH is like "/block/sda" or "/class/input/mice"
|
||||
*/
|
||||
|
||||
action = getenv("ACTION");
|
||||
env_path = getenv("DEVPATH");
|
||||
if (!action || !env_path)
|
||||
bb_show_usage();
|
||||
|
||||
sprintf(temp, "/sys%s", env_path);
|
||||
snprintf(temp, PATH_MAX, "/sys%s", env_path);
|
||||
if (!strcmp(action, "remove"))
|
||||
make_device(temp, 1);
|
||||
else if (!strcmp(action, "add")) {
|
||||
make_device(temp, 0);
|
||||
|
||||
if (ENABLE_FEATURE_MDEV_LOAD_FIRMWARE)
|
||||
load_firmware(getenv("FIRMWARE"), temp);
|
||||
if (ENABLE_FEATURE_MDEV_LOAD_FIRMWARE) {
|
||||
char *fw = getenv("FIRMWARE");
|
||||
if (fw)
|
||||
load_firmware(fw, temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+44
-38
@@ -1059,6 +1059,7 @@ static int nfsmount(struct mntent *mp, long vfsflags, char *filteropts)
|
||||
if (filteropts) for (opt = strtok(filteropts, ","); opt; opt = strtok(NULL, ",")) {
|
||||
char *opteq = strchr(opt, '=');
|
||||
if (opteq) {
|
||||
int val, idx;
|
||||
static const char options[] ALIGN1 =
|
||||
/* 0 */ "rsize\0"
|
||||
/* 1 */ "wsize\0"
|
||||
@@ -1081,87 +1082,92 @@ static int nfsmount(struct mntent *mp, long vfsflags, char *filteropts)
|
||||
/* 18 */ "proto\0"
|
||||
/* 19 */ "namlen\0"
|
||||
/* 20 */ "addr\0";
|
||||
int val = xatoi_u(opteq + 1);
|
||||
*opteq = '\0';
|
||||
switch (index_in_strings(options, opt)) {
|
||||
|
||||
*opteq++ = '\0';
|
||||
idx = index_in_strings(options, opt);
|
||||
switch (idx) {
|
||||
case 12: // "mounthost"
|
||||
mounthost = xstrndup(opteq,
|
||||
strcspn(opteq, " \t\n\r,"));
|
||||
continue;
|
||||
case 18: // "proto"
|
||||
if (!strncmp(opteq, "tcp", 3))
|
||||
tcp = 1;
|
||||
else if (!strncmp(opteq, "udp", 3))
|
||||
tcp = 0;
|
||||
else
|
||||
bb_error_msg("warning: unrecognized proto= option");
|
||||
continue;
|
||||
case 20: // "addr" - ignore
|
||||
continue;
|
||||
}
|
||||
|
||||
val = xatoi_u(opteq);
|
||||
switch (idx) {
|
||||
case 0: // "rsize"
|
||||
data.rsize = val;
|
||||
break;
|
||||
continue;
|
||||
case 1: // "wsize"
|
||||
data.wsize = val;
|
||||
break;
|
||||
continue;
|
||||
case 2: // "timeo"
|
||||
data.timeo = val;
|
||||
break;
|
||||
continue;
|
||||
case 3: // "retrans"
|
||||
data.retrans = val;
|
||||
break;
|
||||
continue;
|
||||
case 4: // "acregmin"
|
||||
data.acregmin = val;
|
||||
break;
|
||||
continue;
|
||||
case 5: // "acregmax"
|
||||
data.acregmax = val;
|
||||
break;
|
||||
continue;
|
||||
case 6: // "acdirmin"
|
||||
data.acdirmin = val;
|
||||
break;
|
||||
continue;
|
||||
case 7: // "acdirmax"
|
||||
data.acdirmax = val;
|
||||
break;
|
||||
continue;
|
||||
case 8: // "actimeo"
|
||||
data.acregmin = val;
|
||||
data.acregmax = val;
|
||||
data.acdirmin = val;
|
||||
data.acdirmax = val;
|
||||
break;
|
||||
continue;
|
||||
case 9: // "retry"
|
||||
retry = val;
|
||||
break;
|
||||
continue;
|
||||
case 10: // "port"
|
||||
port = val;
|
||||
break;
|
||||
continue;
|
||||
case 11: // "mountport"
|
||||
mountport = val;
|
||||
break;
|
||||
case 12: // "mounthost"
|
||||
mounthost = xstrndup(opteq+1,
|
||||
strcspn(opteq+1," \t\n\r,"));
|
||||
break;
|
||||
continue;
|
||||
case 13: // "mountprog"
|
||||
mountprog = val;
|
||||
break;
|
||||
continue;
|
||||
case 14: // "mountvers"
|
||||
mountvers = val;
|
||||
break;
|
||||
continue;
|
||||
case 15: // "nfsprog"
|
||||
nfsprog = val;
|
||||
break;
|
||||
continue;
|
||||
case 16: // "nfsvers"
|
||||
case 17: // "vers"
|
||||
nfsvers = val;
|
||||
break;
|
||||
case 18: // "proto"
|
||||
if (!strncmp(opteq+1, "tcp", 3))
|
||||
tcp = 1;
|
||||
else if (!strncmp(opteq+1, "udp", 3))
|
||||
tcp = 0;
|
||||
else
|
||||
bb_error_msg("warning: unrecognized proto= option");
|
||||
break;
|
||||
continue;
|
||||
case 19: // "namlen"
|
||||
if (nfs_mount_version >= 2)
|
||||
//if (nfs_mount_version >= 2)
|
||||
data.namlen = val;
|
||||
else
|
||||
bb_error_msg("warning: option namlen is not supported\n");
|
||||
break;
|
||||
case 20: // "addr" - ignore
|
||||
break;
|
||||
//else
|
||||
// bb_error_msg("warning: option namlen is not supported\n");
|
||||
continue;
|
||||
default:
|
||||
bb_error_msg("unknown nfs mount parameter: %s=%d", opt, val);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else { /* not of the form opt=val */
|
||||
static const char options[] ALIGN1 =
|
||||
"bg\0"
|
||||
"fg\0"
|
||||
|
||||
Reference in new issue
Block a user