From 5d26df6497505e8ed486bf3e3ba65d0d6f0daa15 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 16 Jul 2010 15:31:38 +0200 Subject: tweak defconfig Signed-off-by: Denys Vlasenko --- archival/Config.src | 2 +- libbb/Config.src | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/archival/Config.src b/archival/Config.src index f64b3347b..9a84fd6c6 100644 --- a/archival/Config.src +++ b/archival/Config.src @@ -39,7 +39,7 @@ config FEATURE_SEAMLESS_Z config AR bool "ar" - default y + default n # needs to be improved to be able to replace binutils ar help ar is an archival utility program used to create, modify, and extract contents from archives. An archive is a single file holding diff --git a/libbb/Config.src b/libbb/Config.src index 80b1e0d21..09bf89246 100644 --- a/libbb/Config.src +++ b/libbb/Config.src @@ -98,7 +98,7 @@ config FEATURE_USERNAME_COMPLETION config FEATURE_EDITING_FANCY_PROMPT bool "Fancy shell prompts" - default n + default y depends on FEATURE_EDITING help Setting this option allows for prompts to use things like \w and -- cgit v1.2.3-55-g6feb From 51ca7761a3579f3c3f7e771b39019e6e248a5171 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 16 Jul 2010 17:16:40 +0200 Subject: cttyhack: move build system bits into cttyhack.c, no code changes Signed-off-by: Denys Vlasenko --- include/applets.src.h | 1 - include/usage.src.h | 11 ----------- shell/Config.src | 36 ----------------------------------- shell/Kbuild.src | 1 - shell/ash.c | 1 + shell/cttyhack.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 49 deletions(-) diff --git a/include/applets.src.h b/include/applets.src.h index 6ca0c3230..195598fee 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -104,7 +104,6 @@ IF_CPIO(APPLET(cpio, _BB_DIR_BIN, _BB_SUID_DROP)) IF_CROND(APPLET(crond, _BB_DIR_USR_SBIN, _BB_SUID_DROP)) IF_CRONTAB(APPLET(crontab, _BB_DIR_USR_BIN, _BB_SUID_REQUIRE)) IF_CRYPTPW(APPLET(cryptpw, _BB_DIR_USR_BIN, _BB_SUID_DROP)) -IF_CTTYHACK(APPLET(cttyhack, _BB_DIR_BIN, _BB_SUID_DROP)) IF_CUT(APPLET_NOEXEC(cut, cut, _BB_DIR_USR_BIN, _BB_SUID_DROP, cut)) IF_DATE(APPLET(date, _BB_DIR_BIN, _BB_SUID_DROP)) IF_DC(APPLET(dc, _BB_DIR_USR_BIN, _BB_SUID_DROP)) diff --git a/include/usage.src.h b/include/usage.src.h index 46d64c135..9b326eebb 100644 --- a/include/usage.src.h +++ b/include/usage.src.h @@ -678,17 +678,6 @@ INSERT "\n -S SALT" \ ) \ -#define cttyhack_trivial_usage \ - "PROG ARGS" -#define cttyhack_full_usage "\n\n" \ - "Give PROG a controlling tty if possible." \ - "\nExample for /etc/inittab (for busybox init):" \ - "\n ::respawn:/bin/cttyhack /bin/sh" \ - "\nGiving controlling tty to shell running with PID 1:" \ - "\n $ exec cttyhack sh" \ - "\nStarting interactive shell from boot shell script:" \ - "\n setsid cttyhack sh" \ - #define cut_trivial_usage \ "[OPTIONS] [FILE]..." #define cut_full_usage "\n\n" \ diff --git a/shell/Config.src b/shell/Config.src index 6389d943a..f6f0b6c94 100644 --- a/shell/Config.src +++ b/shell/Config.src @@ -158,40 +158,4 @@ config FEATURE_SH_NOFORK This feature is relatively new. Use with care. -config CTTYHACK - bool "cttyhack" - default y - help - One common problem reported on the mailing list is "can't access tty; - job control turned off" error message which typically appears when - one tries to use shell with stdin/stdout opened to /dev/console. - This device is special - it cannot be a controlling tty. - - Proper solution is to use correct device instead of /dev/console. - - cttyhack provides "quick and dirty" solution to this problem. - It analyzes stdin with various ioctls, trying to determine whether - it is a /dev/ttyN or /dev/ttySN (virtual terminal or serial line). - If it detects one, it closes stdin/out/err and reopens that device. - Then it executes given program. Opening the device will make - that device a controlling tty. This may require cttyhack - to be a session leader. - - Example for /etc/inittab (for busybox init): - - ::respawn:/bin/cttyhack /bin/sh - - Starting an interactive shell from boot shell script: - - setsid cttyhack sh - - Giving controlling tty to shell running with PID 1: - - # exec cttyhack sh - - Without cttyhack, you need to know exact tty name, - and do something like this: - - # exec setsid sh -c 'exec sh /dev/tty1 2>&1' - endmenu diff --git a/shell/Kbuild.src b/shell/Kbuild.src index bce99240f..a669bdfb0 100644 --- a/shell/Kbuild.src +++ b/shell/Kbuild.src @@ -8,5 +8,4 @@ lib-y:= INSERT -lib-$(CONFIG_CTTYHACK) += cttyhack.o lib-$(CONFIG_SH_MATH_SUPPORT) += math.o diff --git a/shell/ash.c b/shell/ash.c index 9b33e78ec..fd119fa51 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -179,6 +179,7 @@ //config: "PS#" may contain volatile content, such as backquote commands. //config: This option recreates the prompt string from the environment //config: variable each time it is displayed. +//config: //usage:#define ash_trivial_usage NOUSAGE_STR //usage:#define ash_full_usage "" diff --git a/shell/cttyhack.c b/shell/cttyhack.c index 67736ad62..7af13fdfd 100644 --- a/shell/cttyhack.c +++ b/shell/cttyhack.c @@ -6,6 +6,58 @@ */ #include "libbb.h" +//applet:IF_CTTYHACK(APPLET(cttyhack, _BB_DIR_BIN, _BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_CTTYHACK) += cttyhack.o + +//config:config CTTYHACK +//config: bool "cttyhack" +//config: default y +//config: help +//config: One common problem reported on the mailing list is "can't access tty; +//config: job control turned off" error message which typically appears when +//config: one tries to use shell with stdin/stdout opened to /dev/console. +//config: This device is special - it cannot be a controlling tty. +//config: +//config: Proper solution is to use correct device instead of /dev/console. +//config: +//config: cttyhack provides "quick and dirty" solution to this problem. +//config: It analyzes stdin with various ioctls, trying to determine whether +//config: it is a /dev/ttyN or /dev/ttySN (virtual terminal or serial line). +//config: If it detects one, it closes stdin/out/err and reopens that device. +//config: Then it executes given program. Opening the device will make +//config: that device a controlling tty. This may require cttyhack +//config: to be a session leader. +//config: +//config: Example for /etc/inittab (for busybox init): +//config: +//config: ::respawn:/bin/cttyhack /bin/sh +//config: +//config: Starting an interactive shell from boot shell script: +//config: +//config: setsid cttyhack sh +//config: +//config: Giving controlling tty to shell running with PID 1: +//config: +//config: # exec cttyhack sh +//config: +//config: Without cttyhack, you need to know exact tty name, +//config: and do something like this: +//config: +//config: # exec setsid sh -c 'exec sh /dev/tty1 2>&1' +//config: + +//usage:#define cttyhack_trivial_usage +//usage: "PROG ARGS" +//usage:#define cttyhack_full_usage "\n\n" +//usage: "Give PROG a controlling tty if possible." +//usage: "\nExample for /etc/inittab (for busybox init):" +//usage: "\n ::respawn:/bin/cttyhack /bin/sh" +//usage: "\nGiving controlling tty to shell running with PID 1:" +//usage: "\n $ exec cttyhack sh" +//usage: "\nStarting interactive shell from boot shell script:" +//usage: "\n setsid cttyhack sh" + /* From */ struct vt_stat { unsigned short v_active; /* active vt */ -- cgit v1.2.3-55-g6feb From 6adf2aad38cf2f5a056f9014955807607bcb41b2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 16 Jul 2010 19:26:38 +0200 Subject: hush: move msh/lash config into hush.c, no code changes Signed-off-by: Denys Vlasenko --- shell/Config.src | 23 ----------------------- shell/hush.c | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/shell/Config.src b/shell/Config.src index f6f0b6c94..c9c2439e7 100644 --- a/shell/Config.src +++ b/shell/Config.src @@ -62,29 +62,6 @@ config FEATURE_BASH_IS_NONE endchoice -config LASH - bool "lash (deprecated: aliased to hush)" - default n - select HUSH - help - lash is deprecated and will be removed, please migrate to hush. - -config MSH - bool "msh (deprecated: please use hush)" - default n - select HUSH - help - msh is deprecated and will be removed, please migrate to hush. - If there is a feature msh has but hush does not, please let us know. - -# The minix shell (adds just 30k) is quite complete and handles things -# like for/do/done, case/esac and all the things you expect a Bourne -# shell to do. It is not always pedantically correct about Bourne -# shell grammar (try running the shell testscript "tests/sh.testcases" -# on it and compare vs bash) but for most things it works quite well. -# It uses only vfork, so it can be used on uClinux systems. - - config SH_MATH_SUPPORT bool "POSIX math support" default y diff --git a/shell/hush.c b/shell/hush.c index 56a3f4b14..9208ec497 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -224,6 +224,20 @@ //config: This instructs hush to print commands before execution. //config: Adds ~300 bytes. //config: +//config:config LASH +//config: bool "lash (deprecated: aliased to hush)" +//config: default n +//config: select HUSH +//config: help +//config: lash is deprecated and will be removed, please migrate to hush. +//config: +//config:config MSH +//config: bool "msh (deprecated: aliased to hush)" +//config: default n +//config: select HUSH +//config: help +//config: msh is deprecated and will be removed, please migrate to hush. +//config: //usage:#define hush_trivial_usage NOUSAGE_STR //usage:#define hush_full_usage "" -- cgit v1.2.3-55-g6feb From d1516c4d628dbded9e1abefaacc1535aaecef418 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 17 Jul 2010 22:43:42 +0200 Subject: dos2unix: fix the case w/o parameters Signed-off-by: Denys Vlasenko --- coreutils/dos2unix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c index 1911f5319..e06ecc4e0 100644 --- a/coreutils/dos2unix.c +++ b/coreutils/dos2unix.c @@ -92,7 +92,7 @@ int dos2unix_main(int argc UNUSED_PARAM, char **argv) do { /* might be convert(NULL) if there is no filename given */ convert(*argv, conv_type); - } while (*++argv); + } while (*argv && *++argv); return 0; } -- cgit v1.2.3-55-g6feb From 4cab7f3e63ff850bc478f96d0589a01dec878a00 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 18 Jul 2010 17:41:17 +0200 Subject: depmod: generate "new-style" modules.dep with relative paths. function old new delta parse_module 384 379 -5 depmod_main 590 559 -31 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-36) Total: -36 bytes Signed-off-by: Denys Vlasenko --- modutils/depmod.c | 76 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/modutils/depmod.c b/modutils/depmod.c index c734f142b..694f9ea5a 100644 --- a/modutils/depmod.c +++ b/modutils/depmod.c @@ -28,16 +28,6 @@ typedef struct module_info { struct module_info *dnext, *dprev; } module_info; -enum { - ARG_a = (1<<0), /* All modules, ignore mods in argv */ - ARG_A = (1<<1), /* Only emit .ko that are newer than modules.dep file */ - ARG_b = (1<<2), /* base directory when modules are in staging area */ - ARG_e = (1<<3), /* with -F, print unresolved symbols */ - ARG_F = (1<<4), /* System.map that contains the symbols */ - ARG_n = (1<<5), /* dry-run, print to stdout only */ - ARG_r = (1<<6) /* Compat dummy. Linux Makefile uses it */ -}; - static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARAM, void *data, int depth UNUSED_PARAM) { @@ -58,7 +48,7 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA *first = info; info->dnext = info->dprev = info; - info->name = xasprintf("/%s", fname); + info->name = xstrdup(fname + 2); /* skip "./" */ info->modname = xstrdup(filename2modname(fname, modname)); for (ptr = image; ptr < image + len - 10; ptr++) { if (strncmp(ptr, "depends=", 8) == 0) { @@ -134,10 +124,44 @@ static void xfreopen_write(const char *file, FILE *f) bb_perror_msg_and_die("can't open '%s'", file); } +/* Usage: + * [-aAenv] [-C FILE or DIR] [-b BASE] [-F System.map] [VERSION] [MODFILES]... + * -a --all + * Probe all modules. Default if no MODFILES. + * -A --quick + * Check modules.dep's mtime against module files' mtimes. + * -b --basedir BASE + * Use $BASE/lib/modules/VERSION + * -C --config FILE or DIR + * Path to /etc/depmod.conf or /etc/depmod.d/ + * -e --errsyms + * When combined with the -F option, this reports any symbols which + * which are not supplied by other modules or kernel. + * -F --filesyms System.map + * -n --dry-run + * Print modules.dep etc to standard output + * -v --verbose + * Print to stdout all the symbols each module depends on + * and the module's file name which provides that symbol. + * -r No-op + * + * So far we only support: [-rn] [-b BASE] [VERSION] [MODFILES]... + * -aAeF are accepted but ignored. -vC are not accepted. + */ +enum { + //OPT_a = (1 << 0), /* All modules, ignore mods in argv */ + //OPT_A = (1 << 1), /* Only emit .ko that are newer than modules.dep file */ + OPT_b = (1 << 2), /* base directory when modules are in staging area */ + //OPT_e = (1 << 3), /* with -F, print unresolved symbols */ + //OPT_F = (1 << 4), /* System.map that contains the symbols */ + OPT_n = (1 << 5), /* dry-run, print to stdout only */ + OPT_r = (1 << 6) /* Compat dummy. Linux Makefile uses it */ +}; + int depmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int depmod_main(int argc UNUSED_PARAM, char **argv) { - module_info *modules = NULL, *m, *dep; + module_info *modules, *m, *dep; const char *moddir_base = "/"; char *moddir, *version; struct utsname uts; @@ -152,36 +176,30 @@ int depmod_main(int argc UNUSED_PARAM, char **argv) /* If a version is provided, then that kernel version's module directory * is used, rather than the current kernel version (as returned by * "uname -r"). */ - if (*argv && sscanf(*argv, "%d.%d.%d", &tmp, &tmp, &tmp) == 3) { + if (*argv && sscanf(*argv, "%u.%u.%u", &tmp, &tmp, &tmp) == 3) { version = *argv++; } else { uname(&uts); version = uts.release; } moddir = concat_path_file(&CONFIG_DEFAULT_MODULES_DIR[1], version); + xchdir(moddir); + if (ENABLE_FEATURE_CLEAN_UP) + free(moddir); /* Scan modules */ + modules = NULL; if (*argv) { - char *modfile; - struct stat sb; do { - modfile = concat_path_file(moddir, *argv); - xstat(modfile, &sb); - parse_module(modfile, &sb, &modules, 0); - free(modfile); - } while (*(++argv)); + parse_module(*argv, /*sb (unused):*/ NULL, &modules, 0); + } while (*++argv); } else { - recursive_action(moddir, ACTION_RECURSE, + recursive_action(".", ACTION_RECURSE, parse_module, NULL, &modules, 0); } - /* Prepare for writing out the dep files */ - xchdir(moddir); - if (ENABLE_FEATURE_CLEAN_UP) - free(moddir); - /* Generate dependency and alias files */ - if (!(option_mask32 & ARG_n)) + if (!(option_mask32 & OPT_n)) xfreopen_write(CONFIG_DEFAULT_DEPMOD_FILE, stdout); for (m = modules; m != NULL; m = m->next) { printf("%s:", m->name); @@ -200,7 +218,7 @@ int depmod_main(int argc UNUSED_PARAM, char **argv) } #if ENABLE_FEATURE_MODUTILS_ALIAS - if (!(option_mask32 & ARG_n)) + if (!(option_mask32 & OPT_n)) xfreopen_write("modules.alias", stdout); for (m = modules; m != NULL; m = m->next) { const char *fname = bb_basename(m->name); @@ -218,7 +236,7 @@ int depmod_main(int argc UNUSED_PARAM, char **argv) } #endif #if ENABLE_FEATURE_MODUTILS_SYMBOLS - if (!(option_mask32 & ARG_n)) + if (!(option_mask32 & OPT_n)) xfreopen_write("modules.symbols", stdout); for (m = modules; m != NULL; m = m->next) { const char *fname = bb_basename(m->name); -- cgit v1.2.3-55-g6feb From b9e35dc15dbf8aa22dbc260d121ad8f7a34017de Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 18 Jul 2010 22:21:24 +0200 Subject: lineedit: cosmetics, no code changes Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 8a2ea7974..3905b8cc4 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -53,19 +53,15 @@ #if ENABLE_FEATURE_EDITING -#define ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR \ +#define ENABLE_USERNAME_OR_HOMEDIR \ (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) -#define IF_FEATURE_GETUSERNAME_AND_HOMEDIR(...) -#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR -#undef IF_FEATURE_GETUSERNAME_AND_HOMEDIR -#define IF_FEATURE_GETUSERNAME_AND_HOMEDIR(...) __VA_ARGS__ +#define IF_USERNAME_OR_HOMEDIR(...) +#if ENABLE_USERNAME_OR_HOMEDIR +# undef IF_USERNAME_OR_HOMEDIR +# define IF_USERNAME_OR_HOMEDIR(...) __VA_ARGS__ #endif -#define SEQ_CLEAR_TILL_END_OF_SCREEN "\033[J" -//#define SEQ_CLEAR_TILL_END_OF_LINE "\033[K" - - #undef CHAR_T #if ENABLE_UNICODE_SUPPORT # define BB_NUL ((wchar_t)0) @@ -90,14 +86,16 @@ static bool BB_ispunct(CHAR_T c) { return ((unsigned)c < 256 && ispunct(c)); } # define BB_isalnum(c) isalnum(c) # define BB_ispunct(c) ispunct(c) #endif +#if ENABLE_UNICODE_PRESERVE_BROKEN +# define unicode_mark_raw_byte(wc) ((wc) | 0x20000000) +# define unicode_is_raw_byte(wc) ((wc) & 0x20000000) +#else +# define unicode_is_raw_byte(wc) 0 +#endif -# if ENABLE_UNICODE_PRESERVE_BROKEN -# define unicode_mark_raw_byte(wc) ((wc) | 0x20000000) -# define unicode_is_raw_byte(wc) ((wc) & 0x20000000) -# else -# define unicode_is_raw_byte(wc) 0 -# endif +#define SEQ_CLEAR_TILL_END_OF_SCREEN "\033[J" +//#define SEQ_CLEAR_TILL_END_OF_LINE "\033[K" enum { @@ -107,7 +105,7 @@ enum { : 0x7ff0 }; -#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR +#if ENABLE_USERNAME_OR_HOMEDIR static const char null_str[] ALIGN1 = ""; #endif @@ -134,7 +132,7 @@ struct lineedit_statics { int num_ok_lines; /* = 1; */ #endif -#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR +#if ENABLE_USERNAME_OR_HOMEDIR char *user_buf; char *home_pwd_buf; /* = (char*)null_str; */ #endif @@ -145,7 +143,7 @@ struct lineedit_statics { #endif #if ENABLE_FEATURE_EDITING_VI -#define DELBUFSIZ 128 +# define DELBUFSIZ 128 CHAR_T *delptr; smallint newdelflag; /* whether delbuf should be reused yet */ CHAR_T delbuf[DELBUFSIZ]; /* a place to store deleted characters */ @@ -191,7 +189,7 @@ extern struct lineedit_statics *const lineedit_ptr_to_statics; barrier(); \ cmdedit_termw = 80; \ IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines = 1;) \ - IF_FEATURE_GETUSERNAME_AND_HOMEDIR(home_pwd_buf = (char*)null_str;) \ + IF_USERNAME_OR_HOMEDIR(home_pwd_buf = (char*)null_str;) \ } while (0) static void deinit_S(void) { @@ -200,7 +198,7 @@ static void deinit_S(void) * (otherwise it points to verbatim prompt (NOT malloced) */ free((char*)cmdedit_prompt); #endif -#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR +#if ENABLE_USERNAME_OR_HOMEDIR free(user_buf); if (home_pwd_buf != null_str) free(home_pwd_buf); @@ -1669,7 +1667,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) c = *prmt_ptr++; switch (c) { -# if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR +# if ENABLE_USERNAME_OR_HOMEDIR case 'u': pbuf = user_buf ? user_buf : (char*)""; break; @@ -1681,7 +1679,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) case '$': c = (geteuid() == 0 ? '#' : '$'); break; -# if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR +# if ENABLE_USERNAME_OR_HOMEDIR case 'w': /* /home/user[/something] -> ~[/something] */ pbuf = cwd_buf; @@ -1957,7 +1955,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li /* Now initialize things */ previous_SIGWINCH_handler = signal(SIGWINCH, win_changed); win_changed(0); /* do initial resizing */ -#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR +#if ENABLE_USERNAME_OR_HOMEDIR { struct passwd *entry; @@ -2379,7 +2377,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li } #endif -/* Stop bug catching using "command_must_not_be_used" trick */ +/* End of bug-catching "command_must_not_be_used" trick */ #undef command #if ENABLE_UNICODE_SUPPORT @@ -2413,7 +2411,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li return len; /* can't return command_len, DEINIT_S() destroys it */ } -#else +#else /* !FEATURE_EDITING */ #undef read_line_input int FAST_FUNC read_line_input(const char* prompt, char* command, int maxsize) @@ -2424,7 +2422,7 @@ int FAST_FUNC read_line_input(const char* prompt, char* command, int maxsize) return strlen(command); } -#endif /* FEATURE_EDITING */ +#endif /* !FEATURE_EDITING */ /* -- cgit v1.2.3-55-g6feb From 55241fa2e0a623c6f3f3f9c6e430d72bc10858bc Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 18 Jul 2010 22:53:06 +0200 Subject: lineedit: limit ASK_TERMINAL to the case when we can't find out the width Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 3905b8cc4..a62ab6d29 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -149,6 +149,7 @@ struct lineedit_statics { CHAR_T delbuf[DELBUFSIZ]; /* a place to store deleted characters */ #endif #if ENABLE_FEATURE_EDITING_ASK_TERMINAL + smallint unknown_width; smallint sent_ESC_br6n; #endif @@ -1610,14 +1611,16 @@ static void ask_terminal(void) * poll([{fd=0, events=POLLIN}], 1, 4294967295) = 1 ([{fd=0, revents=POLLIN}]) * read(0, "\n", 1) = 1 <-- oh crap, user's input got in first */ - struct pollfd pfd; - - pfd.fd = STDIN_FILENO; - pfd.events = POLLIN; - if (safe_poll(&pfd, 1, 0) == 0) { - S.sent_ESC_br6n = 1; - fputs("\033" "[6n", stdout); - fflush_all(); /* make terminal see it ASAP! */ + if (S.unknown_width) { /* only if window size is not known */ + struct pollfd pfd; + + pfd.fd = STDIN_FILENO; + pfd.events = POLLIN; + if (safe_poll(&pfd, 1, 0) == 0) { + S.sent_ESC_br6n = 1; + fputs("\033" "[6n", stdout); + fflush_all(); /* make terminal see it ASAP! */ + } } } #else @@ -1763,11 +1766,13 @@ static void cmdedit_setwidth(unsigned w, int redraw_flg) static void win_changed(int nsig) { + int sv_errno = errno; unsigned width; - get_terminal_width_height(0, &width, NULL); + IF_FEATURE_EDITING_ASK_TERMINAL(S.unknown_width =) get_terminal_width_height(0, &width, NULL); cmdedit_setwidth(width, nsig /* - just a yes/no flag */); if (nsig == SIGWINCH) signal(SIGWINCH, win_changed); /* rearm ourself */ + errno = sv_errno; } static int lineedit_read_key(char *read_key_buffer) -- cgit v1.2.3-55-g6feb From fb4cb1c41697b4009608527a343dbd8265ad7993 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 18 Jul 2010 23:02:36 +0200 Subject: tweak defconfig Signed-off-by: Denys Vlasenko --- e2fsprogs/Config.src | 2 +- networking/nc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2fsprogs/Config.src b/e2fsprogs/Config.src index f362c6b0a..62bc810f8 100644 --- a/e2fsprogs/Config.src +++ b/e2fsprogs/Config.src @@ -45,7 +45,7 @@ config LSATTR config TUNE2FS bool "tune2fs" - default y + default n # off: it is too limited compared to upstream version help tune2fs allows the system administrator to adjust various tunable filesystem parameters on Linux ext2/ext3 filesystems. diff --git a/networking/nc.c b/networking/nc.c index 0dacaf117..c77137480 100644 --- a/networking/nc.c +++ b/networking/nc.c @@ -34,7 +34,7 @@ //config: //config:config NC_110_COMPAT //config: bool "Netcat 1.10 compatibility (+2.5k)" -//config: default y +//config: default n # off specially for Rob //config: depends on NC //config: help //config: This option makes nc closely follow original nc-1.10. -- cgit v1.2.3-55-g6feb From daf286cda559dd1eff0c9db46a4562c0255e76f1 Mon Sep 17 00:00:00 2001 From: Alexander Shishkin Date: Thu, 15 Jul 2010 17:39:24 +0300 Subject: Fix out-of-tree build's recursion While doing O=build build I've noticed that it was getting gradually slower with each invocation. The reason turned out to be that the build directory was inside the source tree and got recreated inside itself with all its subdirectories. This patch changes the behavior so that only the directories with Kbuild.src or Config.src in them are created in the out-of-tree build directory. A quick rebuild from scratch revealed no problems with this. Signed-off-by: Alexander Shishkin Signed-off-by: Denys Vlasenko --- scripts/gen_build_files.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/gen_build_files.sh b/scripts/gen_build_files.sh index 968158758..18c172d5a 100755 --- a/scripts/gen_build_files.sh +++ b/scripts/gen_build_files.sh @@ -53,8 +53,8 @@ fi src="$srctree/$d/Kbuild.src" dst="$d/Kbuild" - mkdir -p -- "$d" 2>/dev/null if test -f "$src"; then + mkdir -p -- "$d" 2>/dev/null #echo " CHK $dst" s=`sed -n 's@^//kbuild:@@p' -- "$srctree/$d"/*.c` @@ -73,8 +73,8 @@ fi src="$srctree/$d/Config.src" dst="$d/Config.in" - mkdir -p -- "$d" 2>/dev/null if test -f "$src"; then + mkdir -p -- "$d" 2>/dev/null #echo " CHK $dst" s=`sed -n 's@^//config:@@p' -- "$srctree/$d"/*.c` -- cgit v1.2.3-55-g6feb From b175462422f02a159a14dc5561d8bef6f84b2b66 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Thu, 27 May 2010 15:32:19 +0200 Subject: readlink: use xmalloc_realpath() Using realpath() directly with a non-NULL output buffer is unsafe because its behavior is unspecified on systems which don't have PATH_MAX (ie. Hurd) I beleive this also fixes a small bug whereby 'buf' would not be freed on 'readlink -v' with ENABLE_FEATURE_CLEANUP. Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- coreutils/readlink.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/coreutils/readlink.c b/coreutils/readlink.c index 20df38b96..2ed5e2cac 100644 --- a/coreutils/readlink.c +++ b/coreutils/readlink.c @@ -36,7 +36,6 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) { char *buf; char *fname; - char pathbuf[PATH_MAX]; IF_FEATURE_READLINK_FOLLOW( unsigned opt; @@ -56,7 +55,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) logmode = LOGMODE_NONE; if (opt & 1) { /* -f */ - buf = realpath(fname, pathbuf); + buf = xmalloc_realpath(fname); } else { buf = xmalloc_readlink_or_warn(fname); } @@ -65,7 +64,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) return EXIT_FAILURE; printf((opt & 2) ? "%s" : "%s\n", buf); - if (ENABLE_FEATURE_CLEAN_UP && !opt) + if (ENABLE_FEATURE_CLEAN_UP) free(buf); fflush_stdout_and_exit(EXIT_SUCCESS); -- cgit v1.2.3-55-g6feb From 1d7266d3b59be361763dab61f680103bbb70f3e9 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Mon, 19 Jul 2010 00:44:56 +0200 Subject: mark Linux-specific configuration options PLATFORM_LINUX is used as a dependency for applets or features which require Linux-specific interfaces. Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- Config.in | 12 ++++++++++++ console-tools/Config.src | 13 +++++++++++++ coreutils/Config.src | 2 ++ coreutils/date.c | 2 +- e2fsprogs/Config.src | 1 + init/Config.src | 2 ++ init/bootchartd.c | 1 + libbb/Config.src | 1 + loginutils/Config.src | 3 +++ miscutils/Config.src | 19 ++++++++++++++++++- miscutils/conspy.c | 1 + miscutils/ubi_attach_detach.c | 2 ++ modutils/Config.src | 1 + networking/Config.src | 23 ++++++++++++++++++++++- networking/udhcp/Config.src | 2 ++ procps/Config.src | 4 +++- shell/cttyhack.c | 1 + sysklogd/Config.src | 1 + util-linux/Config.src | 27 +++++++++++++++++++++++++++ 19 files changed, 114 insertions(+), 4 deletions(-) diff --git a/Config.in b/Config.in index eebc9774d..35f43b3cd 100644 --- a/Config.in +++ b/Config.in @@ -47,6 +47,17 @@ config USE_PORTABLE_CODE compiler other than gcc. If you do use gcc, this option may needlessly increase code size. +config PLATFORM_LINUX + bool "Enable Linux-specific applets and features" + default y + help + For the most part, busybox requires only POSIX compatibility + from the target system, but some applets and features use + Linux-specific interfaces. + + Answering 'N' here will disable such applets and hide the + corresponding configuration options. + choice prompt "Buffer allocation policy" default FEATURE_BUFFERS_USE_MALLOC @@ -353,6 +364,7 @@ config FEATURE_SUID_CONFIG_QUIET config SELINUX bool "Support NSA Security Enhanced Linux" default n + depends on PLATFORM_LINUX help Enable support for SELinux in applets ls, ps, and id. Also provide the option of compiling in SELinux applets. diff --git a/console-tools/Config.src b/console-tools/Config.src index 6e3191ada..cdb26800e 100644 --- a/console-tools/Config.src +++ b/console-tools/Config.src @@ -10,6 +10,7 @@ INSERT config CHVT bool "chvt" default y + depends on PLATFORM_LINUX help This program is used to change to another terminal. Example: chvt 4 (change to terminal /dev/tty4) @@ -17,6 +18,7 @@ config CHVT config FGCONSOLE bool "fgconsole" default y + depends on PLATFORM_LINUX help This program prints active (foreground) console number. @@ -29,12 +31,14 @@ config CLEAR config DEALLOCVT bool "deallocvt" default y + depends on PLATFORM_LINUX help This program deallocates unused virtual consoles. config DUMPKMAP bool "dumpkmap" default y + depends on PLATFORM_LINUX help This program dumps the kernel's keyboard translation table to stdout, in binary format. You can then use loadkmap to load it. @@ -42,18 +46,21 @@ config DUMPKMAP config KBD_MODE bool "kbd_mode" default y + depends on PLATFORM_LINUX help This program reports and sets keyboard mode. config LOADFONT bool "loadfont" default y + depends on PLATFORM_LINUX help This program loads a console font from standard input. config LOADKMAP bool "loadkmap" default y + depends on PLATFORM_LINUX help This program loads a keyboard translation table from standard input. @@ -61,6 +68,7 @@ config LOADKMAP config OPENVT bool "openvt" default y + depends on PLATFORM_LINUX help This program is used to start a command on an unused virtual terminal. @@ -92,6 +100,7 @@ config FEATURE_RESIZE_PRINT config SETCONSOLE bool "setconsole" default y + depends on PLATFORM_LINUX help This program redirects the system console to another device, like the current tty while logged in via telnet. @@ -106,6 +115,7 @@ config FEATURE_SETCONSOLE_LONG_OPTIONS config SETFONT bool "setfont" default y + depends on PLATFORM_LINUX help Allows to load console screen map. Useful for i18n. @@ -127,6 +137,7 @@ config DEFAULT_SETFONT_DIR config SETKEYCODES bool "setkeycodes" default y + depends on PLATFORM_LINUX help This program loads entries into the kernel's scancode-to-keycode map, allowing unusual keyboards to generate usable keycodes. @@ -134,12 +145,14 @@ config SETKEYCODES config SETLOGCONS bool "setlogcons" default y + depends on PLATFORM_LINUX help This program redirects the output console of kernel messages. config SHOWKEY bool "showkey" default y + depends on PLATFORM_LINUX help Shows keys pressed. diff --git a/coreutils/Config.src b/coreutils/Config.src index d4c9e0541..780b73fda 100644 --- a/coreutils/Config.src +++ b/coreutils/Config.src @@ -591,6 +591,7 @@ config FEATURE_SPLIT_FANCY config STAT bool "stat" default y + depends on PLATFORM_LINUX # statfs() help display file or filesystem status. @@ -606,6 +607,7 @@ config FEATURE_STAT_FORMAT config STTY bool "stty" default y + depends on PLATFORM_LINUX help stty is used to change and print terminal line settings. diff --git a/coreutils/date.c b/coreutils/date.c index c737f09f3..cb41724af 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -72,7 +72,7 @@ //config:config FEATURE_DATE_NANO //config: bool "Support %[num]N nanosecond format specifier" //config: default n -//config: depends on DATE +//config: depends on DATE && PLATFORM_LINUX # syscall(__NR_clock_gettime) //config: help //config: Support %[num]N format specifier. Adds ~250 bytes of code. //config: diff --git a/e2fsprogs/Config.src b/e2fsprogs/Config.src index 62bc810f8..6043e9b57 100644 --- a/e2fsprogs/Config.src +++ b/e2fsprogs/Config.src @@ -33,6 +33,7 @@ config FSCK config LSATTR bool "lsattr" default y + depends on PLATFORM_LINUX help lsattr lists the file attributes on a second extended file system. diff --git a/init/Config.src b/init/Config.src index 590e29890..a5e76be6a 100644 --- a/init/Config.src +++ b/init/Config.src @@ -10,6 +10,7 @@ INSERT config INIT bool "init" default y + depends on PLATFORM_LINUX select FEATURE_SYSLOG help init is the first program run when the system boots. @@ -92,6 +93,7 @@ config FEATURE_INITRD config HALT bool "poweroff, halt, and reboot" default y + depends on PLATFORM_LINUX help Stop all processes and either halt, reboot, or power off the system. diff --git a/init/bootchartd.c b/init/bootchartd.c index dae2fe6e9..a1c01641b 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c @@ -6,6 +6,7 @@ //config:config BOOTCHARTD //config: bool "bootchartd" //config: default y +//config: depends on PLATFORM_LINUX //config: help //config: bootchartd is commonly used to profile the boot process //config: for the purpose of speeding it up. In this case, it is started diff --git a/libbb/Config.src b/libbb/Config.src index 09bf89246..9b01757c6 100644 --- a/libbb/Config.src +++ b/libbb/Config.src @@ -153,6 +153,7 @@ config FEATURE_COPYBUF_KB config MONOTONIC_SYSCALL bool "Use clock_gettime(CLOCK_MONOTONIC) syscall" default n + depends on PLATFORM_LINUX help Use clock_gettime(CLOCK_MONOTONIC) syscall for measuring time intervals (time, ping, traceroute etc need this). diff --git a/loginutils/Config.src b/loginutils/Config.src index 5d497c4dc..425d041b9 100644 --- a/loginutils/Config.src +++ b/loginutils/Config.src @@ -179,6 +179,7 @@ config DELUSER config GETTY bool "getty" default y + depends on PLATFORM_LINUX select FEATURE_SYSLOG help getty lets you log in on a tty, it is normally invoked by init. @@ -186,6 +187,7 @@ config GETTY config LOGIN bool "login" default y + depends on PLATFORM_LINUX select FEATURE_SUID select FEATURE_SYSLOG help @@ -295,6 +297,7 @@ config SULOGIN config VLOCK bool "vlock" default y + depends on PLATFORM_LINUX select FEATURE_SUID help Build the "vlock" applet which allows you to lock (virtual) terminals. diff --git a/miscutils/Config.src b/miscutils/Config.src index 2f7c50271..e89e231e6 100644 --- a/miscutils/Config.src +++ b/miscutils/Config.src @@ -10,6 +10,7 @@ INSERT config ADJTIMEX bool "adjtimex" default y + depends on PLATFORM_LINUX help Adjtimex reads and optionally sets adjustment parameters for the Linux clock adjustment algorithm. @@ -24,6 +25,7 @@ config BBCONFIG config BEEP bool "beep" default y + depends on PLATFORM_LINUX help The beep applets beeps in a given freq/Hz. @@ -180,6 +182,7 @@ config FEATURE_DC_LIBM config DEVFSD bool "devfsd (obsolete)" default n + depends on PLATFORM_LINUX select FEATURE_SYSLOG help This is deprecated and should NOT be used anymore. @@ -223,6 +226,7 @@ config DEVFSD_VERBOSE config FEATURE_DEVFS bool "Use devfs names for all devices (obsolete)" default n + depends on PLATFORM_LINUX help This is obsolete and should NOT be used anymore. Use linux >= 2.6 (optionally with hotplug) and mdev instead! @@ -242,6 +246,7 @@ config DEVMEM config EJECT bool "eject" default y + depends on PLATFORM_LINUX help Used to eject cdroms. (defaults to /dev/cdrom) @@ -256,6 +261,7 @@ config FEATURE_EJECT_SCSI config FBSPLASH bool "fbsplash" default y + depends on PLATFORM_LINUX help Shows splash image and progress bar on framebuffer device. Can be used during boot phase of an embedded device. ~2kb. @@ -305,6 +311,7 @@ config FLASH_ERASEALL config IONICE bool "ionice" default y + depends on PLATFORM_LINUX help Set/set program io scheduling class and priority Requires kernel >= 2.6.13 @@ -344,6 +351,11 @@ endchoice config LESS bool "less" default y + depends on PLATFORM_LINUX + depends on PLATFORM_LINUX + depends on PLATFORM_LINUX + depends on PLATFORM_LINUX + depends on PLATFORM_LINUX help 'less' is a pager, meaning that it displays text files. It possesses a wide array of features, and is an improvement over 'more'. @@ -410,6 +422,7 @@ config FEATURE_LESS_LINENUMS config HDPARM bool "hdparm" default y + depends on PLATFORM_LINUX help Get/Set hard drive parameters. Primarily intended for ATA drives. Adds about 13k (or around 30k if you enable the @@ -526,6 +539,7 @@ config MT config RAIDAUTORUN bool "raidautorun" default y + depends on PLATFORM_LINUX help raidautorun tells the kernel md driver to search and start RAID arrays. @@ -533,7 +547,7 @@ config RAIDAUTORUN config READAHEAD bool "readahead" default y - depends on LFS + depends on LFS && PLATFORM_LINUX help Preload the files listed on the command line into RAM cache so that subsequent reads on these files will not block on disk I/O. @@ -550,6 +564,7 @@ config READAHEAD config RFKILL bool "rfkill" default n # doesn't build on Ubuntu 9.04 + depends on PLATFORM_LINUX help Enable/disable wireless devices. @@ -570,6 +585,7 @@ config RUNLEVEL config RX bool "rx" default y + depends on PLATFORM_LINUX help Receive files using the Xmodem protocol. @@ -641,6 +657,7 @@ config WALL config WATCHDOG bool "watchdog" default y + depends on PLATFORM_LINUX help The watchdog utility is used with hardware or software watchdog device drivers. It opens the specified watchdog device special file diff --git a/miscutils/conspy.c b/miscutils/conspy.c index 509a0f271..a173d8efd 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c @@ -17,6 +17,7 @@ //config:config CONSPY //config: bool "conspy" //config: default n +//config: depends on PLATFORM_LINUX //config: help //config: A text-mode VNC like program for Linux virtual terminals. //config: example: conspy NUM shared access to console num diff --git a/miscutils/ubi_attach_detach.c b/miscutils/ubi_attach_detach.c index 7b92a8afc..0d63a10d5 100644 --- a/miscutils/ubi_attach_detach.c +++ b/miscutils/ubi_attach_detach.c @@ -12,12 +12,14 @@ //config:config UBIATTACH //config: bool "ubiattach" //config: default n +//config: depends on PLATFORM_LINUX //config: help //config: Attach MTD device to an UBI device. //config: //config:config UBIDETACH //config: bool "ubidetach" //config: default n +//config: depends on PLATFORM_LINUX //config: help //config: Detach MTD device from an UBI device. diff --git a/modutils/Config.src b/modutils/Config.src index a7dcb3ab3..4191d29f2 100644 --- a/modutils/Config.src +++ b/modutils/Config.src @@ -4,6 +4,7 @@ # menu "Linux Module Utilities" +depends on PLATFORM_LINUX INSERT diff --git a/networking/Config.src b/networking/Config.src index 449436247..26c59e7c1 100644 --- a/networking/Config.src +++ b/networking/Config.src @@ -43,6 +43,7 @@ config FEATURE_PREFER_IPV4_ADDRESS config VERBOSE_RESOLUTION_ERRORS bool "Verbose resolution errors" default n + depends on PLATFORM_LINUX #because of xsocket() in libbb/xfuncs_prinf.c help Enable if you are not satisfied with simplistic "can't resolve 'hostname.com'" and want to know more. @@ -51,18 +52,21 @@ config VERBOSE_RESOLUTION_ERRORS config ARP bool "arp" default y + depends on PLATFORM_LINUX help Manipulate the system ARP cache. config ARPING bool "arping" default y + depends on PLATFORM_LINUX help Ping hosts by ARP packets. config BRCTL bool "brctl" default y + depends on PLATFORM_LINUX help Manage ethernet bridges. Supports addbr/delbr and addif/delif. @@ -95,6 +99,7 @@ config DNSD config ETHER_WAKE bool "ether-wake" default y + depends on PLATFORM_LINUX help Send a magic packet to wake up sleeping machines. @@ -269,6 +274,7 @@ config FEATURE_HTTPD_PROXY config IFCONFIG bool "ifconfig" default y + depends on PLATFORM_LINUX help Ifconfig is used to configure the kernel-resident network interfaces. @@ -316,6 +322,7 @@ config FEATURE_IFCONFIG_BROADCAST_PLUS config IFENSLAVE bool "ifenslave" default y + depends on PLATFORM_LINUX help Userspace application to bind several interfaces to a logical interface (use with kernel bonding driver). @@ -323,6 +330,7 @@ config IFENSLAVE config IFPLUGD bool "ifplugd" default y + depends on PLATFORM_LINUX help Network interface plug detection daemon. @@ -364,7 +372,7 @@ config FEATURE_IFUPDOWN_IP config FEATURE_IFUPDOWN_IP_BUILTIN bool "Use busybox ip applet" default y - depends on FEATURE_IFUPDOWN_IP + depends on FEATURE_IFUPDOWN_IP && PLATFORM_LINUX select IP select FEATURE_IP_ADDRESS select FEATURE_IP_LINK @@ -483,6 +491,7 @@ config FEATURE_INETD_RPC config IP bool "ip" default y + depends on PLATFORM_LINUX help The "ip" applet is a TCP/IP interface configuration and routing utility. You generally don't need "ip" to use busybox with @@ -598,6 +607,7 @@ config FEATURE_IPCALC_LONG_OPTIONS config NAMEIF bool "nameif" default y + depends on PLATFORM_LINUX select FEATURE_SYSLOG help nameif is used to rename network interface by its MAC address. @@ -626,6 +636,7 @@ config FEATURE_NAMEIF_EXTENDED config NETSTAT bool "netstat" default y + depends on PLATFORM_LINUX help netstat prints information about the Linux networking subsystem. @@ -654,6 +665,7 @@ config NSLOOKUP config NTPD bool "ntpd" default y + depends on PLATFORM_LINUX help The NTP client/server daemon. @@ -668,6 +680,7 @@ config FEATURE_NTPD_SERVER config PING bool "ping" default y + depends on PLATFORM_LINUX help ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. @@ -696,12 +709,14 @@ config PSCAN config ROUTE bool "route" default y + depends on PLATFORM_LINUX help Route displays or manipulates the kernel's IP routing tables. config SLATTACH bool "slattach" default y + depends on PLATFORM_LINUX help slattach is a small utility to attach network interfaces to serial lines. @@ -719,6 +734,7 @@ config SLATTACH config TCPSVD bool "tcpsvd" default y + depends on PLATFORM_LINUX help tcpsvd listens on a TCP port and runs a program for each new connection. @@ -888,6 +904,7 @@ config TFTP_DEBUG config TRACEROUTE bool "traceroute" default y + depends on PLATFORM_LINUX help Utility to trace the route of IP packets. @@ -924,6 +941,7 @@ config FEATURE_TRACEROUTE_USE_ICMP config TUNCTL bool "tunctl" default y + depends on PLATFORM_LINUX help tunctl creates or deletes tun devices. @@ -949,6 +967,7 @@ config IFUPDOWN_UDHCPC_CMD_OPTIONS config UDPSVD bool "udpsvd" default y + depends on PLATFORM_LINUX help udpsvd listens on an UDP port and runs a program for each new connection. @@ -956,6 +975,7 @@ config UDPSVD config VCONFIG bool "vconfig" default y + depends on PLATFORM_LINUX help Creates, removes, and configures VLAN interfaces @@ -990,6 +1010,7 @@ config FEATURE_WGET_LONG_OPTIONS config ZCIP bool "zcip" default y + depends on PLATFORM_LINUX select FEATURE_SYSLOG help ZCIP provides ZeroConf IPv4 address selection, according to RFC 3927. diff --git a/networking/udhcp/Config.src b/networking/udhcp/Config.src index aac88569b..331dffc2e 100644 --- a/networking/udhcp/Config.src +++ b/networking/udhcp/Config.src @@ -8,6 +8,7 @@ INSERT config UDHCPD bool "udhcp server (udhcpd)" default y + depends on PLATFORM_LINUX help udhcpd is a DHCP server geared primarily toward embedded systems, while striving to be fully functional and RFC compliant. @@ -51,6 +52,7 @@ config DHCPD_LEASES_FILE config UDHCPC bool "udhcp client (udhcpc)" default y + depends on PLATFORM_LINUX help udhcpc is a DHCP client geared primarily toward embedded systems, while striving to be fully functional and RFC compliant. diff --git a/procps/Config.src b/procps/Config.src index e61de5614..1ff6dfd30 100644 --- a/procps/Config.src +++ b/procps/Config.src @@ -10,6 +10,7 @@ INSERT config FREE bool "free" default y + depends on PLATFORM_LINUX #sysinfo() help free displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. @@ -104,7 +105,7 @@ config FEATURE_PS_WIDE config FEATURE_PS_TIME bool "Enable time and elapsed time output" default y - depends on PS && DESKTOP + depends on PS && DESKTOP && PLATFORM_LINUX #sysinfo() help Support -o time and -o etime output specifiers. @@ -200,6 +201,7 @@ config FEATURE_SHOW_THREADS config UPTIME bool "uptime" default y + depends on PLATFORM_LINUX #sysinfo() help uptime gives a one line display of the current time, how long the system has been running, how many users are currently logged diff --git a/shell/cttyhack.c b/shell/cttyhack.c index 7af13fdfd..a80d49dc3 100644 --- a/shell/cttyhack.c +++ b/shell/cttyhack.c @@ -13,6 +13,7 @@ //config:config CTTYHACK //config: bool "cttyhack" //config: default y +//config: depends on PLATFORM_LINUX //config: help //config: One common problem reported on the mailing list is "can't access tty; //config: job control turned off" error message which typically appears when diff --git a/sysklogd/Config.src b/sysklogd/Config.src index 6d574abb1..bfe2d1cc3 100644 --- a/sysklogd/Config.src +++ b/sysklogd/Config.src @@ -109,6 +109,7 @@ config FEATURE_LOGREAD_REDUCED_LOCKING config KLOGD bool "klogd" default y + depends on PLATFORM_LINUX help klogd is a utility which intercepts and logs all messages from the Linux kernel and sends the messages diff --git a/util-linux/Config.src b/util-linux/Config.src index 91d1fc2ce..98953c17b 100644 --- a/util-linux/Config.src +++ b/util-linux/Config.src @@ -10,6 +10,7 @@ INSERT config ACPID bool "acpid" default y + depends on PLATFORM_LINUX help acpid listens to ACPI events coming either in textual form from /proc/acpi/event (though it is marked deprecated it is still widely @@ -32,6 +33,7 @@ config FEATURE_ACPID_COMPAT config BLKID bool "blkid" default y + depends on PLATFORM_LINUX select VOLUMEID help Lists labels and UUIDs of all filesystems. @@ -41,6 +43,7 @@ config BLKID config DMESG bool "dmesg" default y + depends on PLATFORM_LINUX help dmesg is used to examine or control the kernel ring buffer. When the Linux kernel prints messages to the system log, they are stored in @@ -74,6 +77,7 @@ config FEATURE_DMESG_PRETTY config FBSET bool "fbset" default y + depends on PLATFORM_LINUX help fbset is used to show or change the settings of a Linux frame buffer device. The frame buffer device provides a simple and unique @@ -102,6 +106,7 @@ config FEATURE_FBSET_READMODE config FDFLUSH bool "fdflush" default y + depends on PLATFORM_LINUX help fdflush is only needed when changing media on slightly-broken removable media drives. It is used to make Linux believe that a @@ -114,12 +119,14 @@ config FDFLUSH config FDFORMAT bool "fdformat" default y + depends on PLATFORM_LINUX help fdformat is used to low-level format a floppy disk. config FDISK bool "fdisk" default y + depends on PLATFORM_LINUX help The fdisk utility is used to divide hard disks into one or more logical disks, which are generally called partitions. This utility @@ -187,6 +194,7 @@ config FEATURE_FDISK_ADVANCED config FINDFS bool "findfs" default y + depends on PLATFORM_LINUX select VOLUMEID help Prints the name of a filesystem with given label or UUID. @@ -202,6 +210,7 @@ config FLOCK config FREERAMDISK bool "freeramdisk" default y + depends on PLATFORM_LINUX help Linux allows you to create ramdisks. This utility allows you to delete them and completely free all memory that was used for the @@ -224,12 +233,14 @@ config FSCK_MINIX config MKFS_EXT2 bool "mkfs_ext2" default y + depends on PLATFORM_LINUX help Utility to create EXT2 filesystems. config MKFS_MINIX bool "mkfs_minix" default y + depends on PLATFORM_LINUX help The minix filesystem is a nice, small, compact, read-write filesystem with little overhead. If you wish to be able to create minix @@ -247,6 +258,7 @@ config FEATURE_MINIX2 config MKFS_REISER bool "mkfs_reiser" default n + depends on PLATFORM_LINUX help Utility to create ReiserFS filesystems. Note: this applet needs a lot of testing and polishing. @@ -254,6 +266,7 @@ config MKFS_REISER config MKFS_VFAT bool "mkfs_vfat" default y + depends on PLATFORM_LINUX help Utility to create FAT32 filesystems. @@ -302,6 +315,7 @@ config HD config HWCLOCK bool "hwclock" default y + depends on PLATFORM_LINUX help The hwclock utility is used to read and set the hardware clock on a system. This is primarily used to set the current time on @@ -341,6 +355,7 @@ config IPCRM config IPCS bool "ipcs" default y + depends on PLATFORM_LINUX select FEATURE_SUID help The ipcs utility is used to provide information on the currently @@ -349,6 +364,7 @@ config IPCS config LOSETUP bool "losetup" default y + depends on PLATFORM_LINUX help losetup is used to associate or detach a loop device with a regular file or block device, and to query the status of a loop device. This @@ -357,6 +373,7 @@ config LOSETUP config LSPCI bool "lspci" default y + #depends on PLATFORM_LINUX help lspci is a utility for displaying information about PCI buses in the system and devices connected to them. @@ -366,6 +383,7 @@ config LSPCI config LSUSB bool "lsusb" default y + #depends on PLATFORM_LINUX help lsusb is a utility for displaying information about USB buses in the system and devices connected to them. @@ -375,6 +393,7 @@ config LSUSB config MDEV bool "mdev" default y + depends on PLATFORM_LINUX help mdev is a mini-udev implementation for dynamically creating device nodes in the /dev directory. @@ -473,6 +492,7 @@ config FEATURE_USE_TERMIOS config MOUNT bool "mount" default y + depends on PLATFORM_LINUX help All files and filesystems in Unix are arranged into one big directory tree. The 'mount' utility is used to graft a filesystem onto a @@ -555,6 +575,7 @@ config FEATURE_MOUNT_FSTAB config PIVOT_ROOT bool "pivot_root" default y + depends on PLATFORM_LINUX help The pivot_root utility swaps the mount points for the root filesystem with some other mounted filesystem. This allows you to do all sorts @@ -582,12 +603,14 @@ config RDEV config READPROFILE bool "readprofile" default y + #depends on PLATFORM_LINUX help This allows you to parse /proc/profile for basic profiling. config RTCWAKE bool "rtcwake" default y + depends on PLATFORM_LINUX help Enter a system sleep state until specified wakeup time. @@ -607,6 +630,7 @@ config SCRIPTREPLAY config SETARCH bool "setarch" default y + depends on PLATFORM_LINUX help The linux32 utility is used to create a 32bit environment for the specified program (usually a shell). It only makes sense to have @@ -616,6 +640,7 @@ config SETARCH config SWAPONOFF bool "swaponoff" default y + depends on PLATFORM_LINUX help This option enables both the 'swapon' and the 'swapoff' utilities. Once you have created some swap space using 'mkswap', you also need @@ -634,6 +659,7 @@ config FEATURE_SWAPON_PRI config SWITCH_ROOT bool "switch_root" default y + depends on PLATFORM_LINUX help The switch_root utility is used from initramfs to select a new root device. Under initramfs, you have to use this instead of @@ -653,6 +679,7 @@ config SWITCH_ROOT config UMOUNT bool "umount" default y + depends on PLATFORM_LINUX help When you want to remove a mounted filesystem from its current mount point, for example when you are shutting down the system, the -- cgit v1.2.3-55-g6feb From f812eace1863feeac64dc8af27f4ab0f98119618 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Thu, 27 May 2010 15:37:32 +0200 Subject: init,loginutils: termios portability fixes Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- init/init.c | 17 ++++++++++++++++- loginutils/Config.src | 2 -- loginutils/getty.c | 27 ++++++++++++++------------- loginutils/login.c | 2 +- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/init/init.c b/init/init.c index 2eb8f1a54..1388c75cc 100644 --- a/init/init.c +++ b/init/init.c @@ -14,11 +14,19 @@ #include #include #include +#ifdef __linux__ #include +#endif #if ENABLE_FEATURE_UTMP # include /* DEAD_PROCESS */ #endif +/* Used only for sanitizing purposes in set_sane_term() below. On systems where + * the baud rate is stored in a separate field, we can safely disable them. */ +#ifndef CBAUD +# define CBAUD 0 +# define CBAUDEX 0 +#endif /* Was a CONFIG_xxx option. A lot of people were building * not fully functional init by switching it on! */ @@ -166,7 +174,9 @@ static void message(int where, const char *fmt, ...) static void console_init(void) { +#ifdef VT_OPENQRY int vtno; +#endif char *s; s = getenv("CONSOLE"); @@ -190,6 +200,7 @@ static void console_init(void) } s = getenv("TERM"); +#ifdef VT_OPENQRY if (ioctl(STDIN_FILENO, VT_OPENQRY, &vtno) != 0) { /* Not a linux terminal, probably serial console. * Force the TERM setting to vt102 @@ -198,7 +209,9 @@ static void console_init(void) putenv((char*)"TERM=vt102"); if (!ENABLE_FEATURE_INIT_SYSLOG) log_console = NULL; - } else if (!s) + } else +#endif + if (!s) putenv((char*)"TERM=linux"); } @@ -220,8 +233,10 @@ static void set_sane_term(void) tty.c_cc[VSTOP] = 19; /* C-s */ tty.c_cc[VSUSP] = 26; /* C-z */ +#ifdef __linux__ /* use line discipline 0 */ tty.c_line = 0; +#endif /* Make it be sane */ tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD; diff --git a/loginutils/Config.src b/loginutils/Config.src index 425d041b9..6ec289355 100644 --- a/loginutils/Config.src +++ b/loginutils/Config.src @@ -179,7 +179,6 @@ config DELUSER config GETTY bool "getty" default y - depends on PLATFORM_LINUX select FEATURE_SYSLOG help getty lets you log in on a tty, it is normally invoked by init. @@ -187,7 +186,6 @@ config GETTY config LOGIN bool "login" default y - depends on PLATFORM_LINUX select FEATURE_SUID select FEATURE_SYSLOG help diff --git a/loginutils/getty.c b/loginutils/getty.c index a5e8e906a..7f04d33fb 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c @@ -282,10 +282,8 @@ static void termios_init(struct termios *tp, int speed, struct options *op) * reads will be done in raw mode anyway. Errors will be dealt with * later on. */ -#ifdef __linux__ /* flush input and output queues, important for modems! */ - ioctl(0, TCFLSH, TCIOFLUSH); /* tcflush(0, TCIOFLUSH)? - same */ -#endif + tcflush(0, TCIOFLUSH); ispeed = ospeed = speed; if (speed == B0) { /* Speed was specified as "0" on command line. @@ -299,10 +297,13 @@ static void termios_init(struct termios *tp, int speed, struct options *op) cfsetispeed(tp, ispeed); cfsetospeed(tp, ospeed); - tp->c_iflag = tp->c_lflag = tp->c_line = 0; + tp->c_iflag = tp->c_lflag = 0; tp->c_oflag = OPOST | ONLCR; tp->c_cc[VMIN] = 1; tp->c_cc[VTIME] = 0; +#ifdef __linux__ + tp->c_line = 0; +#endif /* Optionally enable hardware flow control */ #ifdef CRTSCTS @@ -360,10 +361,8 @@ static void auto_baud(char *buf, unsigned size_buf, struct termios *tp) for (bp = buf; bp < buf + nread; bp++) { if (isdigit(*bp)) { speed = bcode(bp); - if (speed > 0) { - tp->c_cflag &= ~CBAUD; - tp->c_cflag |= speed; - } + if (speed > 0) + cfsetspeed(tp, speed); break; } } @@ -417,7 +416,7 @@ static char *get_logname(char *logname, unsigned size_logname, /* Flush pending input (esp. after parsing or switching the baud rate). */ sleep(1); - ioctl(0, TCFLSH, TCIFLUSH); /* tcflush(0, TCIOFLUSH)? - same */ + tcflush(0, TCIOFLUSH); /* Prompt for and read a login name. */ logname[0] = '\0'; @@ -526,7 +525,9 @@ static void termios_final(struct options *op, struct termios *tp, struct chardat tp->c_cc[VQUIT] = DEF_QUIT; /* default quit */ tp->c_cc[VEOF] = DEF_EOF; /* default EOF character */ tp->c_cc[VEOL] = DEF_EOL; +#ifdef VSWTC tp->c_cc[VSWTC] = DEF_SWITCH; /* default switch character */ +#endif /* Account for special characters seen in input. */ if (cp->eol == CR) { @@ -572,8 +573,8 @@ static void termios_final(struct options *op, struct termios *tp, struct chardat #endif /* Finally, make the new settings effective */ - /* It's tcsetattr_stdin_TCSANOW() + error check */ - ioctl_or_perror_and_die(0, TCSETS, tp, "%s: TCSETS", op->tty); + if (tcsetattr_stdin_TCSANOW(tp) < 0) + bb_perror_msg_and_die("%s: tcsetattr", op->tty); } int getty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; @@ -650,8 +651,8 @@ int getty_main(int argc UNUSED_PARAM, char **argv) * by patching the SunOS kernel variable "zsadtrlow" to a larger value; * 5 seconds seems to be a good value. */ - /* tcgetattr() + error check */ - ioctl_or_perror_and_die(0, TCGETS, &termios, "%s: TCGETS", options.tty); + if (tcgetattr(0, &termios) < 0) + bb_perror_msg_and_die("%s: tcgetattr", options.tty); pid = getpid(); #ifdef __linux__ diff --git a/loginutils/login.c b/loginutils/login.c index 88ed0af78..10012486f 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -264,7 +264,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) while (1) { /* flush away any type-ahead (as getty does) */ - ioctl(0, TCFLSH, TCIFLUSH); + tcflush(0, TCIFLUSH); if (!username[0]) get_username_or_die(username, sizeof(username)); -- cgit v1.2.3-55-g6feb From 714674e4da3d92c5dd14e00ab30794a895b91eb4 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Thu, 27 May 2010 15:38:44 +0200 Subject: init,halt: portability improvements * make init and halt use the same RB_* constants for reboot() * conditionalize the Linux-specific code Inspired by init.init.diff from the Debian kFreeBSD patches at: http://svn.debian.org/viewsvn/d-i/people/slackydeb/kfreebsd/busybox/1.14/debian Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- init/Config.src | 2 -- init/halt.c | 14 +------------- init/init.c | 16 ++++++++-------- init/reboot.h | 31 +++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 23 deletions(-) create mode 100644 init/reboot.h diff --git a/init/Config.src b/init/Config.src index a5e76be6a..590e29890 100644 --- a/init/Config.src +++ b/init/Config.src @@ -10,7 +10,6 @@ INSERT config INIT bool "init" default y - depends on PLATFORM_LINUX select FEATURE_SYSLOG help init is the first program run when the system boots. @@ -93,7 +92,6 @@ config FEATURE_INITRD config HALT bool "poweroff, halt, and reboot" default y - depends on PLATFORM_LINUX help Stop all processes and either halt, reboot, or power off the system. diff --git a/init/halt.c b/init/halt.c index f1bb2c4a8..abd801fda 100644 --- a/init/halt.c +++ b/init/halt.c @@ -8,7 +8,7 @@ */ #include "libbb.h" -#include +#include "reboot.h" #if ENABLE_FEATURE_WTMP #include @@ -36,18 +36,6 @@ static void write_wtmp(void) #define write_wtmp() ((void)0) #endif -#ifndef RB_HALT_SYSTEM -#define RB_HALT_SYSTEM RB_HALT -#endif - -#ifndef RB_POWERDOWN -/* Stop system and switch power off if possible. */ -# define RB_POWERDOWN 0x4321fedc -#endif -#ifndef RB_POWER_OFF -# define RB_POWER_OFF RB_POWERDOWN -#endif - int halt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int halt_main(int argc UNUSED_PARAM, char **argv) diff --git a/init/init.c b/init/init.c index 1388c75cc..d8bf15894 100644 --- a/init/init.c +++ b/init/init.c @@ -12,7 +12,6 @@ #include "libbb.h" #include #include -#include #include #ifdef __linux__ #include @@ -20,6 +19,7 @@ #if ENABLE_FEATURE_UTMP # include /* DEAD_PROCESS */ #endif +#include "reboot.h" /* reboot() constants */ /* Used only for sanitizing purposes in set_sane_term() below. On systems where * the baud rate is stored in a separate field, we can safely disable them. */ @@ -97,13 +97,6 @@ static const char *log_console = VC_5; enum { L_LOG = 0x1, L_CONSOLE = 0x2, -#ifndef RB_HALT_SYSTEM - RB_HALT_SYSTEM = 0xcdef0123, /* FIXME: this overflows enum */ - RB_ENABLE_CAD = 0x89abcdef, - RB_DISABLE_CAD = 0, - RB_POWER_OFF = 0x4321fedc, - RB_AUTOBOOT = 0x01234567, -#endif }; /* Print a message to the specified device. @@ -724,10 +717,12 @@ static void restart_handler(int sig UNUSED_PARAM) run_shutdown_and_kill_processes(); +#ifdef RB_ENABLE_CAD /* Allow Ctrl-Alt-Del to reboot the system. * This is how kernel sets it up for init, we follow suit. */ reboot(RB_ENABLE_CAD); /* misnomer */ +#endif if (open_stdio_to_tty(a->terminal)) { dbg_message(L_CONSOLE, "Trying to re-exec %s", a->command); @@ -870,9 +865,11 @@ int init_main(int argc UNUSED_PARAM, char **argv) ) { bb_show_usage(); } +#ifdef RB_DISABLE_CAD /* Turn off rebooting via CTL-ALT-DEL - we get a * SIGINT on CAD so we can shut things down gracefully... */ reboot(RB_DISABLE_CAD); /* misnomer */ +#endif } /* Figure out where the default console should be */ @@ -895,6 +892,8 @@ int init_main(int argc UNUSED_PARAM, char **argv) message(L_CONSOLE | L_LOG, "init started: %s", bb_banner); #endif +/* struct sysinfo is linux-specific */ +#ifdef __linux__ /* Make sure there is enough memory to do something useful. */ if (ENABLE_SWAPONOFF) { struct sysinfo info; @@ -910,6 +909,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) run_actions(SYSINIT); /* wait and removing */ } } +#endif /* Check if we are supposed to be in single user mode */ if (argv[1] diff --git a/init/reboot.h b/init/reboot.h new file mode 100644 index 000000000..ff045fdd1 --- /dev/null +++ b/init/reboot.h @@ -0,0 +1,31 @@ +/* + * Definitions related to the reboot() system call, + * shared between init.c and halt.c. + */ + +#include + +#ifndef RB_HALT_SYSTEM +# if defined(__linux__) +# define RB_HALT_SYSTEM 0xcdef0123 +# define RB_ENABLE_CAD 0x89abcdef +# define RB_DISABLE_CAD 0 +# define RB_POWER_OFF 0x4321fedc +# define RB_AUTOBOOT 0x01234567 +# elif defined(RB_HALT) +# define RB_HALT_SYSTEM RB_HALT +# endif +#endif + +/* Stop system and switch power off if possible. */ +#ifndef RB_POWER_OFF +# if defined(RB_POWERDOWN) +# define RB_POWER_OFF RB_POWERDOWN +# elif defined(__linux__) +# define RB_POWER_OFF 0x4321fedc +# else +# warning "poweroff unsupported, using halt as fallback" +# define RB_POWER_OFF RB_HALT_SYSTEM +# endif +#endif + -- cgit v1.2.3-55-g6feb From 1c05303fdc302725093294eb0305adc003d52bcb Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Thu, 27 May 2010 15:46:07 +0200 Subject: init: make the initial $TERM value configurable Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- init/Config.src | 12 ++++++++++++ init/init.c | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/init/Config.src b/init/Config.src index 590e29890..2cac3573e 100644 --- a/init/Config.src +++ b/init/Config.src @@ -89,6 +89,18 @@ config FEATURE_INITRD This does not apply to initramfs, which runs /init as PID 1 and requires no special support. +config INIT_TERMINAL_TYPE + string "Initial terminal type" + default "linux" + depends on INIT + help + This is the initial value set by init for the TERM environment + variable. This variable is used by programs which make use of + extended terminal capabilities. + + Note that on Linux, init attempts to detect serial terminal and + sets TERM to "vt102" if one is found. + config HALT bool "poweroff, halt, and reboot" default y diff --git a/init/init.c b/init/init.c index d8bf15894..fa1af6d7c 100644 --- a/init/init.c +++ b/init/init.c @@ -205,7 +205,7 @@ static void console_init(void) } else #endif if (!s) - putenv((char*)"TERM=linux"); + putenv((char*)"TERM=" CONFIG_INIT_TERMINAL_TYPE); } /* Set terminal settings to reasonable defaults. -- cgit v1.2.3-55-g6feb From 816ed971e4ce60564f7ecbdc016d268d8e936230 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Thu, 27 May 2010 15:46:29 +0200 Subject: libbb.h: add device names for Hurd and FreeBSD Adapted from include.libbb.diff from the Debian kFreeBSD people: http://svn.debian.org/viewsvn/d-i/people/slackydeb/kfreebsd/busybox/1.14/debian Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- include/libbb.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index e2a8322b8..c043506b9 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1613,7 +1613,27 @@ extern const char bb_default_login_shell[]; /* "sh" */ #define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6) -#if ENABLE_FEATURE_DEVFS +/* The following devices are the same on all systems. */ +#define CURRENT_TTY "/dev/tty" +#define DEV_CONSOLE "/dev/console" + +#if defined(__FreeBSD_kernel__) +# define CURRENT_VC CURRENT_TTY +# define VC_1 "/dev/ttyv0" +# define VC_2 "/dev/ttyv1" +# define VC_3 "/dev/ttyv2" +# define VC_4 "/dev/ttyv3" +# define VC_5 "/dev/ttyv4" +# define VC_FORMAT "/dev/ttyv%d" +#elif defined(__GNU__) +# define CURRENT_VC CURRENT_TTY +# define VC_1 "/dev/tty1" +# define VC_2 "/dev/tty2" +# define VC_3 "/dev/tty3" +# define VC_4 "/dev/tty4" +# define VC_5 "/dev/tty5" +# define VC_FORMAT "/dev/tty%d" +#elif ENABLE_FEATURE_DEVFS /* from now on, assume Linux naming */ # define CURRENT_VC "/dev/vc/0" # define VC_1 "/dev/vc/1" # define VC_2 "/dev/vc/2" @@ -1660,10 +1680,6 @@ extern const char bb_default_login_shell[]; # define FB_0 "/dev/fb0" #endif -/* The following devices are the same on devfs and non-devfs systems. */ -#define CURRENT_TTY "/dev/tty" -#define DEV_CONSOLE "/dev/console" - #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0]))) -- cgit v1.2.3-55-g6feb From 84b01d5afc8230c79a1b8469c222d940c0d4e792 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Thu, 27 May 2010 15:46:33 +0200 Subject: mkdir: fix -p on FreeBSD This patch is libbb.make_directory.diff from Debian kFreeBSD at: http://svn.debian.org/viewsvn/d-i/people/slackydeb/kfreebsd/busybox/1.14/debian Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- libbb/make_directory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbb/make_directory.c b/libbb/make_directory.c index 4486eb1ed..6dd04cf99 100644 --- a/libbb/make_directory.c +++ b/libbb/make_directory.c @@ -86,7 +86,7 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags) if (mkdir(path, 0777) < 0) { /* If we failed for any other reason than the directory * already exists, output a diagnostic and return -1 */ - if (errno != EEXIST + if ((errno != EEXIST && errno != EISDIR) || !(flags & FILEUTILS_RECUR) || ((stat(path, &st) < 0) || !S_ISDIR(st.st_mode)) ) { -- cgit v1.2.3-55-g6feb From 29885114a5e3d22ee7aa3ab0e373e00e7cff443c Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Thu, 27 May 2010 15:39:24 +0200 Subject: libbb: conditionalize AF_* usage in error reporting Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- libbb/xfuncs_printf.c | 4 ++++ networking/Config.src | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index 7069a7c8e..91f7ba22c 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -387,8 +387,12 @@ int FAST_FUNC xsocket(int domain, int type, int protocol) /* Hijack vaguely related config option */ #if ENABLE_VERBOSE_RESOLUTION_ERRORS const char *s = "INET"; +# ifdef AF_PACKET if (domain == AF_PACKET) s = "PACKET"; +# endif +# ifdef AF_NETLINK if (domain == AF_NETLINK) s = "NETLINK"; +# endif IF_FEATURE_IPV6(if (domain == AF_INET6) s = "INET6";) bb_perror_msg_and_die("socket(AF_%s,%d,%d)", s, type, protocol); #else diff --git a/networking/Config.src b/networking/Config.src index 26c59e7c1..fc613e8d3 100644 --- a/networking/Config.src +++ b/networking/Config.src @@ -43,7 +43,6 @@ config FEATURE_PREFER_IPV4_ADDRESS config VERBOSE_RESOLUTION_ERRORS bool "Verbose resolution errors" default n - depends on PLATFORM_LINUX #because of xsocket() in libbb/xfuncs_prinf.c help Enable if you are not satisfied with simplistic "can't resolve 'hostname.com'" and want to know more. -- cgit v1.2.3-55-g6feb From 2ea12d8b6d2a36c5d49df1ae97b86ba287835249 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Thu, 27 May 2010 15:46:25 +0200 Subject: tcpsvd,udpsvd: conditionalize usage of SO_ORIGINAL_DST On systems without this call, $TCPORIGDSTADDR is not set. Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- networking/Config.src | 2 -- networking/tcpudp.c | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/networking/Config.src b/networking/Config.src index fc613e8d3..2d29c423a 100644 --- a/networking/Config.src +++ b/networking/Config.src @@ -733,7 +733,6 @@ config SLATTACH config TCPSVD bool "tcpsvd" default y - depends on PLATFORM_LINUX help tcpsvd listens on a TCP port and runs a program for each new connection. @@ -966,7 +965,6 @@ config IFUPDOWN_UDHCPC_CMD_OPTIONS config UDPSVD bool "udpsvd" default y - depends on PLATFORM_LINUX help udpsvd listens on an UDP port and runs a program for each new connection. diff --git a/networking/tcpudp.c b/networking/tcpudp.c index 53e622b56..40f68258e 100644 --- a/networking/tcpudp.c +++ b/networking/tcpudp.c @@ -30,9 +30,12 @@ */ #include "libbb.h" + /* Wants etc, thus included after libbb.h: */ +#ifdef __linux__ #include /* for __be32 etc */ #include +#endif // TODO: move into this file: #include "tcpudp_perhost.h" @@ -464,6 +467,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv) /* setup ucspi env */ const char *proto = tcp ? "TCP" : "UDP"; +#ifdef SO_ORIGINAL_DST /* Extract "original" destination addr:port * from Linux firewall. Useful when you redirect * an outbond connection to local handler, and it needs @@ -473,6 +477,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv) xsetenv_plain("TCPORIGDSTADDR", addr); free(addr); } +#endif xsetenv_plain("PROTO", proto); xsetenv_proto(proto, "LOCALADDR", local_addr); xsetenv_proto(proto, "REMOTEADDR", remote_addr); -- cgit v1.2.3-55-g6feb From ba085c6351b49d7c71f3635a0f4709e1927fdc51 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 21 Jul 2010 08:58:11 +0200 Subject: make DESKTOP=y the default Signed-off-by: Denys Vlasenko --- Config.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Config.in b/Config.in index 35f43b3cd..828b30471 100644 --- a/Config.in +++ b/Config.in @@ -15,7 +15,7 @@ menu "General Configuration" config DESKTOP bool "Enable options for full-blown desktop systems" - default n + default y help Enable options and features which are not essential. Select this only if you plan to use busybox on full-blown -- cgit v1.2.3-55-g6feb From 23e8c08fa2e1faab335e7ff625272f57d1dde469 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 21 Jul 2010 10:29:07 +0200 Subject: mpstat: new applet. ~5.5k Signed-off-by: Marek Polacek Signed-off-by: Denys Vlasenko --- procps/mpstat.c | 1024 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1024 insertions(+) create mode 100644 procps/mpstat.c diff --git a/procps/mpstat.c b/procps/mpstat.c new file mode 100644 index 000000000..0f633c713 --- /dev/null +++ b/procps/mpstat.c @@ -0,0 +1,1024 @@ +/* vi: set sw=4 ts=4: */ +/* + * Per-processor statistics, based on sysstat version 9.1.2 by Sebastien Godard + * + * Copyright (C) 2010 Marek Polacek + * + * Licensed under GPLv2, see file License in this tarball for details. + */ + +//applet:IF_MPSTAT(APPLET(mpstat, _BB_DIR_BIN, _BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_MPSTAT) += mpstat.o + +//config:config MPSTAT +//config: bool "mpstat" +//config: default y +//config: help +//config: Per-processor statistics + +#include "libbb.h" +#include /* struct utsname */ + +//#define debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__) +#define debug(fmt, ...) ((void)0) + +/* Size of /proc/interrupts line, CPU data excluded */ +#define INTERRUPTS_LINE 64 +/* Maximum number of interrupts */ +#define NR_IRQS 256 +#define NR_IRQCPU_PREALLOC 3 +#define MAX_IRQ_LEN 16 +#define MAX_PF_NAME 512 + +/* System files */ +#define SYSFS_DEVCPU "/sys/devices/system/cpu" +#define PROCFS_STAT "/proc/stat" +#define PROCFS_INTERRUPTS "/proc/interrupts" +#define PROCFS_SOFTIRQS "/proc/softirqs" +#define PROCFS_UPTIME "/proc/uptime" + + +#if 1 +typedef unsigned long long data_t; +typedef long long idata_t; +#define FMT_DATA "ll" +#define DATA_MAX ULLONG_MAX +#else +typedef unsigned long data_t; +typedef long idata_t; +#define FMT_DATA "l" +#define DATA_MAX ULONG_MAX +#endif + + +struct stats_irqcpu { + unsigned interrupt; + char irq_name[MAX_IRQ_LEN]; +}; + +/* Structure for CPU statistics */ +struct stats_cpu { + data_t cpu_user; + data_t cpu_nice; + data_t cpu_system; + data_t cpu_idle; + data_t cpu_iowait; + data_t cpu_steal; + data_t cpu_irq; + data_t cpu_softirq; + data_t cpu_guest; +}; + +/* Struct for interrupts statistics */ +struct stats_irq { + data_t irq_nr; +}; + + +/* Globals. Try to sort by size. */ +struct globals { + int interval; + int count; + unsigned cpu_nr; /* Number of CPUs */ + unsigned irqcpu_nr; /* Number of interrupts per CPU */ + unsigned softirqcpu_nr; /* Number of soft interrupts per CPU */ + unsigned options; + unsigned hz; + unsigned cpu_bitmap_len; + smallint p_option; + smallint header_done; + smallint avg_header_done; + unsigned char *cpu_bitmap; /* Bit 0: global, bit 1: 1st proc... */ + data_t global_uptime[3]; + data_t per_cpu_uptime[3]; + struct stats_cpu *st_cpu[3]; + struct stats_irq *st_irq[3]; + struct stats_irqcpu *st_irqcpu[3]; + struct stats_irqcpu *st_softirqcpu[3]; + struct tm timestamp[3]; +}; +#define G (*ptr_to_globals) +#define INIT_G() do { \ + SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ +} while (0) + +/* The selected interrupts statistics (bits in G.options) */ +enum { + D_CPU = 1 << 0, + D_IRQ_SUM = 1 << 1, + D_IRQ_CPU = 1 << 2, + D_SOFTIRQS = 1 << 3, +}; + + +/* Does str start with "cpu"? */ +static int starts_with_cpu(const char *str) +{ + return !((str[0] - 'c') | (str[1] - 'p') | (str[2] - 'u')); +} + +/* Is option on? */ +static ALWAYS_INLINE int display_opt(int opt) +{ + return (opt & G.options); +} + +#if DATA_MAX > 0xffffffff +/* + * Handle overflow conditions properly for counters which can have + * less bits than data_t, depending on the kernel version. + */ +/* Surprisingly, on 32bit inlining is a size win */ +static ALWAYS_INLINE data_t overflow_safe_sub(data_t prev, data_t curr) +{ + data_t v = curr - prev; + + if ((idata_t)v < 0 /* curr < prev - counter overflow? */ + && prev <= 0xffffffff /* kernel uses 32bit value for the counter? */ + ) { + /* Add 33th bit set to 1 to curr, compensating for the overflow */ + /* double shift defeats "warning: left shift count >= width of type" */ + v += ((data_t)1 << 16) << 16; + } + return v; +} +#else +static ALWAYS_INLINE data_t overflow_safe_sub(data_t prev, data_t curr) +{ + return curr - prev; +} +#endif + +static double percent_value(data_t prev, data_t curr, data_t itv) +{ + return ((double)overflow_safe_sub(prev, curr)) / itv * 100; +} + +static double hz_value(data_t prev, data_t curr, data_t itv) +{ + return ((double)overflow_safe_sub(prev, curr)) / itv * G.hz; +} + +static ALWAYS_INLINE data_t jiffies_diff(data_t old, data_t new) +{ + data_t diff = new - old; + return (diff == 0) ? 1 : diff; +} + +static int is_cpu_in_bitmap(unsigned cpu) +{ + return G.cpu_bitmap[cpu >> 3] & (1 << (cpu & 7)); +} + +static void write_irqcpu_stats(struct stats_irqcpu *per_cpu_stats[], + int total_irqs, + data_t itv, + int prev, int current, + const char *prev_str, const char *current_str) +{ + int j; + int offset, cpu; + struct stats_irqcpu *p0, *q0; + + /* Check if number of IRQs has changed */ + if (G.interval != 0) { + for (j = 0; j <= total_irqs; j++) { + p0 = &per_cpu_stats[current][j]; + if (p0->irq_name[0] != '\0') { + q0 = &per_cpu_stats[prev][j]; + if (strcmp(p0->irq_name, q0->irq_name) != 0) { + /* Strings are different */ + break; + } + } + } + } + + /* Print header */ + printf("\n%-11s CPU", prev_str); + for (j = 0; j < total_irqs; j++) { + p0 = &per_cpu_stats[current][j]; + if (p0->irq_name[0] != '\0') + printf(" %8s/s", p0->irq_name); + } + bb_putchar('\n'); + + for (cpu = 1; cpu <= G.cpu_nr; cpu++) { + /* Check if we want stats about this CPU */ + if (!is_cpu_in_bitmap(cpu) && G.p_option) { + continue; + } + + printf("%-11s %4u", current_str, cpu - 1); + + for (j = 0; j < total_irqs; j++) { + /* IRQ field set only for proc 0 */ + p0 = &per_cpu_stats[current][j]; + + /* + * An empty string for irq name means that + * interrupt is no longer used. + */ + if (p0->irq_name[0] != '\0') { + offset = j; + q0 = &per_cpu_stats[prev][offset]; + + /* + * If we want stats for the time since boot + * we have p0->irq != q0->irq. + */ + if (strcmp(p0->irq_name, q0->irq_name) != 0 + && G.interval != 0 + ) { + if (j) { + offset = j - 1; + q0 = &per_cpu_stats[prev][offset]; + } + if (strcmp(p0->irq_name, q0->irq_name) != 0 + && (j + 1 < total_irqs) + ) { + offset = j + 1; + q0 = &per_cpu_stats[prev][offset]; + } + } + + if (strcmp(p0->irq_name, q0->irq_name) == 0 + || G.interval == 0 + ) { + struct stats_irqcpu *p, *q; + p = &per_cpu_stats[current][(cpu - 1) * total_irqs + j]; + q = &per_cpu_stats[prev][(cpu - 1) * total_irqs + offset]; + printf(" %10.2f", + (double)(p->interrupt - q->interrupt) / itv * G.hz); + } else { + printf(" N/A"); + } + } + } + bb_putchar('\n'); + } +} + +static data_t get_per_cpu_interval(const struct stats_cpu *scc, + const struct stats_cpu *scp) +{ + return ((scc->cpu_user + scc->cpu_nice + + scc->cpu_system + scc->cpu_iowait + + scc->cpu_idle + scc->cpu_steal + + scc->cpu_irq + scc->cpu_softirq) - + (scp->cpu_user + scp->cpu_nice + + scp->cpu_system + scp->cpu_iowait + + scp->cpu_idle + scp->cpu_steal + + scp->cpu_irq + scp->cpu_softirq)); +} + +static void print_stats_cpu_struct(const struct stats_cpu *p, + const struct stats_cpu *c, + data_t itv) +{ + printf(" %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n", + percent_value(p->cpu_user - p->cpu_guest, + /**/ c->cpu_user - c->cpu_guest, itv), + percent_value(p->cpu_nice , c->cpu_nice , itv), + percent_value(p->cpu_system , c->cpu_system , itv), + percent_value(p->cpu_iowait , c->cpu_iowait , itv), + percent_value(p->cpu_irq , c->cpu_irq , itv), + percent_value(p->cpu_softirq, c->cpu_softirq, itv), + percent_value(p->cpu_steal , c->cpu_steal , itv), + percent_value(p->cpu_guest , c->cpu_guest , itv), + percent_value(p->cpu_idle , c->cpu_idle , itv) + ); +} + +static void write_stats_core(int prev, int current, + const char *prev_str, const char *current_str) +{ + struct stats_cpu *scc, *scp; + data_t itv, global_itv; + int cpu; + + /* Compute time interval */ + itv = global_itv = jiffies_diff(G.global_uptime[prev], G.global_uptime[current]); + + /* Reduce interval to one CPU */ + if (G.cpu_nr > 1) + itv = jiffies_diff(G.per_cpu_uptime[prev], G.per_cpu_uptime[current]); + + /* Print CPU stats */ + if (display_opt(D_CPU)) { + + /* This is done exactly once */ + if (!G.header_done) { + printf("\n%-11s CPU %%usr %%nice %%sys %%iowait %%irq %%soft %%steal %%guest %%idle\n", + prev_str + ); + G.header_done = 1; + } + + for (cpu = 0; cpu <= G.cpu_nr; cpu++) { + data_t per_cpu_itv; + + /* Print stats about this particular CPU? */ + if (!is_cpu_in_bitmap(cpu)) + continue; + + scc = &G.st_cpu[current][cpu]; + scp = &G.st_cpu[prev][cpu]; + per_cpu_itv = global_itv; + + printf((cpu ? "%-11s %4u" : "%-11s all"), current_str, cpu - 1); + if (cpu) { + double idle; + /* + * If the CPU is offline, then it isn't in /proc/stat, + * so all values are 0. + * NB: Guest time is already included in user time. + */ + if ((scc->cpu_user | scc->cpu_nice | scc->cpu_system | + scc->cpu_iowait | scc->cpu_idle | scc->cpu_steal | + scc->cpu_irq | scc->cpu_softirq) == 0 + ) { + /* + * Set current struct fields to values from prev. + * iteration. Then their values won't jump from + * zero, when the CPU comes back online. + */ + *scc = *scp; + idle = 0.0; + goto print_zeros; + } + /* Compute interval again for current proc */ + per_cpu_itv = get_per_cpu_interval(scc, scp); + if (per_cpu_itv == 0) { + /* + * If the CPU is tickless then there is no change in CPU values + * but the sum of values is not zero. + */ + idle = 100.0; + print_zeros: + printf(" %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n", + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, idle); + continue; + } + } + print_stats_cpu_struct(scp, scc, per_cpu_itv); + } + } + + /* Print total number of IRQs per CPU */ + if (display_opt(D_IRQ_SUM)) { + + /* Print average header, this is done exactly once */ + if (!G.avg_header_done) { + printf("\n%-11s CPU intr/s\n", prev_str); + G.avg_header_done = 1; + } + + for (cpu = 0; cpu <= G.cpu_nr; cpu++) { + data_t per_cpu_itv; + + /* Print stats about this CPU? */ + if (!is_cpu_in_bitmap(cpu)) + continue; + + per_cpu_itv = itv; + printf((cpu ? "%-11s %4u" : "%-11s all"), current_str, cpu - 1); + if (cpu) { + scc = &G.st_cpu[current][cpu]; + scp = &G.st_cpu[prev][cpu]; + /* Compute interval again for current proc */ + per_cpu_itv = get_per_cpu_interval(scc, scp); + if (per_cpu_itv == 0) { + printf(" %9.2f\n", 0.0); + continue; + } + } + printf(" %9.2f\n", hz_value(G.st_irq[prev][cpu].irq_nr, G.st_irq[current][cpu].irq_nr, per_cpu_itv)); + } + } + + if (display_opt(D_IRQ_CPU)) { + write_irqcpu_stats(G.st_irqcpu, G.irqcpu_nr, + itv, + prev, current, + prev_str, current_str + ); + } + + if (display_opt(D_SOFTIRQS)) { + write_irqcpu_stats(G.st_softirqcpu, G.softirqcpu_nr, + itv, + prev, current, + prev_str, current_str + ); + } +} + +/* + * Print the statistics + */ +static void write_stats(int current) +{ + char prev_time[16]; + char curr_time[16]; + + strftime(prev_time, sizeof(prev_time), "%X", &G.timestamp[!current]); + strftime(curr_time, sizeof(curr_time), "%X", &G.timestamp[current]); + + write_stats_core(!current, current, prev_time, curr_time); +} + +static void write_stats_avg(int current) +{ + write_stats_core(2, current, "Average:", "Average:"); +} + +/* + * Read CPU statistics + */ +static void get_cpu_statistics(struct stats_cpu *cpu, data_t *up, data_t *up0) +{ + FILE *fp; + char buf[1024]; + + fp = xfopen_for_read(PROCFS_STAT); + + while (fgets(buf, sizeof(buf), fp)) { + data_t sum; + unsigned cpu_number; + struct stats_cpu *cp; + + if (!starts_with_cpu(buf)) + continue; /* not "cpu" */ + if (buf[3] == ' ') { + /* "cpu " */ + cp = cpu; + } else { + /* "cpuN" */ + if (G.cpu_nr == 0 + || sscanf(buf + 3, "%u ", &cpu_number) != 1 + || cpu_number >= G.cpu_nr + ) { + continue; + } + cp = &cpu[cpu_number + 1]; + } + + /* Read the jiffies, save them */ + /* Not all fields have to be present */ + memset(cp, 0, sizeof(*cp)); + sscanf(skip_non_whitespace(buf + 3), + " %"FMT_DATA"u %"FMT_DATA"u %"FMT_DATA"u" + " %"FMT_DATA"u %"FMT_DATA"u %"FMT_DATA"u" + " %"FMT_DATA"u %"FMT_DATA"u %"FMT_DATA"u", + &cp->cpu_user, &cp->cpu_nice, &cp->cpu_system, + &cp->cpu_idle, &cp->cpu_iowait, &cp->cpu_irq, + &cp->cpu_softirq, &cp->cpu_steal, + &cp->cpu_guest + ); + /* + * Compute uptime in jiffies (1/HZ), it'll be the sum of + * individual CPU's uptimes. + * NB: We have to omit cpu_guest, because cpu_user includes it. + */ + sum = cp->cpu_user + cp->cpu_nice + cp->cpu_system + + cp->cpu_idle + cp->cpu_iowait + cp->cpu_irq + + cp->cpu_softirq + cp->cpu_steal; + + if (buf[3] == ' ') { + /* "cpu " */ + *up = sum; + } else { + /* "cpuN" */ + if (cpu_number == 0 && *up0 != 0) { + /* Compute uptime of single CPU */ + *up0 = sum; + } + } + } + fclose(fp); +} + +/* + * Read IRQs from /proc/stat + */ +static void get_irqs_from_stat(struct stats_irq *irq) +{ + FILE *fp; + char buf[1024]; + + fp = fopen_for_read(PROCFS_STAT); + if (!fp) + return; + + while (fgets(buf, sizeof(buf), fp)) { + if (strncmp(buf, "intr ", 5) == 0) + /* Read total number of IRQs since system boot */ + sscanf(buf + 5, "%"FMT_DATA"u", &irq->irq_nr); + } + + fclose(fp); +} + +/* + * Read stats from /proc/interrupts or /proc/softirqs + */ +static void get_irqs_from_interrupts(const char *fname, + struct stats_irqcpu *per_cpu_stats[], + int irqs_per_cpu, int current) +{ + FILE *fp; + struct stats_irq *irq_i; + struct stats_irqcpu *ic; + char *buf; + unsigned buflen; + unsigned cpu; + unsigned irq; + int cpu_index[G.cpu_nr]; + int iindex; + int len, digit; + + for (cpu = 1; cpu <= G.cpu_nr; cpu++) { + irq_i = &G.st_irq[current][cpu]; + irq_i->irq_nr = 0; + } + + fp = fopen_for_read(fname); + if (!fp) + return; + + buflen = INTERRUPTS_LINE + 16 * G.cpu_nr; + buf = xmalloc(buflen); + + /* Parse header and determine, which CPUs are online */ + iindex = 0; + while (fgets(buf, buflen, fp)) { + char *cp, *next; + next = buf; + while ((cp = strstr(next, "CPU")) != NULL + && iindex < G.cpu_nr + ) { + cpu = strtoul(cp + 3, &next, 10); + cpu_index[iindex++] = cpu; + } + if (iindex) /* We found header */ + break; + } + + irq = 0; + while (fgets(buf, buflen, fp) + && irq < irqs_per_cpu + ) { + char *cp; + /* Skip over ":" */ + cp = strchr(buf, ':'); + if (!cp) + continue; + + ic = &per_cpu_stats[current][irq]; + len = cp - buf; + if (len > sizeof(ic->irq_name)) { + len = sizeof(ic->irq_name); + } + safe_strncpy(ic->irq_name, buf, len); + digit = isdigit(buf[len - 1]); + cp++; + + for (cpu = 0; cpu < iindex; cpu++) { + char *next; + ic = &per_cpu_stats[current][cpu_index[cpu] * irqs_per_cpu + irq]; + irq_i = &G.st_irq[current][cpu_index[cpu] + 1]; + ic->interrupt = strtoul(cp, &next, 10); + if (digit) { + /* Do not count non-numerical IRQs */ + irq_i->irq_nr += ic->interrupt; + } + cp = next; + } + irq++; + } + fclose(fp); + free(buf); + + while (irq < irqs_per_cpu) { + /* Number of interrupts per CPU has changed */ + ic = &per_cpu_stats[current][irq]; + ic->irq_name[0] = '\0'; /* False interrupt */ + irq++; + } +} + +static void get_uptime(data_t *uptime) +{ + FILE *fp; + char buf[sizeof(long)*3 * 2 + 4]; /* enough for long.long */ + unsigned long uptime_sec, decimal; + + fp = fopen_for_read(PROCFS_UPTIME); + if (!fp) + return; + if (fgets(buf, sizeof(buf), fp)) { + if (sscanf(buf, "%lu.%lu", &uptime_sec, &decimal) == 2) { + *uptime = (data_t)uptime_sec * G.hz + decimal * G.hz / 100; + } + } + + fclose(fp); +} + +static void get_localtime(struct tm *tm) +{ + time_t timer; + time(&timer); + localtime_r(&timer, tm); +} + +static void alarm_handler(int sig UNUSED_PARAM) +{ + signal(SIGALRM, alarm_handler); + alarm(G.interval); +} + +static void main_loop(void) +{ + unsigned current; + unsigned cpus; + + /* Read the stats */ + if (G.cpu_nr > 1) { + G.per_cpu_uptime[0] = 0; + get_uptime(&G.per_cpu_uptime[0]); + } + + get_cpu_statistics(G.st_cpu[0], &G.global_uptime[0], &G.per_cpu_uptime[0]); + + if (display_opt(D_IRQ_SUM)) + get_irqs_from_stat(G.st_irq[0]); + + if (display_opt(D_IRQ_SUM | D_IRQ_CPU)) + get_irqs_from_interrupts(PROCFS_INTERRUPTS, G.st_irqcpu, + G.irqcpu_nr, 0); + + if (display_opt(D_SOFTIRQS)) + get_irqs_from_interrupts(PROCFS_SOFTIRQS, G.st_softirqcpu, + G.softirqcpu_nr, 0); + + if (G.interval == 0) { + /* Display since boot time */ + cpus = G.cpu_nr + 1; + G.timestamp[1] = G.timestamp[0]; + memset(G.st_cpu[1], 0, sizeof(G.st_cpu[1][0]) * cpus); + memset(G.st_irq[1], 0, sizeof(G.st_irq[1][0]) * cpus); + memset(G.st_irqcpu[1], 0, sizeof(G.st_irqcpu[1][0]) * cpus * G.irqcpu_nr); + memset(G.st_softirqcpu[1], 0, sizeof(G.st_softirqcpu[1][0]) * cpus * G.softirqcpu_nr); + + write_stats(0); + + /* And we're done */ + return; + } + + /* Set a handler for SIGALRM */ + alarm_handler(0); + + /* Save the stats we already have. We need them to compute the average */ + G.timestamp[2] = G.timestamp[0]; + G.global_uptime[2] = G.global_uptime[0]; + G.per_cpu_uptime[2] = G.per_cpu_uptime[0]; + cpus = G.cpu_nr + 1; + memcpy(G.st_cpu[2], G.st_cpu[0], sizeof(G.st_cpu[0][0]) * cpus); + memcpy(G.st_irq[2], G.st_irq[0], sizeof(G.st_irq[0][0]) * cpus); + memcpy(G.st_irqcpu[2], G.st_irqcpu[0], sizeof(G.st_irqcpu[0][0]) * cpus * G.irqcpu_nr); + if (display_opt(D_SOFTIRQS)) { + memcpy(G.st_softirqcpu[2], G.st_softirqcpu[0], + sizeof(G.st_softirqcpu[0][0]) * cpus * G.softirqcpu_nr); + } + + current = 1; + while (1) { + /* Suspend until a signal is received */ + pause(); + + /* Set structures to 0 to distinguish off/online CPUs */ + memset(&G.st_cpu[current][/*cpu:*/ 1], 0, sizeof(G.st_cpu[0][0]) * G.cpu_nr); + + get_localtime(&G.timestamp[current]); + + /* Read stats */ + if (G.cpu_nr > 1) { + G.per_cpu_uptime[current] = 0; + get_uptime(&G.per_cpu_uptime[current]); + } + get_cpu_statistics(G.st_cpu[current], &G.global_uptime[current], &G.per_cpu_uptime[current]); + + if (display_opt(D_IRQ_SUM)) + get_irqs_from_stat(G.st_irq[current]); + + if (display_opt(D_IRQ_SUM | D_IRQ_CPU)) + get_irqs_from_interrupts(PROCFS_INTERRUPTS, G.st_irqcpu, + G.irqcpu_nr, current); + + if (display_opt(D_SOFTIRQS)) + get_irqs_from_interrupts(PROCFS_SOFTIRQS, + G.st_softirqcpu, + G.softirqcpu_nr, current); + + write_stats(current); + + if (G.count > 0) { + if (--G.count == 0) + break; + } + + current ^= 1; + } + + /* Print average statistics */ + write_stats_avg(current); +} + +/* Initialization */ + +/* Get number of clock ticks per sec */ +static ALWAYS_INLINE unsigned get_hz(void) +{ + return sysconf(_SC_CLK_TCK); +} + +static void alloc_struct(int cpus) +{ + int i; + for (i = 0; i < 3; i++) { + G.st_cpu[i] = xzalloc(sizeof(G.st_cpu[i][0]) * cpus); + G.st_irq[i] = xzalloc(sizeof(G.st_irq[i][0]) * cpus); + G.st_irqcpu[i] = xzalloc(sizeof(G.st_irqcpu[i][0]) * cpus * G.irqcpu_nr); + G.st_softirqcpu[i] = xzalloc(sizeof(G.st_softirqcpu[i][0]) * cpus * G.softirqcpu_nr); + } + G.cpu_bitmap_len = (cpus >> 3) + 1; + G.cpu_bitmap = xzalloc(G.cpu_bitmap_len); +} + +static void print_header(struct tm *t) +{ + char cur_date[16]; + struct utsname uts; + + /* Get system name, release number and hostname */ + uname(&uts); + + strftime(cur_date, sizeof(cur_date), "%x", t); + + printf("%s %s (%s) \t%s \t_%s_\t(%d CPU)\n", + uts.sysname, uts.release, uts.nodename, cur_date, uts.machine, G.cpu_nr); +} + +/* + * Get number of processors in /sys + */ +static int get_sys_cpu_nr(void) +{ + DIR *dir; + struct dirent *d; + struct stat buf; + char line[MAX_PF_NAME]; + int proc_nr = 0; + + dir = opendir(SYSFS_DEVCPU); + if (!dir) + return 0; /* /sys not mounted */ + + /* Get current file entry */ + while ((d = readdir(dir)) != NULL) { + if (starts_with_cpu(d->d_name) && isdigit(d->d_name[3])) { + snprintf(line, MAX_PF_NAME, "%s/%s", SYSFS_DEVCPU, + d->d_name); + line[MAX_PF_NAME - 1] = '\0'; + /* Get information about file */ + if (stat(line, &buf) < 0) + continue; + /* If found 'cpuN', we have one more processor */ + if (S_ISDIR(buf.st_mode)) + proc_nr++; + } + } + + closedir(dir); + return proc_nr; +} + +/* + * Get number of processors in /proc/stat + * Return value '0' means one CPU and non SMP kernel. + * Otherwise N means N processor(s) and SMP kernel. + */ +static int get_proc_cpu_nr(void) +{ + FILE *fp; + char line[256]; + int proc_nr = -1; + + fp = xfopen_for_read(PROCFS_STAT); + while (fgets(line, sizeof(line), fp)) { + if (!starts_with_cpu(line)) { + if (proc_nr >= 0) + break; /* we are past "cpuN..." lines */ + continue; + } + if (line[3] != ' ') { /* "cpuN" */ + int num_proc; + if (sscanf(line + 3, "%u", &num_proc) == 1 + && num_proc > proc_nr + ) { + proc_nr = num_proc; + } + } + } + + fclose(fp); + return proc_nr + 1; +} + +static int get_cpu_nr(void) +{ + int n; + + /* Try to use /sys, if possible */ + n = get_sys_cpu_nr(); + if (n == 0) + /* Otherwise use /proc/stat */ + n = get_proc_cpu_nr(); + + return n; +} + +/* + * Get number of interrupts available per processor + */ +static int get_irqcpu_nr(const char *f, int max_irqs) +{ + FILE *fp; + char *line; + unsigned linelen; + unsigned irq; + + fp = fopen_for_read(f); + if (!fp) /* No interrupts file */ + return 0; + + linelen = INTERRUPTS_LINE + 16 * G.cpu_nr; + line = xmalloc(linelen); + + irq = 0; + while (fgets(line, linelen, fp) + && irq < max_irqs + ) { + int p = strcspn(line, ":"); + if ((p > 0) && (p < 16)) + irq++; + } + + fclose(fp); + free(line); + + return irq; +} + +//usage:#define mpstat_trivial_usage +//usage: "[-A] [-I SUM|CPU|ALL|SCPU] [-u] [-P num|ALL] [INTERVAL [COUNT]]" +//usage:#define mpstat_full_usage "\n\n" +//usage: "Per-processor statistics\n" +//usage: "\nOptions:" +//usage: "\n -A Same as -I ALL -u -P ALL" +//usage: "\n -I SUM|CPU|ALL|SCPU Report interrupt statistics" +//usage: "\n -P num|ALL Processor to monitor" +//usage: "\n -u Report CPU utilization" + +int mpstat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int mpstat_main(int UNUSED_PARAM argc, char **argv) +{ + char *opt_irq_fmt; + char *opt_set_cpu; + int i, opt; + enum { + OPT_ALL = 1 << 0, /* -A */ + OPT_INTS = 1 << 1, /* -I */ + OPT_SETCPU = 1 << 2, /* -P */ + OPT_UTIL = 1 << 3, /* -u */ + }; + + /* Dont buffer data if redirected to a pipe */ + setbuf(stdout, NULL); + + INIT_G(); + + G.interval = -1; + + /* Get number of processors */ + G.cpu_nr = get_cpu_nr(); + + /* Get number of clock ticks per sec */ + G.hz = get_hz(); + + /* Calculate number of interrupts per processor */ + G.irqcpu_nr = get_irqcpu_nr(PROCFS_INTERRUPTS, NR_IRQS) + NR_IRQCPU_PREALLOC; + + /* Calculate number of soft interrupts per processor */ + G.softirqcpu_nr = get_irqcpu_nr(PROCFS_SOFTIRQS, NR_IRQS) + NR_IRQCPU_PREALLOC; + + /* Allocate space for structures. + 1 for global structure. */ + alloc_struct(G.cpu_nr + 1); + + /* Parse and process arguments */ + opt = getopt32(argv, "AI:P:u", &opt_irq_fmt, &opt_set_cpu); + argv += optind; + + if (*argv) { + /* Get interval */ + G.interval = xatoi_u(*argv); + G.count = -1; + argv++; + if (*argv) { + /* Get count value */ + if (G.interval == 0) + bb_show_usage(); + G.count = xatoi_u(*argv); + //if (*++argv) + // bb_show_usage(); + } + } + if (G.interval < 0) + G.interval = 0; + + if (opt & OPT_ALL) { + G.p_option = 1; + G.options |= D_CPU + D_IRQ_SUM + D_IRQ_CPU + D_SOFTIRQS; + /* Select every CPU */ + memset(G.cpu_bitmap, 0xff, G.cpu_bitmap_len); + } + + if (opt & OPT_INTS) { + if (strcmp(opt_irq_fmt, "ALL") == 0) + G.options |= D_IRQ_SUM + D_IRQ_CPU + D_SOFTIRQS; + else if (strcmp(opt_irq_fmt, "CPU") == 0) + G.options |= D_IRQ_CPU; + else if (strcmp(opt_irq_fmt, "SUM") == 0) + G.options |= D_IRQ_SUM; + else if (strcmp(opt_irq_fmt, "SCPU") == 0) + G.options |= D_SOFTIRQS; + else + bb_show_usage(); + } + + if ((opt & OPT_UTIL) /* -u? */ + || G.options == 0 /* nothing? (use default then) */ + ) { + G.options |= D_CPU; + } + + if (opt & OPT_SETCPU) { + char *t; + G.p_option = 1; + + for (t = strtok(opt_set_cpu, ","); t; t = strtok(NULL, ",")) { + if (strcmp(t, "ALL") == 0) { + /* Select every CPU */ + memset(G.cpu_bitmap, 0xff, G.cpu_bitmap_len); + } else { + /* Get CPU number */ + unsigned n = xatoi_u(t); + if (n >= G.cpu_nr) + bb_error_msg_and_die("not that many processors"); + n++; + G.cpu_bitmap[n >> 3] |= 1 << (n & 7); + } + } + } + + if (!G.p_option) + /* Display global stats */ + G.cpu_bitmap[0] = 1; + + /* Get time */ + get_localtime(&G.timestamp[0]); + + /* Display header */ + print_header(&G.timestamp[0]); + + /* The main loop */ + main_loop(); + + if (ENABLE_FEATURE_CLEAN_UP) { + /* Clean up */ + for (i = 0; i < 3; i++) { + free(G.st_cpu[i]); + free(G.st_irq[i]); + free(G.st_irqcpu[i]); + free(G.st_softirqcpu[i]); + } + free(G.cpu_bitmap); + free(&G); + } + + return EXIT_SUCCESS; +} -- cgit v1.2.3-55-g6feb From 217df6ea9fe3fa93e2cf3e6b44cbec14a526f422 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 21 Jul 2010 11:54:33 +0200 Subject: mpstat: small code shrink Signed-off-by: Denys Vlasenko --- procps/mpstat.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/procps/mpstat.c b/procps/mpstat.c index 0f633c713..125bb3de7 100644 --- a/procps/mpstat.c +++ b/procps/mpstat.c @@ -57,7 +57,6 @@ struct stats_irqcpu { char irq_name[MAX_IRQ_LEN]; }; -/* Structure for CPU statistics */ struct stats_cpu { data_t cpu_user; data_t cpu_nice; @@ -70,13 +69,12 @@ struct stats_cpu { data_t cpu_guest; }; -/* Struct for interrupts statistics */ struct stats_irq { data_t irq_nr; }; -/* Globals. Try to sort by size. */ +/* Globals. Sort by size and access frequency. */ struct globals { int interval; int count; @@ -451,11 +449,10 @@ static void get_cpu_statistics(struct stats_cpu *cpu, data_t *up, data_t *up0) if (!starts_with_cpu(buf)) continue; /* not "cpu" */ - if (buf[3] == ' ') { - /* "cpu " */ - cp = cpu; - } else { - /* "cpuN" */ + + cp = cpu; /* for "cpu " case */ + if (buf[3] != ' ') { + /* "cpuN " */ if (G.cpu_nr == 0 || sscanf(buf + 3, "%u ", &cpu_number) != 1 || cpu_number >= G.cpu_nr @@ -465,17 +462,16 @@ static void get_cpu_statistics(struct stats_cpu *cpu, data_t *up, data_t *up0) cp = &cpu[cpu_number + 1]; } - /* Read the jiffies, save them */ + /* Read the counters, save them */ /* Not all fields have to be present */ memset(cp, 0, sizeof(*cp)); - sscanf(skip_non_whitespace(buf + 3), + sscanf(buf, "%*s" " %"FMT_DATA"u %"FMT_DATA"u %"FMT_DATA"u" " %"FMT_DATA"u %"FMT_DATA"u %"FMT_DATA"u" " %"FMT_DATA"u %"FMT_DATA"u %"FMT_DATA"u", &cp->cpu_user, &cp->cpu_nice, &cp->cpu_system, &cp->cpu_idle, &cp->cpu_iowait, &cp->cpu_irq, - &cp->cpu_softirq, &cp->cpu_steal, - &cp->cpu_guest + &cp->cpu_softirq, &cp->cpu_steal, &cp->cpu_guest ); /* * Compute uptime in jiffies (1/HZ), it'll be the sum of @@ -490,7 +486,7 @@ static void get_cpu_statistics(struct stats_cpu *cpu, data_t *up, data_t *up0) /* "cpu " */ *up = sum; } else { - /* "cpuN" */ + /* "cpuN " */ if (cpu_number == 0 && *up0 != 0) { /* Compute uptime of single CPU */ *up0 = sum; @@ -769,7 +765,7 @@ static void print_header(struct tm *t) strftime(cur_date, sizeof(cur_date), "%x", t); - printf("%s %s (%s) \t%s \t_%s_\t(%d CPU)\n", + printf("%s %s (%s)\t%s\t_%s_\t(%u CPU)\n", uts.sysname, uts.release, uts.nodename, cur_date, uts.machine, G.cpu_nr); } -- cgit v1.2.3-55-g6feb From c5fb0ada9b9efe65ceef3f2b5171573463e07b4f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 21 Jul 2010 12:39:42 +0200 Subject: vi: fix "ask terminal" code function old new delta edit_file 761 793 +32 refresh 773 780 +7 query_screen_dimensions 63 54 -9 Signed-off-by: Denys Vlasenko --- editors/vi.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/editors/vi.c b/editors/vi.c index 0f412c362..73e095cf8 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -504,20 +504,17 @@ static int init_text_buffer(char *fn) } #if ENABLE_FEATURE_VI_WIN_RESIZE -static void query_screen_dimensions(void) +static int query_screen_dimensions(void) { -# if ENABLE_FEATURE_VI_ASK_TERMINAL - if (!G.get_rowcol_error) - G.get_rowcol_error = -# endif - get_terminal_width_height(STDIN_FILENO, &columns, &rows); + int err = get_terminal_width_height(STDIN_FILENO, &columns, &rows); if (rows > MAX_SCR_ROWS) rows = MAX_SCR_ROWS; if (columns > MAX_SCR_COLS) columns = MAX_SCR_COLS; + return err; } #else -# define query_screen_dimensions() ((void)0) +# define query_screen_dimensions() (0) #endif static void edit_file(char *fn) @@ -536,7 +533,7 @@ static void edit_file(char *fn) rows = 24; columns = 80; size = 0; - query_screen_dimensions(); + IF_FEATURE_VI_ASK_TERMINAL(G.get_rowcol_error =) query_screen_dimensions(); #if ENABLE_FEATURE_VI_ASK_TERMINAL if (G.get_rowcol_error /* TODO? && no input on stdin */) { uint64_t k; @@ -546,9 +543,12 @@ static void edit_file(char *fn) if ((int32_t)k == KEYCODE_CURSOR_POS) { uint32_t rc = (k >> 32); columns = (rc & 0x7fff); + if (columns > MAX_SCR_COLS) + columns = MAX_SCR_COLS; rows = ((rc >> 16) & 0x7fff); + if (rows > MAX_SCR_ROWS) + rows = MAX_SCR_ROWS; } - query_screen_dimensions(); } #endif new_screen(rows, columns); // get memory for virtual screen @@ -2797,7 +2797,7 @@ static void refresh(int full_screen) int li, changed; char *tp, *sp; // pointer into text[] and screen[] - if (ENABLE_FEATURE_VI_WIN_RESIZE) { + if (ENABLE_FEATURE_VI_WIN_RESIZE IF_FEATURE_VI_ASK_TERMINAL(&& !G.get_rowcol_error) ) { unsigned c = columns, r = rows; query_screen_dimensions(); full_screen |= (c - columns) | (r - rows); -- cgit v1.2.3-55-g6feb From 4f0279bd930d02db2d5df51ce878b9b9b940f069 Mon Sep 17 00:00:00 2001 From: Maksym Kryzhanovskyy Date: Thu, 22 Jul 2010 02:18:05 +0200 Subject: ifplugd: code shrink function old new delta ifplugd_main 1089 1161 +72 method_table - 40 +40 detect_link 221 207 -14 static.method 40 - -40 netlink_open 79 - -79 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 1/1 up/down: 112/-133) Total: -21 bytes Signed-off-by: Denys Vlasenko --- networking/ifplugd.c | 333 +++++++++++++++++++++++++-------------------------- 1 file changed, 164 insertions(+), 169 deletions(-) diff --git a/networking/ifplugd.c b/networking/ifplugd.c index eb7442881..2f8c90ffc 100644 --- a/networking/ifplugd.c +++ b/networking/ifplugd.c @@ -71,16 +71,6 @@ enum { # define OPTION_STR "+ansfFi:r:It:u:d:m:pqlx:M" #endif -enum { // api mode - API_AUTO = 'a', - API_ETHTOOL = 'e', - API_MII = 'm', - API_PRIVATE = 'p', - API_WLAN = 'w', - API_IFF = 'i', -}; -static const char api_modes[] ALIGN1 = "aempwi"; - enum { // interface status IFSTATUS_ERR = -1, IFSTATUS_DOWN = 0, @@ -107,8 +97,6 @@ struct globals { const char *api_mode; const char *script_name; const char *extra_arg; - - smallint (*detect_link_func)(void); }; #define G (*ptr_to_globals) #define INIT_G() do { \ @@ -123,42 +111,12 @@ struct globals { } while (0) -static const char *strstatus(int status) -{ - if (status == IFSTATUS_ERR) - return "error"; - return "down\0up" + (status * 5); -} +/* Utility routines */ -static int run_script(const char *action) +static void set_ifreq_to_ifname(struct ifreq *ifreq) { - char *env_PREVIOUS, *env_CURRENT; - char *argv[5]; - int r; - - bb_error_msg("executing '%s %s %s'", G.script_name, G.iface, action); - - argv[0] = (char*) G.script_name; - argv[1] = (char*) G.iface; - argv[2] = (char*) action; - argv[3] = (char*) G.extra_arg; - argv[4] = NULL; - - env_PREVIOUS = xasprintf("%s=%s", IFPLUGD_ENV_PREVIOUS, strstatus(G.iface_prev_status)); - putenv(env_PREVIOUS); - env_CURRENT = xasprintf("%s=%s", IFPLUGD_ENV_CURRENT, strstatus(G.iface_last_status)); - putenv(env_CURRENT); - - /* r < 0 - can't exec, 0 <= r < 0x180 - exited, >=0x180 - killed by sig (r-0x180) */ - r = spawn_and_wait(argv); - - unsetenv(IFPLUGD_ENV_PREVIOUS); - unsetenv(IFPLUGD_ENV_CURRENT); - free(env_PREVIOUS); - free(env_CURRENT); - - bb_error_msg("exit code: %d", r & 0xff); - return (option_mask32 & FLAG_IGNORE_RETVAL) ? 0 : r; + memset(ifreq, 0, sizeof(struct ifreq)); + strncpy_IFNAMSIZ(ifreq->ifr_name, G.iface); } static int network_ioctl(int request, void* data, const char *errmsg) @@ -169,80 +127,7 @@ static int network_ioctl(int request, void* data, const char *errmsg) return r; } -static void set_ifreq_to_ifname(struct ifreq *ifreq) -{ - memset(ifreq, 0, sizeof(struct ifreq)); - strncpy_IFNAMSIZ(ifreq->ifr_name, G.iface); -} - -static void up_iface(void) -{ - struct ifreq ifrequest; - - if (!G.iface_exists) - return; - - set_ifreq_to_ifname(&ifrequest); - if (network_ioctl(SIOCGIFFLAGS, &ifrequest, "getting interface flags") < 0) { - G.iface_exists = 0; - return; - } - - if (!(ifrequest.ifr_flags & IFF_UP)) { - ifrequest.ifr_flags |= IFF_UP; - /* Let user know we mess up with interface */ - bb_error_msg("upping interface"); - if (network_ioctl(SIOCSIFFLAGS, &ifrequest, "setting interface flags") < 0) - xfunc_die(); - } - -#if 0 /* why do we mess with IP addr? It's not our business */ - if (network_ioctl(SIOCGIFADDR, &ifrequest, "can't get interface address") < 0) { - } else if (ifrequest.ifr_addr.sa_family != AF_INET) { - bb_perror_msg("the interface is not IP-based"); - } else { - ((struct sockaddr_in*)(&ifrequest.ifr_addr))->sin_addr.s_addr = INADDR_ANY; - network_ioctl(SIOCSIFADDR, &ifrequest, "can't set interface address"); - } - network_ioctl(SIOCGIFFLAGS, &ifrequest, "can't get interface flags"); -#endif -} - -static void maybe_up_new_iface(void) -{ - if (!(option_mask32 & FLAG_NO_AUTO)) - up_iface(); - -#if 0 /* bloat */ - struct ifreq ifrequest; - struct ethtool_drvinfo driver_info; - - set_ifreq_to_ifname(&ifrequest); - driver_info.cmd = ETHTOOL_GDRVINFO; - ifrequest.ifr_data = &driver_info; - if (network_ioctl(SIOCETHTOOL, &ifrequest, NULL) == 0) { - char buf[sizeof("/xx:xx:xx:xx:xx:xx")]; - - /* Get MAC */ - buf[0] = '\0'; - set_ifreq_to_ifname(&ifrequest); - if (network_ioctl(SIOCGIFHWADDR, &ifrequest, NULL) == 0) { - sprintf(buf, "/%02X:%02X:%02X:%02X:%02X:%02X", - (uint8_t)(ifrequest.ifr_hwaddr.sa_data[0]), - (uint8_t)(ifrequest.ifr_hwaddr.sa_data[1]), - (uint8_t)(ifrequest.ifr_hwaddr.sa_data[2]), - (uint8_t)(ifrequest.ifr_hwaddr.sa_data[3]), - (uint8_t)(ifrequest.ifr_hwaddr.sa_data[4]), - (uint8_t)(ifrequest.ifr_hwaddr.sa_data[5])); - } - - bb_error_msg("using interface %s%s with driver<%s> (version: %s)", - G.iface, buf, driver_info.driver, driver_info.version); - } -#endif - if (G.api_method_num == 0) - G.detect_link_func = NULL; -} +/* Link detection routines and table */ static smallint detect_link_mii(void) { @@ -349,18 +234,139 @@ static smallint detect_link_wlan(void) return IFSTATUS_UP; } +enum { // api mode + API_ETHTOOL, // 'e' + API_MII, // 'm' + API_PRIVATE, // 'p' + API_WLAN, // 'w' + API_IFF, // 'i' + API_AUTO, // 'a' +}; + +static const char api_modes[] ALIGN1 = "empwia"; + +static const struct { + const char *name; + smallint (*func)(void); +} method_table[] = { + { "SIOCETHTOOL" , &detect_link_ethtool }, + { "SIOCGMIIPHY" , &detect_link_mii }, + { "SIOCDEVPRIVATE" , &detect_link_priv }, + { "wireless extension", &detect_link_wlan }, + { "IFF_RUNNING" , &detect_link_iff }, +}; + + + +static const char *strstatus(int status) +{ + if (status == IFSTATUS_ERR) + return "error"; + return "down\0up" + (status * 5); +} + +static int run_script(const char *action) +{ + char *env_PREVIOUS, *env_CURRENT; + char *argv[5]; + int r; + + bb_error_msg("executing '%s %s %s'", G.script_name, G.iface, action); + + argv[0] = (char*) G.script_name; + argv[1] = (char*) G.iface; + argv[2] = (char*) action; + argv[3] = (char*) G.extra_arg; + argv[4] = NULL; + + env_PREVIOUS = xasprintf("%s=%s", IFPLUGD_ENV_PREVIOUS, strstatus(G.iface_prev_status)); + putenv(env_PREVIOUS); + env_CURRENT = xasprintf("%s=%s", IFPLUGD_ENV_CURRENT, strstatus(G.iface_last_status)); + putenv(env_CURRENT); + + /* r < 0 - can't exec, 0 <= r < 0x180 - exited, >=0x180 - killed by sig (r-0x180) */ + r = spawn_and_wait(argv); + + unsetenv(IFPLUGD_ENV_PREVIOUS); + unsetenv(IFPLUGD_ENV_CURRENT); + free(env_PREVIOUS); + free(env_CURRENT); + + bb_error_msg("exit code: %d", r & 0xff); + return (option_mask32 & FLAG_IGNORE_RETVAL) ? 0 : r; +} + +static void up_iface(void) +{ + struct ifreq ifrequest; + + if (!G.iface_exists) + return; + + set_ifreq_to_ifname(&ifrequest); + if (network_ioctl(SIOCGIFFLAGS, &ifrequest, "getting interface flags") < 0) { + G.iface_exists = 0; + return; + } + + if (!(ifrequest.ifr_flags & IFF_UP)) { + ifrequest.ifr_flags |= IFF_UP; + /* Let user know we mess up with interface */ + bb_error_msg("upping interface"); + if (network_ioctl(SIOCSIFFLAGS, &ifrequest, "setting interface flags") < 0) + xfunc_die(); + } + +#if 0 /* why do we mess with IP addr? It's not our business */ + if (network_ioctl(SIOCGIFADDR, &ifrequest, "can't get interface address") < 0) { + } else if (ifrequest.ifr_addr.sa_family != AF_INET) { + bb_perror_msg("the interface is not IP-based"); + } else { + ((struct sockaddr_in*)(&ifrequest.ifr_addr))->sin_addr.s_addr = INADDR_ANY; + network_ioctl(SIOCSIFADDR, &ifrequest, "can't set interface address"); + } + network_ioctl(SIOCGIFFLAGS, &ifrequest, "can't get interface flags"); +#endif +} + +static void maybe_up_new_iface(void) +{ + if (!(option_mask32 & FLAG_NO_AUTO)) + up_iface(); + +#if 0 /* bloat */ + struct ifreq ifrequest; + struct ethtool_drvinfo driver_info; + + set_ifreq_to_ifname(&ifrequest); + driver_info.cmd = ETHTOOL_GDRVINFO; + ifrequest.ifr_data = &driver_info; + if (network_ioctl(SIOCETHTOOL, &ifrequest, NULL) == 0) { + char buf[sizeof("/xx:xx:xx:xx:xx:xx")]; + + /* Get MAC */ + buf[0] = '\0'; + set_ifreq_to_ifname(&ifrequest); + if (network_ioctl(SIOCGIFHWADDR, &ifrequest, NULL) == 0) { + sprintf(buf, "/%02X:%02X:%02X:%02X:%02X:%02X", + (uint8_t)(ifrequest.ifr_hwaddr.sa_data[0]), + (uint8_t)(ifrequest.ifr_hwaddr.sa_data[1]), + (uint8_t)(ifrequest.ifr_hwaddr.sa_data[2]), + (uint8_t)(ifrequest.ifr_hwaddr.sa_data[3]), + (uint8_t)(ifrequest.ifr_hwaddr.sa_data[4]), + (uint8_t)(ifrequest.ifr_hwaddr.sa_data[5])); + } + + bb_error_msg("using interface %s%s with driver<%s> (version: %s)", + G.iface, buf, driver_info.driver, driver_info.version); + } +#endif + if (G.api_mode[0] == 'a') + G.api_method_num = API_AUTO; +} + static smallint detect_link(void) { - static const struct { - const char *name; - smallint (*func)(void); - } method[] = { - { "SIOCETHTOOL" , &detect_link_ethtool }, - { "SIOCGMIIPHY" , &detect_link_mii }, - { "SIOCDEVPRIVATE" , &detect_link_priv }, - { "wireless extension", &detect_link_wlan }, - { "IFF_RUNNING" , &detect_link_iff }, - }; smallint status; if (!G.iface_exists) @@ -373,38 +379,34 @@ static smallint detect_link(void) if (!(option_mask32 & FLAG_NO_AUTO)) up_iface(); - if (!G.detect_link_func) { - if (G.api_method_num == 0) { - int i; - smallint sv_logmode; - - sv_logmode = logmode; - for (i = 0; i < ARRAY_SIZE(method); i++) { - logmode = LOGMODE_NONE; - status = method[i].func(); - logmode = sv_logmode; - if (status != IFSTATUS_ERR) { - G.detect_link_func = method[i].func; - bb_error_msg("using %s detection mode", method[i].name); - goto _2; - } + if (G.api_method_num == API_AUTO) { + int i; + smallint sv_logmode; + + sv_logmode = logmode; + for (i = 0; i < ARRAY_SIZE(method_table); i++) { + logmode = LOGMODE_NONE; + status = method_table[i].func(); + logmode = sv_logmode; + if (status != IFSTATUS_ERR) { + G.api_method_num = i; + bb_error_msg("using %s detection mode", method_table[i].name); + break; } - goto _1; } - G.detect_link_func = method[G.api_method_num - 1].func; + } else { + status = method_table[G.api_method_num].func(); } - status = G.detect_link_func(); - _1: if (status == IFSTATUS_ERR) { if (option_mask32 & FLAG_IGNORE_FAIL) status = IFSTATUS_DOWN; else if (option_mask32 & FLAG_IGNORE_FAIL_POSITIVE) status = IFSTATUS_UP; - else if (G.api_method_num == 0) + else if (G.api_mode[0] == 'a') bb_error_msg("can't detect link status"); } - _2: + if (status != G.iface_last_status) { G.iface_prev_status = G.iface_last_status; G.iface_last_status = status; @@ -475,23 +477,6 @@ static NOINLINE int check_existence_through_netlink(void) return G.iface_exists; } -static NOINLINE int netlink_open(void) -{ - int fd; - struct sockaddr_nl addr; - - fd = xsocket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); - - memset(&addr, 0, sizeof(addr)); - addr.nl_family = AF_NETLINK; - addr.nl_groups = RTMGRP_LINK; - addr.nl_pid = getpid(); - - xbind(fd, (struct sockaddr*)&addr, sizeof(addr)); - - return fd; -} - #if ENABLE_FEATURE_PIDFILE static NOINLINE pid_t read_pid(const char *filename) { @@ -545,6 +530,7 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) if (pid_from_pidfile > 0 && kill(pid_from_pidfile, 0) == 0) bb_error_msg_and_die("daemon already running"); #endif + api_mode_found = strchr(api_modes, G.api_mode[0]); if (!api_mode_found) bb_error_msg_and_die("unknown API mode '%s'", G.api_mode); @@ -555,7 +541,16 @@ int ifplugd_main(int argc UNUSED_PARAM, char **argv) xmove_fd(xsocket(AF_INET, SOCK_DGRAM, 0), ioctl_fd); if (opts & FLAG_MONITOR) { - xmove_fd(netlink_open(), netlink_fd); + struct sockaddr_nl addr; + int fd = xsocket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); + + memset(&addr, 0, sizeof(addr)); + addr.nl_family = AF_NETLINK; + addr.nl_groups = RTMGRP_LINK; + addr.nl_pid = getpid(); + + xbind(fd, (struct sockaddr*)&addr, sizeof(addr)); + xmove_fd(fd, netlink_fd); } write_pidfile(pidfile_name); -- cgit v1.2.3-55-g6feb From b78ac5a20ea2f3038f9738cb05bc3bc3725fabba Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 23 Jul 2010 01:31:24 +0200 Subject: libnetlink: code shrink function old new delta xrtnl_open 95 93 -2 parse_rtattr 87 85 -2 rtnl_close 9 - -9 xrtnl_wilddump_request 101 64 -37 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/3 up/down: 0/-50) Total: -50 bytes Signed-off-by: Natanael Copa Signed-off-by: Denys Vlasenko --- networking/libiproute/libnetlink.c | 38 ++++++++++++++------------------------ networking/libiproute/libnetlink.h | 6 +++--- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index ba24832d6..8da80b2fc 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c @@ -1,14 +1,13 @@ /* vi: set sw=4 ts=4: */ /* - * libnetlink.c RTnetlink service routines. + * RTnetlink service routines. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version - * 2 of the License, or (at your option) any later version. - * - * Authors: Alexey Kuznetsov, + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. * + * Authors: Alexey Kuznetsov, */ #include @@ -17,12 +16,7 @@ #include "libbb.h" #include "libnetlink.h" -void FAST_FUNC rtnl_close(struct rtnl_handle *rth) -{ - close(rth->fd); -} - -int FAST_FUNC xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/) +void FAST_FUNC xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/) { socklen_t addr_len; @@ -44,7 +38,6 @@ int FAST_FUNC xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/) bb_error_msg_and_die("wrong address family %d", rth->local.nl_family); */ rth->seq = time(NULL); - return 0; } int FAST_FUNC xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) @@ -53,10 +46,6 @@ int FAST_FUNC xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int ty struct nlmsghdr nlh; struct rtgenmsg g; } req; - struct sockaddr_nl nladdr; - - memset(&nladdr, 0, sizeof(nladdr)); - nladdr.nl_family = AF_NETLINK; req.nlh.nlmsg_len = sizeof(req); req.nlh.nlmsg_type = type; @@ -65,8 +54,7 @@ int FAST_FUNC xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int ty req.nlh.nlmsg_seq = rth->dump = ++rth->seq; req.g.rtgen_family = family; - return xsendto(rth->fd, (void*)&req, sizeof(req), - (struct sockaddr*)&nladdr, sizeof(nladdr)); + return rtnl_send(rth, (void*)&req, sizeof(req)); } int FAST_FUNC rtnl_send(struct rtnl_handle *rth, char *buf, int len) @@ -339,8 +327,10 @@ int FAST_FUNC addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data) { int len = RTA_LENGTH(4); struct rtattr *rta; - if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) + + if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) { return -1; + } rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); rta->rta_type = type; rta->rta_len = len; @@ -354,8 +344,9 @@ int FAST_FUNC addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, in int len = RTA_LENGTH(alen); struct rtattr *rta; - if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) + if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) { return -1; + } rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); rta->rta_type = type; rta->rta_len = len; @@ -397,7 +388,7 @@ int FAST_FUNC rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data } -int FAST_FUNC parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) +void FAST_FUNC parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) { while (RTA_OK(rta, len)) { if (rta->rta_type <= max) { @@ -408,5 +399,4 @@ int FAST_FUNC parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int if (len) { bb_error_msg("deficit %d, rta_len=%d!", len, rta->rta_len); } - return 0; } diff --git a/networking/libiproute/libnetlink.h b/networking/libiproute/libnetlink.h index 41ecfa6d0..4e4d5b7b9 100644 --- a/networking/libiproute/libnetlink.h +++ b/networking/libiproute/libnetlink.h @@ -18,8 +18,8 @@ struct rtnl_handle { uint32_t dump; }; -extern int xrtnl_open(struct rtnl_handle *rth) FAST_FUNC; -extern void rtnl_close(struct rtnl_handle *rth) FAST_FUNC; +extern void xrtnl_open(struct rtnl_handle *rth) FAST_FUNC; +#define rtnl_close(rth) (close((rth)->fd)) extern int xrtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type) FAST_FUNC; extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) FAST_FUNC; extern int xrtnl_dump_filter(struct rtnl_handle *rth, @@ -42,7 +42,7 @@ extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int a extern int rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t data) FAST_FUNC; extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen) FAST_FUNC; -extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) FAST_FUNC; +extern void parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) FAST_FUNC; POP_SAVED_FUNCTION_VISIBILITY -- cgit v1.2.3-55-g6feb From e0a622093c6c1f3e3a1f58713118395994000fd9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 24 Jul 2010 23:26:58 +0200 Subject: ip: fix "ip r" breakage function old new delta static.ip_func_ptrs - 32 +32 ip_main 110 53 -57 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 32/-57) Total: -25 bytes Signed-off-by: Denys Vlasenko --- networking/ip.c | 62 +++++++++++++++++++++------------------------------------ 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/networking/ip.c b/networking/ip.c index 7a0f308f0..3a99fa320 100644 --- a/networking/ip.c +++ b/networking/ip.c @@ -1,14 +1,12 @@ /* vi: set sw=4 ts=4: */ /* - * ip.c "ip" utility frontend. + * "ip" utility frontend. * * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. * - * Authors: Alexey Kuznetsov, - * + * Authors: Alexey Kuznetsov, * * Changes: - * * Rani Assaf 980929: resolve addresses * Bernhard Reutner-Fischer rewrote to use index_in_substr_array */ @@ -24,12 +22,14 @@ || ENABLE_FEATURE_IP_TUNNEL \ || ENABLE_FEATURE_IP_RULE -static int NORETURN ip_print_help(char **argv UNUSED_PARAM) +static int ip_print_help(char **argv UNUSED_PARAM) { bb_show_usage(); } -static int ip_do(int (*ip_func)(char **argv), char **argv) +typedef int (*ip_func_ptr_t)(char**); + +static int ip_do(ip_func_ptr_t ip_func, char **argv) { argv = ip_parse_common_args(argv + 1); return ip_func(argv); @@ -78,45 +78,29 @@ int ip_main(int argc UNUSED_PARAM, char **argv) static const char keywords[] ALIGN1 = IF_FEATURE_IP_ADDRESS("address\0") IF_FEATURE_IP_ROUTE("route\0") + IF_FEATURE_IP_ROUTE("r\0") IF_FEATURE_IP_LINK("link\0") - IF_FEATURE_IP_TUNNEL("tunnel\0" "tunl\0") + IF_FEATURE_IP_TUNNEL("tunnel\0") + IF_FEATURE_IP_TUNNEL("tunl\0") IF_FEATURE_IP_RULE("rule\0") ; - enum { - IF_FEATURE_IP_ADDRESS(IP_addr,) - IF_FEATURE_IP_ROUTE(IP_route,) - IF_FEATURE_IP_LINK(IP_link,) - IF_FEATURE_IP_TUNNEL(IP_tunnel, IP_tunl,) - IF_FEATURE_IP_RULE(IP_rule,) - IP_none + static const ip_func_ptr_t ip_func_ptrs[] = { + ip_print_help, + IF_FEATURE_IP_ADDRESS(do_ipaddr,) + IF_FEATURE_IP_ROUTE(do_iproute,) + IF_FEATURE_IP_ROUTE(do_iproute,) + IF_FEATURE_IP_LINK(do_iplink,) + IF_FEATURE_IP_TUNNEL(do_iptunnel,) + IF_FEATURE_IP_TUNNEL(do_iptunnel,) + IF_FEATURE_IP_RULE(do_iprule,) }; - int (*ip_func)(char**) = ip_print_help; + ip_func_ptr_t ip_func; + int key; argv = ip_parse_common_args(argv + 1); - if (*argv) { - int key = index_in_substrings(keywords, *argv); - argv++; -#if ENABLE_FEATURE_IP_ADDRESS - if (key == IP_addr) - ip_func = do_ipaddr; -#endif -#if ENABLE_FEATURE_IP_ROUTE - if (key == IP_route) - ip_func = do_iproute; -#endif -#if ENABLE_FEATURE_IP_LINK - if (key == IP_link) - ip_func = do_iplink; -#endif -#if ENABLE_FEATURE_IP_TUNNEL - if (key == IP_tunnel || key == IP_tunl) - ip_func = do_iptunnel; -#endif -#if ENABLE_FEATURE_IP_RULE - if (key == IP_rule) - ip_func = do_iprule; -#endif - } + key = *argv ? index_in_substrings(keywords, *argv++) : -1; + ip_func = ip_func_ptrs[key + 1]; + return ip_func(argv); } -- cgit v1.2.3-55-g6feb From 2e9b5510d687e5418bea85c3b04ad1e1fa797b6f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 24 Jul 2010 23:27:38 +0200 Subject: libiproute: code shrink by adding FAST_FUNC function old new delta ipaddr_list_or_flush 1282 1293 +11 ip_parse_common_args 153 151 -2 ip_main 53 50 -3 ip_do 19 15 -4 do_iptunnel 985 980 -5 do_iprule 982 977 -5 do_iplink 1637 1631 -6 do_iproute 2105 2098 -7 do_ipaddr 1406 1398 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/8 up/down: 11/-40) Total: -29 bytes Signed-off-by: Denys Vlasenko --- networking/ip.c | 4 ++-- networking/libiproute/ip_common.h | 29 ++++++++++++++-------------- networking/libiproute/ip_parse_common_args.c | 2 +- networking/libiproute/ipaddress.c | 4 ++-- networking/libiproute/iplink.c | 2 +- networking/libiproute/iproute.c | 2 +- networking/libiproute/iprule.c | 2 +- networking/libiproute/iptunnel.c | 2 +- 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/networking/ip.c b/networking/ip.c index 3a99fa320..004289667 100644 --- a/networking/ip.c +++ b/networking/ip.c @@ -22,12 +22,12 @@ || ENABLE_FEATURE_IP_TUNNEL \ || ENABLE_FEATURE_IP_RULE -static int ip_print_help(char **argv UNUSED_PARAM) +static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM) { bb_show_usage(); } -typedef int (*ip_func_ptr_t)(char**); +typedef int FAST_FUNC (*ip_func_ptr_t)(char**); static int ip_do(ip_func_ptr_t ip_func, char **argv) { diff --git a/networking/libiproute/ip_common.h b/networking/libiproute/ip_common.h index aef325281..30c7e595b 100644 --- a/networking/libiproute/ip_common.h +++ b/networking/libiproute/ip_common.h @@ -15,22 +15,21 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN -extern char **ip_parse_common_args(char **argv); -extern int print_neigh(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); -extern int ipaddr_list_or_flush(char **argv, int flush); -extern int iproute_monitor(char **argv); -extern void iplink_usage(void) NORETURN; -extern void ipneigh_reset_filter(void); +char FAST_FUNC **ip_parse_common_args(char **argv); +//int FAST_FUNC print_neigh(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); +int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush); +//int FAST_FUNC iproute_monitor(char **argv); +//void FAST_FUNC ipneigh_reset_filter(void); -extern int do_ipaddr(char **argv); -extern int do_iproute(char **argv); -extern int do_iprule(char **argv); -extern int do_ipneigh(char **argv); -extern int do_iptunnel(char **argv); -extern int do_iplink(char **argv); -extern int do_ipmonitor(char **argv); -extern int do_multiaddr(char **argv); -extern int do_multiroute(char **argv); +int FAST_FUNC do_ipaddr(char **argv); +int FAST_FUNC do_iproute(char **argv); +int FAST_FUNC do_iprule(char **argv); +//int FAST_FUNC do_ipneigh(char **argv); +int FAST_FUNC do_iptunnel(char **argv); +int FAST_FUNC do_iplink(char **argv); +//int FAST_FUNC do_ipmonitor(char **argv); +//int FAST_FUNC do_multiaddr(char **argv); +//int FAST_FUNC do_multiroute(char **argv); POP_SAVED_FUNCTION_VISIBILITY diff --git a/networking/libiproute/ip_parse_common_args.c b/networking/libiproute/ip_parse_common_args.c index 5e4012b81..bf01528c4 100644 --- a/networking/libiproute/ip_parse_common_args.c +++ b/networking/libiproute/ip_parse_common_args.c @@ -22,7 +22,7 @@ family_t preferred_family = AF_UNSPEC; smallint oneline; char _SL_; -char **ip_parse_common_args(char **argv) +char** FAST_FUNC ip_parse_common_args(char **argv) { static const char ip_common_commands[] ALIGN1 = "oneline" "\0" diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 381293412..b6f469d0f 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -415,7 +415,7 @@ static void ipaddr_reset_filter(int _oneline) } /* Return value becomes exitcode. It's okay to not return at all */ -int ipaddr_list_or_flush(char **argv, int flush) +int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush) { static const char option[] ALIGN1 = "to\0""scope\0""up\0""label\0""dev\0"; @@ -747,7 +747,7 @@ static int ipaddr_modify(int cmd, char **argv) } /* Return value becomes exitcode. It's okay to not return at all */ -int do_ipaddr(char **argv) +int FAST_FUNC do_ipaddr(char **argv) { static const char commands[] ALIGN1 = "add\0""delete\0""list\0""show\0""lst\0""flush\0"; diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c index 8bf892797..9f9218573 100644 --- a/networking/libiproute/iplink.c +++ b/networking/libiproute/iplink.c @@ -362,7 +362,7 @@ static int do_change(char **argv, const unsigned rtm) } /* Return value becomes exitcode. It's okay to not return at all */ -int do_iplink(char **argv) +int FAST_FUNC do_iplink(char **argv) { static const char keywords[] ALIGN1 = "add\0""delete\0""set\0""show\0""lst\0""list\0"; diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index d771a609b..8dba2bf3d 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c @@ -869,7 +869,7 @@ static int iproute_get(char **argv) } /* Return value becomes exitcode. It's okay to not return at all */ -int do_iproute(char **argv) +int FAST_FUNC do_iproute(char **argv) { static const char ip_route_commands[] ALIGN1 = /*0-3*/ "add\0""append\0""change\0""chg\0" diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c index 835529ec4..3af6a83a8 100644 --- a/networking/libiproute/iprule.c +++ b/networking/libiproute/iprule.c @@ -304,7 +304,7 @@ static int iprule_modify(int cmd, char **argv) } /* Return value becomes exitcode. It's okay to not return at all */ -int do_iprule(char **argv) +int FAST_FUNC do_iprule(char **argv) { static const char ip_rule_commands[] ALIGN1 = "add\0""delete\0""list\0""show\0"; diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c index 257343826..8389ef348 100644 --- a/networking/libiproute/iptunnel.c +++ b/networking/libiproute/iptunnel.c @@ -556,7 +556,7 @@ static int do_show(char **argv) } /* Return value becomes exitcode. It's okay to not return at all */ -int do_iptunnel(char **argv) +int FAST_FUNC do_iptunnel(char **argv) { static const char keywords[] ALIGN1 = "add\0""change\0""delete\0""show\0""list\0""lst\0"; -- cgit v1.2.3-55-g6feb From 451add4f23c14459734e05104ea0bc5ed4de39ee Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 25 Jul 2010 00:06:41 +0200 Subject: lineedit: mostly revert recent wrong logic in "ask terminal" code Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index a62ab6d29..6df556f4e 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -149,7 +149,6 @@ struct lineedit_statics { CHAR_T delbuf[DELBUFSIZ]; /* a place to store deleted characters */ #endif #if ENABLE_FEATURE_EDITING_ASK_TERMINAL - smallint unknown_width; smallint sent_ESC_br6n; #endif @@ -1611,16 +1610,14 @@ static void ask_terminal(void) * poll([{fd=0, events=POLLIN}], 1, 4294967295) = 1 ([{fd=0, revents=POLLIN}]) * read(0, "\n", 1) = 1 <-- oh crap, user's input got in first */ - if (S.unknown_width) { /* only if window size is not known */ - struct pollfd pfd; - - pfd.fd = STDIN_FILENO; - pfd.events = POLLIN; - if (safe_poll(&pfd, 1, 0) == 0) { - S.sent_ESC_br6n = 1; - fputs("\033" "[6n", stdout); - fflush_all(); /* make terminal see it ASAP! */ - } + struct pollfd pfd; + + pfd.fd = STDIN_FILENO; + pfd.events = POLLIN; + if (safe_poll(&pfd, 1, 0) == 0) { + S.sent_ESC_br6n = 1; + fputs("\033" "[6n", stdout); + fflush_all(); /* make terminal see it ASAP! */ } } #else @@ -1768,7 +1765,7 @@ static void win_changed(int nsig) { int sv_errno = errno; unsigned width; - IF_FEATURE_EDITING_ASK_TERMINAL(S.unknown_width =) get_terminal_width_height(0, &width, NULL); + get_terminal_width_height(0, &width, NULL); cmdedit_setwidth(width, nsig /* - just a yes/no flag */); if (nsig == SIGWINCH) signal(SIGWINCH, win_changed); /* rearm ourself */ -- cgit v1.2.3-55-g6feb From 535ce1df5cb6a2bf588e1c2655cf09f49ed455db Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 25 Jul 2010 03:20:25 +0200 Subject: httpd: cosmetic fixes, no code changes Signed-off-by: Denys Vlasenko --- networking/httpd.c | 53 +++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/networking/httpd.c b/networking/httpd.c index 8ad7e88b1..12bad597a 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -5,23 +5,20 @@ * Copyright (C) 2002,2003 Glenn Engel * Copyright (C) 2003-2006 Vladimir Oleynik * - * simplify patch stolen from libbb without using strdup - * * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. * ***************************************************************************** * * Typical usage: - * for non root user - * httpd -p 8080 -h $HOME/public_html - * or for daemon start from rc script with uid=0: - * httpd -u www - * This is equivalent if www user have uid=80 to - * httpd -p 80 -u 80 -h /www -c /etc/httpd.conf -r "Web Server Authentication" - * + * For non root user: + * httpd -p 8080 -h $HOME/public_html + * For daemon start from rc script with uid=0: + * httpd -u www + * which is equivalent to (assuming user www has uid 80): + * httpd -p 80 -u 80 -h $PWD -c /etc/httpd.conf -r "Web Server Authentication" * - * When an url starts by "/cgi-bin/" it is assumed to be a cgi script. The - * server changes directory to the location of the script and executes it + * When an url starts with "/cgi-bin/" it is assumed to be a cgi script. + * The server changes directory to the location of the script and executes it * after setting QUERY_STRING and other environment variables. * * Doc: @@ -29,8 +26,8 @@ * * The applet can also be invoked as an url arg decoder and html text encoder * as follows: - * foo=`httpd -d $foo` # decode "Hello%20World" as "Hello World" - * bar=`httpd -e ""` # encode as "<Hello World>" + * foo=`httpd -d $foo` # decode "Hello%20World" as "Hello World" + * bar=`httpd -e ""` # encode as "<Hello World>" * Note that url encoding for arguments is not the same as html encoding for * presentation. -d decodes an url-encoded argument while -e encodes in html * for page display. @@ -100,15 +97,14 @@ #if ENABLE_FEATURE_HTTPD_USE_SENDFILE # include #endif - -#define DEBUG 0 - -#define IOBUF_SIZE 8192 /* IO buffer */ - /* amount of buffering in a pipe */ #ifndef PIPE_BUF # define PIPE_BUF 4096 #endif + +#define DEBUG 0 + +#define IOBUF_SIZE 8192 #if PIPE_BUF >= IOBUF_SIZE # error "PIPE_BUF >= IOBUF_SIZE" #endif @@ -118,6 +114,7 @@ static const char DEFAULT_PATH_HTTPD_CONF[] ALIGN1 = "/etc"; static const char HTTPD_CONF[] ALIGN1 = "httpd.conf"; static const char HTTP_200[] ALIGN1 = "HTTP/1.0 200 OK\r\n"; +static const char index_html[] ALIGN1 = "index.html"; typedef struct has_next_ptr { struct has_next_ptr *next; @@ -170,7 +167,6 @@ enum { HTTP_PAYMENT_REQUIRED = 402, HTTP_BAD_GATEWAY = 502, HTTP_SERVICE_UNAVAILABLE = 503, /* overload, maintenance */ - HTTP_RESPONSE_SETSIZE = 0xffffffff #endif }; @@ -231,9 +227,6 @@ static const struct { #endif }; -static const char index_html[] ALIGN1 = "index.html"; - - struct globals { int verbose; /* must be int (used by getopt32) */ smallint flg_deny_all; @@ -777,7 +770,7 @@ static char *encodeString(const char *string) char *p = out; char ch; - while ((ch = *string++)) { + while ((ch = *string++) != '\0') { /* very simple check for what to encode */ if (isalnum(ch)) *p++ = ch; @@ -787,7 +780,7 @@ static char *encodeString(const char *string) *p = '\0'; return out; } -#endif /* FEATURE_HTTPD_ENCODE_URL_STR */ +#endif /* * Given a URL encoded string, convert it to plain ascii. @@ -814,12 +807,12 @@ static unsigned hex_to_bin(unsigned char c) if (v <= 5) return v + 10; return ~0; -} /* For testing: void t(char c) { printf("'%c'(%u) %u\n", c, c, hex_to_bin(c)); } int main() { t(0x10); t(0x20); t('0'); t('9'); t('A'); t('F'); t('a'); t('f'); t('0'-1); t('9'+1); t('A'-1); t('F'+1); t('a'-1); t('f'+1); return 0; } */ +} static char *decodeString(char *orig, int option_d) { /* note that decoded string is always shorter than original */ @@ -1964,7 +1957,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) if (http_major_version >= '0') { /* Request was with "... HTTP/nXXX", and n >= 0 */ - /* Read until blank line for HTTP version specified, else parse immediate */ + /* Read until blank line */ while (1) { if (!get_line()) break; /* EOF or error or empty line */ @@ -1991,9 +1984,9 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) if ((STRNCASECMP(iobuf, "Content-length:") == 0)) { /* extra read only for POST */ if (prequest != request_GET -#if ENABLE_FEATURE_HTTPD_CGI +# if ENABLE_FEATURE_HTTPD_CGI && prequest != request_HEAD -#endif +# endif ) { tptr = skip_whitespace(iobuf + sizeof("Content-length:") - 1); if (!tptr[0]) @@ -2183,9 +2176,9 @@ static void mini_httpd(int server_socket) /* Wait for connections... */ fromAddr.len = LSA_SIZEOF_SA; n = accept(server_socket, &fromAddr.u.sa, &fromAddr.len); - if (n < 0) continue; + /* set the KEEPALIVE option to cull dead connections */ setsockopt(n, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); @@ -2226,9 +2219,9 @@ static void mini_httpd_nommu(int server_socket, int argc, char **argv) /* Wait for connections... */ fromAddr.len = LSA_SIZEOF_SA; n = accept(server_socket, &fromAddr.u.sa, &fromAddr.len); - if (n < 0) continue; + /* set the KEEPALIVE option to cull dead connections */ setsockopt(n, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); -- cgit v1.2.3-55-g6feb From 7a2ba329b9235af4c647e0a88c1db023b51cf8a4 Mon Sep 17 00:00:00 2001 From: Peter Korsgaard Date: Sun, 25 Jul 2010 03:20:53 +0200 Subject: httpd: optional support for gzip-compressed pages function old new delta send_file_and_exit 662 761 +99 handle_incoming_and_exit 2756 2830 +74 send_headers 603 654 +51 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 224/0) Total: 224 bytes Signed-off-by: Peter Korsgaard Signed-off-by: Denys Vlasenko --- networking/Config.src | 8 ++++++++ networking/httpd.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/networking/Config.src b/networking/Config.src index 2d29c423a..8604c53e9 100644 --- a/networking/Config.src +++ b/networking/Config.src @@ -270,6 +270,14 @@ config FEATURE_HTTPD_PROXY Then a request to /url/myfile will be forwarded to http://hostname[:port]/new/path/myfile. +config FEATURE_HTTPD_GZIP + bool "Support for GZIP content encoding" + default y + depends on HTTPD + help + Makes httpd send files using GZIP content encoding if the + client supports it and a pre-compressed .gz exists. + config IFCONFIG bool "ifconfig" default y diff --git a/networking/httpd.c b/networking/httpd.c index 12bad597a..cad45cd5d 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -277,6 +277,10 @@ struct globals { #if ENABLE_FEATURE_HTTPD_PROXY Htaccess_Proxy *proxy; #endif +#if ENABLE_FEATURE_HTTPD_GZIP + /* client can handle gzip / we are going to send gzip */ + smallint content_gzip; +#endif }; #define G (*ptr_to_globals) #define verbose (G.verbose ) @@ -319,6 +323,11 @@ enum { #define hdr_cnt (G.hdr_cnt ) #define http_error_page (G.http_error_page ) #define proxy (G.proxy ) +#if ENABLE_FEATURE_HTTPD_GZIP +# define content_gzip (G.content_gzip ) +#else +# define content_gzip 0 +#endif #define INIT_G() do { \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \ @@ -1027,10 +1036,14 @@ static void send_headers(int responseNum) #endif "Last-Modified: %s\r\n%s %"OFF_FMT"u\r\n", tmp_str, - "Content-length:", + content_gzip ? "Transfer-length:" : "Content-length:", file_size ); } + + if (content_gzip) + len += sprintf(iobuf + len, "Content-Encoding: gzip\r\n"); + iobuf[len++] = '\r'; iobuf[len++] = '\n'; if (infoString) { @@ -1500,7 +1513,22 @@ static NOINLINE void send_file_and_exit(const char *url, int what) int fd; ssize_t count; - fd = open(url, O_RDONLY); + if (content_gzip) { + /* does .gz exist? Then use it instead */ + char *gzurl = xasprintf("%s.gz", url); + fd = open(gzurl, O_RDONLY); + free(gzurl); + if (fd != -1) { + struct stat sb; + fstat(fd, &sb); + file_size = sb.st_size; + } else { + IF_FEATURE_HTTPD_GZIP(content_gzip = 0;) + fd = open(url, O_RDONLY); + } + } else { + fd = open(url, O_RDONLY); + } if (fd < 0) { if (DEBUG) bb_perror_msg("can't open '%s'", url); @@ -1583,8 +1611,11 @@ static NOINLINE void send_file_and_exit(const char *url, int what) url, found_mime_type); #if ENABLE_FEATURE_HTTPD_RANGES - if (what == SEND_BODY) - range_start = 0; /* err pages and ranges don't mix */ + if (what == SEND_BODY /* err pages and ranges don't mix */ + || content_gzip /* we are sending compressed page: can't do ranges */ ///why? + ) { + range_start = 0; + } range_len = MAXINT(off_t); if (range_start) { if (!range_end) { @@ -2047,6 +2078,23 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) } } } +#endif +#if ENABLE_FEATURE_HTTPD_GZIP + if (STRNCASECMP(iobuf, "Accept-Encoding:") == 0) { + char *s = iobuf + sizeof("Accept-Encoding:")-1; + while (*s) { + ///is "Accept-Encoding: compress,gzip" valid? + // (that is, no space after ',') - + // this code won't handle that + s = skip_whitespace(s); + if (STRNCASECMP(s, "gzip") == 0) + content_gzip = 1; + /* Note: we do not support "gzip;q=0" + * method of _disabling_ gzip + * delivery */ + s = skip_non_whitespace(s); + } + } #endif } /* while extra header reading */ } -- cgit v1.2.3-55-g6feb From ccb977186100ccf6b443c5f08c8b179c9b7e720b Mon Sep 17 00:00:00 2001 From: Alexander Shishkin Date: Sun, 25 Jul 2010 13:07:39 +0200 Subject: ash: fix $! value when traps are set Signed-off-by: Alexander Shishkin Signed-off-by: Denys Vlasenko --- shell/ash.c | 1 + shell/ash_test/ash-signals/signal7.right | 1 + shell/ash_test/ash-signals/signal7.tests | 18 ++++++++++++++++++ shell/hush.c | 4 ++-- shell/hush_test/hush-trap/signal7.right | 1 + shell/hush_test/hush-trap/signal7.tests | 18 ++++++++++++++++++ 6 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 shell/ash_test/ash-signals/signal7.right create mode 100755 shell/ash_test/ash-signals/signal7.tests create mode 100644 shell/hush_test/hush-trap/signal7.right create mode 100755 shell/hush_test/hush-trap/signal7.tests diff --git a/shell/ash.c b/shell/ash.c index fd119fa51..988edab8a 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -4633,6 +4633,7 @@ clear_traps(void) INT_ON; } } + may_have_traps = 0; } /* Lives far away from here, needed for forkchild */ diff --git a/shell/ash_test/ash-signals/signal7.right b/shell/ash_test/ash-signals/signal7.right new file mode 100644 index 000000000..ba7453e42 --- /dev/null +++ b/shell/ash_test/ash-signals/signal7.right @@ -0,0 +1 @@ +Bug detected: 0 diff --git a/shell/ash_test/ash-signals/signal7.tests b/shell/ash_test/ash-signals/signal7.tests new file mode 100755 index 000000000..c2b1381f9 --- /dev/null +++ b/shell/ash_test/ash-signals/signal7.tests @@ -0,0 +1,18 @@ +bug() { + trap : exit + # Bug was causing sh to be run in subshell, + # as if this line is replaced with (sh -c ...; exit $?) & + # here: + sh -c 'echo REAL_CHILD=$$' & + echo PARENTS_IDEA_OF_CHILD=$! + wait # make sure bkgd shell completes +} + +bug | { +while read varval; do + eval $varval +done +test x"$REAL_CHILD" != x"" \ +&& test x"$REAL_CHILD" = x"$PARENTS_IDEA_OF_CHILD" +echo "Bug detected: $?" +} diff --git a/shell/hush.c b/shell/hush.c index 9208ec497..45c98bb36 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -4108,8 +4108,6 @@ static void insert_bg_job(struct pipe *pi) if (G_interactive_fd) printf("[%d] %d %s\n", job->jobid, job->cmds[0].pid, job->cmdtext); - /* Last command's pid goes to $! */ - G.last_bg_pid = job->cmds[job->num_cmds - 1].pid; G.last_jobid = job->jobid; } @@ -5076,6 +5074,8 @@ static int run_list(struct pipe *pi) if (G.run_list_level == 1) insert_bg_job(pi); #endif + /* Last command's pid goes to $! */ + G.last_bg_pid = pi->cmds[pi->num_cmds - 1].pid; G.last_exitcode = rcode = EXIT_SUCCESS; debug_printf_exec(": cmd&: exitcode EXIT_SUCCESS\n"); } else { diff --git a/shell/hush_test/hush-trap/signal7.right b/shell/hush_test/hush-trap/signal7.right new file mode 100644 index 000000000..ba7453e42 --- /dev/null +++ b/shell/hush_test/hush-trap/signal7.right @@ -0,0 +1 @@ +Bug detected: 0 diff --git a/shell/hush_test/hush-trap/signal7.tests b/shell/hush_test/hush-trap/signal7.tests new file mode 100755 index 000000000..c2b1381f9 --- /dev/null +++ b/shell/hush_test/hush-trap/signal7.tests @@ -0,0 +1,18 @@ +bug() { + trap : exit + # Bug was causing sh to be run in subshell, + # as if this line is replaced with (sh -c ...; exit $?) & + # here: + sh -c 'echo REAL_CHILD=$$' & + echo PARENTS_IDEA_OF_CHILD=$! + wait # make sure bkgd shell completes +} + +bug | { +while read varval; do + eval $varval +done +test x"$REAL_CHILD" != x"" \ +&& test x"$REAL_CHILD" = x"$PARENTS_IDEA_OF_CHILD" +echo "Bug detected: $?" +} -- cgit v1.2.3-55-g6feb From f3ea792badae9cd7c4205ac363301f1e94e57d4e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 26 Jul 2010 01:06:14 +0200 Subject: *: mass cosmetic removal of extra empty lines. no code changes Signed-off-by: Denys Vlasenko --- archival/bz/compress.c | 1 - archival/unzip.c | 1 - coreutils/cut.c | 1 - coreutils/expr.c | 1 - coreutils/ls.c | 2 -- e2fsprogs/old_e2fsprogs/e2fsck.c | 34 +++++++++----------------- e2fsprogs/old_e2fsprogs/ext2fs/alloc.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/alloc_tables.c | 4 --- e2fsprogs/old_e2fsprogs/ext2fs/bb_inode.c | 6 ----- e2fsprogs/old_e2fsprogs/ext2fs/bitops.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/block.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/bmap.c | 3 --- e2fsprogs/old_e2fsprogs/ext2fs/bmove.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/brel.h | 1 - e2fsprogs/old_e2fsprogs/ext2fs/closefs.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/cmp_bitmaps.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/dir_iterate.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/dirblock.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/dupfs.c | 2 -- e2fsprogs/old_e2fsprogs/ext2fs/e2image.h | 13 ---------- e2fsprogs/old_e2fsprogs/ext2fs/ext2_ext_attr.h | 1 - e2fsprogs/old_e2fsprogs/ext2fs/ext2fsP.h | 2 -- e2fsprogs/old_e2fsprogs/ext2fs/freefs.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/get_pathname.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/ind_block.c | 2 -- e2fsprogs/old_e2fsprogs/ext2fs/inline.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/inode.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/inode_io.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/jfs_dat.h | 2 -- e2fsprogs/old_e2fsprogs/ext2fs/lookup.c | 2 -- e2fsprogs/old_e2fsprogs/ext2fs/mkdir.c | 3 --- e2fsprogs/old_e2fsprogs/ext2fs/mkjournal.c | 2 -- e2fsprogs/old_e2fsprogs/ext2fs/namei.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/newdir.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/read_bb.c | 2 -- e2fsprogs/old_e2fsprogs/ext2fs/read_bb_file.c | 2 -- e2fsprogs/old_e2fsprogs/ext2fs/res_gdt.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/rs_bitmap.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/rw_bitmaps.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/swapfs.c | 2 -- e2fsprogs/old_e2fsprogs/ext2fs/unlink.c | 1 - e2fsprogs/old_e2fsprogs/util.c | 1 - loginutils/addgroup.c | 1 - miscutils/crond.c | 1 - miscutils/hdparm.c | 4 +-- networking/ntpd.c | 1 - networking/telnet.c | 1 - networking/traceroute.c | 1 - selinux/setfiles.c | 1 - shell/ash.c | 2 -- shell/hush.c | 1 - util-linux/fdisk.c | 1 - util-linux/volume_id/volume_id.c | 1 - 53 files changed, 13 insertions(+), 111 deletions(-) diff --git a/archival/bz/compress.c b/archival/bz/compress.c index 640b8872b..b9b0949a9 100644 --- a/archival/bz/compress.c +++ b/archival/bz/compress.c @@ -212,7 +212,6 @@ void generateMTFValues(EState* s) wr++; s->mtfFreq[j+1]++; } - } } diff --git a/archival/unzip.c b/archival/unzip.c index 84081c021..d9705a56e 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -359,7 +359,6 @@ int unzip_main(int argc, char **argv) default: bb_show_usage(); - } break; diff --git a/coreutils/cut.c b/coreutils/cut.c index 53f343a33..696478bb2 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c @@ -37,7 +37,6 @@ static int cmpfunc(const void *a, const void *b) { return (((struct cut_list *) a)->startpos - ((struct cut_list *) b)->startpos); - } static void cut_file(FILE *file, char delim, const struct cut_list *cut_lists, unsigned nlists) diff --git a/coreutils/expr.c b/coreutils/expr.c index f40edad4e..8988340f1 100644 --- a/coreutils/expr.c +++ b/coreutils/expr.c @@ -341,7 +341,6 @@ static VALUE *eval6(void) freev(i2); } return v; - } /* Handle : operator (pattern matching). diff --git a/coreutils/ls.c b/coreutils/ls.c index 1197f7d71..3e6980509 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -52,7 +52,6 @@ enum { - TERMINAL_WIDTH = 80, /* use 79 if terminal has linefold bug */ COLUMN_GAP = 2, /* includes the file type char */ @@ -120,7 +119,6 @@ LIST_LONG = LIST_MODEBITS | LIST_NLINKS | LIST_ID_NAME | LIST_SIZE | \ SPLIT_DIR = 1, SPLIT_FILE = 0, SPLIT_SUBDIR = 2, - }; /* "[-]Cadil1", POSIX mandated options, busybox always supports */ diff --git a/e2fsprogs/old_e2fsprogs/e2fsck.c b/e2fsprogs/old_e2fsprogs/e2fsck.c index 4c4c78d00..f58fe9286 100644 --- a/e2fsprogs/old_e2fsprogs/e2fsck.c +++ b/e2fsprogs/old_e2fsprogs/e2fsck.c @@ -517,7 +517,6 @@ static void dict_insert(dict_t *dict, dnode_t *node, const void *key) } dict_root(dict)->color = dnode_black; - } /* @@ -801,7 +800,6 @@ static void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino, int num_blocks) dir->dx_block = e2fsck_allocate_memory(ctx, num_blocks * sizeof (struct dx_dirblock_info), "dx_block info array"); - } /* @@ -1724,7 +1722,6 @@ errout: ext2fs_free_mem(&j_inode); ext2fs_free_mem(&journal); return retval; - } static errcode_t e2fsck_journal_fix_bad_inode(e2fsck_t ctx, @@ -3375,7 +3372,6 @@ static void e2fsck_pass1(e2fsck_t ctx) e2fsck_write_inode(ctx, ino, inode, "pass1"); } - } /* * If dtime is set, offer to clear it. mke2fs @@ -3678,7 +3674,6 @@ endit: ext2fs_free_mem(&block_buf); ext2fs_free_mem(&inode); - } /* @@ -4451,8 +4446,7 @@ static void mark_table_blocks(e2fsck_t ctx) ctx->invalid_bitmaps++; } } else { - ext2fs_mark_block_bitmap(ctx->block_found_map, - b); + ext2fs_mark_block_bitmap(ctx->block_found_map, b); } } } @@ -4469,10 +4463,9 @@ static void mark_table_blocks(e2fsck_t ctx) ctx->invalid_bitmaps++; } } else { - ext2fs_mark_block_bitmap(ctx->block_found_map, - fs->group_desc[i].bg_block_bitmap); - } - + ext2fs_mark_block_bitmap(ctx->block_found_map, + fs->group_desc[i].bg_block_bitmap); + } } /* * Mark block used for the inode bitmap @@ -4486,8 +4479,8 @@ static void mark_table_blocks(e2fsck_t ctx) ctx->invalid_bitmaps++; } } else { - ext2fs_mark_block_bitmap(ctx->block_found_map, - fs->group_desc[i].bg_inode_bitmap); + ext2fs_mark_block_bitmap(ctx->block_found_map, + fs->group_desc[i].bg_inode_bitmap); } } block += fs->super->s_blocks_per_group; @@ -5588,7 +5581,6 @@ static void e2fsck_pass2(e2fsck_t ctx) ext2fs_mark_super_dirty(fs); } } - } #define MAX_DEPTH 32000 @@ -9748,7 +9740,6 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx) if (print_answer) printf("%s.\n", answer ? _(preen_msg[(int) ptr->prompt]) : _("IGNORED")); - } if ((ptr->prompt == PROMPT_ABORT) && answer) @@ -11324,7 +11315,7 @@ static int release_inode_block(ext2_filsys fs, blk_t *block_nr, if ((blk < fs->super->s_first_data_block) || (blk >= fs->super->s_blocks_count)) { fix_problem(ctx, PR_0_ORPHAN_ILLEGAL_BLOCK_NUM, pctx); - return_abort: + return_abort: pb->abort = 1; return BLOCK_ABORT; } @@ -11537,7 +11528,7 @@ static int release_orphan_inodes(e2fsck_t ctx) } ext2fs_free_mem(&block_buf); return 0; -return_abort: + return_abort: ext2fs_free_mem(&block_buf); return 1; } @@ -11618,7 +11609,7 @@ static void check_resize_inode(e2fsck_t ctx) !(inode.i_mode & LINUX_S_IFREG) || (blk < fs->super->s_first_data_block || blk >= fs->super->s_blocks_count)) { - resize_inode_invalid: + resize_inode_invalid: if (fix_problem(ctx, PR_0_RESIZE_INODE_INVALID, &pctx)) { memset(&inode, 0, sizeof(inode)); e2fsck_write_inode(ctx, EXT2_RESIZE_INO, &inode, @@ -11660,10 +11651,9 @@ static void check_resize_inode(e2fsck_t ctx) } } -cleanup: + cleanup: ext2fs_free_mem(&dind_buf); - - } +} static void check_super_block(e2fsck_t ctx) { @@ -11842,7 +11832,6 @@ static void check_super_block(e2fsck_t ctx) (gd->bg_free_inodes_count > sb->s_inodes_per_group) || (gd->bg_used_dirs_count > sb->s_inodes_per_group)) ext2fs_unmark_valid(fs); - } /* @@ -11902,7 +11891,6 @@ static void check_super_block(e2fsck_t ctx) fs->super->s_feature_incompat &= ~EXT2_FEATURE_INCOMPAT_FILETYPE; ext2fs_mark_super_dirty(fs); - } } diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/alloc.c b/e2fsprogs/old_e2fsprogs/ext2fs/alloc.c index 5021d72c9..cbb63e15a 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/alloc.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/alloc.c @@ -171,4 +171,3 @@ errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, blk_t finish, } while (b != finish); return EXT2_ET_BLOCK_ALLOC_FAIL; } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/alloc_tables.c b/e2fsprogs/old_e2fsprogs/ext2fs/alloc_tables.c index b2d786ed8..7c60e2bf5 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/alloc_tables.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/alloc_tables.c @@ -97,12 +97,9 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, fs->group_desc[group].bg_inode_table = new_blk; } - return 0; } - - errcode_t ext2fs_allocate_tables(ext2_filsys fs) { errcode_t retval; @@ -115,4 +112,3 @@ errcode_t ext2fs_allocate_tables(ext2_filsys fs) } return 0; } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/bb_inode.c b/e2fsprogs/old_e2fsprogs/ext2fs/bb_inode.c index 1deae54e8..a96789618 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/bb_inode.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/bb_inode.c @@ -260,9 +260,3 @@ static int set_bad_block_proc(ext2_filsys fs, blk_t *block_nr, *block_nr = blk; return BLOCK_CHANGED; } - - - - - - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/bitops.c b/e2fsprogs/old_e2fsprogs/ext2fs/bitops.c index 987061130..3cf157949 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/bitops.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/bitops.c @@ -88,4 +88,3 @@ void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap, bb_error_msg("#%lu", arg); #endif } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/block.c b/e2fsprogs/old_e2fsprogs/ext2fs/block.c index 498096995..dbd04f846 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/block.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/block.c @@ -435,4 +435,3 @@ errcode_t ext2fs_block_iterate(ext2_filsys fs, return ext2fs_block_iterate2(fs, ino, BLOCK_FLAG_NO_LARGE | flags, block_buf, xlate_func, &xl); } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/bmap.c b/e2fsprogs/old_e2fsprogs/ext2fs/bmap.c index b2d0279d8..796b0e4f5 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/bmap.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/bmap.c @@ -259,6 +259,3 @@ done: } return retval; } - - - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/bmove.c b/e2fsprogs/old_e2fsprogs/ext2fs/bmove.c index 635410da5..ec9244d0b 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/bmove.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/bmove.c @@ -153,4 +153,3 @@ errcode_t ext2fs_move_blocks(ext2_filsys fs, } return 0; } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/brel.h b/e2fsprogs/old_e2fsprogs/ext2fs/brel.h index 216fd132c..87bf72be4 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/brel.h +++ b/e2fsprogs/old_e2fsprogs/ext2fs/brel.h @@ -84,4 +84,3 @@ errcode_t ext2fs_brel_memarray_create(char *name, blk_t max_block, #define ext2fs_brel_move(brel, old, new) ((brel)->move((brel), old, new)) #define ext2fs_brel_delete(brel, old) ((brel)->delete((brel), old)) #define ext2fs_brel_free(brel) ((brel)->free((brel))) - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/closefs.c b/e2fsprogs/old_e2fsprogs/ext2fs/closefs.c index 7ba7f22e2..bfa15e22a 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/closefs.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/closefs.c @@ -378,4 +378,3 @@ errcode_t ext2fs_close(ext2_filsys fs) ext2fs_free(fs); return 0; } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/cmp_bitmaps.c b/e2fsprogs/old_e2fsprogs/ext2fs/cmp_bitmaps.c index 05b8eb8d7..7f78ff804 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/cmp_bitmaps.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/cmp_bitmaps.c @@ -70,4 +70,3 @@ errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1, return 0; } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/dir_iterate.c b/e2fsprogs/old_e2fsprogs/ext2fs/dir_iterate.c index b7d873595..eb5dae0a6 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/dir_iterate.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/dir_iterate.c @@ -217,4 +217,3 @@ next: return BLOCK_ABORT; return 0; } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/dirblock.c b/e2fsprogs/old_e2fsprogs/ext2fs/dirblock.c index f651338e3..f9c5a104b 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/dirblock.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/dirblock.c @@ -130,4 +130,3 @@ errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block, { return ext2fs_write_dir_block2(fs, block, inbuf, 0); } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/dupfs.c b/e2fsprogs/old_e2fsprogs/ext2fs/dupfs.c index 203c29fe3..d1879377a 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/dupfs.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/dupfs.c @@ -92,6 +92,4 @@ errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest) errout: ext2fs_free(fs); return retval; - } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/e2image.h b/e2fsprogs/old_e2fsprogs/ext2fs/e2image.h index 8d38ecc13..a598d0111 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/e2image.h +++ b/e2fsprogs/old_e2fsprogs/ext2fs/e2image.h @@ -37,16 +37,3 @@ struct ext2_image_hdr { __u32 offset_blockmap; /* Byte offset of the inode bitmaps */ __u32 offset_reserved[8]; }; - - - - - - - - - - - - - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/ext2_ext_attr.h b/e2fsprogs/old_e2fsprogs/ext2fs/ext2_ext_attr.h index cc91bb8d6..ca309c0d0 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/ext2_ext_attr.h +++ b/e2fsprogs/old_e2fsprogs/ext2fs/ext2_ext_attr.h @@ -50,4 +50,3 @@ struct ext2_ext_attr_entry { sizeof(struct ext2_xattr_entry)) & ~EXT2_EXT_ATTR_ROUND) #define EXT2_XATTR_SIZE(size) \ (((size) + EXT2_EXT_ATTR_ROUND) & ~EXT2_EXT_ATTR_ROUND) - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/ext2fsP.h b/e2fsprogs/old_e2fsprogs/ext2fs/ext2fsP.h index 908b5d9a4..7a02e9a8e 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/ext2fsP.h +++ b/e2fsprogs/old_e2fsprogs/ext2fs/ext2fsP.h @@ -85,5 +85,3 @@ extern int ext2fs_process_dir_block(ext2_filsys fs, blk_t ref_block, int ref_offset, void *priv_data); - - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/freefs.c b/e2fsprogs/old_e2fsprogs/ext2fs/freefs.c index 65c4ee794..0c5d48b11 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/freefs.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/freefs.c @@ -125,4 +125,3 @@ void ext2fs_free_dblist(ext2_dblist dblist) dblist->magic = 0; ext2fs_free_mem(&dblist); } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/get_pathname.c b/e2fsprogs/old_e2fsprogs/ext2fs/get_pathname.c index a98b2b9e5..a3bbad851 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/get_pathname.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/get_pathname.c @@ -153,5 +153,4 @@ errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino, retval = ext2fs_get_pathname_int(fs, dir, ino, 32, buf, name); ext2fs_free_mem(&buf); return retval; - } diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/ind_block.c b/e2fsprogs/old_e2fsprogs/ext2fs/ind_block.c index c86a1c59a..a1038300b 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/ind_block.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/ind_block.c @@ -67,5 +67,3 @@ errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf) #endif return io_channel_write_blk(fs->io, blk, 1, buf); } - - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/inline.c b/e2fsprogs/old_e2fsprogs/ext2fs/inline.c index 9b620a772..d328cc950 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/inline.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/inline.c @@ -30,4 +30,3 @@ #include "ext2_fs.h" #define INCLUDE_INLINE_FUNCS #include "ext2fs.h" - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/inode.c b/e2fsprogs/old_e2fsprogs/ext2fs/inode.c index 5e0d081bd..7a1d5c94b 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/inode.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/inode.c @@ -764,4 +764,3 @@ errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino) return EXT2_ET_NO_DIRECTORY; return 0; } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/inode_io.c b/e2fsprogs/old_e2fsprogs/ext2fs/inode_io.c index 4bfa93aef..b861d5ff6 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/inode_io.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/inode_io.c @@ -268,4 +268,3 @@ static errcode_t inode_flush(io_channel channel) return ext2fs_file_flush(data->file); } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/jfs_dat.h b/e2fsprogs/old_e2fsprogs/ext2fs/jfs_dat.h index 136635de0..17c586a29 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/jfs_dat.h +++ b/e2fsprogs/old_e2fsprogs/ext2fs/jfs_dat.h @@ -60,6 +60,4 @@ typedef struct journal_superblock_s /* Dynamic information describing the current state of the log */ __u32 s_sequence; /* first commit ID expected in log */ __u32 s_start; /* blocknr of start of log */ - } journal_superblock_t; - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/lookup.c b/e2fsprogs/old_e2fsprogs/ext2fs/lookup.c index 31b30a182..b2e8de8ec 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/lookup.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/lookup.c @@ -66,5 +66,3 @@ errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name, return (ls.found) ? 0 : EXT2_ET_FILE_NOT_FOUND; } - - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/mkdir.c b/e2fsprogs/old_e2fsprogs/ext2fs/mkdir.c index 93f47b06f..a86ac8e93 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/mkdir.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/mkdir.c @@ -136,7 +136,4 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, cleanup: ext2fs_free_mem(&block); return retval; - } - - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/mkjournal.c b/e2fsprogs/old_e2fsprogs/ext2fs/mkjournal.c index db1c8bff3..748d9abc7 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/mkjournal.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/mkjournal.c @@ -188,7 +188,6 @@ static int mkjournal_proc(ext2_filsys fs, return (BLOCK_CHANGED | BLOCK_ABORT); else return BLOCK_CHANGED; - } /* @@ -423,6 +422,5 @@ main(int argc, char **argv) } ext2fs_close(fs); exit(0); - } #endif diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/namei.c b/e2fsprogs/old_e2fsprogs/ext2fs/namei.c index 14d48fb72..18244613c 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/namei.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/namei.c @@ -202,4 +202,3 @@ errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd, ext2fs_free_mem(&buf); return retval; } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/newdir.c b/e2fsprogs/old_e2fsprogs/ext2fs/newdir.c index 9470e7f56..9f156626d 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/newdir.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/newdir.c @@ -66,7 +66,6 @@ errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino, dir->name_len = 2 | filetype; dir->name[0] = '.'; dir->name[1] = '.'; - } *block = buf; return 0; diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/read_bb.c b/e2fsprogs/old_e2fsprogs/ext2fs/read_bb.c index 4766157c2..ce77bc9f6 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/read_bb.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/read_bb.c @@ -94,5 +94,3 @@ errcode_t ext2fs_read_bb_inode(ext2_filsys fs, ext2_badblocks_list *bb_list) return rb.err; } - - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/read_bb_file.c b/e2fsprogs/old_e2fsprogs/ext2fs/read_bb_file.c index 831adcc3a..bf1fc328b 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/read_bb_file.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/read_bb_file.c @@ -94,5 +94,3 @@ errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, return ext2fs_read_bb_FILE2(fs, f, bb_list, (void *) invalid, call_compat_invalid); } - - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/res_gdt.c b/e2fsprogs/old_e2fsprogs/ext2fs/res_gdt.c index 3c550d511..403463a90 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/res_gdt.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/res_gdt.c @@ -218,4 +218,3 @@ out_free: ext2fs_free_mem((void *)&dindir_buf); return retval; } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/rs_bitmap.c b/e2fsprogs/old_e2fsprogs/ext2fs/rs_bitmap.c index e932b3c9d..32e87b77a 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/rs_bitmap.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/rs_bitmap.c @@ -104,4 +104,3 @@ errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end, bmap->magic = EXT2_ET_MAGIC_BLOCK_BITMAP; return retval; } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/rw_bitmaps.c b/e2fsprogs/old_e2fsprogs/ext2fs/rw_bitmaps.c index 0ae0a8234..b618acc5b 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/rw_bitmaps.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/rw_bitmaps.c @@ -293,4 +293,3 @@ errcode_t ext2fs_write_bitmaps(ext2_filsys fs) } return 0; } - diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/swapfs.c b/e2fsprogs/old_e2fsprogs/ext2fs/swapfs.c index 2fca3cfbb..07b757abd 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/swapfs.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/swapfs.c @@ -66,7 +66,6 @@ void ext2fs_swap_super(struct ext2_super_block * sb) sb->s_hash_seed[i] = ext2fs_swab32(sb->s_hash_seed[i]); for (i=0; i < 17; i++) sb->s_jnl_blocks[i] = ext2fs_swab32(sb->s_jnl_blocks[i]); - } void ext2fs_swap_group_desc(struct ext2_group_desc *gdp) @@ -222,7 +221,6 @@ void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t, ext2fs_swap_ext_attr((char *) (eat + 1), (char *) (eaf + 1), bufsize - sizeof(struct ext2_inode) - t->i_extra_isize - sizeof(__u32), 0); - } void ext2fs_swap_inode(ext2_filsys fs, struct ext2_inode *t, diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/unlink.c b/e2fsprogs/old_e2fsprogs/ext2fs/unlink.c index 83ac2713e..71a9ffcb9 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/unlink.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/unlink.c @@ -97,4 +97,3 @@ errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, return (ls.done) ? 0 : EXT2_ET_DIR_NO_SPACE; } - diff --git a/e2fsprogs/old_e2fsprogs/util.c b/e2fsprogs/old_e2fsprogs/util.c index 64cca05a7..0829f5686 100644 --- a/e2fsprogs/old_e2fsprogs/util.c +++ b/e2fsprogs/old_e2fsprogs/util.c @@ -95,7 +95,6 @@ force_check: bb_error_msg("%s is apparently in use by the system", device); goto force_check; } - } void parse_journal_opts(char **journal_device, int *journal_flags, diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c index 215e4a9e0..78ca22585 100644 --- a/loginutils/addgroup.c +++ b/loginutils/addgroup.c @@ -168,7 +168,6 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv) { die_if_bad_username(argv[0]); new_group(argv[0], gid); - } /* Reached only on success */ return EXIT_SUCCESS; diff --git a/miscutils/crond.c b/miscutils/crond.c index 66110bb85..d028eb089 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -243,7 +243,6 @@ static void ParseField(char *user, char *ary, int modvalue, int off, goto err; } } while (n1 != n2); - } if (*ptr != ',') { break; diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index 9738620fd..236b1749c 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c @@ -730,8 +730,8 @@ static void identify(uint16_t *val) if (val[MINOR] && (val[MINOR] <= MINOR_MAX)) { if (like_std < 3) like_std = 3; std = actual_ver[val[MINOR]]; - if (std) printf("\n\tUsed: %s ", nth_string(minor_str, val[MINOR])); - + if (std) + printf("\n\tUsed: %s ", nth_string(minor_str, val[MINOR])); } /* looks like when they up-issue the std, they obsolete one; * thus, only the newest 4 issues need be supported. (That's diff --git a/networking/ntpd.c b/networking/ntpd.c index 14c3a5fbb..d00ee49e5 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -592,7 +592,6 @@ filter_datapoints(peer_t *p) p->filter_offset, x, p->filter_dispersion, p->filter_jitter); - } static void diff --git a/networking/telnet.c b/networking/telnet.c index 57997f6b9..e0022b2cb 100644 --- a/networking/telnet.c +++ b/networking/telnet.c @@ -150,7 +150,6 @@ static void con_escape(void) cookmode(); ret: bb_got_signal = 0; - } static void handle_net_output(int len) diff --git a/networking/traceroute.c b/networking/traceroute.c index 2d3e77011..c18fba8d0 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -666,7 +666,6 @@ packet_ok(int read_len, len_and_sockaddr *from_lsa, return (type == ICMP6_TIME_EXCEEDED ? -1 : (code<<8)+1); } } - } # if ENABLE_FEATURE_TRACEROUTE_VERBOSE diff --git a/selinux/setfiles.c b/selinux/setfiles.c index f45e41b2b..989510e3d 100644 --- a/selinux/setfiles.c +++ b/selinux/setfiles.c @@ -118,7 +118,6 @@ static void add_exclude(const char *directory) if (directory == NULL || directory[0] != '/') { bb_error_msg_and_die("full path required for exclude: %s", directory); - } if (lstat(directory, &sb)) { bb_error_msg("directory \"%s\" not found, ignoring", directory); diff --git a/shell/ash.c b/shell/ash.c index 988edab8a..d8becc37a 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -11215,7 +11215,6 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) } IF_ASH_ALIAS(if (c != PEOA)) USTPUTC(c, out); - } c = pgetc_fast(); } /* for (;;) */ @@ -12055,7 +12054,6 @@ evalcmd(int argc UNUSED_PARAM, char **argv) p = grabstackstr(concat); } evalstring(p, ~SKIPEVAL); - } return exitstatus; } diff --git a/shell/hush.c b/shell/hush.c index 45c98bb36..0a420f685 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -4518,7 +4518,6 @@ static NOINLINE int run_pipe(struct pipe *pi) #ifdef CMD_SINGLEWORD_NOGLOB_COND else if (command->cmd_type == CMD_SINGLEWORD_NOGLOB_COND) { argv_expanded = expand_strvec_to_strvec_singleword_noglob_cond(argv + command->assignment_cnt); - } #endif else { diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index aa718c787..fc02000e5 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c @@ -2043,7 +2043,6 @@ fix_partition_table_order(void) fix_chain_of_logicals(); printf("Done.\n"); - } #endif diff --git a/util-linux/volume_id/volume_id.c b/util-linux/volume_id/volume_id.c index c8cf946df..f41d4e0d9 100644 --- a/util-linux/volume_id/volume_id.c +++ b/util-linux/volume_id/volume_id.c @@ -195,7 +195,6 @@ int FAST_FUNC volume_id_probe_all(struct volume_id *id, /*uint64_t off,*/ uint64 ret: volume_id_free_buffer(id); return (- id->error); /* 0 or -1 */ - } /* open volume by device node */ -- cgit v1.2.3-55-g6feb From 0f8960542f6f5ae258e72e56ba7296a01a9c10af Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 26 Jul 2010 01:35:44 +0200 Subject: *: more empty lines removed. no code changes Signed-off-by: Denys Vlasenko --- archival/lzo1x_9x.c | 1 - e2fsprogs/old_e2fsprogs/ext2fs/rw_bitmaps.c | 1 - networking/interface.c | 1 - networking/ntpd.c | 1 - scripts/find_stray_empty_lines | 7 +++++++ 5 files changed, 7 insertions(+), 4 deletions(-) create mode 100755 scripts/find_stray_empty_lines diff --git a/archival/lzo1x_9x.c b/archival/lzo1x_9x.c index 0baed5469..483205155 100644 --- a/archival/lzo1x_9x.c +++ b/archival/lzo1x_9x.c @@ -675,7 +675,6 @@ static int min_gain(unsigned ahead, unsigned lit1, static void better_match(const lzo_swd_p swd, unsigned *m_len, unsigned *m_off) { - if (*m_len <= M2_MIN_LEN) return; diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/rw_bitmaps.c b/e2fsprogs/old_e2fsprogs/ext2fs/rw_bitmaps.c index b618acc5b..bba432679 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/rw_bitmaps.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/rw_bitmaps.c @@ -266,7 +266,6 @@ errcode_t ext2fs_read_block_bitmap(ext2_filsys fs) errcode_t ext2fs_read_bitmaps(ext2_filsys fs) { - EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); if (fs->inode_map && fs->block_map) diff --git a/networking/interface.c b/networking/interface.c index 659ac36ea..7c6ed82df 100644 --- a/networking/interface.c +++ b/networking/interface.c @@ -927,7 +927,6 @@ static void print_bytes_scaled(unsigned long long ull, const char *end) static void ife_print6(struct interface *ptr) { - FILE *f; char addr6[40], devname[20]; struct sockaddr_in6 sap; diff --git a/networking/ntpd.c b/networking/ntpd.c index d00ee49e5..e9cfdbddd 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -2060,7 +2060,6 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) static double direct_freq(double fp_offset) { - #ifdef KERNEL_PLL /* * If the kernel is enabled, we need the residual offset to diff --git a/scripts/find_stray_empty_lines b/scripts/find_stray_empty_lines new file mode 100755 index 000000000..58daf2f0c --- /dev/null +++ b/scripts/find_stray_empty_lines @@ -0,0 +1,7 @@ +#!/bin/sh + +grep -n -B1 -r $'^\t*}$' . | grep -A1 '.[ch]-[0-9]*-$' +grep -n -A1 -r $'^\t*{$' . | grep -B1 '.[ch]-[0-9]*-$' +# or (less surefire ones): +grep -n -B1 -r $'^\t*}' . | grep -A1 '.[ch]-[0-9]*-$' +grep -n -A1 -r $'^\t*{' . | grep -B1 '.[ch]-[0-9]*-$' -- cgit v1.2.3-55-g6feb From ba2dcccd799963ac74ee92300df494947820608b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 26 Jul 2010 01:49:12 +0200 Subject: *: trailing empty lines removed Signed-off-by: Denys Vlasenko --- archival/libunarchive/unxz/README | 1 - debianutils/Config.src | 1 - docs/busybox_footer.pod | 1 - docs/cgi/cl.html | 2 +- docs/cgi/env.html | 2 +- docs/cgi/in.html | 2 +- docs/cgi/interface.html | 2 +- docs/cgi/out.html | 2 +- docs/contributing.txt | 2 -- docs/posix_conformance.txt | 1 - e2fsprogs/old_e2fsprogs/e2fsck.h | 2 -- e2fsprogs/old_e2fsprogs/e2p/ostype.c | 2 -- examples/bootfloppy/display.txt | 1 - examples/bootfloppy/etc/fstab | 1 - examples/bootfloppy/etc/inittab | 1 - examples/bootfloppy/etc/profile | 1 - examples/bootfloppy/mkrootfs.sh | 1 - examples/inittab | 1 - init/reboot.h | 1 - libbb/README | 1 - libbb/selinux_common.c | 1 - networking/libiproute/ll_proto.c | 1 - scripts/Makefile.host | 1 - scripts/Makefile.lib | 2 -- scripts/basic/docproc.c | 1 - scripts/find_stray_empty_lines | 10 ++++++++++ scripts/kconfig/check.sh | 1 - scripts/kconfig/lex.zconf.c_shipped | 1 - scripts/kconfig/menu.c | 1 - scripts/kconfig/util.c | 1 - scripts/kconfig/zconf.hash.c_shipped | 1 - scripts/kconfig/zconf.tab.c_shipped | 2 -- scripts/showasm | 1 - selinux/Config.src | 1 - shell/hush_test/hush-misc/break1.tests | 1 - sysklogd/Config.src | 1 - testsuite/basename/basename-works | 1 - testsuite/dirname/dirname-works | 1 - testsuite/expr/expr-works | 1 - testsuite/ln/ln-preserves-soft-links | 1 - testsuite/readlink.tests | 1 - testsuite/uptime/uptime-works | 1 - 42 files changed, 15 insertions(+), 46 deletions(-) diff --git a/archival/libunarchive/unxz/README b/archival/libunarchive/unxz/README index f79b0a404..c5972f6b8 100644 --- a/archival/libunarchive/unxz/README +++ b/archival/libunarchive/unxz/README @@ -133,4 +133,3 @@ Specifying the calling convention For example, on Windows, you may make all functions use the stdcall calling convention by defining XZ_FUNC=__stdcall when building and using the functions from XZ Embedded. - diff --git a/debianutils/Config.src b/debianutils/Config.src index 838d8f00c..cbc09b5ce 100644 --- a/debianutils/Config.src +++ b/debianutils/Config.src @@ -83,4 +83,3 @@ config WHICH print out their pathnames. endmenu - diff --git a/docs/busybox_footer.pod b/docs/busybox_footer.pod index 5ed937991..47eabaeeb 100644 --- a/docs/busybox_footer.pod +++ b/docs/busybox_footer.pod @@ -253,4 +253,3 @@ Tito Ragusa devfsd and size optimizations in strings, openvt and deallocvt. =cut - diff --git a/docs/cgi/cl.html b/docs/cgi/cl.html index 5779d623e..4f8faae9f 100644 --- a/docs/cgi/cl.html +++ b/docs/cgi/cl.html @@ -43,4 +43,4 @@ CGI - Common Gateway Interface

