#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
-#ifndef major
+#if !defined(major) || defined(__GLIBC__)
# include <sys/sysmacros.h>
#endif
#include <sys/wait.h>
#if ENABLE_SELINUX
# include <selinux/selinux.h>
# include <selinux/context.h>
-# include <selinux/flask.h>
-# include <selinux/av_permissions.h>
#endif
#if ENABLE_FEATURE_UTMP
# if defined __UCLIBC__ && ( \
# include <netinet/in.h>
#else
# include <arpa/inet.h>
-# if !defined(__socklen_t_defined) && !defined(_SOCKLEN_T_DECLARED)
-/* We #define socklen_t *after* includes, otherwise we get
- * typedef redefinition errors from system headers
- * (in case "is it defined already" detection above failed)
- */
-# define socklen_t bb_socklen_t
- typedef unsigned socklen_t;
-# endif
+//This breaks on bionic:
+//# if !defined(__socklen_t_defined) && !defined(_SOCKLEN_T_DECLARED)
+///* We #define socklen_t *after* includes, otherwise we get
+// * typedef redefinition errors from system headers
+// * (in case "is it defined already" detection above failed)
+// */
+//# define socklen_t bb_socklen_t
+// typedef unsigned socklen_t;
+//# endif
+//if this is still needed, add a fix along the lines of
+// ifdef SPECIFIC_BROKEN_LIBC_CHECK / typedef socklen_t / endif
+//in platform.h instead!
#endif
#ifndef HAVE_CLEARENV
# define clearenv() do { if (environ) environ[0] = NULL; } while (0)
/* Busybox does not use threads, we can speed up stdio. */
#ifdef HAVE_UNLOCKED_STDIO
# undef getc
-# define getc(stream) getc_unlocked(stream)
+# define getc(stream) getc_unlocked(stream)
# undef getchar
-# define getchar() getchar_unlocked()
+# define getchar() getchar_unlocked()
# undef putc
-# define putc(c, stream) putc_unlocked(c, stream)
+# define putc(c,stream) putc_unlocked(c,stream)
# undef putchar
-# define putchar(c) putchar_unlocked(c)
+# define putchar(c) putchar_unlocked(c)
# undef fgetc
-# define fgetc(stream) getc_unlocked(stream)
+# define fgetc(stream) getc_unlocked(stream)
# undef fputc
-# define fputc(c, stream) putc_unlocked(c, stream)
+# define fputc(c,stream) putc_unlocked(c,stream)
#endif
/* Above functions are required by POSIX.1-2008, below ones are extensions */
#ifdef HAVE_UNLOCKED_LINE_OPS
# undef fgets
-# define fgets(s, n, stream) fgets_unlocked(s, n, stream)
+# define fgets(s,n,stream) fgets_unlocked(s,n,stream)
# undef fputs
-# define fputs(s, stream) fputs_unlocked(s, stream)
+# define fputs(s,stream) fputs_unlocked(s,stream)
+/* musl <= 1.1.15 does not support fflush_unlocked(NULL) */
+//# undef fflush
+//# define fflush(stream) fflush_unlocked(stream)
+# undef feof
+# define feof(stream) feof_unlocked(stream)
+# undef ferror
+# define ferror(stream) ferror_unlocked(stream)
+# undef fileno
+# define fileno(stream) fileno_unlocked(stream)
#endif
//TODO: supply a pointer to char[11] buffer (avoid statics)?
extern const char *bb_mode_string(mode_t mode) FAST_FUNC;
extern int is_directory(const char *name, int followLinks) FAST_FUNC;
-enum { /* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depend on them. */
+enum { /* cp.c, mv.c, install.c depend on these values. CAREFUL when changing them! */
FILEUTILS_PRESERVE_STATUS = 1 << 0, /* -p */
FILEUTILS_DEREFERENCE = 1 << 1, /* !-d */
FILEUTILS_RECUR = 1 << 2, /* -R */
FILEUTILS_MAKE_SOFTLINK = 1 << 6, /* -s */
FILEUTILS_DEREF_SOFTLINK = 1 << 7, /* -L */
FILEUTILS_DEREFERENCE_L0 = 1 << 8, /* -H */
+ /* -a = -pdR (mapped in cp.c) */
+ /* -r = -dR (mapped in cp.c) */
+ /* -P = -d (mapped in cp.c) */
+ FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE, /* -v */
+ FILEUTILS_UPDATE = 1 << 13, /* -u */
+#if ENABLE_SELINUX
+ FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 14, /* -c */
+#endif
+ FILEUTILS_RMDEST = 1 << (15 - !ENABLE_SELINUX), /* --remove-destination */
+ /*
+ * Hole. cp may have some bits set here,
+ * they should not affect remove_file()/copy_file()
+ */
#if ENABLE_SELINUX
- FILEUTILS_PRESERVE_SECURITY_CONTEXT = 1 << 9, /* -c */
- FILEUTILS_SET_SECURITY_CONTEXT = 1 << 10,
+ FILEUTILS_SET_SECURITY_CONTEXT = 1 << 30,
#endif
- FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11,
- /* -v */
- FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE,
+ FILEUTILS_IGNORE_CHMOD_ERR = 1 << 31,
};
-#define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c")
+#define FILEUTILS_CP_OPTSTR "pdRfilsLHarPvu" IF_SELINUX("c")
extern int remove_file(const char *path, int flags) FAST_FUNC;
/* NB: without FILEUTILS_RECUR in flags, it will basically "cat"
* the source, not copy (unless "source" is a directory).
void xsetegid(gid_t egid) FAST_FUNC;
void xseteuid(uid_t euid) FAST_FUNC;
void xchdir(const char *path) FAST_FUNC;
+void xfchdir(int fd) FAST_FUNC;
void xchroot(const char *path) FAST_FUNC;
void xsetenv(const char *key, const char *value) FAST_FUNC;
void bb_unsetenv(const char *key) FAST_FUNC;
#define BB_EXECVP(prog,cmd) execvp(prog,cmd)
#define BB_EXECLP(prog,cmd,...) execlp(prog,cmd,__VA_ARGS__)
#endif
-int BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC;
+void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC;
+void exec_prog_or_SHELL(char **argv) NORETURN FAST_FUNC;
-/* xvfork() can't be a _function_, return after vfork mangles stack
+/* xvfork() can't be a _function_, return after vfork in child mangles stack
* in the parent. It must be a macro. */
#define xvfork() \
({ \
#if BB_MMU
pid_t xfork(void) FAST_FUNC;
#endif
+void xvfork_parent_waits_and_exits(void) FAST_FUNC;
/* NOMMU friendy fork+exec: */
pid_t spawn(char **argv) FAST_FUNC;
* if (rc > 0) bb_error_msg("exit code: %d", rc & 0xff);
*/
int wait4pid(pid_t pid) FAST_FUNC;
+int wait_for_exitstatus(pid_t pid) FAST_FUNC;
/* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */
int spawn_and_wait(char **argv) FAST_FUNC;
/* Does NOT check that applet is NOFORK, just blindly runs it */
extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
extern void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
extern void bb_perror_nomsg(void) FAST_FUNC;
-extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
extern void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC;
extern void bb_logenv_override(void) FAST_FUNC;
/* If shell needs them, they exist even if not enabled as applets */
int echo_main(int argc, char** argv) IF_ECHO(MAIN_EXTERNALLY_VISIBLE);
int printf_main(int argc, char **argv) IF_PRINTF(MAIN_EXTERNALLY_VISIBLE);
-int test_main(int argc, char **argv) IF_TEST(MAIN_EXTERNALLY_VISIBLE);
-int kill_main(int argc, char **argv) IF_KILL(MAIN_EXTERNALLY_VISIBLE);
+int test_main(int argc, char **argv)
+#if ENABLE_TEST || ENABLE_TEST1 || ENABLE_TEST2
+ MAIN_EXTERNALLY_VISIBLE
+#endif
+;
+int kill_main(int argc, char **argv)
+#if ENABLE_KILL || ENABLE_KILLALL || ENABLE_KILLALL5
+ MAIN_EXTERNALLY_VISIBLE
+#endif
+;
/* Similar, but used by chgrp, not shell */
int chown_main(int argc, char **argv) IF_CHOWN(MAIN_EXTERNALLY_VISIBLE);
/* Used by ftpd */
#ifndef BUILD_INDIVIDUAL
extern int find_applet_by_name(const char *name) FAST_FUNC;
-/* Returns only if applet is not found. */
-extern void run_applet_and_exit(const char *name, char **argv) FAST_FUNC;
extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC;
#endif
#endif
extern void bb_do_delay(int seconds) FAST_FUNC;
extern void change_identity(const struct passwd *pw) FAST_FUNC;
-extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) NORETURN FAST_FUNC;
+extern void run_shell(const char *shell, int loginshell, const char **args) NORETURN FAST_FUNC;
/* Returns $SHELL, getpwuid(getuid())->pw_shell, or DEFAULT_SHELL.
* Note that getpwuid result might need xstrdup'ing
* yet doesn't represent any valid Unicode character.
* Also, -1 is reserved for error indication and we don't use it. */
enum {
- KEYCODE_UP = -2,
- KEYCODE_DOWN = -3,
- KEYCODE_RIGHT = -4,
- KEYCODE_LEFT = -5,
- KEYCODE_HOME = -6,
- KEYCODE_END = -7,
- KEYCODE_INSERT = -8,
- KEYCODE_DELETE = -9,
- KEYCODE_PAGEUP = -10,
- KEYCODE_PAGEDOWN = -11,
- // -12 is reserved for Alt/Ctrl/Shift-TAB
+ KEYCODE_UP = -2,
+ KEYCODE_DOWN = -3,
+ KEYCODE_RIGHT = -4,
+ KEYCODE_LEFT = -5,
+ KEYCODE_HOME = -6,
+ KEYCODE_END = -7,
+ KEYCODE_INSERT = -8,
+ KEYCODE_DELETE = -9,
+ KEYCODE_PAGEUP = -10,
+ KEYCODE_PAGEDOWN = -11,
+ KEYCODE_BACKSPACE = -12, /* Used only if Alt/Ctrl/Shifted */
+ KEYCODE_D = -13, /* Used only if Alted */
#if 0
- KEYCODE_FUN1 = -13,
- KEYCODE_FUN2 = -14,
- KEYCODE_FUN3 = -15,
- KEYCODE_FUN4 = -16,
- KEYCODE_FUN5 = -17,
- KEYCODE_FUN6 = -18,
- KEYCODE_FUN7 = -19,
- KEYCODE_FUN8 = -20,
- KEYCODE_FUN9 = -21,
- KEYCODE_FUN10 = -22,
- KEYCODE_FUN11 = -23,
- KEYCODE_FUN12 = -24,
-#endif
- /* Be sure that last defined value is small enough
- * to not interfere with Alt/Ctrl/Shift bits.
- * So far we do not exceed -31 (0xfff..fffe1),
- * which gives us three upper bits in LSB to play with.
+ KEYCODE_FUN1 = ,
+ KEYCODE_FUN2 = ,
+ KEYCODE_FUN3 = ,
+ KEYCODE_FUN4 = ,
+ KEYCODE_FUN5 = ,
+ KEYCODE_FUN6 = ,
+ KEYCODE_FUN7 = ,
+ KEYCODE_FUN8 = ,
+ KEYCODE_FUN9 = ,
+ KEYCODE_FUN10 = ,
+ KEYCODE_FUN11 = ,
+ KEYCODE_FUN12 = ,
+#endif
+ /* ^^^^^ Be sure that last defined value is small enough.
+ * Current read_key() code allows going up to -32 (0xfff..fffe0).
+ * This gives three upper bits in LSB to play with:
+ * KEYCODE_foo values are 0xfff..fffXX, lowest XX bits are: scavvvvv,
+ * s=0 if SHIFT, c=0 if CTRL, a=0 if ALT,
+ * vvvvv bits are the same for same key regardless of "shift bits".
*/
- //KEYCODE_SHIFT_TAB = (-12) & ~0x80,
- //KEYCODE_SHIFT_... = KEYCODE_... & ~0x80,
- //KEYCODE_CTRL_UP = KEYCODE_UP & ~0x40,
- //KEYCODE_CTRL_DOWN = KEYCODE_DOWN & ~0x40,
- KEYCODE_CTRL_RIGHT = KEYCODE_RIGHT & ~0x40,
- KEYCODE_CTRL_LEFT = KEYCODE_LEFT & ~0x40,
- //KEYCODE_ALT_UP = KEYCODE_UP & ~0x20,
- //KEYCODE_ALT_DOWN = KEYCODE_DOWN & ~0x20,
- KEYCODE_ALT_RIGHT = KEYCODE_RIGHT & ~0x20,
- KEYCODE_ALT_LEFT = KEYCODE_LEFT & ~0x20,
+ //KEYCODE_SHIFT_... = KEYCODE_... & ~0x80,
+ KEYCODE_CTRL_RIGHT = KEYCODE_RIGHT & ~0x40,
+ KEYCODE_CTRL_LEFT = KEYCODE_LEFT & ~0x40,
+ KEYCODE_ALT_RIGHT = KEYCODE_RIGHT & ~0x20,
+ KEYCODE_ALT_LEFT = KEYCODE_LEFT & ~0x20,
+ KEYCODE_ALT_BACKSPACE = KEYCODE_BACKSPACE & ~0x20,
+ KEYCODE_ALT_D = KEYCODE_D & ~0x20,
KEYCODE_CURSOR_POS = -0x100, /* 0xfff..fff00 */
/* How long is the longest ESC sequence we know?
typedef struct sha3_ctx_t {
uint64_t state[25];
unsigned bytes_queued;
+ unsigned input_block_bytes;
} sha3_ctx_t;
void md5_begin(md5_ctx_t *ctx) FAST_FUNC;
void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
uoff_t transferred,
uoff_t totalsize) FAST_FUNC;
+unsigned ubi_devnum_from_devname(const char *str) FAST_FUNC;
+int ubi_get_volid_by_name(unsigned ubi_devnum, const char *vol_name) FAST_FUNC;
+
extern const char *applet_name;
extern const int const_int_0;
//extern const int const_int_1;
-
-/* Providing hard guarantee on minimum size (think of BUFSIZ == 128) */
-enum { COMMON_BUFSIZE = (BUFSIZ >= 256*sizeof(void*) ? BUFSIZ+1 : 256*sizeof(void*)) };
-extern char bb_common_bufsiz1[COMMON_BUFSIZE];
/* This struct is deliberately not defined. */
/* See docs/keep_data_small.txt */
struct globals;