From vda at busybox.net Mon Oct 1 02:59:02 2007 From: vda at busybox.net (vda at busybox.net) Date: Mon, 1 Oct 2007 02:59:02 -0700 (PDT) Subject: svn commit: trunk/busybox/shell Message-ID: <20071001095902.CC190A6590@busybox.net> Author: vda Date: 2007-10-01 02:59:01 -0700 (Mon, 01 Oct 2007) New Revision: 20155 Log: hush: stop doing manual acounting of open fd's, kernel can do it for us Modified: trunk/busybox/shell/hush.c Changeset: Modified: trunk/busybox/shell/hush.c =================================================================== --- trunk/busybox/shell/hush.c 2007-10-01 08:05:26 UTC (rev 20154) +++ trunk/busybox/shell/hush.c 2007-10-01 09:59:01 UTC (rev 20155) @@ -277,11 +277,6 @@ smallint res_word; /* needed for if, for, while, until... */ }; -struct close_me { - struct close_me *next; - int fd; -}; - /* On program start, environ points to initial environment. * putenv adds new pointers into it, unsetenv removes them. * Neither of these (de)allocates the strings. @@ -362,7 +357,6 @@ int global_argc; int last_return_code; const char *ifs; - struct close_me *close_me_head; const char *cwd; unsigned last_bg_pid; struct variable *top_var; /* = &shell_ver (set in main()) */ @@ -409,7 +403,6 @@ #define last_return_code (G.last_return_code) #define ifs (G.ifs ) #define fake_mode (G.fake_mode ) -#define close_me_head (G.close_me_head ) #define cwd (G.cwd ) #define last_bg_pid (G.last_bg_pid ) #define top_var (G.top_var ) @@ -487,10 +480,6 @@ static int file_peek(struct in_str *i); static void setup_file_in_str(struct in_str *i, FILE *f); static void setup_string_in_str(struct in_str *i, const char *s); -/* close_me manipulations: */ -static void mark_open(int fd); -static void mark_closed(int fd); -static void close_all(void); /* "run" the final data structures: */ #if !defined(DEBUG_CLEAN) #define free_pipe_list(head, indent) free_pipe_list(head) @@ -999,14 +988,13 @@ bb_error_msg("cannot open '%s'", argv[1]); return EXIT_FAILURE; } + close_on_exec_on(fileno(input)); /* Now run the file */ /* XXX argv and argc are broken; need to save old global_argv * (pointer only is OK!) on this stack frame, * set global_argv=argv+1, recurse, and restore. */ - mark_open(fileno(input)); status = parse_and_run_file(input); - mark_closed(fileno(input)); fclose(input); return status; } @@ -1251,33 +1239,6 @@ i->eof_flag = 0; } -static void mark_open(int fd) -{ - struct close_me *new = xmalloc(sizeof(struct close_me)); - new->fd = fd; - new->next = close_me_head; - close_me_head = new; -} - -static void mark_closed(int fd) -{ - struct close_me *tmp; - if (close_me_head == NULL || close_me_head->fd != fd) - bb_error_msg_and_die("corrupt close_me"); - tmp = close_me_head; - close_me_head = close_me_head->next; - free(tmp); -} - -static void close_all(void) -{ - struct close_me *c; - for (c = close_me_head; c; c = c->next) { - close(c->fd); - } - close_me_head = NULL; -} - /* squirrel != NULL means we squirrel away copies of stdin, stdout, * and stderr if they are redirected. */ static int setup_redirects(struct child_prog *prog, int squirrel[]) @@ -1826,7 +1787,6 @@ } #endif /* in non-interactive case fatal sigs are already SIG_DFL */ - close_all(); if (nextin != 0) { dup2(nextin, 0); close(nextin); @@ -3183,7 +3143,7 @@ p = generate_stream_from_list(inner.list_head); if (p == NULL) return 1; - mark_open(fileno(p)); + close_on_exec_on(fileno(p)); setup_file_in_str(&pipe_str, p); /* now send results of command back into original context */ @@ -3206,7 +3166,6 @@ * to do better, by using wait(), and keeping track of background jobs * at the same time. That would be a lot of work, and contrary * to the KISS philosophy of this program. */ - mark_closed(fileno(p)); retcode = fclose(p); free_pipe_list(inner.list_head, 0); debug_printf("closed FILE from child, retcode=%d\n", retcode); @@ -3718,9 +3677,8 @@ debug_printf("sourcing /etc/profile\n"); input = fopen("/etc/profile", "r"); if (input != NULL) { - mark_open(fileno(input)); + close_on_exec_on(fileno(input)); parse_and_run_file(input); - mark_closed(fileno(input)); fclose(input); } } From vda at busybox.net Mon Oct 1 02:59:47 2007 From: vda at busybox.net (vda at busybox.net) Date: Mon, 1 Oct 2007 02:59:47 -0700 (PDT) Subject: svn commit: trunk/busybox/shell Message-ID: <20071001095947.A40A4A65B0@busybox.net> Author: vda Date: 2007-10-01 02:59:47 -0700 (Mon, 01 Oct 2007) New Revision: 20156 Log: hush: feeble attempt at making it more NOMMU-friendly Modified: trunk/busybox/shell/hush.c Changeset: Modified: trunk/busybox/shell/hush.c =================================================================== --- trunk/busybox/shell/hush.c 2007-10-01 09:59:01 UTC (rev 20155) +++ trunk/busybox/shell/hush.c 2007-10-01 09:59:47 UTC (rev 20156) @@ -86,6 +86,15 @@ #include "busybox.h" /* for struct bb_applet */ +#if !BB_MMU +/* A bit drastic. Can allow some simpler commands + * by analysing command in generate_stream_from_list() + */ +#undef ENABLE_HUSH_TICK +#define ENABLE_HUSH_TICK 0 +#endif + + /* If you comment out one of these below, it will be #defined later * to perform debug printfs to stderr: */ #define debug_printf(...) do {} while (0) @@ -1268,7 +1277,7 @@ squirrel[redir->fd] = dup(redir->fd); } if (openfd == -3) { - close(openfd); + //close(openfd); // close(-3) ??! } else { dup2(openfd, redir->fd); if (redir->dup == -1) @@ -1291,8 +1300,9 @@ } } -/* never returns */ -/* XXX no exit() here. If you don't exec, use _exit instead. +/* Called after [v]fork() in run_pipe_real(), or from builtin_exec(). + * Never returns. + * XXX no exit() here. If you don't exec, use _exit instead. * The at_exit handlers apparently confuse the calling process, * in particular stdin handling. Not sure why? -- because of vfork! (vda) */ static void pseudo_exec_argv(char **argv) @@ -1359,6 +1369,8 @@ _exit(1); } +/* Called after [v]fork() in run_pipe_real() + */ static void pseudo_exec(struct child_prog *child) { // FIXME: buggy wrt NOMMU! Must not modify any global data @@ -1370,7 +1382,9 @@ } if (child->group) { - // FIXME: do not modify globals! Think vfork! +#if !BB_MMU + bb_error_msg_and_exit("nested lists are not supported on NOMMU"); +#else #if ENABLE_HUSH_INTERACTIVE debug_printf_exec("pseudo_exec: setting interactive_fd=0\n"); interactive_fd = 0; /* crucial!!!! */ @@ -1380,6 +1394,7 @@ /* OK to leak memory by not calling free_pipe_list, * since this process is about to exit */ _exit(rcode); +#endif } /* Can happen. See what bash does with ">foo" by itself. */ @@ -1787,14 +1802,8 @@ } #endif /* in non-interactive case fatal sigs are already SIG_DFL */ - if (nextin != 0) { - dup2(nextin, 0); - close(nextin); - } - if (nextout != 1) { - dup2(nextout, 1); - close(nextout); - } + xmove_fd(nextin, 0); + xmove_fd(nextout, 1); if (pipefds[0] != -1) { close(pipefds[0]); /* opposite end of our output pipe */ } @@ -3084,17 +3093,14 @@ } #if ENABLE_HUSH_TICK +/* NB: currently disabled on NOMMU */ static FILE *generate_stream_from_list(struct pipe *head) { FILE *pf; int pid, channel[2]; xpipe(channel); -#if BB_MMU pid = fork(); -#else - pid = vfork(); -#endif if (pid < 0) { bb_perror_msg_and_die("fork"); } else if (pid == 0) { From vda at busybox.net Mon Oct 1 03:00:46 2007 From: vda at busybox.net (vda at busybox.net) Date: Mon, 1 Oct 2007 03:00:46 -0700 (PDT) Subject: svn commit: trunk/busybox/shell Message-ID: <20071001100046.2C9FEA65EA@busybox.net> Author: vda Date: 2007-10-01 03:00:45 -0700 (Mon, 01 Oct 2007) New Revision: 20157 Log: hush: int->smallint for flag vars; make some names more "greppable" Modified: trunk/busybox/shell/hush.c Changeset: Modified: trunk/busybox/shell/hush.c =================================================================== --- trunk/busybox/shell/hush.c 2007-10-01 09:59:47 UTC (rev 20156) +++ trunk/busybox/shell/hush.c 2007-10-01 10:00:45 UTC (rev 20157) @@ -246,7 +246,7 @@ redir_type type; /* type of redirection */ int fd; /* file descriptor being redirected */ int dup; /* -1, or file descriptor being duplicated */ - glob_t word; /* *word.gl_pathv is the filename */ + glob_t glob_word; /* *word.gl_pathv is the filename */ }; struct child_prog { @@ -304,8 +304,8 @@ char *data; int length; int maxlen; - int quote; - int nonnull; + smallint o_quote; + smallint nonnull; } o_string; #define NULL_O_STRING {NULL,0,0,0,0} /* used for initialization: o_string foo = NULL_O_STRING; */ @@ -1256,13 +1256,13 @@ struct redir_struct *redir; for (redir = prog->redirects; redir; redir = redir->next) { - if (redir->dup == -1 && redir->word.gl_pathv == NULL) { + if (redir->dup == -1 && redir->glob_word.gl_pathv == NULL) { /* something went wrong in the parse. Pretend it didn't happen */ continue; } if (redir->dup == -1) { mode = redir_table[redir->type].mode; - openfd = open_or_warn(redir->word.gl_pathv[0], mode); + openfd = open_or_warn(redir->glob_word.gl_pathv[0], mode); if (openfd < 0) { /* this could get lost if stderr has been redirected, but bash and ash both lose it as well (though zsh doesn't!) */ @@ -2162,9 +2162,9 @@ debug_printf_clean("%s redirect %d%s", indenter(indent), r->fd, redir_table[r->type].descrip); if (r->dup == -1) { /* guard against the case >$FOO, where foo is unset or blank */ - if (r->word.gl_pathv) { - debug_printf_clean(" %s\n", *r->word.gl_pathv); - globfree(&r->word); + if (r->glob_word.gl_pathv) { + debug_printf_clean(" %s\n", r->glob_word.gl_pathv[0]); + globfree(&r->glob_word); } } else { debug_printf_clean("&%d\n", r->dup); @@ -2216,6 +2216,10 @@ return rcode; } +/* Whoever decided to muck with glob internal data is AN IDIOT! */ +/* uclibc happily changed the way it works (and it has rights to do so!), + all hell broke loose (SEGVs) */ + /* The API for glob is arguably broken. This routine pushes a non-matching * string into the output structure, removing non-backslashed backslashes. * If someone can prove me wrong, by performing this function within the @@ -2769,9 +2773,9 @@ last_redir = redir; redir = redir->next; } - redir = xmalloc(sizeof(struct redir_struct)); - redir->next = NULL; - redir->word.gl_pathv = NULL; + redir = xzalloc(sizeof(struct redir_struct)); + /* redir->next = NULL; */ + /* redir->glob_word.gl_pathv = NULL; */ if (last_redir) { last_redir->next = redir; } else { @@ -2924,7 +2928,7 @@ return 0; } if (ctx->pending_redirect) { - glob_target = &ctx->pending_redirect->word; + glob_target = &ctx->pending_redirect->glob_word; } else { if (child->group) { syntax(NULL); @@ -3160,10 +3164,10 @@ continue; } while (eol_cnt) { - b_addqchr(dest, '\n', dest->quote); + b_addqchr(dest, '\n', dest->o_quote); eol_cnt--; } - b_addqchr(dest, ch, dest->quote); + b_addqchr(dest, ch, dest->o_quote); } debug_printf("done reading from pipe, pclose()ing\n"); @@ -3224,7 +3228,7 @@ static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *input) { int ch = b_peek(input); /* first character after the $ */ - unsigned char quote_mask = dest->quote ? 0x80 : 0; + unsigned char quote_mask = dest->o_quote ? 0x80 : 0; debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); if (isalpha(ch)) { @@ -3289,7 +3293,7 @@ return 1; break; default: - b_addqchr(dest, '$', dest->quote); + b_addqchr(dest, '$', dest->o_quote); } debug_printf_parse("handle_dollar return 0\n"); return 0; @@ -3304,9 +3308,9 @@ redir_type redir_style; int next; - /* Only double-quote state is handled in the state variable dest->quote. + /* Only double-quote state is handled in the state variable dest->o_quote. * A single-quote triggers a bypass of the main loop until its mate is - * found. When recursing, quote state is passed in via dest->quote. */ + * found. When recursing, quote state is passed in via dest->o_quote. */ debug_printf_parse("parse_stream entered, end_trigger='%s'\n", end_trigger); @@ -3320,16 +3324,16 @@ next = b_peek(input); } debug_printf_parse(": ch=%c (%d) m=%d quote=%d\n", - ch, ch, m, dest->quote); + ch, ch, m, dest->o_quote); if (m == CHAR_ORDINARY - || (m != CHAR_SPECIAL && dest->quote) + || (m != CHAR_SPECIAL && dest->o_quote) ) { if (ch == EOF) { syntax("unterminated \""); debug_printf_parse("parse_stream return 1: unterminated \"\n"); return 1; } - b_addqchr(dest, ch, dest->quote); + b_addqchr(dest, ch, dest->o_quote); continue; } if (m == CHAR_IFS) { @@ -3347,7 +3351,7 @@ } } if ((end_trigger && strchr(end_trigger, ch)) - && !dest->quote && ctx->res_w == RES_NONE + && !dest->o_quote && ctx->res_w == RES_NONE ) { debug_printf_parse("parse_stream return 0: end_trigger char found\n"); return 0; @@ -3356,7 +3360,7 @@ continue; switch (ch) { case '#': - if (dest->length == 0 && !dest->quote) { + if (dest->length == 0 && !dest->o_quote) { while (1) { ch = b_peek(input); if (ch == EOF || ch == '\n') @@ -3364,7 +3368,7 @@ b_getch(input); } } else { - b_addqchr(dest, ch, dest->quote); + b_addqchr(dest, ch, dest->o_quote); } break; case '\\': @@ -3373,8 +3377,8 @@ debug_printf_parse("parse_stream return 1: \\\n"); return 1; } - b_addqchr(dest, '\\', dest->quote); - b_addqchr(dest, b_getch(input), dest->quote); + b_addqchr(dest, '\\', dest->o_quote); + b_addqchr(dest, b_getch(input), dest->o_quote); break; case '$': if (handle_dollar(dest, ctx, input) != 0) { @@ -3398,7 +3402,7 @@ break; case '"': dest->nonnull = 1; - dest->quote = !dest->quote; + dest->o_quote ^= 1; /* invert */ break; #if ENABLE_HUSH_TICK case '`': @@ -3561,7 +3565,7 @@ b_reset(&temp); } temp.nonnull = 0; - temp.quote = 0; + temp.o_quote = 0; inp->p = NULL; free_pipe_list(ctx.list_head, 0); } From vda at busybox.net Mon Oct 1 03:02:25 2007 From: vda at busybox.net (vda at busybox.net) Date: Mon, 1 Oct 2007 03:02:25 -0700 (PDT) Subject: svn commit: trunk/busybox/shell Message-ID: <20071001100225.E3BF0A67F7@busybox.net> Author: vda Date: 2007-10-01 03:02:25 -0700 (Mon, 01 Oct 2007) New Revision: 20158 Log: hush: fix glob() abuse. Code was making unfounded assumptions how glob() works, and it broke horribly on specific uclibc config. Modified: trunk/busybox/shell/hush.c Changeset: Modified: trunk/busybox/shell/hush.c =================================================================== --- trunk/busybox/shell/hush.c 2007-10-01 10:00:45 UTC (rev 20157) +++ trunk/busybox/shell/hush.c 2007-10-01 10:02:25 UTC (rev 20158) @@ -246,7 +246,7 @@ redir_type type; /* type of redirection */ int fd; /* file descriptor being redirected */ int dup; /* -1, or file descriptor being duplicated */ - glob_t glob_word; /* *word.gl_pathv is the filename */ + char **glob_word; /* *word.gl_pathv is the filename */ }; struct child_prog { @@ -256,7 +256,7 @@ smallint subshell; /* flag, non-zero if group must be forked */ smallint is_stopped; /* is the program currently running? */ struct redir_struct *redirects; /* I/O redirections */ - glob_t glob_result; /* result of parameter globbing */ + char **glob_result; /* result of parameter globbing */ struct pipe *family; /* pointer back to the child's parent pipe */ //sp counting seems to be broken... so commented out, grep for '//sp:' //sp: int sp; /* number of SPECIAL_VAR_SYMBOL */ @@ -503,9 +503,9 @@ static void pseudo_exec(struct child_prog *child) ATTRIBUTE_NORETURN; static int run_pipe_real(struct pipe *pi); /* extended glob support: */ -static int globhack(const char *src, int flags, glob_t *pglob); +static char **globhack(const char *src, char **strings); static int glob_needed(const char *s); -static int xglob(o_string *dest, int flags, glob_t *pglob); +static int xglob(o_string *dest, char ***pglob); /* variable assignment: */ static int is_assignment(const char *s); /* data structure manipulation: */ @@ -548,6 +548,58 @@ static int set_local_var(char *str, int flg_export); static void unset_local_var(const char *name); + +static char **add_strings_to_strings(int need_xstrdup, char **strings, char **add) +{ + int i; + unsigned count1; + unsigned count2; + char **v; + + v = strings; + count1 = 0; + if (v) { + while (*v) { + count1++; + v++; + } + } + count2 = 0; + v = add; + while (*v) { + count2++; + v++; + } + v = xrealloc(strings, (count1 + count2 + 1) * sizeof(char*)); + v[count1 + count2] = NULL; + i = count2; + while (--i >= 0) + v[count1 + i] = need_xstrdup ? xstrdup(add[i]) : add[i]; + return v; +} + +/* 'add' should be a malloced pointer */ +static char **add_string_to_strings(char **strings, char *add) +{ + char *v[2]; + + v[0] = add; + v[1] = NULL; + + return add_strings_to_strings(0, strings, v); +} + +static void free_strings(char **strings) +{ + if (strings) { + char **v = strings; + while (*v) + free(*v++); + free(strings); + } +} + + /* Table of built-in functions. They can be forked or not, depending on * context: within pipes, they fork. As simple commands, they do not. * When used in non-forking context, they can change global variables @@ -1067,16 +1119,14 @@ { o->length = 0; o->nonnull = 0; - if (o->data != NULL) - *o->data = '\0'; + if (o->data) + o->data[0] = '\0'; } static void b_free(o_string *o) { - b_reset(o); free(o->data); - o->data = NULL; - o->maxlen = 0; + memset(o, 0, sizeof(*o)); } /* My analysis of quoting semantics tells me that state information @@ -1256,13 +1306,13 @@ struct redir_struct *redir; for (redir = prog->redirects; redir; redir = redir->next) { - if (redir->dup == -1 && redir->glob_word.gl_pathv == NULL) { + if (redir->dup == -1 && redir->glob_word == NULL) { /* something went wrong in the parse. Pretend it didn't happen */ continue; } if (redir->dup == -1) { mode = redir_table[redir->type].mode; - openfd = open_or_warn(redir->glob_word.gl_pathv[0], mode); + openfd = open_or_warn(redir->glob_word[0], mode); if (openfd < 0) { /* this could get lost if stderr has been redirected, but bash and ash both lose it as well (though zsh doesn't!) */ @@ -2024,6 +2074,7 @@ #if ENABLE_HUSH_LOOPS if (rword == RES_FOR && pi->num_progs) { if (!for_lcur) { + /* first loop through for */ /* if no variable values after "in" we skip "for" */ if (!pi->next->progs->argv) continue; @@ -2036,17 +2087,16 @@ } free(pi->progs->argv[0]); if (!*for_lcur) { + /* for loop is over, clean up */ free(for_list); for_lcur = NULL; flag_rep = 0; pi->progs->argv[0] = for_varname; - pi->progs->glob_result.gl_pathv[0] = pi->progs->argv[0]; continue; } /* insert next value from for_lcur */ /* vda: does it need escaping? */ pi->progs->argv[0] = xasprintf("%s=%s", for_varname, *for_lcur++); - pi->progs->glob_result.gl_pathv[0] = pi->progs->argv[0]; } if (rword == RES_IN) continue; @@ -2149,8 +2199,8 @@ for (a = 0, p = child->argv; *p; a++, p++) { debug_printf_clean("%s argv[%d] = %s\n", indenter(indent), a, *p); } - globfree(&child->glob_result); - child->argv = NULL; + free_strings(child->glob_result); + child->glob_result = NULL; } else if (child->group) { debug_printf_clean("%s begin group (subshell:%d)\n", indenter(indent), child->subshell); ret_code = free_pipe_list(child->group, indent+3); @@ -2162,9 +2212,10 @@ debug_printf_clean("%s redirect %d%s", indenter(indent), r->fd, redir_table[r->type].descrip); if (r->dup == -1) { /* guard against the case >$FOO, where foo is unset or blank */ - if (r->glob_word.gl_pathv) { - debug_printf_clean(" %s\n", r->glob_word.gl_pathv[0]); - globfree(&r->glob_word); + if (r->glob_word) { + debug_printf_clean(" %s\n", r->glob_word[0]); + free_strings(r->glob_word); + r->glob_word = NULL; } } else { debug_printf_clean("&%d\n", r->dup); @@ -2224,80 +2275,79 @@ * string into the output structure, removing non-backslashed backslashes. * If someone can prove me wrong, by performing this function within the * original glob(3) api, feel free to rewrite this routine into oblivion. - * Return code (0 vs. GLOB_NOSPACE) matches glob(3). * XXX broken if the last character is '\\', check that before calling. */ -static int globhack(const char *src, int flags, glob_t *pglob) +static char **globhack(const char *src, char **strings) { - int cnt = 0, pathc; + int cnt; const char *s; - char *dest; + char *v, *dest; + for (cnt = 1, s = src; s && *s; s++) { if (*s == '\\') s++; cnt++; } - dest = xmalloc(cnt); - if (!(flags & GLOB_APPEND)) { - pglob->gl_pathv = NULL; - pglob->gl_pathc = 0; - pglob->gl_offs = 0; - pglob->gl_offs = 0; - } - pathc = ++pglob->gl_pathc; - pglob->gl_pathv = xrealloc(pglob->gl_pathv, (pathc+1) * sizeof(*pglob->gl_pathv)); - pglob->gl_pathv[pathc-1] = dest; - pglob->gl_pathv[pathc] = NULL; + v = dest = xmalloc(cnt); for (s = src; s && *s; s++, dest++) { if (*s == '\\') s++; *dest = *s; } *dest = '\0'; - return 0; + + return add_string_to_strings(strings, v); } /* XXX broken if the last character is '\\', check that before calling */ static int glob_needed(const char *s) { for (; *s; s++) { - if (*s == '\\') s++; - if (strchr("*[?", *s)) return 1; + if (*s == '\\') + s++; + if (strchr("*[?", *s)) + return 1; } return 0; } -static int xglob(o_string *dest, int flags, glob_t *pglob) +static int xglob(o_string *dest, char ***pglob) { - int gr; - /* short-circuit for null word */ /* we can code this better when the debug_printf's are gone */ if (dest->length == 0) { if (dest->nonnull) { /* bash man page calls this an "explicit" null */ - gr = globhack(dest->data, flags, pglob); - debug_printf("globhack returned %d\n", gr); - } else { - return 0; + *pglob = globhack(dest->data, *pglob); } - } else if (glob_needed(dest->data)) { - gr = glob(dest->data, flags, NULL, pglob); + return 0; + } + + if (glob_needed(dest->data)) { + glob_t globdata; + int gr; + + memset(&globdata, 0, sizeof(globdata)); + gr = glob(dest->data, 0, NULL, &globdata); debug_printf("glob returned %d\n", gr); + if (gr == GLOB_NOSPACE) + bb_error_msg_and_die("out of memory during glob"); if (gr == GLOB_NOMATCH) { + debug_printf("globhack returned %d\n", gr); /* quote removal, or more accurately, backslash removal */ - gr = globhack(dest->data, flags, pglob); - debug_printf("globhack returned %d\n", gr); + *pglob = globhack(dest->data, *pglob); + return 0; } - } else { - gr = globhack(dest->data, flags, pglob); - debug_printf("globhack returned %d\n", gr); + if (gr != 0) { /* GLOB_ABORTED ? */ + bb_error_msg("glob(3) error %d", gr); + } + if (globdata.gl_pathv && globdata.gl_pathv[0]) + *pglob = add_strings_to_strings(1, *pglob, globdata.gl_pathv); + /* globprint(glob_target); */ + globfree(&globdata); + return gr; } - if (gr == GLOB_NOSPACE) - bb_error_msg_and_die("out of memory during glob"); - if (gr != 0) { /* GLOB_ABORTED ? */ - bb_error_msg("glob(3) error %d", gr); - } - /* globprint(glob_target); */ - return gr; + + *pglob = globhack(dest->data, *pglob); + return 0; } /* expand_strvec_to_strvec() takes a list of strings, expands @@ -2775,7 +2825,7 @@ } redir = xzalloc(sizeof(struct redir_struct)); /* redir->next = NULL; */ - /* redir->glob_word.gl_pathv = NULL; */ + /* redir->glob_word = NULL; */ if (last_redir) { last_redir->next = redir; } else { @@ -2919,8 +2969,8 @@ static int done_word(o_string *dest, struct p_context *ctx) { struct child_prog *child = ctx->child; - glob_t *glob_target; - int gr, flags = 0; + char ***glob_target; + int gr; debug_printf_parse("done_word entered: '%s' %p\n", dest->data, child); if (dest->length == 0 && !dest->nonnull) { @@ -2942,11 +2992,9 @@ return (ctx->res_w == RES_SNTX); } } - glob_target = &child->glob_result; - if (child->argv) - flags |= GLOB_APPEND; + glob_target = &child->argv; } - gr = xglob(dest, flags, glob_target); + gr = xglob(dest, glob_target); if (gr != 0) { debug_printf_parse("done_word return 1: xglob returned %d\n", gr); return 1; @@ -2954,14 +3002,17 @@ b_reset(dest); if (ctx->pending_redirect) { - ctx->pending_redirect = NULL; - if (glob_target->gl_pathc != 1) { + if (ctx->pending_redirect->glob_word + && ctx->pending_redirect->glob_word[0] + && ctx->pending_redirect->glob_word[1] + ) { + /* more than one word resulted from globbing redir */ + ctx->pending_redirect = NULL; bb_error_msg("ambiguous redirect"); debug_printf_parse("done_word return 1: ambiguous redirect\n"); return 1; } - } else { - child->argv = glob_target->gl_pathv; + ctx->pending_redirect = NULL; } #if ENABLE_HUSH_LOOPS if (ctx->res_w == RES_FOR) { @@ -3006,7 +3057,7 @@ /*child->argv = NULL;*/ /*child->is_stopped = 0;*/ /*child->group = NULL;*/ - /*child->glob_result.gl_pathv = NULL;*/ + /*child->glob_result = NULL;*/ child->family = pi; //sp: /*child->sp = 0;*/ //pt: child->parse_type = ctx->parse_type; From vda at busybox.net Mon Oct 1 04:58:41 2007 From: vda at busybox.net (vda at busybox.net) Date: Mon, 1 Oct 2007 04:58:41 -0700 (PDT) Subject: svn commit: trunk/busybox: applets archival coreutils e2fsprogs e2f etc... Message-ID: <20071001115841.5F0C8A657F@busybox.net> Author: vda Date: 2007-10-01 04:58:38 -0700 (Mon, 01 Oct 2007) New Revision: 20159 Log: 'simple' error message functions by Loic Grenie . 263 bytes saved. Modified: trunk/busybox/applets/applets.c trunk/busybox/archival/bbunzip.c trunk/busybox/coreutils/chmod.c trunk/busybox/coreutils/chown.c trunk/busybox/coreutils/dd.c trunk/busybox/coreutils/df.c trunk/busybox/coreutils/du.c trunk/busybox/coreutils/env.c trunk/busybox/coreutils/expand.c trunk/busybox/coreutils/fold.c trunk/busybox/coreutils/head.c trunk/busybox/coreutils/ln.c trunk/busybox/coreutils/ls.c trunk/busybox/coreutils/mkfifo.c trunk/busybox/coreutils/mknod.c trunk/busybox/coreutils/nice.c trunk/busybox/coreutils/nohup.c trunk/busybox/coreutils/realpath.c trunk/busybox/coreutils/split.c trunk/busybox/coreutils/touch.c trunk/busybox/coreutils/wc.c trunk/busybox/e2fsprogs/fsck.c trunk/busybox/e2fsprogs/old_e2fsprogs/fsck.c trunk/busybox/findutils/find.c trunk/busybox/findutils/grep.c trunk/busybox/findutils/xargs.c trunk/busybox/include/libbb.h trunk/busybox/init/mesg.c trunk/busybox/libbb/change_identity.c trunk/busybox/libbb/dump.c trunk/busybox/libbb/perror_msg.c trunk/busybox/libbb/perror_msg_and_die.c trunk/busybox/libbb/recursive_action.c trunk/busybox/libbb/vfork_daemon_rexec.c trunk/busybox/libbb/wfopen.c trunk/busybox/libbb/xfuncs.c trunk/busybox/loginutils/adduser.c trunk/busybox/miscutils/chrt.c trunk/busybox/miscutils/mountpoint.c trunk/busybox/miscutils/setsid.c trunk/busybox/miscutils/taskset.c trunk/busybox/modutils/rmmod.c trunk/busybox/networking/httpd.c trunk/busybox/networking/inetd.c trunk/busybox/networking/netstat.c trunk/busybox/selinux/setfiles.c trunk/busybox/shell/lash.c trunk/busybox/util-linux/mount.c trunk/busybox/util-linux/setarch.c trunk/busybox/util-linux/swaponoff.c Changeset: Modified: trunk/busybox/applets/applets.c =================================================================== --- trunk/busybox/applets/applets.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/applets/applets.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -526,7 +526,7 @@ applets[i].name); rc = lf(busybox, fpc); if (rc != 0 && errno != EEXIST) { - bb_perror_msg("%s", fpc); + bb_simple_perror_msg(fpc); } free(fpc); } Modified: trunk/busybox/archival/bbunzip.c =================================================================== --- trunk/busybox/archival/bbunzip.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/archival/bbunzip.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -49,7 +49,7 @@ /* Open src */ if (filename) { if (stat(filename, &stat_buf) != 0) { - bb_perror_msg("%s", filename); + bb_simple_perror_msg(filename); err: exitcode = 1; goto free_name; Modified: trunk/busybox/coreutils/chmod.c =================================================================== --- trunk/busybox/coreutils/chmod.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/chmod.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -63,7 +63,7 @@ } err: if (!OPT_QUIET) - bb_perror_msg("%s", fileName); + bb_simple_perror_msg(fileName); return FALSE; } Modified: trunk/busybox/coreutils/chown.c =================================================================== --- trunk/busybox/coreutils/chown.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/chown.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -57,7 +57,7 @@ return TRUE; } if (!OPT_QUIET) - bb_perror_msg("%s", fileName); /* A filename can have % in it... */ + bb_simple_perror_msg(fileName); /* A filename can have % in it... */ return FALSE; } Modified: trunk/busybox/coreutils/dd.c =================================================================== --- trunk/busybox/coreutils/dd.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/dd.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -278,7 +278,7 @@ if (n < 0) { if (flags & FLAG_NOERROR) { n = ibs; - bb_perror_msg("%s", infile); + bb_simple_perror_msg(infile); } else goto die_infile; } @@ -320,12 +320,12 @@ } if (close(ifd) < 0) { die_infile: - bb_perror_msg_and_die("%s", infile); + bb_simple_perror_msg_and_die(infile); } if (close(ofd) < 0) { die_outfile: - bb_perror_msg_and_die("%s", outfile); + bb_simple_perror_msg_and_die(outfile); } out_status: dd_output_status(0); Modified: trunk/busybox/coreutils/df.c =================================================================== --- trunk/busybox/coreutils/df.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/df.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -100,7 +100,7 @@ mount_point = mount_entry->mnt_dir; if (statfs(mount_point, &s) != 0) { - bb_perror_msg("%s", mount_point); + bb_simple_perror_msg(mount_point); goto SET_ERROR; } Modified: trunk/busybox/coreutils/du.c =================================================================== --- trunk/busybox/coreutils/du.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/du.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -67,7 +67,7 @@ unsigned long sum; if (lstat(filename, &statbuf) != 0) { - bb_perror_msg("%s", filename); + bb_simple_perror_msg(filename); G.status = EXIT_FAILURE; return 0; } @@ -85,7 +85,7 @@ if (S_ISLNK(statbuf.st_mode)) { if (G.slink_depth > G.du_depth) { /* -H or -L */ if (stat(filename, &statbuf) != 0) { - bb_perror_msg("%s", filename); + bb_simple_perror_msg(filename); G.status = EXIT_FAILURE; return 0; } Modified: trunk/busybox/coreutils/env.c =================================================================== --- trunk/busybox/coreutils/env.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/env.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -81,7 +81,7 @@ BB_EXECVP(*argv, argv); /* SUSv3-mandated exit codes. */ xfunc_error_retval = (errno == ENOENT) ? 127 : 126; - bb_perror_msg_and_die("%s", *argv); + bb_simple_perror_msg_and_die(*argv); } for (ep = environ; *ep; ep++) { Modified: trunk/busybox/coreutils/expand.c =================================================================== --- trunk/busybox/coreutils/expand.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/expand.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -192,7 +192,7 @@ /* Check and close the file */ /* We do want all of them to execute, thus | instead of || */ if (ferror(file) | fclose_if_not_stdin(file)) { - bb_perror_msg("%s", *argv); + bb_simple_perror_msg(*argv); exit_status = EXIT_FAILURE; } /* If stdin also clear EOF */ Modified: trunk/busybox/coreutils/fold.c =================================================================== --- trunk/busybox/coreutils/fold.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/fold.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -145,7 +145,7 @@ } if (ferror(istream) || fclose_if_not_stdin(istream)) { - bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ + bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */ errs |= EXIT_FAILURE; } } while (*++argv); Modified: trunk/busybox/coreutils/head.c =================================================================== --- trunk/busybox/coreutils/head.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/head.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -128,7 +128,7 @@ putchar(c); } if (fclose_if_not_stdin(fp)) { - bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ + bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */ retval = EXIT_FAILURE; } die_if_ferror_stdout(); Modified: trunk/busybox/coreutils/ln.c =================================================================== --- trunk/busybox/coreutils/ln.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/ln.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -64,7 +64,7 @@ if (!(flag & LN_SYMLINK) && stat(*argv, &statbuf)) { // coreutils: "ln dangling_symlink new_hardlink" works if (lstat(*argv, &statbuf) || !S_ISLNK(statbuf.st_mode)) { - bb_perror_msg("%s", *argv); + bb_simple_perror_msg(*argv); status = EXIT_FAILURE; free(src_name); continue; @@ -75,7 +75,7 @@ char *backup; backup = xasprintf("%s%s", src, suffix); if (rename(src, backup) < 0 && errno != ENOENT) { - bb_perror_msg("%s", src); + bb_simple_perror_msg(src); status = EXIT_FAILURE; free(backup); continue; @@ -97,7 +97,7 @@ } if (link_func(*argv, src) != 0) { - bb_perror_msg("%s", src); + bb_simple_perror_msg(src); status = EXIT_FAILURE; } Modified: trunk/busybox/coreutils/ls.c =================================================================== --- trunk/busybox/coreutils/ls.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/ls.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -171,7 +171,7 @@ } #endif if (stat(fullname, &dstat)) { - bb_perror_msg("%s", fullname); + bb_simple_perror_msg(fullname); status = EXIT_FAILURE; return 0; } @@ -182,7 +182,7 @@ } #endif if (lstat(fullname, &dstat)) { - bb_perror_msg("%s", fullname); + bb_simple_perror_msg(fullname); status = EXIT_FAILURE; return 0; } Modified: trunk/busybox/coreutils/mkfifo.c =================================================================== --- trunk/busybox/coreutils/mkfifo.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/mkfifo.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -28,7 +28,7 @@ do { if (mkfifo(*argv, mode) < 0) { - bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ + bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */ retval = EXIT_FAILURE; } } while (*++argv); Modified: trunk/busybox/coreutils/mknod.c =================================================================== --- trunk/busybox/coreutils/mknod.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/mknod.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -44,7 +44,7 @@ if (mknod(name, mode, dev) == 0) { return EXIT_SUCCESS; } - bb_perror_msg_and_die("%s", name); + bb_simple_perror_msg_and_die(name); } } bb_show_usage(); Modified: trunk/busybox/coreutils/nice.c =================================================================== --- trunk/busybox/coreutils/nice.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/nice.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -51,5 +51,5 @@ /* The exec failed... */ xfunc_error_retval = (errno == ENOENT) ? 127 : 126; /* SUSv3 */ - bb_perror_msg_and_die("%s", *argv); + bb_simple_perror_msg_and_die(*argv); } Modified: trunk/busybox/coreutils/nohup.c =================================================================== --- trunk/busybox/coreutils/nohup.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/nohup.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -56,5 +56,5 @@ BB_EXECVP(argv[1], argv+1); if (ENABLE_FEATURE_CLEAN_UP && home) free((char*)nohupout); - bb_perror_msg_and_die("%s", argv[1]); + bb_simple_perror_msg_and_die(argv[1]); } Modified: trunk/busybox/coreutils/realpath.c =================================================================== --- trunk/busybox/coreutils/realpath.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/realpath.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -35,7 +35,7 @@ puts(resolved_path); } else { retval = EXIT_FAILURE; - bb_perror_msg("%s", *argv); + bb_simple_perror_msg(*argv); } } while (--argc); Modified: trunk/busybox/coreutils/split.c =================================================================== --- trunk/busybox/coreutils/split.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/split.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -104,7 +104,7 @@ if (!bytes_read) break; if (bytes_read < 0) - bb_perror_msg_and_die("%s", argv[0]); + bb_simple_perror_msg_and_die(argv[0]); src = read_buffer; do { if (!remaining) { Modified: trunk/busybox/coreutils/touch.c =================================================================== --- trunk/busybox/coreutils/touch.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/touch.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -49,7 +49,7 @@ } } status = EXIT_FAILURE; - bb_perror_msg("%s", *argv); + bb_simple_perror_msg(*argv); } } while (*++argv); Modified: trunk/busybox/coreutils/wc.c =================================================================== --- trunk/busybox/coreutils/wc.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/coreutils/wc.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -150,7 +150,7 @@ } } else if (c == EOF) { if (ferror(fp)) { - bb_perror_msg("%s", arg); + bb_simple_perror_msg(arg); status = EXIT_FAILURE; } --counts[WC_CHARS]; Modified: trunk/busybox/e2fsprogs/fsck.c =================================================================== --- trunk/busybox/e2fsprogs/fsck.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/e2fsprogs/fsck.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -659,7 +659,7 @@ if (!noexecute) { pid = spawn(argv); if (pid < 0) - bb_perror_msg("%s", argv[0]); + bb_simple_perror_msg(argv[0]); } for (i = num_args+1; i < argc; i++) Modified: trunk/busybox/e2fsprogs/old_e2fsprogs/fsck.c =================================================================== --- trunk/busybox/e2fsprogs/old_e2fsprogs/fsck.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/e2fsprogs/old_e2fsprogs/fsck.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -626,7 +626,7 @@ if (!interactive) close(0); (void) execv(s, argv); - bb_perror_msg_and_die("%s", argv[0]); + bb_simple_perror_msg_and_die(argv[0]); } for (i = 1; i < argc; i++) Modified: trunk/busybox/findutils/find.c =================================================================== --- trunk/busybox/findutils/find.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/findutils/find.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -277,7 +277,7 @@ rc = spawn_and_wait(argv); if (rc < 0) - bb_perror_msg("%s", argv[0]); + bb_simple_perror_msg(argv[0]); i = 0; while (argv[i]) @@ -347,7 +347,7 @@ rc = unlink(fileName); } if (rc < 0) - bb_perror_msg("%s", fileName); + bb_simple_perror_msg(fileName); return TRUE; } #endif @@ -780,7 +780,7 @@ ap->context = NULL; /* SELinux headers erroneously declare non-const parameter */ if (selinux_raw_to_trans_context((char*)arg1, &ap->context)) - bb_perror_msg("%s", arg1); + bb_simple_perror_msg(arg1); } #endif else { Modified: trunk/busybox/findutils/grep.c =================================================================== --- trunk/busybox/findutils/grep.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/findutils/grep.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -369,7 +369,7 @@ FILE *file = fopen(filename, "r"); if (file == NULL) { if (!SUPPRESS_ERR_MSGS) - bb_perror_msg("%s", cur_file); + bb_simple_perror_msg(cur_file); open_errors = 1; return 0; } @@ -517,7 +517,7 @@ file = fopen(cur_file, "r"); if (file == NULL) { if (!SUPPRESS_ERR_MSGS) - bb_perror_msg("%s", cur_file); + bb_simple_perror_msg(cur_file); open_errors = 1; continue; } Modified: trunk/busybox/findutils/xargs.c =================================================================== --- trunk/busybox/findutils/xargs.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/findutils/xargs.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -57,7 +57,7 @@ status = spawn_and_wait(args); if (status < 0) { - bb_perror_msg("%s", args[0]); + bb_simple_perror_msg(args[0]); return errno == ENOENT ? 127 : 126; } if (status == 255) { Modified: trunk/busybox/include/libbb.h =================================================================== --- trunk/busybox/include/libbb.h 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/include/libbb.h 2007-10-01 11:58:38 UTC (rev 20159) @@ -677,7 +677,9 @@ extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); extern void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); +extern void bb_simple_perror_msg(const char *s); extern void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); +extern void bb_simple_perror_msg_and_die(const char *s) __attribute__ ((noreturn)); extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); extern void bb_perror_nomsg_and_die(void) ATTRIBUTE_NORETURN; @@ -1185,7 +1187,6 @@ #include #endif - #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #endif /* __LIBBUSYBOX_H__ */ Modified: trunk/busybox/init/mesg.c =================================================================== --- trunk/busybox/init/mesg.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/init/mesg.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -40,7 +40,7 @@ return EXIT_SUCCESS; } } - bb_perror_msg_and_die("%s", tty); + bb_simple_perror_msg_and_die(tty); } bb_show_usage(); } Modified: trunk/busybox/libbb/change_identity.c =================================================================== --- trunk/busybox/libbb/change_identity.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/libbb/change_identity.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -47,5 +47,5 @@ const char *err_msg = change_identity_e2str(pw); if (err_msg) - bb_perror_msg_and_die("%s", err_msg); + bb_simple_perror_msg_and_die(err_msg); } Modified: trunk/busybox/libbb/dump.c =================================================================== --- trunk/busybox/libbb/dump.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/libbb/dump.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -297,7 +297,7 @@ if (statok) { if (fstat(STDIN_FILENO, &sbuf)) { - bb_perror_msg_and_die("%s", fname); + bb_simple_perror_msg_and_die(fname); } if ((!(S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode) || @@ -309,7 +309,7 @@ } } if (fseek(stdin, bb_dump_skip, SEEK_SET)) { - bb_perror_msg_and_die("%s", fname); + bb_simple_perror_msg_and_die(fname); } savaddress = address += bb_dump_skip; bb_dump_skip = 0; @@ -328,7 +328,7 @@ for (;;) { if (*_argv) { if (!(freopen(*_argv, "r", stdin))) { - bb_perror_msg("%s", *_argv); + bb_simple_perror_msg(*_argv); exitval = 1; ++_argv; continue; @@ -393,7 +393,7 @@ bb_dump_length == -1 ? need : MIN(bb_dump_length, need), stdin); if (!n) { if (ferror(stdin)) { - bb_perror_msg("%s", _argv[-1]); + bb_simple_perror_msg(_argv[-1]); } ateof = 1; continue; Modified: trunk/busybox/libbb/perror_msg.c =================================================================== --- trunk/busybox/libbb/perror_msg.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/libbb/perror_msg.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -18,3 +18,8 @@ bb_verror_msg(s, p, errno ? strerror(errno) : NULL); va_end(p); } + +void bb_simple_perror_msg(const char *s) +{ + bb_perror_msg("%s", s); +} Modified: trunk/busybox/libbb/perror_msg_and_die.c =================================================================== --- trunk/busybox/libbb/perror_msg_and_die.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/libbb/perror_msg_and_die.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -19,3 +19,8 @@ va_end(p); xfunc_die(); } + +void bb_simple_perror_msg_and_die(const char *s) +{ + bb_perror_msg_and_die("%s", s); +} Modified: trunk/busybox/libbb/recursive_action.c =================================================================== --- trunk/busybox/libbb/recursive_action.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/libbb/recursive_action.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -120,6 +120,6 @@ return TRUE; done_nak_warn: - bb_perror_msg("%s", fileName); + bb_simple_perror_msg(fileName); return FALSE; } Modified: trunk/busybox/libbb/vfork_daemon_rexec.c =================================================================== --- trunk/busybox/libbb/vfork_daemon_rexec.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/libbb/vfork_daemon_rexec.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -62,7 +62,7 @@ { pid_t pid = spawn(argv); if (pid < 0) - bb_perror_msg_and_die("%s", *argv); + bb_simple_perror_msg_and_die(*argv); return pid; } Modified: trunk/busybox/libbb/wfopen.c =================================================================== --- trunk/busybox/libbb/wfopen.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/libbb/wfopen.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -13,7 +13,7 @@ { FILE *fp = fopen(path, mode); if (!fp) { - bb_perror_msg("%s", path); + bb_simple_perror_msg(path); errno = 0; } return fp; Modified: trunk/busybox/libbb/xfuncs.c =================================================================== --- trunk/busybox/libbb/xfuncs.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/libbb/xfuncs.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -704,13 +704,13 @@ ret = ioctl(fd, request, argp); if (ret < 0) - bb_perror_msg("%s", ioctl_name); + bb_simple_perror_msg(ioctl_name); return ret; } void bb_xioctl(int fd, int request, void *argp, const char *ioctl_name) { if (ioctl(fd, request, argp) < 0) - bb_perror_msg_and_die("%s", ioctl_name); + bb_simple_perror_msg_and_die(ioctl_name); } #else int bb_ioctl_or_warn(int fd, int request, void *argp) Modified: trunk/busybox/loginutils/adduser.c =================================================================== --- trunk/busybox/loginutils/adduser.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/loginutils/adduser.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -144,7 +144,7 @@ if (mkdir(p->pw_dir, 0755) || chown(p->pw_dir, p->pw_uid, p->pw_gid) || chmod(p->pw_dir, 02755)) { - bb_perror_msg("%s", p->pw_dir); + bb_simple_perror_msg(p->pw_dir); } } Modified: trunk/busybox/miscutils/chrt.c =================================================================== --- trunk/busybox/miscutils/chrt.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/miscutils/chrt.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -115,7 +115,7 @@ } ++argv; BB_EXECVP(*argv, argv); - bb_perror_msg_and_die("%s", *argv); + bb_simple_perror_msg_and_die(*argv); } #undef OPT_p #undef OPT_r Modified: trunk/busybox/miscutils/mountpoint.c =================================================================== --- trunk/busybox/miscutils/mountpoint.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/miscutils/mountpoint.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -61,6 +61,6 @@ } } if (!(opt & OPT_q)) - bb_perror_msg("%s", arg); + bb_simple_perror_msg(arg); return EXIT_FAILURE; } Modified: trunk/busybox/miscutils/setsid.c =================================================================== --- trunk/busybox/miscutils/setsid.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/miscutils/setsid.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -29,5 +29,5 @@ setsid(); /* no error possible */ BB_EXECVP(argv[1], argv + 1); - bb_perror_msg_and_die("%s", argv[1]); + bb_simple_perror_msg_and_die(argv[1]); } Modified: trunk/busybox/miscutils/taskset.c =================================================================== --- trunk/busybox/miscutils/taskset.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/miscutils/taskset.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -92,7 +92,7 @@ } ++argv; BB_EXECVP(*argv, argv); - bb_perror_msg_and_die("%s", *argv); + bb_simple_perror_msg_and_die(*argv); } #undef OPT_p #undef TASKSET_PRINTF_MASK Modified: trunk/busybox/modutils/rmmod.c =================================================================== --- trunk/busybox/modutils/rmmod.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/modutils/rmmod.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -85,7 +85,7 @@ } if (syscall(__NR_delete_module, ENABLE_FEATURE_2_6_MODULES ? misc_buf : argv[n], flags)) { - bb_perror_msg("%s", argv[n]); + bb_simple_perror_msg(argv[n]); ret = EXIT_FAILURE; } } Modified: trunk/busybox/networking/httpd.c =================================================================== --- trunk/busybox/networking/httpd.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/networking/httpd.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -504,7 +504,7 @@ return; } if (configFile && flag == FIRST_PARSE) /* if -c option given */ - bb_perror_msg_and_die("%s", cf); + bb_simple_perror_msg_and_die(cf); flag = FIND_FROM_HTTPD_ROOT; cf = httpd_conf; } Modified: trunk/busybox/networking/inetd.c =================================================================== --- trunk/busybox/networking/inetd.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/networking/inetd.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -983,7 +983,7 @@ char protoname[10]; if (!setconfig()) { - bb_perror_msg("%s", config_filename); + bb_simple_perror_msg(config_filename); return; } for (sep = servtab; sep; sep = sep->se_next) Modified: trunk/busybox/networking/netstat.c =================================================================== --- trunk/busybox/networking/netstat.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/networking/netstat.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -464,7 +464,7 @@ procinfo = fopen(file, "r"); if (procinfo == NULL) { if (errno != ENOENT) { - bb_perror_msg("%s", file); + bb_simple_perror_msg(file); } else { bb_error_msg("no support for '%s' on this system", name); } Modified: trunk/busybox/selinux/setfiles.c =================================================================== --- trunk/busybox/selinux/setfiles.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/selinux/setfiles.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -595,7 +595,7 @@ if (argc == 1) bb_show_usage(); if (stat(argv[optind], &sb) < 0) { - bb_perror_msg_and_die("%s", argv[optind]); + bb_simple_perror_msg_and_die(argv[optind]); } if (!S_ISREG(sb.st_mode)) { bb_error_msg_and_die("spec file %s is not a regular file", argv[optind]); @@ -603,7 +603,7 @@ /* Load the file contexts configuration and check it. */ rc = matchpathcon_init(argv[optind]); if (rc < 0) { - bb_perror_msg_and_die("%s", argv[optind]); + bb_simple_perror_msg_and_die(argv[optind]); } optind++; Modified: trunk/busybox/shell/lash.c =================================================================== --- trunk/busybox/shell/lash.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/shell/lash.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -1159,7 +1159,7 @@ /* Do not use bb_perror_msg_and_die() here, since we must not * call exit() but should call _exit() instead */ - bb_perror_msg("%s", child->argv[0]); + bb_simple_perror_msg(child->argv[0]); _exit(EXIT_FAILURE); } Modified: trunk/busybox/util-linux/mount.c =================================================================== --- trunk/busybox/util-linux/mount.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/util-linux/mount.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -1655,7 +1655,7 @@ && (i & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE)) ) { rc = mount("", argv[0], "", i, ""); - if (rc) bb_perror_msg_and_die("%s", argv[0]); + if (rc) bb_simple_perror_msg_and_die(argv[0]); goto clean_up; } Modified: trunk/busybox/util-linux/setarch.c =================================================================== --- trunk/busybox/util-linux/setarch.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/util-linux/setarch.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -44,5 +44,5 @@ BB_EXECVP(argv[0], argv); } - bb_perror_msg_and_die("%s", argv[0]); + bb_simple_perror_msg_and_die(argv[0]); } Modified: trunk/busybox/util-linux/swaponoff.c =================================================================== --- trunk/busybox/util-linux/swaponoff.c 2007-10-01 10:02:25 UTC (rev 20158) +++ trunk/busybox/util-linux/swaponoff.c 2007-10-01 11:58:38 UTC (rev 20159) @@ -31,7 +31,7 @@ status = swapoff(device); if (status != 0) { - bb_perror_msg("%s", device); + bb_simple_perror_msg(device); return 1; } From vda at busybox.net Mon Oct 1 05:05:12 2007 From: vda at busybox.net (vda at busybox.net) Date: Mon, 1 Oct 2007 05:05:12 -0700 (PDT) Subject: svn commit: trunk/busybox: archival coreutils libbb miscutils netwo etc... Message-ID: <20071001120512.E26D1A688A@busybox.net> Author: vda Date: 2007-10-01 05:05:12 -0700 (Mon, 01 Oct 2007) New Revision: 20160 Log: printf("%s\n") -> puts() Modified: trunk/busybox/archival/unzip.c trunk/busybox/coreutils/id.c trunk/busybox/libbb/lineedit.c trunk/busybox/miscutils/hdparm.c trunk/busybox/networking/nslookup.c trunk/busybox/selinux/matchpathcon.c trunk/busybox/util-linux/losetup.c Changeset: Modified: trunk/busybox/archival/unzip.c =================================================================== --- trunk/busybox/archival/unzip.c 2007-10-01 11:58:38 UTC (rev 20159) +++ trunk/busybox/archival/unzip.c 2007-10-01 12:05:12 UTC (rev 20160) @@ -263,9 +263,9 @@ total_size += zip_header.formatted.ucmpsize; if (listing) { /* List entry */ - if (verbose) { - unsigned int dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); - printf("%9u %02u-%02u-%02u %02u:%02u %s\n", + if (verbose) { + unsigned int dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); + printf("%9u %02u-%02u-%02u %02u:%02u %s\n", zip_header.formatted.ucmpsize, (dostime & 0x01e00000) >> 21, (dostime & 0x001f0000) >> 16, @@ -273,12 +273,12 @@ (dostime & 0x0000f800) >> 11, (dostime & 0x000007e0) >> 5, dst_fn); - total_entries++; - } else { - /* short listing -- filenames only */ - printf("%s\n", dst_fn); - } - i = 'n'; + total_entries++; + } else { + /* short listing -- filenames only */ + puts(dst_fn); + } + i = 'n'; } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ i = -1; } else if (last_char_is(dst_fn, '/')) { /* Extract directory */ Modified: trunk/busybox/coreutils/id.c =================================================================== --- trunk/busybox/coreutils/id.c 2007-10-01 11:58:38 UTC (rev 20159) +++ trunk/busybox/coreutils/id.c 2007-10-01 12:05:12 UTC (rev 20160) @@ -92,7 +92,7 @@ if (getcon(&scontext)) { bb_error_msg_and_die("can't get process context"); } - printf("%s\n", scontext); + puts(scontext); } #endif /* exit */ Modified: trunk/busybox/libbb/lineedit.c =================================================================== --- trunk/busybox/libbb/lineedit.c 2007-10-01 11:58:38 UTC (rev 20159) +++ trunk/busybox/libbb/lineedit.c 2007-10-01 12:05:12 UTC (rev 20160) @@ -700,7 +700,7 @@ printf("%s%-*s", matches[n], (int)(column_width - strlen(matches[n])), ""); } - printf("%s\n", matches[n]); + puts(matches[n]); } } Modified: trunk/busybox/miscutils/hdparm.c =================================================================== --- trunk/busybox/miscutils/hdparm.c 2007-10-01 11:58:38 UTC (rev 20159) +++ trunk/busybox/miscutils/hdparm.c 2007-10-01 12:05:12 UTC (rev 20160) @@ -849,7 +849,7 @@ jj >>= 1; } } - printf("%s\n", kk ? "" : "\n\tLikely used CD-ROM ATAPI-1"); + puts(kk ? "" : "\n\tLikely used CD-ROM ATAPI-1"); /* the cdrom stuff is more like ATA-2 than anything else, so: */ like_std = 2; } Modified: trunk/busybox/networking/nslookup.c =================================================================== --- trunk/busybox/networking/nslookup.c 2007-10-01 11:58:38 UTC (rev 20159) +++ trunk/busybox/networking/nslookup.c 2007-10-01 12:05:12 UTC (rev 20160) @@ -69,7 +69,7 @@ unsigned cnt = 0; printf("%-10s %s\n", header, hostname); - // printf("%s\n", cur->ai_canonname); ? + // puts(cur->ai_canonname); ? while (cur) { char *dotted, *revhost; dotted = xmalloc_sockaddr2dotted_noport(cur->ai_addr); Modified: trunk/busybox/selinux/matchpathcon.c =================================================================== --- trunk/busybox/selinux/matchpathcon.c 2007-10-01 11:58:38 UTC (rev 20159) +++ trunk/busybox/selinux/matchpathcon.c 2007-10-01 12:05:12 UTC (rev 20160) @@ -17,7 +17,7 @@ if (!noprint) printf("%s\t%s\n", path, buf); else - printf("%s\n", buf); + puts(buf); freecon(buf); return 0; Modified: trunk/busybox/util-linux/losetup.c =================================================================== --- trunk/busybox/util-linux/losetup.c 2007-10-01 11:58:38 UTC (rev 20159) +++ trunk/busybox/util-linux/losetup.c 2007-10-01 12:05:12 UTC (rev 20160) @@ -64,7 +64,7 @@ s = query_loop(dev); if (!s) { if (opt == 0x4) { - printf("%s\n", dev); + puts(dev); return EXIT_SUCCESS; } } else { From aldot at busybox.net Mon Oct 1 11:04:43 2007 From: aldot at busybox.net (aldot at busybox.net) Date: Mon, 1 Oct 2007 11:04:43 -0700 (PDT) Subject: svn commit: trunk/busybox/editors Message-ID: <20071001180443.6E0FDA688D@busybox.net> Author: aldot Date: 2007-10-01 11:04:42 -0700 (Mon, 01 Oct 2007) New Revision: 20164 Log: - ditch 2 bytes Modified: trunk/busybox/editors/vi.c Changeset: Modified: trunk/busybox/editors/vi.c =================================================================== --- trunk/busybox/editors/vi.c 2007-10-01 16:15:31 UTC (rev 20163) +++ trunk/busybox/editors/vi.c 2007-10-01 18:04:42 UTC (rev 20164) @@ -1721,7 +1721,7 @@ } // find matching char of pair () [] {} -static char *find_pair(char * p, char c) +static char *find_pair(char * p, const char c) { char match, *q; int dir, level; @@ -1895,8 +1895,8 @@ "\n\tLast command repeat with \'.\'" #endif #if ENABLE_FEATURE_VI_YANKMARK - "\n\tLine marking with 'x" - "\n\tNamed buffers with \"x" + "\n\tLine marking with 'x" + "\n\tNamed buffers with \"x" #endif #if ENABLE_FEATURE_VI_READONLY "\n\tReadonly if vi is called as \"view\"" From vda at busybox.net Tue Oct 2 02:57:42 2007 From: vda at busybox.net (vda at busybox.net) Date: Tue, 2 Oct 2007 02:57:42 -0700 (PDT) Subject: svn commit: trunk/busybox/sysklogd Message-ID: <20071002095742.3E18DA605C@busybox.net> Author: vda Date: 2007-10-02 02:57:41 -0700 (Tue, 02 Oct 2007) New Revision: 20169 Log: logger: fix a problem of losing all argv except first Modified: trunk/busybox/sysklogd/logger.c Changeset: Modified: trunk/busybox/sysklogd/logger.c =================================================================== --- trunk/busybox/sysklogd/logger.c 2007-10-01 21:21:07 UTC (rev 20168) +++ trunk/busybox/sysklogd/logger.c 2007-10-02 09:57:41 UTC (rev 20169) @@ -107,7 +107,7 @@ argv += optind; if (!argc) { #define strbuf bb_common_bufsiz1 - while (fgets(strbuf, BUFSIZ, stdin)) { + while (fgets(strbuf, COMMON_BUFSIZE, stdin)) { if (strbuf[0] && NOT_LONE_CHAR(strbuf, '\n') ) { @@ -117,11 +117,11 @@ } } else { char *message = NULL; - int len = 1; /* for NUL */ + int len = 0; int pos = 0; do { len += strlen(*argv) + 1; - message = xrealloc(message, len); + message = xrealloc(message, len + 1); sprintf(message + pos, " %s", *argv), pos = len; } while (*++argv); From vda at busybox.net Tue Oct 2 03:17:57 2007 From: vda at busybox.net (vda at busybox.net) Date: Tue, 2 Oct 2007 03:17:57 -0700 (PDT) Subject: svn commit: trunk/busybox/coreutils Message-ID: <20071002101757.210ACA6076@busybox.net> Author: vda Date: 2007-10-02 03:17:56 -0700 (Tue, 02 Oct 2007) New Revision: 20170 Log: tail: work correctly on /proc files (Kazuo TAKADA ) Modified: trunk/busybox/coreutils/tail.c Changeset: Modified: trunk/busybox/coreutils/tail.c =================================================================== --- trunk/busybox/coreutils/tail.c 2007-10-02 09:57:41 UTC (rev 20169) +++ trunk/busybox/coreutils/tail.c 2007-10-02 10:17:56 UTC (rev 20170) @@ -47,13 +47,16 @@ static ssize_t tail_read(int fd, char *buf, size_t count) { ssize_t r; - off_t current, end; + off_t current; struct stat sbuf; - end = current = lseek(fd, 0, SEEK_CUR); - if (!fstat(fd, &sbuf)) - end = sbuf.st_size; - lseek(fd, end < current ? 0 : current, SEEK_SET); + /* (A good comment is missing here) */ + current = lseek(fd, 0, SEEK_CUR); + /* /proc files report zero st_size, don't lseek them. */ + if (fstat(fd, &sbuf) == 0 && sbuf.st_size) + if (sbuf.st_size < current) + lseek(fd, 0, SEEK_SET); + r = safe_read(fd, buf, count); if (r < 0) { bb_perror_msg(bb_msg_read_error); @@ -67,8 +70,12 @@ static unsigned eat_num(const char *p) { - if (*p == '-') p++; - else if (*p == '+') { p++; G.status = EXIT_FAILURE; } + if (*p == '-') + p++; + else if (*p == '+') { + p++; + G.status = EXIT_FAILURE; + } return xatou_sfx(p, tail_suffixes); } From bugs at busybox.net Tue Oct 2 19:27:42 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Tue, 2 Oct 2007 19:27:42 -0700 Subject: [BusyBox 0001518]: display ipv6 address issus Message-ID: <6bc137ea768f3c72dbffe909b05cdf8d@busybox.net> The following issue has been SUBMITTED. ====================================================================== http://busybox.net/bugs/view.php?id=1518 ====================================================================== Reported By: arprip Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1518 Category: Networking Support Reproducibility: always Severity: minor Priority: normal Status: assigned ====================================================================== Date Submitted: 10-02-2007 19:27 PDT Last Modified: 10-02-2007 19:27 PDT ====================================================================== Summary: display ipv6 address issus Description: Even use busybox 1.7.2 , I still can not see the ipv6 link local address by ifconfig . Here is the log ========================================= br0 Link encap:Ethernet HWaddr 00:05:5D:21:99:96 inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: h?.xA/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:261 errors:0 dropped:0 overruns:0 frame:0 TX packets:43 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:24678 (24.0 KiB) TX bytes:15610 (15.2 KiB) eth0 Link encap:Ethernet HWaddr 00:05:5D:21:99:96 inet6 addr: h?.xA/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:291 errors:0 dropped:0 overruns:0 frame:0 TX packets:46 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:32743 (31.9 KiB) TX bytes:16052 (15.6 KiB) Interrupt:6 Base address:0x6000 eth1 Link encap:Ethernet HWaddr 00:05:5D:21:99:95 inet6 addr: h?.xA/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: h?.xA/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:36 errors:0 dropped:0 overruns:0 frame:0 TX packets:36 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:9836 (9.6 KiB) TX bytes:9836 (9.6 KiB) ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 10-02-07 19:27 arprip New Issue 10-02-07 19:27 arprip Status new => assigned 10-02-07 19:27 arprip Assigned To => BusyBox ====================================================================== From bugs at busybox.net Tue Oct 2 19:56:53 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Tue, 2 Oct 2007 19:56:53 -0700 Subject: [BusyBox 0001519]: ipv6 address can not be set Message-ID: <3f99844b5e3624339f150e287bbec1a2@busybox.net> The following issue has been SUBMITTED. ====================================================================== http://busybox.net/bugs/view.php?id=1519 ====================================================================== Reported By: arprip Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1519 Category: Networking Support Reproducibility: always Severity: minor Priority: normal Status: assigned ====================================================================== Date Submitted: 10-02-2007 19:56 PDT Last Modified: 10-02-2007 19:56 PDT ====================================================================== Summary: ipv6 address can not be set Description: Use busybox 1.7.2. I can not use ifconfig to set the ipv6 address to interface. for example / # ifconfig eth0 44::4/128 ifconfig: bad address '44::4' It will show me the bad address. ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 10-02-07 19:56 arprip New Issue 10-02-07 19:56 arprip Status new => assigned 10-02-07 19:56 arprip Assigned To => BusyBox ====================================================================== From bugs at busybox.net Wed Oct 3 06:35:07 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Wed, 3 Oct 2007 06:35:07 -0700 Subject: [BusyBox 0000355]: ZyXEL Kernel /BusyBox GPL violation? Message-ID: <386cba4784abd41d31b63c12a0ed81d3@bugs.busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=355 ====================================================================== Reported By: macemoneta Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 355 Category: License Violations Reproducibility: always Severity: minor Priority: normal Status: feedback ====================================================================== Date Submitted: 07-25-2005 20:27 PDT Last Modified: 10-03-2007 06:35 PDT ====================================================================== Summary: ZyXEL Kernel /BusyBox GPL violation? Description: I purchased a ZyXEL router, and noted in its log: 0day 00:00:16 klogd started: BusyBox v1.00-pre8 (2005.06.02-02:19+0000) 0day 00:00:16 Linux version 2.4.18-MIPS-01.00 (root at UTOPIA) (gcc version 3.3.3) http://busybox.net/bugs/view.php?id=53 Fri Jun 10 16:13:48 CST 2005 ... I contacted the vendor to request source, since no mention of it is made on their website (http://www.zyxel.com), or documentation: --- Subject: Linux GPL software for P-330W Where can I obtain the Linux software for the P-330W, as required under Gnu Public Licence (Firmware Version: v4.2.1.6.6e.)? --- Their response: --- Sir, Our unit is only based on Linux. It is not necessarily built off the source code. The code was developed by our engineers in Taiwan. As this is the case, we do not have access to the code here, and it is not covered by the GPL. If you need more assistance, please call at 1-800-255-4101. Thank you, Scott Latimer Technicial Support Specialist ZyXEL Communications 1130 N Miller Street Anaheim, CA 92806 A+, Network+ --- The response seems meaningless; does this constitute a violation of GPL? If so what, if any, action needs to be taken? ====================================================================== ---------------------------------------------------------------------- macemoneta - 07-26-05 07:41 ---------------------------------------------------------------------- Some additional details, from the kernel violation template: The checklist: * Does the distribution contain a copy of the License? No * Does it clearly state which software is covered by the License? Does it say anything misleading, perhaps giving the impression that something is covered by the License when in fact it is not? No, neither the printed documentation, nor their web site states which software is covered by GPL. * Is source code included in the distribution? No * Is a written offer for source code included with a distribution of just binaries? No * Is the available source code complete, or is it designed for linking in other non-free modules? No source code If there seems to be a real violation, the next thing you need to do is record the details carefully: * the precise name of the product ZyXEL P-330W * the name of the person or organization distributing it ZyXEL: http://www.zyxel.com * email addresses, postal addresses and phone numbers for how to contact the distributor(s) ZyXEL Communications 1130 N Miller Street Anaheim, CA 92806 1-800-255-4101 No email direct found. * the exact name of the package whose license is violated BusyBox v1.00-pre8 * how the license was violated: * Is the copyright notice of the copyright holder included? No * Is the source code completely missing? Yes * Does the written offer for source, if given, only give a website and/or FTP site where to download the source? No location for download, no offer of source available. * Is there a copy of the license included in the distribution? No * Is some of the source available, but not all? If so, what parts are missing? All missing ---------------------------------------------------------------------- macemoneta - 07-31-05 13:25 ---------------------------------------------------------------------- A firmware update is now available for download from the manufacturer here: ftp://ftp.us.zyxel.com/P330W/firmware/P330W_v4.2.1.6.8e_firmware.zip Examining the firmware file, I also found the "webs" web server (also GPL), so I notified that project developer as well. ---------------------------------------------------------------------- vapier - 07-31-05 15:53 ---------------------------------------------------------------------- ive mirrored the zip here: http://dev.gentoo.org/~vapier/uclibc/P330W_v4.2.1.6.8e_firmware.zip ---------------------------------------------------------------------- macemoneta - 01-09-06 17:39 ---------------------------------------------------------------------- Zyxel has released the sourcecode here: ftp://opensource.zyxel.com ---------------------------------------------------------------------- vapier - 01-09-06 17:44 ---------------------------------------------------------------------- thanks ! ive moved them from the hall of shame to the products page :) ---------------------------------------------------------------------- macemoneta - 09-27-06 00:51 ---------------------------------------------------------------------- It looks like Zyxel has fallen out of compliance again. The ftp site is no longer available (tried for over 30 days), and multiple support requests to Zyxel on the issue have been ignored. Also, all references to Linux and the GPL license have been removed from the web site as well as in the firmware download, user manual, etc. ---------------------------------------------------------------------- ehovland - 11-07-06 12:13 ---------------------------------------------------------------------- As of 2006-11-07 the FTP server ftp://opensource.zyxel.com/ is up and serving files for three different products. It would be nice if the ftp site was more easily found through their website. Neither 'opensource' or 'linux' produces a hit to that FTP server or an http enabled link to that source code. I wouldn't call that compliance unless the FSF calls that compliance. Feel free to keep nudging ZyXEL. ---------------------------------------------------------------------- macemoneta - 11-07-06 13:03 ---------------------------------------------------------------------- Confirming that the server is back up, but they are still not providing the current firmware. For the P-330W, the current firmware is P330W_V1.7_firmware.zip, but their source is for the original base release (1.4): ncftp /P330W > ls binutils-2.14.90.0.8.tar.gz P-330W_V1.4.tgz gcc-3.3.3.tar.gz upnpd.tgz There doesn't seem to be much incentive for them to remain in compliance. My emails to them seem to be bit-bucketed at this point. ---------------------------------------------------------------------- madsara - 10-03-07 06:35 ---------------------------------------------------------------------- I'm curious, does anyone have the source code and build tools for the P330? Zyxel currently does *not* have this available for download via opensource.zyxel.com. I have a number of these devices in my possession, and my emails to Zyxel have gone unanswered. If anyone still has a tarball lying around, I'd be grateful. Issue History Date Modified Username Field Change ====================================================================== 07-25-05 20:27 macemoneta New Issue 07-25-05 20:27 macemoneta Status new => assigned 07-25-05 20:27 macemoneta Assigned To => BusyBox 07-26-05 07:41 macemoneta Note Added: 0000342 07-31-05 13:25 macemoneta Note Added: 0000357 07-31-05 15:53 vapier Note Added: 0000362 01-09-06 17:39 macemoneta Note Added: 0000891 01-09-06 17:44 vapier Note Added: 0000892 01-09-06 17:44 vapier Status assigned => closed 01-09-06 17:44 vapier Resolution open => fixed 09-27-06 00:32 macemoneta Status closed => feedback 09-27-06 00:32 macemoneta Resolution fixed => reopened 09-27-06 00:32 macemoneta Note Added: 0001647 09-27-06 00:51 macemoneta Note Edited: 0001647 09-27-06 00:51 macemoneta Note Edited: 0001647 11-07-06 12:13 ehovland Note Added: 0001736 11-07-06 13:03 macemoneta Note Added: 0001737 10-03-07 06:35 madsara Note Added: 0002809 ====================================================================== From bugs at busybox.net Wed Oct 3 09:35:04 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Wed, 3 Oct 2007 09:35:04 -0700 Subject: [BusyBox 0001329]: Patch for "util-linux/mdev.c": make it able to create symlinks and subdirectories Message-ID: <6c095a825c627885dda76f142cd330bd@busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1329 ====================================================================== Reported By: Souf Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1329 Category: New Features Reproducibility: always Severity: minor Priority: normal Status: assigned ====================================================================== Date Submitted: 04-29-2007 10:44 PDT Last Modified: 10-03-2007 09:35 PDT ====================================================================== Summary: Patch for "util-linux/mdev.c": make it able to create symlinks and subdirectories Description: This patch adds to mdev.c the ability to create symlinks and subdirectories: examples: stderr -> /proc/self/fd/2 pcmC[0-9]D[0-9]c 0:0 0666 >> /dev/snd/ 0755 modified files: util-linux/mdev.c util-linux/Config.in docs/mdev.txt The patch corrects also the bug 0001299 I wish that this patch be deeply tested before a possible integration ====================================================================== ---------------------------------------------------------------------- vapier - 05-02-07 10:57 ---------------------------------------------------------------------- you removed support for program execution which is not desirable i'll post a diff patch to the busybox mailing list we've been using in Blackfin/uClinux-dist ---------------------------------------------------------------------- Souf - 05-03-07 11:44 ---------------------------------------------------------------------- New patch for mdev.c which restores support for program execution ---------------------------------------------------------------------- richard - 10-03-07 09:35 ---------------------------------------------------------------------- This update to the patch (against busybox_1_7_stable) allows simple substitution for the device name, to allow mdev to create for example /dev/mtdblock/0 from mtdblock0. The rule used is: mtdblock([0-9]) 0:0 0600 >> /dev/mtdblock/ 0755 I have found that a useful addition to this patch. Issue History Date Modified Username Field Change ====================================================================== 04-29-07 10:44 Souf New Issue 04-29-07 10:44 Souf Status new => assigned 04-29-07 10:44 Souf Assigned To => BusyBox 04-29-07 10:44 Souf File Added: mdev.patch 05-02-07 10:57 vapier Note Added: 0002336 05-03-07 11:44 Souf Note Added: 0002340 05-03-07 11:46 Souf File Added: mdev_2.patch 10-03-07 09:35 richard Note Added: 0002811 ====================================================================== From bugs at busybox.net Thu Oct 4 00:19:49 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Thu, 4 Oct 2007 00:19:49 -0700 Subject: [BusyBox 0001520]: Incorrect usage of strncat in coreutils/stat.c Message-ID: <3aa4b4a5523c94ecf6e776df2d83ce5b@busybox.net> The following issue has been SUBMITTED. ====================================================================== http://busybox.net/bugs/view.php?id=1520 ====================================================================== Reported By: d3z Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1520 Category: Security Reproducibility: always Severity: minor Priority: normal Status: assigned ====================================================================== Date Submitted: 10-04-2007 00:19 PDT Last Modified: 10-04-2007 00:19 PDT ====================================================================== Summary: Incorrect usage of strncat in coreutils/stat.c Description: coreutils/stat.c contains numerous instances of 'strncat' that are incorrect. strncat(pformat, "s", buf_len); should instead read something like: strncat(pformat, "s", buf_len-strlen(pformat)-1); This could cause a buffer overflow if the buffer size computations were incorrect. ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 10-04-07 00:19 d3z New Issue 10-04-07 00:19 d3z Status new => assigned 10-04-07 00:19 d3z Assigned To => BusyBox ====================================================================== From bugs at busybox.net Thu Oct 4 04:03:03 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Thu, 4 Oct 2007 04:03:03 -0700 Subject: [BusyBox 0001521]: Busybox 1.7.1 - mkswap can't create correctly a 4Go swap partition on a mapper device... Message-ID: <77e2ba213656e89d0bbfbb08299af8a5@busybox.net> The following issue has been SUBMITTED. ====================================================================== http://busybox.net/bugs/view.php?id=1521 ====================================================================== Reported By: rol Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1521 Category: Other Reproducibility: always Severity: major Priority: normal Status: assigned ====================================================================== Date Submitted: 10-04-2007 04:03 PDT Last Modified: 10-04-2007 04:03 PDT ====================================================================== Summary: Busybox 1.7.1 - mkswap can't create correctly a 4Go swap partition on a mapper device... Description: Hello, It seems that the mkswap utility is not behaving as expected : - If the partition is too big, the reported size is wrong, - It is not possible to put a label, - the created swap partition cannot be activated. Here is a copy of the tests done : [root at corp-ref busybox-1.7.1]# ./mkswap BusyBox v1.7.1 (2007-10-01 15:05:39 GMT) multi-call binary Usage: mkswap [-c] [-v0|-v1] device [block-count] Prepare a disk partition to be used as swap partition Options: -c Check for read-ability -v0 Make version 0 swap [max 128 Megs] -v1 Make version 1 swap [big!] (default for kernels > 2.1.117) block-count Number of block to use (default is entire partition) [root at corp-ref busybox-1.7.1]# ./mkswap /dev/mapper/isw_decfbeidae_RAID1p5 Setting up swapspace version 1, size = -1407488 bytes # Here, the size is wrong.... [root at corp-ref busybox-1.7.1]# mkswap -L SWAP-isw_decfbe /dev/mapper/isw_decfbeidae_RAID1p5 Setting up swapspace version 1, size = 4293558 kB LABEL=SWAP-isw_decfbe, no uuid # Same partition, using system mkswap : partition is correct. What's more, any attempts to activate it fails : [root at corp-ref busybox-1.7.1]# ./mkswap /dev/mapper/isw_decfbeidae_RAID1p5 Setting up swapspace version 1, size = -1407488 bytes [root at corp-ref busybox-1.7.1]# swapon -a swapon: /dev/mapper/isw_decfbeidae_RAID1p5: Invalid argument Paul ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 10-04-07 04:03 rol New Issue 10-04-07 04:03 rol Status new => assigned 10-04-07 04:03 rol Assigned To => BusyBox ====================================================================== From vda at busybox.net Fri Oct 5 08:26:09 2007 From: vda at busybox.net (vda at busybox.net) Date: Fri, 5 Oct 2007 08:26:09 -0700 (PDT) Subject: svn commit: trunk/busybox: archival archival/libunarchive include Message-ID: <20071005152609.3866CA4652@busybox.net> Author: vda Date: 2007-10-05 08:26:08 -0700 (Fri, 05 Oct 2007) New Revision: 20181 Log: gunzip: support concatenated gz files. text data bss dec hex filename 770988 1029 9552 781569 bed01 busybox.t0/busybox 771105 1029 9552 781686 bed76 busybox.t3/busybox Modified: trunk/busybox/archival/bbunzip.c trunk/busybox/archival/libunarchive/Kbuild trunk/busybox/archival/libunarchive/decompress_unzip.c trunk/busybox/archival/libunarchive/get_header_tar_gz.c trunk/busybox/archival/rpm.c trunk/busybox/archival/rpm2cpio.c trunk/busybox/include/unarchive.h Changeset: Sorry, the patch is too large to include (1127 lines). Please use ViewCVS to see it! http://busybox.net/cgi-bin/viewcvs.cgi?view=rev&root=svn&rev=20181 From vda at busybox.net Fri Oct 5 08:27:04 2007 From: vda at busybox.net (vda at busybox.net) Date: Fri, 5 Oct 2007 08:27:04 -0700 (PDT) Subject: svn commit: trunk/busybox/archival Message-ID: <20071005152704.8F14AA5D2A@busybox.net> Author: vda Date: 2007-10-05 08:27:03 -0700 (Fri, 05 Oct 2007) New Revision: 20182 Log: add tests for gunzip Added: trunk/busybox/archival/bbunzip_test.sh trunk/busybox/archival/bbunzip_test2.sh trunk/busybox/archival/bbunzip_test3.sh Changeset: Added: trunk/busybox/archival/bbunzip_test.sh =================================================================== --- trunk/busybox/archival/bbunzip_test.sh (rev 0) +++ trunk/busybox/archival/bbunzip_test.sh 2007-10-05 15:27:03 UTC (rev 20182) @@ -0,0 +1,61 @@ +#!/bin/sh +# Test that concatenated gz files are unpacking correctly. +# It also tests that unpacking in general is working right. +# Since zip code has many corner cases, run it for a few hours +# to get a decent coverage (200000 tests or more). + +gzip="gzip" +gunzip="../busybox gunzip" +# Or the other way around: +#gzip="../busybox gzip" +#gunzip="gunzip" + +c=0 +i=$PID +while true; do + c=$((c+1)) + + # RANDOM is not very random on some shells. Spice it up. + # 100003 is prime + len1=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 )) + i=$((i * 1664525 + 1013904223)) + len2=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 )) + + # Just using urandom will make gzip use method 0 (store) - + # not good for test coverage! + cat /dev/urandom | while true; do read junk; echo "junk $c $i $junk"; done \ + | dd bs=$len1 count=1 >z1 2>/dev/null + cat /dev/urandom | while true; do read junk; echo "junk $c $i $junk"; done \ + | dd bs=$len2 count=1 >z2 2>/dev/null + + $gzip zz.gz + $gzip >zz.gz + $gunzip -c zz.gz >z9 || { + echo "Exitcode $?" + exit + } + sum=`cat z1 z2 | md5sum` + sum9=`md5sum /dev/null + $gzip z1 + $gzip z2 + cat z1.gz z2.gz z1.gz z2.gz >zz.gz + $gunzip -c zz.gz >z9 || { + echo "Exitcode $? (2)" + exit + } + sum9=`md5sum /dev/null Added: trunk/busybox/archival/bbunzip_test3.sh =================================================================== --- trunk/busybox/archival/bbunzip_test3.sh (rev 0) +++ trunk/busybox/archival/bbunzip_test3.sh 2007-10-05 15:27:03 UTC (rev 20182) @@ -0,0 +1,23 @@ +#!/bin/sh +# Leak test for gunzip. Watch top for growing process size. +# In this case we look for leaks in "concatenated .gz" code - +# we feed gunzip with a stream of .gz files. + +i=$PID +c=0 +while true; do + c=$((c + 1)) + echo "Block# $c" >&2 + # RANDOM is not very random on some shells. Spice it up. + i=$((i * 1664525 + 1013904223)) + # 100003 is prime + len=$(( (((RANDOM*RANDOM)^i) & 0x7ffffff) % 100003 )) + + # Just using urandom will make gzip use method 0 (store) - + # not good for test coverage! + cat /dev/urandom \ + | while true; do read junk; echo "junk $c $i $junk"; done \ + | dd bs=$len count=1 2>/dev/null \ + | gzip >xxx.gz + cat xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz xxx.gz +done | ../busybox gunzip -c >/dev/null From vda at busybox.net Fri Oct 5 12:17:17 2007 From: vda at busybox.net (vda at busybox.net) Date: Fri, 5 Oct 2007 12:17:17 -0700 (PDT) Subject: svn commit: trunk/busybox/coreutils Message-ID: <20071005191717.08787A65EC@busybox.net> Author: vda Date: 2007-10-05 12:17:16 -0700 (Fri, 05 Oct 2007) New Revision: 20183 Log: tail: sizeof(buf) is sizeof(char*)! must be BUFSIZ Modified: trunk/busybox/coreutils/tail.c Changeset: Modified: trunk/busybox/coreutils/tail.c =================================================================== --- trunk/busybox/coreutils/tail.c 2007-10-05 15:27:03 UTC (rev 20182) +++ trunk/busybox/coreutils/tail.c 2007-10-05 19:17:16 UTC (rev 20183) @@ -57,7 +57,7 @@ if (sbuf.st_size < current) lseek(fd, 0, SEEK_SET); - r = safe_read(fd, buf, count); + r = full_read(fd, buf, count); if (r < 0) { bb_perror_msg(bb_msg_read_error); G.status = EXIT_FAILURE; @@ -271,7 +271,7 @@ if (nfiles > header_threshhold) { fmt = header_fmt; } - while ((nread = tail_read(fds[i], buf, sizeof(buf))) > 0) { + while ((nread = tail_read(fds[i], buf, BUFSIZ)) > 0) { if (fmt) { tail_xprint_header(fmt, argv[i]); fmt = NULL; From vda at busybox.net Fri Oct 5 13:29:32 2007 From: vda at busybox.net (vda at busybox.net) Date: Fri, 5 Oct 2007 13:29:32 -0700 (PDT) Subject: svn commit: trunk/busybox: archival/libunarchive coreutils Message-ID: <20071005202932.613FCA608D@busybox.net> Author: vda Date: 2007-10-05 13:29:31 -0700 (Fri, 05 Oct 2007) New Revision: 20184 Log: delete now unused check_header_gzip.c sum: do not use uintmax needlessly Removed: trunk/busybox/archival/libunarchive/check_header_gzip.c Modified: trunk/busybox/coreutils/sum.c Changeset: Deleted: trunk/busybox/archival/libunarchive/check_header_gzip.c =================================================================== --- trunk/busybox/archival/libunarchive/check_header_gzip.c 2007-10-05 19:17:16 UTC (rev 20183) +++ trunk/busybox/archival/libunarchive/check_header_gzip.c 2007-10-05 20:29:31 UTC (rev 20184) @@ -1,59 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. - */ - -#include "libbb.h" -#include "unarchive.h" /* for external decl of check_header_gzip_or_die */ - -void check_header_gzip_or_die(int src_fd) -{ - union { - unsigned char raw[8]; - struct { - unsigned char method; - unsigned char flags; - unsigned int mtime; - unsigned char xtra_flags; - unsigned char os_flags; - } formatted; - } header; - - xread(src_fd, header.raw, 8); - - /* Check the compression method */ - if (header.formatted.method != 8) { - bb_error_msg_and_die("unknown compression method %d", - header.formatted.method); - } - - if (header.formatted.flags & 0x04) { - /* bit 2 set: extra field present */ - unsigned extra_short; - - extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8); - while (extra_short > 0) { - /* Ignore extra field */ - xread_char(src_fd); - extra_short--; - } - } - - /* Discard original name if any */ - if (header.formatted.flags & 0x08) { - /* bit 3 set: original file name present */ - while (xread_char(src_fd) != 0); - } - - /* Discard file comment if any */ - if (header.formatted.flags & 0x10) { - /* bit 4 set: file comment present */ - while (xread_char(src_fd) != 0); - } - - /* Read the header checksum */ - if (header.formatted.flags & 0x02) { - xread_char(src_fd); - xread_char(src_fd); - } -} Modified: trunk/busybox/coreutils/sum.c =================================================================== --- trunk/busybox/coreutils/sum.c 2007-10-05 19:17:16 UTC (rev 20183) +++ trunk/busybox/coreutils/sum.c 2007-10-05 20:29:31 UTC (rev 20184) @@ -24,7 +24,7 @@ static unsigned sum_file(const char *file, const unsigned type) { #define buf bb_common_bufsiz1 - uintmax_t total_bytes = 0; + unsigned long long total_bytes = 0; int fd = 0, r; /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ @@ -67,9 +67,9 @@ if (type >= SUM_SYSV) { r = (s & 0xffff) + ((s & 0xffffffff) >> 16); s = (r & 0xffff) + (r >> 16); - printf("%d %ju %s\n", s, (total_bytes+511)/512, file); + printf("%d %llu %s\n", s, (total_bytes + 511) / 512, file); } else - printf("%05d %5ju %s\n", s, (total_bytes+1023)/1024, file); + printf("%05d %5llu %s\n", s, (total_bytes + 1023) / 1024, file); return 1; #undef buf } From vda at busybox.net Fri Oct 5 13:31:23 2007 From: vda at busybox.net (vda at busybox.net) Date: Fri, 5 Oct 2007 13:31:23 -0700 (PDT) Subject: svn commit: trunk/busybox/coreutils Message-ID: <20071005203123.890A5A609E@busybox.net> Author: vda Date: 2007-10-05 13:31:23 -0700 (Fri, 05 Oct 2007) New Revision: 20185 Log: stat: code shrink; stop using bss; stop using strncat incorrectly function old new delta printfs - 28 +28 strcatc - 26 +26 human_time 41 44 +3 print_it 229 219 -10 buf 30 - -30 print_statfs 420 358 -62 print_stat 1089 921 -168 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 1/3 up/down: 57/-270) Total: -213 bytes text data bss dec hex filename 771105 1029 9552 781686 bed76 busybox_old 770892 1029 9520 781441 bec81 busybox_unstripped Modified: trunk/busybox/coreutils/stat.c Changeset: Modified: trunk/busybox/coreutils/stat.c =================================================================== --- trunk/busybox/coreutils/stat.c 2007-10-05 20:29:31 UTC (rev 20184) +++ trunk/busybox/coreutils/stat.c 2007-10-05 20:31:23 UTC (rev 20185) @@ -16,14 +16,12 @@ #include "libbb.h" /* vars to control behavior */ -#define OPT_FILESYS (1<<0) -#define OPT_TERSE (1<<1) -#define OPT_DEREFERENCE (1<<2) -#define OPT_SELINUX (1<<3) +#define OPT_FILESYS (1 << 0) +#define OPT_TERSE (1 << 1) +#define OPT_DEREFERENCE (1 << 2) +#define OPT_SELINUX (1 << 3) -static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1; - -static char const * file_type(struct stat const *st) +static const char *file_type(const struct stat *st) { /* See POSIX 1003.1-2001 XCU Table 4-8 lines 17093-17107 * for some of these formats. @@ -46,7 +44,7 @@ return "weird file"; } -static char const *human_time(time_t t) +static const char *human_time(time_t t) { /* Old static char *str; @@ -56,8 +54,12 @@ */ /* coreutils 6.3 compat: */ + /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/ +#define buf bb_common_bufsiz1 + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.000000000", localtime(&t)); return buf; +#undef buf } /* Return the type of the specified file system. @@ -65,11 +67,10 @@ * Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2) * Still others have neither and have to get by with f_type (Linux). */ -static char const *human_fstype(long f_type) +static const char *human_fstype(uint32_t f_type) { - int i; static const struct types { - long type; + uint32_t type; const char *const fs; } humantypes[] = { { 0xADFF, "affs" }, @@ -109,67 +110,80 @@ { 0x62656572, "sysfs" }, { 0, "UNKNOWN" } }; + + int i; + for (i = 0; humantypes[i].type; ++i) if (humantypes[i].type == f_type) break; return humantypes[i].fs; } +static void strcatc(char *str, char c) +{ + int len = strlen(str); + str[len++] = c; + str[len] = '\0'; +} + +static void printfs(char *pformat, const char *msg) +{ + strcatc(pformat, 's'); + printf(pformat, msg); +} + #if ENABLE_FEATURE_STAT_FORMAT /* print statfs info */ -static void print_statfs(char *pformat, const size_t buf_len, const char m, - const char *const filename, void const *data - USE_SELINUX(, security_context_t scontext)) +static void print_statfs(char *pformat, const char m, + const char *const filename, const void *data + USE_SELINUX(, security_context_t scontext)) { - struct statfs const *statfsbuf = data; + const struct statfs *statfsbuf = data; if (m == 'n') { - strncat(pformat, "s", buf_len); - printf(pformat, filename); + printfs(pformat, filename); } else if (m == 'i') { - strncat(pformat, "Lx", buf_len); + strcat(pformat, "Lx"); printf(pformat, statfsbuf->f_fsid); } else if (m == 'l') { - strncat(pformat, "lu", buf_len); + strcat(pformat, "lu"); printf(pformat, statfsbuf->f_namelen); } else if (m == 't') { - strncat(pformat, "lx", buf_len); + strcat(pformat, "lx"); printf(pformat, (unsigned long) (statfsbuf->f_type)); /* no equiv */ } else if (m == 'T') { - strncat(pformat, "s", buf_len); - printf(pformat, human_fstype(statfsbuf->f_type)); + printfs(pformat, human_fstype(statfsbuf->f_type)); } else if (m == 'b') { - strncat(pformat, "jd", buf_len); + strcat(pformat, "jd"); printf(pformat, (intmax_t) (statfsbuf->f_blocks)); } else if (m == 'f') { - strncat(pformat, "jd", buf_len); + strcat(pformat, "jd"); printf(pformat, (intmax_t) (statfsbuf->f_bfree)); } else if (m == 'a') { - strncat(pformat, "jd", buf_len); + strcat(pformat, "jd"); printf(pformat, (intmax_t) (statfsbuf->f_bavail)); } else if (m == 's' || m == 'S') { - strncat(pformat, "lu", buf_len); + strcat(pformat, "lu"); printf(pformat, (unsigned long) (statfsbuf->f_bsize)); } else if (m == 'c') { - strncat(pformat, "jd", buf_len); + strcat(pformat, "jd"); printf(pformat, (intmax_t) (statfsbuf->f_files)); } else if (m == 'd') { - strncat(pformat, "jd", buf_len); + strcat(pformat, "jd"); printf(pformat, (intmax_t) (statfsbuf->f_ffree)); #if ENABLE_SELINUX } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) { - strncat(pformat, "s", buf_len); - printf(scontext); + printfs(pformat, scontext); #endif } else { - strncat(pformat, "c", buf_len); + strcatc(pformat, 'c'); printf(pformat, m); } } /* print stat info */ -static void print_stat(char *pformat, const size_t buf_len, const char m, - const char *const filename, void const *data - USE_SELINUX(, security_context_t scontext)) +static void print_stat(char *pformat, const char m, + const char *const filename, const void *data + USE_SELINUX(, security_context_t scontext)) { #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) struct stat *statbuf = (struct stat *) data; @@ -177,131 +191,118 @@ struct group *gw_ent; if (m == 'n') { - strncat(pformat, "s", buf_len); - printf(pformat, filename); + printfs(pformat, filename); } else if (m == 'N') { - strncat(pformat, "s", buf_len); + strcatc(pformat, 's'); if (S_ISLNK(statbuf->st_mode)) { char *linkname = xmalloc_readlink_or_warn(filename); - if (linkname == NULL) { - bb_perror_msg("cannot read symbolic link '%s'", filename); + if (linkname == NULL) return; - } /*printf("\"%s\" -> \"%s\"", filename, linkname); */ printf(pformat, filename); printf(" -> "); printf(pformat, linkname); + free(linkname); } else { printf(pformat, filename); } } else if (m == 'd') { - strncat(pformat, "ju", buf_len); + strcat(pformat, "ju"); printf(pformat, (uintmax_t) statbuf->st_dev); } else if (m == 'D') { - strncat(pformat, "jx", buf_len); + strcat(pformat, "jx"); printf(pformat, (uintmax_t) statbuf->st_dev); } else if (m == 'i') { - strncat(pformat, "ju", buf_len); + strcat(pformat, "ju"); printf(pformat, (uintmax_t) statbuf->st_ino); } else if (m == 'a') { - strncat(pformat, "lo", buf_len); + strcat(pformat, "lo"); printf(pformat, (unsigned long) (statbuf->st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO))); } else if (m == 'A') { - strncat(pformat, "s", buf_len); - printf(pformat, bb_mode_string(statbuf->st_mode)); + printfs(pformat, bb_mode_string(statbuf->st_mode)); } else if (m == 'f') { - strncat(pformat, "lx", buf_len); + strcat(pformat, "lx"); printf(pformat, (unsigned long) statbuf->st_mode); } else if (m == 'F') { - strncat(pformat, "s", buf_len); - printf(pformat, file_type(statbuf)); + printfs(pformat, file_type(statbuf)); } else if (m == 'h') { - strncat(pformat, "lu", buf_len); + strcat(pformat, "lu"); printf(pformat, (unsigned long) statbuf->st_nlink); } else if (m == 'u') { - strncat(pformat, "lu", buf_len); + strcat(pformat, "lu"); printf(pformat, (unsigned long) statbuf->st_uid); } else if (m == 'U') { - strncat(pformat, "s", buf_len); setpwent(); pw_ent = getpwuid(statbuf->st_uid); - printf(pformat, (pw_ent != 0L) ? pw_ent->pw_name : "UNKNOWN"); + printfs(pformat, (pw_ent != 0L) ? pw_ent->pw_name : "UNKNOWN"); } else if (m == 'g') { - strncat(pformat, "lu", buf_len); + strcat(pformat, "lu"); printf(pformat, (unsigned long) statbuf->st_gid); } else if (m == 'G') { - strncat(pformat, "s", buf_len); setgrent(); gw_ent = getgrgid(statbuf->st_gid); - printf(pformat, (gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN"); + printfs(pformat, (gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN"); } else if (m == 't') { - strncat(pformat, "lx", buf_len); + strcat(pformat, "lx"); printf(pformat, (unsigned long) major(statbuf->st_rdev)); } else if (m == 'T') { - strncat(pformat, "lx", buf_len); + strcat(pformat, "lx"); printf(pformat, (unsigned long) minor(statbuf->st_rdev)); } else if (m == 's') { - strncat(pformat, "ju", buf_len); + strcat(pformat, "ju"); printf(pformat, (uintmax_t) (statbuf->st_size)); } else if (m == 'B') { - strncat(pformat, "lu", buf_len); + strcat(pformat, "lu"); printf(pformat, (unsigned long) 512); //ST_NBLOCKSIZE } else if (m == 'b') { - strncat(pformat, "ju", buf_len); + strcat(pformat, "ju"); printf(pformat, (uintmax_t) statbuf->st_blocks); } else if (m == 'o') { - strncat(pformat, "lu", buf_len); + strcat(pformat, "lu"); printf(pformat, (unsigned long) statbuf->st_blksize); } else if (m == 'x') { - strncat(pformat, "s", buf_len); - printf(pformat, human_time(statbuf->st_atime)); + printfs(pformat, human_time(statbuf->st_atime)); } else if (m == 'X') { - strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len); + strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu"); printf(pformat, (unsigned long) statbuf->st_atime); } else if (m == 'y') { - strncat(pformat, "s", buf_len); - printf(pformat, human_time(statbuf->st_mtime)); + printfs(pformat, human_time(statbuf->st_mtime)); } else if (m == 'Y') { - strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len); + strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu"); printf(pformat, (unsigned long) statbuf->st_mtime); } else if (m == 'z') { - strncat(pformat, "s", buf_len); - printf(pformat, human_time(statbuf->st_ctime)); + printfs(pformat, human_time(statbuf->st_ctime)); } else if (m == 'Z') { - strncat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu", buf_len); + strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu"); printf(pformat, (unsigned long) statbuf->st_ctime); #if ENABLE_SELINUX } else if (m == 'C' && (option_mask32 & OPT_SELINUX)) { - strncat(pformat, "s", buf_len); - printf(pformat, scontext); + printfs(pformat, scontext); #endif } else { - strncat(pformat, "c", buf_len); + strcatc(pformat, 'c'); printf(pformat, m); } } -static void print_it(char const *masterformat, char const *filename, - void (*print_func) (char *, size_t, char, char const *, void const * - USE_SELINUX(, security_context_t scontext)), - void const *data USE_SELINUX(, security_context_t scontext) ) +static void print_it(const char *masterformat, const char *filename, + void (*print_func) (char*, char, const char*, const void* USE_SELINUX(, security_context_t scontext)), + const void *data + USE_SELINUX(, security_context_t scontext) ) { - char *b; - - /* create a working copy of the format string */ + /* Create a working copy of the format string */ char *format = xstrdup(masterformat); - /* Add 2 to accomodate our conversion of the stat '%s' format string * to the printf '%llu' one. */ - size_t n_alloc = strlen(format) + 2 + 1; - char *dest = xmalloc(n_alloc); + char *dest = xmalloc(strlen(format) + 2 + 1); + char *b; b = format; while (b) { size_t len; char *p = strchr(b, '%'); if (!p) { - /* coreutils 6.3 always print at the end */ + /* coreutils 6.3 always prints at the end */ /*fputs(b, stdout);*/ puts(b); break; @@ -309,10 +310,11 @@ *p++ = '\0'; fputs(b, stdout); + /* dest = "%" */ len = strspn(p, "#-+.I 0123456789"); dest[0] = '%'; memcpy(dest + 1, p, len); - dest[1 + len] = 0; + dest[1 + len] = '\0'; p += len; b = p + 1; @@ -324,7 +326,8 @@ bb_putchar('%'); break; default: - print_func(dest, n_alloc, *p, filename, data USE_SELINUX(,scontext)); + /* Completes "%" with specifier and printfs */ + print_func(dest, *p, filename, data USE_SELINUX(,scontext)); break; } } @@ -335,7 +338,7 @@ #endif /* Stat the file system and print what we find. */ -static bool do_statfs(char const *filename, char const *format) +static bool do_statfs(const char *filename, const char *format) { struct statfs statfsbuf; #if ENABLE_SELINUX @@ -358,7 +361,7 @@ } #if ENABLE_FEATURE_STAT_FORMAT - if (format == NULL) + if (format == NULL) { #if !ENABLE_SELINUX format = (option_mask32 & OPT_TERSE ? "%n %i %l %t %s %b %f %a %c %d\n" @@ -367,9 +370,8 @@ "Block size: %-10s\n" "Blocks: Total: %-10b Free: %-10f Available: %a\n" "Inodes: Total: %-10c Free: %d"); - print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext)); #else - format = (option_mask32 & OPT_TERSE + format = (option_mask32 & OPT_TERSE ? (option_mask32 & OPT_SELINUX ? "%n %i %l %t %s %b %f %a %c %d %C\n": "%n %i %l %t %s %b %f %a %c %d\n") : (option_mask32 & OPT_SELINUX ? @@ -385,8 +387,9 @@ "Blocks: Total: %-10b Free: %-10f Available: %a\n" "Inodes: Total: %-10c Free: %d\n") ); +#endif /* SELINUX */ + } print_it(format, filename, print_statfs, &statfsbuf USE_SELINUX(, scontext)); -#endif /* SELINUX */ #else /* FEATURE_STAT_FORMAT */ format = (option_mask32 & OPT_TERSE ? "%s %llx %lu " @@ -444,7 +447,7 @@ } /* stat the file and print what we find */ -static bool do_stat(char const *filename, char const *format) +static bool do_stat(const char *filename, const char *format) { struct stat statbuf; #if ENABLE_SELINUX @@ -612,7 +615,7 @@ char *format = NULL; int i; int ok = 1; - bool (*statfunc)(char const *, char const *) = do_stat; + bool (*statfunc)(const char *, const char *) = do_stat; getopt32(argv, "ftL" USE_SELINUX("Z") From bugs at busybox.net Fri Oct 5 13:32:30 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Fri, 5 Oct 2007 13:32:30 -0700 Subject: [BusyBox 0001520]: Incorrect usage of strncat in coreutils/stat.c Message-ID: <17928695c8164f2e495cdf8809b29e56@busybox.net> The following issue has been CLOSED ====================================================================== http://busybox.net/bugs/view.php?id=1520 ====================================================================== Reported By: d3z Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1520 Category: Security Reproducibility: always Severity: minor Priority: normal Status: closed Resolution: open Fixed in Version: ====================================================================== Date Submitted: 10-04-2007 00:19 PDT Last Modified: 10-05-2007 13:32 PDT ====================================================================== Summary: Incorrect usage of strncat in coreutils/stat.c Description: coreutils/stat.c contains numerous instances of 'strncat' that are incorrect. strncat(pformat, "s", buf_len); should instead read something like: strncat(pformat, "s", buf_len-strlen(pformat)-1); This could cause a buffer overflow if the buffer size computations were incorrect. ====================================================================== ---------------------------------------------------------------------- vda - 10-05-07 13:32 ---------------------------------------------------------------------- Can be replaced by plain strcat, we do have enough buffer space there. Fixed in svn, thanks. function old new delta printfs - 28 +28 strcatc - 26 +26 human_time 41 44 +3 print_it 229 219 -10 buf 30 - -30 print_statfs 420 358 -62 print_stat 1089 921 -168 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 1/3 up/down: 57/-270) Total: -213 bytes text data bss dec hex filename 771105 1029 9552 781686 bed76 busybox_old 770892 1029 9520 781441 bec81 busybox_unstripped Issue History Date Modified Username Field Change ====================================================================== 10-04-07 00:19 d3z New Issue 10-04-07 00:19 d3z Status new => assigned 10-04-07 00:19 d3z Assigned To => BusyBox 10-05-07 13:32 vda Status assigned => closed 10-05-07 13:32 vda Note Added: 0002812 ====================================================================== From vda at busybox.net Fri Oct 5 14:23:49 2007 From: vda at busybox.net (vda at busybox.net) Date: Fri, 5 Oct 2007 14:23:49 -0700 (PDT) Subject: svn commit: trunk/busybox/runit Message-ID: <20071005212349.C66DCA65E9@busybox.net> Author: vda Date: 2007-10-05 14:23:49 -0700 (Fri, 05 Oct 2007) New Revision: 20186 Log: chpst: stop using data/bss function old new delta chpst_main 1066 1089 +23 set_user 4 - -4 root 4 - -4 nicelvl 4 - -4 limitt 4 - -4 limits 196 192 -4 limitr 4 - -4 limitp 4 - -4 limito 4 - -4 limitl 4 - -4 limitf 4 - -4 limitd 4 - -4 limitc 4 - -4 limita 4 - -4 env_user 4 - -4 env_dir 4 - -4 ------------------------------------------------------------------------------ (add/remove: 0/14 grow/shrink: 1/1 up/down: 23/-60) Total: -37 bytes text data bss dec hex filename 770892 1029 9520 781441 bec81 busybox_old 770916 989 9496 781401 bec59 busybox_unstripped Modified: trunk/busybox/runit/chpst.c Changeset: Modified: trunk/busybox/runit/chpst.c =================================================================== --- trunk/busybox/runit/chpst.c 2007-10-05 20:31:23 UTC (rev 20185) +++ trunk/busybox/runit/chpst.c 2007-10-05 21:23:49 UTC (rev 20186) @@ -39,21 +39,43 @@ #define OPT_nostdout (option_mask32 & 0x10000) #define OPT_nostderr (option_mask32 & 0x20000) -static char *set_user; -static char *env_user; -static const char *env_dir; -static long limitd = -2; -static long limits = -2; -static long limitl = -2; -static long limita = -2; -static long limito = -2; -static long limitp = -2; -static long limitf = -2; -static long limitc = -2; -static long limitr = -2; -static long limitt = -2; -static int nicelvl; -static const char *root; +struct globals { + char *set_user; + char *env_user; + const char *env_dir; + const char *root; + long limitd; /* limitX are initialized to -2 */ + long limits; + long limitl; + long limita; + long limito; + long limitp; + long limitf; + long limitc; + long limitr; + long limitt; + int nicelvl; +}; +#define G (*(struct globals*)&bb_common_bufsiz1) +#define set_user (G.set_user) +#define env_user (G.env_user) +#define env_dir (G.env_dir ) +#define root (G.root ) +#define limitd (G.limitd ) +#define limits (G.limits ) +#define limitl (G.limitl ) +#define limita (G.limita ) +#define limito (G.limito ) +#define limitp (G.limitp ) +#define limitf (G.limitf ) +#define limitc (G.limitc ) +#define limitr (G.limitr ) +#define limitt (G.limitt ) +#define nicelvl (G.nicelvl ) +#define INIT_G() do { \ + long *p = &limitd; \ + do *p++ = -2; while (p <= &limitt); \ +} while (0) static void suidgid(char *user) { @@ -100,7 +122,8 @@ directory_name); break; } - if (d->d_name[0] == '.') continue; + if (d->d_name[0] == '.') + continue; fd = open(d->d_name, O_RDONLY | O_NDELAY); if (fd < 0) { if ((errno == EISDIR) && env_dir) { @@ -129,9 +152,9 @@ tail = memchr(buf, '\n', sizeof(buf)); /* skip trailing whitespace */; while (1) { - if (tail[0]==' ') tail[0] = '\0'; - if (tail[0]=='\t') tail[0] = '\0'; - if (tail[0]=='\n') tail[0] = '\0'; + if (tail[0] == ' ') tail[0] = '\0'; + if (tail[0] == '\t') tail[0] = '\0'; + if (tail[0] == '\n') tail[0] = '\0'; if (tail == buf) break; tail--; } @@ -139,7 +162,8 @@ } } closedir(dir); - if (fchdir(wdir) == -1) bb_perror_msg_and_die("fchdir"); + if (fchdir(wdir) == -1) + bb_perror_msg_and_die("fchdir"); close(wdir); } @@ -147,12 +171,14 @@ { struct rlimit r; - if (getrlimit(what, &r) == -1) bb_perror_msg_and_die("getrlimit"); + if (getrlimit(what, &r) == -1) + bb_perror_msg_and_die("getrlimit"); if ((l < 0) || (l > r.rlim_max)) r.rlim_cur = r.rlim_max; else r.rlim_cur = l; - if (setrlimit(what, &r) == -1) bb_perror_msg_and_die("setrlimit"); + if (setrlimit(what, &r) == -1) + bb_perror_msg_and_die("setrlimit"); } static void slimit(void) @@ -161,24 +187,27 @@ #ifdef RLIMIT_DATA limit(RLIMIT_DATA, limitd); #else - if (OPT_verbose) bb_error_msg("system does not support %s", - "RLIMIT_DATA"); + if (OPT_verbose) + bb_error_msg("system does not support RLIMIT_%s", + "DATA"); #endif } if (limits >= -1) { #ifdef RLIMIT_STACK limit(RLIMIT_STACK, limits); #else - if (OPT_verbose) bb_error_msg("system does not support %s", - "RLIMIT_STACK"); + if (OPT_verbose) + bb_error_msg("system does not support RLIMIT_%s", + "STACK"); #endif } if (limitl >= -1) { #ifdef RLIMIT_MEMLOCK limit(RLIMIT_MEMLOCK, limitl); #else - if (OPT_verbose) bb_error_msg("system does not support %s", - "RLIMIT_MEMLOCK"); + if (OPT_verbose) + bb_error_msg("system does not support RLIMIT_%s", + "MEMLOCK"); #endif } if (limita >= -1) { @@ -189,8 +218,8 @@ limit(RLIMIT_AS, limita); #else if (OPT_verbose) - bb_error_msg("system does not support %s", - "RLIMIT_VMEM"); + bb_error_msg("system does not support RLIMIT_%s", + "VMEM"); #endif #endif } @@ -202,8 +231,8 @@ limit(RLIMIT_OFILE, limito); #else if (OPT_verbose) - bb_error_msg("system does not support %s", - "RLIMIT_NOFILE"); + bb_error_msg("system does not support RLIMIT_%s", + "NOFILE"); #endif #endif } @@ -211,53 +240,60 @@ #ifdef RLIMIT_NPROC limit(RLIMIT_NPROC, limitp); #else - if (OPT_verbose) bb_error_msg("system does not support %s", - "RLIMIT_NPROC"); + if (OPT_verbose) + bb_error_msg("system does not support RLIMIT_%s", + "NPROC"); #endif } if (limitf >= -1) { #ifdef RLIMIT_FSIZE limit(RLIMIT_FSIZE, limitf); #else - if (OPT_verbose) bb_error_msg("system does not support %s", - "RLIMIT_FSIZE"); + if (OPT_verbose) + bb_error_msg("system does not support RLIMIT_%s", + "FSIZE"); #endif } if (limitc >= -1) { #ifdef RLIMIT_CORE limit(RLIMIT_CORE, limitc); #else - if (OPT_verbose) bb_error_msg("system does not support %s", - "RLIMIT_CORE"); + if (OPT_verbose) + bb_error_msg("system does not support RLIMIT_%s", + "CORE"); #endif } if (limitr >= -1) { #ifdef RLIMIT_RSS limit(RLIMIT_RSS, limitr); #else - if (OPT_verbose) bb_error_msg("system does not support %s", - "RLIMIT_RSS"); + if (OPT_verbose) + bb_error_msg("system does not support RLIMIT_%s", + "RSS"); #endif } if (limitt >= -1) { #ifdef RLIMIT_CPU limit(RLIMIT_CPU, limitt); #else - if (OPT_verbose) bb_error_msg("system does not support %s", - "RLIMIT_CPU"); + if (OPT_verbose) + bb_error_msg("system does not support RLIMIT_%s", + "CPU"); #endif } } /* argv[0] */ -static void setuidgid(int, char **); -static void envuidgid(int, char **); -static void envdir(int, char **); -static void softlimit(int, char **); +static void setuidgid(int, char **) ATTRIBUTE_NORETURN; +static void envuidgid(int, char **) ATTRIBUTE_NORETURN; +static void envdir(int, char **) ATTRIBUTE_NORETURN; +static void softlimit(int, char **) ATTRIBUTE_NORETURN; int chpst_main(int argc, char **argv); int chpst_main(int argc, char **argv) { + INIT_G(); + if (applet_name[3] == 'd') envdir(argc, argv); if (applet_name[1] == 'o') softlimit(argc, argv); if (applet_name[0] == 's') setuidgid(argc, argv); From vda at busybox.net Fri Oct 5 15:11:09 2007 From: vda at busybox.net (vda at busybox.net) Date: Fri, 5 Oct 2007 15:11:09 -0700 (PDT) Subject: svn commit: trunk/busybox/runit Message-ID: <20071005221109.CC2E9A67FF@busybox.net> Author: vda Date: 2007-10-05 15:11:06 -0700 (Fri, 05 Oct 2007) New Revision: 20187 Log: chpst: fix whitespace damage svlogd: fix bug (two different "line" variables); stop using data/bss function old new delta processorstop 419 432 +13 rotate 514 525 +11 buffer_pwrite 493 499 +6 sig_term_handler 68 70 +2 sig_hangup_handler 34 36 +2 sig_alarm_handler 34 36 +2 rmoldest 305 307 +2 processorstart 401 403 +2 logdir_close 188 190 +2 tmaxflag 1 - -1 rotateasap 1 - -1 repl 1 - -1 reopenasap 1 - -1 linecomplete 1 - -1 exitasap 1 - -1 wstat 4 - -4 verbose 9 5 -4 replace 4 - -4 nearest_rotate 4 - -4 linemax 4 - -4 linelen 4 - -4 line 4 - -4 fndir 4 - -4 fl_flag_0 4 - -4 fdwdir 4 - -4 dirn 4 - -4 dir 4 - -4 blocked_sigset 4 - -4 sig_child_handler 248 239 -9 logdirs_reopen 1263 1240 -23 buffer_pread 532 473 -59 svlogd_main 1466 1367 -99 ------------------------------------------------------------------------------ (add/remove: 0/18 grow/shrink: 9/5 up/down: 42/-248) Total: -206 bytes text data bss dec hex filename 770916 989 9496 781401 bec59 busybox_old 770768 980 9448 781196 beb8c busybox_unstripped Modified: trunk/busybox/runit/chpst.c trunk/busybox/runit/svlogd.c Changeset: Modified: trunk/busybox/runit/chpst.c =================================================================== --- trunk/busybox/runit/chpst.c 2007-10-05 21:23:49 UTC (rev 20186) +++ trunk/busybox/runit/chpst.c 2007-10-05 22:11:06 UTC (rev 20187) @@ -54,7 +54,7 @@ long limitc; long limitr; long limitt; - int nicelvl; + int nicelvl; }; #define G (*(struct globals*)&bb_common_bufsiz1) #define set_user (G.set_user) Modified: trunk/busybox/runit/svlogd.c =================================================================== --- trunk/busybox/runit/svlogd.c 2007-10-05 21:23:49 UTC (rev 20186) +++ trunk/busybox/runit/svlogd.c 2007-10-05 22:11:06 UTC (rev 20187) @@ -37,31 +37,7 @@ #define FMT_PTIME 30 -static unsigned verbose; -static int linemax = 1000; -////static int buflen = 1024; -static int linelen; - -static char **fndir; -static int fdwdir; -static int wstat; -static unsigned nearest_rotate; - -static char *line; -static smallint exitasap; -static smallint rotateasap; -static smallint reopenasap; -static smallint linecomplete = 1; - -static smallint tmaxflag; - -static char repl; -static const char *replace = ""; - -static sigset_t *blocked_sigset; -static int fl_flag_0; - -static struct logdir { +struct logdir { ////char *btmp; /* pattern list to match, in "aa\0bb\0\cc\0\0" form */ char *inst; @@ -81,9 +57,65 @@ char fnsave[FMT_PTIME]; char match; char matcherr; -} *dir; -static unsigned dirn; +}; + +struct globals { + struct logdir *dir; + unsigned verbose; + int linemax; + ////int buflen; + int linelen; + + int fdwdir; + char **fndir; + int wstat; + unsigned nearest_rotate; + + smallint exitasap; + smallint rotateasap; + smallint reopenasap; + smallint linecomplete; + smallint tmaxflag; + + char repl; + const char *replace; + int fl_flag_0; + unsigned dirn; + + sigset_t blocked_sigset; +}; +#define G (*(struct globals*)ptr_to_globals) +#define dir (G.dir ) +#define verbose (G.verbose ) +#define linemax (G.linemax ) +#define buflen (G.buflen ) +#define linelen (G.linelen ) +#define fndir (G.fndir ) +#define fdwdir (G.fdwdir ) +#define wstat (G.wstat ) +#define nearest_rotate (G.nearest_rotate) +#define exitasap (G.exitasap ) +#define rotateasap (G.rotateasap ) +#define reopenasap (G.reopenasap ) +#define linecomplete (G.linecomplete ) +#define tmaxflag (G.tmaxflag ) +#define repl (G.repl ) +#define replace (G.replace ) +#define blocked_sigset (G.blocked_sigset) +#define fl_flag_0 (G.fl_flag_0 ) +#define dirn (G.dirn ) +#define INIT_G() do { \ + PTR_TO_GLOBALS = xzalloc(sizeof(G)); \ + linemax = 1000; \ + /*buflen = 1024;*/ \ + linecomplete = 1; \ + replace = ""; \ +} while (0) + +#define line bb_common_bufsiz1 + + #define FATAL "fatal: " #define WARNING "warning: " #define PAUSE "pausing: " @@ -700,14 +732,14 @@ } } - sigprocmask(SIG_UNBLOCK, blocked_sigset, NULL); + sigprocmask(SIG_UNBLOCK, &blocked_sigset, NULL); i = nearest_rotate - now; if (i > 1000000) i = 1000000; if (i <= 0) i = 1; poll(&input, 1, i * 1000); - sigprocmask(SIG_BLOCK, blocked_sigset, NULL); + sigprocmask(SIG_BLOCK, &blocked_sigset, NULL); i = ndelay_read(0, s, len); if (i >= 0) @@ -814,7 +846,6 @@ int svlogd_main(int argc, char **argv); int svlogd_main(int argc, char **argv) { - sigset_t ss; char *r,*l,*b; ssize_t stdin_cnt = 0; int i; @@ -822,7 +853,7 @@ unsigned timestamp = 0; void* (*memRchr)(const void *, int, size_t) = memchr; -#define line bb_common_bufsiz1 + INIT_G(); opt_complementary = "tt:vv"; opt = getopt32(argv, "r:R:l:b:tv", @@ -866,13 +897,12 @@ * with the same stdin */ fl_flag_0 = fcntl(0, F_GETFL); - blocked_sigset = &ss; - sigemptyset(&