#define bb_need_name_too_long
#endif
#define bb_need_memory_exhausted
+#define bb_need_full_version
#define BB_DECLARE_EXTERN
#include "messages.c"
#include <utime.h>
#include <unistd.h>
#include <ctype.h>
-#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/utsname.h> /* for uname(2) */
#if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF
-# if defined BB_FEATURE_USE_PROCFS
-const char mtab_file[] = "/proc/mounts";
-# else
-# if defined BB_MTAB
+# if defined BB_MTAB
const char mtab_file[] = "/etc/mtab";
+# else
+# if defined BB_FEATURE_USE_PROCFS
+const char mtab_file[] = "/proc/mounts";
# else
# if defined BB_FEATURE_USE_DEVPS_PATCH
const char mtab_file[] = "/dev/mtab";
extern void usage(const char *usage)
{
- fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
- BB_VER, BB_BT);
+ fprintf(stderr, "%s\n\n", full_version);
fprintf(stderr, "Usage: %s\n", usage);
exit FALSE;
}
const char *, fstype, unsigned long int, rwflag, const void *, data);
#endif
+#if defined BB_INSMOD || defined BB_LSMOD
+#ifndef __NR_query_module
+#define __NR_query_module 167
+#endif
+_syscall5(int, query_module, const char *, name, int, which,
+ void *, buf, size_t, bufsize, size_t*, ret);
+#endif
#if defined (BB_CP_MV) || defined (BB_DU)
}
#endif
+#if defined (BB_AR) || defined BB_CP_MV
+/*
+ * Copy readSize bytes between two file descriptors
+ */
+int copySubFile(int srcFd, int dstFd, size_t remaining)
+{
+ size_t size;
+ char buffer[BUFSIZ];
+
+ while (remaining > 0) {
+ if (remaining > BUFSIZ)
+ size = BUFSIZ;
+ else
+ size = remaining;
+ if (fullWrite(dstFd, buffer, fullRead(srcFd, buffer, size)) < size)
+ return(FALSE);
+ remaining -= size;
+ }
+ return (TRUE);
+}
+#endif
+
+
#if defined (BB_CP_MV)
/*
* Copy one file to another, while possibly preserving its modes, times, and
{
int rfd;
int wfd;
- int rcc;
int status;
- char buf[BUF_SIZE];
struct stat srcStatBuf;
struct stat dstStatBuf;
struct utimbuf times;
return FALSE;
}
- wfd =
- open(destName, O_WRONLY | O_CREAT | O_TRUNC,
+ wfd = open(destName, O_WRONLY | O_CREAT | O_TRUNC,
srcStatBuf.st_mode);
if (wfd < 0) {
perror(destName);
return FALSE;
}
- while ((rcc = read(rfd, buf, sizeof(buf))) > 0) {
- if (fullWrite(wfd, buf, rcc) < 0)
- goto error_exit;
- }
- if (rcc < 0) {
- goto error_exit;
- }
-
+ if (copySubFile(rfd, wfd, srcStatBuf.st_size)==FALSE)
+ goto error_exit;
+
close(rfd);
if (close(wfd) < 0) {
return FALSE;
-#if defined BB_TAR || defined BB_LS
+#if defined BB_TAR || defined BB_LS ||defined BB_AR
#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
return buf;
}
-#endif /* BB_TAR */
+#endif /* BB_TAR || BB_AR */
#if defined BB_TAR || defined BB_CP_MV || defined BB_AR
/*
return total;
}
-#endif /* BB_TAR || BB_CP_MV */
+#endif /* BB_TAR || BB_CP_MV || BB_AR */
-#if defined BB_TAR || defined BB_TAIL || defined BB_AR
+#if defined BB_TAR || defined BB_TAIL || defined BB_AR || defined BB_SH || defined BB_CP_MV
/*
* Read all of the supplied buffer from a file.
* This does multiple reads as necessary.
return total;
}
-#endif /* BB_TAR || BB_TAIL */
+#endif /* BB_TAR || BB_TAIL || BB_AR || BB_SH */
#if defined (BB_CHMOD_CHOWN_CHGRP) \
status =
recursiveAction(nextFile, TRUE, followLinks, depthFirst,
fileAction, dirAction, userData);
- if (status < 0) {
+ if (status == FALSE) {
closedir(dir);
return FALSE;
}
#if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_MKDIR) \
- || defined (BB_MKFIFO) || defined (BB_MKNOD)
+ || defined (BB_MKFIFO) || defined (BB_MKNOD) || defined (BB_AR)
/* [ugoa]{+|-|=}[rwxst] */
char type;
char c;
+ if (s==NULL)
+ return (FALSE);
+
do {
for (;;) {
switch (c = *s++) {
#endif /* BB_CHVT || BB_DEALLOCVT || BB_SETKEYCODES */
-#if !defined BB_REGEXP && (defined BB_GREP || defined BB_SED)
-
-/* Do a case insensitive strstr() */
-char *stristr(char *haystack, const char *needle)
-{
- int len = strlen(needle);
-
- while (*haystack) {
- if (!strncasecmp(haystack, needle, len))
- break;
- haystack++;
- }
-
- if (!(*haystack))
- haystack = NULL;
-
- return haystack;
-}
-
-/* This tries to find a needle in a haystack, but does so by
- * only trying to match literal strings (look 'ma, no regexps!)
- * This is short, sweet, and carries _very_ little baggage,
- * unlike its beefier cousin in regexp.c
- * -Erik Andersen
- */
-extern int find_match(char *haystack, char *needle, int ignoreCase)
-{
-
- if (ignoreCase == FALSE)
- haystack = strstr(haystack, needle);
- else
- haystack = stristr(haystack, needle);
- if (haystack == NULL)
- return FALSE;
- return TRUE;
-}
-
-
-/* This performs substitutions after a string match has been found. */
-extern int replace_match(char *haystack, char *needle, char *newNeedle,
- int ignoreCase)
-{
- int foundOne = 0;
- char *where, *slider, *slider1, *oldhayStack;
-
- if (ignoreCase == FALSE)
- where = strstr(haystack, needle);
- else
- where = stristr(haystack, needle);
-
- if (strcmp(needle, newNeedle) == 0)
- return FALSE;
-
- oldhayStack = (char *) xmalloc((unsigned) (strlen(haystack)));
- while (where != NULL) {
- foundOne++;
- strcpy(oldhayStack, haystack);
- for (slider = haystack, slider1 = oldhayStack; slider != where;
- slider++, slider1++);
- *slider = 0;
- haystack = strcat(haystack, newNeedle);
- slider1 += strlen(needle);
- haystack = strcat(haystack, slider1);
- where = strstr(slider, needle);
- }
- free(oldhayStack);
-
- if (foundOne > 0)
- return TRUE;
- else
- return FALSE;
-}
-
-#endif /* ! BB_REGEXP && (BB_GREP || BB_SED) */
-
-
#if defined BB_FIND || defined BB_INSMOD
/*
* Routine to see if a text string is matched by a wildcard pattern.
#endif /* BB_DD || BB_TAIL */
-#if defined BB_INIT || defined BB_SYSLOGD || defined BB_AR
+#if defined BB_INIT || defined BB_SYSLOGD
/* try to open up the specified device */
extern int device_open(char *device, int mode)
{
* some new processes start up while we wait. The kernel will
* just ignore any extras if we give it too many, and will trunc.
* the list if we give it too few. */
- pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
+ pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
pid_array[0] = num_pids+10;
/* Now grab the pid list */
if ((strstr(info.command_line, pidName) != NULL)
&& (strlen(pidName) == strlen(info.command_line))) {
- pidList=realloc( pidList, sizeof(pid_t) * (j+2));
- if (pidList==NULL)
- fatalError(memory_exhausted);
+ pidList=xrealloc( pidList, sizeof(pid_t) * (j+2));
pidList[j++]=info.pid;
}
}
FILE *status;
char filename[256];
char buffer[256];
- char* p;
/* If it isn't a number, we don't want it */
if (!isdigit(*next->d_name))
continue;
- /* Now open the status file */
- sprintf(filename, "/proc/%s/status", next->d_name);
+ sprintf(filename, "/proc/%s/cmdline", next->d_name);
status = fopen(filename, "r");
if (!status) {
continue;
fgets(buffer, 256, status);
fclose(status);
- /* Make sure we only match on the process name */
- p=buffer+5; /* Skip the name */
- while ((p)++) {
- if (*p==0 || *p=='\n') {
- *p='\0';
- break;
- }
- }
- p=buffer+6; /* Skip the "Name:\t" */
-
- if ((strstr(p, pidName) != NULL)
- && (strlen(pidName) == strlen(p))) {
- pidList=realloc( pidList, sizeof(pid_t) * (i+2));
- if (pidList==NULL)
- fatalError(memory_exhausted);
+ if (strstr(get_last_path_component(buffer), pidName) != NULL) {
+ pidList=xrealloc( pidList, sizeof(pid_t) * (i+2));
pidList[i++]=strtol(next->d_name, NULL, 0);
}
}
+
if (pidList)
pidList[i]=0;
return pidList;
#endif /* BB_FEATURE_USE_DEVPS_PATCH */
#endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */
+#ifndef DMALLOC
/* this should really be farmed out to libbusybox.a */
extern void *xmalloc(size_t size)
{
- void *cp = malloc(size);
+ void *ptr = malloc(size);
- if (cp == NULL)
+ if (!ptr)
fatalError(memory_exhausted);
- return cp;
+ return ptr;
}
-#if defined BB_FEATURE_NFSMOUNT
+extern void *xrealloc(void *old, size_t size)
+{
+ void *ptr = realloc(old, size);
+ if (!ptr)
+ fatalError(memory_exhausted);
+ return ptr;
+}
+
+extern void *xcalloc(size_t nmemb, size_t size)
+{
+ void *ptr = calloc(nmemb, size);
+ if (!ptr)
+ fatalError(memory_exhausted);
+ return ptr;
+}
+#endif
+
+#if defined BB_FEATURE_NFSMOUNT || defined BB_SH || defined BB_LS
+# ifndef DMALLOC
extern char * xstrdup (const char *s) {
char *t;
return t;
}
+# endif
+#endif
+#if defined BB_FEATURE_NFSMOUNT
extern char * xstrndup (const char *s, int n) {
char *t;
if (strcmp(entry->d_name, "..") == 0)
continue;
- sprintf( fileName, "/dev/%s", entry->d_name);
+ snprintf( fileName, strlen(name)+1, "/dev/%s", entry->d_name);
if (stat(fileName, &statBuf) != 0)
continue;
break;
/* grow the line buffer as necessary */
if (idx > linebufsz-2)
- linebuf = realloc(linebuf, linebufsz += GROWBY);
+ linebuf = xrealloc(linebuf, linebufsz += GROWBY);
linebuf[idx++] = (char)ch;
if ((char)ch == '\n')
break;
return linebuf;
}
+#if defined BB_CAT || defined BB_LSMOD
+extern void print_file(FILE *file)
+{
+ int c;
+
+ while ((c = getc(file)) != EOF)
+ putc(c, stdout);
+ fclose(file);
+ fflush(stdout);
+}
+
+extern int print_file_by_name(char *filename)
+{
+ FILE *file;
+ file = fopen(filename, "r");
+ if (file == NULL) {
+ return FALSE;
+ }
+ print_file(file);
+ return TRUE;
+}
+#endif /* BB_CAT || BB_LSMOD */
+
#if defined BB_ECHO || defined BB_TR
char process_escape_sequence(char **ptr)
{
}
#endif
-#if defined BB_BASENAME || defined BB_LN
+#if defined BB_BASENAME || defined BB_LN || defined BB_SH
char *get_last_path_component(char *path)
{
char *s=path+strlen(path)-1;