Some adjustments, mostly from David McCullough <davidm@lineo.com> 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
This commit is contained in:
Eric Andersen 2001-07-19 22:28:02 +00:00
parent 0382eb8865
commit 20aab260e2
18 changed files with 149 additions and 109 deletions

View File

@ -417,6 +417,19 @@
// Nothing beyond this point should ever be touched by
// mere mortals so leave this stuff alone.
//
#include <features.h>
#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

View File

@ -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 {} \;

View File

@ -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)
{

View File

@ -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,

View File

@ -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;

5
kill.c
View File

@ -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;

View File

@ -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"));
}

View File

@ -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, <waltje@uwalt.nl.mugnet.org>
* and others. Copyright 1993 MicroWalt Corporation
@ -78,7 +78,9 @@
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#if 0
#include <arpa/nameser.h>
#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

View File

@ -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;
}

2
ls.c
View File

@ -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)
{

View File

@ -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;
}

View File

@ -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 $
*/

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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,

4
vi.c
View File

@ -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;

4
wget.c
View File

@ -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 $
*/