From aldot at busybox.net Sun Sep 2 07:51:56 2007 From: aldot at busybox.net (aldot at busybox.net) Date: Sun, 2 Sep 2007 07:51:56 -0700 (PDT) Subject: svn commit: trunk/busybox/scripts Message-ID: <20070902145156.449A5A6575@busybox.net> Author: aldot Date: 2007-09-02 07:51:54 -0700 (Sun, 02 Sep 2007) New Revision: 19760 Log: - fix bug where we linked again -lm even though it is not needed. For BBOX_LIB_LIST="crypt m" trylink ... with just applet true, we pulled in libm because in this case we tried to use invalid flags (plain "-l" without a lib) which of course failed, thus the script thought that -lm was needed. The fix is not to pass "-l" without a lib if we are about to check if any or the last remaining lib is really needed. Modified: trunk/busybox/scripts/trylink Changeset: Modified: trunk/busybox/scripts/trylink =================================================================== --- trunk/busybox/scripts/trylink 2007-09-01 19:42:11 UTC (rev 19759) +++ trunk/busybox/scripts/trylink 2007-09-02 14:51:54 UTC (rev 19760) @@ -39,8 +39,17 @@ for one in $BBOX_LIB_LIST; do without_one=`echo " $BBOX_LIB_LIST " | sed "s/ $one / /g" | xargs` l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/'` - $debug && echo "Trying -l options: $l_list" - if try "-Wl,--start-group $l_list -Wl,--end-group" "$@"; then + # If l_list is just "-l" without a lib, then make sure to test the + # correct thing to fail: just using -l will fail, so the last lib + # (usually m in my case) will incorrectly be added as needed. + if test "x$without_one" != "x"; then + l_list="-Wl,--start-group $l_list -Wl,--end-group" + else + # without_one is empty, so l_list has to be empty too + l_list="" + fi + $debug && echo "Trying -l options: '$l_list'" + if try "$l_list" "$@"; then echo "Library $one is not needed" BBOX_LIB_LIST="$without_one" all_needed=false From aldot at busybox.net Sun Sep 2 08:28:30 2007 From: aldot at busybox.net (aldot at busybox.net) Date: Sun, 2 Sep 2007 08:28:30 -0700 (PDT) Subject: svn commit: trunk/busybox/scripts Message-ID: <20070902152830.24992A4636@busybox.net> Author: aldot Date: 2007-09-02 08:28:30 -0700 (Sun, 02 Sep 2007) New Revision: 19762 Log: - Generally strip off -l that does not pull in a lib. If l_list is non-empty then add the group flags. Modified: trunk/busybox/scripts/trylink Changeset: Modified: trunk/busybox/scripts/trylink =================================================================== --- trunk/busybox/scripts/trylink 2007-09-02 14:56:39 UTC (rev 19761) +++ trunk/busybox/scripts/trylink 2007-09-02 15:28:30 UTC (rev 19762) @@ -14,9 +14,11 @@ BBOX_LIB_LIST=`echo "$BBOX_LIB_LIST" | xargs -n1 | sort | uniq | xargs` # First link with all libs. If it fails, bail out -l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/'` +l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` + echo "Trying libraries: $BBOX_LIB_LIST" -try "-Wl,--start-group $l_list -Wl,--end-group" "$@" \ +test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" +try "$l_list" "$@" \ || { echo "Failed: $* -Wl,--start-group $l_list -Wl,--end-group" cat busybox_ld.err @@ -38,16 +40,8 @@ all_needed=true for one in $BBOX_LIB_LIST; do without_one=`echo " $BBOX_LIB_LIST " | sed "s/ $one / /g" | xargs` - l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/'` - # If l_list is just "-l" without a lib, then make sure to test the - # correct thing to fail: just using -l will fail, so the last lib - # (usually m in my case) will incorrectly be added as needed. - if test "x$without_one" != "x"; then - l_list="-Wl,--start-group $l_list -Wl,--end-group" - else - # without_one is empty, so l_list has to be empty too - l_list="" - fi + l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` + test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" $debug && echo "Trying -l options: '$l_list'" if try "$l_list" "$@"; then echo "Library $one is not needed" @@ -71,10 +65,12 @@ ####$ever_discarded && { # Make the binary with final, minimal list of libs echo "Final link with: $BBOX_LIB_LIST" - l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/'` + l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` # --verbose gives us gobs of info to stdout (e.g. linker script used) + test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group -Wl,--verbose" if ! test -f busybox_ldscript; then - try "-Wl,--start-group $l_list -Wl,--end-group -Wl,--verbose" "$@" >busybox_ld.out ####|| exit 1 + + try "$l_list" "$@" >busybox_ld.out ####|| exit 1 else echo "Custom linker script 'busybox_ldscript' found, using it" # Add SORT_BY_ALIGNMENT to linker script (found in busybox_ld.out): @@ -82,7 +78,7 @@ # *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*) # *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*) # This will eliminate most of the data padding (~3kb). - try "-Wl,--start-group $l_list -Wl,--end-group -Wl,--verbose -Wl,-T -Wl,busybox_ldscript" "$@" >busybox_ld.out + try "$l_list -Wl,-T -Wl,busybox_ldscript" "$@" >busybox_ld.out fi ####} ####rm busybox_ld.err From aldot at busybox.net Sun Sep 2 15:12:07 2007 From: aldot at busybox.net (aldot at busybox.net) Date: Sun, 2 Sep 2007 15:12:07 -0700 (PDT) Subject: svn commit: trunk/busybox/networking Message-ID: <20070902221207.B6AEBA6817@busybox.net> Author: aldot Date: 2007-09-02 15:12:07 -0700 (Sun, 02 Sep 2007) New Revision: 19768 Log: - IFUPDOWN_IFSTATE_PATH depends on IFUPDOWN Modified: trunk/busybox/networking/Config.in Changeset: Modified: trunk/busybox/networking/Config.in =================================================================== --- trunk/busybox/networking/Config.in 2007-09-02 22:09:11 UTC (rev 19767) +++ trunk/busybox/networking/Config.in 2007-09-02 22:12:07 UTC (rev 19768) @@ -249,6 +249,7 @@ config IFUPDOWN_IFSTATE_PATH string "Absolute path to ifstate file" default "/var/run/ifstate" + depends on IFUPDOWN help ifupdown keeps state information in a file called ifstate. Typically it is located in /var/run/ifstate, however From vda at busybox.net Mon Sep 3 04:28:15 2007 From: vda at busybox.net (vda at busybox.net) Date: Mon, 3 Sep 2007 04:28:15 -0700 (PDT) Subject: svn commit: trunk/busybox/scripts Message-ID: <20070903112815.9D6BCA6815@busybox.net> Author: vda Date: 2007-09-03 04:28:14 -0700 (Mon, 03 Sep 2007) New Revision: 19774 Log: trylink: reinstate accidentally deleted --verbose trylink: remove commented-out parts Modified: trunk/busybox/scripts/trylink Changeset: Modified: trunk/busybox/scripts/trylink =================================================================== --- trunk/busybox/scripts/trylink 2007-09-03 09:02:10 UTC (rev 19773) +++ trunk/busybox/scripts/trylink 2007-09-03 11:28:14 UTC (rev 19774) @@ -14,9 +14,8 @@ BBOX_LIB_LIST=`echo "$BBOX_LIB_LIST" | xargs -n1 | sort | uniq | xargs` # First link with all libs. If it fails, bail out -l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` - echo "Trying libraries: $BBOX_LIB_LIST" +l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" try "$l_list" "$@" \ || { @@ -25,16 +24,8 @@ exit 1 } -#### Hack disabled: conflicts with ld --verbose flag in last link phase - -##### Hack: we are not supposed to know executable name, -##### but this hack cuts down link time -####mv busybox_unstripped busybox_unstripped.tmp -####mv busybox.map busybox.map.tmp - # Now try to remove each lib and build without it. # Stop when no lib can be removed. -####ever_discarded=false while test "$BBOX_LIB_LIST"; do $debug && echo "Trying libraries: $BBOX_LIB_LIST" all_needed=true @@ -47,7 +38,6 @@ echo "Library $one is not needed" BBOX_LIB_LIST="$without_one" all_needed=false -#### ever_discarded=true else echo "Library $one is needed" fi @@ -60,26 +50,19 @@ #{ echo "$BBOX_LIB_LIST" | grep -q ' '; } || break done -####mv busybox_unstripped.tmp busybox_unstripped -####mv busybox.map.tmp busybox.map -####$ever_discarded && { - # Make the binary with final, minimal list of libs - echo "Final link with: $BBOX_LIB_LIST" - l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` - # --verbose gives us gobs of info to stdout (e.g. linker script used) - test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group -Wl,--verbose" - if ! test -f busybox_ldscript; then - - try "$l_list" "$@" >busybox_ld.out ####|| exit 1 - else - echo "Custom linker script 'busybox_ldscript' found, using it" - # Add SORT_BY_ALIGNMENT to linker script (found in busybox_ld.out): - # .rodata : { *(.rodata SORT_BY_ALIGNMENT(.rodata.*) .gnu.linkonce.r.*) } - # *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*) - # *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*) - # This will eliminate most of the data padding (~3kb). - try "$l_list -Wl,-T -Wl,busybox_ldscript" "$@" >busybox_ld.out - fi -####} -####rm busybox_ld.err -####exit 0 # Ensure "success" exit code +# Make the binary with final, minimal list of libs +echo "Final link with: $BBOX_LIB_LIST" +l_list=`echo "$BBOX_LIB_LIST" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` +test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group -Wl,--verbose" +# --verbose gives us gobs of info to stdout (e.g. linker script used) +if ! test -f busybox_ldscript; then + try "$l_list -Wl,--verbose" "$@" >busybox_ld.out +else + echo "Custom linker script 'busybox_ldscript' found, using it" + # Add SORT_BY_ALIGNMENT to linker script (found in busybox_ld.out): + # .rodata : { *(.rodata SORT_BY_ALIGNMENT(.rodata.*) .gnu.linkonce.r.*) } + # *(.data SORT_BY_ALIGNMENT(.data.*) .gnu.linkonce.d.*) + # *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*) + # This will eliminate most of the data padding (~3kb). + try "$l_list -Wl,--verbose -Wl,-T -Wl,busybox_ldscript" "$@" >busybox_ld.out +fi From vda at busybox.net Mon Sep 3 04:56:28 2007 From: vda at busybox.net (vda at busybox.net) Date: Mon, 3 Sep 2007 04:56:28 -0700 (PDT) Subject: svn commit: trunk/busybox/loginutils Message-ID: <20070903115628.9049AA6833@busybox.net> Author: vda Date: 2007-09-03 04:56:27 -0700 (Mon, 03 Sep 2007) New Revision: 19775 Log: login: do reject wrong passwords with PAM auth Modified: trunk/busybox/loginutils/login.c Changeset: Modified: trunk/busybox/loginutils/login.c =================================================================== --- trunk/busybox/loginutils/login.c 2007-09-03 11:28:14 UTC (rev 19774) +++ trunk/busybox/loginutils/login.c 2007-09-03 11:56:27 UTC (rev 19775) @@ -307,18 +307,26 @@ goto pam_auth_failed; } pamret = pam_authenticate(pamh, 0); - if (pamret == PAM_SUCCESS) { - char *pamuser; - /* check that the account is healthy. */ - pamret = pam_acct_mgmt(pamh, 0); - if (pamret != PAM_SUCCESS) { - failed_msg = "account setup"; - goto pam_auth_failed; - } - /* read user back */ + if (pamret != PAM_SUCCESS) { + failed_msg = "pam_authenticate"; + goto pam_auth_failed; + /* TODO: or just "goto auth_failed" + * since user seems to enter wrong password + * (in this case pamret == 7) + */ + } + /* check that the account is healthy */ + pamret = pam_acct_mgmt(pamh, 0); + if (pamret != PAM_SUCCESS) { + failed_msg = "account setup"; + goto pam_auth_failed; + } + /* read user back */ + { + const char *pamuser; /* gcc: "dereferencing type-punned pointer breaks aliasing rules..." - * thus we use double cast */ - if (pam_get_item(pamh, PAM_USER, (const void **)(void*)&pamuser) != PAM_SUCCESS) { + * thus we cast to (void*) */ + if (pam_get_item(pamh, PAM_USER, (void*)&pamuser) != PAM_SUCCESS) { failed_msg = "pam_get_item(USER)"; goto pam_auth_failed; } @@ -331,7 +339,7 @@ break; goto auth_failed; pam_auth_failed: - bb_error_msg("%s failed: %s", failed_msg, pam_strerror(pamh, pamret)); + bb_error_msg("%s failed: %s (%d)", failed_msg, pam_strerror(pamh, pamret), pamret); safe_strncpy(username, "UNKNOWN", sizeof(username)); #else /* not PAM */ pw = getpwnam(username); @@ -360,6 +368,7 @@ auth_failed: opt &= ~LOGIN_OPT_f; bb_do_delay(FAIL_DELAY); + /* TODO: doesn't sound like correct English phrase to me */ puts("Login incorrect"); if (++count == 3) { syslog(LOG_WARNING, "invalid password for '%s'%s", From vda at busybox.net Mon Sep 3 13:06:00 2007 From: vda at busybox.net (vda at busybox.net) Date: Mon, 3 Sep 2007 13:06:00 -0700 (PDT) Subject: svn commit: trunk/busybox/coreutils Message-ID: <20070903200600.46DD1A614D@busybox.net> Author: vda Date: 2007-09-03 13:05:58 -0700 (Mon, 03 Sep 2007) New Revision: 19776 Log: du: remove statics (by Bernhard Fischer ) $ ./.cmk bloatcheck function old new delta du_main 340 348 +8 print 39 40 +1 status 129 125 -4 slink_depth 4 - -4 print_files 4 - -4 one_file_system 4 - -4 max_print_depth 4 - -4 du_depth 4 - -4 disp_hr 4 - -4 count_hardlinks 4 - -4 du 407 401 -6 dir_dev 8 - -8 ------------------------------------------------------------------------------ (add/remove: 0/8 grow/shrink: 2/2 up/down: 9/-46) Total: -37 bytes text data bss dec hex filename 864 12 28 904 388 busybox.t3/coreutils/du.o 867 0 0 867 363 busybox.t4/coreutils/du.o 770647 1063 10788 782498 bf0a2 busybox.t3/busybox_unstripped 770651 1051 10764 782466 bf082 busybox.t4/busybox_unstripped Modified: trunk/busybox/coreutils/du.c Changeset: Modified: trunk/busybox/coreutils/du.c =================================================================== --- trunk/busybox/coreutils/du.c 2007-09-03 11:56:27 UTC (rev 19775) +++ trunk/busybox/coreutils/du.c 2007-09-03 20:05:58 UTC (rev 19776) @@ -25,37 +25,34 @@ #include "libbb.h" +struct globals { #if ENABLE_FEATURE_HUMAN_READABLE -# if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K -static unsigned long disp_hr = 1024; -# else -static unsigned long disp_hr = 512; -# endif -#elif ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K -static unsigned disp_k = 1; + unsigned long disp_hr; #else -static unsigned disp_k; /* bss inits to 0 */ + unsigned disp_k; #endif -static int max_print_depth = INT_MAX; -static nlink_t count_hardlinks = 1; + int max_print_depth; + nlink_t count_hardlinks; -static int status; -static int print_files; -static int slink_depth; -static int du_depth; -static int one_file_system; -static dev_t dir_dev; + bool status; + bool one_file_system; + int print_files; + int slink_depth; + int du_depth; + dev_t dir_dev; +}; +#define G (*(struct globals*)&bb_common_bufsiz1) -static void print(long size, const char *const filename) +static void print(unsigned long size, const char *filename) { /* TODO - May not want to defer error checking here. */ #if ENABLE_FEATURE_HUMAN_READABLE - printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr), + printf("%s\t%s\n", make_human_readable_str(size, 512, G.disp_hr), filename); #else - if (disp_k) { + if (G.disp_k) { size++; size >>= 1; } @@ -64,21 +61,21 @@ } /* tiny recursive du */ -static long du(const char *const filename) +static unsigned long du(const char *filename) { struct stat statbuf; - long sum; + unsigned long sum; if (lstat(filename, &statbuf) != 0) { bb_perror_msg("%s", filename); - status = EXIT_FAILURE; + G.status = EXIT_FAILURE; return 0; } - if (one_file_system) { - if (du_depth == 0) { - dir_dev = statbuf.st_dev; - } else if (dir_dev != statbuf.st_dev) { + if (G.one_file_system) { + if (G.du_depth == 0) { + G.dir_dev = statbuf.st_dev; + } else if (G.dir_dev != statbuf.st_dev) { return 0; } } @@ -86,20 +83,20 @@ sum = statbuf.st_blocks; if (S_ISLNK(statbuf.st_mode)) { - if (slink_depth > du_depth) { /* -H or -L */ + if (G.slink_depth > G.du_depth) { /* -H or -L */ if (stat(filename, &statbuf) != 0) { bb_perror_msg("%s", filename); - status = EXIT_FAILURE; + G.status = EXIT_FAILURE; return 0; } sum = statbuf.st_blocks; - if (slink_depth == 1) { - slink_depth = INT_MAX; /* Convert -H to -L. */ + if (G.slink_depth == 1) { + G.slink_depth = INT_MAX; /* Convert -H to -L. */ } } } - if (statbuf.st_nlink > count_hardlinks) { + if (statbuf.st_nlink > G.count_hardlinks) { /* Add files/directories with links only once */ if (is_in_ino_dev_hashtable(&statbuf)) { return 0; @@ -114,7 +111,7 @@ dir = warn_opendir(filename); if (!dir) { - status = EXIT_FAILURE; + G.status = EXIT_FAILURE; return sum; } @@ -128,16 +125,16 @@ newfile = concat_subpath_file(filename, name); if (newfile == NULL) continue; - ++du_depth; + ++G.du_depth; sum += du(newfile); - --du_depth; + --G.du_depth; free(newfile); } closedir(dir); - } else if (du_depth > print_files) { + } else if (G.du_depth > G.print_files) { return sum; } - if (du_depth <= max_print_depth) { + if (G.du_depth <= G.max_print_depth) { print(sum, filename); } return sum; @@ -146,21 +143,23 @@ int du_main(int argc, char **argv); int du_main(int argc, char **argv) { - long total; + unsigned long total; int slink_depth_save; - int print_final_total; + bool print_final_total; char *smax_print_depth; unsigned opt; -#if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K - if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */ #if ENABLE_FEATURE_HUMAN_READABLE - disp_hr = 512; + USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;) + SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;) + if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */ + G.disp_hr = 512; #else - disp_k = 0; + USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 1;) + /* SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 0;) - G is pre-zeroed */ #endif - } -#endif + G.max_print_depth = INT_MAX; + G.count_hardlinks = 1; /* Note: SUSv3 specifies that -a and -s options cannot be used together * in strictly conforming applications. However, it also says that some @@ -171,75 +170,76 @@ #if ENABLE_FEATURE_HUMAN_READABLE opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s"; opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth); + argv += optind; if (opt & (1 << 9)) { /* -h opt */ - disp_hr = 0; + G.disp_hr = 0; } if (opt & (1 << 10)) { /* -m opt */ - disp_hr = 1024*1024; + G.disp_hr = 1024*1024; } if (opt & (1 << 2)) { /* -k opt */ - disp_hr = 1024; + G.disp_hr = 1024; } #else opt_complementary = "H-L:L-H:s-d:d-s"; opt = getopt32(argv, "aHkLsx" "d:" "lc", &smax_print_depth); + argv += optind; #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K if (opt & (1 << 2)) { /* -k opt */ - disp_k = 1; + G.disp_k = 1; } #endif #endif if (opt & (1 << 0)) { /* -a opt */ - print_files = INT_MAX; + G.print_files = INT_MAX; } if (opt & (1 << 1)) { /* -H opt */ - slink_depth = 1; + G.slink_depth = 1; } if (opt & (1 << 3)) { /* -L opt */ - slink_depth = INT_MAX; + G.slink_depth = INT_MAX; } if (opt & (1 << 4)) { /* -s opt */ - max_print_depth = 0; + G.max_print_depth = 0; } - one_file_system = opt & (1 << 5); /* -x opt */ + G.one_file_system = opt & (1 << 5); /* -x opt */ if (opt & (1 << 6)) { /* -d opt */ - max_print_depth = xatoi_u(smax_print_depth); + G.max_print_depth = xatoi_u(smax_print_depth); } if (opt & (1 << 7)) { /* -l opt */ - count_hardlinks = MAXINT(nlink_t); + G.count_hardlinks = MAXINT(nlink_t); } print_final_total = opt & (1 << 8); /* -c opt */ /* go through remaining args (if any) */ - argv += optind; - if (optind >= argc) { + if (!*argv) { *--argv = (char*)"."; - if (slink_depth == 1) { - slink_depth = 0; + if (G.slink_depth == 1) { + G.slink_depth = 0; } } - slink_depth_save = slink_depth; + slink_depth_save = G.slink_depth; total = 0; do { total += du(*argv); - slink_depth = slink_depth_save; + G.slink_depth = slink_depth_save; } while (*++argv); + if (ENABLE_FEATURE_CLEAN_UP) reset_ino_dev_hashtable(); - if (print_final_total) { + if (print_final_total) print(total, "total"); - } - fflush_stdout_and_exit(status); + fflush_stdout_and_exit(G.status); } From bugs at busybox.net Tue Sep 4 04:13:34 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Tue, 4 Sep 2007 04:13:34 -0700 Subject: [BusyBox 0001482]: watchdog should support subsecond refresh interval Message-ID: <4fad2b3aed3bbf95090f1dd993a311e0@bugs.busybox.net> The following issue has been SUBMITTED. ====================================================================== http://busybox.net/bugs/view.php?id=1482 ====================================================================== Reported By: iggarpe Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1482 Category: New Features Reproducibility: always Severity: feature Priority: normal Status: assigned ====================================================================== Date Submitted: 09-04-2007 04:13 PDT Last Modified: 09-04-2007 04:13 PDT ====================================================================== Summary: watchdog should support subsecond refresh interval Description: Some advantech boards comes with a crippled watchdog that can only support a 1 second timeout. In this scenario, the watchdog utility is completely useless (the lowes refresh interval would be 1 ("watchdog -t 1"). ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 09-04-07 04:13 iggarpe New Issue 09-04-07 04:13 iggarpe Status new => assigned 09-04-07 04:13 iggarpe Assigned To => BusyBox ====================================================================== From vda at busybox.net Tue Sep 4 11:30:27 2007 From: vda at busybox.net (vda at busybox.net) Date: Tue, 4 Sep 2007 11:30:27 -0700 (PDT) Subject: svn commit: trunk/busybox/util-linux Message-ID: <20070904183027.EFF49A659B@busybox.net> Author: vda Date: 2007-09-04 11:30:26 -0700 (Tue, 04 Sep 2007) New Revision: 19782 Log: mount: ignore NFS bg option on NOMMU machines Modified: trunk/busybox/util-linux/mount.c Changeset: Modified: trunk/busybox/util-linux/mount.c =================================================================== --- trunk/busybox/util-linux/mount.c 2007-09-04 16:22:41 UTC (rev 19781) +++ trunk/busybox/util-linux/mount.c 2007-09-04 18:30:26 UTC (rev 19782) @@ -725,6 +725,7 @@ return &p; } +#if BB_MMU static int daemonize(void) { int fd; @@ -744,6 +745,9 @@ logmode = LOGMODE_SYSLOG; return 1; } +#else +static inline int daemonize(void) { return -ENOSYS; } +#endif // TODO static inline int we_saw_this_host_before(const char *hostname) @@ -786,7 +790,11 @@ int port; int mountport; int proto; - int bg; +#if BB_MMU + int bg = 0; +#else + enum { bg = 0 }; +#endif int soft; int intr; int posix; @@ -867,7 +875,6 @@ data.acdirmax = 60; data.namlen = NAME_MAX; - bg = 0; soft = 0; intr = 0; posix = 0; @@ -1010,10 +1017,14 @@ } switch (index_in_strings(options, opt)) { case 0: // "bg" +#if BB_MMU bg = val; +#endif break; case 1: // "fg" +#if BB_MMU bg = !val; +#endif break; case 2: // "soft" soft = val; From vda at busybox.net Tue Sep 4 12:33:24 2007 From: vda at busybox.net (vda at busybox.net) Date: Tue, 4 Sep 2007 12:33:24 -0700 (PDT) Subject: svn commit: trunk/busybox: archival archival/libunarchive include Message-ID: <20070904193324.82FCCA606B@busybox.net> Author: vda Date: 2007-09-04 12:33:22 -0700 (Tue, 04 Sep 2007) New Revision: 19783 Log: tar: conditionally don't wait for vforked child to exec, as it always works right on Linux, and anyway mayresult only on less-than-clear error message only, it will not cause tar to misbehave. function old new delta open_transformer 98 80 -18 writeTarFile 714 547 -167 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-185) Total: -185 bytes text data bss dec hex filename 770651 1051 10764 782466 bf082 busybox_old 770463 1051 10764 782278 befc6 busybox_unstripped Modified: trunk/busybox/archival/libunarchive/open_transformer.c trunk/busybox/archival/tar.c trunk/busybox/include/libbb.h Changeset: Modified: trunk/busybox/archival/libunarchive/open_transformer.c =================================================================== --- trunk/busybox/archival/libunarchive/open_transformer.c 2007-09-04 18:30:26 UTC (rev 19782) +++ trunk/busybox/archival/libunarchive/open_transformer.c 2007-09-04 19:33:22 UTC (rev 19783) @@ -25,8 +25,10 @@ close(fd_pipe[0]); /* We don't wan't to read from the parent */ // FIXME: error check? transformer(src_fd, fd_pipe[1]); - close(fd_pipe[1]); /* Send EOF */ - close(src_fd); + if (ENABLE_FEATURE_CLEAN_UP) { + close(fd_pipe[1]); /* Send EOF */ + close(src_fd); + } exit(0); /* notreached */ } Modified: trunk/busybox/archival/tar.c =================================================================== --- trunk/busybox/archival/tar.c 2007-09-04 18:30:26 UTC (rev 19782) +++ trunk/busybox/archival/tar.c 2007-09-04 19:33:22 UTC (rev 19783) @@ -106,7 +106,7 @@ typedef enum TarFileType TarFileType; /* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */ -static void addHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr, +static void addHardLinkInfo(HardLinkInfo **hlInfoHeadPtr, struct stat *statbuf, const char *fileName) { @@ -122,7 +122,7 @@ strcpy(hlInfo->name, fileName); } -static void freeHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr) +static void freeHardLinkInfo(HardLinkInfo **hlInfoHeadPtr) { HardLinkInfo *hlInfo; HardLinkInfo *hlInfoNext; @@ -139,7 +139,7 @@ } /* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */ -static HardLinkInfo *findHardLinkInfo(HardLinkInfo * hlInfo, struct stat *statbuf) +static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf) { while (hlInfo) { if ((statbuf->st_ino == hlInfo->ino) && (statbuf->st_dev == hlInfo->dev)) @@ -504,13 +504,21 @@ bb_perror_msg_and_die("cannot stat tar file"); if ((ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2) && gzip) { - int gzipDataPipe[2] = { -1, -1 }; - int gzipStatusPipe[2] = { -1, -1 }; +// On Linux, vfork never unpauses parent early, although standard +// allows for that. Do we want to waste bytes checking for it? +#define WAIT_FOR_CHILD 0 + volatile int vfork_exec_errno = 0; +#if WAIT_FOR_CHILD + struct { int rd; int wr; } gzipStatusPipe; +#endif + struct { int rd; int wr; } gzipDataPipe; const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2"; - xpipe(gzipDataPipe); - xpipe(gzipStatusPipe); + xpipe(&gzipDataPipe.rd); +#if WAIT_FOR_CHILD + xpipe(&gzipStatusPipe.rd); +#endif signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */ @@ -522,41 +530,45 @@ #endif gzipPid = vfork(); + if (gzipPid < 0) + bb_perror_msg_and_die("vfork gzip"); if (gzipPid == 0) { - dup2(gzipDataPipe[0], 0); - close(gzipDataPipe[1]); - - dup2(tbInfo.tarFd, 1); - - close(gzipStatusPipe[0]); - fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows success */ - + /* child */ + xmove_fd(tbInfo.tarFd, 1); + xmove_fd(gzipDataPipe.rd, 0); + close(gzipDataPipe.wr); +#if WAIT_FOR_CHILD + close(gzipStatusPipe.rd); + fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC); +#endif + /* exec gzip/bzip2 program/applet */ BB_EXECLP(zip_exec, zip_exec, "-f", NULL); vfork_exec_errno = errno; + _exit(1); + } - close(gzipStatusPipe[1]); - exit(-1); - } else if (gzipPid > 0) { - close(gzipDataPipe[0]); - close(gzipStatusPipe[1]); + /* parent */ + xmove_fd(gzipDataPipe.wr, tbInfo.tarFd); + close(gzipDataPipe.rd); +#if WAIT_FOR_CHILD + close(gzipStatusPipe.wr); + while (1) { + char buf; + int n; - while (1) { - char buf; + /* Wait until child execs (or fails to) */ + n = full_read(gzipStatusPipe.rd, &buf, 1); + if ((n < 0) && (/*errno == EAGAIN ||*/ errno == EINTR)) + continue; /* try it again */ - int n = full_read(gzipStatusPipe[0], &buf, 1); - - if (n == 0 && vfork_exec_errno != 0) { - errno = vfork_exec_errno; - bb_perror_msg_and_die("cannot exec %s", zip_exec); - } else if ((n < 0) && (errno == EAGAIN || errno == EINTR)) - continue; /* try it again */ - break; - } - close(gzipStatusPipe[0]); - - tbInfo.tarFd = gzipDataPipe[1]; - } else bb_perror_msg_and_die("vfork gzip"); + } + close(gzipStatusPipe.rd); +#endif + if (vfork_exec_errno) { + errno = vfork_exec_errno; + bb_perror_msg_and_die("cannot exec %s", zip_exec); + } } tbInfo.excludeList = exclude; Modified: trunk/busybox/include/libbb.h =================================================================== --- trunk/busybox/include/libbb.h 2007-09-04 18:30:26 UTC (rev 19782) +++ trunk/busybox/include/libbb.h 2007-09-04 19:33:22 UTC (rev 19783) @@ -512,6 +512,9 @@ char *find_execable(const char *filename); int exists_execable(const char *filename); +/* BB_EXECxx always execs (it's not doing NOFORK/NOEXEC stuff), + * but it may exec busybox and call applet instead of searching PATH. + */ #if ENABLE_FEATURE_PREFER_APPLETS int bb_execvp(const char *file, char *const argv[]); #define BB_EXECVP(prog,cmd) bb_execvp(prog,cmd) From vda at busybox.net Wed Sep 5 04:30:35 2007 From: vda at busybox.net (vda at busybox.net) Date: Wed, 5 Sep 2007 04:30:35 -0700 (PDT) Subject: svn commit: trunk/busybox: applets include libbb Message-ID: <20070905113035.DC718A69B2@busybox.net> Author: vda Date: 2007-09-05 04:30:34 -0700 (Wed, 05 Sep 2007) New Revision: 19791 Log: busybox --install -s: prevent puzzling "/bin/busybox: Invalid argument" message libbb: comment out realpath, add readlink which doesn't warn Modified: trunk/busybox/applets/applets.c trunk/busybox/include/libbb.h trunk/busybox/libbb/xreadlink.c Changeset: Modified: trunk/busybox/applets/applets.c =================================================================== --- trunk/busybox/applets/applets.c 2007-09-05 06:52:09 UTC (rev 19790) +++ trunk/busybox/applets/applets.c 2007-09-05 11:30:34 UTC (rev 19791) @@ -546,7 +546,7 @@ help: output_width = 80; if (ENABLE_FEATURE_AUTOWIDTH) { - /* Obtain the terminal width. */ + /* Obtain the terminal width */ get_terminal_width_height(0, &output_width, NULL); } /* leading tab and room to wrap */ @@ -580,12 +580,11 @@ if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) { const char *busybox; - busybox = xmalloc_readlink_or_warn(bb_busybox_exec_path); + busybox = xmalloc_readlink(bb_busybox_exec_path); if (!busybox) busybox = bb_busybox_exec_path; /* -s makes symlinks */ - install_links(busybox, - argv[2] && strcmp(argv[2], "-s") == 0); + install_links(busybox, argv[2] && strcmp(argv[2], "-s") == 0); return 0; } Modified: trunk/busybox/include/libbb.h =================================================================== --- trunk/busybox/include/libbb.h 2007-09-05 06:52:09 UTC (rev 19790) +++ trunk/busybox/include/libbb.h 2007-09-05 11:30:34 UTC (rev 19791) @@ -249,9 +249,10 @@ DIR *xopendir(const char *path); DIR *warn_opendir(const char *path); +/* UNUSED: char *xmalloc_realpath(const char *path); */ +char *xmalloc_readlink(const char *path); +char *xmalloc_readlink_or_warn(const char *path); char *xrealloc_getcwd_or_warn(char *cwd); -char *xmalloc_readlink_or_warn(const char *path); -char *xmalloc_realpath(const char *path); //TODO: signal(sid, f) is the same? then why? @@ -317,8 +318,8 @@ }; /* Create stream socket, and allocate suitable lsa. * (lsa of correct size and lsa->sa.sa_family (AF_INET/AF_INET6)) - * af == AF_UNSPEC will result in trying to create IPv6, and - * if kernel doesn't support it, IPv4. + * af == AF_UNSPEC will result in trying to create IPv6 socket, + * and if kernel doesn't support it, IPv4. */ int xsocket_type(len_and_sockaddr **lsap, USE_FEATURE_IPV6(int af,) int sock_type); int xsocket_stream(len_and_sockaddr **lsap); Modified: trunk/busybox/libbb/xreadlink.c =================================================================== --- trunk/busybox/libbb/xreadlink.c 2007-09-05 06:52:09 UTC (rev 19790) +++ trunk/busybox/libbb/xreadlink.c 2007-09-05 11:30:34 UTC (rev 19791) @@ -10,8 +10,7 @@ * NOTE: This function returns a malloced char* that you will have to free * yourself. You have been warned. */ - -char *xmalloc_readlink_or_warn(const char *path) +char *xmalloc_readlink(const char *path) { enum { GROWBY = 80 }; /* how large we will grow strings by */ @@ -20,20 +19,30 @@ do { buf = xrealloc(buf, bufsize += GROWBY); - readsize = readlink(path, buf, bufsize); /* 1st try */ + readsize = readlink(path, buf, bufsize); if (readsize == -1) { - bb_perror_msg("%s", path); free(buf); return NULL; } - } - while (bufsize < readsize + 1); + } while (bufsize < readsize + 1); buf[readsize] = '\0'; return buf; } +char *xmalloc_readlink_or_warn(const char *path) +{ + char *buf = xmalloc_readlink(path); + if (!buf) { + /* EINVAL => "file: Invalid argument" => puzzled user */ + bb_error_msg("%s: cannot read link (not a symlink?)", path); + } + return buf; +} + +/* UNUSED */ +#if 0 char *xmalloc_realpath(const char *path) { #if defined(__GLIBC__) && !defined(__UCLIBC__) @@ -46,3 +55,4 @@ return xstrdup(realpath(path, buf)); #endif } +#endif From bugs at busybox.net Wed Sep 5 04:42:48 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Wed, 5 Sep 2007 04:42:48 -0700 Subject: [BusyBox 0001482]: watchdog should support subsecond refresh interval Message-ID: <245f967b168f621fe563b656e8dd98a5@bugs.busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1482 ====================================================================== Reported By: iggarpe Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1482 Category: New Features Reproducibility: always Severity: feature Priority: normal Status: assigned ====================================================================== Date Submitted: 09-04-2007 04:13 PDT Last Modified: 09-05-2007 04:42 PDT ====================================================================== Summary: watchdog should support subsecond refresh interval Description: Some advantech boards comes with a crippled watchdog that can only support a 1 second timeout. In this scenario, the watchdog utility is completely useless (the lowes refresh interval would be 1 ("watchdog -t 1"). ====================================================================== ---------------------------------------------------------------------- iggarpe - 09-05-07 04:42 ---------------------------------------------------------------------- Uploaded quasi-trivial patch that supports "ms" suffix in -t option. Issue History Date Modified Username Field Change ====================================================================== 09-04-07 04:13 iggarpe New Issue 09-04-07 04:13 iggarpe Status new => assigned 09-04-07 04:13 iggarpe Assigned To => BusyBox 09-05-07 04:42 iggarpe File Added: busybox-trunk-watchdog-ms.patch 09-05-07 04:42 iggarpe Note Added: 0002715 ====================================================================== From vda at busybox.net Wed Sep 5 04:48:33 2007 From: vda at busybox.net (vda at busybox.net) Date: Wed, 5 Sep 2007 04:48:33 -0700 (PDT) Subject: svn commit: trunk/busybox: archival archival/libunarchive include Message-ID: <20070905114833.6278930043@busybox.net> Author: vda Date: 2007-09-05 04:48:32 -0700 (Wed, 05 Sep 2007) New Revision: 19792 Log: tar + gzip/bzip2/etc: support NOMMU machines (by Alex Landau ) Modified: trunk/busybox/archival/bbunzip.c trunk/busybox/archival/libunarchive/Kbuild trunk/busybox/archival/libunarchive/get_header_tar_bz2.c trunk/busybox/archival/libunarchive/get_header_tar_gz.c trunk/busybox/archival/libunarchive/get_header_tar_lzma.c trunk/busybox/archival/libunarchive/open_transformer.c trunk/busybox/archival/rpm.c trunk/busybox/archival/tar.c trunk/busybox/include/unarchive.h Changeset: Modified: trunk/busybox/archival/bbunzip.c =================================================================== --- trunk/busybox/archival/bbunzip.c 2007-09-05 11:30:34 UTC (rev 19791) +++ trunk/busybox/archival/bbunzip.c 2007-09-05 11:48:32 UTC (rev 19792) @@ -298,7 +298,7 @@ int unlzma_main(int argc, char **argv); int unlzma_main(int argc, char **argv) { - getopt32(argv, "c"); + getopt32(argv, "cf"); argv += optind; /* lzmacat? */ if (applet_name[4] == 'c') Modified: trunk/busybox/archival/libunarchive/Kbuild =================================================================== --- trunk/busybox/archival/libunarchive/Kbuild 2007-09-05 11:30:34 UTC (rev 19791) +++ trunk/busybox/archival/libunarchive/Kbuild 2007-09-05 11:48:32 UTC (rev 19792) @@ -35,36 +35,34 @@ get_header_tar.o \ filter_accept_list_reassign.o -# open_transformer uses fork(). Compile it only if absolutely necessary lib-$(CONFIG_RPM) += open_transformer.o -lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o -lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o -lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o -lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o -lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o -lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o -lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o +lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o +lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o +lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o +lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o +lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o +lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o +lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o -lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o -lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o -lib-$(CONFIG_UNLZMA) += decompress_unlzma.o -lib-$(CONFIG_CPIO) += get_header_cpio.o -lib-$(CONFIG_DPKG) += $(DPKG_FILES) -lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES) -lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += $(GUNZIP_FILES) get_header_tar_gz.o -lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o -lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o -lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES) -lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o -lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o -lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o -lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o -lib-$(CONFIG_TAR) += get_header_tar.o -lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o -lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o -lib-$(CONFIG_FEATURE_TAR_GZIP) += $(GUNZIP_FILES) get_header_tar_gz.o -lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o -lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o -lib-$(CONFIG_UNZIP) += $(GUNZIP_FILES) -lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o - +lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o +lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o +lib-$(CONFIG_UNLZMA) += decompress_unlzma.o +lib-$(CONFIG_CPIO) += get_header_cpio.o +lib-$(CONFIG_DPKG) += $(DPKG_FILES) +lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES) +lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += $(GUNZIP_FILES) get_header_tar_gz.o +lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o +lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o +lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES) +lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o +lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o +lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o +lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o +lib-$(CONFIG_TAR) += get_header_tar.o +lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o +lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o +lib-$(CONFIG_FEATURE_TAR_GZIP) += $(GUNZIP_FILES) get_header_tar_gz.o +lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o +lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o +lib-$(CONFIG_UNZIP) += $(GUNZIP_FILES) +lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o Modified: trunk/busybox/archival/libunarchive/get_header_tar_bz2.c =================================================================== --- trunk/busybox/archival/libunarchive/get_header_tar_bz2.c 2007-09-05 11:30:34 UTC (rev 19791) +++ trunk/busybox/archival/libunarchive/get_header_tar_bz2.c 2007-09-05 11:48:32 UTC (rev 19792) @@ -11,7 +11,7 @@ /* Can't lseek over pipes */ archive_handle->seek = seek_by_read; - archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream); + archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream, "bunzip2", "bunzip2", "-cf", "-", NULL); archive_handle->offset = 0; while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/; Modified: trunk/busybox/archival/libunarchive/get_header_tar_gz.c =================================================================== --- trunk/busybox/archival/libunarchive/get_header_tar_gz.c 2007-09-05 11:30:34 UTC (rev 19791) +++ trunk/busybox/archival/libunarchive/get_header_tar_gz.c 2007-09-05 11:48:32 UTC (rev 19792) @@ -8,19 +8,26 @@ char get_header_tar_gz(archive_handle_t *archive_handle) { +#if BB_MMU unsigned char magic[2]; +#endif /* Can't lseek over pipes */ archive_handle->seek = seek_by_read; + /* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case). + * Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will + * need the header. */ +#if BB_MMU xread(archive_handle->src_fd, &magic, 2); if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { bb_error_msg_and_die("invalid gzip magic"); } check_header_gzip_or_die(archive_handle->src_fd); +#endif - archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream); + archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip", "gunzip", "-cf", "-", NULL); archive_handle->offset = 0; while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/; Modified: trunk/busybox/archival/libunarchive/get_header_tar_lzma.c =================================================================== --- trunk/busybox/archival/libunarchive/get_header_tar_lzma.c 2007-09-05 11:30:34 UTC (rev 19791) +++ trunk/busybox/archival/libunarchive/get_header_tar_lzma.c 2007-09-05 11:48:32 UTC (rev 19792) @@ -14,7 +14,7 @@ /* Can't lseek over pipes */ archive_handle->seek = seek_by_read; - archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream); + archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma", "unlzma", "-cf", "-", NULL); archive_handle->offset = 0; while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/; Modified: trunk/busybox/archival/libunarchive/open_transformer.c =================================================================== --- trunk/busybox/archival/libunarchive/open_transformer.c 2007-09-05 11:30:34 UTC (rev 19791) +++ trunk/busybox/archival/libunarchive/open_transformer.c 2007-09-05 11:48:32 UTC (rev 19792) @@ -7,29 +7,48 @@ #include "unarchive.h" /* transformer(), more than meets the eye */ +/* + * On MMU machine, the transform_prog and ... are stripped + * by a macro in include/unarchive.h. On NOMMU, transformer is stripped. + */ int open_transformer(int src_fd, - USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd)) + USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd), + const char *transform_prog, ...) { int fd_pipe[2]; int pid; xpipe(fd_pipe); +#if BB_MMU pid = fork(); - if (pid == -1) { +#else + pid = vfork(); +#endif + if (pid == -1) bb_perror_msg_and_die("fork failed"); - } if (pid == 0) { +#if !BB_MMU + va_list ap; +#endif /* child process */ close(fd_pipe[0]); /* We don't wan't to read from the parent */ // FIXME: error check? +#if BB_MMU transformer(src_fd, fd_pipe[1]); if (ENABLE_FEATURE_CLEAN_UP) { close(fd_pipe[1]); /* Send EOF */ close(src_fd); } exit(0); +#else + xmove_fd(src_fd, 0); + xmove_fd(fd_pipe[1], 1); + va_start(ap, transform_prog); + BB_EXECVP(transform_prog, ap); + bb_perror_and_die("exec failed"); +#endif /* notreached */ } Modified: trunk/busybox/archival/rpm.c =================================================================== --- trunk/busybox/archival/rpm.c 2007-09-05 11:30:34 UTC (rev 19791) +++ trunk/busybox/archival/rpm.c 2007-09-05 11:48:32 UTC (rev 19792) @@ -187,9 +187,15 @@ static void extract_cpio_gz(int fd) { - USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd); archive_handle_t *archive_handle; unsigned char magic[2]; +#if BB_MMU + USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd); + enum { xformer_prog = 0 }; +#else + enum { xformer = 0 }; + const char *xformer_prog; +#endif /* Initialize */ archive_handle = init_handle(); @@ -202,11 +208,19 @@ archive_handle->offset = 0; xread(archive_handle->src_fd, &magic, 2); +#if BB_MMU xformer = unpack_gz_stream; +#else + xformer_prog = "gunzip"; +#endif if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { if (ENABLE_FEATURE_RPM_BZ2 && (magic[0] == 0x42) && (magic[1] == 0x5a)) { +#if BB_MMU xformer = unpack_bz2_stream; +#else + xformer_prog = "bunzip2"; +#endif /* We can do better, need modifying unpack_bz2_stream to not require * first 2 bytes. Not very hard to do... I mean, TODO :) */ xlseek(archive_handle->src_fd, -2, SEEK_CUR); @@ -214,11 +228,17 @@ bb_error_msg_and_die("no gzip" USE_FEATURE_RPM_BZ2("/bzip") " magic"); - } else + } else { check_header_gzip_or_die(archive_handle->src_fd); +#if !BB_MMU + /* NOMMU version of open_transformer execs an external unzipper that should + * have the file position at the start of the file */ + xlseek(archive_handle->src_fd, 0, SEEK_SET); +#endif + } xchdir("/"); /* Install RPM's to root */ - archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer); + archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer, xformer_prog, xformer_prog, "-cf", "-", NULL); archive_handle->offset = 0; while (get_header_cpio(archive_handle) == EXIT_SUCCESS) continue; Modified: trunk/busybox/archival/tar.c =================================================================== --- trunk/busybox/archival/tar.c 2007-09-05 11:30:34 UTC (rev 19791) +++ trunk/busybox/archival/tar.c 2007-09-05 11:48:32 UTC (rev 19792) @@ -660,7 +660,7 @@ bb_error_msg_and_die("invalid magic"); } - archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress); + archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress, "uncompress", "uncompress", "-cf", "-", NULL); archive_handle->offset = 0; while (get_header_tar(archive_handle) == EXIT_SUCCESS) /* nothing */; Modified: trunk/busybox/include/unarchive.h =================================================================== --- trunk/busybox/include/unarchive.h 2007-09-05 11:30:34 UTC (rev 19791) +++ trunk/busybox/include/unarchive.h 2007-09-05 11:48:32 UTC (rev 19792) @@ -115,7 +115,13 @@ extern USE_DESKTOP(long long) int unpack_gz_stream(int src_fd, int dst_fd); extern USE_DESKTOP(long long) int unpack_lzma_stream(int src_fd, int dst_fd); +#if BB_MMU extern int open_transformer(int src_fd, USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd)); +#define open_transformer(src_fd, transformer, transform_prog, ...) open_transformer(src_fd, transformer) +#else +extern int open_transformer(int src_fd, const char *transform_prog, ...); +#define open_transformer(src_fd, transformer, transform_prog, ...) open_transformer(src_fd, transform_prog, __VA_ARGS__) +#endif #endif From bugs at busybox.net Wed Sep 5 04:49:19 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Wed, 5 Sep 2007 04:49:19 -0700 Subject: [BusyBox 0001482]: watchdog should support subsecond refresh interval Message-ID: <1c29802b33f55017483daabb1d64fd40@bugs.busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1482 ====================================================================== Reported By: iggarpe Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1482 Category: New Features Reproducibility: always Severity: feature Priority: normal Status: assigned ====================================================================== Date Submitted: 09-04-2007 04:13 PDT Last Modified: 09-05-2007 04:49 PDT ====================================================================== Summary: watchdog should support subsecond refresh interval Description: Some advantech boards comes with a crippled watchdog that can only support a 1 second timeout. In this scenario, the watchdog utility is completely useless (the lowes refresh interval would be 1 ("watchdog -t 1"). ====================================================================== ---------------------------------------------------------------------- iggarpe - 09-05-07 04:42 ---------------------------------------------------------------------- Uploaded quasi-trivial patch that supports "ms" suffix in -t option. ---------------------------------------------------------------------- iggarpe - 09-05-07 04:49 ---------------------------------------------------------------------- Please use the v2 patch. Missed a silly bug in the first upload. Issue History Date Modified Username Field Change ====================================================================== 09-04-07 04:13 iggarpe New Issue 09-04-07 04:13 iggarpe Status new => assigned 09-04-07 04:13 iggarpe Assigned To => BusyBox 09-05-07 04:42 iggarpe File Added: busybox-trunk-watchdog-ms.patch 09-05-07 04:42 iggarpe Note Added: 0002715 09-05-07 04:48 iggarpe File Added: busybox-trunk-watchdog-ms-v2.patch 09-05-07 04:49 iggarpe Note Added: 0002716 ====================================================================== From bugs at busybox.net Wed Sep 5 05:11:32 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Wed, 5 Sep 2007 05:11:32 -0700 Subject: [BusyBox 0001482]: watchdog should support subsecond refresh interval Message-ID: <90af25f9e729f0457d8aceebb183331f@bugs.busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1482 ====================================================================== Reported By: iggarpe Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1482 Category: New Features Reproducibility: always Severity: feature Priority: normal Status: assigned ====================================================================== Date Submitted: 09-04-2007 04:13 PDT Last Modified: 09-05-2007 05:11 PDT ====================================================================== Summary: watchdog should support subsecond refresh interval Description: Some advantech boards comes with a crippled watchdog that can only support a 1 second timeout. In this scenario, the watchdog utility is completely useless (the lowes refresh interval would be 1 ("watchdog -t 1"). ====================================================================== ---------------------------------------------------------------------- iggarpe - 09-05-07 04:42 ---------------------------------------------------------------------- Uploaded quasi-trivial patch that supports "ms" suffix in -t option. ---------------------------------------------------------------------- iggarpe - 09-05-07 04:49 ---------------------------------------------------------------------- Please use the v2 patch. Missed a silly bug in the first upload. ---------------------------------------------------------------------- iggarpe - 09-05-07 05:11 ---------------------------------------------------------------------- Please remove a debug "fprintf(stderr,...)" left in the patch. Issue History Date Modified Username Field Change ====================================================================== 09-04-07 04:13 iggarpe New Issue 09-04-07 04:13 iggarpe Status new => assigned 09-04-07 04:13 iggarpe Assigned To => BusyBox 09-05-07 04:42 iggarpe File Added: busybox-trunk-watchdog-ms.patch 09-05-07 04:42 iggarpe Note Added: 0002715 09-05-07 04:48 iggarpe File Added: busybox-trunk-watchdog-ms-v2.patch 09-05-07 04:49 iggarpe Note Added: 0002716 09-05-07 05:11 iggarpe Note Added: 0002717 ====================================================================== From vda at busybox.net Wed Sep 5 05:13:52 2007 From: vda at busybox.net (vda at busybox.net) Date: Wed, 5 Sep 2007 05:13:52 -0700 (PDT) Subject: svn commit: trunk/busybox: include miscutils Message-ID: <20070905121352.A3B51A6AAF@busybox.net> Author: vda Date: 2007-09-05 05:13:51 -0700 (Wed, 05 Sep 2007) New Revision: 19793 Log: watchdog: allow millisecond spec (-t 250ms) function old new delta packed_usage 23069 23113 +44 static.suffixes - 24 +24 watchdog_main 147 160 +13 static.V - 1 +1 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 2/0 up/down: 82/0) Total: 82 bytes Modified: trunk/busybox/include/usage.h trunk/busybox/miscutils/watchdog.c Changeset: Modified: trunk/busybox/include/usage.h =================================================================== --- trunk/busybox/include/usage.h 2007-09-05 11:48:32 UTC (rev 19792) +++ trunk/busybox/include/usage.h 2007-09-05 12:13:51 UTC (rev 19793) @@ -3843,7 +3843,7 @@ #define watch_full_usage \ "Execute a program periodically" \ "\n\nOptions:\n" \ - " -n Loop period in seconds - default is 2\n" \ + " -n Loop period in seconds (default 2)\n" \ " -t Don't print header" #define watch_example_usage \ "$ watch date\n" \ @@ -3852,12 +3852,14 @@ "Mon Dec 17 10:31:44 GMT 2000" #define watchdog_trivial_usage \ - "[-t seconds] [-F] DEV" + "[-t N[ms]] [-F] DEV" #define watchdog_full_usage \ "Periodically write to watchdog device DEV" \ - "\n\nOptions:\n" \ - " -t Timer period in seconds - default is 30\n" \ - " -F Stay in the foreground and don't fork" + "\n\nOptions:" \ + "\n -t N Timer period (default 30)" \ + "\n -F Stay in the foreground and don't fork" \ + "\n" \ + "\nUse -t 500ms to specify period in milliseconds" #define wc_trivial_usage \ "[OPTION]... [FILE]..." Modified: trunk/busybox/miscutils/watchdog.c =================================================================== --- trunk/busybox/miscutils/watchdog.c 2007-09-05 11:48:32 UTC (rev 19792) +++ trunk/busybox/miscutils/watchdog.c 2007-09-05 12:13:51 UTC (rev 19793) @@ -16,7 +16,9 @@ static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) ATTRIBUTE_NORETURN; static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) { - write(3, "V", 1); /* Magic, see watchdog-api.txt in kernel */ + static const char V = 'V'; + + write(3, &V, 1); /* Magic, see watchdog-api.txt in kernel */ if (ENABLE_FEATURE_CLEAN_UP) close(3); exit(0); @@ -26,14 +28,20 @@ int watchdog_main(int argc, char **argv) { unsigned opts; - unsigned timer_duration = 30; /* Userspace timer duration, in seconds */ + unsigned timer_duration = 30000; /* Userspace timer duration, in milliseconds */ char *t_arg; opt_complementary = "=1"; /* must have 1 argument */ opts = getopt32(argv, "Ft:", &t_arg); - if (opts & OPT_TIMER) - timer_duration = xatou(t_arg); + if (opts & OPT_TIMER) { + static const struct suffix_mult suffixes[] = { + { "ms", 1 }, + { "", 1000 }, + { } + }; + timer_duration = xatou_sfx(t_arg, suffixes); + } if (!(opts & OPT_FOREGROUND)) { bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); @@ -50,10 +58,8 @@ * Make sure we clear the counter before sleeping, as the counter value * is undefined at this point -- PFM */ - write(3, "", 1); - sleep(timer_duration); + write(3, "", 1); /* write zero byte */ + usleep(timer_duration * 1000L); } - - watchdog_shutdown(0); - /* return EXIT_SUCCESS; */ + return EXIT_SUCCESS; /* - not reached, but gcc 4.2.1 is too dumb! */ } From bugs at busybox.net Wed Sep 5 05:14:05 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Wed, 5 Sep 2007 05:14:05 -0700 Subject: [BusyBox 0001482]: watchdog should support subsecond refresh interval Message-ID: The following issue has been CLOSED ====================================================================== http://busybox.net/bugs/view.php?id=1482 ====================================================================== Reported By: iggarpe Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1482 Category: New Features Reproducibility: always Severity: feature Priority: normal Status: closed Resolution: open Fixed in Version: ====================================================================== Date Submitted: 09-04-2007 04:13 PDT Last Modified: 09-05-2007 05:14 PDT ====================================================================== Summary: watchdog should support subsecond refresh interval Description: Some advantech boards comes with a crippled watchdog that can only support a 1 second timeout. In this scenario, the watchdog utility is completely useless (the lowes refresh interval would be 1 ("watchdog -t 1"). ====================================================================== ---------------------------------------------------------------------- iggarpe - 09-05-07 04:42 ---------------------------------------------------------------------- Uploaded quasi-trivial patch that supports "ms" suffix in -t option. ---------------------------------------------------------------------- iggarpe - 09-05-07 04:49 ---------------------------------------------------------------------- Please use the v2 patch. Missed a silly bug in the first upload. ---------------------------------------------------------------------- iggarpe - 09-05-07 05:11 ---------------------------------------------------------------------- Please remove a debug "fprintf(stderr,...)" left in the patch. ---------------------------------------------------------------------- vda - 09-05-07 05:14 ---------------------------------------------------------------------- Applied to svn, thanks! Issue History Date Modified Username Field Change ====================================================================== 09-04-07 04:13 iggarpe New Issue 09-04-07 04:13 iggarpe Status new => assigned 09-04-07 04:13 iggarpe Assigned To => BusyBox 09-05-07 04:42 iggarpe File Added: busybox-trunk-watchdog-ms.patch 09-05-07 04:42 iggarpe Note Added: 0002715 09-05-07 04:48 iggarpe File Added: busybox-trunk-watchdog-ms-v2.patch 09-05-07 04:49 iggarpe Note Added: 0002716 09-05-07 05:11 iggarpe Note Added: 0002717 09-05-07 05:14 vda Status assigned => closed 09-05-07 05:14 vda Note Added: 0002718 ====================================================================== From bugs at busybox.net Wed Sep 5 07:49:19 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Wed, 5 Sep 2007 07:49:19 -0700 Subject: [BusyBox 0001489]: Usage help for watchdog applet is missing a '\n' at the end of the -F option line. Message-ID: <9d18c18a47da12aaf23bf037bcb17e9e@bugs.busybox.net> The following issue has been SUBMITTED. ====================================================================== http://busybox.net/bugs/view.php?id=1489 ====================================================================== Reported By: iggarpe Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1489 Category: Other Reproducibility: always Severity: text Priority: normal Status: assigned ====================================================================== Date Submitted: 09-05-2007 07:49 PDT Last Modified: 09-05-2007 07:49 PDT ====================================================================== Summary: Usage help for watchdog applet is missing a '\n' at the end of the -F option line. Description: Title says it all. include/usage.h ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 09-05-07 07:49 iggarpe New Issue 09-05-07 07:49 iggarpe Status new => assigned 09-05-07 07:49 iggarpe Assigned To => BusyBox ====================================================================== From bugs at busybox.net Wed Sep 5 07:58:21 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Wed, 5 Sep 2007 07:58:21 -0700 Subject: [BusyBox 0001489]: Usage help for watchdog applet is missing a '\n' at the end of the -F option line. Message-ID: <296dc66b12858f73eb0104e8dcf39dff@bugs.busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1489 ====================================================================== Reported By: iggarpe Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1489 Category: Other Reproducibility: always Severity: text Priority: normal Status: assigned ====================================================================== Date Submitted: 09-05-2007 07:49 PDT Last Modified: 09-05-2007 07:58 PDT ====================================================================== Summary: Usage help for watchdog applet is missing a '\n' at the end of the -F option line. Description: Title says it all. include/usage.h ====================================================================== ---------------------------------------------------------------------- iggarpe - 09-05-07 07:58 ---------------------------------------------------------------------- Please ignore. Actually the mistake is only in my recent "millisecond" patch, I just got confused by the unusual formatting of the '\n'. Issue History Date Modified Username Field Change ====================================================================== 09-05-07 07:49 iggarpe New Issue 09-05-07 07:49 iggarpe Status new => assigned 09-05-07 07:49 iggarpe Assigned To => BusyBox 09-05-07 07:58 iggarpe Note Added: 0002719 ====================================================================== From bugs at busybox.net Wed Sep 5 08:30:59 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Wed, 5 Sep 2007 08:30:59 -0700 Subject: [BusyBox 0001489]: Usage help for watchdog applet is missing a '\n' at the end of the -F option line. Message-ID: <83d5a12f7ad0054a0852dab92c12d772@busybox.net> The following issue has been CLOSED ====================================================================== http://busybox.net/bugs/view.php?id=1489 ====================================================================== Reported By: iggarpe Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1489 Category: Other Reproducibility: always Severity: text Priority: normal Status: closed Resolution: open Fixed in Version: ====================================================================== Date Submitted: 09-05-2007 07:49 PDT Last Modified: 09-05-2007 08:30 PDT ====================================================================== Summary: Usage help for watchdog applet is missing a '\n' at the end of the -F option line. Description: Title says it all. include/usage.h ====================================================================== ---------------------------------------------------------------------- iggarpe - 09-05-07 07:58 ---------------------------------------------------------------------- Please ignore. Actually the mistake is only in my recent "millisecond" patch, I just got confused by the unusual formatting of the '\n'. ---------------------------------------------------------------------- vda - 09-05-07 08:30 ---------------------------------------------------------------------- current svn seems to be ok: $ ./busybox watchdog BusyBox v1.8.0.svn (2007-09-05 12:45:24 IST) multi-call binary Usage: watchdog [-t N[ms]] [-F] DEV Periodically write to watchdog device DEV Options: -t N Timer period (default 30) -F Stay in the foreground and don't fork Use -t 500ms to specify period in milliseconds Issue History Date Modified Username Field Change ====================================================================== 09-05-07 07:49 iggarpe New Issue 09-05-07 07:49 iggarpe Status new => assigned 09-05-07 07:49 iggarpe Assigned To => BusyBox 09-05-07 07:58 iggarpe Note Added: 0002719 09-05-07 08:30 vda Status assigned => closed 09-05-07 08:30 vda Note Added: 0002720 ====================================================================== From vda at busybox.net Wed Sep 5 08:46:05 2007 From: vda at busybox.net (vda at busybox.net) Date: Wed, 5 Sep 2007 08:46:05 -0700 (PDT) Subject: svn commit: trunk/busybox/include Message-ID: <20070905154605.3EFC430047@busybox.net> Author: vda Date: 2007-09-05 08:45:51 -0700 (Wed, 05 Sep 2007) New Revision: 19794 Log: usage: trim a bit function old new delta packed_usage 23113 23011 -102 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-102) Total: -102 bytes text data bss dec hex filename 770610 1051 10764 782425 bf059 busybox_old 770508 1051 10764 782323 beff3 busybox_unstripped Modified: trunk/busybox/include/usage.h Changeset: Modified: trunk/busybox/include/usage.h =================================================================== --- trunk/busybox/include/usage.h 2007-09-05 12:13:51 UTC (rev 19793) +++ trunk/busybox/include/usage.h 2007-09-05 15:45:51 UTC (rev 19794) @@ -16,7 +16,7 @@ #define addgroup_full_usage \ "Add a group to the system"USE_FEATURE_ADDUSER_TO_GROUP(" or add an user to a group") \ "\n\nOptions:\n" \ - " -g GID Specify gid" + " -g GID Group id" #define adduser_trivial_usage \ "[OPTIONS] user_name" @@ -28,7 +28,7 @@ " -s SHELL Login shell\n" \ " -G GROUP Add user to existing group\n" \ " -S Create a system user (ignored)\n" \ - " -D Do not assign a password (logins still possible via ssh)\n" \ + " -D Do not assign a password\n" \ " -H Do not create home directory" #define adjtimex_trivial_usage \ @@ -40,7 +40,7 @@ " -q Quiet\n" \ " -o offset Time offset, microseconds\n" \ " -f frequency Frequency adjust, integer kernel units (65536 is 1ppm)\n" \ - " (positive values make the system clock run faster)\n" \ + " (positive values make clock run faster)\n" \ " -t tick Microseconds per tick, usually 10000\n" \ " -p timeconstant" @@ -70,10 +70,10 @@ "\n -d Delete a specified entry" \ "\n -v Verbose" \ "\n -n Don't resolve names" \ - "\n -i if Specify network interface (e.g. eth0)" \ + "\n -i if Network interface (e.g. eth0)" \ "\n -D Read from given device" \ - "\n -A, -p Specify protocol family" \ - "\n -H hwtype Specify hardware address type" + "\n -A, -p Protocol family" \ + "\n -H hwtype Hardware address type" #define arping_trivial_usage \ "[-fqbDUA] [-c count] [-w timeout] [-i device] [-s sender] target" @@ -103,7 +103,7 @@ #define awk_full_usage \ "Options:\n" \ " -v var=val Set variable\n" \ - " -F sep Use 'sep' as field separator\n" \ + " -F sep Use sep as field separator\n" \ " -f filename Read program from file" #define basename_trivial_usage \ @@ -468,11 +468,11 @@ #define crontab_full_usage \ " file [opts] Replace crontab from file\n" \ " - [opts] Replace crontab from stdin\n" \ - " -u user Specify user\n" \ + " -u user User\n" \ " -l [user] List crontab for user\n" \ " -e [user] Edit crontab for user\n" \ " -d [user] Delete crontab for user\n" \ - " -c dir Specify crontab directory" + " -c dir Crontab directory" #define cryptpw_trivial_usage \ "[-a des|md5] [string]" @@ -509,11 +509,11 @@ USE_FEATURE_DATE_ISOFMT( \ " -I[TIMESPEC] Outputs an ISO-8601 compliant date/time string\n" \ " TIMESPEC='date' (or missing) for date only,\n" \ - " 'hours', 'minutes', or 'seconds' for date and,\n" \ + " 'hours', 'minutes', or 'seconds' for date and\n" \ " time to the indicated precision\n" \ " -D hint Use 'hint' as date format, via strptime()\n" \ ) \ - " -s Sets time described by STRING\n" \ + " -s STRING Sets time described by STRING\n" \ " -r FILE Displays the last modification time of FILE\n" \ " -u Prints or sets Coordinated Universal Time" #define date_example_usage \ @@ -596,9 +596,9 @@ "\n\nOptions:" \ "\n mntpnt The mount point where devfs is mounted" \ "\n -v Print the protocol version numbers for devfsd" \ - "\n and the kernel-side protocol version and exits" \ + "\n and the kernel-side protocol version and exit" \ USE_DEVFSD_FG_NP( \ - "\n -fg Run the daemon in the foreground" \ + "\n -fg Run in foreground" \ "\n -np Exit after parsing the configuration file" \ "\n and processing synthetic REGISTER events," \ "\n do not poll for events") @@ -1606,7 +1606,7 @@ " -c Copy the file, default\n" \ " -d Create directories\n" \ " -g Set group ownership\n" \ - " -m Set permission modes\n" \ + " -m Set permissions\n" \ " -o Set ownership\n" \ " -p Preserve date\n" \ " -s Strip symbol tables" \ @@ -1672,7 +1672,7 @@ #define ipcs_trivial_usage \ "[[-smq] -i shmid] | [[-asmq] [-tcplu]]" #define ipcs_full_usage \ - " -i Specify a specific resource id\n" \ + " -i Show a specific resource\n" \ "Resource specification:\n" \ " -m Shared memory segments\n" \ " -q Message queues\n" \ @@ -1764,7 +1764,7 @@ "Kernel logger" \ "\n\nOptions:\n" \ " -c n Sets the default log level of console messages to n\n" \ - " -n Run as foreground process" + " -n Run in foreground" #define length_trivial_usage \ "STRING" @@ -1781,11 +1781,9 @@ "changed, and files can be manipulated in various ways." \ "\n\nOptions:\n" \ " -E Quit once the end of a file is reached\n" \ - " -M Display a status line containing the current line numbers\n" \ + " -M,-m Display a status line containing the current line numbers\n" \ " and the percentage through the file\n" \ " -N Prefix line numbers to each line\n" \ - " -m Display a status line containing the percentage through the\n" \ - " file\n" \ " -~ Suppress ~s displayed when input past the end of the file is\n" \ " reached" @@ -1804,7 +1802,7 @@ "\n\nOptions:\n" \ " -s Make symlinks instead of hardlinks\n" \ " -f Remove existing destination files\n" \ - " -n No dereference symlinks - treat like normal file\n" \ + " -n Don't dereference symlinks - treat like normal file\n" \ " -b Make a backup of the target (if exists) before link operation\n" \ " -S suf Use suffix instead of ~ when making backup files" #define ln_example_usage \ @@ -2144,10 +2142,10 @@ #define mkfs_minix_full_usage \ "Make a MINIX filesystem" \ "\n\nOptions:\n" \ - " -c Check the device for bad blocks\n" \ - " -n [14|30] Specify the maximum length of filenames\n" \ - " -i INODES Specify the number of inodes for the filesystem\n" \ - " -l FILENAME Read the bad blocks list from FILENAME\n" \ + " -c Check device for bad blocks\n" \ + " -n [14|30] Maximum length of filenames\n" \ + " -i INODES Number of inodes for the filesystem\n" \ + " -l FILENAME Read bad blocks list from FILENAME\n" \ " -v Make a Minix version 2 filesystem" #define mknod_trivial_usage \ @@ -2281,7 +2279,7 @@ ) \ " -o option One of many filesystem options, listed below\n" \ " -r Mount the filesystem read-only\n" \ - " -t fs-type Specify the filesystem type\n" \ + " -t fs-type Filesystem type\n" \ " -w Mount for reading and writing (default)\n" \ "\n" \ "Options for use with the \"-o\" flag:\n" \ @@ -3095,7 +3093,7 @@ " -f Ignore case\n" \ " -g General numerical sort\n" \ " -i Ignore unprintable characters\n" \ - " -k Specify sort key\n" \ + " -k Sort key\n" \ " -M Sort month\n") \ " -n Sort numbers\n" \ USE_FEATURE_SORT_BIG( \ @@ -3146,7 +3144,7 @@ "\n -S|--start Start" \ "\n -K|--stop Stop" \ "\n -a|--startas pathname Starts process specified by pathname" \ - "\n -b|--background Force process into background" \ + "\n -b|--background Put process into background" \ "\n -u|--user username|uid Stop this user's processes" \ "\n -x|--exec executable Program to either start or check" \ "\n -m|--make-pidfile Create the -p file and enter pid in it" \ @@ -3338,7 +3336,7 @@ "System logging utility.\n" \ "Note that this version of syslogd ignores /etc/syslog.conf." \ "\n\nOptions:" \ - "\n -n Run as foreground process" \ + "\n -n Run in foreground" \ "\n -O FILE Log to given file (default=/var/log/messages)" \ "\n -l n Set local log level" \ "\n -S Smaller logging output" \ @@ -3472,7 +3470,7 @@ USE_FEATURE_TELNETD_STANDALONE( \ "\n -p PORT Port to listen to" \ "\n -b ADDR Address to bind to" \ - "\n -F Stay in foreground" \ + "\n -F Run in foreground" \ "\n -i Run as inetd subservice" \ ) @@ -3613,7 +3611,7 @@ " -t tos Type-of-service in probe packets (default 0)\n" \ " -w wait Time in seconds to wait for a response to a probe\n" \ " (default 3 sec)\n" \ - " -g Specify a loose source route gateway (8 max)" + " -g Loose source route gateway (8 max)" #define true_trivial_usage \ @@ -3664,7 +3662,7 @@ "\n -r,--request=IP IP address to request" \ "\n -s,--script=file Run file at dhcp events (default: /usr/share/udhcpc/default.script)" \ "\n -t,--retries=N Send up to N request packets"\ - "\n -f,--foreground Stay in foreground" \ + "\n -f,--foreground Run in foreground" \ "\n -b,--background Background if lease cannot be immediately negotiated" \ "\n -S,--syslog Log to syslog too" \ "\n -n,--now Exit with failure if lease cannot be immediately negotiated" \ @@ -3677,7 +3675,7 @@ #define udhcpd_full_usage \ "DHCP server" \ - "\n -f Stay in foreground" \ + "\n -f Run in foreground" \ "\n -S Log to syslog too" #define umount_trivial_usage \ @@ -3857,7 +3855,7 @@ "Periodically write to watchdog device DEV" \ "\n\nOptions:" \ "\n -t N Timer period (default 30)" \ - "\n -F Stay in the foreground and don't fork" \ + "\n -F Run in foreground" \ "\n" \ "\nUse -t 500ms to specify period in milliseconds" @@ -3940,7 +3938,7 @@ #define zcip_full_usage \ "Manage a ZeroConf IPv4 link-local address" \ "\n\nOptions:\n" \ - " -f Foreground mode\n" \ + " -f Run in foreground\n" \ " -q Quit after address (no daemon)\n" \ " -r 169.254.x.x Request this address first\n" \ " -v Verbose" From vda at busybox.net Thu Sep 6 09:57:05 2007 From: vda at busybox.net (vda at busybox.net) Date: Thu, 6 Sep 2007 09:57:05 -0700 (PDT) Subject: svn commit: trunk/busybox/util-linux Message-ID: <20070906165705.BBDF330071@busybox.net> Author: vda Date: 2007-09-06 09:57:05 -0700 (Thu, 06 Sep 2007) New Revision: 19795 Log: umount: support (by ignoring) -i; style fixes Modified: trunk/busybox/util-linux/umount.c Changeset: Modified: trunk/busybox/util-linux/umount.c =================================================================== --- trunk/busybox/util-linux/umount.c 2007-09-05 15:45:51 UTC (rev 19794) +++ trunk/busybox/util-linux/umount.c 2007-09-06 16:57:05 UTC (rev 19795) @@ -12,13 +12,14 @@ #include #include "libbb.h" -#define OPTION_STRING "flDnravdt:" -#define OPT_FORCE 1 -#define OPT_LAZY 2 -#define OPT_DONTFREELOOP 4 -#define OPT_NO_MTAB 8 -#define OPT_REMOUNT 16 -#define OPT_ALL (ENABLE_FEATURE_UMOUNT_ALL ? 32 : 0) +/* ignored: -v -d -t -i */ +#define OPTION_STRING "flDnra" "vdt:i" +#define OPT_FORCE (1 << 0) +#define OPT_LAZY (1 << 1) +#define OPT_DONTFREELOOP (1 << 2) +#define OPT_NO_MTAB (1 << 3) +#define OPT_REMOUNT (1 << 4) +#define OPT_ALL (ENABLE_FEATURE_UMOUNT_ALL ? (1 << 5) : 0) int umount_main(int argc, char **argv); int umount_main(int argc, char **argv) @@ -77,7 +78,8 @@ /* If we're not umounting all, we need at least one argument. */ if (!(opt & OPT_ALL) && !fstype) { m = 0; - if (!argc) bb_show_usage(); + if (!argc) + bb_show_usage(); } // Loop through everything we're supposed to umount, and do so. @@ -86,11 +88,14 @@ char *zapit = *argv; // Do we already know what to umount this time through the loop? - if (m) safe_strncpy(path, m->dir, PATH_MAX); + if (m) + safe_strncpy(path, m->dir, PATH_MAX); // For umount -a, end of mtab means time to exit. - else if (opt & OPT_ALL) break; + else if (opt & OPT_ALL) + break; // Get next command line argument (and look it up in mtab list) - else if (!argc--) break; + else if (!argc--) + break; else { argv++; realpath(zapit, path); From pgf at busybox.net Thu Sep 6 10:45:18 2007 From: pgf at busybox.net (pgf at busybox.net) Date: Thu, 6 Sep 2007 10:45:18 -0700 (PDT) Subject: svn commit: trunk/busybox/findutils Message-ID: <20070906174518.A6CDC30054@busybox.net> Author: pgf Date: 2007-09-06 10:45:16 -0700 (Thu, 06 Sep 2007) New Revision: 19796 Log: fix -xdev behavior in the presence of two or more nested mount points on the command line, e.g. "find / /boot -xdev". Modified: trunk/busybox/findutils/find.c Changeset: Modified: trunk/busybox/findutils/find.c =================================================================== --- trunk/busybox/findutils/find.c 2007-09-06 16:57:05 UTC (rev 19795) +++ trunk/busybox/findutils/find.c 2007-09-06 17:45:16 UTC (rev 19796) @@ -383,9 +383,11 @@ #if ENABLE_FEATURE_FIND_XDEV if (S_ISDIR(statbuf->st_mode) && xdev_count) { for (i = 0; i < xdev_count; i++) { - if (xdev_dev[i] != statbuf->st_dev) - return SKIP; + if (xdev_dev[i] == statbuf->st_dev) + break; } + if (i == xdev_count) + return SKIP; } #endif i = exec_actions(actions, fileName, statbuf); From pgf at busybox.net Thu Sep 6 10:52:22 2007 From: pgf at busybox.net (pgf at busybox.net) Date: Thu, 6 Sep 2007 10:52:22 -0700 (PDT) Subject: svn commit: trunk/busybox/networking Message-ID: <20070906175222.1F88230054@busybox.net> Author: pgf Date: 2007-09-06 10:52:22 -0700 (Thu, 06 Sep 2007) New Revision: 19797 Log: fix infinite retry bug. also, reduce per-packet receive timeout to something more reasonable than 5 seconds, and add simple exponential backoff to compensate. improves performance on marginal networks. Modified: trunk/busybox/networking/tftp.c Changeset: Modified: trunk/busybox/networking/tftp.c =================================================================== --- trunk/busybox/networking/tftp.c 2007-09-06 17:45:16 UTC (rev 19796) +++ trunk/busybox/networking/tftp.c 2007-09-06 17:52:22 UTC (rev 19797) @@ -21,12 +21,12 @@ #include "libbb.h" - #if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT #define TFTP_BLOCKSIZE_DEFAULT 512 /* according to RFC 1350, don't change */ -#define TFTP_TIMEOUT 5 /* seconds */ -#define TFTP_NUM_RETRIES 5 /* number of retries */ +#define TFTP_TIMEOUT 50000 /* 50ms, in microseconds */ +#define TFTP_MAXTIMEOUT 999000 /* about 1 second, in microseconds */ +#define TFTP_NUM_RETRIES 12 /* number of backed-off retries */ /* opcodes we support */ #define TFTP_RRQ 1 @@ -124,7 +124,7 @@ uint16_t opcode; uint16_t block_nr = 1; uint16_t recv_blk; - int timeout = TFTP_NUM_RETRIES; + int retries, waittime; char *cp; unsigned org_port; @@ -206,6 +206,10 @@ send_len = cp - xbuf; /* NB: send_len value is preserved in code below * for potential resend */ + + retries = TFTP_NUM_RETRIES; /* re-initialize */ + waittime = TFTP_TIMEOUT; + send_again: #if ENABLE_DEBUG_TFTP fprintf(stderr, "sending %u bytes\n", send_len); @@ -218,11 +222,10 @@ if (finished && (opcode == TFTP_ACK)) goto ret; - timeout = TFTP_NUM_RETRIES; /* re-initialize */ recv_again: /* Receive packet */ - tv.tv_sec = TFTP_TIMEOUT; - tv.tv_usec = 0; + tv.tv_sec = 0; + tv.tv_usec = waittime; FD_ZERO(&rfds); FD_SET(socketfd, &rfds); switch (select(socketfd + 1, &rfds, NULL, NULL, &tv)) { @@ -248,12 +251,18 @@ goto recv_again; goto process_pkt; case 0: - timeout--; - if (timeout == 0) { - bb_error_msg("last timeout"); + retries--; + if (retries == 0) { + bb_error_msg("timeout"); goto ret; } - bb_error_msg("last timeout" + 5); + + /* exponential backoff with limit */ + waittime += waittime/2; + if (waittime > TFTP_MAXTIMEOUT) { + waittime = TFTP_MAXTIMEOUT; + } + goto send_again; /* resend last sent pkt */ default: bb_perror_msg("select"); From vda at busybox.net Fri Sep 7 06:43:30 2007 From: vda at busybox.net (vda at busybox.net) Date: Fri, 7 Sep 2007 06:43:30 -0700 (PDT) Subject: svn commit: trunk/busybox: editors networking networking/udhcp shel etc... Message-ID: <20070907134330.345C0A65FF@busybox.net> Author: vda Date: 2007-09-07 06:43:28 -0700 (Fri, 07 Sep 2007) New Revision: 19798 Log: *: replace select-for-one descriptor with poll, it's smaller. $ ./.cmk bloatcheck function old new delta readit 406 364 -42 syslogd_main 1249 1206 -43 traceroute_main 4115 4060 -55 mysleep 112 45 -67 arpping 579 441 -138 tftp 1575 1182 -393 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-738) Total: -738 bytes text data bss dec hex filename 770580 1051 10764 782395 bf03b busybox_old 769820 1051 10764 781635 bed43 busybox_unstripped Modified: trunk/busybox/editors/vi.c trunk/busybox/networking/tftp.c trunk/busybox/networking/traceroute.c trunk/busybox/networking/udhcp/arpping.c trunk/busybox/shell/ash.c trunk/busybox/sysklogd/syslogd.c Changeset: Modified: trunk/busybox/editors/vi.c =================================================================== --- trunk/busybox/editors/vi.c 2007-09-06 17:52:22 UTC (rev 19797) +++ trunk/busybox/editors/vi.c 2007-09-07 13:43:28 UTC (rev 19798) @@ -237,7 +237,8 @@ static void show_help(void); // display some help info static void rawmode(void); // set "raw" mode on tty static void cookmode(void); // return to "cooked" mode on tty -static int mysleep(int); // sleep for 'h' 1/100 seconds +// sleep for 'h' 1/100 seconds, return 1/0 if stdin is (ready for read)/(not ready) +static int mysleep(int); static char readit(void); // read (maybe cursor) key from stdin static char get_one_char(void); // read 1 char from stdin static int file_size(const char *); // what is the byte size of "fn" @@ -2134,17 +2135,11 @@ static int mysleep(int hund) // sleep for 'h' 1/100 seconds { - fd_set rfds; - struct timeval tv; + struct pollfd pfd[1]; - // Don't hang- Wait 5/100 seconds- 1 Sec= 1000000 - fflush(stdout); - FD_ZERO(&rfds); - FD_SET(0, &rfds); - tv.tv_sec = 0; - tv.tv_usec = hund * 10000; - select(1, &rfds, NULL, NULL, &tv); - return FD_ISSET(0, &rfds); + pfd[0].fd = 0; + pfd[0].events = POLLIN; + return poll(pfd, 1, hund*10) > 0; } #define readbuffer bb_common_bufsiz1 @@ -2217,25 +2212,20 @@ if (n <= 0) return 0; // error if (readbuffer[0] == 27) { - fd_set rfds; - struct timeval tv; - // This is an ESC char. Is this Esc sequence? // Could be bare Esc key. See if there are any // more chars to read after the ESC. This would // be a Function or Cursor Key sequence. - FD_ZERO(&rfds); - FD_SET(0, &rfds); - tv.tv_sec = 0; - tv.tv_usec = 50000; // Wait 5/100 seconds- 1 Sec=1000000 - + struct pollfd pfd[1]; + pfd[0].fd = 0; + pfd[0].events = POLLIN; + // Wait 50 ms // keep reading while there are input chars and room in buffer - while (select(1, &rfds, NULL, NULL, &tv) > 0 && n <= (MAX_LINELEN - 5)) { + while (poll(pfd, 1, 50) > 0 && n <= (MAX_LINELEN - 5)) { // read the rest of the ESC string - int r = read(0, (void *) (readbuffer + n), MAX_LINELEN - n); - if (r > 0) { + int r = read(0, readbuffer + n, MAX_LINELEN - n); + if (r > 0) n += r; - } } } readed_for_parse = n; Modified: trunk/busybox/networking/tftp.c =================================================================== --- trunk/busybox/networking/tftp.c 2007-09-06 17:52:22 UTC (rev 19797) +++ trunk/busybox/networking/tftp.c 2007-09-07 13:43:28 UTC (rev 19798) @@ -23,10 +23,10 @@ #if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT -#define TFTP_BLOCKSIZE_DEFAULT 512 /* according to RFC 1350, don't change */ -#define TFTP_TIMEOUT 50000 /* 50ms, in microseconds */ -#define TFTP_MAXTIMEOUT 999000 /* about 1 second, in microseconds */ -#define TFTP_NUM_RETRIES 12 /* number of backed-off retries */ +#define TFTP_BLOCKSIZE_DEFAULT 512 /* according to RFC 1350, don't change */ +#define TFTP_TIMEOUT_MS 50 +#define TFTP_MAXTIMEOUT_MS 2000 +#define TFTP_NUM_RETRIES 12 /* number of backed-off retries */ /* opcodes we support */ #define TFTP_RRQ 1 @@ -114,9 +114,8 @@ const char *remotefile, const int localfd, unsigned port, int tftp_bufsize) { - struct timeval tv; - fd_set rfds; - int socketfd; + struct pollfd pfd[1]; +#define socketfd (pfd[0].fd) int len; int send_len; USE_FEATURE_TFTP_BLOCKSIZE(smallint want_option_ack = 0;) @@ -124,7 +123,7 @@ uint16_t opcode; uint16_t block_nr = 1; uint16_t recv_blk; - int retries, waittime; + int retries, waittime_ms; char *cp; unsigned org_port; @@ -208,7 +207,7 @@ * for potential resend */ retries = TFTP_NUM_RETRIES; /* re-initialize */ - waittime = TFTP_TIMEOUT; + waittime_ms = TFTP_TIMEOUT_MS; send_again: #if ENABLE_DEBUG_TFTP @@ -224,11 +223,9 @@ recv_again: /* Receive packet */ - tv.tv_sec = 0; - tv.tv_usec = waittime; - FD_ZERO(&rfds); - FD_SET(socketfd, &rfds); - switch (select(socketfd + 1, &rfds, NULL, NULL, &tv)) { + /*pfd[0].fd = socketfd;*/ + pfd[0].events = POLLIN; + switch (poll(pfd, 1, waittime_ms)) { unsigned from_port; case 1: from->len = peer_lsa->len; @@ -258,14 +255,14 @@ } /* exponential backoff with limit */ - waittime += waittime/2; - if (waittime > TFTP_MAXTIMEOUT) { - waittime = TFTP_MAXTIMEOUT; + waittime_ms += waittime_ms/2; + if (waittime_ms > TFTP_MAXTIMEOUT_MS) { + waittime_ms = TFTP_MAXTIMEOUT_MS; } goto send_again; /* resend last sent pkt */ default: - bb_perror_msg("select"); + bb_perror_msg("poll"); goto ret; } process_pkt: Modified: trunk/busybox/networking/traceroute.c =================================================================== --- trunk/busybox/networking/traceroute.c 2007-09-06 17:52:22 UTC (rev 19797) +++ trunk/busybox/networking/traceroute.c 2007-09-07 13:43:28 UTC (rev 19798) @@ -346,10 +346,10 @@ struct globals { - /* last inbound (icmp) packet */ - unsigned char packet[512]; struct sockaddr_storage whereto; /* Who to try to reach */ struct sockaddr_storage wherefrom; /* Who we are */ + /* last inbound (icmp) packet */ + unsigned char packet[512]; #if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE /* Maximum number of gateways (include room for one noop) */ #define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(uint32_t))) @@ -359,7 +359,7 @@ }; #define G (*ptr_to_globals) - +#define INIT_G() PTR_TO_GLOBALS = xzalloc(sizeof(G)) #define packet (G.packet ) #define whereto (G.whereto ) #define wherefrom (G.wherefrom) @@ -537,21 +537,15 @@ static int wait_for_reply(int sock, struct sockaddr_in *fromp) { - fd_set fds; - struct timeval tvwait; + struct pollfd pfd[1]; int cc = 0; socklen_t fromlen = sizeof(*fromp); - FD_ZERO(&fds); - FD_SET(sock, &fds); - - tvwait.tv_sec = waittime; - tvwait.tv_usec = 0; - - if (select(sock + 1, &fds, NULL, NULL, &tvwait) > 0) - cc = recvfrom(sock, (char *)packet, sizeof(packet), 0, + pfd[0].fd = sock; + pfd[0].events = POLLIN; + if (poll(pfd, 1, waittime * 1000) > 0) + cc = recvfrom(sock, packet, sizeof(packet), 0, (struct sockaddr *)fromp, &fromlen); - return cc; } @@ -930,7 +924,7 @@ llist_t *source_route_list = NULL; #endif - PTR_TO_GLOBALS = xzalloc(sizeof(G)); + INIT_G(); from = (struct sockaddr_in *)&wherefrom; to = (struct sockaddr_in *)&whereto; Modified: trunk/busybox/networking/udhcp/arpping.c =================================================================== --- trunk/busybox/networking/udhcp/arpping.c 2007-09-06 17:52:22 UTC (rev 19797) +++ trunk/busybox/networking/udhcp/arpping.c 2007-09-07 13:43:28 UTC (rev 19798) @@ -37,14 +37,12 @@ int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface) { - int timeout = 2; - int s; /* socket */ + int timeout_ms = 2000; + struct pollfd pfd[1]; +#define s (pfd[0].fd) /* socket */ int rv = 1; /* "no reply received" yet */ struct sockaddr addr; /* for interface name */ struct arpMsg arp; - fd_set fdset; - struct timeval tm; - unsigned prevTime; s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP)); if (s == -1) { @@ -80,18 +78,17 @@ /* wait for arp reply, and check it */ do { int r; - prevTime = monotonic_sec(); - FD_ZERO(&fdset); - FD_SET(s, &fdset); - tm.tv_sec = timeout; - tm.tv_usec = 0; - r = select(s + 1, &fdset, NULL, NULL, &tm); + unsigned prevTime = monotonic_us(); + + pfd[0].events = POLLIN; + r = poll(pfd, 1, timeout_ms); if (r < 0) { - bb_perror_msg("error on ARPING request"); - if (errno != EINTR) + if (errno != EINTR) { + bb_perror_msg("poll"); break; + } } else if (r) { - if (recv(s, &arp, sizeof(arp), 0) < 0) + if (read(s, &arp, sizeof(arp)) < 0) break; if (arp.operation == htons(ARPOP_REPLY) && memcmp(arp.tHaddr, from_mac, 6) == 0 @@ -101,8 +98,8 @@ break; } } - timeout -= monotonic_sec() - prevTime; - } while (timeout > 0); + timeout_ms -= (monotonic_us() - prevTime) / 1000; + } while (timeout_ms > 0); ret: close(s); Modified: trunk/busybox/shell/ash.c =================================================================== --- trunk/busybox/shell/ash.c 2007-09-06 17:52:22 UTC (rev 19797) +++ trunk/busybox/shell/ash.c 2007-09-07 13:43:28 UTC (rev 19798) @@ -11589,6 +11589,7 @@ #endif #if ENABLE_ASH_READ_TIMEOUT if (ts.tv_sec || ts.tv_usec) { +// TODO: replace with poll, it is smaller FD_ZERO(&set); FD_SET(0, &set); Modified: trunk/busybox/sysklogd/syslogd.c =================================================================== --- trunk/busybox/sysklogd/syslogd.c 2007-09-06 17:52:22 UTC (rev 19797) +++ trunk/busybox/sysklogd/syslogd.c 2007-09-07 13:43:28 UTC (rev 19798) @@ -471,8 +471,8 @@ static void do_syslogd(void) { struct sockaddr_un sunx; - int sock_fd; - fd_set fds; + struct pollfd pfd[1]; +#define sock_fd (pfd[0].fd) char *dev_log_name; /* Set up signal handlers */ @@ -526,20 +526,20 @@ (char*)"syslogd started: BusyBox v" BB_VER, 0); for (;;) { - FD_ZERO(&fds); - FD_SET(sock_fd, &fds); - - if (select(sock_fd + 1, &fds, NULL, NULL, NULL) < 0) { + /*pfd[0].fd = sock_fd;*/ + pfd[0].events = POLLIN; + pfd[0].revents = 0; + if (poll(pfd, 1, -1) < 0) { /* -1: no timeout */ if (errno == EINTR) { /* alarm may have happened */ continue; } - bb_perror_msg_and_die("select"); + bb_perror_msg_and_die("poll"); } - if (FD_ISSET(sock_fd, &fds)) { + if (pfd[0].revents) { int i; - i = recv(sock_fd, G.recvbuf, MAX_READ - 1, 0); + i = read(sock_fd, G.recvbuf, MAX_READ - 1); if (i <= 0) bb_perror_msg_and_die("UNIX socket error"); /* TODO: maybe suppress duplicates? */ @@ -559,7 +559,7 @@ #endif G.recvbuf[i] = '\0'; split_escape_and_log(G.recvbuf, i); - } /* FD_ISSET() */ + } } /* for */ } From vda at busybox.net Fri Sep 7 06:53:33 2007 From: vda at busybox.net (vda at busybox.net) Date: Fri, 7 Sep 2007 06:53:33 -0700 (PDT) Subject: svn commit: trunk/busybox/sysklogd Message-ID: <20070907135333.91F88A6834@busybox.net> Author: vda Date: 2007-09-07 06:53:32 -0700 (Fri, 07 Sep 2007) New Revision: 19799 Log: syslogd: do not need to poll(), we can just block in read(). function old new delta syslogd_main 1206 1106 -100 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-100) Total: -100 bytes text data bss dec hex filename 769820 1051 10764 781635 bed43 busybox_old 769702 1051 10764 781517 beccd busybox_unstripped Modified: trunk/busybox/sysklogd/syslogd.c Changeset: Modified: trunk/busybox/sysklogd/syslogd.c =================================================================== --- trunk/busybox/sysklogd/syslogd.c 2007-09-07 13:43:28 UTC (rev 19798) +++ trunk/busybox/sysklogd/syslogd.c 2007-09-07 13:53:32 UTC (rev 19799) @@ -471,8 +471,7 @@ static void do_syslogd(void) { struct sockaddr_un sunx; - struct pollfd pfd[1]; -#define sock_fd (pfd[0].fd) + int sock_fd; char *dev_log_name; /* Set up signal handlers */ @@ -526,40 +525,34 @@ (char*)"syslogd started: BusyBox v" BB_VER, 0); for (;;) { - /*pfd[0].fd = sock_fd;*/ - pfd[0].events = POLLIN; - pfd[0].revents = 0; - if (poll(pfd, 1, -1) < 0) { /* -1: no timeout */ - if (errno == EINTR) { - /* alarm may have happened */ + size_t sz; + + sz = read(sock_fd, G.recvbuf, MAX_READ - 1); + if (sz <= 0) { + if (sz == 0) + continue; /* EOF from unix socket??? */ + if (errno == EINTR) /* alarm may have happened */ continue; - } - bb_perror_msg_and_die("poll"); + bb_perror_msg_and_die("read from /dev/log"); } - if (pfd[0].revents) { - int i; - i = read(sock_fd, G.recvbuf, MAX_READ - 1); - if (i <= 0) - bb_perror_msg_and_die("UNIX socket error"); - /* TODO: maybe suppress duplicates? */ + /* TODO: maybe suppress duplicates? */ #if ENABLE_FEATURE_REMOTE_LOG - /* We are not modifying log messages in any way before send */ - /* Remote site cannot trust _us_ anyway and need to do validation again */ - if (G.remoteAddr) { - if (-1 == G.remoteFD) { - G.remoteFD = socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0); - } - if (-1 != G.remoteFD) { - /* send message to remote logger, ignore possible error */ - sendto(G.remoteFD, G.recvbuf, i, MSG_DONTWAIT, - &G.remoteAddr->sa, G.remoteAddr->len); - } + /* We are not modifying log messages in any way before send */ + /* Remote site cannot trust _us_ anyway and need to do validation again */ + if (G.remoteAddr) { + if (-1 == G.remoteFD) { + G.remoteFD = socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0); } -#endif - G.recvbuf[i] = '\0'; - split_escape_and_log(G.recvbuf, i); + if (-1 != G.remoteFD) { + /* send message to remote logger, ignore possible error */ + sendto(G.remoteFD, G.recvbuf, sz, MSG_DONTWAIT, + &G.remoteAddr->sa, G.remoteAddr->len); + } } +#endif + G.recvbuf[sz] = '\0'; + split_escape_and_log(G.recvbuf, sz); } /* for */ } From vda at busybox.net Fri Sep 7 12:33:56 2007 From: vda at busybox.net (vda at busybox.net) Date: Fri, 7 Sep 2007 12:33:56 -0700 (PDT) Subject: svn commit: trunk/busybox: libbb util-linux Message-ID: <20070907193356.B0A6330069@busybox.net> Author: vda Date: 2007-09-07 12:33:56 -0700 (Fri, 07 Sep 2007) New Revision: 19800 Log: messages: by popular request allow PATH to be customized at build time mount: smallish code shrink Modified: trunk/busybox/libbb/messages.c trunk/busybox/util-linux/mount.c Changeset: Modified: trunk/busybox/libbb/messages.c =================================================================== --- trunk/busybox/libbb/messages.c 2007-09-07 13:53:32 UTC (rev 19799) +++ trunk/busybox/libbb/messages.c 2007-09-07 19:33:56 UTC (rev 19800) @@ -7,13 +7,21 @@ #include "libbb.h" +/* allow default system PATH to be extended via CFLAGS */ +#ifndef BB_ADDITIONAL_PATH +#define BB_ADDITIONAL_PATH "" +#endif + +/* allow version to be extended, via CFLAGS */ #ifndef BB_EXTRA_VERSION -#define BANNER "BusyBox v" BB_VER " (" BB_BT ")" -#else +#define BB_EXTRA_VERSION BB_BT +#endif + #define BANNER "BusyBox v" BB_VER " (" BB_EXTRA_VERSION ")" -#endif + const char bb_banner[] ALIGN1 = BANNER; + const char bb_msg_memory_exhausted[] ALIGN1 = "memory exhausted"; const char bb_msg_invalid_date[] ALIGN1 = "invalid date '%s'"; const char bb_msg_write_error[] ALIGN1 = "write error"; @@ -39,7 +47,8 @@ const char bb_default_login_shell[] ALIGN1 = LIBBB_DEFAULT_LOGIN_SHELL; /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, * but I want to save a few bytes here. Check libbb.h before changing! */ -const char bb_PATH_root_path[] ALIGN1 = "PATH=/sbin:/usr/sbin:/bin:/usr/bin"; +const char bb_PATH_root_path[] ALIGN1 = + "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH; const int const_int_0; @@ -49,11 +58,11 @@ /* This is usually something like "/var/adm/wtmp" or "/var/log/wtmp" */ const char bb_path_wtmp_file[] ALIGN1 = #if defined _PATH_WTMP -_PATH_WTMP; + _PATH_WTMP; #elif defined WTMP_FILE -WTMP_FILE; + WTMP_FILE; #else -# error unknown path to wtmp file +#error unknown path to wtmp file #endif char bb_common_bufsiz1[COMMON_BUFSIZE]; Modified: trunk/busybox/util-linux/mount.c =================================================================== --- trunk/busybox/util-linux/mount.c 2007-09-07 13:53:32 UTC (rev 19799) +++ trunk/busybox/util-linux/mount.c 2007-09-07 19:33:56 UTC (rev 19800) @@ -1527,11 +1527,10 @@ if (ENABLE_FEATURE_CLEAN_UP) free(filteropts); - if (rc && errno == EBUSY && ignore_busy) - rc = 0; + if (errno == EBUSY && ignore_busy) + return 0; if (rc < 0) bb_perror_msg("mounting %s on %s failed", mp->mnt_fsname, mp->mnt_dir); - return rc; } From pgf at busybox.net Fri Sep 7 13:28:25 2007 From: pgf at busybox.net (pgf at busybox.net) Date: Fri, 7 Sep 2007 13:28:25 -0700 (PDT) Subject: svn commit: trunk/busybox: archival include Message-ID: <20070907202825.C123AA6AAD@busybox.net> Author: pgf Date: 2007-09-07 13:28:25 -0700 (Fri, 07 Sep 2007) New Revision: 19801 Log: overload the existing '-q' flag so that if '-l' and '-q' are used together, a "short form" listing (just pathnames) is generated. change a few flag variables to "smallint" as well. Modified: trunk/busybox/archival/unzip.c trunk/busybox/include/usage.h Changeset: Modified: trunk/busybox/archival/unzip.c =================================================================== --- trunk/busybox/archival/unzip.c 2007-09-07 19:33:56 UTC (rev 19800) +++ trunk/busybox/archival/unzip.c 2007-09-07 20:28:25 UTC (rev 19801) @@ -97,7 +97,10 @@ int unzip_main(int argc, char **argv) { zip_header_t zip_header; - enum {v_silent, v_normal, v_list} verbosity = v_normal; + smallint verbose = 1; + smallint listing = 0; + smallint list_header_done = 0; + smallint failed; enum {o_prompt, o_never, o_always} overwrite = o_prompt; unsigned int total_size = 0; unsigned int total_entries = 0; @@ -106,7 +109,7 @@ llist_t *zaccept = NULL; llist_t *zreject = NULL; char *base_dir = NULL; - int failed, i, opt, opt_range = 0, list_header_done = 0; + int i, opt, opt_range = 0; char key_buf[512]; struct stat stat_buf; @@ -115,7 +118,7 @@ case 0: /* Options */ switch (opt) { case 'l': /* List */ - verbosity = v_list; + listing = 1; break; case 'n': /* Never overwrite existing files */ @@ -130,7 +133,7 @@ dst_fd = STDOUT_FILENO; case 'q': /* Be quiet */ - verbosity = (verbosity == v_normal) ? v_silent : verbosity; + verbose = 0; break; case 1 : /* The zip file */ @@ -205,7 +208,7 @@ if (base_dir) xchdir(base_dir); - if (verbosity != v_silent) + if (verbose) printf("Archive: %s\n", src_fn); failed = 0; @@ -245,7 +248,7 @@ /* Skip extra header bytes */ unzip_skip(src_fd, zip_header.formatted.extra_len); - if ((verbosity == v_list) && !list_header_done){ + if (listing && verbose && !list_header_done){ puts(" Length Date Time Name\n" " -------- ---- ---- ----"); list_header_done = 1; @@ -259,7 +262,8 @@ } else { /* Extract entry */ total_size += zip_header.formatted.ucmpsize; - if (verbosity == v_list) { /* List entry */ + if (listing) { /* List entry */ + if (verbose) { unsigned int dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); printf("%9u %02u-%02u-%02u %02u:%02u %s\n", zip_header.formatted.ucmpsize, @@ -270,7 +274,11 @@ (dostime & 0x000007e0) >> 5, dst_fn); total_entries++; - i = 'n'; + } else { + /* short listing -- filenames only */ + printf("%s\n", dst_fn); + } + i = 'n'; } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ i = -1; } else if (last_char_is(dst_fn, '/')) { /* Extract directory */ @@ -278,7 +286,7 @@ if (errno != ENOENT) { bb_perror_msg_and_die("cannot stat '%s'",dst_fn); } - if (verbosity == v_normal) { + if (verbose) { printf(" creating: %s\n", dst_fn); } unzip_create_leading_dirs(dst_fn); @@ -326,7 +334,7 @@ unzip_create_leading_dirs(dst_fn); dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC); case -1: /* Unzip */ - if (verbosity == v_normal) { + if (verbose) { printf(" inflating: %s\n", dst_fn); } if (unzip_extract(&zip_header, src_fd, dst_fd)) { @@ -368,7 +376,7 @@ } } - if (verbosity == v_list) { + if (listing && verbose) { printf(" -------- -------\n" "%9d %d files\n", total_size, total_entries); } Modified: trunk/busybox/include/usage.h =================================================================== --- trunk/busybox/include/usage.h 2007-09-07 19:33:56 UTC (rev 19800) +++ trunk/busybox/include/usage.h 2007-09-07 20:28:25 UTC (rev 19801) @@ -3763,7 +3763,7 @@ #define unzip_full_usage \ "Extract files from ZIP archives" \ "\n\nOptions:\n" \ - " -l List archive contents (short form)\n" \ + " -l List archive contents (with -q for short form)\n" \ " -n Never overwrite existing files (default)\n" \ " -o Overwrite files without prompting\n" \ " -p Send output to stdout\n" \ From vda at busybox.net Sat Sep 8 09:51:20 2007 From: vda at busybox.net (vda at busybox.net) Date: Sat, 8 Sep 2007 09:51:20 -0700 (PDT) Subject: svn commit: trunk/busybox: include libbb procps Message-ID: <20070908165120.6B632A6838@busybox.net> Author: vda Date: 2007-09-08 09:51:19 -0700 (Sat, 08 Sep 2007) New Revision: 19802 Log: top: TOPMEM feature - 's(how sizes)' command. +2.5k when enabled, +80 bytes when disabled (mainly because of text wrapping fixes in display_process_list). Modified: trunk/busybox/include/libbb.h trunk/busybox/libbb/procps.c trunk/busybox/procps/Config.in trunk/busybox/procps/top.c Changeset: Modified: trunk/busybox/include/libbb.h =================================================================== --- trunk/busybox/include/libbb.h 2007-09-07 20:28:25 UTC (rev 19801) +++ trunk/busybox/include/libbb.h 2007-09-08 16:51:19 UTC (rev 19802) @@ -904,6 +904,15 @@ unsigned uid; unsigned gid; unsigned tty_major,tty_minor; +#if ENABLE_FEATURE_TOPMEM + unsigned long mapped_rw; + unsigned long mapped_ro; + unsigned long shared_clean; + unsigned long shared_dirty; + unsigned long private_clean; + unsigned long private_dirty; + unsigned long stack; +#endif char state[4]; /* basename of executable in exec(2), read from /proc/N/stat * (if executable is symlink or script, it is NOT replaced @@ -927,7 +936,8 @@ PSSCAN_STIME = 1 << 12, PSSCAN_UTIME = 1 << 13, PSSCAN_TTY = 1 << 14, - USE_SELINUX(PSSCAN_CONTEXT = 1 << 15,) + PSSCAN_SMAPS = (1 << 15) * ENABLE_FEATURE_TOPMEM, + USE_SELINUX(PSSCAN_CONTEXT = 1 << 16,) /* These are all retrieved from proc/NN/stat in one go: */ PSSCAN_STAT = PSSCAN_PPID | PSSCAN_PGID | PSSCAN_SID | PSSCAN_COMM | PSSCAN_STATE Modified: trunk/busybox/libbb/procps.c =================================================================== --- trunk/busybox/libbb/procps.c 2007-09-07 20:28:25 UTC (rev 19801) +++ trunk/busybox/libbb/procps.c 2007-09-08 16:51:19 UTC (rev 19802) @@ -115,6 +115,28 @@ free(sp); } +#if ENABLE_FEATURE_TOPMEM +static unsigned long fast_strtoul_16(char **endptr) +{ + unsigned char c; + char *str = *endptr; + unsigned long n = 0; + + while ((c = *str++) != ' ') { + c = ((c|0x20) - '0'); + if (c > 9) + // c = c + '0' - 'a' + 10: + c = c - ('a' - '0' - 10); + n = n*16 + c; + } + *endptr = str; /* We skip trailing space! */ + return n; +} +/* TOPMEM uses fast_strtoul_10, so... */ +#undef ENABLE_FEATURE_FAST_TOP +#define ENABLE_FEATURE_FAST_TOP 1 +#endif + #if ENABLE_FEATURE_FAST_TOP /* We cut a lot of corners here for speed */ static unsigned long fast_strtoul_10(char **endptr) @@ -278,6 +300,57 @@ } +#if ENABLE_FEATURE_TOPMEM + if (flags & (PSSCAN_SMAPS)) { + FILE *file; + + strcpy(filename_tail, "/smaps"); + file = fopen(filename, "r"); + if (!file) + break; + while (fgets(buf, sizeof(buf), file)) { + unsigned long sz; + char *tp; + char w; +#define SCAN(str, name) \ + if (strncmp(buf, str, sizeof(str)-1) == 0) { \ + tp = skip_whitespace(buf + sizeof(str)-1); \ + sp->name += fast_strtoul_10(&tp); \ + continue; \ + } + SCAN("Shared_Clean:" , shared_clean ); + SCAN("Shared_Dirty:" , shared_dirty ); + SCAN("Private_Clean:", private_clean); + SCAN("Private_Dirty:", private_dirty); +#undef SCAN + // f7d29000-f7d39000 rw-s ADR M:m OFS FILE + tp = strchr(buf, '-'); + if (tp) { + *tp = ' '; + tp = buf; + sz = fast_strtoul_16(&tp); /* start */ + sz = (fast_strtoul_16(&tp) - sz) >> 10; /* end - start */ + // tp -> "rw-s" string + w = tp[1]; + // skipping "rw-s ADR M:m OFS " + tp = skip_whitespace(skip_fields(tp, 4)); + // filter out /dev/something (something != zero) + if (strncmp(tp, "/dev/", 5) != 0 || strcmp(tp, "/dev/zero\n") == 0) { + if (w == 'w') { + sp->mapped_rw += sz; + } else if (w == '-') { + sp->mapped_ro += sz; + } + } +//else printf("DROPPING %s (%s)\n", buf, tp); + if (strcmp(tp, "[stack]\n") == 0) + sp->stack += sz; + } + } + fclose(file); + } +#endif /* TOPMEM */ + #if 0 /* PSSCAN_CMD is not used */ if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) { if (sp->argv0) { Modified: trunk/busybox/procps/Config.in =================================================================== --- trunk/busybox/procps/Config.in 2007-09-07 20:28:25 UTC (rev 19801) +++ trunk/busybox/procps/Config.in 2007-09-08 16:51:19 UTC (rev 19802) @@ -128,6 +128,13 @@ help Show 1/10th of a percent in CPU/mem statistics. +config FEATURE_TOPMEM + bool "topmem" + default n + depends on TOP + help + Enable 's' in top (gives lots of memory info) + config UPTIME bool "uptime" default n Modified: trunk/busybox/procps/top.c =================================================================== --- trunk/busybox/procps/top.c 2007-09-07 20:28:25 UTC (rev 19801) +++ trunk/busybox/procps/top.c 2007-09-08 16:51:19 UTC (rev 19802) @@ -58,11 +58,17 @@ typedef int (*cmp_funcp)(top_status_t *P, top_status_t *Q); + enum { SORT_DEPTH = 3 }; + struct globals { top_status_t *top; int ntop; +#if ENABLE_FEATURE_TOPMEM + smallint sort_field; + smallint inverted; +#endif #if ENABLE_FEATURE_USE_TERMIOS struct termios initial_settings; #endif @@ -81,7 +87,9 @@ #define G (*(struct globals*)&bb_common_bufsiz1) #define top (G.top ) #define ntop (G.ntop ) -#define initial_settings (G. initial_settings ) +#define sort_field (G.sort_field ) +#define inverted (G.inverted ) +#define initial_settings (G.initial_settings ) #define sort_function (G.sort_function ) #define prev_hist (G.prev_hist ) #define prev_hist_count (G.prev_hist_count ) @@ -371,15 +379,11 @@ /* what info of the processes is shown */ printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, " PID PPID USER STAT VSZ %MEM %CPU COMMAND"); -#define MIN_WIDTH \ - sizeof( " PID PPID USER STAT VSZ %MEM %CPU C") #else /* !CPU_USAGE_PERCENTAGE */ printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, " PID PPID USER STAT VSZ %MEM COMMAND"); -#define MIN_WIDTH \ - sizeof( " PID PPID USER STAT VSZ %MEM C") #endif #if ENABLE_FEATURE_TOP_DECIMALS @@ -434,20 +438,23 @@ /* printf(" pmem_scale=%u pcpu_scale=%u ", pmem_scale, pcpu_scale); */ #endif - /* Ok, all prelim data is ready, go thru the list */ + scr_width += 2; /* account for leading '\n' and trailing NUL */ + /* Ok, all preliminary data is ready, go thru the list */ while (count-- > 0) { - int col = scr_width; + char buf[scr_width]; + unsigned col; CALC_STAT(pmem, (s->vsz*pmem_scale + pmem_half) >> pmem_shift); #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE CALC_STAT(pcpu, (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift); #endif - if (s->vsz >= 100*1024) + if (s->vsz >= 100000) sprintf(vsz_str_buf, "%6ldm", s->vsz/1024); else sprintf(vsz_str_buf, "%7ld", s->vsz); // PID PPID USER STAT VSZ %MEM [%CPU] COMMAND - col -= printf("\n" "%5u%6u %-8.8s %s%s" FMT + col = snprintf(buf, scr_width, + "\n" "%5u%6u %-8.8s %s%s" FMT #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE FMT #endif @@ -459,11 +466,9 @@ , SHOW_STAT(pcpu) #endif ); - if (col > 0) { - char buf[col + 1]; - read_cmdline(buf, col, s->pid, s->comm); - fputs(buf, stdout); - } + if (col < scr_width) + read_cmdline(buf + col, scr_width - col, s->pid, s->comm); + fputs(buf, stdout); /* printf(" %d/%d %lld/%lld", s->pcpu, total_pcpu, jif.busy - prev_jif.busy, jif.total - prev_jif.total); */ s++; @@ -481,7 +486,7 @@ { clear_username_cache(); free(top); - top = 0; + top = NULL; ntop = 0; } @@ -508,13 +513,298 @@ #endif /* FEATURE_USE_TERMIOS */ + + + + + + + + + + + + + + +typedef unsigned long mem_t; + +typedef struct topmem_status_t { + unsigned pid; + char comm[COMM_LEN]; + /* vsz doesn't count /dev/xxx mappings except /dev/zero */ + mem_t vsz ; + mem_t vszrw ; + mem_t rss ; + mem_t rss_sh ; + mem_t dirty ; + mem_t dirty_sh; + mem_t stack ; +} topmem_status_t; + +enum { NUM_SORT_FIELD = 7 }; + +#define topmem ((topmem_status_t*)top) + +#if ENABLE_FEATURE_TOPMEM +static int topmem_sort(char *a, char *b) +{ + int n; + mem_t l, r; + + n = offsetof(topmem_status_t, vsz) + (sort_field * sizeof(mem_t)); + l = *(mem_t*)(a + n); + r = *(mem_t*)(b + n); +// if (l == r) { +// l = a->mapped_rw; +// r = b->mapped_rw; +// } + /* We want to avoid unsigned->signed and truncation errors */ + /* l>r: -1, l=r: 0, l r) ? -1 : (l != r); + return inverted ? -n : n; +} + +/* Cut "NNNN " out of " NNNN kb" */ +static char *grab_number(char *str, const char *match, unsigned sz) +{ + if (strncmp(str, match, sz) == 0) { + str = skip_whitespace(str + sz); + (skip_non_whitespace(str))[1] = '\0'; + return xstrdup(str); + } + return NULL; +} + +/* display header info (meminfo / loadavg) */ +static void display_topmem_header(int scr_width) +{ + char linebuf[128]; + int i; + FILE *fp; + union { + struct { + /* 1 */ char *total; + /* 2 */ char *mfree; + /* 3 */ char *buf; + /* 4 */ char *cache; + /* 5 */ char *swaptotal; + /* 6 */ char *swapfree; + /* 7 */ char *dirty; + /* 8 */ char *mwrite; + /* 9 */ char *anon; + /* 10 */ char *map; + /* 11 */ char *slab; + }; + char *str[11]; + } Z; +#define total Z.total +#define mfree Z.mfree +#define buf Z.buf +#define cache Z.cache +#define swaptotal Z.swaptotal +#define swapfree Z.swapfree +#define dirty Z.dirty +#define mwrite Z.mwrite +#define anon Z.anon +#define map Z.map +#define slab Z.slab +#define str Z.str + + memset(&Z, 0, sizeof(Z)); + + /* read memory info */ + fp = xfopen("meminfo", "r"); + while (fgets(linebuf, sizeof(linebuf), fp)) { + char *p; + +#define SCAN(match, name) \ + p = grab_number(linebuf, match, sizeof(match)-1); \ + if (p) { name = p; continue; } + + SCAN("MemTotal:", total); + SCAN("MemFree:", mfree); + SCAN("Buffers:", buf); + SCAN("Cached:", cache); + SCAN("SwapTotal:", swaptotal); + SCAN("SwapFree:", swapfree); + SCAN("Dirty:", dirty); + SCAN("Writeback:", mwrite); + SCAN("AnonPages:", anon); + SCAN("Mapped:", map); + SCAN("Slab:", slab); +#undef SCAN + } + fclose(fp); + +#define S(s) (s ? s : "0") + snprintf(linebuf, sizeof(linebuf), + "Mem %stotal %sanon %smap %sfree", + S(total), S(anon), S(map), S(mfree)); + printf(OPT_BATCH_MODE ? "%.*s\n" : "\e[H\e[J%.*s\n", scr_width, linebuf); + + snprintf(linebuf, sizeof(linebuf), + " %sslab %sbuf %scache %sdirty %swrite", + S(slab), S(buf), S(cache), S(dirty), S(mwrite)); + printf("%.*s\n", scr_width, linebuf); + + snprintf(linebuf, sizeof(linebuf), + "Swap %stotal %sfree", // TODO: % used? + S(swaptotal), S(swapfree)); + printf("%.*s\n", scr_width, linebuf); +#undef S + + for (i = 0; i < ARRAY_SIZE(str); i++) + free(str[i]); +#undef total +#undef free +#undef buf +#undef cache +#undef swaptotal +#undef swapfree +#undef dirty +#undef write +#undef anon +#undef map +#undef slab +#undef str +} + +// Converts unsigned long long value into compact 5-char +// representation. Sixth char is always ' ' +static void smart_ulltoa6(unsigned long long ul, char buf[6]) +{ + const char *fmt; + char c; + unsigned v, u, idx = 0; + + if (ul > 99999) { // do not scale if 99999 or less + ul *= 10; + do { + ul /= 1024; + idx++; + } while (ul >= 100000); + } + v = ul; // ullong divisions are expensive, avoid them + + fmt = " 123456789"; + u = v / 10; + v = v % 10; + if (!idx) { + // 99999 or less: use "12345" format + // u is value/10, v is last digit + c = buf[0] = " 123456789"[u/1000]; + if (c != ' ') fmt = "0123456789"; + c = buf[1] = fmt[u/100%10]; + if (c != ' ') fmt = "0123456789"; + c = buf[2] = fmt[u/10%10]; + if (c != ' ') fmt = "0123456789"; + buf[3] = fmt[u%10]; + buf[4] = "0123456789"[v]; + } else { + // value has been scaled into 0..9999.9 range + // u is value, v is 1/10ths (allows for 92.1M format) + if (u >= 100) { + // value is >= 100: use "1234M', " 123M" formats + c = buf[0] = " 123456789"[u/1000]; + if (c != ' ') fmt = "0123456789"; + c = buf[1] = fmt[u/100%10]; + if (c != ' ') fmt = "0123456789"; + v = u % 10; + u = u / 10; + buf[2] = fmt[u%10]; + } else { + // value is < 100: use "92.1M" format + c = buf[0] = " 123456789"[u/10]; + if (c != ' ') fmt = "0123456789"; + buf[1] = fmt[u%10]; + buf[2] = '.'; + } + buf[3] = "0123456789"[v]; + // see http://en.wikipedia.org/wiki/Tera + buf[4] = " mgtpezy"[idx]; + } + buf[5] = ' '; +} + +static void display_topmem_process_list(int count, int scr_width) +{ +#define HDR_STR " PID VSZ VSZRW RSS (SHR) DIRTY (SHR) STACK" +#define MIN_WIDTH sizeof(HDR_STR) + const topmem_status_t *s = topmem; + char buf[scr_width | MIN_WIDTH]; /* a|b is a cheap max(a,b) */ + + display_topmem_header(scr_width); + strcpy(buf, HDR_STR " COMMAND"); + buf[5 + sort_field * 6] = '*'; + printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, buf); + + while (--count >= 0) { + // PID VSZ VSZRW RSS (SHR) DIRTY (SHR) COMMAND + smart_ulltoa6(s->pid , &buf[0*6]); + smart_ulltoa6(s->vsz , &buf[1*6]); + smart_ulltoa6(s->vszrw , &buf[2*6]); + smart_ulltoa6(s->rss , &buf[3*6]); + smart_ulltoa6(s->rss_sh , &buf[4*6]); + smart_ulltoa6(s->dirty , &buf[5*6]); + smart_ulltoa6(s->dirty_sh, &buf[6*6]); + smart_ulltoa6(s->stack , &buf[7*6]); + buf[8*6] = '\0'; + if (scr_width > MIN_WIDTH) { + read_cmdline(&buf[8*6], scr_width - MIN_WIDTH, s->pid, s->comm); + } + printf("\n""%.*s", scr_width, buf); + s++; + } + putchar(OPT_BATCH_MODE ? '\n' : '\r'); + fflush(stdout); +#undef HDR_STR +#undef MIN_WIDTH +} +#else +void display_topmem_process_list(int count, int scr_width); +int topmem_sort(char *a, char *b); +#endif /* TOPMEM */ + + + + + + + + + + + + + + + + +enum { + TOP_MASK = 0 + | PSSCAN_PID + | PSSCAN_PPID + | PSSCAN_VSZ + | PSSCAN_STIME + | PSSCAN_UTIME + | PSSCAN_STATE + | PSSCAN_COMM + | PSSCAN_UIDGID, + TOPMEM_MASK = 0 + | PSSCAN_PID + | PSSCAN_SMAPS + | PSSCAN_COMM, +}; + int top_main(int argc, char **argv); int top_main(int argc, char **argv) { int count, lines, col; unsigned interval; - int iterations = -1; /* infinite */ + int iterations = 0; /* infinite */ char *sinterval, *siterations; + SKIP_FEATURE_TOPMEM(const) unsigned scan_mask = TOP_MASK; #if ENABLE_FEATURE_USE_TERMIOS struct termios new_settings; struct pollfd pfd[1]; @@ -563,62 +853,82 @@ procps_status_t *p = NULL; /* Default */ - lines = 24 - 3 USE_FEATURE_TOP_CPU_GLOBAL_PERCENTS( - 1); + lines = 24; col = 79; #if ENABLE_FEATURE_USE_TERMIOS get_terminal_width_height(0, &col, &lines); - /* We wrap horribly if width is too narrow (TODO) */ - if (lines < 5 || col < MIN_WIDTH) { + if (lines < 5 || col < 10) { sleep(interval); continue; } - lines -= 3 USE_FEATURE_TOP_CPU_GLOBAL_PERCENTS( + 1); #endif /* FEATURE_USE_TERMIOS */ + if (!ENABLE_FEATURE_TOP_CPU_GLOBAL_PERCENTS && scan_mask == TOP_MASK) + lines -= 3; + else + lines -= 4; /* read process IDs & status for all the processes */ - while ((p = procps_scan(p, 0 - | PSSCAN_PID - | PSSCAN_PPID - | PSSCAN_VSZ - | PSSCAN_STIME - | PSSCAN_UTIME - | PSSCAN_STATE - | PSSCAN_COMM - | PSSCAN_UIDGID - )) != NULL) { - int n = ntop; - top = xrealloc(top, (++ntop) * sizeof(*top)); - top[n].pid = p->pid; - top[n].ppid = p->ppid; - top[n].vsz = p->vsz; + while ((p = procps_scan(p, scan_mask)) != NULL) { + int n; + if (scan_mask == TOP_MASK) { + n = ntop; + top = xrealloc(top, (++ntop) * sizeof(*top)); + top[n].pid = p->pid; + top[n].ppid = p->ppid; + top[n].vsz = p->vsz; #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE - top[n].ticks = p->stime + p->utime; + top[n].ticks = p->stime + p->utime; #endif - top[n].uid = p->uid; - strcpy(top[n].state, p->state); - strcpy(top[n].comm, p->comm); + top[n].uid = p->uid; + strcpy(top[n].state, p->state); + strcpy(top[n].comm, p->comm); + } else { /* TOPMEM */ +#if ENABLE_FEATURE_TOPMEM + if (!(p->mapped_ro | p->mapped_rw)) + continue; /* kernel threads are ignored */ + n = ntop; + top = xrealloc(topmem, (++ntop) * sizeof(*topmem)); + strcpy(topmem[n].comm, p->comm); + topmem[n].pid = p->pid; + topmem[n].vsz = p->mapped_rw + p->mapped_ro; + topmem[n].vszrw = p->mapped_rw; + topmem[n].rss_sh = p->shared_clean + p->shared_dirty; + topmem[n].rss = p->private_clean + p->private_dirty + topmem[n].rss_sh; + topmem[n].dirty = p->private_dirty + p->shared_dirty; + topmem[n].dirty_sh = p->shared_dirty; + topmem[n].stack = p->stack; +#endif + } } if (ntop == 0) { bb_error_msg_and_die("no process info in /proc"); } + + if (scan_mask == TOP_MASK) { #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE - if (!prev_hist_count) { + if (!prev_hist_count) { + do_stats(); + usleep(100000); + clearmems(); + continue; + } do_stats(); - sleep(1); - clearmems(); - continue; - } - do_stats(); /* TODO: we don't need to sort all 10000 processes, we need to find top 24! */ - qsort(top, ntop, sizeof(top_status_t), (void*)mult_lvl_cmp); + qsort(top, ntop, sizeof(top_status_t), (void*)mult_lvl_cmp); #else - qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0])); + qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0])); #endif /* FEATURE_TOP_CPU_USAGE_PERCENTAGE */ + } else { /* TOPMEM */ + qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort); + } count = lines; if (OPT_BATCH_MODE || count > ntop) { count = ntop; } - display_process_list(count, col); + if (scan_mask == TOP_MASK) + display_process_list(count, col); + else + display_topmem_process_list(count, col); clearmems(); if (iterations >= 0 && !--iterations) break; @@ -628,11 +938,17 @@ if (poll(pfd, 1, interval * 1000) != 0) { if (read(0, &c, 1) != 1) /* signal */ break; - if (c == 'q' || c == initial_settings.c_cc[VINTR]) + if (c == initial_settings.c_cc[VINTR]) break; - if (c == 'N') + c |= 0x20; /* lowercase */ + if (c == 'q') + break; + if (c == 'n') { + USE_FEATURE_TOPMEM(scan_mask = TOP_MASK;) sort_function[0] = pid_sort; - if (c == 'M') { + } + if (c == 'm') { + USE_FEATURE_TOPMEM(scan_mask = TOP_MASK;) sort_function[0] = mem_sort; #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE sort_function[1] = pcpu_sort; @@ -640,17 +956,30 @@ #endif } #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE - if (c == 'P') { + if (c == 'p') { + USE_FEATURE_TOPMEM(scan_mask = TOP_MASK;) sort_function[0] = pcpu_sort; sort_function[1] = mem_sort; sort_function[2] = time_sort; } - if (c == 'T') { + if (c == 't') { + USE_FEATURE_TOPMEM(scan_mask = TOP_MASK;) sort_function[0] = time_sort; sort_function[1] = mem_sort; sort_function[2] = pcpu_sort; } +#if ENABLE_FEATURE_TOPMEM + if (c == 's') { + scan_mask = TOPMEM_MASK; + free(prev_hist); + prev_hist = NULL; + prev_hist_count = 0; + sort_field = (sort_field + 1) % NUM_SORT_FIELD; + } + if (c == 'r') + inverted ^= 1; #endif +#endif } #endif /* FEATURE_USE_TERMIOS */ } From vda at busybox.net Sat Sep 8 10:21:02 2007 From: vda at busybox.net (vda at busybox.net) Date: Sat, 8 Sep 2007 10:21:02 -0700 (PDT) Subject: svn commit: trunk/busybox/procps Message-ID: <20070908172102.8A7D3A6130@busybox.net> Author: vda Date: 2007-09-08 10:21:01 -0700 (Sat, 08 Sep 2007) New Revision: 19803 Log: top: add sizeof(G) check; fix