style fixes. No code changes
This commit is contained in:
parent
50f7f446ec
commit
51742f4bb0
@ -124,7 +124,7 @@ static const unsigned short mode_mask[] = {
|
|||||||
0, S_IXOTH, S_IXOTH, 0 /* other */
|
0, S_IXOTH, S_IXOTH, 0 /* other */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define parse_error(x) do { errmsg = x; goto pe_label; } while(0)
|
#define parse_error(x) do { errmsg = x; goto pe_label; } while (0)
|
||||||
|
|
||||||
static void parse_config_file(void)
|
static void parse_config_file(void)
|
||||||
{
|
{
|
||||||
|
@ -217,7 +217,7 @@ char* make_new_name_gunzip(char *filename)
|
|||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
extension[-1] = '\0';
|
extension[-1] = '\0';
|
||||||
} else if(strcmp(extension, "tgz") == 0) {
|
} else if (strcmp(extension, "tgz") == 0) {
|
||||||
filename = xstrdup(filename);
|
filename = xstrdup(filename);
|
||||||
extension = strrchr(filename, '.');
|
extension = strrchr(filename, '.');
|
||||||
extension[2] = 'a';
|
extension[2] = 'a';
|
||||||
|
@ -47,7 +47,7 @@ aa: 85.1% -- replaced with aa.gz
|
|||||||
//#define DEBUG 1
|
//#define DEBUG 1
|
||||||
/* Diagnostic functions */
|
/* Diagnostic functions */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# define Assert(cond,msg) {if(!(cond)) bb_error_msg(msg);}
|
# define Assert(cond,msg) { if (!(cond)) bb_error_msg(msg); }
|
||||||
# define Trace(x) fprintf x
|
# define Trace(x) fprintf x
|
||||||
# define Tracev(x) {if (verbose) fprintf x ;}
|
# define Tracev(x) {if (verbose) fprintf x ;}
|
||||||
# define Tracevv(x) {if (verbose > 1) fprintf x ;}
|
# define Tracevv(x) {if (verbose > 1) fprintf x ;}
|
||||||
|
@ -676,7 +676,7 @@ static void handle_SIGCHLD(int status)
|
|||||||
/* child exited with 0 */
|
/* child exited with 0 */
|
||||||
return;
|
return;
|
||||||
/* Cannot happen?
|
/* Cannot happen?
|
||||||
if(!WIFSIGNALED(status) && !WIFEXITED(status)) return; */
|
if (!WIFSIGNALED(status) && !WIFEXITED(status)) return; */
|
||||||
child_error = 1;
|
child_error = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,11 +29,11 @@ int rm_main(int argc, char **argv)
|
|||||||
opt_complementary = "f-i:i-f";
|
opt_complementary = "f-i:i-f";
|
||||||
opt = getopt32(argc, argv, "fiRr");
|
opt = getopt32(argc, argv, "fiRr");
|
||||||
argv += optind;
|
argv += optind;
|
||||||
if(opt & 1)
|
if (opt & 1)
|
||||||
flags |= FILEUTILS_FORCE;
|
flags |= FILEUTILS_FORCE;
|
||||||
if(opt & 2)
|
if (opt & 2)
|
||||||
flags |= FILEUTILS_INTERACTIVE;
|
flags |= FILEUTILS_INTERACTIVE;
|
||||||
if(opt & 12)
|
if (opt & 12)
|
||||||
flags |= FILEUTILS_RECUR;
|
flags |= FILEUTILS_RECUR;
|
||||||
|
|
||||||
if (*argv != NULL) {
|
if (*argv != NULL) {
|
||||||
|
@ -183,7 +183,7 @@ static int do_stop(void)
|
|||||||
if (!quiet && killed) {
|
if (!quiet && killed) {
|
||||||
printf("stopped %s (pid", what);
|
printf("stopped %s (pid", what);
|
||||||
for (p = found; p; p = p->next)
|
for (p = found; p; p = p->next)
|
||||||
if(p->pid < 0)
|
if (p->pid < 0)
|
||||||
printf(" %d", -p->pid);
|
printf(" %d", -p->pid);
|
||||||
puts(")");
|
puts(")");
|
||||||
}
|
}
|
||||||
|
@ -2145,7 +2145,8 @@ static var *evaluate(node *op, var *res)
|
|||||||
X.rsm = newfile(R.s);
|
X.rsm = newfile(R.s);
|
||||||
if (! X.rsm->F) {
|
if (! X.rsm->F) {
|
||||||
if (opn == '|') {
|
if (opn == '|') {
|
||||||
if((X.rsm->F = popen(R.s, "w")) == NULL)
|
X.rsm->F = popen(R.s, "w");
|
||||||
|
if (X.rsm->F == NULL)
|
||||||
bb_perror_msg_and_die("popen");
|
bb_perror_msg_and_die("popen");
|
||||||
X.rsm->is_pipe = 1;
|
X.rsm->is_pipe = 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -62,7 +62,9 @@ static char *extract_filename(char *line, int patch_level)
|
|||||||
|
|
||||||
/* skip over (patch_level) number of leading directories */
|
/* skip over (patch_level) number of leading directories */
|
||||||
for (i = 0; i < patch_level; i++) {
|
for (i = 0; i < patch_level; i++) {
|
||||||
if(!(temp = strchr(filename_start_ptr, '/'))) break;
|
temp = strchr(filename_start_ptr, '/');
|
||||||
|
if (!temp)
|
||||||
|
break;
|
||||||
filename_start_ptr = temp + 1;
|
filename_start_ptr = temp + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,7 +447,7 @@ static void edit_file(char * fn)
|
|||||||
q = p;
|
q = p;
|
||||||
p = strchr(q,'\n');
|
p = strchr(q,'\n');
|
||||||
if (p)
|
if (p)
|
||||||
while(*p == '\n')
|
while (*p == '\n')
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
if (*q)
|
if (*q)
|
||||||
colon(q);
|
colon(q);
|
||||||
|
@ -141,7 +141,7 @@ static xlist_t *process_stdin(xlist_t *list_arg,
|
|||||||
} else {
|
} else {
|
||||||
goto set;
|
goto set;
|
||||||
}
|
}
|
||||||
} else { /* if(state == NORM) */
|
} else { /* if (state == NORM) */
|
||||||
if (ISSPACE(c)) {
|
if (ISSPACE(c)) {
|
||||||
if (s) {
|
if (s) {
|
||||||
unexpected_eof:
|
unexpected_eof:
|
||||||
|
@ -843,7 +843,7 @@ static void parse_inittab(void)
|
|||||||
for (a = actions; a->name != 0; a++) {
|
for (a = actions; a->name != 0; a++) {
|
||||||
if (strcmp(a->name, action) == 0) {
|
if (strcmp(a->name, action) == 0) {
|
||||||
if (*id != '\0') {
|
if (*id != '\0') {
|
||||||
if(strncmp(id, "/dev/", 5) == 0)
|
if (strncmp(id, "/dev/", 5) == 0)
|
||||||
id += 5;
|
id += 5;
|
||||||
strcpy(tmpConsole, "/dev/");
|
strcpy(tmpConsole, "/dev/");
|
||||||
safe_strncpy(tmpConsole + 5, id,
|
safe_strncpy(tmpConsole + 5, id,
|
||||||
|
@ -254,7 +254,7 @@ int copy_file(const char *source, const char *dest, int flags)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (con) {
|
if (con) {
|
||||||
if(setfilecon(dest, con) == -1) {
|
if (setfilecon(dest, con) == -1) {
|
||||||
bb_perror_msg("setfilecon:%s,%s", dest, con);
|
bb_perror_msg("setfilecon:%s,%s", dest, con);
|
||||||
freecon(con);
|
freecon(con);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -50,17 +50,17 @@ int get_console_fd(void)
|
|||||||
|
|
||||||
for (fd = 2; fd >= 0; fd--) {
|
for (fd = 2; fd >= 0; fd--) {
|
||||||
int fd4name;
|
int fd4name;
|
||||||
int choise_fd;
|
int choice_fd;
|
||||||
char arg;
|
char arg;
|
||||||
|
|
||||||
fd4name = open_a_console(console_names[fd]);
|
fd4name = open_a_console(console_names[fd]);
|
||||||
chk_std:
|
chk_std:
|
||||||
choise_fd = (fd4name >= 0 ? fd4name : fd);
|
choice_fd = (fd4name >= 0 ? fd4name : fd);
|
||||||
|
|
||||||
arg = 0;
|
arg = 0;
|
||||||
if (ioctl(choise_fd, KDGKBTYPE, &arg) == 0)
|
if (ioctl(choice_fd, KDGKBTYPE, &arg) == 0)
|
||||||
return choise_fd;
|
return choice_fd;
|
||||||
if(fd4name >= 0) {
|
if (fd4name >= 0) {
|
||||||
close(fd4name);
|
close(fd4name);
|
||||||
fd4name = -1;
|
fd4name = -1;
|
||||||
goto chk_std;
|
goto chk_std;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
* end of line. If end isn't NULL, length of the chunk read is stored in it.
|
* end of line. If end isn't NULL, length of the chunk read is stored in it.
|
||||||
* Return NULL if EOF/error */
|
* Return NULL if EOF/error */
|
||||||
|
|
||||||
char *bb_get_chunk_from_file(FILE * file, int *end)
|
char *bb_get_chunk_from_file(FILE *file, int *end)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
@ -27,7 +27,8 @@ char *bb_get_chunk_from_file(FILE * file, int *end)
|
|||||||
while ((ch = getc(file)) != EOF) {
|
while ((ch = getc(file)) != EOF) {
|
||||||
/* grow the line buffer as necessary */
|
/* grow the line buffer as necessary */
|
||||||
if (idx >= linebufsz) {
|
if (idx >= linebufsz) {
|
||||||
linebuf = xrealloc(linebuf, linebufsz += 80);
|
linebufsz += 80;
|
||||||
|
linebuf = xrealloc(linebuf, linebufsz);
|
||||||
}
|
}
|
||||||
linebuf[idx++] = (char) ch;
|
linebuf[idx++] = (char) ch;
|
||||||
if (!ch || (end && ch == '\n'))
|
if (!ch || (end && ch == '\n'))
|
||||||
@ -49,7 +50,7 @@ char *bb_get_chunk_from_file(FILE * file, int *end)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get line, including trailing \n if any */
|
/* Get line, including trailing \n if any */
|
||||||
char *xmalloc_fgets(FILE * file)
|
char *xmalloc_fgets(FILE *file)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ char *xmalloc_fgets(FILE * file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get line. Remove trailing \n */
|
/* Get line. Remove trailing \n */
|
||||||
char *xmalloc_getline(FILE * file)
|
char *xmalloc_getline(FILE *file)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *c = bb_get_chunk_from_file(file, &i);
|
char *c = bb_get_chunk_from_file(file, &i);
|
||||||
|
@ -43,7 +43,7 @@ void print_login_issue(const char *issue_file, const char *tty)
|
|||||||
outbuf = buf;
|
outbuf = buf;
|
||||||
buf[0] = c;
|
buf[0] = c;
|
||||||
buf[1] = '\0';
|
buf[1] = '\0';
|
||||||
if(c == '\n') {
|
if (c == '\n') {
|
||||||
buf[1] = '\r';
|
buf[1] = '\r';
|
||||||
buf[2] = '\0';
|
buf[2] = '\0';
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,8 @@
|
|||||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
|
|
||||||
void trim(char *s)
|
void trim(char *s)
|
||||||
{
|
{
|
||||||
size_t len = strlen(s);
|
size_t len = strlen(s);
|
||||||
@ -23,9 +19,9 @@ void trim(char *s)
|
|||||||
while (len && isspace(s[len-1])) --len;
|
while (len && isspace(s[len-1])) --len;
|
||||||
|
|
||||||
/* trim leading whitespace */
|
/* trim leading whitespace */
|
||||||
if(len) {
|
if (len) {
|
||||||
lws = strspn(s, " \n\r\t\v");
|
lws = strspn(s, " \n\r\t\v");
|
||||||
memmove(s, s + lws, len -= lws);
|
memmove(s, s + lws, len -= lws);
|
||||||
}
|
}
|
||||||
s[len] = 0;
|
s[len] = '\0';
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ int makedevs_main(int argc, char **argv)
|
|||||||
int sz;
|
int sz;
|
||||||
|
|
||||||
sz = snprintf(buf, sizeof(buf), "%s%d", basedev, S);
|
sz = snprintf(buf, sizeof(buf), "%s%d", basedev, S);
|
||||||
if(sz<0 || sz>=sizeof(buf)) /* libc different */
|
if (sz < 0 || sz >= sizeof(buf)) /* libc different */
|
||||||
bb_error_msg_and_die("%s too large", basedev);
|
bb_error_msg_and_die("%s too large", basedev);
|
||||||
|
|
||||||
/* if mode != S_IFCHR and != S_IFBLK third param in mknod() ignored */
|
/* if mode != S_IFCHR and != S_IFBLK third param in mknod() ignored */
|
||||||
|
@ -3410,7 +3410,7 @@ static struct obj_file *obj_load(FILE * fp, int loadprogbits)
|
|||||||
sec->header = section_headers[i];
|
sec->header = section_headers[i];
|
||||||
sec->idx = i;
|
sec->idx = i;
|
||||||
|
|
||||||
if(sec->header.sh_size) {
|
if (sec->header.sh_size) {
|
||||||
switch (sec->header.sh_type) {
|
switch (sec->header.sh_type) {
|
||||||
case SHT_NULL:
|
case SHT_NULL:
|
||||||
case SHT_NOTE:
|
case SHT_NOTE:
|
||||||
@ -4219,17 +4219,17 @@ int insmod_main( int argc, char **argv)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flag_print_load_map)
|
if (flag_print_load_map)
|
||||||
print_load_map(f);
|
print_load_map(f);
|
||||||
|
|
||||||
exit_status = EXIT_SUCCESS;
|
exit_status = EXIT_SUCCESS;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
#if ENABLE_FEATURE_CLEAN_UP
|
#if ENABLE_FEATURE_CLEAN_UP
|
||||||
if(fp)
|
if (fp)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
free(tmp1);
|
free(tmp1);
|
||||||
if(!tmp1)
|
if (!tmp1)
|
||||||
free(m_name);
|
free(m_name);
|
||||||
free(m_filename);
|
free(m_filename);
|
||||||
#endif
|
#endif
|
||||||
|
@ -46,11 +46,11 @@ int rmmod_main(int argc, char **argv)
|
|||||||
|
|
||||||
/* Parse command line. */
|
/* Parse command line. */
|
||||||
n = getopt32(argc, argv, "wfa");
|
n = getopt32(argc, argv, "wfa");
|
||||||
if((n & 1)) // --wait
|
if (n & 1) // --wait
|
||||||
flags &= ~O_NONBLOCK;
|
flags &= ~O_NONBLOCK;
|
||||||
if((n & 2)) // --force
|
if (n & 2) // --force
|
||||||
flags |= O_TRUNC;
|
flags |= O_TRUNC;
|
||||||
if((n & 4)) {
|
if (n & 4) {
|
||||||
/* Unload _all_ unused modules via NULL delete_module() call */
|
/* Unload _all_ unused modules via NULL delete_module() call */
|
||||||
/* until the number of modules does not change */
|
/* until the number of modules does not change */
|
||||||
size_t nmod = 0; /* number of modules */
|
size_t nmod = 0; /* number of modules */
|
||||||
|
@ -149,13 +149,13 @@ enum {
|
|||||||
/* Debug: squirt whatever message and sleep a bit so we can see it go by. */
|
/* Debug: squirt whatever message and sleep a bit so we can see it go by. */
|
||||||
/* Beware: writes to stdOUT... */
|
/* Beware: writes to stdOUT... */
|
||||||
#if 0
|
#if 0
|
||||||
#define Debug(...) do { printf(__VA_ARGS__); printf("\n"); fflush(stdout); sleep(1); } while(0)
|
#define Debug(...) do { printf(__VA_ARGS__); printf("\n"); fflush(stdout); sleep(1); } while (0)
|
||||||
#else
|
#else
|
||||||
#define Debug(...) do { } while(0)
|
#define Debug(...) do { } while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define holler_error(...) do { if (o_verbose) bb_error_msg(__VA_ARGS__); } while(0)
|
#define holler_error(...) do { if (o_verbose) bb_error_msg(__VA_ARGS__); } while (0)
|
||||||
#define holler_perror(...) do { if (o_verbose) bb_perror_msg(__VA_ARGS__); } while(0)
|
#define holler_perror(...) do { if (o_verbose) bb_perror_msg(__VA_ARGS__); } while (0)
|
||||||
|
|
||||||
/* catch: no-brainer interrupt handler */
|
/* catch: no-brainer interrupt handler */
|
||||||
static void catch(int sig)
|
static void catch(int sig)
|
||||||
|
@ -147,7 +147,7 @@ int nslookup_main(int argc, char **argv)
|
|||||||
/* (but it also says "may be enabled in /etc/resolv.conf|) */
|
/* (but it also says "may be enabled in /etc/resolv.conf|) */
|
||||||
/*_res.options |= RES_USE_INET6;*/
|
/*_res.options |= RES_USE_INET6;*/
|
||||||
|
|
||||||
if(argc == 3)
|
if (argc == 3)
|
||||||
set_default_dns(argv[2]);
|
set_default_dns(argv[2]);
|
||||||
|
|
||||||
server_print();
|
server_print();
|
||||||
|
@ -174,7 +174,7 @@ static void INET_setroute(int action, char **args)
|
|||||||
|
|
||||||
/* recognize x.x.x.x/mask format. */
|
/* recognize x.x.x.x/mask format. */
|
||||||
prefix = strchr(target, '/');
|
prefix = strchr(target, '/');
|
||||||
if(prefix) {
|
if (prefix) {
|
||||||
int prefix_len;
|
int prefix_len;
|
||||||
|
|
||||||
prefix_len = xatoul_range(prefix+1, 0, 32);
|
prefix_len = xatoul_range(prefix+1, 0, 32);
|
||||||
@ -193,7 +193,7 @@ static void INET_setroute(int action, char **args)
|
|||||||
if (isnet < 0) {
|
if (isnet < 0) {
|
||||||
bb_error_msg_and_die("resolving %s", target);
|
bb_error_msg_and_die("resolving %s", target);
|
||||||
}
|
}
|
||||||
if(prefix) {
|
if (prefix) {
|
||||||
/* do not destroy prefix for process args */
|
/* do not destroy prefix for process args */
|
||||||
*prefix = '/';
|
*prefix = '/';
|
||||||
}
|
}
|
||||||
|
@ -301,14 +301,16 @@ int sysctl_display_all(const char *path, int output, int show_table)
|
|||||||
char *tmpdir;
|
char *tmpdir;
|
||||||
struct stat ts;
|
struct stat ts;
|
||||||
|
|
||||||
if (!(dp = opendir(path))) {
|
dp = opendir(path);
|
||||||
|
if (!dp) {
|
||||||
retval = -1;
|
retval = -1;
|
||||||
} else {
|
} else {
|
||||||
while ((de = readdir(dp)) != NULL) {
|
while ((de = readdir(dp)) != NULL) {
|
||||||
tmpdir = concat_subpath_file(path, de->d_name);
|
tmpdir = concat_subpath_file(path, de->d_name);
|
||||||
if(tmpdir == NULL)
|
if (tmpdir == NULL)
|
||||||
continue;
|
continue;
|
||||||
if ((retval2 = stat(tmpdir, &ts)) != 0)
|
retval2 = stat(tmpdir, &ts);
|
||||||
|
if (retval2 != 0)
|
||||||
bb_perror_msg(tmpdir);
|
bb_perror_msg(tmpdir);
|
||||||
else {
|
else {
|
||||||
if (S_ISDIR(ts.st_mode)) {
|
if (S_ISDIR(ts.st_mode)) {
|
||||||
|
@ -46,7 +46,7 @@ int uptime_main(int argc, char **argv)
|
|||||||
upminutes = (int) info.uptime / 60;
|
upminutes = (int) info.uptime / 60;
|
||||||
uphours = (upminutes / 60) % 24;
|
uphours = (upminutes / 60) % 24;
|
||||||
upminutes %= 60;
|
upminutes %= 60;
|
||||||
if(uphours)
|
if (uphours)
|
||||||
printf("%2d:%02d, ", uphours, upminutes);
|
printf("%2d:%02d, ", uphours, upminutes);
|
||||||
else
|
else
|
||||||
printf("%d min, ", upminutes);
|
printf("%d min, ", upminutes);
|
||||||
|
@ -178,7 +178,7 @@ void find_export_symbols(char * filename)
|
|||||||
fprintf(stderr, "docproc: ");
|
fprintf(stderr, "docproc: ");
|
||||||
perror(real_filename);
|
perror(real_filename);
|
||||||
}
|
}
|
||||||
while(fgets(line, MAXLINESZ, fp)) {
|
while (fgets(line, MAXLINESZ, fp)) {
|
||||||
char *p;
|
char *p;
|
||||||
char *e;
|
char *e;
|
||||||
if (((p = strstr(line, "EXPORT_SYMBOL_GPL")) != 0) ||
|
if (((p = strstr(line, "EXPORT_SYMBOL_GPL")) != 0) ||
|
||||||
@ -291,7 +291,7 @@ void parse_file(FILE *infile)
|
|||||||
{
|
{
|
||||||
char line[MAXLINESZ];
|
char line[MAXLINESZ];
|
||||||
char * s;
|
char * s;
|
||||||
while(fgets(line, MAXLINESZ, infile)) {
|
while (fgets(line, MAXLINESZ, infile)) {
|
||||||
if (line[0] == '!') {
|
if (line[0] == '!') {
|
||||||
s = line + 2;
|
s = line + 2;
|
||||||
switch (line[1]) {
|
switch (line[1]) {
|
||||||
|
@ -53,7 +53,7 @@ int matchpathcon_main(int argc, char **argv)
|
|||||||
bb_perror_msg_and_die("error while processing %s", prefix);
|
bb_perror_msg_and_die("error while processing %s", prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
while((path = *argv++) != NULL) {
|
while ((path = *argv++) != NULL) {
|
||||||
security_context_t con;
|
security_context_t con;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
12
shell/bbsh.c
12
shell/bbsh.c
@ -68,7 +68,7 @@ struct pipeline {
|
|||||||
|
|
||||||
static void free_list(void *list, void (*freeit)(void *data))
|
static void free_list(void *list, void (*freeit)(void *data))
|
||||||
{
|
{
|
||||||
while(list) {
|
while (list) {
|
||||||
void **next = (void **)list;
|
void **next = (void **)list;
|
||||||
void *list_next = *next;
|
void *list_next = *next;
|
||||||
freeit(list);
|
freeit(list);
|
||||||
@ -159,12 +159,12 @@ static int run_pipeline(struct pipeline *line)
|
|||||||
// Handle local commands. This is totally fake and plastic.
|
// Handle local commands. This is totally fake and plastic.
|
||||||
if (cmd->argc==2 && !strcmp(cmd->argv[0],"cd"))
|
if (cmd->argc==2 && !strcmp(cmd->argv[0],"cd"))
|
||||||
chdir(cmd->argv[1]);
|
chdir(cmd->argv[1]);
|
||||||
else if(!strcmp(cmd->argv[0],"exit"))
|
else if (!strcmp(cmd->argv[0],"exit"))
|
||||||
exit(cmd->argc>1 ? atoi(cmd->argv[1]) : 0);
|
exit(cmd->argc>1 ? atoi(cmd->argv[1]) : 0);
|
||||||
else {
|
else {
|
||||||
int status;
|
int status;
|
||||||
pid_t pid=fork();
|
pid_t pid=fork();
|
||||||
if(!pid) {
|
if (!pid) {
|
||||||
run_applet_and_exit(cmd->argv[0],cmd->argc,cmd->argv);
|
run_applet_and_exit(cmd->argv[0],cmd->argc,cmd->argv);
|
||||||
execvp(cmd->argv[0],cmd->argv);
|
execvp(cmd->argv[0],cmd->argv);
|
||||||
printf("No %s",cmd->argv[0]);
|
printf("No %s",cmd->argv[0]);
|
||||||
@ -179,7 +179,7 @@ static void free_cmd(void *data)
|
|||||||
{
|
{
|
||||||
struct command *cmd=(struct command *)data;
|
struct command *cmd=(struct command *)data;
|
||||||
|
|
||||||
while(cmd->argc) free(cmd->argv[--cmd->argc]);
|
while (cmd->argc) free(cmd->argv[--cmd->argc]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -211,8 +211,8 @@ int bbsh_main(int argc, char **argv)
|
|||||||
else {
|
else {
|
||||||
unsigned cmdlen=0;
|
unsigned cmdlen=0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if(!f) putchar('$');
|
if (!f) putchar('$');
|
||||||
if(1 > getline(&command, &cmdlen,f ? : stdin)) break;
|
if (1 > getline(&command, &cmdlen,f ? : stdin)) break;
|
||||||
|
|
||||||
handle(command);
|
handle(command);
|
||||||
}
|
}
|
||||||
|
24
shell/msh.c
24
shell/msh.c
@ -92,21 +92,21 @@ extern char **environ;
|
|||||||
#ifdef MSHDEBUG
|
#ifdef MSHDEBUG
|
||||||
int mshdbg = MSHDEBUG;
|
int mshdbg = MSHDEBUG;
|
||||||
|
|
||||||
#define DBGPRINTF(x) if(mshdbg>0)printf x
|
#define DBGPRINTF(x) if (mshdbg>0) printf x
|
||||||
#define DBGPRINTF0(x) if(mshdbg>0)printf x
|
#define DBGPRINTF0(x) if (mshdbg>0) printf x
|
||||||
#define DBGPRINTF1(x) if(mshdbg>1)printf x
|
#define DBGPRINTF1(x) if (mshdbg>1) printf x
|
||||||
#define DBGPRINTF2(x) if(mshdbg>2)printf x
|
#define DBGPRINTF2(x) if (mshdbg>2) printf x
|
||||||
#define DBGPRINTF3(x) if(mshdbg>3)printf x
|
#define DBGPRINTF3(x) if (mshdbg>3) printf x
|
||||||
#define DBGPRINTF4(x) if(mshdbg>4)printf x
|
#define DBGPRINTF4(x) if (mshdbg>4) printf x
|
||||||
#define DBGPRINTF5(x) if(mshdbg>5)printf x
|
#define DBGPRINTF5(x) if (mshdbg>5) printf x
|
||||||
#define DBGPRINTF6(x) if(mshdbg>6)printf x
|
#define DBGPRINTF6(x) if (mshdbg>6) printf x
|
||||||
#define DBGPRINTF7(x) if(mshdbg>7)printf x
|
#define DBGPRINTF7(x) if (mshdbg>7) printf x
|
||||||
#define DBGPRINTF8(x) if(mshdbg>8)printf x
|
#define DBGPRINTF8(x) if (mshdbg>8) printf x
|
||||||
#define DBGPRINTF9(x) if(mshdbg>9)printf x
|
#define DBGPRINTF9(x) if (mshdbg>9) printf x
|
||||||
|
|
||||||
int mshdbg_rc = 0;
|
int mshdbg_rc = 0;
|
||||||
|
|
||||||
#define RCPRINTF(x) if(mshdbg_rc)printf x
|
#define RCPRINTF(x) if (mshdbg_rc) printf x
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ static void append_mount_options(char **oldopts, const char *newopts)
|
|||||||
&& (p[len]==',' || p[len]==0))
|
&& (p[len]==',' || p[len]==0))
|
||||||
goto skip;
|
goto skip;
|
||||||
p = strchr(p,',');
|
p = strchr(p,',');
|
||||||
if(!p) break;
|
if (!p) break;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
p = xasprintf("%s,%.*s", *oldopts, len, newopts);
|
p = xasprintf("%s,%.*s", *oldopts, len, newopts);
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#define MS_MOVE 8192
|
#define MS_MOVE 8192
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dev_t rootdev;
|
static dev_t rootdev;
|
||||||
|
|
||||||
// Recursively delete contents of rootfs.
|
// Recursively delete contents of rootfs.
|
||||||
|
|
||||||
@ -39,12 +39,13 @@ static void delete_contents(const char *directory)
|
|||||||
|
|
||||||
// Recursively delete the contents of directories.
|
// Recursively delete the contents of directories.
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
if((dir = opendir(directory))) {
|
dir = opendir(directory);
|
||||||
|
if (dir) {
|
||||||
while ((d = readdir(dir))) {
|
while ((d = readdir(dir))) {
|
||||||
char *newdir=d->d_name;
|
char *newdir = d->d_name;
|
||||||
|
|
||||||
// Skip . and ..
|
// Skip . and ..
|
||||||
if(*newdir=='.' && (!newdir[1] || (newdir[1]=='.' && !newdir[2])))
|
if (*newdir=='.' && (!newdir[1] || (newdir[1]=='.' && !newdir[2])))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Recurse to delete contents
|
// Recurse to delete contents
|
||||||
@ -66,7 +67,7 @@ static void delete_contents(const char *directory)
|
|||||||
int switch_root_main(int argc, char **argv);
|
int switch_root_main(int argc, char **argv);
|
||||||
int switch_root_main(int argc, char **argv)
|
int switch_root_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *newroot, *console=NULL;
|
char *newroot, *console = NULL;
|
||||||
struct stat st1, st2;
|
struct stat st1, st2;
|
||||||
struct statfs stfs;
|
struct statfs stfs;
|
||||||
|
|
||||||
@ -77,18 +78,18 @@ int switch_root_main(int argc, char **argv)
|
|||||||
|
|
||||||
// Change to new root directory and verify it's a different fs.
|
// Change to new root directory and verify it's a different fs.
|
||||||
|
|
||||||
newroot=argv[optind++];
|
newroot = argv[optind++];
|
||||||
|
|
||||||
if (chdir(newroot) || lstat(".", &st1) || lstat("/", &st2) ||
|
if (chdir(newroot) || lstat(".", &st1) || lstat("/", &st2) ||
|
||||||
st1.st_dev == st2.st_dev)
|
st1.st_dev == st2.st_dev)
|
||||||
{
|
{
|
||||||
bb_error_msg_and_die("bad newroot %s", newroot);
|
bb_error_msg_and_die("bad newroot %s", newroot);
|
||||||
}
|
}
|
||||||
rootdev=st2.st_dev;
|
rootdev = st2.st_dev;
|
||||||
|
|
||||||
// Additional sanity checks: we're about to rm -rf /, so be REALLY SURE
|
// Additional sanity checks: we're about to rm -rf /, so be REALLY SURE
|
||||||
// we mean it. (I could make this a CONFIG option, but I would get email
|
// we mean it. (I could make this a CONFIG option, but I would get email
|
||||||
// from all the people who WILL eat their filesystemss.)
|
// from all the people who WILL eat their filesystems.)
|
||||||
|
|
||||||
if (lstat("/init", &st1) || !S_ISREG(st1.st_mode) || statfs("/", &stfs) ||
|
if (lstat("/init", &st1) || !S_ISREG(st1.st_mode) || statfs("/", &stfs) ||
|
||||||
(stfs.f_type != RAMFS_MAGIC && stfs.f_type != TMPFS_MAGIC) ||
|
(stfs.f_type != RAMFS_MAGIC && stfs.f_type != TMPFS_MAGIC) ||
|
||||||
@ -105,14 +106,13 @@ int switch_root_main(int argc, char **argv)
|
|||||||
// recalculate "." and ".." links.
|
// recalculate "." and ".." links.
|
||||||
|
|
||||||
if (mount(".", "/", NULL, MS_MOVE, NULL) || chroot(".") || chdir("/"))
|
if (mount(".", "/", NULL, MS_MOVE, NULL) || chroot(".") || chdir("/"))
|
||||||
bb_error_msg_and_die("moving root");
|
bb_error_msg_and_die("error moving root");
|
||||||
|
|
||||||
// If a new console specified, redirect stdin/stdout/stderr to that.
|
// If a new console specified, redirect stdin/stdout/stderr to that.
|
||||||
|
|
||||||
if (console) {
|
if (console) {
|
||||||
close(0);
|
close(0);
|
||||||
if (open(console, O_RDWR) < 0)
|
xopen(console, O_RDWR);
|
||||||
bb_error_msg_and_die("bad console '%s'", console);
|
|
||||||
dup2(0, 1);
|
dup2(0, 1);
|
||||||
dup2(0, 2);
|
dup2(0, 2);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user