cgi@ncsa.uiuc.edu
- \ No newline at end of file + diff --git a/docs/cgi/env.html b/docs/cgi/env.html index 924026b3e..b83c750bf 100644 --- a/docs/cgi/env.html +++ b/docs/cgi/env.html @@ -146,4 +146,4 @@ interface specification

CGI - Common Gateway Interface

cgi@ncsa.uiuc.edu
- \ No newline at end of file + diff --git a/docs/cgi/in.html b/docs/cgi/in.html index 679306aaa..7ee5fe601 100644 --- a/docs/cgi/in.html +++ b/docs/cgi/in.html @@ -30,4 +30,4 @@ interface specification

CGI - Common Gateway Interface

cgi@ncsa.uiuc.edu
- \ No newline at end of file + diff --git a/docs/cgi/interface.html b/docs/cgi/interface.html index ea73ce3a2..0be016b4c 100644 --- a/docs/cgi/interface.html +++ b/docs/cgi/interface.html @@ -26,4 +26,4 @@ the following is a hotlink to graphic detail.

CGI - Common Gateway Interface

cgi@ncsa.uiuc.edu
- \ No newline at end of file + diff --git a/docs/cgi/out.html b/docs/cgi/out.html index 2203ee5a0..5266985b5 100644 --- a/docs/cgi/out.html +++ b/docs/cgi/out.html @@ -123,4 +123,4 @@ interface specification

