Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (7 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/include/libbb.h

    r2725 r3232  
    2121#include <setjmp.h>
    2222#include <signal.h>
     23#if defined __UCLIBC__ /* TODO: and glibc? */
     24/* use inlined versions of these: */
     25# define sigfillset(s)    __sigfillset(s)
     26# define sigemptyset(s)   __sigemptyset(s)
     27# define sigisemptyset(s) __sigisemptyset(s)
     28#endif
    2329#include <stdint.h>
    2430#include <stdio.h>
     
    2733#include <stddef.h>
    2834#include <string.h>
     35/* There are two incompatible basename's, let not use them! */
     36/* See the dirname/basename man page for details */
     37#include <libgen.h> /* dirname,basename */
     38#undef basename
     39#define basename dont_use_basename
    2940#include <sys/poll.h>
    3041#include <sys/ioctl.h>
     
    3445#include <sys/time.h>
    3546#include <sys/types.h>
     47#ifndef major
     48# include <sys/sysmacros.h>
     49#endif
    3650#include <sys/wait.h>
    3751#include <termios.h>
    3852#include <time.h>
    39 #include <unistd.h>
    4053#include <sys/param.h>
    41 #ifdef HAVE_MNTENT_H
    42 # include <mntent.h>
    43 #endif
    44 #ifdef HAVE_SYS_STATFS_H
    45 # include <sys/statfs.h>
    46 #endif
    47 #if ENABLE_SELINUX
    48 # include <selinux/selinux.h>
    49 # include <selinux/context.h>
    50 # include <selinux/flask.h>
    51 # include <selinux/av_permissions.h>
    52 #endif
    53 #if ENABLE_LOCALE_SUPPORT
    54 # include <locale.h>
    55 #else
    56 # define setlocale(x,y) ((void)0)
    57 #endif
    58 #ifdef DMALLOC
    59 # include <dmalloc.h>
    60 #endif
    6154#include <pwd.h>
    6255#include <grp.h>
     
    6861#  include <shadow.h>
    6962# endif
     63#endif
     64#if defined(ANDROID) || defined(__ANDROID__)
     65# define endpwent() ((void)0)
     66# define endgrent() ((void)0)
     67#endif
     68#ifdef HAVE_MNTENT_H
     69# include <mntent.h>
     70#endif
     71#ifdef HAVE_SYS_STATFS_H
     72# include <sys/statfs.h>
     73#endif
     74/* Don't do this here:
     75 * #include <sys/sysinfo.h>
     76 * Some linux/ includes pull in conflicting definition
     77 * of struct sysinfo (only in some toolchanins), which breaks build.
     78 * Include sys/sysinfo.h only in those files which need it.
     79 */
     80#if ENABLE_SELINUX
     81# include <selinux/selinux.h>
     82# include <selinux/context.h>
     83# include <selinux/flask.h>
     84# include <selinux/av_permissions.h>
     85#endif
     86#if ENABLE_FEATURE_UTMP
     87# include <utmp.h>
     88#endif
     89#if ENABLE_LOCALE_SUPPORT
     90# include <locale.h>
     91#else
     92# define setlocale(x,y) ((void)0)
     93#endif
     94#ifdef DMALLOC
     95# include <dmalloc.h>
     96#endif
     97/* Just in case libc doesn't define some of these... */
     98#ifndef _PATH_PASSWD
     99#define _PATH_PASSWD  "/etc/passwd"
     100#endif
     101#ifndef _PATH_GROUP
     102#define _PATH_GROUP   "/etc/group"
     103#endif
     104#ifndef _PATH_SHADOW
     105#define _PATH_SHADOW  "/etc/shadow"
     106#endif
     107#ifndef _PATH_GSHADOW
     108#define _PATH_GSHADOW "/etc/gshadow"
    70109#endif
    71110#if defined __FreeBSD__ || defined __OpenBSD__
     
    85124# endif
    86125#endif
     126#ifndef HAVE_CLEARENV
     127# define clearenv() do { if (environ) environ[0] = NULL; } while (0)
     128#endif
     129#ifndef HAVE_FDATASYNC
     130# define fdatasync fsync
     131#endif
     132#ifndef HAVE_XTABS
     133# define XTABS TAB3
     134#endif
    87135
    88136
     
    95143/* klogctl is in libc's klog.h, but we cheat and not #include that */
    96144int klogctl(int type, char *b, int len);
    97 /* This is declared here rather than #including <libgen.h> in order to avoid
    98  * confusing the two versions of basename.  See the dirname/basename man page
    99  * for details. */
    100 #if !defined __FreeBSD__
    101 char *dirname(char *path);
    102 #endif
    103 /* Include our own copy of struct sysinfo to avoid binary compatibility
    104  * problems with Linux 2.4, which changed things.  Grumble, grumble. */
    105 struct sysinfo {
    106     long uptime;            /* Seconds since boot */
    107     unsigned long loads[3];     /* 1, 5, and 15 minute load averages */
    108     unsigned long totalram;     /* Total usable main memory size */
    109     unsigned long freeram;      /* Available memory size */
    110     unsigned long sharedram;    /* Amount of shared memory */
    111     unsigned long bufferram;    /* Memory used by buffers */
    112     unsigned long totalswap;    /* Total swap space size */
    113     unsigned long freeswap;     /* swap space still available */
    114     unsigned short procs;       /* Number of current processes */
    115     unsigned short pad;         /* Padding needed for m68k */
    116     unsigned long totalhigh;    /* Total high memory size */
    117     unsigned long freehigh;     /* Available high memory size */
    118     unsigned int mem_unit;      /* Memory unit size in bytes */
    119     char _f[20 - 2 * sizeof(long) - sizeof(int)]; /* Padding: libc5 uses this.. */
    120 };
    121 int sysinfo(struct sysinfo* info);
    122145#ifndef PATH_MAX
    123146# define PATH_MAX 256
     
    125148#ifndef BUFSIZ
    126149# define BUFSIZ 4096
     150#endif
     151
     152
     153/* Busybox does not use threads, we can speed up stdio. */
     154#ifdef HAVE_UNLOCKED_STDIO
     155# undef  getc
     156# define getc(stream) getc_unlocked(stream)
     157# undef  getchar
     158# define getchar() getchar_unlocked()
     159# undef  putc
     160# define putc(c, stream) putc_unlocked(c, stream)
     161# undef  putchar
     162# define putchar(c) putchar_unlocked(c)
     163# undef  fgetc
     164# define fgetc(stream) getc_unlocked(stream)
     165# undef  fputc
     166# define fputc(c, stream) putc_unlocked(c, stream)
     167#endif
     168/* Above functions are required by POSIX.1-2008, below ones are extensions */
     169#ifdef HAVE_UNLOCKED_LINE_OPS
     170# undef  fgets
     171# define fgets(s, n, stream) fgets_unlocked(s, n, stream)
     172# undef  fputs
     173# define fputs(s, stream) fputs_unlocked(s, stream)
    127174#endif
    128175
     
    169216/* "long" is long enough on this system */
    170217typedef unsigned long uoff_t;
    171 #  define XATOOFF(a) xatoul_range(a, 0, LONG_MAX)
     218#  define XATOOFF(a) xatoul_range((a), 0, LONG_MAX)
    172219/* usage: sz = BB_STRTOOFF(s, NULL, 10); if (errno || sz < 0) die(); */
    173220#  define BB_STRTOOFF bb_strtoul
     
    178225/* "long" is too short, need "long long" */
    179226typedef unsigned long long uoff_t;
    180 #  define XATOOFF(a) xatoull_range(a, 0, LLONG_MAX)
     227#  define XATOOFF(a) xatoull_range((a), 0, LLONG_MAX)
    181228#  define BB_STRTOOFF bb_strtoull
    182229#  define STRTOOFF strtoull
     
    195242# else
    196243typedef unsigned long uoff_t;
    197 #  define XATOOFF(a) xatoul_range(a, 0, LONG_MAX)
     244#  define XATOOFF(a) xatoul_range((a), 0, LONG_MAX)
    198245#  define BB_STRTOOFF bb_strtoul
    199246#  define STRTOOFF strtol
     
    203250/* scary. better ideas? (but do *test* them first!) */
    204251#define OFF_T_MAX  ((off_t)~((off_t)1 << (sizeof(off_t)*8-1)))
     252/* Users report bionic to use 32-bit off_t even if LARGEFILE support is requested.
     253 * We misdetected that. Don't let it build:
     254 */
     255struct BUG_off_t_size_is_misdetected {
     256    char BUG_off_t_size_is_misdetected[sizeof(off_t) == sizeof(uoff_t) ? 1 : -1];
     257};
    205258
    206259/* Some useful definitions */
     
    211264#undef SKIP
    212265#define SKIP    ((int) 2)
    213 
    214 /* for mtab.c */
    215 #define MTAB_GETMOUNTPT '1'
    216 #define MTAB_GETDEVICE  '2'
    217 
    218 #define BUF_SIZE        8192
    219 #define EXPAND_ALLOC    1024
    220266
    221267/* Macros for min/max.  */
     
    273319//TODO: supply a pointer to char[11] buffer (avoid statics)?
    274320extern const char *bb_mode_string(mode_t mode) FAST_FUNC;
    275 extern int is_directory(const char *name, int followLinks, struct stat *statBuf) FAST_FUNC;
     321extern int is_directory(const char *name, int followLinks) FAST_FUNC;
    276322enum {  /* DO NOT CHANGE THESE VALUES!  cp.c, mv.c, install.c depend on them. */
    277323    FILEUTILS_PRESERVE_STATUS = 1 << 0, /* -p */
     
    288334    FILEUTILS_SET_SECURITY_CONTEXT = 1 << 10,
    289335#endif
     336    FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11,
    290337};
    291338#define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c")
     
    324371/* this helper yells "short read!" if param is not -1 */
    325372extern void complain_copyfd_and_die(off_t sz) NORETURN FAST_FUNC;
     373
    326374extern char bb_process_escape_sequence(const char **ptr) FAST_FUNC;
    327375char* strcpy_and_process_escape_sequences(char *dst, const char *src) FAST_FUNC;
     
    332380 * "abc/def/" -> "def" !!
    333381 */
    334 extern char *bb_get_last_path_component_strip(char *path) FAST_FUNC;
     382char *bb_get_last_path_component_strip(char *path) FAST_FUNC;
    335383/* "abc/def/" -> "" and it never modifies 'path' */
    336 extern char *bb_get_last_path_component_nostrip(const char *path) FAST_FUNC;
    337 
    338 int ndelay_on(int fd) FAST_FUNC;
    339 int ndelay_off(int fd) FAST_FUNC;
    340 int close_on_exec_on(int fd) FAST_FUNC;
     384char *bb_get_last_path_component_nostrip(const char *path) FAST_FUNC;
     385/* Simpler version: does not special case "/" string */
     386const char *bb_basename(const char *name) FAST_FUNC;
     387/* NB: can violate const-ness (similarly to strchr) */
     388char *last_char_is(const char *s, int c) FAST_FUNC;
     389
     390void ndelay_on(int fd) FAST_FUNC;
     391void ndelay_off(int fd) FAST_FUNC;
     392void close_on_exec_on(int fd) FAST_FUNC;
    341393void xdup2(int, int) FAST_FUNC;
    342394void xmove_fd(int, int) FAST_FUNC;
     
    518570 * This is useful if you plan to bind to resulting local lsa.
    519571 */
    520 #if ENABLE_FEATURE_IPV6
    521572int xsocket_type(len_and_sockaddr **lsap, int af, int sock_type) FAST_FUNC;
    522 #else
    523 int xsocket_type(len_and_sockaddr **lsap, int sock_type) FAST_FUNC;
    524 #define xsocket_type(lsap, af, sock_type) xsocket_type((lsap), (sock_type))
    525 #endif
    526573int xsocket_stream(len_and_sockaddr **lsap) FAST_FUNC;
    527574/* Create server socket bound to bindaddr:port. bindaddr can be NULL,
     
    563610 * otherwise no-op. Useful for ftp.
    564611 * NB: does NOT do htons() internally, just direct assignment. */
    565 void set_nport(len_and_sockaddr *lsa, unsigned port) FAST_FUNC;
     612void set_nport(struct sockaddr *sa, unsigned port) FAST_FUNC;
    566613/* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */
    567614int get_nport(const struct sockaddr *sa) FAST_FUNC;
     
    592639        socklen_t sa_size) FAST_FUNC;
    593640
     641uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC;
    594642
    595643char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
     
    636684void *xzalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
    637685void *xrealloc(void *old, size_t size) FAST_FUNC;
    638 /* After xrealloc_vector(v, 4, idx) it's ok to use
     686/* After v = xrealloc_vector(v, SHIFT, idx) it's ok to use
    639687 * at least v[idx] and v[idx+1], for all idx values.
    640  * shift specifies how many new elements are added (1: 2, 2: 4... 8: 256...)
    641  * when all elements are used up. New elements are zeroed out. */
     688 * SHIFT specifies how many new elements are added (1:2, 2:4, ..., 8:256...)
     689 * when all elements are used up. New elements are zeroed out.
     690 * xrealloc_vector(v, SHIFT, idx) *MUST* be called with consecutive IDXs -
     691 * skipping an index is a bad bug - it may miss a realloc!
     692 */
    642693#define xrealloc_vector(vector, shift, idx) \
    643694    xrealloc_vector_helper((vector), (sizeof((vector)[0]) << 8) + (shift), (idx))
     
    646697
    647698extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC;
    648 extern ssize_t nonblock_safe_read(int fd, void *buf, size_t count) FAST_FUNC;
     699extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count, int loop_on_EINTR) FAST_FUNC;
    649700// NB: will return short read on error, not -1,
    650701// if some data was read before error occurred
     
    657708// Reads byte-by-byte. Useful when it is important to not read ahead.
    658709// Bytes are appended to pfx (which must be malloced, or NULL).
    659 extern char *xmalloc_reads(int fd, char *pfx, size_t *maxsz_p) FAST_FUNC;
     710extern char *xmalloc_reads(int fd, size_t *maxsz_p) FAST_FUNC;
    660711/* Reads block up to *maxsz_p (default: INT_MAX - 4095) */
    661712extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
    662713/* Returns NULL if file can't be opened (default max size: INT_MAX - 4095) */
    663714extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
    664 /* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */
    665 #if ENABLE_FEATURE_SEAMLESS_LZMA \
     715/* Never returns NULL */
     716extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
     717
     718#define SEAMLESS_COMPRESSION (0 \
     719 || ENABLE_FEATURE_SEAMLESS_XZ \
     720 || ENABLE_FEATURE_SEAMLESS_LZMA \
    666721 || ENABLE_FEATURE_SEAMLESS_BZ2 \
    667722 || ENABLE_FEATURE_SEAMLESS_GZ \
    668  /* || ENABLE_FEATURE_SEAMLESS_Z */
    669 extern void setup_unzip_on_fd(int fd /*, int fail_if_not_detected*/) FAST_FUNC;
    670 #else
    671 # define setup_unzip_on_fd(...) ((void)0)
    672 #endif
     723 || ENABLE_FEATURE_SEAMLESS_Z)
     724
     725#if SEAMLESS_COMPRESSION
     726/* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */
     727extern int setup_unzip_on_fd(int fd, int fail_if_not_detected) FAST_FUNC;
    673728/* Autodetects .gz etc */
    674729extern int open_zipped(const char *fname) FAST_FUNC;
     730#else
     731# define setup_unzip_on_fd(...) (0)
     732# define open_zipped(fname)     open((fname), O_RDONLY);
     733#endif
    675734extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
    676 /* Never returns NULL */
    677 extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
    678735
    679736extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC;
     
    693750extern void xprint_and_close_file(FILE *file) FAST_FUNC;
    694751
     752/* Reads a line from a text file, up to a newline or NUL byte, inclusive.
     753 * Returns malloc'ed char*. If end is NULL '\n' isn't considered
     754 * end of line. If end isn't NULL, length of the chunk is stored in it.
     755 * Returns NULL if EOF/error.
     756 */
    695757extern char *bb_get_chunk_from_file(FILE *file, int *end) FAST_FUNC;
    696 extern char *bb_get_chunk_with_continuation(FILE *file, int *end, int *lineno) FAST_FUNC;
    697758/* Reads up to (and including) TERMINATING_STRING: */
    698759extern char *xmalloc_fgets_str(FILE *file, const char *terminating_string) FAST_FUNC RETURNS_MALLOC;
     
    736797
    737798char *safe_gethostname(void) FAST_FUNC;
    738 char *safe_getdomainname(void) FAST_FUNC;
    739799
    740800/* Convert each alpha char in str to lower-case */
     
    759819        unsigned long block_size, unsigned long display_unit) FAST_FUNC;
    760820/* Put a string of hex bytes ("1b2e66fe"...), return advanced pointer */
    761 char *bin2hex(char *buf, const char *cp, int count) FAST_FUNC;
     821char *bin2hex(char *dst, const char *src, int count) FAST_FUNC;
    762822/* Reverse */
    763 char* hex2bin(char *dst, const char *str, int count) FAST_FUNC;
     823char* hex2bin(char *dst, const char *src, int count) FAST_FUNC;
    764824
    765825/* Generate a UUID */
     
    813873char* uid2uname(uid_t uid) FAST_FUNC;
    814874char* gid2group(gid_t gid) FAST_FUNC;
    815 char* uid2uname_utoa(long uid) FAST_FUNC;
    816 char* gid2group_utoa(long gid) FAST_FUNC;
     875char* uid2uname_utoa(uid_t uid) FAST_FUNC;
     876char* gid2group_utoa(gid_t gid) FAST_FUNC;
    817877/* versions which cache results (useful for ps, ls etc) */
    818878const char* get_cached_username(uid_t uid) FAST_FUNC;
     
    820880void clear_username_cache(void) FAST_FUNC;
    821881/* internally usernames are saved in fixed-sized char[] buffers */
    822 enum { USERNAME_MAX_SIZE = 16 - sizeof(int) };
     882enum { USERNAME_MAX_SIZE = 32 - sizeof(uid_t) };
    823883#if ENABLE_FEATURE_CHECK_NAMES
    824884void die_if_bad_username(const char* name) FAST_FUNC;
     
    835895#endif
    836896
     897
    837898int execable_file(const char *name) FAST_FUNC;
    838899char *find_execable(const char *filename, char **PATHp) FAST_FUNC;
     
    843904 */
    844905#if ENABLE_FEATURE_PREFER_APPLETS
    845 int bb_execvp(const char *file, char *const argv[]) FAST_FUNC;
    846 #define BB_EXECVP(prog,cmd) bb_execvp(prog,cmd)
     906int BB_EXECVP(const char *file, char *const argv[]) FAST_FUNC;
    847907#define BB_EXECLP(prog,cmd,...) \
    848     execlp((find_applet_by_name(prog) >= 0) ? CONFIG_BUSYBOX_EXEC_PATH : prog, \
    849         cmd, __VA_ARGS__)
     908    do { \
     909        if (find_applet_by_name(prog) >= 0) \
     910            execlp(bb_busybox_exec_path, cmd, __VA_ARGS__); \
     911        execlp(prog, cmd, __VA_ARGS__); \
     912    } while (0)
    850913#else
    851914#define BB_EXECVP(prog,cmd)     execvp(prog,cmd)
    852 #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, __VA_ARGS__)
     915#define BB_EXECLP(prog,cmd,...) execlp(prog,cmd,__VA_ARGS__)
    853916#endif
    854917int BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC;
     
    884947/* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */
    885948int spawn_and_wait(char **argv) FAST_FUNC;
    886 struct nofork_save_area {
    887     jmp_buf die_jmp;
    888     const char *applet_name;
    889     uint32_t option_mask32;
    890     int die_sleep;
    891     uint8_t xfunc_error_retval;
    892     smallint saved;
    893 };
    894 void save_nofork_data(struct nofork_save_area *save) FAST_FUNC;
    895 void restore_nofork_data(struct nofork_save_area *save) FAST_FUNC;
    896949/* Does NOT check that applet is NOFORK, just blindly runs it */
    897950int run_nofork_applet(int applet_no, char **argv) FAST_FUNC;
    898 int run_nofork_applet_prime(struct nofork_save_area *old, int applet_no, char **argv) FAST_FUNC;
    899951
    900952/* Helpers for daemonization.
     
    926978    DAEMON_CLOSE_EXTRA_FDS = 4,
    927979    DAEMON_ONLY_SANITIZE = 8, /* internal use */
     980    DAEMON_DOUBLE_FORK = 16, /* double fork to avoid controlling tty */
    928981};
    929982#if BB_MMU
     
    934987#else
    935988  extern bool re_execed;
     989  /* Note: re_exec() and fork_or_rexec() do argv[0][0] |= 0x80 on NOMMU!
     990   * _Parent_ needs to undo it if it doesn't want to have argv[0] mangled.
     991   */
    936992  void re_exec(char **argv) NORETURN FAST_FUNC;
    937993  pid_t fork_or_rexec(char **argv) FAST_FUNC;
     
    9631019
    9641020
     1021/* Having next pointer as a first member allows easy creation
     1022 * of "llist-compatible" structs, and using llist_FOO functions
     1023 * on them.
     1024 */
    9651025typedef struct llist_t {
     1026    struct llist_t *link;
    9661027    char *data;
    967     struct llist_t *link;
    9681028} llist_t;
    9691029void llist_add_to(llist_t **old_head, void *data) FAST_FUNC;
     
    11161176 * malloc and return it in *devname.
    11171177 * return value: 1: read-only loopdev was setup, 0: rw, < 0: error */
    1118 extern int set_loop(char **devname, const char *file, unsigned long long offset) FAST_FUNC;
     1178extern int set_loop(char **devname, const char *file, unsigned long long offset, int ro) FAST_FUNC;
    11191179
    11201180/* Like bb_ask below, but asks on stdin with no timeout.  */
     
    11371197    // keep a copy of current line
    11381198    PARSE_KEEP_COPY = 0x00200000 * ENABLE_FEATURE_CROND_D,
    1139 //  PARSE_ESCAPE    = 0x00400000, // process escape sequences in tokens
     1199    PARSE_EOL_COMMENTS = 0x00400000, // comments are recognized even if they aren't the first char
    11401200    // NORMAL is:
    11411201    // * remove leading and trailing delimiters and collapse
     
    11431203    // * warn and continue if less than mintokens delimiters found
    11441204    // * grab everything into last token
    1145     PARSE_NORMAL    = PARSE_COLLAPSE | PARSE_TRIM | PARSE_GREEDY,
     1205    // * comments are recognized even if they aren't the first char
     1206    PARSE_NORMAL    = PARSE_COLLAPSE | PARSE_TRIM | PARSE_GREEDY | PARSE_EOL_COMMENTS,
    11461207};
    11471208typedef struct parser_t {
    11481209    FILE *fp;
    1149     char *line;
    11501210    char *data;
     1211    char *line, *nline;
     1212    size_t line_alloc, nline_alloc;
    11511213    int lineno;
    11521214} parser_t;
     
    11641226 * filename should not be NULL. */
    11651227char *concat_path_file(const char *path, const char *filename) FAST_FUNC;
     1228/* Returns NULL on . and .. */
    11661229char *concat_subpath_file(const char *path, const char *filename) FAST_FUNC;
    1167 const char *bb_basename(const char *name) FAST_FUNC;
    1168 /* NB: can violate const-ness (similarly to strchr) */
    1169 char *last_char_is(const char *s, int c) FAST_FUNC;
    11701230
    11711231
     
    11801240char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC;
    11811241
    1182 #define FAIL_DELAY 3
     1242#define LOGIN_FAIL_DELAY 3
    11831243extern void bb_do_delay(int seconds) FAST_FUNC;
    11841244extern void change_identity(const struct passwd *pw) FAST_FUNC;
    11851245extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) NORETURN FAST_FUNC;
     1246
     1247/* Returns $SHELL, getpwuid(getuid())->pw_shell, or DEFAULT_SHELL.
     1248 * Note that getpwuid result might need xstrdup'ing
     1249 * if there is a possibility of intervening getpwxxx() calls.
     1250 */
     1251const char *get_shell_name(void) FAST_FUNC;
     1252
    11861253#if ENABLE_SELINUX
    11871254extern void renew_current_security_context(void) FAST_FUNC;
     
    11951262#endif
    11961263extern void selinux_or_die(void) FAST_FUNC;
     1264
     1265
     1266/* systemd support */
     1267#define SD_LISTEN_FDS_START 3
     1268int sd_listen_fds(void);
     1269
    11971270
    11981271/* setup_environment:
     
    12141287#define SETUP_ENV_CLEARENV  (1 << 1)
    12151288#define SETUP_ENV_TO_TMP    (1 << 2)
     1289#define SETUP_ENV_NO_CHDIR  (1 << 4)
    12161290extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
    12171291extern int correct_password(const struct passwd *pw) FAST_FUNC;
     
    12221296extern char *pw_encrypt(const char *clear, const char *salt, int cleanup) FAST_FUNC;
    12231297extern int obscure(const char *old, const char *newval, const struct passwd *pwdp) FAST_FUNC;
    1224 /* rnd is additional random input. New one is returned.
     1298/*
     1299 * rnd is additional random input. New one is returned.
    12251300 * Useful if you call crypt_make_salt many times in a row:
    12261301 * rnd = crypt_make_salt(buf1, 4, 0);
     
    12291304 * (otherwise we risk having same salt generated)
    12301305 */
    1231 extern int crypt_make_salt(char *p, int cnt, int rnd) FAST_FUNC;
     1306extern int crypt_make_salt(char *p, int cnt /*, int rnd*/) FAST_FUNC;
     1307/* "$N$" + sha_salt_16_bytes + NUL */
     1308#define MAX_PW_SALT_LEN (3 + 16 + 1)
     1309extern char* crypt_make_pw_salt(char p[MAX_PW_SALT_LEN], const char *algo) FAST_FUNC;
     1310
    12321311
    12331312/* Returns number of lines changed, or -1 on error */
     
    12761355#ifdef __GLIBC__
    12771356/* At least glibc has horrendously large inline for this, so wrap it */
    1278 unsigned long long bb_makedev(unsigned int major, unsigned int minor) FAST_FUNC;
     1357unsigned long long bb_makedev(unsigned major, unsigned minor) FAST_FUNC;
    12791358#undef makedev
    12801359#define makedev(a,b) bb_makedev(a,b)
     
    12971376    KEYCODE_PAGEUP   = -10,
    12981377    KEYCODE_PAGEDOWN = -11,
    1299 
    1300     KEYCODE_CTRL_UP    = KEYCODE_UP    & ~0x40,
    1301     KEYCODE_CTRL_DOWN  = KEYCODE_DOWN  & ~0x40,
     1378    // -12 is reserved for Alt/Ctrl/Shift-TAB
     1379#if 0
     1380    KEYCODE_FUN1     = -13,
     1381    KEYCODE_FUN2     = -14,
     1382    KEYCODE_FUN3     = -15,
     1383    KEYCODE_FUN4     = -16,
     1384    KEYCODE_FUN5     = -17,
     1385    KEYCODE_FUN6     = -18,
     1386    KEYCODE_FUN7     = -19,
     1387    KEYCODE_FUN8     = -20,
     1388    KEYCODE_FUN9     = -21,
     1389    KEYCODE_FUN10    = -22,
     1390    KEYCODE_FUN11    = -23,
     1391    KEYCODE_FUN12    = -24,
     1392#endif
     1393    /* Be sure that last defined value is small enough
     1394     * to not interfere with Alt/Ctrl/Shift bits.
     1395     * So far we do not exceed -31 (0xfff..fffe1),
     1396     * which gives us three upper bits in LSB to play with.
     1397     */
     1398    //KEYCODE_SHIFT_TAB  = (-12)         & ~0x80,
     1399    //KEYCODE_SHIFT_...  = KEYCODE_...   & ~0x80,
     1400    //KEYCODE_CTRL_UP    = KEYCODE_UP    & ~0x40,
     1401    //KEYCODE_CTRL_DOWN  = KEYCODE_DOWN  & ~0x40,
    13021402    KEYCODE_CTRL_RIGHT = KEYCODE_RIGHT & ~0x40,
    13031403    KEYCODE_CTRL_LEFT  = KEYCODE_LEFT  & ~0x40,
    1304 #if 0
    1305     KEYCODE_FUN1     = -12,
    1306     KEYCODE_FUN2     = -13,
    1307     KEYCODE_FUN3     = -14,
    1308     KEYCODE_FUN4     = -15,
    1309     KEYCODE_FUN5     = -16,
    1310     KEYCODE_FUN6     = -17,
    1311     KEYCODE_FUN7     = -18,
    1312     KEYCODE_FUN8     = -19,
    1313     KEYCODE_FUN9     = -20,
    1314     KEYCODE_FUN10    = -21,
    1315     KEYCODE_FUN11    = -22,
    1316     KEYCODE_FUN12    = -23,
    1317 #endif
     1404    //KEYCODE_ALT_UP     = KEYCODE_UP    & ~0x20,
     1405    //KEYCODE_ALT_DOWN   = KEYCODE_DOWN  & ~0x20,
     1406    KEYCODE_ALT_RIGHT  = KEYCODE_RIGHT & ~0x20,
     1407    KEYCODE_ALT_LEFT   = KEYCODE_LEFT  & ~0x20,
     1408
    13181409    KEYCODE_CURSOR_POS = -0x100, /* 0xfff..fff00 */
    13191410    /* How long is the longest ESC sequence we know?
     
    13421433#if ENABLE_FEATURE_EDITING
    13431434/* It's NOT just ENABLEd or disabled. It's a number: */
    1344 # ifdef CONFIG_FEATURE_EDITING_HISTORY
     1435# if defined CONFIG_FEATURE_EDITING_HISTORY && CONFIG_FEATURE_EDITING_HISTORY > 0
    13451436#  define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0)
     1437unsigned size_from_HISTFILESIZE(const char *hp);
    13461438# else
    13471439#  define MAX_HISTORY 0
     
    13531445    int cnt_history;
    13541446    int cur_history;
     1447    int max_history; /* must never be <= 0 */
    13551448#  if ENABLE_FEATURE_EDITING_SAVEHISTORY
     1449    /* meaning of this field depends on FEATURE_EDITING_SAVE_ON_EXIT:
     1450     * if !FEATURE_EDITING_SAVE_ON_EXIT: "how many lines are
     1451     * in on-disk history"
     1452     * if FEATURE_EDITING_SAVE_ON_EXIT: "how many in-memory lines are
     1453     * also in on-disk history (and thus need to be skipped on save)"
     1454     */
    13561455    unsigned cnt_history_in_file;
    13571456    const char *hist_file;
     
    13611460} line_input_t;
    13621461enum {
    1363     DO_HISTORY = 1 * (MAX_HISTORY > 0),
    1364     SAVE_HISTORY = 2 * (MAX_HISTORY > 0) * ENABLE_FEATURE_EDITING_SAVEHISTORY,
    1365     TAB_COMPLETION = 4 * ENABLE_FEATURE_TAB_COMPLETION,
    1366     USERNAME_COMPLETION = 8 * ENABLE_FEATURE_USERNAME_COMPLETION,
    1367     VI_MODE = 0x10 * ENABLE_FEATURE_EDITING_VI,
    1368     WITH_PATH_LOOKUP = 0x20,
    1369     FOR_SHELL = DO_HISTORY | SAVE_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION,
     1462    DO_HISTORY       = 1 * (MAX_HISTORY > 0),
     1463    TAB_COMPLETION   = 2 * ENABLE_FEATURE_TAB_COMPLETION,
     1464    USERNAME_COMPLETION = 4 * ENABLE_FEATURE_USERNAME_COMPLETION,
     1465    VI_MODE          = 8 * ENABLE_FEATURE_EDITING_VI,
     1466    WITH_PATH_LOOKUP = 0x10,
     1467    FOR_SHELL        = DO_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION,
    13701468};
    13711469line_input_t *new_line_input_t(int flags) FAST_FUNC;
    13721470/* So far static: void free_line_input_t(line_input_t *n) FAST_FUNC; */
    1373 /* maxsize must be >= 2.
     1471/*
     1472 * maxsize must be >= 2.
    13741473 * Returns:
    13751474 * -1 on read errors or EOF, or on bare Ctrl-D,
     
    13771476 * >0 length of input string, including terminating '\n'
    13781477 */
    1379 int read_line_input(const char* prompt, char* command, int maxsize, line_input_t *state) FAST_FUNC;
     1478int read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) FAST_FUNC;
     1479# if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
     1480void save_history(line_input_t *st);
     1481# endif
    13801482#else
    13811483#define MAX_HISTORY 0
    13821484int read_line_input(const char* prompt, char* command, int maxsize) FAST_FUNC;
    1383 #define read_line_input(prompt, command, maxsize, state) \
     1485#define read_line_input(state, prompt, command, maxsize, timeout) \
    13841486    read_line_input(prompt, command, maxsize)
    13851487#endif
     
    14151517#endif
    14161518int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
    1417               void (*cb)(struct smaprec *, void *), void *data);
     1519        void (*cb)(struct smaprec *, void *), void *data);
    14181520
    14191521typedef struct procps_status_t {
     
    14271529    char *exe;
    14281530    IF_SELINUX(char *context;)
     1531    IF_FEATURE_SHOW_THREADS(unsigned main_thread_pid;)
    14291532    /* Everything below must contain no ptrs to malloc'ed data:
    14301533     * it is memset(0) for each process in procps_scan() */
     
    14881591    PSSCAN_RUIDGID  = (1 << 21) * ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS,
    14891592    PSSCAN_TASKS    = (1 << 22) * ENABLE_FEATURE_SHOW_THREADS,
    1490     /* These are all retrieved from proc/NN/stat in one go: */
    1491     PSSCAN_STAT     = PSSCAN_PPID | PSSCAN_PGID | PSSCAN_SID
    1492     /**/            | PSSCAN_COMM | PSSCAN_STATE
    1493     /**/            | PSSCAN_VSZ | PSSCAN_RSS
    1494     /**/            | PSSCAN_STIME | PSSCAN_UTIME | PSSCAN_START_TIME
    1495     /**/            | PSSCAN_TTY | PSSCAN_NICE
    1496     /**/            | PSSCAN_CPU
    14971593};
    14981594//procps_status_t* alloc_procps_scan(void) FAST_FUNC;
     
    15081604
    15091605
    1510 extern const char bb_uuenc_tbl_base64[];
    1511 extern const char bb_uuenc_tbl_std[];
     1606/* Use strict=1 if you process input from untrusted source:
     1607 * it will return NULL on invalid %xx (bad hex chars)
     1608 * and str + 1 if decoded char is / or NUL.
     1609 * In non-strict mode, it always succeeds (returns str),
     1610 * and also it additionally decoded '+' to space.
     1611 */
     1612char *percent_decode_in_place(char *str, int strict) FAST_FUNC;
     1613
     1614
     1615extern const char bb_uuenc_tbl_base64[] ALIGN1;
     1616extern const char bb_uuenc_tbl_std[] ALIGN1;
    15121617void bb_uuencode(char *store, const void *s, int length, const char *tbl) FAST_FUNC;
    15131618enum {
     
    15161621    BASE64_FLAG_NO_STOP_CHAR = 0x80,
    15171622};
    1518 void FAST_FUNC read_base64(FILE *src_stream, FILE *dst_stream, int flags);
     1623const char *decode_base64(char **pp_dst, const char *src) FAST_FUNC;
     1624void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC;
    15191625
    15201626typedef struct md5_ctx_t {
     
    15311637    uint8_t wbuffer[128]; /* always correctly aligned for uint64_t */
    15321638} sha512_ctx_t;
     1639typedef struct sha3_ctx_t {
     1640    uint64_t state[25];
     1641    unsigned bytes_queued;
     1642} sha3_ctx_t;
    15331643void md5_begin(md5_ctx_t *ctx) FAST_FUNC;
    1534 void md5_hash(md5_ctx_t *ctx, const void *data, size_t length) FAST_FUNC;
     1644void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
    15351645void md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC;
    15361646void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC;
     
    15431653void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
    15441654void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC;
     1655void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC;
     1656void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
     1657void sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC;
    15451658
    15461659extern uint32_t *global_crc32_table;
     
    15581671
    15591672typedef struct bb_progress_t {
    1560     off_t lastsize;
    1561     unsigned lastupdate_sec;
     1673    unsigned last_size;
     1674    unsigned last_update_sec;
     1675    unsigned last_change_sec;
    15621676    unsigned start_sec;
    1563     smallint inited;
     1677    const char *curfile;
    15641678} bb_progress_t;
    15651679
    1566 void bb_progress_init(bb_progress_t *p) FAST_FUNC;
    1567 void bb_progress_update(bb_progress_t *p, const char *curfile,
    1568             off_t beg_range, off_t transferred,
    1569             off_t totalsize) FAST_FUNC;
     1680#define is_bb_progress_inited(p) ((p)->curfile != NULL)
     1681#define bb_progress_free(p) do { \
     1682    if (ENABLE_UNICODE_SUPPORT) free((char*)((p)->curfile)); \
     1683    (p)->curfile = NULL; \
     1684} while (0)
     1685void bb_progress_init(bb_progress_t *p, const char *curfile) FAST_FUNC;
     1686void bb_progress_update(bb_progress_t *p,
     1687            uoff_t beg_range,
     1688            uoff_t transferred,
     1689            uoff_t totalsize) FAST_FUNC;
     1690
    15701691
    15711692extern const char *applet_name;
     
    15811702 */
    15821703/* "BusyBox vN.N.N (timestamp or extra_version)" */
    1583 extern const char bb_banner[];
    1584 extern const char bb_msg_memory_exhausted[];
    1585 extern const char bb_msg_invalid_date[];
     1704extern const char bb_banner[] ALIGN1;
     1705extern const char bb_msg_memory_exhausted[] ALIGN1;
     1706extern const char bb_msg_invalid_date[] ALIGN1;
    15861707#define bb_msg_read_error "read error"
    15871708#define bb_msg_write_error "write error"
    1588 extern const char bb_msg_unknown[];
    1589 extern const char bb_msg_can_not_create_raw_socket[];
    1590 extern const char bb_msg_perm_denied_are_you_root[];
    1591 extern const char bb_msg_you_must_be_root[];
    1592 extern const char bb_msg_requires_arg[];
    1593 extern const char bb_msg_invalid_arg[];
    1594 extern const char bb_msg_standard_input[];
    1595 extern const char bb_msg_standard_output[];
     1709extern const char bb_msg_unknown[] ALIGN1;
     1710extern const char bb_msg_can_not_create_raw_socket[] ALIGN1;
     1711extern const char bb_msg_perm_denied_are_you_root[] ALIGN1;
     1712extern const char bb_msg_you_must_be_root[] ALIGN1;
     1713extern const char bb_msg_requires_arg[] ALIGN1;
     1714extern const char bb_msg_invalid_arg[] ALIGN1;
     1715extern const char bb_msg_standard_input[] ALIGN1;
     1716extern const char bb_msg_standard_output[] ALIGN1;
    15961717
    15971718/* NB: (bb_hexdigits_upcase[i] | 0x20) -> lowercase hex digit */
    1598 extern const char bb_hexdigits_upcase[];
    1599 
    1600 extern const char bb_path_wtmp_file[];
     1719extern const char bb_hexdigits_upcase[] ALIGN1;
     1720
     1721extern const char bb_path_wtmp_file[] ALIGN1;
    16011722
    16021723/* Busybox mount uses either /proc/mounts or /etc/mtab to
     
    16041725#define bb_path_mtab_file IF_FEATURE_MTAB_SUPPORT("/etc/mtab")IF_NOT_FEATURE_MTAB_SUPPORT("/proc/mounts")
    16051726
    1606 #define bb_path_passwd_file "/etc/passwd"
    1607 #define bb_path_shadow_file "/etc/shadow"
    1608 #define bb_path_gshadow_file "/etc/gshadow"
    1609 #define bb_path_group_file "/etc/group"
     1727#define bb_path_passwd_file  _PATH_PASSWD
     1728#define bb_path_group_file   _PATH_GROUP
     1729#define bb_path_shadow_file  _PATH_SHADOW
     1730#define bb_path_gshadow_file _PATH_GSHADOW
    16101731
    16111732#define bb_path_motd_file "/etc/motd"
    16121733
    16131734#define bb_dev_null "/dev/null"
    1614 extern const char bb_busybox_exec_path[];
     1735extern const char bb_busybox_exec_path[] ALIGN1;
    16151736/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
    16161737 * but I want to save a few bytes here */
    1617 extern const char bb_PATH_root_path[]; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */
     1738extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */
    16181739#define bb_default_root_path (bb_PATH_root_path + sizeof("PATH"))
    16191740#define bb_default_path      (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin"))
     
    16451766 * don't forget to change increment constant. */
    16461767#define LIBBB_DEFAULT_LOGIN_SHELL  "-/bin/sh"
    1647 extern const char bb_default_login_shell[];
     1768extern const char bb_default_login_shell[] ALIGN1;
    16481769/* "/bin/sh" */
    16491770#define DEFAULT_SHELL              (bb_default_login_shell+1)
Note: See TracChangeset for help on using the changeset viewer.