From: Eric Andersen Date: Thu, 19 Jul 2001 22:28:02 +0000 (-0000) Subject: Some adjustments, mostly from David McCullough to X-Git-Tag: 0_60_0~50 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=20aab260e2f7011523402464fb079f48e5899890;p=oweals%2Fbusybox.git Some adjustments, mostly from David McCullough to make busybox be more uClinux friendly. I also adjusted Config.h for uClinux so it will automagically disable apps the arn't going to work without fork() and such. -Erik --- diff --git a/Config.h b/Config.h index 00294f72e..1daf65cc7 100644 --- a/Config.h +++ b/Config.h @@ -417,6 +417,19 @@ // Nothing beyond this point should ever be touched by // mere mortals so leave this stuff alone. // +#include +#if defined __UCLIBC__ && ! defined __UCLIBC_HAS_MMU__ + #undef BB_RPM2CPIO /* Uses gz_open(), which uses fork() */ + #undef BB_DPKG_DEB /* Uses gz_open(), which uses fork() */ + #undef BB_FEATURE_ASH /* Uses fork() */ + #undef BB_FEATURE_HUSH /* Uses fork() */ + #undef BB_FEATURE_LASH /* Uses fork() */ + #undef BB_INIT /* Uses fork() */ + #undef BB_FEATURE_TAR_GZIP /* Uses fork() */ + #undef BB_SYSLOGD /* Uses daemon() */ + #undef BB_KLOGD /* Uses daemon() */ + #undef BB_UPDATE /* Uses daemon() */ +#endif #if defined BB_SH #if defined BB_FEATURE_COMMAND_EDITING #define BB_CMDEDIT diff --git a/Makefile b/Makefile index 2b31895e6..8b4c16fee 100644 --- a/Makefile +++ b/Makefile @@ -396,7 +396,7 @@ clean: docs/busybox.lineo.com/BusyBox.html - rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \ docs/busybox.pdf docs/busybox.lineo.com/busybox.html - - rm -f multibuild.log Config.h.orig + - rm -f multibuild.log Config.h.orig *.gdb *.elf - rm -rf docs/busybox _install libpwd.a libbb.a pod2htm* - rm -f busybox.links libbb/loop.h *~ slist.mk core applet_source_list - find -name \*.o -exec rm -f {} \; diff --git a/coreutils/ls.c b/coreutils/ls.c index bd79cc940..10191476e 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -303,6 +303,7 @@ static struct dnode **dnalloc(int num) return(p); } +#ifdef BB_FEATURE_LS_RECURSIVE static void dfree(struct dnode **dnp) { struct dnode *cur, *next; @@ -318,6 +319,7 @@ static void dfree(struct dnode **dnp) } free(dnp); /* free the array holding the dnode pointers */ } +#endif static struct dnode **splitdnarray(struct dnode **dn, int nfiles, int which) { diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c index 6a3f78a42..6ac9f1bf3 100644 --- a/coreutils/uudecode.c +++ b/coreutils/uudecode.c @@ -207,6 +207,8 @@ static int decode (const char *inname, char buf[2 * BUFSIZ]; char *outname; int do_base64 = 0; + int res; + int dofre; /* Search for header line. */ @@ -226,6 +228,7 @@ static int decode (const char *inname, } /* If the output file name is given on the command line this rules. */ + dofre = FALSE; if (forced_outname != NULL) outname = (char *) forced_outname; else { @@ -248,10 +251,11 @@ static int decode (const char *inname, } n = strlen (pw->pw_dir); n1 = strlen (p); - outname = (char *) alloca ((size_t) (n + n1 + 2)); + outname = (char *) xmalloc ((size_t) (n + n1 + 2)); memcpy (outname + n + 1, p, (size_t) (n1 + 1)); memcpy (outname, pw->pw_dir, (size_t) n); outname[n] = '/'; + dofre = TRUE; } } @@ -261,6 +265,8 @@ static int decode (const char *inname, || chmod (outname, mode & (S_IRWXU | S_IRWXG | S_IRWXO)) )) { perror_msg("%s", outname); /* */ + if (dofre) + free(outname); return FALSE; } @@ -269,9 +275,12 @@ static int decode (const char *inname, /* For each input line: */ if (do_base64) - return read_base64 (inname); + res = read_base64 (inname); else - return read_stduu (inname); + res = read_stduu (inname); + if (dofre) + free(outname); + return res; } int uudecode_main (int argc, diff --git a/editors/vi.c b/editors/vi.c index f75c884eb..cfdc29fcb 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -19,7 +19,7 @@ */ static const char vi_Version[] = - "$Id: vi.c,v 1.12 2001/07/17 01:12:36 andersen Exp $"; + "$Id: vi.c,v 1.13 2001/07/19 22:28:01 andersen Exp $"; /* * To compile for standalone use: @@ -3554,7 +3554,7 @@ static int file_write(Byte * fn, Byte * first, Byte * last) } charcnt = 0; // FIXIT- use the correct umask() - fd = open((char *) fn, (O_RDWR | O_CREAT | O_TRUNC), 0664); + fd = open((char *) fn, (O_WRONLY | O_CREAT | O_TRUNC), 0664); if (fd < 0) return (-1); cnt = last - first + 1; diff --git a/kill.c b/kill.c index 8745f63c1..34cbc4d6a 100644 --- a/kill.c +++ b/kill.c @@ -147,9 +147,8 @@ extern int kill_main(int argc, char **argv) const struct signal_name *s = signames; while (s->name != 0) { - col += - fprintf(stderr, "%2d) %-8s", s->number, - (s++)->name); + col += fprintf(stderr, "%2d) %-8s", s->number, s->name); + s++; if (col > 60) { fprintf(stderr, "\n"); col = 0; diff --git a/libbb/gz_open.c b/libbb/gz_open.c index b23920b16..ef30ff894 100644 --- a/libbb/gz_open.c +++ b/libbb/gz_open.c @@ -15,7 +15,7 @@ extern FILE *gz_open(FILE *compressed_file, int *pid) return(NULL); } if ((*pid = fork()) == -1) { - error_msg("fork failured"); + error_msg("fork failed"); return(NULL); } if (*pid==0) { @@ -29,7 +29,7 @@ extern FILE *gz_open(FILE *compressed_file, int *pid) } close(unzip_pipe[1]); if (unzip_pipe[0] == -1) { - error_msg("Couldnt initialise gzip stream"); + error_msg("gzip stream init failed"); } return(fdopen(unzip_pipe[0], "r")); } diff --git a/libbb/interface.c b/libbb/interface.c index 8eb03a61c..484597c5f 100644 --- a/libbb/interface.c +++ b/libbb/interface.c @@ -3,7 +3,7 @@ * that either displays or sets the characteristics of * one or more of the system's networking interfaces. * - * Version: $Id: interface.c,v 1.3 2001/06/01 21:47:15 andersen Exp $ + * Version: $Id: interface.c,v 1.4 2001/07/19 22:28:02 andersen Exp $ * * Author: Fred N. van Kempen, * and others. Copyright 1993 MicroWalt Corporation @@ -78,7 +78,9 @@ #include #include #include +#if 0 #include +#endif #include "libbb.h" #define _(x) x @@ -455,9 +457,11 @@ static int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in, #ifdef DEBUG fprintf (stderr, "getnetbyaddr (%08lx)\n", host_ad); #endif +#if 0 np = getnetbyaddr(host_ad, AF_INET); if (np != NULL) safe_strncpy(name, np->n_name, len); +#endif } if ((ent == NULL) && (np == NULL)) safe_strncpy(name, inet_ntoa(s_in->sin_addr), len); @@ -1068,7 +1072,6 @@ static int if_readconf(void) struct ifconf ifc; struct ifreq *ifr; int n, err = -1; - /* XXX Should this re-use the global skfd? */ int skfd2; /* SIOCGIFCONF currently seems to only work properly on AF_INET sockets diff --git a/logger.c b/logger.c index b8aae3d28..623a4f9e5 100644 --- a/logger.c +++ b/logger.c @@ -127,14 +127,20 @@ extern int logger_main(int argc, char **argv) } } + openlog(name, option, (pri | LOG_FACMASK)); if (optind == argc) { - /* read from stdin */ - i = 0; - while ((c = getc(stdin)) != EOF && i < sizeof(buf)) { - buf[i++] = c; - } - buf[i++] = '\0'; - message = buf; + do { + /* read from stdin */ + i = 0; + while ((c = getc(stdin)) != EOF && c != '\n' && + i < (sizeof(buf)-1)) { + buf[i++] = c; + } + if (i > 0) { + buf[i++] = '\0'; + syslog(pri, "%s", buf); + } + } while (c != EOF); } else { len = 1; /* for the '\0' */ message=xcalloc(1, 1); @@ -146,12 +152,10 @@ extern int logger_main(int argc, char **argv) strcat(message, " "); } message[strlen(message)-1] = '\0'; + syslog(pri, "%s", message); } - /*openlog(name, option, (pri | LOG_FACMASK)); - syslog(pri, "%s", message); - closelog();*/ - syslog_msg_with_name(name,(pri | LOG_FACMASK),pri,message); + closelog(); return EXIT_SUCCESS; } diff --git a/ls.c b/ls.c index bd79cc940..10191476e 100644 --- a/ls.c +++ b/ls.c @@ -303,6 +303,7 @@ static struct dnode **dnalloc(int num) return(p); } +#ifdef BB_FEATURE_LS_RECURSIVE static void dfree(struct dnode **dnp) { struct dnode *cur, *next; @@ -318,6 +319,7 @@ static void dfree(struct dnode **dnp) } free(dnp); /* free the array holding the dnode pointers */ } +#endif static struct dnode **splitdnarray(struct dnode **dn, int nfiles, int which) { diff --git a/miscutils/update.c b/miscutils/update.c index a6550b05c..603740e38 100644 --- a/miscutils/update.c +++ b/miscutils/update.c @@ -65,46 +65,44 @@ extern int update_main(int argc, char **argv) show_usage(); } } + + if (daemon(0, 1) < 0) + perror_msg_and_die("daemon"); - pid = fork(); - if (pid < 0) - return EXIT_FAILURE; - else if (pid == 0) { - /* Become a proper daemon */ - setsid(); - chdir("/"); + /* Become a proper daemon */ + setsid(); + chdir("/"); #ifdef OPEN_MAX - for (pid = 0; pid < OPEN_MAX; pid++) close(pid); + for (pid = 0; pid < OPEN_MAX; pid++) close(pid); #else - /* glibc 2.1.92 requires using sysconf(_SC_OPEN_MAX) */ - for (pid = 0; pid < sysconf(_SC_OPEN_MAX); pid++) close(pid); + /* glibc 2.1.92 requires using sysconf(_SC_OPEN_MAX) */ + for (pid = 0; pid < sysconf(_SC_OPEN_MAX); pid++) close(pid); #endif - /* - * This is no longer necessary since 1.3.5x, but it will harmlessly - * exit if that is the case. - */ + /* This is no longer necessary since 1.3.5x, but it will harmlessly + * exit if that is the case. + */ - /* set the program name that will show up in a 'ps' listing */ - argv[0] = "bdflush (update)"; - argv[1] = NULL; - argv[2] = NULL; - for (;;) { - if (use_sync) { - sleep(sync_duration); - sync(); - } else { - sleep(flush_duration); - if (bdflush(1, 0) < 0) { - openlog("update", LOG_CONS, LOG_DAEMON); - syslog(LOG_INFO, - "This kernel does not need update(8). Exiting."); - closelog(); - return EXIT_SUCCESS; - } + /* set the program name that will show up in a 'ps' listing */ + argv[0] = "bdflush (update)"; + argv[1] = NULL; + argv[2] = NULL; + for (;;) { + if (use_sync) { + sleep(sync_duration); + sync(); + } else { + sleep(flush_duration); + if (bdflush(1, 0) < 0) { + openlog("update", LOG_CONS, LOG_DAEMON); + syslog(LOG_INFO, + "This kernel does not need update(8). Exiting."); + closelog(); + return EXIT_SUCCESS; } } } + return EXIT_SUCCESS; } diff --git a/networking/wget.c b/networking/wget.c index 009e0c819..59373d1d9 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -56,12 +56,12 @@ static void parse_url(char *url, struct host_info *h); static FILE *open_socket(char *host, int port); static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc); static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf); -static void progressmeter(int flag); /* Globals (can be accessed from signal handlers */ static off_t filesize = 0; /* content-length of the file */ static int chunked = 0; /* chunked transfer encoding */ #ifdef BB_FEATURE_WGET_STATUSBAR +static void progressmeter(int flag); static char *curfile; /* Name of current file being transferred. */ static struct timeval start; /* Time a transfer started. */ static volatile unsigned long statbytes = 0; /* Number of bytes transferred so far. */ @@ -817,7 +817,7 @@ progressmeter(int flag) * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: wget.c,v 1.44 2001/07/19 19:13:55 kraai Exp $ + * $Id: wget.c,v 1.45 2001/07/19 22:28:01 andersen Exp $ */ diff --git a/procps/kill.c b/procps/kill.c index 8745f63c1..34cbc4d6a 100644 --- a/procps/kill.c +++ b/procps/kill.c @@ -147,9 +147,8 @@ extern int kill_main(int argc, char **argv) const struct signal_name *s = signames; while (s->name != 0) { - col += - fprintf(stderr, "%2d) %-8s", s->number, - (s++)->name); + col += fprintf(stderr, "%2d) %-8s", s->number, s->name); + s++; if (col > 60) { fprintf(stderr, "\n"); col = 0; diff --git a/sysklogd/logger.c b/sysklogd/logger.c index b8aae3d28..623a4f9e5 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c @@ -127,14 +127,20 @@ extern int logger_main(int argc, char **argv) } } + openlog(name, option, (pri | LOG_FACMASK)); if (optind == argc) { - /* read from stdin */ - i = 0; - while ((c = getc(stdin)) != EOF && i < sizeof(buf)) { - buf[i++] = c; - } - buf[i++] = '\0'; - message = buf; + do { + /* read from stdin */ + i = 0; + while ((c = getc(stdin)) != EOF && c != '\n' && + i < (sizeof(buf)-1)) { + buf[i++] = c; + } + if (i > 0) { + buf[i++] = '\0'; + syslog(pri, "%s", buf); + } + } while (c != EOF); } else { len = 1; /* for the '\0' */ message=xcalloc(1, 1); @@ -146,12 +152,10 @@ extern int logger_main(int argc, char **argv) strcat(message, " "); } message[strlen(message)-1] = '\0'; + syslog(pri, "%s", message); } - /*openlog(name, option, (pri | LOG_FACMASK)); - syslog(pri, "%s", message); - closelog();*/ - syslog_msg_with_name(name,(pri | LOG_FACMASK),pri,message); + closelog(); return EXIT_SUCCESS; } diff --git a/update.c b/update.c index a6550b05c..603740e38 100644 --- a/update.c +++ b/update.c @@ -65,46 +65,44 @@ extern int update_main(int argc, char **argv) show_usage(); } } + + if (daemon(0, 1) < 0) + perror_msg_and_die("daemon"); - pid = fork(); - if (pid < 0) - return EXIT_FAILURE; - else if (pid == 0) { - /* Become a proper daemon */ - setsid(); - chdir("/"); + /* Become a proper daemon */ + setsid(); + chdir("/"); #ifdef OPEN_MAX - for (pid = 0; pid < OPEN_MAX; pid++) close(pid); + for (pid = 0; pid < OPEN_MAX; pid++) close(pid); #else - /* glibc 2.1.92 requires using sysconf(_SC_OPEN_MAX) */ - for (pid = 0; pid < sysconf(_SC_OPEN_MAX); pid++) close(pid); + /* glibc 2.1.92 requires using sysconf(_SC_OPEN_MAX) */ + for (pid = 0; pid < sysconf(_SC_OPEN_MAX); pid++) close(pid); #endif - /* - * This is no longer necessary since 1.3.5x, but it will harmlessly - * exit if that is the case. - */ + /* This is no longer necessary since 1.3.5x, but it will harmlessly + * exit if that is the case. + */ - /* set the program name that will show up in a 'ps' listing */ - argv[0] = "bdflush (update)"; - argv[1] = NULL; - argv[2] = NULL; - for (;;) { - if (use_sync) { - sleep(sync_duration); - sync(); - } else { - sleep(flush_duration); - if (bdflush(1, 0) < 0) { - openlog("update", LOG_CONS, LOG_DAEMON); - syslog(LOG_INFO, - "This kernel does not need update(8). Exiting."); - closelog(); - return EXIT_SUCCESS; - } + /* set the program name that will show up in a 'ps' listing */ + argv[0] = "bdflush (update)"; + argv[1] = NULL; + argv[2] = NULL; + for (;;) { + if (use_sync) { + sleep(sync_duration); + sync(); + } else { + sleep(flush_duration); + if (bdflush(1, 0) < 0) { + openlog("update", LOG_CONS, LOG_DAEMON); + syslog(LOG_INFO, + "This kernel does not need update(8). Exiting."); + closelog(); + return EXIT_SUCCESS; } } } + return EXIT_SUCCESS; } diff --git a/uudecode.c b/uudecode.c index 6a3f78a42..6ac9f1bf3 100644 --- a/uudecode.c +++ b/uudecode.c @@ -207,6 +207,8 @@ static int decode (const char *inname, char buf[2 * BUFSIZ]; char *outname; int do_base64 = 0; + int res; + int dofre; /* Search for header line. */ @@ -226,6 +228,7 @@ static int decode (const char *inname, } /* If the output file name is given on the command line this rules. */ + dofre = FALSE; if (forced_outname != NULL) outname = (char *) forced_outname; else { @@ -248,10 +251,11 @@ static int decode (const char *inname, } n = strlen (pw->pw_dir); n1 = strlen (p); - outname = (char *) alloca ((size_t) (n + n1 + 2)); + outname = (char *) xmalloc ((size_t) (n + n1 + 2)); memcpy (outname + n + 1, p, (size_t) (n1 + 1)); memcpy (outname, pw->pw_dir, (size_t) n); outname[n] = '/'; + dofre = TRUE; } } @@ -261,6 +265,8 @@ static int decode (const char *inname, || chmod (outname, mode & (S_IRWXU | S_IRWXG | S_IRWXO)) )) { perror_msg("%s", outname); /* */ + if (dofre) + free(outname); return FALSE; } @@ -269,9 +275,12 @@ static int decode (const char *inname, /* For each input line: */ if (do_base64) - return read_base64 (inname); + res = read_base64 (inname); else - return read_stduu (inname); + res = read_stduu (inname); + if (dofre) + free(outname); + return res; } int uudecode_main (int argc, diff --git a/vi.c b/vi.c index f75c884eb..cfdc29fcb 100644 --- a/vi.c +++ b/vi.c @@ -19,7 +19,7 @@ */ static const char vi_Version[] = - "$Id: vi.c,v 1.12 2001/07/17 01:12:36 andersen Exp $"; + "$Id: vi.c,v 1.13 2001/07/19 22:28:01 andersen Exp $"; /* * To compile for standalone use: @@ -3554,7 +3554,7 @@ static int file_write(Byte * fn, Byte * first, Byte * last) } charcnt = 0; // FIXIT- use the correct umask() - fd = open((char *) fn, (O_RDWR | O_CREAT | O_TRUNC), 0664); + fd = open((char *) fn, (O_WRONLY | O_CREAT | O_TRUNC), 0664); if (fd < 0) return (-1); cnt = last - first + 1; diff --git a/wget.c b/wget.c index 009e0c819..59373d1d9 100644 --- a/wget.c +++ b/wget.c @@ -56,12 +56,12 @@ static void parse_url(char *url, struct host_info *h); static FILE *open_socket(char *host, int port); static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc); static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf); -static void progressmeter(int flag); /* Globals (can be accessed from signal handlers */ static off_t filesize = 0; /* content-length of the file */ static int chunked = 0; /* chunked transfer encoding */ #ifdef BB_FEATURE_WGET_STATUSBAR +static void progressmeter(int flag); static char *curfile; /* Name of current file being transferred. */ static struct timeval start; /* Time a transfer started. */ static volatile unsigned long statbytes = 0; /* Number of bytes transferred so far. */ @@ -817,7 +817,7 @@ progressmeter(int flag) * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: wget.c,v 1.44 2001/07/19 19:13:55 kraai Exp $ + * $Id: wget.c,v 1.45 2001/07/19 22:28:01 andersen Exp $ */