From vda at busybox.net Wed Jan 2 11:55:12 2008 From: vda at busybox.net (vda at busybox.net) Date: Wed, 2 Jan 2008 11:55:12 -0800 (PST) Subject: svn commit: trunk/busybox: archival include init ipsvd libbb miscut etc... Message-ID: <20080102195512.003C01200F3@busybox.net> Author: vda Date: 2008-01-02 11:55:04 -0800 (Wed, 02 Jan 2008) New Revision: 20697 Log: libbb: introduce and use safe_waitpid (loops in EINTR) *: use more approproate (shorter) versions of wait() function old new delta safe_waitpid - 48 +48 wait_any_nohang - 17 +17 send_tree 365 369 +4 processorstop 432 435 +3 text_yank 110 108 -2 make_human_readable_str 202 200 -2 crond_main 1368 1366 -2 handle_sigchld 49 43 -6 reapchild 166 159 -7 custom 260 250 -10 checkscript 191 177 -14 wait_nohang 17 - -17 wait_pid 43 - -43 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 2/7 up/down: 72/-103) Total: -31 bytes Modified: trunk/busybox/archival/tar.c trunk/busybox/include/libbb.h trunk/busybox/init/init.c trunk/busybox/ipsvd/tcpudp.c trunk/busybox/libbb/vfork_daemon_rexec.c trunk/busybox/miscutils/crond.c trunk/busybox/networking/httpd.c trunk/busybox/networking/ifupdown.c trunk/busybox/networking/inetd.c trunk/busybox/networking/telnetd.c trunk/busybox/networking/udhcp/script.c trunk/busybox/runit/runsv.c trunk/busybox/runit/runsvdir.c trunk/busybox/runit/sv.c trunk/busybox/runit/svlogd.c trunk/busybox/shell/ash.c trunk/busybox/shell/hush.c trunk/busybox/shell/msh.c Changeset: Modified: trunk/busybox/archival/tar.c =================================================================== --- trunk/busybox/archival/tar.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/archival/tar.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -610,7 +610,7 @@ if (gzipPid) { int status; - if (waitpid(gzipPid, &status, 0) == -1) + if (safe_waitpid(gzipPid, &status, 0) == -1) bb_perror_msg("waitpid"); else if (!WIFEXITED(status) || WEXITSTATUS(status)) /* gzip was killed or has exited with nonzero! */ @@ -688,7 +688,7 @@ /* Actually, 'status' is a signo. We reuse it for other needs */ /* Wait for any child without blocking */ - if (waitpid(-1, &status, WNOHANG) < 0) + if (wait_any_nohang(&status) < 0) /* wait failed?! I'm confused... */ return; Modified: trunk/busybox/include/libbb.h =================================================================== --- trunk/busybox/include/libbb.h 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/include/libbb.h 2008-01-02 19:55:04 UTC (rev 20697) @@ -587,9 +587,9 @@ * if (rc < 0) bb_perror_msg("%s", argv[0]); * if (rc > 0) bb_error_msg("exit code: %d", rc); */ +int safe_waitpid(int pid, int *wstat, int options); int wait4pid(int pid); -int wait_pid(int *wstat, int pid); -int wait_nohang(int *wstat); +int wait_any_nohang(int *wstat); #define wait_crashed(w) ((w) & 127) #define wait_exitcode(w) ((w) >> 8) #define wait_stopsig(w) ((w) >> 8) Modified: trunk/busybox/init/init.c =================================================================== --- trunk/busybox/init/init.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/init/init.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -95,9 +95,14 @@ /* Function prototypes */ static void delete_init_action(struct init_action *a); -static int waitfor(pid_t pid); static void halt_reboot_pwoff(int sig) ATTRIBUTE_NORETURN; +/* TODO: move to libbb? */ +static int waitfor(pid_t runpid) +{ + return safe_waitpid(runpid, NULL, 0); +} + static void loop_forever(void) ATTRIBUTE_NORETURN; static void loop_forever(void) { @@ -465,19 +470,6 @@ _exit(-1); } -static int waitfor(pid_t runpid) -{ - int status, wpid; - - while (1) { - wpid = waitpid(runpid, &status, 0); - if (wpid == -1 && errno == EINTR) - continue; - break; - } - return wpid; -} - /* Run all commands of a particular type */ static void run_actions(int action) { @@ -520,7 +512,7 @@ reboot(magic); _exit(0); } - waitpid(pid, NULL, 0); + waitfor(pid); } static void kill_all_processes(void) @@ -980,7 +972,7 @@ /* Don't consume all CPU time -- sleep a bit */ sleep(1); - /* Wait for a child process to exit */ + /* Wait for any child process to exit */ wpid = wait(NULL); while (wpid > 0) { /* Find out who died and clean up their corpse */ @@ -995,7 +987,7 @@ } } /* see if anyone else is waiting to be reaped */ - wpid = waitpid(-1, NULL, WNOHANG); + wpid = wait_any_nohang(NULL); } } } Modified: trunk/busybox/ipsvd/tcpudp.c =================================================================== --- trunk/busybox/ipsvd/tcpudp.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/ipsvd/tcpudp.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -121,7 +121,7 @@ int wstat; int pid; - while ((pid = wait_nohang(&wstat)) > 0) { + while ((pid = wait_any_nohang(&wstat)) > 0) { if (max_per_host) ipsvd_perhost_remove(pid); if (cnum) Modified: trunk/busybox/libbb/vfork_daemon_rexec.c =================================================================== --- trunk/busybox/libbb/vfork_daemon_rexec.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/libbb/vfork_daemon_rexec.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -66,6 +66,21 @@ return pid; } +int safe_waitpid(int pid, int *wstat, int options) +{ + int r; + + do + r = waitpid(pid, wstat, options); + while ((r == -1) && (errno == EINTR)); + return r; +} + +int wait_any_nohang(int *wstat) +{ + return safe_waitpid(-1, wstat, WNOHANG); +} + // Wait for the specified child PID to exit, returning child's error return. int wait4pid(int pid) { @@ -76,30 +91,20 @@ /* we expect errno to be already set from failed [v]fork/exec */ return -1; } - if (waitpid(pid, &status, 0) == -1) + if (safe_waitpid(pid, &status, 0) == -1) return -1; if (WIFEXITED(status)) return WEXITSTATUS(status); if (WIFSIGNALED(status)) return WTERMSIG(status) + 1000; return 0; + if (WIFEXITED(status)) + return WEXITSTATUS(status); + if (WIFSIGNALED(status)) + return WTERMSIG(status) + 1000; + return 0; } -int wait_nohang(int *wstat) -{ - return waitpid(-1, wstat, WNOHANG); -} - -int wait_pid(int *wstat, int pid) -{ - int r; - - do - r = waitpid(pid, wstat, 0); - while ((r == -1) && (errno == EINTR)); - return r; -} - #if ENABLE_FEATURE_PREFER_APPLETS void save_nofork_data(struct nofork_save_area *save) { Modified: trunk/busybox/miscutils/crond.c =================================================================== --- trunk/busybox/miscutils/crond.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/miscutils/crond.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -756,7 +756,7 @@ for (line = file->cf_LineBase; line; line = line->cl_Next) { if (line->cl_Pid > 0) { int status; - int r = wait4(line->cl_Pid, &status, WNOHANG, NULL); + int r = waitpid(line->cl_Pid, &status, WNOHANG); if (r < 0 || r == line->cl_Pid) { EndJob(file->cf_User, line); Modified: trunk/busybox/networking/httpd.c =================================================================== --- trunk/busybox/networking/httpd.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/networking/httpd.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -1152,7 +1152,7 @@ count = safe_poll(pfd, 3, -1); if (count <= 0) { #if 0 - if (waitpid(pid, &status, WNOHANG) <= 0) { + if (safe_waitpid(pid, &status, WNOHANG) <= 0) { /* Weird. CGI didn't exit and no fd's * are ready, yet poll returned?! */ continue; Modified: trunk/busybox/networking/ifupdown.c =================================================================== --- trunk/busybox/networking/ifupdown.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/networking/ifupdown.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -944,7 +944,7 @@ execle(DEFAULT_SHELL, DEFAULT_SHELL, "-c", str, NULL, my_environ); exit(127); } - waitpid(child, &status, 0); + safe_waitpid(child, &status, 0); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { return 0; } @@ -1068,7 +1068,7 @@ fprintf(in, "%s\n", map->mapping[i]); } fclose(in); - waitpid(pid, &status, 0); + safe_waitpid(pid, &status, 0); if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { /* If the mapping script exited successfully, try to Modified: trunk/busybox/networking/inetd.c =================================================================== --- trunk/busybox/networking/inetd.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/networking/inetd.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -1161,7 +1161,7 @@ servtab_t *sep; for (;;) { - pid = wait3(&status, WNOHANG, NULL); + pid = wait_any_nohang(&status); if (pid <= 0) break; for (sep = servtab; sep; sep = sep->se_next) Modified: trunk/busybox/networking/telnetd.c =================================================================== --- trunk/busybox/networking/telnetd.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/networking/telnetd.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -394,7 +394,7 @@ /* Looping: more than one child may have exited */ while (1) { - pid = waitpid(-1, NULL, WNOHANG); + pid = wait_any_nohang(NULL); if (pid <= 0) break; ts = sessions; Modified: trunk/busybox/networking/udhcp/script.c =================================================================== --- trunk/busybox/networking/udhcp/script.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/networking/udhcp/script.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -232,7 +232,7 @@ name, NULL, envp); bb_perror_msg_and_die("script %s failed", client_config.script); } - waitpid(pid, NULL, 0); + safe_waitpid(pid, NULL, 0); for (curr = envp; *curr; curr++) free(*curr); free(envp); Modified: trunk/busybox/runit/runsv.c =================================================================== --- trunk/busybox/runit/runsv.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/runit/runsv.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -282,8 +282,7 @@ execve(a, prog, environ); fatal_cannot("run control/?"); } - while (wait_pid(&w, pid) == -1) { - if (errno == EINTR) continue; + while (safe_waitpid(pid, &w, 0) == -1) { warn_cannot("wait for child control/?"); return 0; } @@ -593,7 +592,7 @@ int child; int wstat; - child = wait_nohang(&wstat); + child = wait_any_nohang(&wstat); if (!child) break; if ((child == -1) && (errno != EINTR)) Modified: trunk/busybox/runit/runsvdir.c =================================================================== --- trunk/busybox/runit/runsvdir.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/runit/runsvdir.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -252,7 +252,7 @@ for (;;) { /* collect children */ for (;;) { - pid = wait_nohang(&wstat); + pid = wait_any_nohang(&wstat); if (pid <= 0) break; for (i = 0; i < svnum; i++) { Modified: trunk/busybox/runit/sv.c =================================================================== --- trunk/busybox/runit/sv.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/runit/sv.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -333,8 +333,7 @@ bb_perror_msg(WARN"cannot %s child %s/check", "run", *service); return 0; } - while (wait_pid(&w, pid) == -1) { - if (errno == EINTR) continue; + while (safe_waitpid(pid, &w, 0) == -1) { bb_perror_msg(WARN"cannot %s child %s/check", "wait for", *service); return 0; } Modified: trunk/busybox/runit/svlogd.c =================================================================== --- trunk/busybox/runit/svlogd.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/runit/svlogd.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -265,7 +265,7 @@ if (ld->ppid) { sig_unblock(SIGHUP); - while (wait_pid(&wstat, ld->ppid) == -1) + while (safe_waitpid(ld->ppid, &wstat, 0) == -1) pause2cannot("wait for processor", ld->name); sig_block(SIGHUP); ld->ppid = 0; @@ -794,7 +794,7 @@ if (verbose) bb_error_msg(INFO"sig%s received", "child"); - while ((pid = wait_nohang(&wstat)) > 0) { + while ((pid = wait_any_nohang(&wstat)) > 0) { for (l = 0; l < dirn; ++l) { if (dir[l].ppid == pid) { dir[l].ppid = 0; Modified: trunk/busybox/shell/ash.c =================================================================== --- trunk/busybox/shell/ash.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/shell/ash.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -3768,7 +3768,7 @@ #endif if (block == 0) flags |= WNOHANG; - return wait3(status, flags, (struct rusage *)NULL); + return waitpid(-1, status, flags); // safe_waitpid? } /* Modified: trunk/busybox/shell/hush.c =================================================================== --- trunk/busybox/shell/hush.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/shell/hush.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -1649,6 +1649,7 @@ // + killall -STOP cat wait_more: +// TODO: safe_waitpid? while ((childpid = waitpid(-1, &status, attributes)) > 0) { const int dead = WIFEXITED(status) || WIFSIGNALED(status); Modified: trunk/busybox/shell/msh.c =================================================================== --- trunk/busybox/shell/msh.c 2007-12-30 20:13:39 UTC (rev 20696) +++ trunk/busybox/shell/msh.c 2008-01-02 19:55:04 UTC (rev 20697) @@ -4162,7 +4162,7 @@ return 0; } if (i != 0) { - waitpid(i, NULL, 0); + waitpid(i, NULL, 0); // safe_waitpid? global_env.iop->argp->aword = ++cp; close(pf[1]); PUSHIO(afile, remap(pf[0]), From vda at busybox.net Thu Jan 3 04:12:29 2008 From: vda at busybox.net (vda at busybox.net) Date: Thu, 3 Jan 2008 04:12:29 -0800 (PST) Subject: svn commit: trunk/busybox/sysklogd Message-ID: <20080103121229.612CB1200FA@busybox.net> Author: vda Date: 2008-01-03 04:12:27 -0800 (Thu, 03 Jan 2008) New Revision: 20698 Log: syslogd: don't die if remote host's IP cannot be resolved. retry resolutions every two minutes instead. function old new delta syslogd_main 865 904 +39 timestamp_and_log 324 313 -11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 39/-11) Total: 28 bytes Modified: trunk/busybox/sysklogd/syslogd.c Changeset: Modified: trunk/busybox/sysklogd/syslogd.c =================================================================== --- trunk/busybox/sysklogd/syslogd.c 2008-01-02 19:55:04 UTC (rev 20697) +++ trunk/busybox/sysklogd/syslogd.c 2008-01-03 12:12:27 UTC (rev 20698) @@ -42,7 +42,10 @@ * (semaphores are down but do_mark routine tries to down them again) */ #undef SYSLOGD_MARK -enum { MAX_READ = 256 }; +enum { + MAX_READ = 256, + DNS_WAIT_SEC = 2 * 60, +}; /* Semaphore operation structures */ struct shbuf_ds { @@ -86,6 +89,12 @@ struct globals { GLOBALS + +#if ENABLE_FEATURE_REMOTE_LOG + unsigned last_dns_resolve; + char *remoteAddrStr; +#endif + #if ENABLE_FEATURE_IPC_SYSLOG struct shbuf_ds *shbuf; #endif @@ -128,6 +137,9 @@ }; #define G (*ptr_to_globals) +#define INIT_G() do { \ + PTR_TO_GLOBALS = memcpy(xzalloc(sizeof(G)), &init_data, sizeof(init_data)); \ +} while (0) /* Options */ @@ -140,7 +152,7 @@ USE_FEATURE_ROTATE_LOGFILE(OPTBIT_filesize ,) // -s USE_FEATURE_ROTATE_LOGFILE(OPTBIT_rotatecnt ,) // -b USE_FEATURE_REMOTE_LOG( OPTBIT_remote ,) // -R - USE_FEATURE_REMOTE_LOG( OPTBIT_localtoo ,) // -L + USE_FEATURE_REMOTE_LOG( OPTBIT_locallog ,) // -L USE_FEATURE_IPC_SYSLOG( OPTBIT_circularlog,) // -C OPT_mark = 1 << OPTBIT_mark , @@ -151,7 +163,7 @@ OPT_filesize = USE_FEATURE_ROTATE_LOGFILE((1 << OPTBIT_filesize )) + 0, OPT_rotatecnt = USE_FEATURE_ROTATE_LOGFILE((1 << OPTBIT_rotatecnt )) + 0, OPT_remotelog = USE_FEATURE_REMOTE_LOG( (1 << OPTBIT_remote )) + 0, - OPT_locallog = USE_FEATURE_REMOTE_LOG( (1 << OPTBIT_localtoo )) + 0, + OPT_locallog = USE_FEATURE_REMOTE_LOG( (1 << OPTBIT_locallog )) + 0, OPT_circularlog = USE_FEATURE_IPC_SYSLOG( (1 << OPTBIT_circularlog)) + 0, }; #define OPTION_STR "m:nO:l:S" \ @@ -163,12 +175,11 @@ #define OPTION_DECL *opt_m, *opt_l \ USE_FEATURE_ROTATE_LOGFILE(,*opt_s) \ USE_FEATURE_ROTATE_LOGFILE(,*opt_b) \ - USE_FEATURE_REMOTE_LOG( ,*opt_R) \ USE_FEATURE_IPC_SYSLOG( ,*opt_C = NULL) #define OPTION_PARAM &opt_m, &G.logFilePath, &opt_l \ USE_FEATURE_ROTATE_LOGFILE(,&opt_s) \ USE_FEATURE_ROTATE_LOGFILE(,&opt_b) \ - USE_FEATURE_REMOTE_LOG( ,&opt_R) \ + USE_FEATURE_REMOTE_LOG( ,&G.remoteAddrStr) \ USE_FEATURE_IPC_SYSLOG( ,&opt_C) @@ -387,6 +398,9 @@ { char *timestamp; + if (ENABLE_FEATURE_REMOTE_LOG && !(option_mask32 & OPT_locallog)) + return; + if (len < 16 || msg[3] != ' ' || msg[6] != ' ' || msg[9] != ':' || msg[12] != ':' || msg[15] != ' ' ) { @@ -400,18 +414,14 @@ timestamp[15] = '\0'; /* Log message locally (to file or shared mem) */ - if (!ENABLE_FEATURE_REMOTE_LOG || (option_mask32 & OPT_locallog)) { - if (LOG_PRI(pri) < G.logLevel) { - if (option_mask32 & OPT_small) - sprintf(G.printbuf, "%s %s\n", timestamp, msg); - else { - char res[20]; - parse_fac_prio_20(pri, res); - sprintf(G.printbuf, "%s %s %s %s\n", timestamp, G.localHostName, res, msg); - } - log_locally(G.printbuf); - } + if (option_mask32 & OPT_small) + sprintf(G.printbuf, "%s %s\n", timestamp, msg); + else { + char res[20]; + parse_fac_prio_20(pri, res); + sprintf(G.printbuf, "%s %s %s %s\n", timestamp, G.localHostName, res, msg); } + log_locally(G.printbuf); } static void split_escape_and_log(char *tmpbuf, int len) @@ -443,8 +453,10 @@ *q++ = c; } *q = '\0'; + /* Now log it */ - timestamp_and_log(pri, G.parsebuf, q - G.parsebuf); + if (LOG_PRI(pri) < G.logLevel) + timestamp_and_log(pri, G.parsebuf, q - G.parsebuf); } } @@ -495,6 +507,24 @@ return sock_fd; } +#if ENABLE_FEATURE_REMOTE_LOG +static int try_to_resolve_remote(void) +{ + if (!G.remoteAddr) { + unsigned now = monotonic_sec(); + + /* Don't resolve name too often - DNS timeouts can be big */ + if ((now - G.last_dns_resolve) < DNS_WAIT_SEC) + return -1; + G.last_dns_resolve = now; + G.remoteAddr = host2sockaddr(G.remoteAddrStr, 514); + if (!G.remoteAddr) + return -1; + } + return socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0); +} +#endif + static void do_syslogd(void) ATTRIBUTE_NORETURN; static void do_syslogd(void) { @@ -505,10 +535,7 @@ signal(SIGTERM, quit_signal); signal(SIGQUIT, quit_signal); signal(SIGHUP, SIG_IGN); - signal(SIGCHLD, SIG_IGN); -#ifdef SIGCLD - signal(SIGCLD, SIG_IGN); -#endif + /* signal(SIGCHLD, SIG_IGN); - why? */ #ifdef SYSLOGD_MARK signal(SIGALRM, do_mark); alarm(G.markInterval); @@ -554,19 +581,21 @@ #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 (G.remoteAddrStr) { if (-1 == G.remoteFD) { - G.remoteFD = socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0); + G.remoteFD = try_to_resolve_remote(); + if (-1 == G.remoteFD) + goto no_luck; } - 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); - } + /* send message to remote logger, ignore possible error */ + sendto(G.remoteFD, G.recvbuf, sz, MSG_DONTWAIT, + &G.remoteAddr->sa, G.remoteAddr->len); + no_luck: ; } #endif - split_escape_and_log(G.recvbuf, sz); - } /* for */ + if (!ENABLE_FEATURE_REMOTE_LOG || (option_mask32 & OPT_locallog)) + split_escape_and_log(G.recvbuf, sz); + } /* for (;;) */ } int syslogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; @@ -575,7 +604,10 @@ char OPTION_DECL; char *p; - PTR_TO_GLOBALS = memcpy(xzalloc(sizeof(G)), &init_data, sizeof(init_data)); + INIT_G(); +#if ENABLE_FEATURE_REMOTE_LOG + G.last_dns_resolve = monotonic_sec() - DNS_WAIT_SEC - 1; +#endif /* do normal option parsing */ opt_complementary = "=0"; /* no non-option params */ @@ -595,12 +627,6 @@ if (option_mask32 & OPT_rotatecnt) // -b G.logFileRotate = xatou_range(opt_b, 0, 99); #endif -#if ENABLE_FEATURE_REMOTE_LOG - if (option_mask32 & OPT_remotelog) { // -R - G.remoteAddr = xhost2sockaddr(opt_R, 514); - } - //if (option_mask32 & OPT_locallog) // -L -#endif #if ENABLE_FEATURE_IPC_SYSLOG if (opt_C) // -Cn G.shm_size = xatoul_range(opt_C, 4, INT_MAX/1024) * 1024; From vda at busybox.net Thu Jan 3 04:13:47 2008 From: vda at busybox.net (vda at busybox.net) Date: Thu, 3 Jan 2008 04:13:47 -0800 (PST) Subject: svn commit: trunk/busybox/sysklogd Message-ID: <20080103121347.0DD4B1200FA@busybox.net> Author: vda Date: 2008-01-03 04:13:42 -0800 (Thu, 03 Jan 2008) New Revision: 20699 Log: syslogd: avoid excessive tine() system calls function old new delta timestamp_and_log_internal - 24 +24 log_locally 741 744 +3 timestamp_and_log 313 314 +1 syslogd_main 904 897 -7 quit_signal 101 94 -7 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/2 up/down: 28/-14) Total: 14 bytes Modified: trunk/busybox/sysklogd/syslogd.c Changeset: Modified: trunk/busybox/sysklogd/syslogd.c =================================================================== --- trunk/busybox/sysklogd/syslogd.c 2008-01-03 12:12:27 UTC (rev 20698) +++ trunk/busybox/sysklogd/syslogd.c 2008-01-03 12:13:42 UTC (rev 20699) @@ -285,7 +285,7 @@ /* Print a message to the log file. */ -static void log_locally(char *msg) +static void log_locally(time_t now, char *msg) { struct flock fl; int len = strlen(msg); @@ -297,10 +297,10 @@ } #endif if (G.logFD >= 0) { - time_t cur; - time(&cur); - if (G.last_log_time != cur) { - G.last_log_time = cur; /* reopen log file every second */ + if (!now) + now = time(NULL); + if (G.last_log_time != now) { + G.last_log_time = now; /* reopen log file every second */ close(G.logFD); goto reopen; } @@ -397,23 +397,20 @@ static void timestamp_and_log(int pri, char *msg, int len) { char *timestamp; + time_t now; - if (ENABLE_FEATURE_REMOTE_LOG && !(option_mask32 & OPT_locallog)) - return; - if (len < 16 || msg[3] != ' ' || msg[6] != ' ' || msg[9] != ':' || msg[12] != ':' || msg[15] != ' ' ) { - time_t now; time(&now); - timestamp = ctime(&now) + 4; + timestamp = ctime(&now) + 4; /* skip day of week */ } else { + now = 0; timestamp = msg; msg += 16; } timestamp[15] = '\0'; - /* Log message locally (to file or shared mem) */ if (option_mask32 & OPT_small) sprintf(G.printbuf, "%s %s\n", timestamp, msg); else { @@ -421,9 +418,18 @@ parse_fac_prio_20(pri, res); sprintf(G.printbuf, "%s %s %s %s\n", timestamp, G.localHostName, res, msg); } - log_locally(G.printbuf); + + /* Log message locally (to file or shared mem) */ + log_locally(now, G.printbuf); } +static void timestamp_and_log_internal(const char *msg) +{ + if (ENABLE_FEATURE_REMOTE_LOG && !(option_mask32 & OPT_locallog)) + return; + timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)msg, 0); +} + static void split_escape_and_log(char *tmpbuf, int len) { char *p = tmpbuf; @@ -462,7 +468,7 @@ static void quit_signal(int sig) { - timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)"syslogd exiting", 0); + timestamp_and_log_internal("syslogd exiting"); puts("syslogd exiting"); if (ENABLE_FEATURE_IPC_SYSLOG) ipcsyslog_cleanup(); @@ -473,7 +479,7 @@ static void do_mark(int sig) { if (G.markInterval) { - timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)"-- MARK --", 0); + timestamp_and_log_internal("-- MARK --"); alarm(G.markInterval); } } @@ -546,8 +552,7 @@ ipcsyslog_init(); } - timestamp_and_log(LOG_SYSLOG | LOG_INFO, - (char*)"syslogd started: BusyBox v" BB_VER, 0); + timestamp_and_log_internal("syslogd started: BusyBox v" BB_VER); for (;;) { size_t sz; From bugs at busybox.net Thu Jan 3 12:51:05 2008 From: bugs at busybox.net (bugs at busybox.net) Date: Thu, 3 Jan 2008 12:51:05 -0800 Subject: [BusyBox 0001844]: busybox 1.9.0: "ip route" not working Message-ID: <0329f089c5dc7200a72de3fa963803d4@bugs.busybox.net> The following issue has been SUBMITTED. ====================================================================== http://busybox.net/bugs/view.php?id=1844 ====================================================================== Reported By: razzor Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1844 Category: Networking Support Reproducibility: always Severity: minor Priority: normal Status: assigned ====================================================================== Date Submitted: 01-03-2008 12:51 PST Last Modified: 01-03-2008 12:51 PST ====================================================================== Summary: busybox 1.9.0: "ip route" not working Description: The "ip route" command should show the routing table, but parses the environment: > $ busybox-1.9.0/busybox ip route > ip: an inet address is expected rather than "KDE_MULTIHEAD=false" A "ip route show" works as expected. With attached patch, expected behavior is restored: > $ busybox-1.9.0/busybox ip route > 10.10.0.0/16 dev eth0 src 10.10.250.133 > 169.254.0.0/16 dev eth0 metric 1000 > default via 10.10.250.250 dev eth0 ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 01-03-08 12:51 razzor New Issue 01-03-08 12:51 razzor Status new => assigned 01-03-08 12:51 razzor Assigned To => BusyBox 01-03-08 12:51 razzor File Added: busybox-1.9.0-ip.patch ====================================================================== From vda at busybox.net Fri Jan 4 07:10:48 2008 From: vda at busybox.net (vda at busybox.net) Date: Fri, 4 Jan 2008 07:10:48 -0800 (PST) Subject: svn commit: trunk/busybox/init Message-ID: <20080104151048.08D3E1200FD@busybox.net> Author: vda Date: 2008-01-04 07:10:47 -0800 (Fri, 04 Jan 2008) New Revision: 20706 Log: init: wait for orphaned children too while waiting for sysinit-like processes (Harald K?\195?\188the ) Modified: trunk/busybox/init/init.c Changeset: Modified: trunk/busybox/init/init.c =================================================================== --- trunk/busybox/init/init.c 2008-01-03 13:33:30 UTC (rev 20705) +++ trunk/busybox/init/init.c 2008-01-04 15:10:47 UTC (rev 20706) @@ -97,10 +97,16 @@ static void delete_init_action(struct init_action *a); static void halt_reboot_pwoff(int sig) ATTRIBUTE_NORETURN; -/* TODO: move to libbb? */ -static int waitfor(pid_t runpid) +static void waitfor(pid_t pid) { - return safe_waitpid(runpid, NULL, 0); + /* waitfor(run(x)): protect against failed fork inside run() */ + if (pid <= 0) + return; + + /* Wait for any child (prevent zombies from exiting orphaned processes) + * but exit the loop only when specified one has exited. */ + while (wait(NULL) != pid) + continue; } static void loop_forever(void) ATTRIBUTE_NORETURN; From vda at busybox.net Fri Jan 4 07:28:29 2008 From: vda at busybox.net (vda at busybox.net) Date: Fri, 4 Jan 2008 07:28:29 -0800 (PST) Subject: svn commit: trunk/busybox/networking/libiproute Message-ID: <20080104152829.29E0812011A@busybox.net> Author: vda Date: 2008-01-04 07:28:28 -0800 (Fri, 04 Jan 2008) New Revision: 20707 Log: ip route: "ip route" was misbehaving (extra argv+1 ate 1st env var) Modified: trunk/busybox/networking/libiproute/iproute.c Changeset: Modified: trunk/busybox/networking/libiproute/iproute.c =================================================================== --- trunk/busybox/networking/libiproute/iproute.c 2008-01-04 15:10:47 UTC (rev 20706) +++ trunk/busybox/networking/libiproute/iproute.c 2008-01-04 15:28:28 UTC (rev 20707) @@ -841,15 +841,17 @@ /*0-3*/ "add\0""append\0""change\0""chg\0" /*4-7*/ "delete\0""get\0""list\0""show\0" /*8..*/ "prepend\0""replace\0""test\0""flush\0"; - int command_num = 6; + int command_num; unsigned flags = 0; int cmd = RTM_NEWROUTE; + if (!*argv) + return iproute_list_or_flush(argv, 0); + /* "Standard" 'ip r a' treats 'a' as 'add', not 'append' */ /* It probably means that it is using "first match" rule */ - if (*argv) { - command_num = index_in_substrings(ip_route_commands, *argv); - } + command_num = index_in_substrings(ip_route_commands, *argv); + switch (command_num) { case 0: /* add */ flags = NLM_F_CREATE|NLM_F_EXCL; From bugs at busybox.net Fri Jan 4 07:28:45 2008 From: bugs at busybox.net (bugs at busybox.net) Date: Fri, 4 Jan 2008 07:28:45 -0800 Subject: [BusyBox 0001844]: busybox 1.9.0: "ip route" not working Message-ID: <5ef32c129b862fa0e3b6bb37a58b2389@busybox.net> The following issue has been CLOSED ====================================================================== http://busybox.net/bugs/view.php?id=1844 ====================================================================== Reported By: razzor Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1844 Category: Networking Support Reproducibility: always Severity: minor Priority: normal Status: closed Resolution: open Fixed in Version: ====================================================================== Date Submitted: 01-03-2008 12:51 PST Last Modified: 01-04-2008 07:28 PST ====================================================================== Summary: busybox 1.9.0: "ip route" not working Description: The "ip route" command should show the routing table, but parses the environment: > $ busybox-1.9.0/busybox ip route > ip: an inet address is expected rather than "KDE_MULTIHEAD=false" A "ip route show" works as expected. With attached patch, expected behavior is restored: > $ busybox-1.9.0/busybox ip route > 10.10.0.0/16 dev eth0 src 10.10.250.133 > 169.254.0.0/16 dev eth0 metric 1000 > default via 10.10.250.250 dev eth0 ====================================================================== ---------------------------------------------------------------------- vda - 01-04-08 07:28 ---------------------------------------------------------------------- fixed in svn, thanks Issue History Date Modified Username Field Change ====================================================================== 01-03-08 12:51 razzor New Issue 01-03-08 12:51 razzor Status new => assigned 01-03-08 12:51 razzor Assigned To => BusyBox 01-03-08 12:51 razzor File Added: busybox-1.9.0-ip.patch 01-04-08 07:28 vda Status assigned => closed 01-04-08 07:28 vda Note Added: 0003354 ====================================================================== From vda at busybox.net Fri Jan 4 12:10:52 2008 From: vda at busybox.net (vda at busybox.net) Date: Fri, 4 Jan 2008 12:10:52 -0800 (PST) Subject: svn commit: trunk/busybox: applets Message-ID: <20080104201052.1231E120126@busybox.net> Author: vda Date: 2008-01-04 12:10:51 -0800 (Fri, 04 Jan 2008) New Revision: 20709 Log: Makefile.help: removing allbareconfig target from help applet_tables: fix allnoconfig Modified: trunk/busybox/Makefile.help trunk/busybox/applets/applet_tables.c Changeset: Modified: trunk/busybox/Makefile.help =================================================================== --- trunk/busybox/Makefile.help 2008-01-04 20:07:31 UTC (rev 20708) +++ trunk/busybox/Makefile.help 2008-01-04 20:10:51 UTC (rev 20709) @@ -16,7 +16,6 @@ @echo 'Configuration:' @echo ' allnoconfig - disable all symbols in .config' @echo ' allyesconfig - enable all symbols in .config (see defconfig)' - @echo ' allbareconfig - enable all applets without any sub-features' @echo ' config - text based configurator (of last resort)' @echo ' defconfig - set .config to largest generic configuration' @echo ' menuconfig - interactive curses-based configurator' Modified: trunk/busybox/applets/applet_tables.c =================================================================== --- trunk/busybox/applets/applet_tables.c 2008-01-04 20:07:31 UTC (rev 20708) +++ trunk/busybox/applets/applet_tables.c 2008-01-04 20:10:51 UTC (rev 20709) @@ -71,7 +71,7 @@ puts("/* This is a generated file, don't edit */"); - puts("const char applet_names[] ALIGN1 ="); + puts("const char applet_names[] ALIGN1 = \"\" \n"); for (i = 0; i < NUM_APPLETS; i++) { printf("\"%s\" \"\\0\"\n", applets[i].name); } From vda at busybox.net Fri Jan 4 19:26:41 2008 From: vda at busybox.net (vda at busybox.net) Date: Fri, 4 Jan 2008 19:26:41 -0800 (PST) Subject: svn commit: trunk/busybox: applets include libbb procps Message-ID: <20080105032641.7CF3E12C4B3@busybox.net> Author: vda Date: 2008-01-04 19:26:41 -0800 (Fri, 04 Jan 2008) New Revision: 20710 Log: ps: add conditional support for -o [e]time Modified: trunk/busybox/applets/applet_tables.c trunk/busybox/include/libbb.h trunk/busybox/libbb/procps.c trunk/busybox/procps/Config.in trunk/busybox/procps/ps.c Changeset: Modified: trunk/busybox/applets/applet_tables.c =================================================================== --- trunk/busybox/applets/applet_tables.c 2008-01-04 20:10:51 UTC (rev 20709) +++ trunk/busybox/applets/applet_tables.c 2008-01-05 03:26:41 UTC (rev 20710) @@ -71,7 +71,7 @@ puts("/* This is a generated file, don't edit */"); - puts("const char applet_names[] ALIGN1 = \"\" \n"); + puts("const char applet_names[] ALIGN1 = \"\"\n"); for (i = 0; i < NUM_APPLETS; i++) { printf("\"%s\" \"\\0\"\n", applets[i].name); } Modified: trunk/busybox/include/libbb.h =================================================================== --- trunk/busybox/include/libbb.h 2008-01-04 20:10:51 UTC (rev 20709) +++ trunk/busybox/include/libbb.h 2008-01-05 03:26:41 UTC (rev 20710) @@ -990,6 +990,7 @@ * it is memset(0) for each process in procps_scan() */ unsigned long vsz, rss; /* we round it to kbytes */ unsigned long stime, utime; + unsigned long start_time; unsigned pid; unsigned ppid; unsigned pgid; @@ -1032,11 +1033,12 @@ PSSCAN_SMAPS = (1 << 15) * ENABLE_FEATURE_TOPMEM, PSSCAN_ARGVN = (1 << 16) * (ENABLE_PGREP | ENABLE_PKILL), USE_SELINUX(PSSCAN_CONTEXT = 1 << 17,) + PSSCAN_START_TIME = 1 << 18, /* These are all retrieved from proc/NN/stat in one go: */ PSSCAN_STAT = PSSCAN_PPID | PSSCAN_PGID | PSSCAN_SID | PSSCAN_COMM | PSSCAN_STATE | PSSCAN_VSZ | PSSCAN_RSS - | PSSCAN_STIME | PSSCAN_UTIME + | PSSCAN_STIME | PSSCAN_UTIME | PSSCAN_START_TIME | PSSCAN_TTY, }; procps_status_t* alloc_procps_scan(int flags); Modified: trunk/busybox/libbb/procps.c =================================================================== --- trunk/busybox/libbb/procps.c 2008-01-04 20:10:51 UTC (rev 20709) +++ trunk/busybox/libbb/procps.c 2008-01-05 03:26:41 UTC (rev 20710) @@ -243,7 +243,8 @@ "%lu %lu " /* utime, stime */ "%*s %*s %*s " /* cutime, cstime, priority */ "%ld " /* nice */ - "%*s %*s %*s " /* timeout, it_real_value, start_time */ + "%*s %*s " /* timeout, it_real_value */ + "%lu " /* start_time */ "%lu " /* vsize */ "%lu " /* rss */ /* "%lu %lu %lu %lu %lu %lu " rss_rlim, start_code, end_code, start_stack, kstk_esp, kstk_eip */ @@ -254,6 +255,7 @@ &sp->pgid, &sp->sid, &tty, &sp->utime, &sp->stime, &tasknice, + &sp->start_time, &vsz, &rss); if (n != 10) @@ -280,7 +282,8 @@ sp->stime = fast_strtoul_10(&cp); cp = skip_fields(cp, 3); /* cutime, cstime, priority */ tasknice = fast_strtoul_10(&cp); - cp = skip_fields(cp, 3); /* timeout, it_real_value, start_time */ + cp = skip_fields(cp, 2); /* timeout, it_real_value */ + sp->start_time = fast_strtoul_10(&cp); /* vsz is in bytes and we want kb */ sp->vsz = fast_strtoul_10(&cp) >> 10; /* vsz is in bytes but rss is in *PAGES*! Can you believe that? */ Modified: trunk/busybox/procps/Config.in =================================================================== --- trunk/busybox/procps/Config.in 2008-01-04 20:10:51 UTC (rev 20709) +++ trunk/busybox/procps/Config.in 2008-01-05 03:26:41 UTC (rev 20710) @@ -99,6 +99,21 @@ If given once, 132 chars are printed and given more than one, the length is unlimited. +config FEATURE_PS_TIME + bool "Enable time and elapsed time output" + default n + depends on PS && DESKTOP + help + Support -o time and -o etime output specifiers. + +config FEATURE_PS_UNUSUAL_SYSTEMS + bool "Support Linux prior to 2.4.0 and non-ELF systems" + default n + depends on FEATURE_PS_TIME + help + Include support for measuring HZ on old kernels and non-ELF systems + (if you are on Linux 2.4.0+ and use ELF, you don't need this) + config RENICE bool "renice" default n Modified: trunk/busybox/procps/ps.c =================================================================== --- trunk/busybox/procps/ps.c 2008-01-04 20:10:51 UTC (rev 20709) +++ trunk/busybox/procps/ps.c 2008-01-05 03:26:41 UTC (rev 20710) @@ -16,6 +16,143 @@ #if ENABLE_DESKTOP +#include /* for times() */ +//#include /* for sysinfo() */ +#ifndef AT_CLKTCK +#define AT_CLKTCK 17 +#endif + + +#if ENABLE_SELINUX +#define SELINIX_O_PREFIX "label," +#define DEFAULT_O_STR (SELINIX_O_PREFIX "pid,user" USE_FEATURE_PS_TIME(",time")) +#else +#define DEFAULT_O_STR ("pid,user" USE_FEATURE_PS_TIME(",time")) +#endif + +typedef struct { + uint16_t width; + char name[6]; + const char *header; + void (*f)(char *buf, int size, const procps_status_t *ps); + int ps_flags; +} ps_out_t; + +struct globals { + ps_out_t* out; + int out_cnt; + int print_header; + int need_flags; + char *buffer; + unsigned terminal_width; +#if ENABLE_FEATURE_PS_TIME + unsigned kernel_HZ; + unsigned long long seconds_since_boot; +#endif + char default_o[sizeof(DEFAULT_O_STR)]; +}; +#define G (*(struct globals*)&bb_common_bufsiz1) +#define out (G.out ) +#define out_cnt (G.out_cnt ) +#define print_header (G.print_header ) +#define need_flags (G.need_flags ) +#define buffer (G.buffer ) +#define terminal_width (G.terminal_width ) +#define kernel_HZ (G.kernel_HZ ) +#define seconds_since_boot (G.seconds_since_boot) +#define default_o (G.default_o ) + +#if ENABLE_FEATURE_PS_TIME +/* for ELF executables, notes are pushed before environment and args */ +static ptrdiff_t find_elf_note(ptrdiff_t findme) +{ + ptrdiff_t *ep = (ptrdiff_t *) environ; + + while (*ep++); + while (*ep) { + if (ep[0] == findme) { + return ep[1]; + } + ep += 2; + } + return -1; +} + +#if ENABLE_FEATURE_PS_UNUSUAL_SYSTEMS +static unsigned get_HZ_by_waiting(void) +{ + struct timeval tv1, tv2; + unsigned t1, t2, r, hz; + unsigned cnt = cnt; /* for compiler */ + int diff; + + r = 0; + + /* Wait for times() to reach new tick */ + t1 = times(NULL); + do { + t2 = times(NULL); + } while (t2 == t1); + gettimeofday(&tv2, NULL); + + do { + t1 = t2; + tv1.tv_usec = tv2.tv_usec; + + /* Wait exactly one times() tick */ + do { + t2 = times(NULL); + } while (t2 == t1); + gettimeofday(&tv2, NULL); + + /* Calculate ticks per sec, rounding up to even */ + diff = tv2.tv_usec - tv1.tv_usec; + if (diff <= 0) diff += 1000000; + hz = 1000000u / (unsigned)diff; + hz = (hz+1) & ~1; + + /* Count how many same hz values we saw */ + if (r != hz) { + r = hz; + cnt = 0; + } + cnt++; + } while (cnt < 3); /* exit if saw 3 same values */ + + return r; +} +#else +static inline unsigned get_HZ_by_waiting(void) +{ + /* Better method? */ + return 100; +} +#endif + +static unsigned get_kernel_HZ(void) +{ + //char buf[64]; + struct sysinfo info; + + if (kernel_HZ) + return kernel_HZ; + + /* Works for ELF only, Linux 2.4.0+ */ + kernel_HZ = find_elf_note(AT_CLKTCK); + if (kernel_HZ == (unsigned)-1) + kernel_HZ = get_HZ_by_waiting(); + + //if (open_read_close("/proc/uptime", buf, sizeof(buf) <= 0) + // bb_perror_msg_and_die("cannot read %s", "/proc/uptime"); + //buf[sizeof(buf)-1] = '\0'; + ///sscanf(buf, "%llu", &seconds_since_boot); + sysinfo(&info); + seconds_since_boot = info.uptime; + + return kernel_HZ; +} +#endif + /* Print value to buf, max size+1 chars (including trailing '\0') */ static void func_user(char *buf, int size, const procps_status_t *ps) @@ -73,6 +210,34 @@ snprintf(buf, size+1, "%u,%u", ps->tty_major, ps->tty_minor); } +#if ENABLE_FEATURE_PS_TIME +static void func_etime(char *buf, int size, const procps_status_t *ps) +{ + /* elapsed time [[dd-]hh:]mm:ss; here only mm:ss */ + unsigned long mm; + unsigned ss; + + mm = ps->start_time / get_kernel_HZ(); + /* must be after get_kernel_HZ()! */ + mm = seconds_since_boot - mm; + ss = mm % 60; + mm /= 60; + snprintf(buf, size+1, "%3lu:%02u", mm, ss); +} + +static void func_time(char *buf, int size, const procps_status_t *ps) +{ + /* cumulative time [[dd-]hh:]mm:ss; here only mm:ss */ + unsigned long mm; + unsigned ss; + + mm = (ps->utime + ps->stime) / get_kernel_HZ(); + ss = mm % 60; + mm /= 60; + snprintf(buf, size+1, "%3lu:%02u", mm, ss); +} +#endif + #if ENABLE_SELINUX static void func_label(char *buf, int size, const procps_status_t *ps) { @@ -86,29 +251,11 @@ ps->??? } -static void func_etime(char *buf, int size, const procps_status_t *ps) -{ - elapled time [[dd-]hh:]mm:ss -} - -static void func_time(char *buf, int size, const procps_status_t *ps) -{ - cumulative time [[dd-]hh:]mm:ss -} - static void func_pcpu(char *buf, int size, const procps_status_t *ps) { } */ -typedef struct { - uint16_t width; - char name[6]; - const char *header; - void (*f)(char *buf, int size, const procps_status_t *ps); - int ps_flags; -} ps_out_t; - static const ps_out_t out_spec[] = { // Mandated by POSIX: { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, @@ -117,13 +264,17 @@ { 5 , "pid" ,"PID" ,func_pid ,PSSCAN_PID }, { 5 , "ppid" ,"PPID" ,func_ppid ,PSSCAN_PPID }, { 5 , "pgid" ,"PGID" ,func_pgid ,PSSCAN_PGID }, -// { sizeof("ELAPSED")-1, "etime" ,"ELAPSED",func_etime ,PSSCAN_ }, +#if ENABLE_FEATURE_PS_TIME + { sizeof("ELAPSED")-1, "etime" ,"ELAPSED",func_etime ,PSSCAN_START_TIME }, +#endif // { sizeof("GROUP" )-1, "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, // { sizeof("NI" )-1, "nice" ,"NI" ,func_nice ,PSSCAN_ }, // { sizeof("%CPU" )-1, "pcpu" ,"%CPU" ,func_pcpu ,PSSCAN_ }, // { sizeof("RGROUP" )-1, "rgroup","RGROUP" ,func_rgroup,PSSCAN_UIDGID }, // { sizeof("RUSER" )-1, "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID }, -// { sizeof("TIME" )-1, "time" ,"TIME" ,func_time ,PSSCAN_ }, +#if ENABLE_FEATURE_PS_TIME + { 6 , "time" ,"TIME" ,func_time ,PSSCAN_STIME | PSSCAN_UTIME }, +#endif { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, // Not mandated by POSIX, but useful: @@ -133,31 +284,6 @@ #endif }; -#if ENABLE_SELINUX -#define SELINIX_O_PREFIX "label," -#define DEFAULT_O_STR SELINIX_O_PREFIX "pid,user" /* TODO: ,vsz,stat */ ",args" -#else -#define DEFAULT_O_STR "pid,user" /* TODO: ,vsz,stat */ ",args" -#endif - -struct globals { - ps_out_t* out; - int out_cnt; - int print_header; - int need_flags; - char *buffer; - unsigned terminal_width; - char default_o[sizeof(DEFAULT_O_STR)]; -}; -#define G (*(struct globals*)&bb_common_bufsiz1) -#define out (G.out ) -#define out_cnt (G.out_cnt ) -#define print_header (G.print_header ) -#define need_flags (G.need_flags ) -#define buffer (G.buffer ) -#define terminal_width (G.terminal_width) -#define default_o (G.default_o ) - static ps_out_t* new_out_t(void) { int i = out_cnt++; From vda at busybox.net Sat Jan 5 19:26:54 2008 From: vda at busybox.net (vda at busybox.net) Date: Sat, 5 Jan 2008 19:26:54 -0800 (PST) Subject: svn commit: trunk/busybox: include libbb procps Message-ID: <20080106032654.5FE9E12C544@busybox.net> Author: vda Date: 2008-01-05 19:26:53 -0800 (Sat, 05 Jan 2008) New Revision: 20805 Log: ps: fix overflow in USER and VSZ columns function old new delta smart_ulltoa4 - 280 +280 smart_ulltoa5 283 408 +125 ulltoa6_and_space - 25 +25 scale 28 38 +10 bbunpack 358 366 +8 ps_main 259 261 +2 glob3 35 37 +2 fill_bounds 172 174 +2 process_stdin 456 446 -10 smart_ulltoa6 406 - -406 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 6/1 up/down: 454/-416) Total: 38 bytes Modified: trunk/busybox/include/libbb.h trunk/busybox/libbb/xfuncs.c trunk/busybox/procps/nmeter.c trunk/busybox/procps/ps.c trunk/busybox/procps/top.c Changeset: Modified: trunk/busybox/include/libbb.h =================================================================== --- trunk/busybox/include/libbb.h 2008-01-06 00:04:02 UTC (rev 20804) +++ trunk/busybox/include/libbb.h 2008-01-06 03:26:53 UTC (rev 20805) @@ -503,7 +503,9 @@ /* Returns a pointer past the formatted number, does NOT null-terminate */ char *utoa_to_buf(unsigned n, char *buf, unsigned buflen); char *itoa_to_buf(int n, char *buf, unsigned buflen); -void smart_ulltoa5(unsigned long long ul, char buf[5]); +/* Intelligent formatters of bignums */ +void smart_ulltoa4(unsigned long long ul, char buf[5], const char *scale); +void smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale); //TODO: provide pointer to buf (avoid statics)? const char *make_human_readable_str(unsigned long long size, unsigned long block_size, unsigned long display_unit); Modified: trunk/busybox/libbb/xfuncs.c =================================================================== --- trunk/busybox/libbb/xfuncs.c 2008-01-06 00:04:02 UTC (rev 20804) +++ trunk/busybox/libbb/xfuncs.c 2008-01-06 03:26:53 UTC (rev 20805) @@ -282,10 +282,10 @@ bb_error_msg_and_die(bb_msg_memory_exhausted); } -// Converts unsigned long long value into compact 4-char -// representation. Examples: "1234", "1.2k", " 27M", "123T" -// Fifth char is always '\0' -void smart_ulltoa5(unsigned long long ul, char buf[5]) +/* Converts unsigned long long value into compact 4-char + * representation. Examples: "1234", "1.2k", " 27M", "123T" + * String is not terminated (buf[4] is untouched) */ +void smart_ulltoa4(unsigned long long ul, char buf[5], const char *scale) { const char *fmt; char c; @@ -327,13 +327,66 @@ buf[1] = '.'; } buf[2] = "0123456789"[v]; - // see http://en.wikipedia.org/wiki/Tera - // (small letters stand out better versus numbers) - buf[3] = " kmgtpezy"[idx]; + buf[3] = scale[idx]; /* typically scale = " kmgt..." */ } - buf[4] = '\0'; } +/* Converts unsigned long long value into compact 5-char representation. + * String is not terminated (buf[5] is untouched) */ +void smart_ulltoa5(unsigned long long ul, char buf[6], const char *scale) +{ + 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]; + buf[4] = scale[idx]; /* typically scale = " kmgt..." */ + } +} + + // Convert unsigned integer to ascii, writing into supplied buffer. // A truncated result contains the first few digits of the result ala strncpy. // Returns a pointer past last generated digit, does _not_ store NUL. Modified: trunk/busybox/procps/nmeter.c =================================================================== --- trunk/busybox/procps/nmeter.c 2008-01-06 00:04:02 UTC (rev 20804) +++ trunk/busybox/procps/nmeter.c 2008-01-06 03:26:53 UTC (rev 20805) @@ -257,7 +257,10 @@ static void scale(ullong ul) { char buf[5]; - smart_ulltoa5(ul, buf); + + /* see http://en.wikipedia.org/wiki/Tera */ + smart_ulltoa4(ul, buf, " kmgtpezy"); + buf[4] = '\0'; put(buf); } Modified: trunk/busybox/procps/ps.c =================================================================== --- trunk/busybox/procps/ps.c 2008-01-06 00:04:02 UTC (rev 20804) +++ trunk/busybox/procps/ps.c 2008-01-06 03:26:53 UTC (rev 20805) @@ -25,9 +25,9 @@ #if ENABLE_SELINUX #define SELINIX_O_PREFIX "label," -#define DEFAULT_O_STR (SELINIX_O_PREFIX "pid,user" USE_FEATURE_PS_TIME(",time")) +#define DEFAULT_O_STR (SELINIX_O_PREFIX "pid,user" USE_FEATURE_PS_TIME(",time") ",args") #else -#define DEFAULT_O_STR ("pid,user" USE_FEATURE_PS_TIME(",time")) +#define DEFAULT_O_STR ("pid,user" USE_FEATURE_PS_TIME(",time") ",args") #endif typedef struct { @@ -188,7 +188,10 @@ static void put_lu(char *buf, int size, unsigned long u) { char buf5[5]; - smart_ulltoa5( ((unsigned long long)u) << 10, buf5); + + /* see http://en.wikipedia.org/wiki/Tera */ + smart_ulltoa4( (u, buf5, " mgtpezy"); + buf5[5] = '\0'; sprintf(buf, "%.*s", size, buf5); } @@ -505,9 +508,9 @@ #endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */ if (use_selinux) - puts(" PID Context Stat Command"); + puts(" PID CONTEXT STAT COMMAND"); else - puts(" PID Uid VSZ Stat Command"); + puts(" PID USER VSZ STAT COMMAND"); while ((p = procps_scan(p, 0 | PSSCAN_PID @@ -519,7 +522,7 @@ ))) { #if ENABLE_SELINUX if (use_selinux) { - len = printf("%5u %-32s %s ", + len = printf("%5u %-32.32s %s ", p->pid, p->context ? p->context : "unknown", p->state); @@ -527,12 +530,17 @@ #endif { const char *user = get_cached_username(p->uid); - if (p->vsz == 0) - len = printf("%5u %-8s %s ", - p->pid, user, p->state); - else - len = printf("%5u %-8s %6lu %s ", - p->pid, user, p->vsz, p->state); + //if (p->vsz == 0) + // len = printf("%5u %-8.8s %s ", + // p->pid, user, p->state); + //else + { + char buf6[6]; + smart_ulltoa5(p->vsz, buf6, " mgtpezy"); + buf6[5] = '\0'; + len = printf("%5u %-8.8s %s %s ", + p->pid, user, buf6, p->state); + } } { Modified: trunk/busybox/procps/top.c =================================================================== --- trunk/busybox/procps/top.c 2008-01-06 00:04:02 UTC (rev 20804) +++ trunk/busybox/procps/top.c 2008-01-06 03:26:53 UTC (rev 20805) @@ -669,60 +669,10 @@ #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]) +static void ulltoa6_and_space(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]; - } + /* see http://en.wikipedia.org/wiki/Tera */ + smart_ulltoa5(ul, buf, " mgtpezy"); buf[5] = ' '; } @@ -739,14 +689,14 @@ while (--count >= 0) { // PID VSZ VSZRW RSS (SHR) DIRTY (SHR) COMMAND - smart_ulltoa6(s->pid , &line_buf[0*6]); - smart_ulltoa6(s->vsz , &line_buf[1*6]); - smart_ulltoa6(s->vszrw , &line_buf[2*6]); - smart_ulltoa6(s->rss , &line_buf[3*6]); - smart_ulltoa6(s->rss_sh , &line_buf[4*6]); - smart_ulltoa6(s->dirty , &line_buf[5*6]); - smart_ulltoa6(s->dirty_sh, &line_buf[6*6]); - smart_ulltoa6(s->stack , &line_buf[7*6]); + ulltoa6_and_space(s->pid , &line_buf[0*6]); + ulltoa6_and_space(s->vsz , &line_buf[1*6]); + ulltoa6_and_space(s->vszrw , &line_buf[2*6]); + ulltoa6_and_space(s->rss , &line_buf[3*6]); + ulltoa6_and_space(s->rss_sh , &line_buf[4*6]); + ulltoa6_and_space(s->dirty , &line_buf[5*6]); + ulltoa6_and_space(s->dirty_sh, &line_buf[6*6]); + ulltoa6_and_space(s->stack , &line_buf[7*6]); line_buf[8*6] = '\0'; if (scr_width > MIN_WIDTH) { read_cmdline(&line_buf[8*6], scr_width - MIN_WIDTH, s->pid, s->comm); From vda at busybox.net Sat Jan 5 22:27:18 2008 From: vda at busybox.net (vda at busybox.net) Date: Sat, 5 Jan 2008 22:27:18 -0800 (PST) Subject: svn commit: trunk/busybox: coreutils docs include Message-ID: <20080106062718.75AE412C58A@busybox.net> Author: vda Date: 2008-01-05 22:27:17 -0800 (Sat, 05 Jan 2008) New Revision: 20806 Log: tac: new applet. ~240 bytes. Copyright (C) 2003 Yang Xiaopeng Copyright (C) 2007 Natanael Copa Copyright (C) 2007 Tito Ragusa Modified: trunk/busybox/coreutils/Config.in trunk/busybox/coreutils/Kbuild trunk/busybox/docs/nofork_noexec.txt trunk/busybox/include/applets.h trunk/busybox/include/usage.h Changeset: Modified: trunk/busybox/coreutils/Config.in =================================================================== --- trunk/busybox/coreutils/Config.in 2008-01-06 03:26:53 UTC (rev 20805) +++ trunk/busybox/coreutils/Config.in 2008-01-06 06:27:17 UTC (rev 20806) @@ -579,6 +579,12 @@ help sync is used to flush filesystem buffers. +config TAC + bool "tac" + default n + help + tac is used to concatenate and print files in reverse. + config TAIL bool "tail" default n Modified: trunk/busybox/coreutils/Kbuild =================================================================== --- trunk/busybox/coreutils/Kbuild 2008-01-06 03:26:53 UTC (rev 20805) +++ trunk/busybox/coreutils/Kbuild 2008-01-06 06:27:17 UTC (rev 20806) @@ -66,6 +66,7 @@ lib-$(CONFIG_STTY) += stty.o lib-$(CONFIG_SUM) += sum.o lib-$(CONFIG_SYNC) += sync.o +lib-$(CONFIG_TAC) += tac.o lib-$(CONFIG_TAIL) += tail.o lib-$(CONFIG_TEE) += tee.o lib-$(CONFIG_TEST) += test.o Modified: trunk/busybox/docs/nofork_noexec.txt =================================================================== --- trunk/busybox/docs/nofork_noexec.txt 2008-01-06 03:26:53 UTC (rev 20805) +++ trunk/busybox/docs/nofork_noexec.txt 2008-01-06 06:27:17 UTC (rev 20806) @@ -2,7 +2,7 @@ Unix shells traditionally execute some commands internally in the attempt to dramatically speed up execution. It will be slow as hell if for every -"echo blah" shell will fork and exec /bin/echo. For this end, shells +"echo blah" shell will fork and exec /bin/echo. To this end, shells have to _reimplement_ these commands internally. Busybox is unique in this regard because it already is a collection @@ -11,15 +11,21 @@ are exactly those applets which are eligible for these tricks. Applet will be subject to NOFORK/NOEXEC tricks if it is marked as such -in applets.h. CONFIG_FEATURE_PREFER_APPLETS is a config option which +in applets.h. FEATURE_PREFER_APPLETS is a config option which globally enables usage of NOFORK/NOEXEC tricks. +If it is enabled, FEATURE_SH_STANDALONE can be enabled too, +and then shells will use NOFORK/NOEXEC tricks for ordinary commands. +NB: shell builtins use these tricks regardless of FEATURE_SH_STANDALONE +or FEATURE_PREFER_APPLETS. -If you want to call a program and wait for it, use spawn_and_wait(argv). -It will check whether argv[0] is an applet name and will optionally -do NOFORK/NOEXEC thing. +In C, if you want to call a program and wait for it, use +spawn_and_wait(argv), BB_EXECVP(prog,argv) or BB_EXECLP(prog,argv0,...). +They check whether program name is an applet name and optionally +do NOFORK/NOEXEC thing depending on configuration. -NOEXEC + NOEXEC + NOEXEC applet should work correctly if another applet forks and then executes exit(_main(argc,argv)) in the child. The rules roughly are: @@ -32,10 +38,11 @@ * ... NOEXEC applets save only one half of fork+exec overhead. -NOEXEC trick is disabled for NOMMU compile. +NOEXEC trick is disabled for NOMMU build. -NOFORK + NOFORK + NOFORK applet should work correctly if another applet simply runs _main(argc,argv) and then continues with its business (xargs, find, shells can do it). This poses much more serious limitations @@ -55,6 +62,8 @@ * if you allocate memory, you can use xmalloc() only on the very first allocation. All other allocations should use malloc[_or_warn](). After first allocation, you cannot use any xfuncs. + Otherwise, failing xfunc will return to caller applet + without freeing malloced data! * All allocated data, opened files, signal handlers, termios settings, O_NONBLOCK flags etc should be freed/closed/restored prior to return. * ... Modified: trunk/busybox/include/applets.h =================================================================== --- trunk/busybox/include/applets.h 2008-01-06 03:26:53 UTC (rev 20805) +++ trunk/busybox/include/applets.h 2008-01-06 06:27:17 UTC (rev 20806) @@ -334,6 +334,7 @@ USE_SYNC(APPLET_NOFORK(sync, sync, _BB_DIR_BIN, _BB_SUID_NEVER, sync)) USE_BB_SYSCTL(APPLET(sysctl, _BB_DIR_SBIN, _BB_SUID_NEVER)) USE_SYSLOGD(APPLET(syslogd, _BB_DIR_SBIN, _BB_SUID_NEVER)) +USE_TAC(APPLET_NOEXEC(tac, tac, _BB_DIR_USR_BIN, _BB_SUID_NEVER, tac)) USE_TAIL(APPLET(tail, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) USE_TAR(APPLET(tar, _BB_DIR_BIN, _BB_SUID_NEVER)) USE_TASKSET(APPLET(taskset, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) Modified: trunk/busybox/include/usage.h =================================================================== --- trunk/busybox/include/usage.h 2008-01-06 03:26:53 UTC (rev 20805) +++ trunk/busybox/include/usage.h 2008-01-06 06:27:17 UTC (rev 20806) @@ -3542,6 +3542,11 @@ "$ syslogd -R masterlog:514\n" \ "$ syslogd -R 192.168.1.1:601\n" +#define tac_trivial_usage \ + "[FILE]..." +#define tac_full_usage \ + "Concatenates FILE(s) and prints them to stdout in reverse" + #define tail_trivial_usage \ "[OPTION]... [FILE]..." #define tail_full_usage \ From vda at busybox.net Mon Jan 7 07:58:03 2008 From: vda at busybox.net (vda at busybox.net) Date: Mon, 7 Jan 2008 07:58:03 -0800 (PST) Subject: svn commit: trunk/busybox/sysklogd Message-ID: <20080107155803.3E90612C5F2@busybox.net> Author: vda Date: 2008-01-07 07:58:02 -0800 (Mon, 07 Jan 2008) New Revision: 20807 Log: syslogd: fix shmat error check Modified: trunk/busybox/sysklogd/syslogd.c Changeset: Modified: trunk/busybox/sysklogd/syslogd.c =================================================================== --- trunk/busybox/sysklogd/syslogd.c 2008-01-06 06:27:17 UTC (rev 20806) +++ trunk/busybox/sysklogd/syslogd.c 2008-01-07 15:58:02 UTC (rev 20807) @@ -218,7 +218,7 @@ } G.shbuf = shmat(G.shmid, NULL, 0); - if (!G.shbuf) { + if (G.shbuf == (void*) -1L) { /* shmat has bizarre error return */ bb_perror_msg_and_die("shmat"); } From vda at busybox.net Mon Jan 7 08:13:15 2008 From: vda at busybox.net (vda at busybox.net) Date: Mon, 7 Jan 2008 08:13:15 -0800 (PST) Subject: svn commit: trunk/busybox: libbb miscutils networking procps Message-ID: <20080107161315.265FA12C5FC@busybox.net> Author: vda Date: 2008-01-07 08:13:14 -0800 (Mon, 07 Jan 2008) New Revision: 20808 Log: ps: fix build breakage from vda's recent commit *: whitespace fixes Modified: trunk/busybox/libbb/compare_string_array.c trunk/busybox/libbb/lineedit.c trunk/busybox/libbb/xfuncs.c trunk/busybox/miscutils/hdparm.c trunk/busybox/networking/nameif.c trunk/busybox/networking/ping.c trunk/busybox/networking/wget.c trunk/busybox/procps/pgrep.c trunk/busybox/procps/ps.c Changeset: Modified: trunk/busybox/libbb/compare_string_array.c =================================================================== --- trunk/busybox/libbb/compare_string_array.c 2008-01-07 15:58:02 UTC (rev 20807) +++ trunk/busybox/libbb/compare_string_array.c 2008-01-07 16:13:14 UTC (rev 20808) @@ -70,9 +70,9 @@ const char *nth_string(const char *strings, int n) { - while (n) { - n--; - strings += strlen(strings) + 1; - } - return strings; + while (n) { + n--; + strings += strlen(strings) + 1; + } + return strings; } Modified: trunk/busybox/libbb/lineedit.c =================================================================== --- trunk/busybox/libbb/lineedit.c 2008-01-07 15:58:02 UTC (rev 20807) +++ trunk/busybox/libbb/lineedit.c 2008-01-07 16:13:14 UTC (rev 20808) @@ -65,7 +65,7 @@ enum { /* We use int16_t for positions, need to limit line len */ MAX_LINELEN = CONFIG_FEATURE_EDITING_MAX_LEN < 0x7ff0 - ? CONFIG_FEATURE_EDITING_MAX_LEN + ? CONFIG_FEATURE_EDITING_MAX_LEN : 0x7ff0 }; Modified: trunk/busybox/libbb/xfuncs.c =================================================================== --- trunk/busybox/libbb/xfuncs.c 2008-01-07 15:58:02 UTC (rev 20807) +++ trunk/busybox/libbb/xfuncs.c 2008-01-07 16:13:14 UTC (rev 20808) @@ -166,7 +166,7 @@ int close_on_exec_on(int fd) { - return fcntl(fd, F_SETFD, FD_CLOEXEC); + return fcntl(fd, F_SETFD, FD_CLOEXEC); } int ndelay_off(int fd) Modified: trunk/busybox/miscutils/hdparm.c =================================================================== --- trunk/busybox/miscutils/hdparm.c 2008-01-07 15:58:02 UTC (rev 20807) +++ trunk/busybox/miscutils/hdparm.c 2008-01-07 16:13:14 UTC (rev 20808) @@ -1155,10 +1155,10 @@ #if ENABLE_FEATURE_HDPARM_GET_IDENTITY static const char cfg_str[] ALIGN1 = - """\0" "HardSect""\0" "SoftSect""\0" "NotMFM""\0" - "HdSw>15uSec""\0" "SpinMotCtl""\0" "Fixed""\0" "Removeable""\0" - "DTR<=5Mbs""\0" "DTR>5Mbs""\0" "DTR>10Mbs""\0" "RotSpdTol>.5%""\0" - "dStbOff""\0" "TrkOff""\0" "FmtGapReq""\0" "nonMagnetic" + """\0" "HardSect""\0" "SoftSect""\0" "NotMFM""\0" + "HdSw>15uSec""\0" "SpinMotCtl""\0" "Fixed""\0" "Removeable""\0" + "DTR<=5Mbs""\0" "DTR>5Mbs""\0" "DTR>10Mbs""\0" "RotSpdTol>.5%""\0" + "dStbOff""\0" "TrkOff""\0" "FmtGapReq""\0" "nonMagnetic" ; static const char BuffType[] ALIGN1 = Modified: trunk/busybox/networking/nameif.c =================================================================== --- trunk/busybox/networking/nameif.c 2008-01-07 15:58:02 UTC (rev 20807) +++ trunk/busybox/networking/nameif.c 2008-01-07 16:13:14 UTC (rev 20808) @@ -55,7 +55,7 @@ char version[32]; /* driver version string */ char fw_version[32]; /* firmware version string, if applicable */ char bus_info[ETHTOOL_BUSINFO_LEN]; /* Bus info for this IF. */ - /* For PCI devices, use pci_dev->slot_name. */ + /* For PCI devices, use pci_dev->slot_name. */ char reserved1[32]; char reserved2[16]; uint32_t n_stats; /* number of u64's from ETHTOOL_GSTATS */ Modified: trunk/busybox/networking/ping.c =================================================================== --- trunk/busybox/networking/ping.c 2008-01-07 15:58:02 UTC (rev 20807) +++ trunk/busybox/networking/ping.c 2008-01-07 16:13:14 UTC (rev 20808) @@ -277,8 +277,8 @@ #define rcvd_tbl (G.rcvd_tbl ) void BUG_ping_globals_too_big(void); #define INIT_G() do { \ - if (sizeof(G) > COMMON_BUFSIZE) \ - BUG_ping_globals_too_big(); \ + if (sizeof(G) > COMMON_BUFSIZE) \ + BUG_ping_globals_too_big(); \ pingsock = -1; \ tmin = UINT_MAX; \ } while (0) Modified: trunk/busybox/networking/wget.c =================================================================== --- trunk/busybox/networking/wget.c 2008-01-07 15:58:02 UTC (rev 20807) +++ trunk/busybox/networking/wget.c 2008-01-07 16:13:14 UTC (rev 20808) @@ -36,7 +36,7 @@ }; #define G (*(struct globals*)&bb_common_bufsiz1) struct BUG_G_too_big { - char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; + char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; }; #define content_len (G.content_len ) #define beg_range (G.beg_range ) Modified: trunk/busybox/procps/pgrep.c =================================================================== --- trunk/busybox/procps/pgrep.c 2008-01-07 15:58:02 UTC (rev 20807) +++ trunk/busybox/procps/pgrep.c 2008-01-07 16:13:14 UTC (rev 20808) @@ -116,7 +116,7 @@ cmd = proc->comm; /* NB: OPT_INVERT is always 0 or 1 */ if ((regexec(&re_buffer, cmd, 1, re_match, 0) == 0 /* match found */ - && (!OPT_ANCHOR || (re_match[0].rm_so == 0 && re_match[0].rm_eo == strlen(cmd)))) ^ OPT_INVERT + && (!OPT_ANCHOR || (re_match[0].rm_so == 0 && re_match[0].rm_eo == strlen(cmd)))) ^ OPT_INVERT ) { matched_pid = proc->pid; if (OPT_LAST) { Modified: trunk/busybox/procps/ps.c =================================================================== --- trunk/busybox/procps/ps.c 2008-01-07 15:58:02 UTC (rev 20807) +++ trunk/busybox/procps/ps.c 2008-01-07 16:13:14 UTC (rev 20808) @@ -66,60 +66,60 @@ /* for ELF executables, notes are pushed before environment and args */ static ptrdiff_t find_elf_note(ptrdiff_t findme) { - ptrdiff_t *ep = (ptrdiff_t *) environ; + ptrdiff_t *ep = (ptrdiff_t *) environ; - while (*ep++); - while (*ep) { - if (ep[0] == findme) { - return ep[1]; - } - ep += 2; - } - return -1; + while (*ep++); + while (*ep) { + if (ep[0] == findme) { + return ep[1]; + } + ep += 2; + } + return -1; } #if ENABLE_FEATURE_PS_UNUSUAL_SYSTEMS static unsigned get_HZ_by_waiting(void) { - struct timeval tv1, tv2; - unsigned t1, t2, r, hz; - unsigned cnt = cnt; /* for compiler */ - int diff; + struct timeval tv1, tv2; + unsigned t1, t2, r, hz; + unsigned cnt = cnt; /* for compiler */ + int diff; - r = 0; + r = 0; - /* Wait for times() to reach new tick */ - t1 = times(NULL); - do { - t2 = times(NULL); - } while (t2 == t1); - gettimeofday(&tv2, NULL); + /* Wait for times() to reach new tick */ + t1 = times(NULL); + do { + t2 = times(NULL); + } while (t2 == t1); + gettimeofday(&tv2, NULL); - do { - t1 = t2; - tv1.tv_usec = tv2.tv_usec; + do { + t1 = t2; + tv1.tv_usec = tv2.tv_usec; - /* Wait exactly one times() tick */ - do { - t2 = times(NULL); - } while (t2 == t1); - gettimeofday(&tv2, NULL); + /* Wait exactly one times() tick */ + do { + t2 = times(NULL); + } while (t2 == t1); + gettimeofday(&tv2, NULL); - /* Calculate ticks per sec, rounding up to even */ - diff = tv2.tv_usec - tv1.tv_usec; - if (diff <= 0) diff += 1000000; - hz = 1000000u / (unsigned)diff; - hz = (hz+1) & ~1; + /* Calculate ticks per sec, rounding up to even */ + diff = tv2.tv_usec - tv1.tv_usec; + if (diff <= 0) diff += 1000000; + hz = 1000000u / (unsigned)diff; + hz = (hz+1) & ~1; /* Count how many same hz values we saw */ - if (r != hz) { - r = hz; - cnt = 0; - } - cnt++; - } while (cnt < 3); /* exit if saw 3 same values */ + if (r != hz) { + r = hz; + cnt = 0; + } + cnt++; + } while (cnt < 3); /* exit if saw 3 same values */ - return r; + return r; } #else static inline unsigned get_HZ_by_waiting(void) @@ -190,7 +190,7 @@ char buf5[5]; /* see http://en.wikipedia.org/wiki/Tera */ - smart_ulltoa4( (u, buf5, " mgtpezy"); + smart_ulltoa4(u, buf5, " mgtpezy"); buf5[5] = '\0'; sprintf(buf, "%.*s", size, buf5); } From vda at busybox.net Mon Jan 7 08:14:14 2008 From: vda at busybox.net (vda at busybox.net) Date: Mon, 7 Jan 2008 08:14:14 -0800 (PST) Subject: svn commit: trunk/busybox/coreutils Message-ID: <20080107161414.7574C12C601@busybox.net> Author: vda Date: 2008-01-07 08:14:14 -0800 (Mon, 07 Jan 2008) New Revision: 20809 Log: tac: *really* add tac.c now Added: trunk/busybox/coreutils/tac.c Changeset: Added: trunk/busybox/coreutils/tac.c =================================================================== --- trunk/busybox/coreutils/tac.c (rev 0) +++ trunk/busybox/coreutils/tac.c 2008-01-07 16:14:14 UTC (rev 20809) @@ -0,0 +1,68 @@ +/* vi: set sw=4 ts=4: */ +/* + * tac implementation for busybox + * + * Copyright (C) 2003 Yang Xiaopeng + * Copyright (C) 2007 Natanael Copa + * Copyright (C) 2007 Tito Ragusa + * + * Licensed under GPLv2, see file License in this tarball for details. + * + */ + +/* tac - concatenate and print files in reverse */ + +/* Based on Yang Xiaopeng's (yxp at hanwang.com.cn) patch + * http://www.uclibc.org/lists/busybox/2003-July/008813.html + */ + +#include "libbb.h" + +/* This is a NOEXEC applet. Be very careful! */ + +int tac_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int tac_main(int argc, char **argv) +{ + char **name; + FILE *f; + char *line; + llist_t *list = NULL; + int retval = EXIT_SUCCESS; + + argv++; + if (!*argv) + *--argv = (char *)"-"; + /* We will read from last file to first */ + name = argv; + while (*name) + name++; + + do { + name--; + f = fopen_or_warn_stdin(*name); + if (f == NULL) { + retval = EXIT_FAILURE; + continue; + } + + errno = 0; + /* FIXME: NUL bytes are mishandled. */ + while ((line = xmalloc_fgets(f)) != NULL) + llist_add_to(&list, line); + + /* xmalloc_fgets uses getc and returns NULL on error or EOF. */ + /* It sets errno to ENOENT on EOF, but fopen_or_warn_stdin would */ + /* catch this error so we can filter it out here. */ + if (errno && errno != ENOENT) { + bb_simple_perror_msg(*name); + retval = EXIT_FAILURE; + } + } while (name != argv); + + while (list) { + printf("%s", list->data); + list = list->link; + } + + return retval; +} From vda at busybox.net Mon Jan 7 08:41:41 2008 From: vda at busybox.net (vda at busybox.net) Date: Mon, 7 Jan 2008 08:41:41 -0800 (PST) Subject: svn commit: trunk/busybox/procps Message-ID: <20080107164141.7789E12C619@busybox.net> Author: vda Date: 2008-01-07 08:41:41 -0800 (Mon, 07 Jan 2008) New Revision: 20810 Log: ps: fix COMMAND column adjustment Modified: trunk/busybox/procps/ps.c Changeset: Modified: trunk/busybox/procps/ps.c =================================================================== --- trunk/busybox/procps/ps.c 2008-01-07 16:14:14 UTC (rev 20809) +++ trunk/busybox/procps/ps.c 2008-01-07 16:41:41 UTC (rev 20810) @@ -522,7 +522,7 @@ ))) { #if ENABLE_SELINUX if (use_selinux) { - len = printf("%5u %-32.32s %s ", + len = printf("%5u %-32.32s %s ", p->pid, p->context ? p->context : "unknown", p->state); @@ -538,7 +538,7 @@ char buf6[6]; smart_ulltoa5(p->vsz, buf6, " mgtpezy"); buf6[5] = '\0'; - len = printf("%5u %-8.8s %s %s ", + len = printf("%5u %-8.8s %s %s ", p->pid, user, buf6, p->state); } } From vda at busybox.net Mon Jan 7 08:51:25 2008 From: vda at busybox.net (vda at busybox.net) Date: Mon, 7 Jan 2008 08:51:25 -0800 (PST) Subject: svn commit: trunk/busybox/procps Message-ID: <20080107165125.C9B4212C60C@busybox.net> Author: vda Date: 2008-01-07 08:51:25 -0800 (Mon, 07 Jan 2008) New Revision: 20811 Log: ps: fix yet another buglet from recent ulltoa conversion :( Modified: trunk/busybox/procps/ps.c Changeset: Modified: trunk/busybox/procps/ps.c =================================================================== --- trunk/busybox/procps/ps.c 2008-01-07 16:41:41 UTC (rev 20810) +++ trunk/busybox/procps/ps.c 2008-01-07 16:51:25 UTC (rev 20811) @@ -187,12 +187,12 @@ static void put_lu(char *buf, int size, unsigned long u) { - char buf5[5]; + char buf4[5]; /* see http://en.wikipedia.org/wiki/Tera */ - smart_ulltoa4(u, buf5, " mgtpezy"); - buf5[5] = '\0'; - sprintf(buf, "%.*s", size, buf5); + smart_ulltoa4(u, buf4, " mgtpezy"); + buf4[4] = '\0'; + sprintf(buf, "%.*s", size, buf4); } static void func_vsz(char *buf, int size, const procps_status_t *ps) From vda at busybox.net Mon Jan 7 11:06:47 2008 From: vda at busybox.net (vda at busybox.net) Date: Mon, 7 Jan 2008 11:06:47 -0800 (PST) Subject: svn commit: trunk/busybox: coreutils init networking Message-ID: <20080107190647.CCCF7120103@busybox.net> Author: vda Date: 2008-01-07 11:06:47 -0800 (Mon, 07 Jan 2008) New Revision: 20812 Log: whitespace fixes Modified: trunk/busybox/coreutils/tac.c trunk/busybox/init/Config.in trunk/busybox/networking/netstat.c Changeset: Modified: trunk/busybox/coreutils/tac.c =================================================================== --- trunk/busybox/coreutils/tac.c 2008-01-07 16:51:25 UTC (rev 20811) +++ trunk/busybox/coreutils/tac.c 2008-01-07 19:06:47 UTC (rev 20812) @@ -28,7 +28,7 @@ char *line; llist_t *list = NULL; int retval = EXIT_SUCCESS; - + argv++; if (!*argv) *--argv = (char *)"-"; @@ -48,7 +48,7 @@ errno = 0; /* FIXME: NUL bytes are mishandled. */ while ((line = xmalloc_fgets(f)) != NULL) - llist_add_to(&list, line); + llist_add_to(&list, line); /* xmalloc_fgets uses getc and returns NULL on error or EOF. */ /* It sets errno to ENOENT on EOF, but fopen_or_warn_stdin would */ @@ -63,6 +63,6 @@ printf("%s", list->data); list = list->link; } - + return retval; } Modified: trunk/busybox/init/Config.in =================================================================== --- trunk/busybox/init/Config.in 2008-01-07 16:51:25 UTC (rev 20811) +++ trunk/busybox/init/Config.in 2008-01-07 19:06:47 UTC (rev 20812) @@ -32,8 +32,8 @@ default y depends on FEATURE_USE_INITTAB help - When respawn entries are removed from inittab and a SIGHUP is - sent to init, this feature will kill the processes that have + When respawn entries are removed from inittab and a SIGHUP is + sent to init, this feature will kill the processes that have been removed. config FEATURE_KILL_DELAY Modified: trunk/busybox/networking/netstat.c =================================================================== --- trunk/busybox/networking/netstat.c 2008-01-07 16:51:25 UTC (rev 20811) +++ trunk/busybox/networking/netstat.c 2008-01-07 19:06:47 UTC (rev 20812) @@ -353,7 +353,7 @@ return 0; /* skip header */ /* 2.6.15 may report lines like "... @/tmp/fam-user-^@^@^@^@^@^@^@..." - * Other users report long lines filled by NUL bytes. + * Other users report long lines filled by NUL bytes. * (those ^@ are NUL bytes too). We see them as empty lines. */ if (!line[0]) return 0; From vda at busybox.net Tue Jan 8 12:32:13 2008 From: vda at busybox.net (vda at busybox.net) Date: Tue, 8 Jan 2008 12:32:13 -0800 (PST) Subject: svn commit: trunk/busybox: include shell Message-ID: <20080108203213.6BD9912C591@busybox.net> Author: vda Date: 2008-01-08 12:32:12 -0800 (Tue, 08 Jan 2008) New Revision: 20826 Log: hush: report [v]fork failures hush: more correct handling of piping config: add CONFIG_NOMMU Modified: trunk/busybox/Config.in trunk/busybox/TODO_config_nommu trunk/busybox/include/platform.h trunk/busybox/shell/hush.c Changeset: Modified: trunk/busybox/Config.in =================================================================== --- trunk/busybox/Config.in 2008-01-08 19:23:54 UTC (rev 20825) +++ trunk/busybox/Config.in 2008-01-08 20:32:12 UTC (rev 20826) @@ -280,6 +280,17 @@ Most people will leave this set to 'N'. +config NOMMU + bool "Force NOMMU build" + default n + help + Busybox tries to detect whether architecture it is being + built against supports MMU or not. If this detection fails, + or if you want to build NOMMU version of busybox for testing, + you may force NOMMU build here. + + Most people will leave this set to 'N'. + config BUILD_LIBBUSYBOX bool "Build shared libbusybox" default n Modified: trunk/busybox/TODO_config_nommu =================================================================== --- trunk/busybox/TODO_config_nommu 2008-01-08 19:23:54 UTC (rev 20825) +++ trunk/busybox/TODO_config_nommu 2008-01-08 20:32:12 UTC (rev 20826) @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit -# Busybox version: 1.9.0.svn -# Mon Dec 24 14:21:28 2007 +# Busybox version: 1.10.0.svn +# Tue Jan 8 20:29:22 2008 # CONFIG_HAVE_DOT_CONFIG=y @@ -39,6 +39,7 @@ # Build Options # # CONFIG_STATIC is not set +CONFIG_NOMMU=y # CONFIG_BUILD_LIBBUSYBOX is not set # CONFIG_FEATURE_INDIVIDUAL is not set # CONFIG_FEATURE_SHARED_BUSYBOX is not set @@ -222,6 +223,7 @@ CONFIG_STTY=y CONFIG_SUM=y CONFIG_SYNC=y +CONFIG_TAC=y CONFIG_TAIL=y CONFIG_FEATURE_FANCY_TAIL=y CONFIG_TEE=y @@ -368,6 +370,8 @@ # CONFIG_INIT is not set # CONFIG_DEBUG_INIT is not set # CONFIG_FEATURE_USE_INITTAB is not set +# CONFIG_FEATURE_KILL_REMOVED is not set +CONFIG_FEATURE_KILL_DELAY=0 # CONFIG_FEATURE_INIT_SCTTY is not set # CONFIG_FEATURE_INIT_SYSLOG is not set # CONFIG_FEATURE_EXTRA_QUIET is not set @@ -679,6 +683,8 @@ CONFIG_PKILL=y CONFIG_PS=y CONFIG_FEATURE_PS_WIDE=y +CONFIG_FEATURE_PS_TIME=y +# CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS is not set CONFIG_RENICE=y CONFIG_BB_SYSCTL=y CONFIG_TOP=y @@ -713,7 +719,7 @@ # CONFIG_ASH_EXPAND_PRMT is not set CONFIG_HUSH=y CONFIG_HUSH_HELP=y -# CONFIG_HUSH_INTERACTIVE is not set +CONFIG_HUSH_INTERACTIVE=y # CONFIG_HUSH_JOB is not set CONFIG_HUSH_TICK=y CONFIG_HUSH_IF=y Modified: trunk/busybox/include/platform.h =================================================================== --- trunk/busybox/include/platform.h 2008-01-08 19:23:54 UTC (rev 20825) +++ trunk/busybox/include/platform.h 2008-01-08 20:32:12 UTC (rev 20826) @@ -231,8 +231,9 @@ * for a mmu-less system; the user should pass EXTRA_CFLAGS="-DBB_NOMMU" * on his own. */ -#if defined __UCLIBC__ && __UCLIBC_MAJOR__ >= 0 && __UCLIBC_MINOR__ >= 9 && \ - __UCLIBC_SUBLEVEL__ > 28 && !defined __ARCH_USE_MMU__ +#if ENABLE_NOMMU || \ + (defined __UCLIBC__ && __UCLIBC_MAJOR__ >= 0 && __UCLIBC_MINOR__ >= 9 && \ + __UCLIBC_SUBLEVEL__ > 28 && !defined __ARCH_USE_MMU__) #define BB_MMU 0 #define BB_NOMMU 1 #define USE_FOR_NOMMU(...) __VA_ARGS__ Modified: trunk/busybox/shell/hush.c =================================================================== --- trunk/busybox/shell/hush.c 2008-01-08 19:23:54 UTC (rev 20825) +++ trunk/busybox/shell/hush.c 2008-01-08 20:32:12 UTC (rev 20826) @@ -1777,8 +1777,8 @@ static int run_pipe_real(struct pipe *pi) { int i; - int nextin, nextout; - int pipefds[2]; /* pipefds[0] is for reading */ + int nextin; + int pipefds[2]; /* pipefds[0] is for reading */ struct child_prog *child; const struct built_in_command *x; char *p; @@ -1789,7 +1789,6 @@ debug_printf_exec("run_pipe_real start: single_fg=%d\n", single_fg); - nextin = 0; #if ENABLE_HUSH_JOB pi->pgrp = -1; #endif @@ -1874,13 +1873,14 @@ #endif } - /* Going to fork a child per each pipe member */ - pi->running_progs = 0; - /* Disable job control signals for shell (parent) and * for initial child code after fork */ set_jobctrl_sighandler(SIG_IGN); + /* Going to fork a child per each pipe member */ + pi->running_progs = 0; + nextin = 0; + for (i = 0; i < pi->num_progs; i++) { child = &(pi->progs[i]); if (child->argv) @@ -1889,24 +1889,20 @@ debug_printf_exec(": pipe member with no argv\n"); /* pipes are inserted between pairs of commands */ - if ((i + 1) < pi->num_progs) { - pipe(pipefds); - nextout = pipefds[1]; - } else { - nextout = 1; - pipefds[0] = -1; - } + pipefds[0] = 0; + pipefds[1] = 1; + if ((i + 1) < pi->num_progs) + xpipe(pipefds); - /* XXX test for failed fork()? */ #if BB_MMU child->pid = fork(); #else child->pid = vfork(); #endif if (!child->pid) { /* child */ +#if ENABLE_HUSH_JOB /* Every child adds itself to new process group * with pgid == pid of first child in pipe */ -#if ENABLE_HUSH_JOB if (run_list_level == 1 && interactive_fd) { /* Don't do pgrp restore anymore on fatal signals */ set_fatal_sighandler(SIG_DFL); @@ -1919,12 +1915,10 @@ } } #endif - /* in non-interactive case fatal sigs are already SIG_DFL */ xmove_fd(nextin, 0); - xmove_fd(nextout, 1); - if (pipefds[0] != -1) { - close(pipefds[0]); /* opposite end of our output pipe */ - } + xmove_fd(pipefds[1], 1); /* write end */ + if (pipefds[0] > 1) + close(pipefds[0]); /* read end */ /* Like bash, explicit redirects override pipes, * and the pipe fd is available for dup'ing. */ setup_redirects(child, NULL); @@ -1933,25 +1927,29 @@ set_jobctrl_sighandler(SIG_DFL); set_misc_sighandler(SIG_DFL); signal(SIGCHLD, SIG_DFL); - pseudo_exec(child); + pseudo_exec(child); /* does not return */ } - pi->running_progs++; - + if (child->pid < 0) { /* [v]fork failed */ + /* Clearly indicate, was it fork or vfork */ + bb_perror_msg(BB_MMU ? "cannot fork" : "cannot vfork"); + } else { + pi->running_progs++; #if ENABLE_HUSH_JOB - /* Second and next children need to know pid of first one */ - if (pi->pgrp < 0) - pi->pgrp = child->pid; + /* Second and next children need to know pid of first one */ + if (pi->pgrp < 0) + pi->pgrp = child->pid; #endif - if (nextin != 0) - close(nextin); - if (nextout != 1) - close(nextout); + } - /* If there isn't another process, nextin is garbage - but it doesn't matter */ + if (i) + close(nextin); + if ((i + 1) < pi->num_progs) + close(pipefds[1]); /* write end */ + /* Pass read (output) pipe end to next iteration */ nextin = pipefds[0]; } + debug_printf_exec("run_pipe_real return -1\n"); return -1; } From vda at busybox.net Wed Jan 9 15:00:02 2008 From: vda at busybox.net (vda at busybox.net) Date: Wed, 9 Jan 2008 15:00:02 -0800 (PST) Subject: svn commit: trunk/busybox/coreutils Message-ID: <20080109230002.9B98F12C540@busybox.net> Author: vda Date: 2008-01-09 15:00:00 -0800 (Wed, 09 Jan 2008) New Revision: 20836 Log: tac: handle NULs properly. +145 bytes Modified: trunk/busybox/coreutils/tac.c Changeset: Modified: trunk/busybox/coreutils/tac.c =================================================================== --- trunk/busybox/coreutils/tac.c 2008-01-09 17:13:57 UTC (rev 20835) +++ trunk/busybox/coreutils/tac.c 2008-01-09 23:00:00 UTC (rev 20836) @@ -20,12 +20,17 @@ /* This is a NOEXEC applet. Be very careful! */ +struct lstring { + int size; + char buf[]; +}; + int tac_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int tac_main(int argc, char **argv) { char **name; FILE *f; - char *line; + struct lstring *line = NULL; llist_t *list = NULL; int retval = EXIT_SUCCESS; @@ -38,6 +43,8 @@ name++; do { + int ch, i; + name--; f = fopen_or_warn_stdin(*name); if (f == NULL) { @@ -45,14 +52,26 @@ continue; } - errno = 0; - /* FIXME: NUL bytes are mishandled. */ - while ((line = xmalloc_fgets(f)) != NULL) - llist_add_to(&list, line); - - /* xmalloc_fgets uses getc and returns NULL on error or EOF. */ - /* It sets errno to ENOENT on EOF, but fopen_or_warn_stdin would */ - /* catch this error so we can filter it out here. */ + errno = i = 0; + do { + ch = fgetc(f); + if (ch != EOF) { + if (!(i & 0x7f)) + /* Grow on every 128th char */ + line = xrealloc(line, i + 0x7f + sizeof(int) + 1); + line->buf[i++] = ch; + } + if ((ch == '\n' || ch == EOF) && i) { + line = xrealloc(line, i + sizeof(int)); + line->size = i; + llist_add_to(&list, line); + line = NULL; + i = 0; + } + } while (ch != EOF); + /* fgetc sets errno to ENOENT on EOF, but */ + /* fopen_or_warn_stdin would catch this error */ + /* so we can filter it out here. */ if (errno && errno != ENOENT) { bb_simple_perror_msg(*name); retval = EXIT_FAILURE; @@ -60,8 +79,13 @@ } while (name != argv); while (list) { - printf("%s", list->data); - list = list->link; + line = (struct lstring *)list->data; + xwrite(STDOUT_FILENO, line->buf, line->size); + if (ENABLE_FEATURE_CLEAN_UP) { + free(llist_pop(&list)); + } else { + list = list->link; + } } return retval; From pgf at busybox.net Fri Jan 11 08:12:58 2008 From: pgf at busybox.net (pgf at busybox.net) Date: Fri, 11 Jan 2008 08:12:58 -0800 (PST) Subject: svn commit: trunk/busybox/libbb Message-ID: <20080111161258.9627A12C553@busybox.net> Author: pgf Date: 2008-01-11 08:12:57 -0800 (Fri, 11 Jan 2008) New Revision: 20844 Log: allow 8-bit characters Modified: trunk/busybox/libbb/lineedit.c Changeset: Modified: trunk/busybox/libbb/lineedit.c =================================================================== --- trunk/busybox/libbb/lineedit.c 2008-01-11 09:14:21 UTC (rev 20843) +++ trunk/busybox/libbb/lineedit.c 2008-01-11 16:12:57 UTC (rev 20844) @@ -1768,9 +1768,6 @@ if (vi_cmdmode) /* Don't self-insert */ break; #endif - if (!Isprint(c)) /* Skip non-printable characters */ - break; - if (command_len >= (maxsize - 2)) /* Need to leave space for enter */ break; From pgf at busybox.net Fri Jan 11 08:50:09 2008 From: pgf at busybox.net (pgf at busybox.net) Date: Fri, 11 Jan 2008 08:50:09 -0800 (PST) Subject: svn commit: trunk/busybox/libbb Message-ID: <20080111165009.164A71200F2@busybox.net> Author: pgf Date: 2008-01-11 08:50:08 -0800 (Fri, 11 Jan 2008) New Revision: 20845 Log: enable use of ^V prefix to allow forced insertion of any character. in particular, without this it's impossible to enter a TAB on the commandline (whether tab completion is enabled or not). Modified: trunk/busybox/libbb/lineedit.c Changeset: Modified: trunk/busybox/libbb/lineedit.c =================================================================== --- trunk/busybox/libbb/lineedit.c 2008-01-11 16:12:57 UTC (rev 20844) +++ trunk/busybox/libbb/lineedit.c 2008-01-11 16:50:08 UTC (rev 20845) @@ -1752,8 +1752,8 @@ break; default: /* If it's regular input, do the normal thing */ -#if ENABLE_FEATURE_NONPRINTABLE_INVERSE_PUT - /* Control-V -- Add non-printable symbol */ + + /* Control-V -- force insert of next char */ if (c == CTRL('V')) { if (safe_read(STDIN_FILENO, &c, 1) < 1) goto prepare_to_die; @@ -1761,8 +1761,7 @@ beep(); break; } - } else -#endif + } #if ENABLE_FEATURE_EDITING_VI if (vi_cmdmode) /* Don't self-insert */ From aldot at busybox.net Fri Jan 11 12:52:45 2008 From: aldot at busybox.net (aldot at busybox.net) Date: Fri, 11 Jan 2008 12:52:45 -0800 (PST) Subject: svn commit: trunk/busybox/scripts Message-ID: <20080111205245.BF1B612C568@busybox.net> Author: aldot Date: 2008-01-11 12:52:45 -0800 (Fri, 11 Jan 2008) New Revision: 20846 Log: - add ipsvd Modified: trunk/busybox/scripts/Makefile.IMA Changeset: Modified: trunk/busybox/scripts/Makefile.IMA =================================================================== --- trunk/busybox/scripts/Makefile.IMA 2008-01-11 16:50:08 UTC (rev 20845) +++ trunk/busybox/scripts/Makefile.IMA 2008-01-11 20:52:45 UTC (rev 20846) @@ -63,6 +63,9 @@ include runit/Kbuild lib-all-y += $(patsubst %,runit/%,$(sort $(lib-y))) lib-y:= +include ipsvd/Kbuild +lib-all-y += $(patsubst %,ipsvd/%,$(sort $(lib-y))) +lib-y:= include modutils/Kbuild lib-all-y += $(patsubst %,modutils/%,$(sort $(lib-y))) lib-y:= From aldot at busybox.net Sun Jan 13 07:23:27 2008 From: aldot at busybox.net (aldot at busybox.net) Date: Sun, 13 Jan 2008 07:23:27 -0800 (PST) Subject: svn commit: trunk/busybox: include networking Message-ID: <20080113152327.8952F12C5E2@busybox.net> Author: aldot Date: 2008-01-13 07:23:27 -0800 (Sun, 13 Jan 2008) New Revision: 20850 Log: - new applet brctl text data bss dec hex filename 289 20 0 309 135 networking/brctl.o 335 23 0 358 166 networking/brctl-verbose-ops.o Added: trunk/busybox/networking/brctl.c Modified: trunk/busybox/include/applets.h trunk/busybox/include/usage.h trunk/busybox/networking/Config.in trunk/busybox/networking/Kbuild Changeset: Modified: trunk/busybox/include/applets.h =================================================================== --- trunk/busybox/include/applets.h 2008-01-12 17:59:10 UTC (rev 20849) +++ trunk/busybox/include/applets.h 2008-01-13 15:23:27 UTC (rev 20850) @@ -86,6 +86,7 @@ USE_BASENAME(APPLET_NOFORK(basename, basename, _BB_DIR_USR_BIN, _BB_SUID_NEVER, basename)) USE_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_NEVER)) //USE_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_NEVER)) +USE_BRCTL(APPLET(brctl, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) USE_BUNZIP2(APPLET(bunzip2, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) USE_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, _BB_DIR_USR_BIN, _BB_SUID_NEVER, bzcat)) USE_BZIP2(APPLET(bzip2, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) Modified: trunk/busybox/include/usage.h =================================================================== --- trunk/busybox/include/usage.h 2008-01-12 17:59:10 UTC (rev 20849) +++ trunk/busybox/include/usage.h 2008-01-13 15:23:27 UTC (rev 20850) @@ -119,6 +119,16 @@ "$ basename /foo/bar.txt .txt\n" \ "bar" +#define brctl_trivial_usage \ + "COMMAND [BRIDGE [INTERFACE]]" +#define brctl_full_usage \ + "Manage ethernet bridges." \ + "\n\nCommands:\n" \ + " addbr Create \n" \ + " delbr Delete \n" \ + " addif Add to \n" \ + " delif Delete from " + #define bunzip2_trivial_usage \ "[OPTION]... [FILE]" #define bunzip2_full_usage \ Modified: trunk/busybox/networking/Config.in =================================================================== --- trunk/busybox/networking/Config.in 2008-01-12 17:59:10 UTC (rev 20849) +++ trunk/busybox/networking/Config.in 2008-01-13 15:23:27 UTC (rev 20850) @@ -47,6 +47,12 @@ help Ping hosts by ARP packets. +config BRCTL + bool "brctl" + default n + help + Manage ethernet bridges. + config DNSD bool "dnsd" default n Modified: trunk/busybox/networking/Kbuild =================================================================== --- trunk/busybox/networking/Kbuild 2008-01-12 17:59:10 UTC (rev 20849) +++ trunk/busybox/networking/Kbuild 2008-01-13 15:23:27 UTC (rev 20850) @@ -7,6 +7,7 @@ lib-y:= lib-$(CONFIG_ARP) += arp.o interface.o lib-$(CONFIG_ARPING) += arping.o +lib-$(CONFIG_BRCTL) += brctl.o lib-$(CONFIG_DNSD) += dnsd.o lib-$(CONFIG_ETHER_WAKE) += ether-wake.o lib-$(CONFIG_FAKEIDENTD) += isrv_identd.o isrv.o Added: trunk/busybox/networking/brctl.c =================================================================== --- trunk/busybox/networking/brctl.c (rev 0) +++ trunk/busybox/networking/brctl.c 2008-01-13 15:23:27 UTC (rev 20850) @@ -0,0 +1,87 @@ +/* vi: set sw=4 ts=4: */ +/* + * Small implementation of brctl for busybox. + * + * Copyright (C) 2008 by Bernhard Fischer + * + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + */ +#include "libbb.h" +#include +#include + +#ifdef ENABLE_FEATURE_BRCTL_SHOW +#error Remove these +#endif +#define ENABLE_FEATURE_BRCTL_SHOW 0 +#define USE_FEATURE_BRCTL_SHOW(...) + + +/* Fancy diagnostics -- printing add/del -- costs 49 bytes. */ +#if 0 +#define BRCTL_VERBOSE(...) __VA_ARGS__ +#else +#define BRCTL_VERBOSE(...) +#endif + +int brctl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int brctl_main(int argc, char **argv) +{ + int fd; + static const char keywords[] ALIGN1 = + "addbr\0" "delbr\0" "addif\0" "delif\0" + USE_FEATURE_BRCTL_SHOW("show\0"); + enum { ARG_addbr = 1, ARG_delbr, ARG_addif, ARG_delif + USE_FEATURE_BRCTL_SHOW(, ARG_show) }; + smalluint key; + static char info[] = BRCTL_VERBOSE("%s ")"bridge %s\0 iface %s"; + + argv++; + while (*argv) { + BRCTL_VERBOSE(char *op;) + + key = index_in_strings(keywords, *argv) + 1; + if (key == 0) /* no match found in keywords array, bail out. */ + bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); + argv++; +#if ENABLE_FEATURE_BRCTL_SHOW + if (key == ARG_show) { /* show */ + ; + } +#endif + BRCTL_VERBOSE(op = (char*)((key % 2) ? "add" : "del");) + fd = xsocket(AF_INET, SOCK_STREAM, 0); + if (key < 3) {/* addbr or delbr */ + char *br; + + br = *(argv++); + if (ioctl(fd, key == ARG_addbr ? SIOCBRADDBR : SIOCBRDELBR, br) < 0) + { + info[9 BRCTL_VERBOSE(+3)] = '\0'; + bb_perror_msg_and_die(info, BRCTL_VERBOSE(op,) br); + } + } + if (key > 2) { /* addif or delif */ + struct ifreq ifr; + char *br, *brif; + + br = *(argv++); + if (!*argv) + bb_show_usage(); + brif = *(argv++); + + if (!(ifr.ifr_ifindex = if_nametoindex(brif))) { + bb_perror_msg_and_die(info+11 BRCTL_VERBOSE(+3), brif); + } + safe_strncpy(ifr.ifr_name, br, IFNAMSIZ); + if (ioctl(fd, + key == ARG_addif ? SIOCBRADDIF : SIOCBRDELIF, &ifr) < 0) { + info[9 BRCTL_VERBOSE(+3)] = ','; + bb_perror_msg_and_die (info, BRCTL_VERBOSE(op,) br, brif); + } + } + if (ENABLE_FEATURE_CLEAN_UP) + close(fd); + } + return EXIT_SUCCESS; +} From aldot at busybox.net Sun Jan 13 07:33:14 2008 From: aldot at busybox.net (aldot at busybox.net) Date: Sun, 13 Jan 2008 07:33:14 -0800 (PST) Subject: svn commit: trunk/busybox/scripts Message-ID: <20080113153314.09E3812C5E9@busybox.net> Author: aldot Date: 2008-01-13 07:33:13 -0800 (Sun, 13 Jan 2008) New Revision: 20851 Log: - update defconfig Modified: trunk/busybox/scripts/defconfig Changeset: Modified: trunk/busybox/scripts/defconfig =================================================================== --- trunk/busybox/scripts/defconfig 2008-01-13 15:23:27 UTC (rev 20850) +++ trunk/busybox/scripts/defconfig 2008-01-13 15:33:13 UTC (rev 20851) @@ -553,6 +553,7 @@ # CONFIG_VERBOSE_RESOLUTION_ERRORS is not set CONFIG_ARP=y CONFIG_ARPING=y +CONFIG_BRCTL=y CONFIG_DNSD=y # CONFIG_ETHER_WAKE is not set CONFIG_FAKEIDENTD=y From aldot at busybox.net Sun Jan 13 07:43:28 2008 From: aldot at busybox.net (aldot at busybox.net) Date: Sun, 13 Jan 2008 07:43:28 -0800 (PST) Subject: svn commit: trunk/busybox/networking Message-ID: <20080113154328.9C3A812C5F0@busybox.net> Author: aldot Date: 2008-01-13 07:43:28 -0800 (Sun, 13 Jan 2008) New Revision: 20852 Log: - save four bytes by manually hoisting the br assignment Modified: trunk/busybox/networking/brctl.c Changeset: Modified: trunk/busybox/networking/brctl.c =================================================================== --- trunk/busybox/networking/brctl.c 2008-01-13 15:33:13 UTC (rev 20851) +++ trunk/busybox/networking/brctl.c 2008-01-13 15:43:28 UTC (rev 20852) @@ -35,6 +35,7 @@ USE_FEATURE_BRCTL_SHOW(, ARG_show) }; smalluint key; static char info[] = BRCTL_VERBOSE("%s ")"bridge %s\0 iface %s"; + char *br; argv++; while (*argv) { @@ -51,10 +52,9 @@ #endif BRCTL_VERBOSE(op = (char*)((key % 2) ? "add" : "del");) fd = xsocket(AF_INET, SOCK_STREAM, 0); - if (key < 3) {/* addbr or delbr */ - char *br; + br = *(argv++); - br = *(argv++); + if (key < 3) { /* addbr or delbr */ if (ioctl(fd, key == ARG_addbr ? SIOCBRADDBR : SIOCBRDELBR, br) < 0) { info[9 BRCTL_VERBOSE(+3)] = '\0'; @@ -63,9 +63,8 @@ } if (key > 2) { /* addif or delif */ struct ifreq ifr; - char *br, *brif; + char *brif; - br = *(argv++); if (!*argv) bb_show_usage(); brif = *(argv++); From aldot at busybox.net Sun Jan 13 09:52:54 2008 From: aldot at busybox.net (aldot at busybox.net) Date: Sun, 13 Jan 2008 09:52:54 -0800 (PST) Subject: svn commit: trunk/busybox/include Message-ID: <20080113175254.4D39112C52C@busybox.net> Author: aldot Date: 2008-01-13 09:52:53 -0800 (Sun, 13 Jan 2008) New Revision: 20853 Log: - fix commentary typo Modified: trunk/busybox/include/libbb.h Changeset: Modified: trunk/busybox/include/libbb.h =================================================================== --- trunk/busybox/include/libbb.h 2008-01-13 15:43:28 UTC (rev 20852) +++ trunk/busybox/include/libbb.h 2008-01-13 17:52:53 UTC (rev 20853) @@ -1098,7 +1098,7 @@ #define FILEUTILS_CP_OPTSTR "pdRfils" USE_SELINUX("c") extern const char *applet_name; -/* "BusyBox vN.N.N (timestamp or extra_vestion)" */ +/* "BusyBox vN.N.N (timestamp or extra_version)" */ extern const char bb_banner[]; extern const char bb_msg_memory_exhausted[]; extern const char bb_msg_invalid_date[]; From aldot at busybox.net Sun Jan 13 10:43:50 2008 From: aldot at busybox.net (aldot at busybox.net) Date: Sun, 13 Jan 2008 10:43:50 -0800 (PST) Subject: svn commit: trunk/busybox: include networking Message-ID: <20080113184350.CE23912C4B7@busybox.net> Author: aldot Date: 2008-01-13 10:43:50 -0800 (Sun, 13 Jan 2008) New Revision: 20854 Log: - shrink a bit and implement time related fancy features. Improve help texts. text data bss dec hex filename 253 20 0 273 111 networking/brctl.o.bare 613 20 0 633 279 networking/brctl.o.fancy-time Modified: trunk/busybox/include/usage.h trunk/busybox/networking/Config.in trunk/busybox/networking/brctl.c Changeset: Modified: trunk/busybox/include/usage.h =================================================================== --- trunk/busybox/include/usage.h 2008-01-13 17:52:53 UTC (rev 20853) +++ trunk/busybox/include/usage.h 2008-01-13 18:43:50 UTC (rev 20854) @@ -127,8 +127,13 @@ " addbr Create \n" \ " delbr Delete \n" \ " addif Add to \n" \ - " delif Delete from " - + " delif Delete from " \ +USE_FEATURE_BRCTL_FANCY("\n" \ + " setageing set ageing time\n" \ + " setfd set bridge forward delay\n" \ + " sethello set hello time\n" \ + " setmaxage set max message age\n" \ +) #define bunzip2_trivial_usage \ "[OPTION]... [FILE]" #define bunzip2_full_usage \ Modified: trunk/busybox/networking/Config.in =================================================================== --- trunk/busybox/networking/Config.in 2008-01-13 17:52:53 UTC (rev 20853) +++ trunk/busybox/networking/Config.in 2008-01-13 18:43:50 UTC (rev 20854) @@ -52,7 +52,26 @@ default n help Manage ethernet bridges. + Supports addbr/delbr and addif/delif. +#config FEATURE_BRCTL_SHOW +# bool "support show, showmac and showstp" +# default n +# depends on BRCTL +# help +# Add support for option which print the current config: +# showmacs, showstp, show + +config FEATURE_BRCTL_FANCY + bool "fancy options" + default n + depends on BRCTL + help + Add support for extended option like: + setageing, setfd, sethello, setmaxage, + setpathcost, setportprio, setbridgeprio, + stp + config DNSD bool "dnsd" default n Modified: trunk/busybox/networking/brctl.c =================================================================== --- trunk/busybox/networking/brctl.c 2008-01-13 17:52:53 UTC (rev 20853) +++ trunk/busybox/networking/brctl.c 2008-01-13 18:43:50 UTC (rev 20854) @@ -6,6 +6,9 @@ * * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ +/* This applet currently uses only the ioctl interface and no sysfs at all. + * At the time of this writing this was considered a feature. + */ #include "libbb.h" #include #include @@ -15,72 +18,129 @@ #endif #define ENABLE_FEATURE_BRCTL_SHOW 0 #define USE_FEATURE_BRCTL_SHOW(...) - - -/* Fancy diagnostics -- printing add/del -- costs 49 bytes. */ #if 0 -#define BRCTL_VERBOSE(...) __VA_ARGS__ +#define ENABLE_FEATURE_BRCTL_FANCY 0 +#if ENABLE_FEATURE_BRCTL_FANCY +#define USE_FEATURE_BRCTL_FANCY(...) __VA_ARGS__ #else -#define BRCTL_VERBOSE(...) +#define USE_FEATURE_BRCTL_FANCY(...) #endif +#endif +#if ENABLE_FEATURE_BRCTL_FANCY +#include +/* FIXME: These 4 funcs are not really clean and could be improved */ +static inline ALWAYS_INLINE void strtotimeval(struct timeval *tv, + const char *time_str) +{ + double secs; + if (sscanf(time_str, "%lf", &secs) != 1) + bb_error_msg_and_die (bb_msg_invalid_arg, time_str, "timespec"); + tv->tv_sec = secs; + tv->tv_usec = 1000000 * (secs - tv->tv_sec); +} -int brctl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int brctl_main(int argc, char **argv) +static inline ALWAYS_INLINE unsigned long __tv_to_jiffies(const struct timeval *tv) { + unsigned long long jif; + + jif = 1000000ULL * tv->tv_sec + tv->tv_usec; + + return jif/10000; +} +# ifdef UNUSED && 00 +static void __jiffies_to_tv(struct timeval *tv, unsigned long jiffies) +{ + unsigned long long tvusec; + + tvusec = 10000ULL*jiffies; + tv->tv_sec = tvusec/1000000; + tv->tv_usec = tvusec - 1000000 * tv->tv_sec; +} +# endif +static unsigned long str_to_jiffies(const char *time_str) +{ + struct timeval tv; + strtotimeval(&tv, time_str); + return __tv_to_jiffies(&tv); +} +#endif + + +int brctl_main(int argc ATTRIBUTE_UNUSED, char **argv) MAIN_EXTERNALLY_VISIBLE; +int brctl_main(int argc ATTRIBUTE_UNUSED, char **argv) +{ int fd; static const char keywords[] ALIGN1 = "addbr\0" "delbr\0" "addif\0" "delif\0" - USE_FEATURE_BRCTL_SHOW("show\0"); - enum { ARG_addbr = 1, ARG_delbr, ARG_addif, ARG_delif - USE_FEATURE_BRCTL_SHOW(, ARG_show) }; - smalluint key; - static char info[] = BRCTL_VERBOSE("%s ")"bridge %s\0 iface %s"; + USE_FEATURE_BRCTL_FANCY( + "setageing\0" "setfd\0" "sethello\0" "setmaxage\0" + "setpathcost\0" "setportprio\0" "setbridgeprio\0" + "stp\0" + ) + USE_FEATURE_BRCTL_SHOW("showmacs\0" "show\0"); + enum { ARG_addbr = 0, ARG_delbr, ARG_addif, ARG_delif + USE_FEATURE_BRCTL_FANCY(, + ARG_setageing, ARG_setfd, ARG_sethello, ARG_setmaxage, + ARG_setpathcost, ARG_setportprio, ARG_setbridgeprio, + ARG_stp + ) + USE_FEATURE_BRCTL_SHOW(, ARG_showmacs, ARG_show) }; + smallint key; + struct ifreq ifr; + static char info[] = "bridge %s\0 iface %s"; char *br; argv++; while (*argv) { - BRCTL_VERBOSE(char *op;) - - key = index_in_strings(keywords, *argv) + 1; - if (key == 0) /* no match found in keywords array, bail out. */ + key = index_in_strings(keywords, *argv); + if (key == -1) /* no match found in keywords array, bail out. */ bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); argv++; #if ENABLE_FEATURE_BRCTL_SHOW if (key == ARG_show) { /* show */ - ; + goto out; /* FIXME: implement me! :) */ } #endif - BRCTL_VERBOSE(op = (char*)((key % 2) ? "add" : "del");) fd = xsocket(AF_INET, SOCK_STREAM, 0); br = *(argv++); - if (key < 3) { /* addbr or delbr */ - if (ioctl(fd, key == ARG_addbr ? SIOCBRADDBR : SIOCBRDELBR, br) < 0) - { - info[9 BRCTL_VERBOSE(+3)] = '\0'; - bb_perror_msg_and_die(info, BRCTL_VERBOSE(op,) br); - } + if (key == ARG_addbr || key == ARG_delbr) { /* addbr or delbr */ + ioctl_or_perror_and_die(fd, + key == ARG_addbr ? SIOCBRADDBR : SIOCBRDELBR, + br, info, br); + goto done; } - if (key > 2) { /* addif or delif */ - struct ifreq ifr; + if (!*argv) /* all but 'show' need at least one argument */ + bb_show_usage(); + safe_strncpy(ifr.ifr_name, br, IFNAMSIZ); + if (key == ARG_addif || key == ARG_delif) { /* addif or delif */ char *brif; - if (!*argv) - bb_show_usage(); brif = *(argv++); - if (!(ifr.ifr_ifindex = if_nametoindex(brif))) { - bb_perror_msg_and_die(info+11 BRCTL_VERBOSE(+3), brif); + bb_perror_msg_and_die(info+11, brif); } - safe_strncpy(ifr.ifr_name, br, IFNAMSIZ); - if (ioctl(fd, - key == ARG_addif ? SIOCBRADDIF : SIOCBRDELIF, &ifr) < 0) { - info[9 BRCTL_VERBOSE(+3)] = ','; - bb_perror_msg_and_die (info, BRCTL_VERBOSE(op,) br, brif); - } + ioctl_or_perror_and_die(fd, + key == ARG_addif ? SIOCBRADDIF : SIOCBRDELIF, + &ifr, info, br); } +#if ENABLE_FEATURE_BRCTL_FANCY + if (key - ARG_delif < 5) { /* time related ops */ + unsigned long op = (key == ARG_setageing) ? BRCTL_SET_AGEING_TIME : + (key == ARG_setfd) ? BRCTL_SET_BRIDGE_FORWARD_DELAY: + (key == ARG_sethello) ? BRCTL_SET_BRIDGE_HELLO_TIME: + (key == ARG_setmaxage) ? BRCTL_SET_BRIDGE_MAX_AGE : + -1/*will never be used */; + unsigned long jiff = str_to_jiffies (*(argv++)); + unsigned long args[4] = {op, jiff, 0, 0}; + ifr.ifr_data = (char *) &args; + xioctl(fd, SIOCDEVPRIVATE, &ifr); + } +#endif + done: if (ENABLE_FEATURE_CLEAN_UP) close(fd); } + out: return EXIT_SUCCESS; } From aldot at busybox.net Mon Jan 14 06:32:56 2008 From: aldot at busybox.net (aldot at busybox.net) Date: Mon, 14 Jan 2008 06:32:56 -0800 (PST) Subject: svn commit: trunk/busybox Message-ID: <20080114143256.7AE1D12C55A@busybox.net> Author: aldot Date: 2008-01-14 06:32:56 -0800 (Mon, 14 Jan 2008) New Revision: 20855 Log: - mention strtod code-duplication as TODO for cleanup Modified: trunk/busybox/TODO Changeset: Modified: trunk/busybox/TODO =================================================================== --- trunk/busybox/TODO 2008-01-13 18:43:50 UTC (rev 20854) +++ trunk/busybox/TODO 2008-01-14 14:32:56 UTC (rev 20855) @@ -301,6 +301,9 @@ --- Move __get_hz() to a better place and (re)use it in route.c, ash.c, msh.c --- + See grep -r strtod + Alot of duplication that wants cleanup. +--- Code cleanup: From bugs at busybox.net Mon Jan 14 07:55:42 2008 From: bugs at busybox.net (bugs at busybox.net) Date: Mon, 14 Jan 2008 07:55:42 -0800 Subject: [BusyBox 0001586]: vi generates a Segmentation Fault when pasting Message-ID: <5e400957ddde77b77767d588e914b3be@bugs.busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1586 ====================================================================== Reported By: opalenzuela Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1586 Category: Other Reproducibility: always Severity: minor Priority: normal Status: feedback ====================================================================== Date Submitted: 11-12-2007 07:31 PST Last Modified: 01-14-2008 07:55 PST ====================================================================== Summary: vi generates a Segmentation Fault when pasting Description: Accessing my busybox platform through Putty, and editing a text file with busybox's "vi" (Insertion mode activated) just pasting a quite big amount of plain text bytes (maybe 10KB) it drops with a Segmentation Fault. CPU consumption before the crash was really high too (maybe the auto-justification has some relation with it)... ====================================================================== ---------------------------------------------------------------------- opalenzuela - 11-25-07 23:20 ---------------------------------------------------------------------- It looks like some problems on "auto-justifying" function, and opening-closure control on "{". In my opinion, this functions are not necessary for an embedded platform, and some file editing functions (jump to line, search string, replace?) should be enough. ---------------------------------------------------------------------- vda - 11-25-07 23:26 ---------------------------------------------------------------------- Can you give some *reproducible* way to trigger this? Also state busybox version and maybe attach your .config ---------------------------------------------------------------------- opalenzuela - 01-14-08 07:55 ---------------------------------------------------------------------- I haven't tried with latest versions. This problem was detected on a 1.6.x . I'll confirm it as soon as possible. Thanks. Issue History Date Modified Username Field Change ====================================================================== 11-12-07 07:31 opalenzuela New Issue 11-12-07 07:31 opalenzuela Status new => assigned 11-12-07 07:31 opalenzuela Assigned To => BusyBox 11-25-07 23:20 opalenzuela Note Added: 0002962 11-25-07 23:26 vda Note Added: 0002963 11-25-07 23:27 vda Status assigned => feedback 01-14-08 07:55 opalenzuela Note Added: 0003449 ====================================================================== From aldot at busybox.net Mon Jan 14 08:10:12 2008 From: aldot at busybox.net (aldot at busybox.net) Date: Mon, 14 Jan 2008 08:10:12 -0800 (PST) Subject: svn commit: trunk/busybox: include networking Message-ID: <20080114161012.478A012C550@busybox.net> Author: aldot Date: 2008-01-14 08:10:11 -0800 (Mon, 14 Jan 2008) New Revision: 20856 Log: - implement brctl setpathcost, setportprio, setbridgeprio, stp text data bss dec hex filename 907 20 0 927 39f networking/brctl.o Modified: trunk/busybox/include/usage.h trunk/busybox/networking/Config.in trunk/busybox/networking/brctl.c Changeset: Modified: trunk/busybox/include/usage.h =================================================================== --- trunk/busybox/include/usage.h 2008-01-14 14:32:56 UTC (rev 20855) +++ trunk/busybox/include/usage.h 2008-01-14 16:10:11 UTC (rev 20856) @@ -133,6 +133,10 @@ " setfd set bridge forward delay\n" \ " sethello set hello time\n" \ " setmaxage set max message age\n" \ + " setpathcost set path cost\n" \ + " setportprio set port priority\n" \ + " setbridgeprio set bridge priority\n" \ + " stp [1|0] turn stp on/off\n" \ ) #define bunzip2_trivial_usage \ "[OPTION]... [FILE]" Modified: trunk/busybox/networking/Config.in =================================================================== --- trunk/busybox/networking/Config.in 2008-01-14 14:32:56 UTC (rev 20855) +++ trunk/busybox/networking/Config.in 2008-01-14 16:10:11 UTC (rev 20856) @@ -71,6 +71,7 @@ setageing, setfd, sethello, setmaxage, setpathcost, setportprio, setbridgeprio, stp + This adds about 600 bytes. config DNSD bool "dnsd" Modified: trunk/busybox/networking/brctl.c =================================================================== --- trunk/busybox/networking/brctl.c 2008-01-14 14:32:56 UTC (rev 20855) +++ trunk/busybox/networking/brctl.c 2008-01-14 16:10:11 UTC (rev 20856) @@ -4,6 +4,9 @@ * * Copyright (C) 2008 by Bernhard Fischer * + * Some helper functions from bridge-utils are + * Copyright (C) 2000 Lennert Buytenhek + * * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ /* This applet currently uses only the ioctl interface and no sysfs at all. @@ -13,27 +16,33 @@ #include #include +/* Maximum number of ports supported per bridge interface. */ +#ifndef MAX_PORTS +#define MAX_PORTS 32 +#endif + +/* Use internal number parsing and not the "exact" conversion. */ +/* #define BRCTL_USE_INTERNAL 0 */ /* use exact conversion */ +#define BRCTL_USE_INTERNAL 1 + #ifdef ENABLE_FEATURE_BRCTL_SHOW #error Remove these #endif #define ENABLE_FEATURE_BRCTL_SHOW 0 #define USE_FEATURE_BRCTL_SHOW(...) -#if 0 -#define ENABLE_FEATURE_BRCTL_FANCY 0 + #if ENABLE_FEATURE_BRCTL_FANCY -#define USE_FEATURE_BRCTL_FANCY(...) __VA_ARGS__ -#else -#define USE_FEATURE_BRCTL_FANCY(...) -#endif -#endif -#if ENABLE_FEATURE_BRCTL_FANCY #include /* FIXME: These 4 funcs are not really clean and could be improved */ static inline ALWAYS_INLINE void strtotimeval(struct timeval *tv, const char *time_str) { double secs; +#if BRCTL_USE_INTERNAL + if (!(secs = /*bb_*/strtod(time_str, NULL))) +#else if (sscanf(time_str, "%lf", &secs) != 1) +#endif bb_error_msg_and_die (bb_msg_invalid_arg, time_str, "timespec"); tv->tv_sec = secs; tv->tv_usec = 1000000 * (secs - tv->tv_sec); @@ -47,7 +56,7 @@ return jif/10000; } -# ifdef UNUSED && 00 +# if 00 static void __jiffies_to_tv(struct timeval *tv, unsigned long jiffies) { unsigned long long tvusec; @@ -63,6 +72,15 @@ strtotimeval(&tv, time_str); return __tv_to_jiffies(&tv); } + +static void arm_ioctl(unsigned long *args, + unsigned long arg0, unsigned long arg1, unsigned long arg2) +{ + args[0] = arg0; + args[1] = arg1; + args[2] = arg2; + args[3] = 0; +} #endif @@ -73,22 +91,27 @@ static const char keywords[] ALIGN1 = "addbr\0" "delbr\0" "addif\0" "delif\0" USE_FEATURE_BRCTL_FANCY( + "stp\0" "setageing\0" "setfd\0" "sethello\0" "setmaxage\0" "setpathcost\0" "setportprio\0" "setbridgeprio\0" - "stp\0" ) USE_FEATURE_BRCTL_SHOW("showmacs\0" "show\0"); enum { ARG_addbr = 0, ARG_delbr, ARG_addif, ARG_delif USE_FEATURE_BRCTL_FANCY(, + ARG_stp, ARG_setageing, ARG_setfd, ARG_sethello, ARG_setmaxage, - ARG_setpathcost, ARG_setportprio, ARG_setbridgeprio, - ARG_stp + ARG_setpathcost, ARG_setportprio, ARG_setbridgeprio ) USE_FEATURE_BRCTL_SHOW(, ARG_showmacs, ARG_show) }; smallint key; struct ifreq ifr; static char info[] = "bridge %s\0 iface %s"; - char *br; + char *br, *brif; +#if ENABLE_FEATURE_BRCTL_FANCY + unsigned long args[4] = {0, 0, 0, 0}; + int port; + int tmp; +#endif argv++; while (*argv) { @@ -114,8 +137,6 @@ bb_show_usage(); safe_strncpy(ifr.ifr_name, br, IFNAMSIZ); if (key == ARG_addif || key == ARG_delif) { /* addif or delif */ - char *brif; - brif = *(argv++); if (!(ifr.ifr_ifindex = if_nametoindex(brif))) { bb_perror_msg_and_die(info+11, brif); @@ -123,24 +144,74 @@ ioctl_or_perror_and_die(fd, key == ARG_addif ? SIOCBRADDIF : SIOCBRDELIF, &ifr, info, br); + goto done; } #if ENABLE_FEATURE_BRCTL_FANCY - if (key - ARG_delif < 5) { /* time related ops */ + ifr.ifr_data = (char *) &args; + if (key == ARG_stp) { /* stp */ + /* FIXME: parsing yes/y/on/1 versus no/n/off/0 is too involved */ + arm_ioctl(args, BRCTL_SET_BRIDGE_STP_STATE, + (unsigned)(**argv - '0'), 0); + goto fire; + } + if ((unsigned)(key - ARG_stp) < 5) { /* time related ops */ unsigned long op = (key == ARG_setageing) ? BRCTL_SET_AGEING_TIME : (key == ARG_setfd) ? BRCTL_SET_BRIDGE_FORWARD_DELAY: (key == ARG_sethello) ? BRCTL_SET_BRIDGE_HELLO_TIME: (key == ARG_setmaxage) ? BRCTL_SET_BRIDGE_MAX_AGE : - -1/*will never be used */; - unsigned long jiff = str_to_jiffies (*(argv++)); - unsigned long args[4] = {op, jiff, 0, 0}; - ifr.ifr_data = (char *) &args; + -1/* will never be used */; + arm_ioctl(args, op, str_to_jiffies (*argv), 0); + goto fire; + } + port = -1; + if (key == ARG_setpathcost || key == ARG_setportprio) {/* get portnum */ + int ifidx[MAX_PORTS]; + unsigned i; + + if (!(port = if_nametoindex(*argv))) + bb_error_msg_and_die(bb_msg_invalid_arg, *argv, "port"); + argv++; + memset(ifidx, 0, sizeof ifidx); + arm_ioctl(args, BRCTL_GET_PORT_LIST, (unsigned long)ifidx, + MAX_PORTS); xioctl(fd, SIOCDEVPRIVATE, &ifr); + for (i = 0; i < MAX_PORTS; i++) + if (ifidx[i] == port) { + port = i; + break; + } } + if (key == ARG_setpathcost + || key == ARG_setportprio || key == ARG_setbridgeprio) { + unsigned long op = (key == ARG_setpathcost) ? BRCTL_SET_PATH_COST : + (key == ARG_setportprio) ? BRCTL_SET_PORT_PRIORITY : + (key == ARG_setbridgeprio) ? BRCTL_SET_BRIDGE_PRIORITY : + -1/* will never be used */; + unsigned long arg1 = port; + unsigned long arg2; +# if BRCTL_USE_INTERNAL + tmp = xatoi(*argv); +# else + if (sscanf(*argv, "%i", &tmp) != 1) + bb_error_msg_and_die(bb_msg_invalid_arg, *argv, + key == ARG_setpathcost ? "cost" : "prio"); +# endif + if (key == ARG_setbridgeprio) { + arg1 = tmp; + arg2 = 0; + } else + arg2 = tmp; + arm_ioctl(args, op, arg1, arg2); + } + fire: + /* Execute the previously set command. */ + xioctl(fd, SIOCDEVPRIVATE, &ifr); + argv++; #endif done: if (ENABLE_FEATURE_CLEAN_UP) close(fd); } - out: +USE_FEATURE_BRCTL_SHOW(out:) return EXIT_SUCCESS; } From aldot at busybox.net Thu Jan 17 03:05:14 2008 From: aldot at busybox.net (aldot at busybox.net) Date: Thu, 17 Jan 2008 03:05:14 -0800 (PST) Subject: svn commit: trunk/busybox/include Message-ID: <20080117110514.CEE4A12C575@busybox.net> Author: aldot Date: 2008-01-17 03:05:09 -0800 (Thu, 17 Jan 2008) New Revision: 20860 Log: - correct helptext of stat (Cristian Ionescu-Idbohrn) Modified: trunk/busybox/include/usage.h Changeset: Modified: trunk/busybox/include/usage.h =================================================================== --- trunk/busybox/include/usage.h 2008-01-16 23:59:17 UTC (rev 20859) +++ trunk/busybox/include/usage.h 2008-01-17 11:05:09 UTC (rev 20860) @@ -3373,7 +3373,7 @@ USE_FEATURE_STAT_FORMAT( \ " -c fmt Use the specified format\n") \ " -f Display filesystem status\n" \ - " -L,-l Dereference links\n" \ + " -L Dereference links\n" \ " -t Display info in terse form" \ USE_SELINUX( \ "\n -Z Print security context" \ From aldot at busybox.net Thu Jan 17 03:09:49 2008 From: aldot at busybox.net (aldot at busybox.net) Date: Thu, 17 Jan 2008 03:09:49 -0800 (PST) Subject: svn commit: branches/busybox_1_9_stable/include Message-ID: <20080117110949.0C0EE12C579@busybox.net> Author: aldot Date: 2008-01-17 03:09:45 -0800 (Thu, 17 Jan 2008) New Revision: 20861 Log: - correct helptext of stat (Cristian Ionescu-Idbohrn) Modified: branches/busybox_1_9_stable/include/usage.h Changeset: Modified: branches/busybox_1_9_stable/include/usage.h =================================================================== --- branches/busybox_1_9_stable/include/usage.h 2008-01-17 11:05:09 UTC (rev 20860) +++ branches/busybox_1_9_stable/include/usage.h 2008-01-17 11:09:45 UTC (rev 20861) @@ -3354,7 +3354,7 @@ USE_FEATURE_STAT_FORMAT( \ " -c fmt Use the specified format\n") \ " -f Display filesystem status\n" \ - " -L,-l Dereference links\n" \ + " -L Dereference links\n" \ " -t Display info in terse form" \ USE_SELINUX( \ "\n -Z Print security context" \ From pgf at busybox.net Fri Jan 18 12:41:25 2008 From: pgf at busybox.net (pgf at busybox.net) Date: Fri, 18 Jan 2008 12:41:25 -0800 (PST) Subject: svn commit: trunk/busybox: libbb scripts Message-ID: <20080118204125.7DD8712C575@busybox.net> Author: pgf Date: 2008-01-18 12:41:24 -0800 (Fri, 18 Jan 2008) New Revision: 20875 Log: eliminated CONFIG_FEATURE_EDITING_FANCY_KEYS. the size savings was small, compared to the total size of the command-line editing features, and it removed key bindings that most wouldn't consider "fancy", like ^U, and 'l' and 'h' in vi mode, ^F and ^B in emacs mode. Modified: trunk/busybox/libbb/Config.in trunk/busybox/libbb/lineedit.c trunk/busybox/scripts/defconfig Changeset: Modified: trunk/busybox/libbb/Config.in =================================================================== --- trunk/busybox/libbb/Config.in 2008-01-18 16:21:35 UTC (rev 20874) +++ trunk/busybox/libbb/Config.in 2008-01-18 20:41:24 UTC (rev 20875) @@ -57,14 +57,6 @@ You may want to decrease this parameter if your target machine benefits from smaller stack usage. -config FEATURE_EDITING_FANCY_KEYS - bool "Additional editing keys" - default n - depends on FEATURE_EDITING - help - Enable additonal editing keys (Ctrl-E, Ctrl-U etc). - Arrow keys, Home/End/Delete and Ctrl-W work even without this option. - config FEATURE_EDITING_VI bool "vi-style line editing commands" default n Modified: trunk/busybox/libbb/lineedit.c =================================================================== --- trunk/busybox/libbb/lineedit.c 2008-01-18 16:21:35 UTC (rev 20874) +++ trunk/busybox/libbb/lineedit.c 2008-01-18 20:41:24 UTC (rev 20875) @@ -1423,7 +1423,6 @@ goto_new_line(); break_out = 1; break; -#if ENABLE_FEATURE_EDITING_FANCY_KEYS case CTRL('A'): vi_case('0'|vbit:) /* Control-a -- Beginning of line */ @@ -1436,7 +1435,6 @@ /* Control-b -- Move back one character */ input_backward(1); break; -#endif case CTRL('C'): vi_case(CTRL('C')|vbit:) /* Control-c -- stop gathering input */ @@ -1457,7 +1455,6 @@ input_delete(0); break; -#if ENABLE_FEATURE_EDITING_FANCY_KEYS case CTRL('E'): vi_case('$'|vbit:) /* Control-e -- End of line */ @@ -1469,7 +1466,6 @@ /* Control-f -- Move forward one character */ input_forward(); break; -#endif case '\b': case '\x7f': /* DEL */ @@ -1483,7 +1479,6 @@ break; #endif -#if ENABLE_FEATURE_EDITING_FANCY_KEYS case CTRL('K'): /* Control-k -- clear to end of line */ command[cursor] = 0; @@ -1496,7 +1491,6 @@ printf("\033[H"); redraw(0, command_len - cursor); break; -#endif #if MAX_HISTORY > 0 case CTRL('N'): @@ -1518,7 +1512,6 @@ break; #endif -#if ENABLE_FEATURE_EDITING_FANCY_KEYS case CTRL('U'): vi_case(CTRL('U')|vbit:) /* Control-U -- Clear line before cursor */ @@ -1528,7 +1521,6 @@ redraw(cmdedit_y, command_len); } break; -#endif case CTRL('W'): vi_case(CTRL('W')|vbit:) /* Control-W -- Remove the last word */ Modified: trunk/busybox/scripts/defconfig =================================================================== --- trunk/busybox/scripts/defconfig 2008-01-18 16:21:35 UTC (rev 20874) +++ trunk/busybox/scripts/defconfig 2008-01-18 20:41:24 UTC (rev 20875) @@ -73,7 +73,6 @@ # CONFIG_FEATURE_ETC_NETWORKS is not set CONFIG_FEATURE_EDITING=y CONFIG_FEATURE_EDITING_MAX_LEN=1024 -# CONFIG_FEATURE_EDITING_FANCY_KEYS is not set # CONFIG_FEATURE_EDITING_VI is not set CONFIG_FEATURE_EDITING_HISTORY=15 # CONFIG_FEATURE_EDITING_SAVEHISTORY is not set From aldot at busybox.net Sat Jan 19 03:27:12 2008 From: aldot at busybox.net (aldot at busybox.net) Date: Sat, 19 Jan 2008 03:27:12 -0800 (PST) Subject: svn commit: trunk/busybox/miscutils Message-ID: <20080119112712.ECB3B1200FF@busybox.net> Author: aldot Date: 2008-01-19 03:27:11 -0800 (Sat, 19 Jan 2008) New Revision: 20876 Log: - Fix hdparm's ioctl parameter passing (John Brandwood) Modified: trunk/busybox/miscutils/hdparm.c Changeset: Modified: trunk/busybox/miscutils/hdparm.c =================================================================== --- trunk/busybox/miscutils/hdparm.c 2008-01-18 20:41:24 UTC (rev 20875) +++ trunk/busybox/miscutils/hdparm.c 2008-01-19 11:27:11 UTC (rev 20876) @@ -1764,7 +1764,7 @@ } } if (get_unmask) { - if(!ioctl_or_warn(fd, HDIO_GET_UNMASKINTR, (unsigned long *)parm)) + if(!ioctl_or_warn(fd, HDIO_GET_UNMASKINTR, &parm)) print_value_on_off("unmaskirq", parm); } @@ -1781,24 +1781,24 @@ } #endif if (get_dma_q) { - if(!ioctl_or_warn(fd, HDIO_GET_QDMA, (unsigned long *)parm)) + if(!ioctl_or_warn(fd, HDIO_GET_QDMA, &parm)) print_value_on_off("queue_depth", parm); } if (get_keep) { - if(!ioctl_or_warn(fd, HDIO_GET_KEEPSETTINGS, (unsigned long *)parm)) + if(!ioctl_or_warn(fd, HDIO_GET_KEEPSETTINGS, &parm)) print_value_on_off("keepsettings", parm); } if (get_nowerr) { - if(!ioctl_or_warn(fd, HDIO_GET_NOWERR, (unsigned long *)parm)) + if(!ioctl_or_warn(fd, HDIO_GET_NOWERR, &parm)) print_value_on_off("nowerr", parm); } if (get_readonly) { - if(!ioctl_or_warn(fd, BLKROGET, (unsigned long *)parm)) + if(!ioctl_or_warn(fd, BLKROGET, &parm)) print_value_on_off("readonly", parm); } if (get_readahead) { - if(!ioctl_or_warn(fd, BLKRAGET, (unsigned long *)parm)) + if(!ioctl_or_warn(fd, BLKRAGET, &parm)) print_value_on_off("readahead", parm); } if (get_geom) { From aldot at busybox.net Sat Jan 19 03:27:40 2008 From: aldot at busybox.net (aldot at busybox.net) Date: Sat, 19 Jan 2008 03:27:40 -0800 (PST) Subject: svn commit: branches/busybox_1_9_stable/miscutils Message-ID: <20080119112740.6BB0F1200FF@busybox.net> Author: aldot Date: 2008-01-19 03:27:40 -0800 (Sat, 19 Jan 2008) New Revision: 20877 Log: - Fix hdparm's ioctl parameter passing (John Brandwood) This was applied to trunk as r20876. Modified: branches/busybox_1_9_stable/miscutils/hdparm.c Changeset: Modified: branches/busybox_1_9_stable/miscutils/hdparm.c =================================================================== --- branches/busybox_1_9_stable