CGI - Common Gateway Interface

cgi@ncsa.uiuc.edu
- \ No newline at end of file + diff --git a/docs/contributing.txt b/docs/contributing.txt index d06e4a2da..39aaef1b5 100644 --- a/docs/contributing.txt +++ b/docs/contributing.txt @@ -426,5 +426,3 @@ you're having difficulty following some of the steps outlined in this document don't worry, the folks on the Busybox mailing list are a fairly good-natured bunch and will work with you to help get your patches into shape or help you make contributions. - - diff --git a/docs/posix_conformance.txt b/docs/posix_conformance.txt index d9fa116b8..5b616d701 100644 --- a/docs/posix_conformance.txt +++ b/docs/posix_conformance.txt @@ -739,4 +739,3 @@ xargs Busybox specific options: zcat POSIX options: None zcat Busybox specific options: None - diff --git a/e2fsprogs/old_e2fsprogs/e2fsck.h b/e2fsprogs/old_e2fsprogs/e2fsck.h index 73d398ff4..fdfa2d84a 100644 --- a/e2fsprogs/old_e2fsprogs/e2fsck.h +++ b/e2fsprogs/old_e2fsprogs/e2fsck.h @@ -636,5 +636,3 @@ static inline int tid_geq(tid_t x, tid_t y) int difference = (x - y); return (difference >= 0); } - - diff --git a/e2fsprogs/old_e2fsprogs/e2p/ostype.c b/e2fsprogs/old_e2fsprogs/e2p/ostype.c index 1abe2ba91..6a2f178f3 100644 --- a/e2fsprogs/old_e2fsprogs/e2p/ostype.c +++ b/e2fsprogs/old_e2fsprogs/e2p/ostype.c @@ -70,5 +70,3 @@ int main(int argc, char **argv) exit(0); } #endif - - diff --git a/examples/bootfloppy/display.txt b/examples/bootfloppy/display.txt index 399d326d9..7cae48bb3 100644 --- a/examples/bootfloppy/display.txt +++ b/examples/bootfloppy/display.txt @@ -1,4 +1,3 @@ This boot floppy is made with Busybox, uClibc, and the Linux kernel. Hit RETURN to boot or enter boot parameters at the prompt below. - diff --git a/examples/bootfloppy/etc/fstab b/examples/bootfloppy/etc/fstab index ef14ca2cc..b31f60217 100644 --- a/examples/bootfloppy/etc/fstab +++ b/examples/bootfloppy/etc/fstab @@ -1,2 +1 @@ proc /proc proc defaults 0 0 - diff --git a/examples/bootfloppy/etc/inittab b/examples/bootfloppy/etc/inittab index eb3e979ce..1ac9f68ce 100644 --- a/examples/bootfloppy/etc/inittab +++ b/examples/bootfloppy/etc/inittab @@ -2,4 +2,3 @@ ::respawn:-/bin/sh tty2::askfirst:-/bin/sh ::ctrlaltdel:/bin/umount -a -r - diff --git a/examples/bootfloppy/etc/profile b/examples/bootfloppy/etc/profile index 8a7c77d78..cf68d3393 100644 --- a/examples/bootfloppy/etc/profile +++ b/examples/bootfloppy/etc/profile @@ -5,4 +5,3 @@ echo -n "Processing /etc/profile... " # no-op echo "Done" echo - diff --git a/examples/bootfloppy/mkrootfs.sh b/examples/bootfloppy/mkrootfs.sh index 5cdff21a0..a7fc48b13 100755 --- a/examples/bootfloppy/mkrootfs.sh +++ b/examples/bootfloppy/mkrootfs.sh @@ -102,4 +102,3 @@ then rmdir $TARGET_DIR gzip -9 rootfs fi - diff --git a/examples/inittab b/examples/inittab index 64fc4fce1..c4e0af514 100644 --- a/examples/inittab +++ b/examples/inittab @@ -87,4 +87,3 @@ tty5::respawn:/sbin/getty 38400 tty6 ::ctrlaltdel:/sbin/reboot ::shutdown:/bin/umount -a -r ::shutdown:/sbin/swapoff -a - diff --git a/init/reboot.h b/init/reboot.h index ff045fdd1..949763949 100644 --- a/init/reboot.h +++ b/init/reboot.h @@ -28,4 +28,3 @@ # define RB_POWER_OFF RB_HALT_SYSTEM # endif #endif - diff --git a/libbb/README b/libbb/README index 4f28f7e34..6e63dc5f2 100644 --- a/libbb/README +++ b/libbb/README @@ -8,4 +8,3 @@ that you wrote that is mis-attributed, do let me know so we can fix that up. Erik Andersen - diff --git a/libbb/selinux_common.c b/libbb/selinux_common.c index 7b5696754..2acb50e96 100644 --- a/libbb/selinux_common.c +++ b/libbb/selinux_common.c @@ -53,4 +53,3 @@ void FAST_FUNC selinux_preserve_fcontext(int fdesc) setfscreatecon_or_die(context); freecon(context); } - diff --git a/networking/libiproute/ll_proto.c b/networking/libiproute/ll_proto.c index 145902b2e..1cd576f1d 100644 --- a/networking/libiproute/ll_proto.c +++ b/networking/libiproute/ll_proto.c @@ -126,4 +126,3 @@ int FAST_FUNC ll_proto_a2n(unsigned short *id, char *buf) *id = htons(i); return 0; } - diff --git a/scripts/Makefile.host b/scripts/Makefile.host index 23bd9ff10..2e628508d 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host @@ -153,4 +153,3 @@ $(host-cshlib): %: $(host-cshobjs) FORCE targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\ $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) - diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index be679b624..3e54ea712 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -168,5 +168,3 @@ cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ quiet_cmd_gzip = GZIP $@ cmd_gzip = gzip -f -9 < $< > $@ - - diff --git a/scripts/basic/docproc.c b/scripts/basic/docproc.c index 50ef37157..db30019d8 100644 --- a/scripts/basic/docproc.c +++ b/scripts/basic/docproc.c @@ -397,4 +397,3 @@ int main(int argc, char **argv) fflush(stdout); return exitstatus; } - diff --git a/scripts/find_stray_empty_lines b/scripts/find_stray_empty_lines index 58daf2f0c..60873dac1 100755 --- a/scripts/find_stray_empty_lines +++ b/scripts/find_stray_empty_lines @@ -5,3 +5,13 @@ grep -n -A1 -r $'^\t*{$' . | grep -B1 '.[ch]-[0-9]*-$' # or (less surefire ones): grep -n -B1 -r $'^\t*}' . | grep -A1 '.[ch]-[0-9]*-$' grep -n -A1 -r $'^\t*{' . | grep -B1 '.[ch]-[0-9]*-$' + +# find trailing empty lines +find -type f | xargs tail -1 | while read file; do + test x"$file" = x"" && continue + read lastline + #echo "|$file|$lastline" + if test x"$lastline" = x""; then + echo "$file" + fi +done diff --git a/scripts/kconfig/check.sh b/scripts/kconfig/check.sh index fa59cbf9d..15fc29421 100755 --- a/scripts/kconfig/check.sh +++ b/scripts/kconfig/check.sh @@ -11,4 +11,3 @@ EOF if [ ! "$?" -eq "0" ]; then echo -DKBUILD_NO_NLS; fi - diff --git a/scripts/kconfig/lex.zconf.c_shipped b/scripts/kconfig/lex.zconf.c_shipped index 5fc323de3..4837bbf64 100644 --- a/scripts/kconfig/lex.zconf.c_shipped +++ b/scripts/kconfig/lex.zconf.c_shipped @@ -2322,4 +2322,3 @@ char *zconf_curname(void) { return current_pos.file ? current_pos.file->name : ""; } - diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 0fce20cb7..14cf2ead0 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -394,4 +394,3 @@ struct menu *menu_get_parent_menu(struct menu *menu) } return menu; } - diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index ef4c83228..263091945 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -112,4 +112,3 @@ const char *str_get(struct gstr *gs) { return gs->s; } - diff --git a/scripts/kconfig/zconf.hash.c_shipped b/scripts/kconfig/zconf.hash.c_shipped index 345f0fc07..d39cf189a 100644 --- a/scripts/kconfig/zconf.hash.c_shipped +++ b/scripts/kconfig/zconf.hash.c_shipped @@ -228,4 +228,3 @@ kconf_id_lookup (register const char *str, register unsigned int len) } return 0; } - diff --git a/scripts/kconfig/zconf.tab.c_shipped b/scripts/kconfig/zconf.tab.c_shipped index b62724da0..a27d256d6 100644 --- a/scripts/kconfig/zconf.tab.c_shipped +++ b/scripts/kconfig/zconf.tab.c_shipped @@ -2169,5 +2169,3 @@ void zconfdump(FILE *out) #include "expr.c" #include "symbol.c" #include "menu.c" - - diff --git a/scripts/showasm b/scripts/showasm index 046442653..dc2cd705d 100755 --- a/scripts/showasm +++ b/scripts/showasm @@ -18,4 +18,3 @@ then fi objdump -d $1 | sed -n -e '/./{H;$!d}' -e "x;/^.[0-9a-fA-F]* <$2>:/p" - diff --git a/selinux/Config.src b/selinux/Config.src index 64a99203e..47d15b6af 100644 --- a/selinux/Config.src +++ b/selinux/Config.src @@ -122,4 +122,3 @@ config SESTATUS Displays the status of SELinux. endmenu - diff --git a/shell/hush_test/hush-misc/break1.tests b/shell/hush_test/hush-misc/break1.tests index 912f149c1..3a6b060d9 100755 --- a/shell/hush_test/hush-misc/break1.tests +++ b/shell/hush_test/hush-misc/break1.tests @@ -1,3 +1,2 @@ while true; do echo A; break; echo B; done echo OK:$? - diff --git a/sysklogd/Config.src b/sysklogd/Config.src index bfe2d1cc3..41c0d286b 100644 --- a/sysklogd/Config.src +++ b/sysklogd/Config.src @@ -128,4 +128,3 @@ config LOGGER problems that occur within programs and scripts. endmenu - diff --git a/testsuite/basename/basename-works b/testsuite/basename/basename-works index 38907d4c1..7140e9988 100644 --- a/testsuite/basename/basename-works +++ b/testsuite/basename/basename-works @@ -1,2 +1 @@ test x$(basename $(pwd)) = x$(busybox basename $(pwd)) - diff --git a/testsuite/dirname/dirname-works b/testsuite/dirname/dirname-works index f339c8f73..d673dd937 100644 --- a/testsuite/dirname/dirname-works +++ b/testsuite/dirname/dirname-works @@ -1,2 +1 @@ test x$(dirname $(pwd)) = x$(busybox dirname $(pwd)) - diff --git a/testsuite/expr/expr-works b/testsuite/expr/expr-works index af49ac4d5..5a0fffbdc 100644 --- a/testsuite/expr/expr-works +++ b/testsuite/expr/expr-works @@ -56,4 +56,3 @@ busybox expr 0 \>= 1 if [ $? != 1 ] ; then exit 1; fi; - diff --git a/testsuite/ln/ln-preserves-soft-links b/testsuite/ln/ln-preserves-soft-links index a8123ece3..3a49bedf4 100644 --- a/testsuite/ln/ln-preserves-soft-links +++ b/testsuite/ln/ln-preserves-soft-links @@ -6,4 +6,3 @@ if [ $? != 0 ] ; then exit 0; fi exit 1; - diff --git a/testsuite/readlink.tests b/testsuite/readlink.tests index e6822dff1..ecc3ad03e 100755 --- a/testsuite/readlink.tests +++ b/testsuite/readlink.tests @@ -29,4 +29,3 @@ testing "readlink -f on a wierd dir" "readlink -f $TESTDIR/../$TESTFILE" "$PWD/$ # clean up rm -r "$TESTLINK" "$TESTDIR" - diff --git a/testsuite/uptime/uptime-works b/testsuite/uptime/uptime-works index 80e578778..6b168ab0e 100644 --- a/testsuite/uptime/uptime-works +++ b/testsuite/uptime/uptime-works @@ -1,2 +1 @@ busybox uptime - -- cgit v1.2.3-55-g6feb From e5dbd56d776ec51281dd6fcc345baf77b4eac953 Mon Sep 17 00:00:00 2001 From: Peter Korsgaard Date: Mon, 26 Jul 2010 02:08:35 +0200 Subject: httpd: simplified "gzip" test function old new delta handle_incoming_and_exit 2830 2807 -23 Signed-off-by: Peter Korsgaard Signed-off-by: Denys Vlasenko --- networking/httpd.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/networking/httpd.c b/networking/httpd.c index cad45cd5d..3fea3f04c 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -2081,18 +2081,18 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) #endif #if ENABLE_FEATURE_HTTPD_GZIP if (STRNCASECMP(iobuf, "Accept-Encoding:") == 0) { - char *s = iobuf + sizeof("Accept-Encoding:")-1; - while (*s) { - ///is "Accept-Encoding: compress,gzip" valid? - // (that is, no space after ',') - - // this code won't handle that - s = skip_whitespace(s); - if (STRNCASECMP(s, "gzip") == 0) + /* Note: we do not support "gzip;q=0" + * method of _disabling_ gzip + * delivery. No one uses that, though */ + const char *s = strstr(iobuf, "gzip"); + if (s) { + // want more thorough checks? + //if (s[-1] == ' ' + // || s[-1] == ',' + // || s[-1] == ':' + //) { content_gzip = 1; - /* Note: we do not support "gzip;q=0" - * method of _disabling_ gzip - * delivery */ - s = skip_non_whitespace(s); + //} } } #endif -- cgit v1.2.3-55-g6feb From f0b82142b264c46f6fee2720fdd0d776a127b17d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 26 Jul 2010 12:26:04 +0200 Subject: *: fix unterminated last lines. no code changes Signed-off-by: Denys Vlasenko --- examples/udhcp/sample.bound | 2 +- examples/udhcp/sample.renew | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/udhcp/sample.bound b/examples/udhcp/sample.bound index 2a95d8b7d..bd3569c77 100755 --- a/examples/udhcp/sample.bound +++ b/examples/udhcp/sample.bound @@ -28,4 +28,4 @@ for i in $dns do echo adding dns $i echo nameserver $i >> $RESOLV_CONF -done \ No newline at end of file +done diff --git a/examples/udhcp/sample.renew b/examples/udhcp/sample.renew index 842bafe91..ea368fc9e 100755 --- a/examples/udhcp/sample.renew +++ b/examples/udhcp/sample.renew @@ -28,4 +28,4 @@ for i in $dns do echo adding dns $i echo nameserver $i >> $RESOLV_CONF -done \ No newline at end of file +done -- cgit v1.2.3-55-g6feb From b4d035165f9304e869ec2733ee6ded058c4c9270 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 26 Jul 2010 12:47:36 +0200 Subject: *: s/spaces/tabs/ Signed-off-by: Denys Vlasenko --- docs/ifupdown_design.txt | 28 ++++++++++++++-------------- scripts/kconfig/zconf.y | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/ifupdown_design.txt b/docs/ifupdown_design.txt index 8008e4507..8ab4e51ad 100644 --- a/docs/ifupdown_design.txt +++ b/docs/ifupdown_design.txt @@ -10,27 +10,27 @@ for that. We are doomed to have problems with ifup/ifdown. Just look as this code: static const struct dhcp_client_t ext_dhcp_clients[] = { - { "dhcpcd", "", "" }, - { "dhclient", ........ }, - { "pump", ........ }, - { "udhcpc", ........ }, + { "dhcpcd", "", "" }, + { "dhclient", ........ }, + { "pump", ........ }, + { "udhcpc", ........ }, }; static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) { #if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP - int i ; - for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) { - if (exists_execable(ext_dhcp_clients[i].name)) - return execute(ext_dhcp_clients[i].stopcmd, ifd, exec); - } - bb_error_msg("no dhcp clients found, using static interface shutdown"); - return static_down(ifd, exec); + int i ; + for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) { + if (exists_execable(ext_dhcp_clients[i].name)) + return execute(ext_dhcp_clients[i].stopcmd, ifd, exec); + } + bb_error_msg("no dhcp clients found, using static interface shutdown"); + return static_down(ifd, exec); #elif ENABLE_UDHCPC - return execute("kill " - "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec); + return execute("kill " + "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec); #else - return 0; /* no dhcp support */ + return 0; /* no dhcp support */ #endif } diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index 2007a4e02..bef5e92a3 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -473,7 +473,7 @@ void conf_parse(const char *name) menu_finalize(&rootmenu); for_all_symbols(i, sym) { sym_check_deps(sym); - } + } sym_change_count = 1; } -- cgit v1.2.3-55-g6feb From 06702365d7faf47ebfc5b5453d73ade235ea4c65 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 27 Jul 2010 08:26:32 +0200 Subject: mktemp: fix for dir/file.XXXXXX param (by Rob). +9 bytes. Signed-off-by: Denys Vlasenko --- debianutils/mktemp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debianutils/mktemp.c b/debianutils/mktemp.c index 2c4e19670..7ce9f1096 100644 --- a/debianutils/mktemp.c +++ b/debianutils/mktemp.c @@ -50,7 +50,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) opts = getopt32(argv, "dqtp:", &path); chp = argv[optind] ? argv[optind] : xstrdup("tmp.XXXXXX"); - if (chp[0] != '/' || (opts & 8)) + if (!strchr(chp, '/') || (opts & 8)) chp = concat_path_file(path, chp); if (opts & 1) { /* -d */ -- cgit v1.2.3-55-g6feb From 17e0e43c3522882e2ac8e921132540ba01a1c66c Mon Sep 17 00:00:00 2001 From: Alexander Shishkin Date: Tue, 27 Jul 2010 08:40:55 +0200 Subject: ulimit: set both hard and soft limits by default function old new delta shell_builtin_ulimit 494 498 +4 Signed-off-by: Alexander Shishkin Signed-off-by: Denys Vlasenko --- shell/shell_common.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/shell/shell_common.c b/shell/shell_common.c index 3114ff3f7..dc363e298 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -428,9 +428,14 @@ shell_builtin_ulimit(char **argv) val <<= l->factor_shift; } //bb_error_msg("opt %c val_str:'%s' val:%lld", opt_char, val_str, (long long)val); + /* from man bash: "If neither -H nor -S + * is specified, both the soft and hard + * limits are set. */ + if (!opts) + opts = OPT_hard + OPT_soft; if (opts & OPT_hard) limit.rlim_max = val; - if ((opts & OPT_soft) || opts == 0) + if (opts & OPT_soft) limit.rlim_cur = val; //bb_error_msg("setrlimit(%d, %lld, %lld)", l->cmd, (long long)limit.rlim_cur, (long long)limit.rlim_max); if (setrlimit(l->cmd, &limit) < 0) { -- cgit v1.2.3-55-g6feb From a3f71001c30f8927495828da9888bcef86e24035 Mon Sep 17 00:00:00 2001 From: Javier Viguera Date: Tue, 27 Jul 2010 11:13:28 +0200 Subject: find_stray_empty_lines: fix tail "invalid context" error "tail -1" works only with one input file. Using it with multiple input files throws following error on Ubuntu systems: tail: option used in invalid context Adding "-n" makes it work on all cases. Signed-off-by: Javier Viguera Signed-off-by: Bernhard Reutner-Fischer --- scripts/find_stray_empty_lines | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/find_stray_empty_lines b/scripts/find_stray_empty_lines index 60873dac1..17a2d4a49 100755 --- a/scripts/find_stray_empty_lines +++ b/scripts/find_stray_empty_lines @@ -7,7 +7,7 @@ grep -n -B1 -r $'^\t*}' . | grep -A1 '.[ch]-[0-9]*-$' grep -n -A1 -r $'^\t*{' . | grep -B1 '.[ch]-[0-9]*-$' # find trailing empty lines -find -type f | xargs tail -1 | while read file; do +find -type f | xargs tail -n1 | while read file; do test x"$file" = x"" && continue read lastline #echo "|$file|$lastline" -- cgit v1.2.3-55-g6feb From 3d615b8a4153d791164e44687831392fed26d9b4 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 28 Jul 2010 21:29:19 +0200 Subject: find_stray_empty_lines: make it work Signed-off-by: Bernhard Reutner-Fischer --- scripts/find_stray_empty_lines | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/find_stray_empty_lines b/scripts/find_stray_empty_lines index 17a2d4a49..aae18f99b 100755 --- a/scripts/find_stray_empty_lines +++ b/scripts/find_stray_empty_lines @@ -7,11 +7,13 @@ grep -n -B1 -r $'^\t*}' . | grep -A1 '.[ch]-[0-9]*-$' grep -n -A1 -r $'^\t*{' . | grep -B1 '.[ch]-[0-9]*-$' # find trailing empty lines -find -type f | xargs tail -n1 | while read file; do +find -type f | while read file; do test x"$file" = x"" && continue - read lastline - #echo "|$file|$lastline" - if test x"$lastline" = x""; then + tail -n1 $file | while read lastline + do + #echo "|$file|$lastline" + if test x"$lastline" = x""; then echo "$file" - fi + fi + done done -- cgit v1.2.3-55-g6feb From 416f0405cb03ecc816b829d5a3d357a556b95fcd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 29 Jul 2010 02:22:43 +0200 Subject: less: fix duplicate "depends on PLATFORM_LINUX". no code changes Signed-off-by: Denys Vlasenko --- miscutils/Config.src | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/miscutils/Config.src b/miscutils/Config.src index e89e231e6..dbfd7a1a0 100644 --- a/miscutils/Config.src +++ b/miscutils/Config.src @@ -352,10 +352,6 @@ config LESS bool "less" default y depends on PLATFORM_LINUX - depends on PLATFORM_LINUX - depends on PLATFORM_LINUX - depends on PLATFORM_LINUX - depends on PLATFORM_LINUX help 'less' is a pager, meaning that it displays text files. It possesses a wide array of features, and is an improvement over 'more'. @@ -417,7 +413,7 @@ config FEATURE_LESS_LINENUMS default y depends on FEATURE_LESS_DASHCMD help - Enable "-N" command. + Enables "-N" command. config HDPARM bool "hdparm" @@ -484,15 +480,15 @@ config MAKEDEVS help 'makedevs' is a utility used to create a batch of devices with one command. - . + There are two choices for command line behaviour, the interface as used by LEAF/Linux Router Project, or a device table file. - . + 'leaf' is traditionally what busybox follows, it allows multiple devices of a particluar type to be created per command. e.g. /dev/hda[0-9] Device properties are passed as command line arguments. - . + 'table' reads device properties from a file or stdin, allowing a batch of unrelated devices to be made with one command. User/group names are allowed as an alternative to uid/gid. -- cgit v1.2.3-55-g6feb From 7a07b0ee6a99a98ec1f144d5d06043fa0c03f451 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 29 Jul 2010 04:00:27 +0200 Subject: dc: make it use long longs for integer ops function old new delta print_base 176 238 +62 or 91 103 +12 eor 91 103 +12 and 91 103 +12 not 60 64 +4 mod 103 105 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 6/0 up/down: 104/0) Total: 104 bytes Signed-off-by: Denys Vlasenko --- include/usage.src.h | 22 ------------------ miscutils/dc.c | 65 +++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/include/usage.src.h b/include/usage.src.h index 9b326eebb..0053a7c4b 100644 --- a/include/usage.src.h +++ b/include/usage.src.h @@ -736,28 +736,6 @@ INSERT "$ date\n" \ "Wed Apr 12 18:52:41 MDT 2000\n" -#define dc_trivial_usage \ - "expression..." -#define dc_full_usage "\n\n" \ - "Tiny RPN calculator. Operations:\n" \ - "+, add, -, sub, *, mul, /, div, %, mod, **, exp, and, or, not, eor,\n" \ - "p - print top of the stack (without altering the stack),\n" \ - "f - print entire stack, o - pop the value and set output radix\n" \ - "(value must be 10 or 16).\n" \ - "Examples: 'dc 2 2 add' -> 4, 'dc 8 8 * 2 2 + /' -> 16\n" \ - -#define dc_example_usage \ - "$ dc 2 2 + p\n" \ - "4\n" \ - "$ dc 8 8 \\* 2 2 + / p\n" \ - "16\n" \ - "$ dc 0 1 and p\n" \ - "0\n" \ - "$ dc 0 1 or p\n" \ - "1\n" \ - "$ echo 72 9 div 8 mul p | dc\n" \ - "64\n" - #define dd_trivial_usage \ "[if=FILE] [of=FILE] " IF_FEATURE_DD_IBS_OBS("[ibs=N] [obs=N] ") "[bs=N] [count=N] [skip=N]\n" \ " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync]") diff --git a/miscutils/dc.c b/miscutils/dc.c index cb4b1e9b1..ebf357281 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c @@ -6,7 +6,39 @@ #include "libbb.h" #include -/* Tiny RPN calculator, because "expr" didn't give me bitwise operations. */ +//usage:#define dc_trivial_usage +//usage: "expression..." +//usage: +//usage:#define dc_full_usage "\n\n" +//usage: "Tiny RPN calculator. Operations:\n" +//usage: "+, add, -, sub, *, mul, /, div, %, mod, **, exp, and, or, not, eor,\n" +//usage: "p - print top of the stack (without popping),\n" +//usage: "f - print entire stack, o - pop the value and set output radix\n" +//usage: "(value must be 10, 16, 8 or 2).\n" +//usage: "Examples: 'dc 2 2 add' -> 4, 'dc 8 8 * 2 2 + /' -> 16\n" +//usage: +//usage:#define dc_example_usage +//usage: "$ dc 2 2 + p\n" +//usage: "4\n" +//usage: "$ dc 8 8 \\* 2 2 + / p\n" +//usage: "16\n" +//usage: "$ dc 0 1 and p\n" +//usage: "0\n" +//usage: "$ dc 0 1 or p\n" +//usage: "1\n" +//usage: "$ echo 72 9 div 8 mul p | dc\n" +//usage: "64\n" + +#if 0 +typedef unsigned data_t; +#define DATA_FMT "" +#elif 0 +typedef unsigned long data_t; +#define DATA_FMT "l" +#else +typedef unsigned long long data_t; +#define DATA_FMT "ll" +#endif struct globals { @@ -73,29 +105,29 @@ static void divide(void) static void mod(void) { - unsigned d = pop(); + data_t d = pop(); - push((unsigned) pop() % d); + push((data_t) pop() % d); } static void and(void) { - push((unsigned) pop() & (unsigned) pop()); + push((data_t) pop() & (data_t) pop()); } static void or(void) { - push((unsigned) pop() | (unsigned) pop()); + push((data_t) pop() | (data_t) pop()); } static void eor(void) { - push((unsigned) pop() ^ (unsigned) pop()); + push((data_t) pop() ^ (data_t) pop()); } static void not(void) { - push(~(unsigned) pop()); + push(~(data_t) pop()); } static void set_output_base(void) @@ -112,25 +144,30 @@ static void set_output_base(void) static void print_base(double print) { - unsigned x, i; + data_t x, i; + x = (data_t) print; if (base == 10) { - printf("%g\n", print); + if (x == print) /* exactly representable as unsigned integer */ + printf("%"DATA_FMT"u\n", x); + else + printf("%g\n", print); return; } - x = (unsigned)print; switch (base) { case 16: - printf("%x\n", x); + printf("%"DATA_FMT"x\n", x); break; case 8: - printf("%o\n", x); + printf("%"DATA_FMT"o\n", x); break; default: /* base 2 */ - i = (unsigned)INT_MAX + 1; + i = MAXINT(data_t) - (MAXINT(data_t) >> 1); + /* i is 100000...00000 */ do { - if (x & i) break; + if (x & i) + break; i >>= 1; } while (i > 1); do { -- cgit v1.2.3-55-g6feb From 506d3a9bcaf760bd3f4251421c3932200fb480d8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 29 Jul 2010 04:06:07 +0200 Subject: dc: tweak help text Signed-off-by: Denys Vlasenko --- miscutils/dc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/miscutils/dc.c b/miscutils/dc.c index ebf357281..767d746e0 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c @@ -7,15 +7,15 @@ #include //usage:#define dc_trivial_usage -//usage: "expression..." +//usage: "EXPRESSION..." //usage: //usage:#define dc_full_usage "\n\n" //usage: "Tiny RPN calculator. Operations:\n" //usage: "+, add, -, sub, *, mul, /, div, %, mod, **, exp, and, or, not, eor,\n" //usage: "p - print top of the stack (without popping),\n" -//usage: "f - print entire stack, o - pop the value and set output radix\n" -//usage: "(value must be 10, 16, 8 or 2).\n" -//usage: "Examples: 'dc 2 2 add' -> 4, 'dc 8 8 * 2 2 + /' -> 16\n" +//usage: "f - print entire stack,\n" +//usage: "o - pop the value and set output radix (must be 10, 16, 8 or 2).\n" +//usage: "Examples: 'dc 2 2 add' -> 4, 'dc 8 8 * 2 2 + /' -> 16" //usage: //usage:#define dc_example_usage //usage: "$ dc 2 2 + p\n" -- cgit v1.2.3-55-g6feb From 64b6f7cfbafb66c0b9be08a30ec348579f17052a Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 29 Jul 2010 09:34:04 +0200 Subject: doc: remove trailing empty line Signed-off-by: Bernhard Reutner-Fischer --- Makefile.custom | 1 + docs/busybox_header.pod | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.custom b/Makefile.custom index 01d69ddf8..c6577a568 100644 --- a/Makefile.custom +++ b/Makefile.custom @@ -125,6 +125,7 @@ docs/busybox.pod: $(srctree)/docs/busybox_header.pod \ $(Q)-mkdir -p docs $(Q)-( \ cat $(srctree)/docs/busybox_header.pod; \ + echo; \ applets/usage_pod | sed 's/^[A-Za-z][A-Za-z ]*[a-z]:$$/&\n/'; \ cat $(srctree)/docs/busybox_footer.pod; \ ) > docs/busybox.pod diff --git a/docs/busybox_header.pod b/docs/busybox_header.pod index 2a99636b1..85a173e82 100644 --- a/docs/busybox_header.pod +++ b/docs/busybox_header.pod @@ -80,4 +80,3 @@ been enabled, more detailed usage information will also be available. =head1 COMMANDS Currently available applets include: - -- cgit v1.2.3-55-g6feb From 1538c975ec127efc368284abe0777006719bf505 Mon Sep 17 00:00:00 2001 From: Leonid Lisovskiy Date: Thu, 29 Jul 2010 11:05:30 +0400 Subject: testsuite: typo in tr.tests Hi tr.tests script from bb 1.17 testsuite has wrong "optional" conditional clauses. As result, some tr tests was skipped even if CONFIG_FEATURE_TR_CLASSES=y. Patch attached fixes problem for me. - Leonid Signed-off-by: Leonid Lisovskiy Signed-off-by: Bernhard Reutner-Fischer --- testsuite/testing.sh | 2 +- testsuite/tr.tests | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/testsuite/testing.sh b/testsuite/testing.sh index 913d7f8ef..f907deade 100644 --- a/testsuite/testing.sh +++ b/testsuite/testing.sh @@ -26,7 +26,7 @@ # number of failed tests. # The "optional" function is used to skip certain tests, ala: -# optional CONFIG_FEATURE_THINGY +# optional FEATURE_THINGY # # The "optional" function checks the environment variable "OPTIONFLAGS", # which is either empty (in which case it always clears SKIP) or diff --git a/testsuite/tr.tests b/testsuite/tr.tests index a1f83bfc6..5dabbb52f 100755 --- a/testsuite/tr.tests +++ b/testsuite/tr.tests @@ -15,19 +15,19 @@ testing "tr understands 0-9A-F" \ "tr -cd '[0-9A-F]'" \ "19AF" "" "19AFH\n" -optional CONFIG_FEATURE_TR_CLASSES +optional FEATURE_TR_CLASSES testing "tr understands [:xdigit:]" \ "tr -cd '[:xdigit:]'" \ "19AF" "" "19AFH\n" SKIP= -optional CONFIG_FEATURE_TR_CLASSES +optional FEATURE_TR_CLASSES testing "tr does not stop after [:digit:]" \ "tr '[:digit:]y-z' 111111111123" \ "111abcx23\n" "" "789abcxyz\n" SKIP= -optional CONFIG_FEATURE_TR_CLASSES +optional FEATURE_TR_CLASSES testing "tr has correct xdigit sequence" \ "tr '[:xdigit:]Gg' 1111111151242222333330xX" \ "#1111111151242222x333330X\n" "" \ -- cgit v1.2.3-55-g6feb From 5a71fb82025d8bbb87a2d0a0851cb4c9cc31e888 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Thu, 29 Jul 2010 04:29:47 +0200 Subject: less: remove misguided dependency on PLATFORM_LINUX Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- miscutils/Config.src | 1 - 1 file changed, 1 deletion(-) diff --git a/miscutils/Config.src b/miscutils/Config.src index dbfd7a1a0..cadaabb65 100644 --- a/miscutils/Config.src +++ b/miscutils/Config.src @@ -351,7 +351,6 @@ endchoice config LESS bool "less" default y - depends on PLATFORM_LINUX help 'less' is a pager, meaning that it displays text files. It possesses a wide array of features, and is an improvement over 'more'. -- cgit v1.2.3-55-g6feb From e7a0632b7b38f635853a08c276dad2fbd395ba92 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Thu, 29 Jul 2010 04:29:53 +0200 Subject: bootchartd: mounting tmpfs is Linux-specific Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- init/bootchartd.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/init/bootchartd.c b/init/bootchartd.c index a1c01641b..465a34979 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c @@ -6,7 +6,6 @@ //config:config BOOTCHARTD //config: bool "bootchartd" //config: default y -//config: depends on PLATFORM_LINUX //config: help //config: bootchartd is commonly used to profile the boot process //config: for the purpose of speeding it up. In this case, it is started @@ -46,12 +45,15 @@ #include "libbb.h" /* After libbb.h, since it needs sys/types.h on some systems */ #include -#include -#ifndef MS_SILENT -# define MS_SILENT (1 << 15) -#endif -#ifndef MNT_DETACH -# define MNT_DETACH 0x00000002 + +#ifdef __linux__ +# include +# ifndef MS_SILENT +# define MS_SILENT (1 << 15) +# endif +# ifndef MNT_DETACH +# define MNT_DETACH 0x00000002 +# endif #endif #define BC_VERSION_STR "0.8" @@ -175,6 +177,7 @@ static char *make_tempdir(void) char template[] = "/tmp/bootchart.XXXXXX"; char *tempdir = xstrdup(mkdtemp(template)); if (!tempdir) { +#ifdef __linux__ /* /tmp is not writable (happens when we are used as init). * Try to mount a tmpfs, them cd and lazily unmount it. * Since we unmount it at once, we can mount it anywhere. @@ -192,6 +195,9 @@ static char *make_tempdir(void) if (umount2(try_dir, MNT_DETACH) != 0) { bb_perror_msg_and_die("can't %smount tmpfs", "un"); } +#else + bb_perror_msg_and_die("can't create temporary directory"); +#endif } else { xchdir(tempdir); } -- cgit v1.2.3-55-g6feb From 68fca4cd55e7bf6075eb1ccd303ae57a7ec1b8da Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Thu, 29 Jul 2010 04:29:52 +0200 Subject: vlock: disable linux console calls on other systems Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- loginutils/Config.src | 1 - loginutils/vlock.c | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/loginutils/Config.src b/loginutils/Config.src index 6ec289355..5d497c4dc 100644 --- a/loginutils/Config.src +++ b/loginutils/Config.src @@ -295,7 +295,6 @@ config SULOGIN config VLOCK bool "vlock" default y - depends on PLATFORM_LINUX select FEATURE_SUID help Build the "vlock" applet which allows you to lock (virtual) terminals. diff --git a/loginutils/vlock.c b/loginutils/vlock.c index 85f489c22..59aeb54e8 100644 --- a/loginutils/vlock.c +++ b/loginutils/vlock.c @@ -15,9 +15,11 @@ /* Fixed by Erik Andersen to do passwords the tinylogin way... * It now works with md5, sha1, etc passwords. */ -#include #include "libbb.h" +#ifdef __linux__ +#include + static void release_vt(int signo UNUSED_PARAM) { /* If -a, param is 0, which means: @@ -30,14 +32,17 @@ static void acquire_vt(int signo UNUSED_PARAM) /* ACK to kernel that switch to console is successful */ ioctl(STDIN_FILENO, VT_RELDISP, VT_ACKACQ); } +#endif int vlock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int vlock_main(int argc UNUSED_PARAM, char **argv) { +#ifdef __linux__ struct vt_mode vtm; + struct vt_mode ovtm; +#endif struct termios term; struct termios oterm; - struct vt_mode ovtm; struct passwd *pw; pw = xgetpwuid(getuid()); @@ -55,6 +60,7 @@ int vlock_main(int argc UNUSED_PARAM, char **argv) + (1 << SIGINT ) , SIG_IGN); +#ifdef __linux__ /* We will use SIGUSRx for console switch control: */ /* 1: set handlers */ signal_SA_RESTART_empty_mask(SIGUSR1, release_vt); @@ -62,12 +68,14 @@ int vlock_main(int argc UNUSED_PARAM, char **argv) /* 2: unmask them */ sig_unblock(SIGUSR1); sig_unblock(SIGUSR2); +#endif /* Revert stdin/out to our controlling tty * (or die if we have none) */ xmove_fd(xopen(CURRENT_TTY, O_RDWR), STDIN_FILENO); xdup2(STDIN_FILENO, STDOUT_FILENO); +#ifdef __linux__ xioctl(STDIN_FILENO, VT_GETMODE, &vtm); ovtm = vtm; /* "console switches are controlled by us, not kernel!" */ @@ -75,6 +83,7 @@ int vlock_main(int argc UNUSED_PARAM, char **argv) vtm.relsig = SIGUSR1; vtm.acqsig = SIGUSR2; ioctl(STDIN_FILENO, VT_SETMODE, &vtm); +#endif tcgetattr(STDIN_FILENO, &oterm); term = oterm; @@ -95,7 +104,9 @@ int vlock_main(int argc UNUSED_PARAM, char **argv) puts("Password incorrect"); } while (1); +#ifdef __linux__ ioctl(STDIN_FILENO, VT_SETMODE, &ovtm); +#endif tcsetattr_stdin_TCSANOW(&oterm); fflush_stdout_and_exit(EXIT_SUCCESS); } -- cgit v1.2.3-55-g6feb From 5e87c2ef150275ddb8fd7be0397881eeeb3bb081 Mon Sep 17 00:00:00 2001 From: Maksym Kryzhanovskyy Date: Fri, 30 Jul 2010 03:56:02 +0200 Subject: mpstat: small code shrink Signed-off-by: Maksym Kryzhanovskyy Signed-off-by: Denys Vlasenko --- procps/mpstat.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/procps/mpstat.c b/procps/mpstat.c index 125bb3de7..b0d187ea6 100644 --- a/procps/mpstat.c +++ b/procps/mpstat.c @@ -954,16 +954,14 @@ int mpstat_main(int UNUSED_PARAM argc, char **argv) } if (opt & OPT_INTS) { - if (strcmp(opt_irq_fmt, "ALL") == 0) - G.options |= D_IRQ_SUM + D_IRQ_CPU + D_SOFTIRQS; - else if (strcmp(opt_irq_fmt, "CPU") == 0) - G.options |= D_IRQ_CPU; - else if (strcmp(opt_irq_fmt, "SUM") == 0) - G.options |= D_IRQ_SUM; - else if (strcmp(opt_irq_fmt, "SCPU") == 0) - G.options |= D_SOFTIRQS; - else + static const char v[] = { + D_IRQ_CPU, D_IRQ_SUM, D_SOFTIRQS, + D_IRQ_SUM + D_IRQ_CPU + D_SOFTIRQS + }; + i = index_in_strings("CPU\0SUM\0SCPU\0ALL\0", opt_irq_fmt); + if (i == -1) bb_show_usage(); + G.options |= v[i]; } if ((opt & OPT_UTIL) /* -u? */ -- cgit v1.2.3-55-g6feb From 64c67891a252cfee5ad155abcc49a008d7023d08 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Jul 2010 12:45:14 +0200 Subject: mpstat: fix/improve handling of interrupt names Signed-off-by: Denys Vlasenko --- procps/mpstat.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/procps/mpstat.c b/procps/mpstat.c index b0d187ea6..a1f3937c9 100644 --- a/procps/mpstat.c +++ b/procps/mpstat.c @@ -28,8 +28,16 @@ /* Maximum number of interrupts */ #define NR_IRQS 256 #define NR_IRQCPU_PREALLOC 3 -#define MAX_IRQ_LEN 16 +#define MAX_IRQNAME_LEN 16 #define MAX_PF_NAME 512 +/* sysstat 9.0.6 uses width 8, but newer code which also prints /proc/softirqs + * data needs more: "interrupts" in /proc/softirqs have longer names, + * most are up to 8 chars, one (BLOCK_IOPOLL) is even longer. + * We are printing headers in the " IRQNAME/s" form, experimentally + * anything smaller than 10 chars looks ugly for /proc/softirqs stats. + */ +#define INTRATE_SCRWIDTH 10 +#define INTRATE_SCRWIDTH_STR "10" /* System files */ #define SYSFS_DEVCPU "/sys/devices/system/cpu" @@ -54,7 +62,7 @@ typedef long idata_t; struct stats_irqcpu { unsigned interrupt; - char irq_name[MAX_IRQ_LEN]; + char irq_name[MAX_IRQNAME_LEN]; }; struct stats_cpu { @@ -195,10 +203,23 @@ static void write_irqcpu_stats(struct stats_irqcpu *per_cpu_stats[], /* Print header */ printf("\n%-11s CPU", prev_str); - for (j = 0; j < total_irqs; j++) { - p0 = &per_cpu_stats[current][j]; - if (p0->irq_name[0] != '\0') - printf(" %8s/s", p0->irq_name); + { + /* A bit complex code to "buy back" space if one header is too wide. + * Here's how it looks like. BLOCK_IOPOLL eating too much, + * and latter headers use smaller width to compensate: + * ...BLOCK/s BLOCK_IOPOLL/s TASKLET/s SCHED/s HRTIMER/s RCU/s + * ... 2.32 0.00 0.01 17.58 0.14 141.96 + */ + int expected_len = 0; + int printed_len = 0; + for (j = 0; j < total_irqs; j++) { + p0 = &per_cpu_stats[current][j]; + if (p0->irq_name[0] != '\0') { + int n = (INTRATE_SCRWIDTH-3) - (printed_len - expected_len); + printed_len += printf(" %*s/s", n > 0 ? n : 0, skip_whitespace(p0->irq_name)); + expected_len += INTRATE_SCRWIDTH; + } + } } bb_putchar('\n'); @@ -247,7 +268,7 @@ static void write_irqcpu_stats(struct stats_irqcpu *per_cpu_stats[], struct stats_irqcpu *p, *q; p = &per_cpu_stats[current][(cpu - 1) * total_irqs + j]; q = &per_cpu_stats[prev][(cpu - 1) * total_irqs + offset]; - printf(" %10.2f", + printf("%"INTRATE_SCRWIDTH_STR".2f", (double)(p->interrupt - q->interrupt) / itv * G.hz); } else { printf(" N/A"); @@ -574,10 +595,11 @@ static void get_irqs_from_interrupts(const char *fname, ic = &per_cpu_stats[current][irq]; len = cp - buf; - if (len > sizeof(ic->irq_name)) { - len = sizeof(ic->irq_name); + if (len >= sizeof(ic->irq_name)) { + len = sizeof(ic->irq_name) - 1; } - safe_strncpy(ic->irq_name, buf, len); + safe_strncpy(ic->irq_name, buf, len + 1); + //bb_error_msg("%s: irq%d:'%s' buf:'%s'", fname, irq, ic->irq_name, buf); digit = isdigit(buf[len - 1]); cp++; -- cgit v1.2.3-55-g6feb From 9bb0510b9b065cf81ee6f9e4e34bea8a32915eed Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Jul 2010 13:38:46 +0200 Subject: mpstat: fix total par-cpu IRQ counts Signed-off-by: Denys Vlasenko --- procps/mpstat.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/procps/mpstat.c b/procps/mpstat.c index a1f3937c9..d19abee97 100644 --- a/procps/mpstat.c +++ b/procps/mpstat.c @@ -163,6 +163,7 @@ static double percent_value(data_t prev, data_t curr, data_t itv) static double hz_value(data_t prev, data_t curr, data_t itv) { + //bb_error_msg("curr:%lld prev:%lld G.hz:%u", curr, prev, G.hz); return ((double)overflow_safe_sub(prev, curr)) / itv * G.hz; } @@ -413,6 +414,8 @@ static void write_stats_core(int prev, int current, continue; } } + //bb_error_msg("G.st_irq[%u][%u].irq_nr:%lld - G.st_irq[%u][%u].irq_nr:%lld", + // current, cpu, G.st_irq[prev][cpu].irq_nr, prev, cpu, G.st_irq[current][cpu].irq_nr); printf(" %9.2f\n", hz_value(G.st_irq[prev][cpu].irq_nr, G.st_irq[current][cpu].irq_nr, per_cpu_itv)); } } @@ -523,16 +526,23 @@ static void get_cpu_statistics(struct stats_cpu *cpu, data_t *up, data_t *up0) static void get_irqs_from_stat(struct stats_irq *irq) { FILE *fp; + unsigned cpu; char buf[1024]; + for (cpu = 1; cpu <= G.cpu_nr; cpu++) { + irq->irq_nr = 0; + } + fp = fopen_for_read(PROCFS_STAT); if (!fp) return; while (fgets(buf, sizeof(buf), fp)) { - if (strncmp(buf, "intr ", 5) == 0) + //bb_error_msg("/proc/stat:'%s'", buf); + if (strncmp(buf, "intr ", 5) == 0) { /* Read total number of IRQs since system boot */ sscanf(buf + 5, "%"FMT_DATA"u", &irq->irq_nr); + } } fclose(fp); @@ -554,12 +564,20 @@ static void get_irqs_from_interrupts(const char *fname, unsigned irq; int cpu_index[G.cpu_nr]; int iindex; - int len, digit; - for (cpu = 1; cpu <= G.cpu_nr; cpu++) { - irq_i = &G.st_irq[current][cpu]; - irq_i->irq_nr = 0; - } +// Moved to get_irqs_from_stat(), which is called once, not twice, +// unlike get_irqs_from_interrupts(). +// Otherwise reading of /proc/softirqs +// was resetting counts to 0 after we painstakingly collected them from +// /proc/interrupts. Which resulted in: +// 01:32:47 PM CPU intr/s +// 01:32:47 PM all 591.47 +// 01:32:47 PM 0 0.00 <= ??? +// 01:32:47 PM 1 0.00 <= ??? +// for (cpu = 1; cpu <= G.cpu_nr; cpu++) { +// G.st_irq[current][cpu].irq_nr = 0; +// //bb_error_msg("G.st_irq[%u][%u].irq_nr=0", current, cpu); +// } fp = fopen_for_read(fname); if (!fp) @@ -587,11 +605,15 @@ static void get_irqs_from_interrupts(const char *fname, while (fgets(buf, buflen, fp) && irq < irqs_per_cpu ) { + int len; + char last_char; char *cp; - /* Skip over ":" */ + + /* Skip over "IRQNAME:" */ cp = strchr(buf, ':'); if (!cp) continue; + last_char = cp[-1]; ic = &per_cpu_stats[current][irq]; len = cp - buf; @@ -600,7 +622,6 @@ static void get_irqs_from_interrupts(const char *fname, } safe_strncpy(ic->irq_name, buf, len + 1); //bb_error_msg("%s: irq%d:'%s' buf:'%s'", fname, irq, ic->irq_name, buf); - digit = isdigit(buf[len - 1]); cp++; for (cpu = 0; cpu < iindex; cpu++) { @@ -608,9 +629,11 @@ static void get_irqs_from_interrupts(const char *fname, ic = &per_cpu_stats[current][cpu_index[cpu] * irqs_per_cpu + irq]; irq_i = &G.st_irq[current][cpu_index[cpu] + 1]; ic->interrupt = strtoul(cp, &next, 10); - if (digit) { - /* Do not count non-numerical IRQs */ + /* Count only numerical IRQs */ + if (isdigit(last_char)) { irq_i->irq_nr += ic->interrupt; + //bb_error_msg("G.st_irq[%u][%u].irq_nr + %u = %lld", + // current, cpu_index[cpu] + 1, ic->interrupt, irq_i->irq_nr); } cp = next; } -- cgit v1.2.3-55-g6feb From 3fb4a5e6d86e52014502391d8dca25befa4ff9b4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Jul 2010 13:55:35 +0200 Subject: mpstat: better fix for IRQ counts Signed-off-by: Denys Vlasenko --- procps/mpstat.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/procps/mpstat.c b/procps/mpstat.c index d19abee97..1199b98dd 100644 --- a/procps/mpstat.c +++ b/procps/mpstat.c @@ -93,8 +93,9 @@ struct globals { unsigned hz; unsigned cpu_bitmap_len; smallint p_option; - smallint header_done; - smallint avg_header_done; + // 9.0.6 does not do it. Try "mpstat -A 1 2" - headers are repeated! + //smallint header_done; + //smallint avg_header_done; unsigned char *cpu_bitmap; /* Bit 0: global, bit 1: 1st proc... */ data_t global_uptime[3]; data_t per_cpu_uptime[3]; @@ -206,7 +207,7 @@ static void write_irqcpu_stats(struct stats_irqcpu *per_cpu_stats[], printf("\n%-11s CPU", prev_str); { /* A bit complex code to "buy back" space if one header is too wide. - * Here's how it looks like. BLOCK_IOPOLL eating too much, + * Here's how it looks like. BLOCK_IOPOLL eats too much space, * and latter headers use smaller width to compensate: * ...BLOCK/s BLOCK_IOPOLL/s TASKLET/s SCHED/s HRTIMER/s RCU/s * ... 2.32 0.00 0.01 17.58 0.14 141.96 @@ -328,13 +329,13 @@ static void write_stats_core(int prev, int current, /* Print CPU stats */ if (display_opt(D_CPU)) { - /* This is done exactly once */ - if (!G.header_done) { + ///* This is done exactly once */ + //if (!G.header_done) { printf("\n%-11s CPU %%usr %%nice %%sys %%iowait %%irq %%soft %%steal %%guest %%idle\n", prev_str ); - G.header_done = 1; - } + // G.header_done = 1; + //} for (cpu = 0; cpu <= G.cpu_nr; cpu++) { data_t per_cpu_itv; @@ -389,11 +390,11 @@ static void write_stats_core(int prev, int current, /* Print total number of IRQs per CPU */ if (display_opt(D_IRQ_SUM)) { - /* Print average header, this is done exactly once */ - if (!G.avg_header_done) { + ///* Print average header, this is done exactly once */ + //if (!G.avg_header_done) { printf("\n%-11s CPU intr/s\n", prev_str); - G.avg_header_done = 1; - } + // G.avg_header_done = 1; + //} for (cpu = 0; cpu <= G.cpu_nr; cpu++) { data_t per_cpu_itv; @@ -526,13 +527,8 @@ static void get_cpu_statistics(struct stats_cpu *cpu, data_t *up, data_t *up0) static void get_irqs_from_stat(struct stats_irq *irq) { FILE *fp; - unsigned cpu; char buf[1024]; - for (cpu = 1; cpu <= G.cpu_nr; cpu++) { - irq->irq_nr = 0; - } - fp = fopen_for_read(PROCFS_STAT); if (!fp) return; @@ -565,8 +561,7 @@ static void get_irqs_from_interrupts(const char *fname, int cpu_index[G.cpu_nr]; int iindex; -// Moved to get_irqs_from_stat(), which is called once, not twice, -// unlike get_irqs_from_interrupts(). +// Moved to caller. // Otherwise reading of /proc/softirqs // was resetting counts to 0 after we painstakingly collected them from // /proc/interrupts. Which resulted in: @@ -756,9 +751,15 @@ static void main_loop(void) if (display_opt(D_IRQ_SUM)) get_irqs_from_stat(G.st_irq[current]); - if (display_opt(D_IRQ_SUM | D_IRQ_CPU)) + if (display_opt(D_IRQ_SUM | D_IRQ_CPU)) { + int cpu; + for (cpu = 1; cpu <= G.cpu_nr; cpu++) { + G.st_irq[current][cpu].irq_nr = 0; + } + /* accumulates .irq_nr */ get_irqs_from_interrupts(PROCFS_INTERRUPTS, G.st_irqcpu, G.irqcpu_nr, current); + } if (display_opt(D_SOFTIRQS)) get_irqs_from_interrupts(PROCFS_SOFTIRQS, -- cgit v1.2.3-55-g6feb From 85a359afab4743e68977086bddac301ef0675ee1 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 30 Jul 2010 16:43:11 +0200 Subject: mpstat: do not use /sys to get number of CPUs. /proc should be ok. function old new delta get_cpu_nr - 137 +137 mpstat_main 1140 1131 -9 get_proc_cpu_nr 137 - -137 get_sys_cpu_nr 178 - -178 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 0/1 up/down: 137/-324) Total: -187 bytes Signed-off-by: Denys Vlasenko --- procps/mpstat.c | 49 +------------------------------------------------ 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/procps/mpstat.c b/procps/mpstat.c index 1199b98dd..7610a68fb 100644 --- a/procps/mpstat.c +++ b/procps/mpstat.c @@ -815,46 +815,12 @@ static void print_header(struct tm *t) uts.sysname, uts.release, uts.nodename, cur_date, uts.machine, G.cpu_nr); } -/* - * Get number of processors in /sys - */ -static int get_sys_cpu_nr(void) -{ - DIR *dir; - struct dirent *d; - struct stat buf; - char line[MAX_PF_NAME]; - int proc_nr = 0; - - dir = opendir(SYSFS_DEVCPU); - if (!dir) - return 0; /* /sys not mounted */ - - /* Get current file entry */ - while ((d = readdir(dir)) != NULL) { - if (starts_with_cpu(d->d_name) && isdigit(d->d_name[3])) { - snprintf(line, MAX_PF_NAME, "%s/%s", SYSFS_DEVCPU, - d->d_name); - line[MAX_PF_NAME - 1] = '\0'; - /* Get information about file */ - if (stat(line, &buf) < 0) - continue; - /* If found 'cpuN', we have one more processor */ - if (S_ISDIR(buf.st_mode)) - proc_nr++; - } - } - - closedir(dir); - return proc_nr; -} - /* * Get number of processors in /proc/stat * Return value '0' means one CPU and non SMP kernel. * Otherwise N means N processor(s) and SMP kernel. */ -static int get_proc_cpu_nr(void) +static int get_cpu_nr(void) { FILE *fp; char line[256]; @@ -881,19 +847,6 @@ static int get_proc_cpu_nr(void) return proc_nr + 1; } -static int get_cpu_nr(void) -{ - int n; - - /* Try to use /sys, if possible */ - n = get_sys_cpu_nr(); - if (n == 0) - /* Otherwise use /proc/stat */ - n = get_proc_cpu_nr(); - - return n; -} - /* * Get number of interrupts available per processor */ -- cgit v1.2.3-55-g6feb From 430ba79c39eeed4725c36e9c2ad61c438c8a5d3e Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Fri, 30 Jul 2010 06:21:21 +0200 Subject: cttyhack: serial console detection is Linux-specific Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- shell/cttyhack.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/shell/cttyhack.c b/shell/cttyhack.c index a80d49dc3..3a78bae29 100644 --- a/shell/cttyhack.c +++ b/shell/cttyhack.c @@ -13,7 +13,6 @@ //config:config CTTYHACK //config: bool "cttyhack" //config: default y -//config: depends on PLATFORM_LINUX //config: help //config: One common problem reported on the mailing list is "can't access tty; //config: job control turned off" error message which typically appears when @@ -59,6 +58,10 @@ //usage: "\nStarting interactive shell from boot shell script:" //usage: "\n setsid cttyhack sh" +#if !defined(__linux__) && !defined(TIOCGSERIAL) +# warning cttyhack will not be able to detect a controlling tty on this system +#endif + /* From */ struct vt_stat { unsigned short v_active; /* active vt */ @@ -112,13 +115,19 @@ int cttyhack_main(int argc UNUSED_PARAM, char **argv) close(fd); } else { /* We don't have ctty (or don't have "/dev/tty" node...) */ - if (ioctl(0, TIOCGSERIAL, &u.sr) == 0) { + if (0) {} +#ifdef TIOCGSERIAL + else if (ioctl(0, TIOCGSERIAL, &u.sr) == 0) { /* this is a serial console */ sprintf(console + 8, "S%d", u.sr.line); - } else if (ioctl(0, VT_GETSTATE, &u.vt) == 0) { + } +#endif +#ifdef __linux__ + else if (ioctl(0, VT_GETSTATE, &u.vt) == 0) { /* this is linux virtual tty */ sprintf(console + 8, "S%d" + 1, u.vt.v_active); } +#endif if (console[8]) { fd = xopen(console, O_RDWR); //bb_error_msg("switching to '%s'", console); -- cgit v1.2.3-55-g6feb From 17662801ece60bbcc45bbc3cb1fc0fc3070d0d23 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Jul 2010 17:41:35 +0200 Subject: cttyhack: make it survive WERROR build Signed-off-by: Denys Vlasenko --- shell/cttyhack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/cttyhack.c b/shell/cttyhack.c index 3a78bae29..7a5e1ffd2 100644 --- a/shell/cttyhack.c +++ b/shell/cttyhack.c @@ -58,7 +58,7 @@ //usage: "\nStarting interactive shell from boot shell script:" //usage: "\n setsid cttyhack sh" -#if !defined(__linux__) && !defined(TIOCGSERIAL) +#if !defined(__linux__) && !defined(TIOCGSERIAL) && !ENABLE_WERROR # warning cttyhack will not be able to detect a controlling tty on this system #endif -- cgit v1.2.3-55-g6feb From 63c2e7ecc0c7a72b2ed35475a8d18d3052039ce4 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Sun, 1 Aug 2010 03:01:44 +0200 Subject: klogd: make it work on non-linux systems The klogctl() interface allows changing the console loglevel, but is Linux-specific. The more portable method of reading from _PATH_KLOG is added as an alternative. Adapted from the Debian kFreeBSD patch at: http://svn.debian.org/viewsvn/d-i/people/slackydeb/kfreebsd/busybox/1.14/debian/klogd.diff Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- sysklogd/Config.src | 17 ++++++- sysklogd/klogd.c | 128 ++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 126 insertions(+), 19 deletions(-) diff --git a/sysklogd/Config.src b/sysklogd/Config.src index 41c0d286b..1e5987275 100644 --- a/sysklogd/Config.src +++ b/sysklogd/Config.src @@ -109,7 +109,6 @@ config FEATURE_LOGREAD_REDUCED_LOCKING config KLOGD bool "klogd" default y - depends on PLATFORM_LINUX help klogd is a utility which intercepts and logs all messages from the Linux kernel and sends the messages @@ -117,6 +116,22 @@ config KLOGD you wish to record the messages produced by the kernel, you should enable this option. +config FEATURE_KLOGD_KLOGCTL + bool "Use the klogctl() interface" + default y + depends on KLOGD && PLATFORM_LINUX + help + The klogd applet supports two interfaces for reading + kernel messages. Linux provides the klogctl() interface + which allows reading messages from the kernel ring buffer + independently from the file system. + + If you answer 'N' here, klogd will use the more portable + approach of reading them from /proc or a device node. + However, this method requires the file to be available. + + If in doubt, say 'Y'. + config LOGGER bool "logger" default y diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index c54e80a35..3468656cc 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c @@ -4,7 +4,7 @@ * * Copyright (C) 2001 by Gennady Feldman . * Changes: Made this a standalone busybox module which uses standalone - * syslog() client interface. + * syslog() client interface. * * Copyright (C) 1999-2004 by Erik Andersen * @@ -19,18 +19,93 @@ #include "libbb.h" #include -#include -static void klogd_signal(int sig) + +/* The Linux-specific klogctl(3) interface does not rely on the filesystem and + * allows us to change the console loglevel. Alternatively, we read the + * messages from _PATH_KLOG. */ + +#if ENABLE_FEATURE_KLOGD_KLOGCTL + +# include + +static void klogd_open(void) +{ + /* "Open the log. Currently a NOP" */ + klogctl(1, NULL, 0); +} + +static void klogd_setloglevel(int lvl) +{ + /* "printk() prints a message on the console only if it has a loglevel + * less than console_loglevel". Here we set console_loglevel = lvl. */ + klogctl(8, NULL, lvl); +} + +static int klogd_read(char *bufp, int len) +{ + return klogctl(2, bufp, len); +} +# define READ_ERROR "klogctl(2) error" + +static void klogd_close(void) { /* FYI: cmd 7 is equivalent to setting console_loglevel to 7 * via klogctl(8, NULL, 7). */ klogctl(7, NULL, 0); /* "7 -- Enable printk's to console" */ klogctl(0, NULL, 0); /* "0 -- Close the log. Currently a NOP" */ - syslog(LOG_NOTICE, "klogd: exiting"); - kill_myself_with_sig(sig); } +#else + +# include +# ifndef _PATH_KLOG +# ifdef __GNU__ +# define _PATH_KLOG "/dev/klog" +# else +# error "your system's _PATH_KLOG is unknown" +# endif +# endif +# define PATH_PRINTK "/proc/sys/kernel/printk" + +enum { klogfd = 3 }; + +static void klogd_open(void) +{ + int fd = xopen(_PATH_KLOG, O_RDONLY); + xmove_fd(fd, klogfd); +} + +static void klogd_setloglevel(int lvl) +{ + FILE *fp = fopen_or_warn(PATH_PRINTK, "w"); + if (fp) { + /* This changes only first value: + * "messages with a higher priority than this + * [that is, with numerically lower value] + * will be printed to the console". + * The other three values in this pseudo-file aren't changed. + */ + fprintf(fp, "%u\n", lvl); + fclose(fp); + } +} + +static int klogd_read(char *bufp, int len) +{ + return read(klogfd, bufp, len); +} +# define READ_ERROR "read error" + +static void klogd_close(void) +{ + klogd_setloglevel(7); + if (ENABLE_FEATURE_CLEAN_UP) + close(klogfd); +} + +#endif + #define log_buffer bb_common_bufsiz1 enum { KLOGD_LOGBUF_SIZE = sizeof(log_buffer), @@ -38,6 +113,19 @@ enum { OPT_FOREGROUND = (1 << 1), }; +/* TODO: glibc openlog(LOG_KERN) reverts to LOG_USER instead, + * because that's how they interpret word "default" + * in the openlog() manpage: + * LOG_USER (default) + * generic user-level messages + * and the fact that LOG_KERN is a constant 0. + * glibc interprets it as "0 in openlog() call means 'use default'". + * I think it means "if openlog wasn't called before syslog() is called, + * use default". + * Convincing glibc maintainers otherwise is, as usual, nearly impossible. + * Should we open-code syslog() here to use correct facility? + */ + int klogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int klogd_main(int argc UNUSED_PARAM, char **argv) { @@ -55,34 +143,34 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); } - openlog("kernel", 0, LOG_KERN); - - bb_signals(BB_FATAL_SIGS, klogd_signal); - signal(SIGHUP, SIG_IGN); + logmode = LOGMODE_SYSLOG; - /* "Open the log. Currently a NOP" */ - klogctl(1, NULL, 0); + /* klogd_open() before openlog(), since it might use fixed fd 3, + * and openlog() also may use the same fd 3 if we swap them: + */ + klogd_open(); + openlog("kernel", 0, LOG_KERN); - /* "printk() prints a message on the console only if it has a loglevel - * less than console_loglevel". Here we set console_loglevel = i. */ if (i) - klogctl(8, NULL, i); + klogd_setloglevel(i); + + bb_signals(BB_FATAL_SIGS, record_signo); + signal(SIGHUP, SIG_IGN); syslog(LOG_NOTICE, "klogd started: %s", bb_banner); - while (1) { + while (!bb_got_signal) { int n; int priority; char *start; /* "2 -- Read from the log." */ start = log_buffer + used; - n = klogctl(2, start, KLOGD_LOGBUF_SIZE-1 - used); + n = klogd_read(start, KLOGD_LOGBUF_SIZE-1 - used); if (n < 0) { if (errno == EINTR) continue; - syslog(LOG_ERR, "klogd: error %d in klogctl(2): %m", - errno); + bb_perror_msg(READ_ERROR); break; } start[n] = '\0'; @@ -131,5 +219,9 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) } } + klogd_close(); + syslog(LOG_NOTICE, "klogd: exiting"); + if (bb_got_signal) + kill_myself_with_sig(bb_got_signal); return EXIT_FAILURE; } -- cgit v1.2.3-55-g6feb From 138ce54c9c1930348bc842be781accd7c50c2cef Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Fri, 30 Jul 2010 06:01:37 +0200 Subject: stty: sort out preprocessor conditionals * Move the definitions of missing constants to the top of the file. * Fix undefined IDX_xxx on missing termios constants. * FreeBSD has TABDLY, TAB0 and TAB3, but no TAB1 or TAB2 * Omit the definition of set_window_size() if TIOCGWINSZ is not available. Signed-off-by: Jeremie Koenig Signed-off-by: Denys Vlasenko --- coreutils/Config.src | 1 - coreutils/stty.c | 339 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 214 insertions(+), 126 deletions(-) diff --git a/coreutils/Config.src b/coreutils/Config.src index 780b73fda..0eb70af55 100644 --- a/coreutils/Config.src +++ b/coreutils/Config.src @@ -607,7 +607,6 @@ config FEATURE_STAT_FORMAT config STTY bool "stty" default y - depends on PLATFORM_LINUX help stty is used to change and print terminal line settings. diff --git a/coreutils/stty.c b/coreutils/stty.c index c40d718af..33f7b21dd 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c @@ -115,6 +115,113 @@ # define CSTATUS Control('t') #endif +/* Save us from #ifdef forest plague */ +#ifndef BSDLY +# define BSDLY 0 +#endif +#ifndef CIBAUD +# define CIBAUD 0 +#endif +#ifndef CRDLY +# define CRDLY 0 +#endif +#ifndef CRTSCTS +# define CRTSCTS 0 +#endif +#ifndef ECHOCTL +# define ECHOCTL 0 +#endif +#ifndef ECHOKE +# define ECHOKE 0 +#endif +#ifndef ECHOPRT +# define ECHOPRT 0 +#endif +#ifndef FFDLY +# define FFDLY 0 +#endif +#ifndef IEXTEN +# define IEXTEN 0 +#endif +#ifndef IMAXBEL +# define IMAXBEL 0 +#endif +#ifndef IUCLC +# define IUCLC 0 +#endif +#ifndef IXANY +# define IXANY 0 +#endif +#ifndef NLDLY +# define NLDLY 0 +#endif +#ifndef OCRNL +# define OCRNL 0 +#endif +#ifndef OFDEL +# define OFDEL 0 +#endif +#ifndef OFILL +# define OFILL 0 +#endif +#ifndef OLCUC +# define OLCUC 0 +#endif +#ifndef ONLCR +# define ONLCR 0 +#endif +#ifndef ONLRET +# define ONLRET 0 +#endif +#ifndef ONOCR +# define ONOCR 0 +#endif +#ifndef OXTABS +# define OXTABS 0 +#endif +#ifndef TABDLY +# define TABDLY 0 +#endif +#ifndef TAB1 +# define TAB1 0 +#endif +#ifndef TAB2 +# define TAB2 0 +#endif +#ifndef TOSTOP +# define TOSTOP 0 +#endif +#ifndef VDSUSP +# define VDSUSP 0 +#endif +#ifndef VEOL2 +# define VEOL2 0 +#endif +#ifndef VFLUSHO +# define VFLUSHO 0 +#endif +#ifndef VLNEXT +# define VLNEXT 0 +#endif +#ifndef VREPRINT +# define VREPRINT 0 +#endif +#ifndef VSTATUS +# define VSTATUS 0 +#endif +#ifndef VSWTCH +# define VSWTCH 0 +#endif +#ifndef VTDLY +# define VTDLY 0 +#endif +#ifndef VWERASE +# define VWERASE 0 +#endif +#ifndef XCASE +# define XCASE 0 +#endif + /* Which speeds to set */ enum speed_setting { input_speed, output_speed, both_speeds @@ -167,13 +274,13 @@ enum { IDX_cbreak, IDX_crt, IDX_dec, -#ifdef IXANY +#if IXANY IDX_decctlq, #endif -#if defined(TABDLY) || defined(OXTABS) +#if TABDLY || OXTABS IDX_tabs, #endif -#if defined(XCASE) && defined(IUCLC) && defined(OLCUC) +#if XCASE && IUCLC && OLCUC IDX_lcase, IDX_LCASE, #endif @@ -196,13 +303,13 @@ static const char mode_name[] = MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 ) MI_ENTRY("crt", combination, OMIT, 0, 0 ) MI_ENTRY("dec", combination, OMIT, 0, 0 ) -#ifdef IXANY +#if IXANY MI_ENTRY("decctlq", combination, REV | OMIT, 0, 0 ) #endif -#if defined(TABDLY) || defined(OXTABS) +#if TABDLY || OXTABS MI_ENTRY("tabs", combination, REV | OMIT, 0, 0 ) #endif -#if defined(XCASE) && defined(IUCLC) && defined(OLCUC) +#if XCASE && IUCLC && OLCUC MI_ENTRY("lcase", combination, REV | OMIT, 0, 0 ) MI_ENTRY("LCASE", combination, REV | OMIT, 0, 0 ) #endif @@ -217,7 +324,7 @@ static const char mode_name[] = MI_ENTRY("cstopb", control, REV, CSTOPB, 0 ) MI_ENTRY("cread", control, SANE_SET | REV, CREAD, 0 ) MI_ENTRY("clocal", control, REV, CLOCAL, 0 ) -#ifdef CRTSCTS +#if CRTSCTS MI_ENTRY("crtscts", control, REV, CRTSCTS, 0 ) #endif MI_ENTRY("ignbrk", input, SANE_UNSET | REV, IGNBRK, 0 ) @@ -232,74 +339,78 @@ static const char mode_name[] = MI_ENTRY("ixon", input, REV, IXON, 0 ) MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 ) MI_ENTRY("tandem", input, REV | OMIT, IXOFF, 0 ) -#ifdef IUCLC +#if IUCLC MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 ) #endif -#ifdef IXANY +#if IXANY MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 ) #endif -#ifdef IMAXBEL +#if IMAXBEL MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 ) #endif MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 ) -#ifdef OLCUC +#if OLCUC MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 ) #endif -#ifdef OCRNL +#if OCRNL MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 ) #endif -#ifdef ONLCR +#if ONLCR MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 ) #endif -#ifdef ONOCR +#if ONOCR MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 ) #endif -#ifdef ONLRET +#if ONLRET MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 ) #endif -#ifdef OFILL +#if OFILL MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 ) #endif -#ifdef OFDEL +#if OFDEL MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 ) #endif -#ifdef NLDLY +#if NLDLY MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY) MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY) #endif -#ifdef CRDLY +#if CRDLY MI_ENTRY("cr3", output, SANE_UNSET, CR3, CRDLY) MI_ENTRY("cr2", output, SANE_UNSET, CR2, CRDLY) MI_ENTRY("cr1", output, SANE_UNSET, CR1, CRDLY) MI_ENTRY("cr0", output, SANE_SET, CR0, CRDLY) #endif -#ifdef TABDLY +#if TABDLY MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY) +# if TAB2 MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY) +# endif +# if TAB1 MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY) +# endif MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY) #else -# ifdef OXTABS +# if OXTABS MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 ) # endif #endif -#ifdef BSDLY +#if BSDLY MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY) MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY) #endif -#ifdef VTDLY +#if VTDLY MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY) MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY) #endif -#ifdef FFDLY +#if FFDLY MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY) MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY) #endif MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 ) MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 ) -#ifdef IEXTEN +#if IEXTEN MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ) #endif MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ) @@ -308,21 +419,21 @@ static const char mode_name[] = MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ) MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 ) MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 ) -#ifdef XCASE +#if XCASE MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 ) #endif -#ifdef TOSTOP +#if TOSTOP MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 ) #endif -#ifdef ECHOPRT +#if ECHOPRT MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 ) MI_ENTRY("prterase", local, REV | OMIT, ECHOPRT, 0 ) #endif -#ifdef ECHOCTL +#if ECHOCTL MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 ) MI_ENTRY("ctlecho", local, REV | OMIT, ECHOCTL, 0 ) #endif -#ifdef ECHOKE +#if ECHOKE MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ) MI_ENTRY("crtkill", local, REV | OMIT, ECHOKE, 0 ) #endif @@ -346,13 +457,13 @@ static const struct mode_info mode_info[] = { MI_ENTRY("cbreak", combination, REV | OMIT, 0, 0 ) MI_ENTRY("crt", combination, OMIT, 0, 0 ) MI_ENTRY("dec", combination, OMIT, 0, 0 ) -#ifdef IXANY +#if IXANY MI_ENTRY("decctlq", combination, REV | OMIT, 0, 0 ) #endif -#if defined(TABDLY) || defined(OXTABS) +#if TABDLY || OXTABS MI_ENTRY("tabs", combination, REV | OMIT, 0, 0 ) #endif -#if defined(XCASE) && defined(IUCLC) && defined(OLCUC) +#if XCASE && IUCLC && OLCUC MI_ENTRY("lcase", combination, REV | OMIT, 0, 0 ) MI_ENTRY("LCASE", combination, REV | OMIT, 0, 0 ) #endif @@ -367,7 +478,7 @@ static const struct mode_info mode_info[] = { MI_ENTRY("cstopb", control, REV, CSTOPB, 0 ) MI_ENTRY("cread", control, SANE_SET | REV, CREAD, 0 ) MI_ENTRY("clocal", control, REV, CLOCAL, 0 ) -#ifdef CRTSCTS +#if CRTSCTS MI_ENTRY("crtscts", control, REV, CRTSCTS, 0 ) #endif MI_ENTRY("ignbrk", input, SANE_UNSET | REV, IGNBRK, 0 ) @@ -382,74 +493,78 @@ static const struct mode_info mode_info[] = { MI_ENTRY("ixon", input, REV, IXON, 0 ) MI_ENTRY("ixoff", input, SANE_UNSET | REV, IXOFF, 0 ) MI_ENTRY("tandem", input, REV | OMIT, IXOFF, 0 ) -#ifdef IUCLC +#if IUCLC MI_ENTRY("iuclc", input, SANE_UNSET | REV, IUCLC, 0 ) #endif -#ifdef IXANY +#if IXANY MI_ENTRY("ixany", input, SANE_UNSET | REV, IXANY, 0 ) #endif -#ifdef IMAXBEL +#if IMAXBEL MI_ENTRY("imaxbel", input, SANE_SET | REV, IMAXBEL, 0 ) #endif MI_ENTRY("opost", output, SANE_SET | REV, OPOST, 0 ) -#ifdef OLCUC +#if OLCUC MI_ENTRY("olcuc", output, SANE_UNSET | REV, OLCUC, 0 ) #endif -#ifdef OCRNL +#if OCRNL MI_ENTRY("ocrnl", output, SANE_UNSET | REV, OCRNL, 0 ) #endif -#ifdef ONLCR +#if ONLCR MI_ENTRY("onlcr", output, SANE_SET | REV, ONLCR, 0 ) #endif -#ifdef ONOCR +#if ONOCR MI_ENTRY("onocr", output, SANE_UNSET | REV, ONOCR, 0 ) #endif -#ifdef ONLRET +#if ONLRET MI_ENTRY("onlret", output, SANE_UNSET | REV, ONLRET, 0 ) #endif -#ifdef OFILL +#if OFILL MI_ENTRY("ofill", output, SANE_UNSET | REV, OFILL, 0 ) #endif -#ifdef OFDEL +#if OFDEL MI_ENTRY("ofdel", output, SANE_UNSET | REV, OFDEL, 0 ) #endif -#ifdef NLDLY +#if NLDLY MI_ENTRY("nl1", output, SANE_UNSET, NL1, NLDLY) MI_ENTRY("nl0", output, SANE_SET, NL0, NLDLY) #endif -#ifdef CRDLY +#if CRDLY MI_ENTRY("cr3", output, SANE_UNSET, CR3, CRDLY) MI_ENTRY("cr2", output, SANE_UNSET, CR2, CRDLY) MI_ENTRY("cr1", output, SANE_UNSET, CR1, CRDLY) MI_ENTRY("cr0", output, SANE_SET, CR0, CRDLY) #endif -#ifdef TABDLY +#if TABDLY MI_ENTRY("tab3", output, SANE_UNSET, TAB3, TABDLY) +# if TAB2 MI_ENTRY("tab2", output, SANE_UNSET, TAB2, TABDLY) +# endif +# if TAB1 MI_ENTRY("tab1", output, SANE_UNSET, TAB1, TABDLY) +# endif MI_ENTRY("tab0", output, SANE_SET, TAB0, TABDLY) #else -# ifdef OXTABS +# if OXTABS MI_ENTRY("tab3", output, SANE_UNSET, OXTABS, 0 ) # endif #endif -#ifdef BSDLY +#if BSDLY MI_ENTRY("bs1", output, SANE_UNSET, BS1, BSDLY) MI_ENTRY("bs0", output, SANE_SET, BS0, BSDLY) #endif -#ifdef VTDLY +#if VTDLY MI_ENTRY("vt1", output, SANE_UNSET, VT1, VTDLY) MI_ENTRY("vt0", output, SANE_SET, VT0, VTDLY) #endif -#ifdef FFDLY +#if FFDLY MI_ENTRY("ff1", output, SANE_UNSET, FF1, FFDLY) MI_ENTRY("ff0", output, SANE_SET, FF0, FFDLY) #endif MI_ENTRY("isig", local, SANE_SET | REV, ISIG, 0 ) MI_ENTRY("icanon", local, SANE_SET | REV, ICANON, 0 ) -#ifdef IEXTEN +#if IEXTEN MI_ENTRY("iexten", local, SANE_SET | REV, IEXTEN, 0 ) #endif MI_ENTRY("echo", local, SANE_SET | REV, ECHO, 0 ) @@ -458,21 +573,21 @@ static const struct mode_info mode_info[] = { MI_ENTRY("echok", local, SANE_SET | REV, ECHOK, 0 ) MI_ENTRY("echonl", local, SANE_UNSET | REV, ECHONL, 0 ) MI_ENTRY("noflsh", local, SANE_UNSET | REV, NOFLSH, 0 ) -#ifdef XCASE +#if XCASE MI_ENTRY("xcase", local, SANE_UNSET | REV, XCASE, 0 ) #endif -#ifdef TOSTOP +#if TOSTOP MI_ENTRY("tostop", local, SANE_UNSET | REV, TOSTOP, 0 ) #endif -#ifdef ECHOPRT +#if ECHOPRT MI_ENTRY("echoprt", local, SANE_UNSET | REV, ECHOPRT, 0 ) MI_ENTRY("prterase", local, REV | OMIT, ECHOPRT, 0 ) #endif -#ifdef ECHOCTL +#if ECHOCTL MI_ENTRY("echoctl", local, SANE_SET | REV, ECHOCTL, 0 ) MI_ENTRY("ctlecho", local, REV | OMIT, ECHOCTL, 0 ) #endif -#ifdef ECHOKE +#if ECHOKE MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ) MI_ENTRY("crtkill", local, REV | OMIT, ECHOKE, 0 ) #endif @@ -497,31 +612,31 @@ enum { CIDX_kill, CIDX_eof, CIDX_eol, -#ifdef VEOL2 +#if VEOL2 CIDX_eol2, #endif -#ifdef VSWTCH +#if VSWTCH CIDX_swtch, #endif CIDX_start, CIDX_stop, CIDX_susp, -#ifdef VDSUSP +#if VDSUSP CIDX_dsusp, #endif -#ifdef VREPRINT +#if VREPRINT CIDX_rprnt, #endif -#ifdef VWERASE +#if VWERASE CIDX_werase, #endif -#ifdef VLNEXT +#if VLNEXT CIDX_lnext, #endif -#ifdef VFLUSHO +#if VFLUSHO CIDX_flush, #endif -#ifdef VSTATUS +#if VSTATUS CIDX_status, #endif CIDX_min, @@ -538,31 +653,31 @@ static const char control_name[] = CI_ENTRY("kill", CKILL, VKILL ) CI_ENTRY("eof", CEOF, VEOF ) CI_ENTRY("eol", CEOL, VEOL ) -#ifdef VEOL2 +#if VEOL2 CI_ENTRY("eol2", CEOL2, VEOL2 ) #endif -#ifdef VSWTCH +#if VSWTCH CI_ENTRY("swtch", CSWTCH, VSWTCH ) #endif CI_ENTRY("start", CSTART, VSTART ) CI_ENTRY("stop", CSTOP, VSTOP ) CI_ENTRY("susp", CSUSP, VSUSP ) -#ifdef VDSUSP +#if VDSUSP CI_ENTRY("dsusp", CDSUSP, VDSUSP ) #endif -#ifdef VREPRINT +#if VREPRINT CI_ENTRY("rprnt", CRPRNT, VREPRINT) #endif -#ifdef VWERASE +#if VWERASE CI_ENTRY("werase", CWERASE, VWERASE ) #endif -#ifdef VLNEXT +#if VLNEXT CI_ENTRY("lnext", CLNEXT, VLNEXT ) #endif -#ifdef VFLUSHO +#if VFLUSHO CI_ENTRY("flush", CFLUSHO, VFLUSHO ) #endif -#ifdef VSTATUS +#if VSTATUS CI_ENTRY("status", CSTATUS, VSTATUS ) #endif /* These must be last because of the display routines */ @@ -581,31 +696,31 @@ static const struct control_info control_info[] = { CI_ENTRY("kill", CKILL, VKILL ) CI_ENTRY("eof", CEOF, VEOF ) CI_ENTRY("eol", CEOL, VEOL ) -#ifdef VEOL2 +#if VEOL2 CI_ENTRY("eol2", CEOL2, VEOL2 ) #endif -#ifdef VSWTCH +#if VSWTCH CI_ENTRY("swtch", CSWTCH, VSWTCH ) #endif CI_ENTRY("start", CSTART, VSTART ) CI_ENTRY("stop", CSTOP, VSTOP ) CI_ENTRY("susp", CSUSP, VSUSP ) -#ifdef VDSUSP +#if VDSUSP CI_ENTRY("dsusp", CDSUSP, VDSUSP ) #endif -#ifdef VREPRINT +#if VREPRINT CI_ENTRY("rprnt", CRPRNT, VREPRINT) #endif -#ifdef VWERASE +#if VWERASE CI_ENTRY("werase", CWERASE, VWERASE ) #endif -#ifdef VLNEXT +#if VLNEXT CI_ENTRY("lnext", CLNEXT, VLNEXT ) #endif -#ifdef VFLUSHO +#if VFLUSHO CI_ENTRY("flush", CFLUSHO, VFLUSHO ) #endif -#ifdef VSTATUS +#if VSTATUS CI_ENTRY("status", CSTATUS, VSTATUS ) #endif /* These must be last because of the display routines */ @@ -740,6 +855,7 @@ static void newline(void) wrapf("\n"); } +#ifdef TIOCGWINSZ static void set_window_size(int rows, int cols) { struct winsize win = { 0, 0, 0, 0 }; @@ -760,6 +876,7 @@ static void set_window_size(int rows, int cols) bail: perror_on_device("%s"); } +#endif static void display_window_size(int fancy) { @@ -973,41 +1090,6 @@ static void sane_mode(struct termios *mode) } } -/* Save set_mode from #ifdef forest plague */ -#ifndef ONLCR -#define ONLCR 0 -#endif -#ifndef OCRNL -#define OCRNL 0 -#endif -#ifndef ONLRET -#define ONLRET 0 -#endif -#ifndef XCASE -#define XCASE 0 -#endif -#ifndef IXANY -#define IXANY 0 -#endif -#ifndef TABDLY -#define TABDLY 0 -#endif -#ifndef OXTABS -#define OXTABS 0 -#endif -#ifndef IUCLC -#define IUCLC 0 -#endif -#ifndef OLCUC -#define OLCUC 0 -#endif -#ifndef ECHOCTL -#define ECHOCTL 0 -#endif -#ifndef ECHOKE -#define ECHOKE 0 -#endif - static void set_mode(const struct mode_info *info, int reversed, struct termios *mode) { @@ -1093,27 +1175,32 @@ static void set_mode(const struct mode_info *info, int reversed, mode->c_cc[VTIME] = 0; } } - else if (IXANY && info == &mode_info[IDX_decctlq]) { +#if IXANY + else if (info == &mode_info[IDX_decctlq]) { if (reversed) mode->c_iflag |= IXANY; else mode->c_iflag &= ~IXANY; } - else if (TABDLY && info == &mode_info[IDX_tabs]) { +#endif +#if TABDLY + else if (info == &mode_info[IDX_tabs]) { if (reversed) mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB3; else mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB0; } - else if (OXTABS && info == &mode_info[IDX_tabs]) { +#endif +#if OXTABS + else if (info == &mode_info[IDX_tabs]) { if (reversed) mode->c_oflag |= OXTABS; else mode->c_oflag &= ~OXTABS; - } else - if (XCASE && IUCLC && OLCUC - && (info == &mode_info[IDX_lcase] || info == &mode_info[IDX_LCASE]) - ) { + } +#endif +#if XCASE && IUCLC && OLCUC + else if (info==&mode_info[IDX_lcase] || info==&mode_info[IDX_LCASE]) { if (reversed) { mode->c_lflag &= ~XCASE; mode->c_iflag &= ~IUCLC; @@ -1123,7 +1210,9 @@ static void set_mode(const struct mode_info *info, int reversed, mode->c_iflag |= IUCLC; mode->c_oflag |= OLCUC; } - } else if (info == &mode_info[IDX_crt]) { + } +#endif + else if (info == &mode_info[IDX_crt]) { mode->c_lflag |= ECHOE | ECHOCTL | ECHOKE; } else if (info == &mode_info[IDX_dec]) { mode->c_cc[VINTR] = 3; /* ^C */ @@ -1419,7 +1508,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv) perror_on_device_and_die("%s"); if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) { -#ifdef CIBAUD +#if CIBAUD /* SunOS 4.1.3 (at least) has the problem that after this sequence, tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2); sometimes (m1 != m2). The only difference is in the four bits -- cgit v1.2.3-55-g6feb From 2e284a40bcb9d5c73b86603fe31f3a175023d88a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 1 Aug 2010 04:14:46 +0200 Subject: sed: fix sed -i: unlike without -i, it does not forget ranges Signed-off-by: Denys Vlasenko --- editors/sed.c | 13 +++++++++---- testsuite/sed.tests | 7 ++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index 7af8f867a..7d6e7e79f 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -61,6 +61,10 @@ #include "libbb.h" #include "xregex.h" +enum { + OPT_in_place = 1 << 0, +}; + /* Each sed command turns into one of these structures. */ typedef struct sed_cmd_s { /* Ordered by alignment requirements: currently 36 bytes on x86 */ @@ -938,8 +942,11 @@ static void process_files(void) if (matched) { /* once matched, "n,xxx" range is dead, disabling it */ - if (sed_cmd->beg_line > 0) + if (sed_cmd->beg_line > 0 + && !(option_mask32 & OPT_in_place) /* but not for -i */ + ) { sed_cmd->beg_line = -2; + } sed_cmd->in_match = !( /* has the ending line come, or is this a single address command? */ (sed_cmd->end_line ? @@ -1270,9 +1277,6 @@ static void add_cmd_block(char *cmdstr) int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int sed_main(int argc UNUSED_PARAM, char **argv) { - enum { - OPT_in_place = 1 << 0, - }; unsigned opt; llist_t *opt_e, *opt_f; int status = EXIT_SUCCESS; @@ -1292,6 +1296,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv) opt_e = opt_f = NULL; opt_complementary = "e::f::" /* can occur multiple times */ "nn"; /* count -n */ + /* -i must be first, to match OPT_in_place definition */ opt = getopt32(argv, "irne:f:", &opt_e, &opt_f, &G.be_quiet); /* counter for -n */ //argc -= optind; diff --git a/testsuite/sed.tests b/testsuite/sed.tests index 3301a25f8..445eff6bc 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests @@ -270,11 +270,16 @@ testing "sed a cmd ended by double backslash" \ | two \\ ' -# fisrt three lines are deleted; 4th line is matched and printed by "2,3" and by "4" ranges +# first three lines are deleted; 4th line is matched and printed by "2,3" and by "4" ranges testing "sed with N skipping lines past ranges on next cmds" \ "sed -n '1{N;N;d};1p;2,3p;3p;4p'" \ "4\n4\n" "" "1\n2\n3\n4\n" +testing "sed -i with address modifies all files, not only first" \ + "cp input input2; sed -i -e '1s/foo/bar/' input input2 && cat input input2; rm input2" \ + "bar\nbar\n" "foo\n" "foo\n" + + # testing "description" "arguments" "result" "infile" "stdin" exit $FAILCOUNT -- cgit v1.2.3-55-g6feb From b883bc9884d1e01f9653eb5e7b4a59da80162d3b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 1 Aug 2010 04:19:59 +0200 Subject: sed.tests: make last test less confusing Signed-off-by: Denys Vlasenko --- testsuite/sed.tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/sed.tests b/testsuite/sed.tests index 445eff6bc..880fc2118 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests @@ -277,7 +277,7 @@ testing "sed with N skipping lines past ranges on next cmds" \ testing "sed -i with address modifies all files, not only first" \ "cp input input2; sed -i -e '1s/foo/bar/' input input2 && cat input input2; rm input2" \ - "bar\nbar\n" "foo\n" "foo\n" + "bar\nbar\n" "foo\n" "" # testing "description" "arguments" "result" "infile" "stdin" -- cgit v1.2.3-55-g6feb From 6e06da5efd5d6e341ae2f5116c449994740f5613 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 2 Aug 2010 02:17:25 +0200 Subject: update _shipped file with hurd fix Signed-off-by: Denys Vlasenko --- scripts/kconfig/lex.zconf.c_shipped | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/kconfig/lex.zconf.c_shipped b/scripts/kconfig/lex.zconf.c_shipped index 4837bbf64..51f15e175 100644 --- a/scripts/kconfig/lex.zconf.c_shipped +++ b/scripts/kconfig/lex.zconf.c_shipped @@ -2235,13 +2235,14 @@ static void zconf_endhelp(void) */ FILE *zconf_fopen(const char *name) { - char *env, fullname[PATH_MAX+1]; + char *env; FILE *f; f = fopen(name, "r"); if (!f && name[0] != '/') { env = getenv(SRCTREE); if (env) { + char *fullname = alloca(strlen(env) + strlen(name) + 2); sprintf(fullname, "%s/%s", env, name); f = fopen(fullname, "r"); } -- cgit v1.2.3-55-g6feb From e74d79866c6d125527e3ba69245a087a28fd19ce Mon Sep 17 00:00:00 2001 From: Daniel Dickinson Date: Tue, 3 Aug 2010 04:26:20 +0200 Subject: syslogd: close/re-resolve/reopen remote sockets on some sendto() errors function old new delta syslogd_main 1201 1262 +61 Signed-off-by: Daniel Dickinson Signed-off-by: Denys Vlasenko --- sysklogd/syslogd.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 6bc450bf9..37a119b3d 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -546,7 +546,7 @@ static int try_to_resolve_remote(remoteHost_t *rh) if (!rh->remoteAddr) return -1; } - return socket(rh->remoteAddr->u.sa.sa_family, SOCK_DGRAM, 0); + return xsocket(rh->remoteAddr->u.sa.sa_family, SOCK_DGRAM, 0); } #endif @@ -636,11 +636,25 @@ static void do_syslogd(void) if (rh->remoteFD == -1) continue; } - /* Send message to remote logger, ignore possible error */ - /* TODO: on some errors, close and set G.remoteFD to -1 - * so that DNS resolution and connect is retried? */ - sendto(rh->remoteFD, recvbuf, sz+1, MSG_DONTWAIT, - &(rh->remoteAddr->u.sa), rh->remoteAddr->len); + + /* Send message to remote logger. + * On some errors, close and set remoteFD to -1 + * so that DNS resolution is retried. + */ + if (sendto(rh->remoteFD, recvbuf, sz+1, + MSG_DONTWAIT | MSG_NOSIGNAL, + &(rh->remoteAddr->u.sa), rh->remoteAddr->len) == -1 + ) { + switch (errno) { + case ECONNRESET: + case ENOTCONN: /* paranoia */ + case EPIPE: + close(rh->remoteFD); + rh->remoteFD = -1; + free(rh->remoteAddr); + rh->remoteAddr = NULL; + } + } } #endif if (!ENABLE_FEATURE_REMOTE_LOG || (option_mask32 & OPT_locallog)) { -- cgit v1.2.3-55-g6feb From b0fbe4b5409b136e0c80788cf183ec24237e9c97 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 5 Aug 2010 17:19:27 +0200 Subject: ash: add a testcase for bug 2281 (currently fails). Small code cleanups. function old new delta changepath 195 192 -3 subevalvar 1204 1200 -4 readtoken1 3247 3240 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-14) Total: -14 bytes Signed-off-by: Denys Vlasenko --- shell/ash.c | 83 +++++++++++++++++++++------------ shell/ash_test/ash-redir/redir9.tests | 0 shell/ash_test/ash-vars/var_bash3.right | 40 ++++++++-------- shell/ash_test/ash-vars/var_bash3.tests | 47 +++++++++++-------- shell/ash_test/ash-vars/var_bash4.right | 2 + shell/ash_test/ash-vars/var_bash4.tests | 3 ++ 6 files changed, 104 insertions(+), 71 deletions(-) mode change 100644 => 100755 shell/ash_test/ash-redir/redir9.tests create mode 100644 shell/ash_test/ash-vars/var_bash4.right create mode 100755 shell/ash_test/ash-vars/var_bash4.tests diff --git a/shell/ash.c b/shell/ash.c index d8becc37a..16783f2e8 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -6296,13 +6296,14 @@ parse_sub_pattern(char *arg, int inquotes) #endif /* ENABLE_ASH_BASH_COMPAT */ static const char * -subevalvar(char *p, char *str, int strloc, int subtype, +subevalvar(char *p, char *varname, int strloc, int subtype, int startloc, int varflags, int quotes, struct strlist *var_str_list) { struct nodelist *saveargbackq = argbackq; char *startp; char *loc; char *rmesc, *rmescend; + char *str; IF_ASH_BASH_COMPAT(const char *repl = NULL;) IF_ASH_BASH_COMPAT(int pos, len, orig_len;) int saveherefd = herefd; @@ -6310,6 +6311,9 @@ subevalvar(char *p, char *str, int strloc, int subtype, int zero; char *(*scan)(char*, char*, char*, char*, int, int); + //bb_error_msg("subevalvar(p:'%s',varname:'%s',strloc:%d,subtype:%d,startloc:%d,varflags:%x,quotes:%d", + // p, varname, strloc, subtype, startloc, varflags, quotes); + herefd = -1; argstr(p, (subtype != VSASSIGN && subtype != VSQUESTION) ? EXP_CASE : 0, var_str_list); @@ -6320,11 +6324,15 @@ subevalvar(char *p, char *str, int strloc, int subtype, switch (subtype) { case VSASSIGN: - setvar(str, startp, 0); + setvar(varname, startp, 0); amount = startp - expdest; STADJUST(amount, expdest); return startp; + case VSQUESTION: + varunset(p, varname, startp, varflags); + /* NOTREACHED */ + #if ENABLE_ASH_BASH_COMPAT case VSSUBSTR: loc = str = stackblock() + strloc; @@ -6385,11 +6393,8 @@ subevalvar(char *p, char *str, int strloc, int subtype, STADJUST(amount, expdest); return loc; #endif - - case VSQUESTION: - varunset(p, str, startp, varflags); - /* NOTREACHED */ } + resetloc = expdest - (char *)stackblock(); /* We'll comeback here if we grow the stack while handling @@ -6423,13 +6428,14 @@ subevalvar(char *p, char *str, int strloc, int subtype, if (!repl) { repl = parse_sub_pattern(str, varflags & VSQUOTE); + //bb_error_msg("repl:'%s'", repl); if (!repl) repl = nullstr; } /* If there's no pattern to match, return the expansion unmolested */ if (str[0] == '\0') - return 0; + return NULL; len = 0; idx = startp; @@ -6437,6 +6443,7 @@ subevalvar(char *p, char *str, int strloc, int subtype, while (idx < end) { try_to_match: loc = scanright(idx, rmesc, rmescend, str, quotes, 1); + //bb_error_msg("scanright('%s'):'%s'", str, loc); if (!loc) { /* No match, advance */ char *restart_detect = stackblock(); @@ -6475,6 +6482,7 @@ subevalvar(char *p, char *str, int strloc, int subtype, idx = loc; } + //bb_error_msg("repl:'%s'", repl); for (loc = (char*)repl; *loc; loc++) { char *restart_detect = stackblock(); if (quotes && *loc == '\\') { @@ -6510,6 +6518,7 @@ subevalvar(char *p, char *str, int strloc, int subtype, STPUTC('\0', expdest); startp = (char *)stackblock() + startloc; memmove(startp, (char *)stackblock() + workloc, len + 1); + //bb_error_msg("startp:'%s'", startp); amount = expdest - (startp + len); STADJUST(-amount, expdest); return startp; @@ -6810,7 +6819,7 @@ evalvar(char *p, int flags, struct strlist *var_str_list) */ STPUTC('\0', expdest); patloc = expdest - (char *)stackblock(); - if (NULL == subevalvar(p, /* str: */ NULL, patloc, subtype, + if (NULL == subevalvar(p, /* varname: */ NULL, patloc, subtype, startloc, varflags, //TODO: | EXP_REDIR too? All other such places do it too /* quotes: */ flags & (EXP_FULL | EXP_CASE), @@ -11114,8 +11123,11 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) USTPUTC('\\', out); } #endif - if (dblquote && c != '\\' - && c != '`' && c != '$' + /* Backslash is retained if we are in "str" and next char isn't special */ + if (dblquote + && c != '\\' + && c != '`' + && c != '$' && (c != '"' || eofmark != NULL) ) { USTPUTC(CTLESC, out); @@ -11187,7 +11199,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) } else { /* * unbalanced parens - * (don't 2nd guess - no error) + * (don't 2nd guess - no error) */ pungetc(); USTPUTC(')', out); @@ -11380,8 +11392,6 @@ parsesub: { unsigned char subtype; int typeloc; int flags; - char *p; - static const char types[] ALIGN1 = "}-+?="; c = pgetc(); if (c > 255 /* PEOA or PEOF */ @@ -11394,7 +11404,8 @@ parsesub: { #endif USTPUTC('$', out); pungetc(); - } else if (c == '(') { /* $(command) or $((arith)) */ + } else if (c == '(') { + /* $(command) or $((arith)) */ if (pgetc() == '(') { #if ENABLE_SH_MATH_SUPPORT PARSEARITH(); @@ -11406,6 +11417,7 @@ parsesub: { PARSEBACKQNEW(); } } else { + /* $VAR, $, ${...}, or PEOA/PEOF */ USTPUTC(CTLVAR, out); typeloc = out - (char *)stackblock(); USTPUTC(VSNORMAL, out); @@ -11415,76 +11427,85 @@ parsesub: { if (c == '#') { c = pgetc(); if (c == '}') - c = '#'; + c = '#'; /* ${#} - same as $# */ else - subtype = VSLENGTH; - } else + subtype = VSLENGTH; /* ${#VAR} */ + } else { subtype = 0; + } } if (c <= 255 /* not PEOA or PEOF */ && is_name(c)) { + /* $[{[#]]NAME[}] */ do { STPUTC(c, out); c = pgetc(); } while (c <= 255 /* not PEOA or PEOF */ && is_in_name(c)); } else if (isdigit(c)) { + /* $[{[#]]NUM[}] */ do { STPUTC(c, out); c = pgetc(); } while (isdigit(c)); } else if (is_special(c)) { + /* $[{[#]][}] */ USTPUTC(c, out); c = pgetc(); } else { badsub: raise_error_syntax("bad substitution"); } - if (c != '}' && subtype == VSLENGTH) + if (c != '}' && subtype == VSLENGTH) { + /* ${#VAR didn't end with } */ goto badsub; + } STPUTC('=', out); flags = 0; if (subtype == 0) { + /* ${VAR...} but not $VAR or ${#VAR} */ + /* c == first char after VAR */ switch (c) { case ':': c = pgetc(); #if ENABLE_ASH_BASH_COMPAT if (c == ':' || c == '$' || isdigit(c)) { - pungetc(); subtype = VSSUBSTR; - break; + pungetc(); + break; /* "goto do_pungetc" is bigger (!) */ } #endif flags = VSNUL; /*FALLTHROUGH*/ - default: - p = strchr(types, c); + default: { + static const char types[] ALIGN1 = "}-+?="; + const char *p = strchr(types, c); if (p == NULL) goto badsub; subtype = p - types + VSNORMAL; break; + } case '%': case '#': { int cc = c; - subtype = c == '#' ? VSTRIMLEFT : VSTRIMRIGHT; + subtype = (c == '#' ? VSTRIMLEFT : VSTRIMRIGHT); c = pgetc(); - if (c == cc) - subtype++; - else - pungetc(); + if (c != cc) + goto do_pungetc; + subtype++; break; } #if ENABLE_ASH_BASH_COMPAT case '/': subtype = VSREPLACE; c = pgetc(); - if (c == '/') - subtype++; /* VSREPLACEALL */ - else - pungetc(); + if (c != '/') + goto do_pungetc; + subtype++; /* VSREPLACEALL */ break; #endif } } else { + do_pungetc: pungetc(); } if (dblquote || arinest) diff --git a/shell/ash_test/ash-redir/redir9.tests b/shell/ash_test/ash-redir/redir9.tests old mode 100644 new mode 100755 diff --git a/shell/ash_test/ash-vars/var_bash3.right b/shell/ash_test/ash-vars/var_bash3.right index f7f14791e..a97c850ea 100644 --- a/shell/ash_test/ash-vars/var_bash3.right +++ b/shell/ash_test/ash-vars/var_bash3.right @@ -1,20 +1,20 @@ -a041#c -a041#c -a\041#c -a\041#c -a\041#c -a\041#c -a\041#c -a\041#c -a\041#c -a\c -a\c -a\c -a\\c -a\\c -a\\c -a\tc -a\tc -a\tc -atc -a\tc +1 a041#c +2 a041#c +3 a\041#c +4 a\041#c +5 a\041#c +6 a\041#c +7 a\041#c +8 a\041#c +9 a\041#c +10 a\c +11 a\c +12 a\c +13 a\\c +14 a\\c +15 a\\c +16 a\tc +17 a\tc +18 a\tc +19 atc +20 a\tc diff --git a/shell/ash_test/ash-vars/var_bash3.tests b/shell/ash_test/ash-vars/var_bash3.tests index b9050279e..eca3318e2 100755 --- a/shell/ash_test/ash-vars/var_bash3.tests +++ b/shell/ash_test/ash-vars/var_bash3.tests @@ -1,41 +1,48 @@ a='abc' r=${a//b/\041#} -echo $r -echo ${a//b/\041#} -echo "${a//b/\041#}" +echo 1 $r +echo 2 ${a//b/\041#} +echo 3 "${a//b/\041#}" +# --- var_bash3.xx +# +++ var_bash3.right +# -1 a\041#c +# +1 a041#c +# 2 a041#c +# -3 a041#c +# +3 a\041#c a='abc' r=${a//b/\\041#} -echo $r -echo ${a//b/\\041#} -echo "${a//b/\\041#}" +echo 4 $r +echo 5 ${a//b/\\041#} +echo 6 "${a//b/\\041#}" a='abc' b='\041#' r=${a//b/$b} -echo $r -echo ${a//b/$b} -echo "${a//b/$b}" +echo 7 $r +echo 8 ${a//b/$b} +echo 9 "${a//b/$b}" a='abc' b='\' r="${a//b/$b}" -echo $r -echo ${a//b/$b} -echo "${a//b/$b}" +echo 10 $r +echo 11 ${a//b/$b} +echo 12 "${a//b/$b}" a='abc' b='\\' r="${a//b/$b}" -echo $r -echo ${a//b/$b} -echo "${a//b/$b}" +echo 13 $r +echo 14 ${a//b/$b} +echo 15 "${a//b/$b}" a='abc' b='\t' r="${a//b/$b}" -echo $r -echo ${a//b/$b} -echo "${a//b/$b}" -echo ${a//b/\t} -echo "${a//b/\t}" +echo 16 $r +echo 17 ${a//b/$b} +echo 18 "${a//b/$b}" +echo 19 ${a//b/\t} +echo 20 "${a//b/\t}" diff --git a/shell/ash_test/ash-vars/var_bash4.right b/shell/ash_test/ash-vars/var_bash4.right new file mode 100644 index 000000000..33a511238 --- /dev/null +++ b/shell/ash_test/ash-vars/var_bash4.right @@ -0,0 +1,2 @@ +a*b-backslashstar- +Done: 0 diff --git a/shell/ash_test/ash-vars/var_bash4.tests b/shell/ash_test/ash-vars/var_bash4.tests new file mode 100755 index 000000000..304b3d91c --- /dev/null +++ b/shell/ash_test/ash-vars/var_bash4.tests @@ -0,0 +1,3 @@ +FOO='a*b\*c' +echo "${FOO//\\*/-backslashstar-}" +echo Done: $? -- cgit v1.2.3-55-g6feb From 6814cbc9288601840aedb372e2bd84dab76ffa43 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 5 Aug 2010 18:29:13 +0200 Subject: ash: extend var_bash4.tests; nocode changes Signed-off-by: Denys Vlasenko --- shell/ash_test/ash-vars/var_bash4.right | 4 +++- shell/ash_test/ash-vars/var_bash4.tests | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/shell/ash_test/ash-vars/var_bash4.right b/shell/ash_test/ash-vars/var_bash4.right index 33a511238..fc3a9e41c 100644 --- a/shell/ash_test/ash-vars/var_bash4.right +++ b/shell/ash_test/ash-vars/var_bash4.right @@ -1,2 +1,4 @@ -a*b-backslashstar- +In assignment: a*b-backslashstar- +Unquoted: a*b-backslashstar- +Quoted: a*b-backslashstar- Done: 0 diff --git a/shell/ash_test/ash-vars/var_bash4.tests b/shell/ash_test/ash-vars/var_bash4.tests index 304b3d91c..3b323c576 100755 --- a/shell/ash_test/ash-vars/var_bash4.tests +++ b/shell/ash_test/ash-vars/var_bash4.tests @@ -1,3 +1,6 @@ FOO='a*b\*c' -echo "${FOO//\\*/-backslashstar-}" +BAR=${FOO//\\*/-backslashstar-} +echo In assignment: "$BAR" +echo Unquoted: ${FOO//\\*/-backslashstar-} +echo Quoted: "${FOO//\\*/-backslashstar-}" echo Done: $? -- cgit v1.2.3-55-g6feb