Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/include/libbb.h
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/include/libbb.h
r2725 r3232 21 21 #include <setjmp.h> 22 22 #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 23 29 #include <stdint.h> 24 30 #include <stdio.h> … … 27 33 #include <stddef.h> 28 34 #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 29 40 #include <sys/poll.h> 30 41 #include <sys/ioctl.h> … … 34 45 #include <sys/time.h> 35 46 #include <sys/types.h> 47 #ifndef major 48 # include <sys/sysmacros.h> 49 #endif 36 50 #include <sys/wait.h> 37 51 #include <termios.h> 38 52 #include <time.h> 39 #include <unistd.h>40 53 #include <sys/param.h> 41 #ifdef HAVE_MNTENT_H42 # include <mntent.h>43 #endif44 #ifdef HAVE_SYS_STATFS_H45 # include <sys/statfs.h>46 #endif47 #if ENABLE_SELINUX48 # include <selinux/selinux.h>49 # include <selinux/context.h>50 # include <selinux/flask.h>51 # include <selinux/av_permissions.h>52 #endif53 #if ENABLE_LOCALE_SUPPORT54 # include <locale.h>55 #else56 # define setlocale(x,y) ((void)0)57 #endif58 #ifdef DMALLOC59 # include <dmalloc.h>60 #endif61 54 #include <pwd.h> 62 55 #include <grp.h> … … 68 61 # include <shadow.h> 69 62 # 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" 70 109 #endif 71 110 #if defined __FreeBSD__ || defined __OpenBSD__ … … 85 124 # endif 86 125 #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 87 135 88 136 … … 95 143 /* klogctl is in libc's klog.h, but we cheat and not #include that */ 96 144 int klogctl(int type, char *b, int len); 97 /* This is declared here rather than #including <libgen.h> in order to avoid98 * confusing the two versions of basename. See the dirname/basename man page99 * for details. */100 #if !defined __FreeBSD__101 char *dirname(char *path);102 #endif103 /* Include our own copy of struct sysinfo to avoid binary compatibility104 * 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);122 145 #ifndef PATH_MAX 123 146 # define PATH_MAX 256 … … 125 148 #ifndef BUFSIZ 126 149 # 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) 127 174 #endif 128 175 … … 169 216 /* "long" is long enough on this system */ 170 217 typedef unsigned long uoff_t; 171 # define XATOOFF(a) xatoul_range( a, 0, LONG_MAX)218 # define XATOOFF(a) xatoul_range((a), 0, LONG_MAX) 172 219 /* usage: sz = BB_STRTOOFF(s, NULL, 10); if (errno || sz < 0) die(); */ 173 220 # define BB_STRTOOFF bb_strtoul … … 178 225 /* "long" is too short, need "long long" */ 179 226 typedef 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) 181 228 # define BB_STRTOOFF bb_strtoull 182 229 # define STRTOOFF strtoull … … 195 242 # else 196 243 typedef unsigned long uoff_t; 197 # define XATOOFF(a) xatoul_range( a, 0, LONG_MAX)244 # define XATOOFF(a) xatoul_range((a), 0, LONG_MAX) 198 245 # define BB_STRTOOFF bb_strtoul 199 246 # define STRTOOFF strtol … … 203 250 /* scary. better ideas? (but do *test* them first!) */ 204 251 #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 */ 255 struct BUG_off_t_size_is_misdetected { 256 char BUG_off_t_size_is_misdetected[sizeof(off_t) == sizeof(uoff_t) ? 1 : -1]; 257 }; 205 258 206 259 /* Some useful definitions */ … … 211 264 #undef SKIP 212 265 #define SKIP ((int) 2) 213 214 /* for mtab.c */215 #define MTAB_GETMOUNTPT '1'216 #define MTAB_GETDEVICE '2'217 218 #define BUF_SIZE 8192219 #define EXPAND_ALLOC 1024220 266 221 267 /* Macros for min/max. */ … … 273 319 //TODO: supply a pointer to char[11] buffer (avoid statics)? 274 320 extern 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;321 extern int is_directory(const char *name, int followLinks) FAST_FUNC; 276 322 enum { /* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depend on them. */ 277 323 FILEUTILS_PRESERVE_STATUS = 1 << 0, /* -p */ … … 288 334 FILEUTILS_SET_SECURITY_CONTEXT = 1 << 10, 289 335 #endif 336 FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11, 290 337 }; 291 338 #define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c") … … 324 371 /* this helper yells "short read!" if param is not -1 */ 325 372 extern void complain_copyfd_and_die(off_t sz) NORETURN FAST_FUNC; 373 326 374 extern char bb_process_escape_sequence(const char **ptr) FAST_FUNC; 327 375 char* strcpy_and_process_escape_sequences(char *dst, const char *src) FAST_FUNC; … … 332 380 * "abc/def/" -> "def" !! 333 381 */ 334 externchar *bb_get_last_path_component_strip(char *path) FAST_FUNC;382 char *bb_get_last_path_component_strip(char *path) FAST_FUNC; 335 383 /* "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; 384 char *bb_get_last_path_component_nostrip(const char *path) FAST_FUNC; 385 /* Simpler version: does not special case "/" string */ 386 const char *bb_basename(const char *name) FAST_FUNC; 387 /* NB: can violate const-ness (similarly to strchr) */ 388 char *last_char_is(const char *s, int c) FAST_FUNC; 389 390 void ndelay_on(int fd) FAST_FUNC; 391 void ndelay_off(int fd) FAST_FUNC; 392 void close_on_exec_on(int fd) FAST_FUNC; 341 393 void xdup2(int, int) FAST_FUNC; 342 394 void xmove_fd(int, int) FAST_FUNC; … … 518 570 * This is useful if you plan to bind to resulting local lsa. 519 571 */ 520 #if ENABLE_FEATURE_IPV6521 572 int xsocket_type(len_and_sockaddr **lsap, int af, int sock_type) FAST_FUNC; 522 #else523 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 #endif526 573 int xsocket_stream(len_and_sockaddr **lsap) FAST_FUNC; 527 574 /* Create server socket bound to bindaddr:port. bindaddr can be NULL, … … 563 610 * otherwise no-op. Useful for ftp. 564 611 * NB: does NOT do htons() internally, just direct assignment. */ 565 void set_nport( len_and_sockaddr *lsa, unsigned port) FAST_FUNC;612 void set_nport(struct sockaddr *sa, unsigned port) FAST_FUNC; 566 613 /* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */ 567 614 int get_nport(const struct sockaddr *sa) FAST_FUNC; … … 592 639 socklen_t sa_size) FAST_FUNC; 593 640 641 uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC; 594 642 595 643 char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC; … … 636 684 void *xzalloc(size_t size) FAST_FUNC RETURNS_MALLOC; 637 685 void *xrealloc(void *old, size_t size) FAST_FUNC; 638 /* After xrealloc_vector(v, 4, idx) it's ok to use686 /* After v = xrealloc_vector(v, SHIFT, idx) it's ok to use 639 687 * 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 */ 642 693 #define xrealloc_vector(vector, shift, idx) \ 643 694 xrealloc_vector_helper((vector), (sizeof((vector)[0]) << 8) + (shift), (idx)) … … 646 697 647 698 extern 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;699 extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count, int loop_on_EINTR) FAST_FUNC; 649 700 // NB: will return short read on error, not -1, 650 701 // if some data was read before error occurred … … 657 708 // Reads byte-by-byte. Useful when it is important to not read ahead. 658 709 // 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;710 extern char *xmalloc_reads(int fd, size_t *maxsz_p) FAST_FUNC; 660 711 /* Reads block up to *maxsz_p (default: INT_MAX - 4095) */ 661 712 extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; 662 713 /* Returns NULL if file can't be opened (default max size: INT_MAX - 4095) */ 663 714 extern 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 */ 716 extern 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 \ 666 721 || ENABLE_FEATURE_SEAMLESS_BZ2 \ 667 722 || 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 # else671 # 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! */ 727 extern int setup_unzip_on_fd(int fd, int fail_if_not_detected) FAST_FUNC; 673 728 /* Autodetects .gz etc */ 674 729 extern 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 675 734 extern 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;678 735 679 736 extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC; … … 693 750 extern void xprint_and_close_file(FILE *file) FAST_FUNC; 694 751 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 */ 695 757 extern 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;697 758 /* Reads up to (and including) TERMINATING_STRING: */ 698 759 extern char *xmalloc_fgets_str(FILE *file, const char *terminating_string) FAST_FUNC RETURNS_MALLOC; … … 736 797 737 798 char *safe_gethostname(void) FAST_FUNC; 738 char *safe_getdomainname(void) FAST_FUNC;739 799 740 800 /* Convert each alpha char in str to lower-case */ … … 759 819 unsigned long block_size, unsigned long display_unit) FAST_FUNC; 760 820 /* Put a string of hex bytes ("1b2e66fe"...), return advanced pointer */ 761 char *bin2hex(char * buf, const char *cp, int count) FAST_FUNC;821 char *bin2hex(char *dst, const char *src, int count) FAST_FUNC; 762 822 /* Reverse */ 763 char* hex2bin(char *dst, const char *s tr, int count) FAST_FUNC;823 char* hex2bin(char *dst, const char *src, int count) FAST_FUNC; 764 824 765 825 /* Generate a UUID */ … … 813 873 char* uid2uname(uid_t uid) FAST_FUNC; 814 874 char* gid2group(gid_t gid) FAST_FUNC; 815 char* uid2uname_utoa( longuid) FAST_FUNC;816 char* gid2group_utoa( longgid) FAST_FUNC;875 char* uid2uname_utoa(uid_t uid) FAST_FUNC; 876 char* gid2group_utoa(gid_t gid) FAST_FUNC; 817 877 /* versions which cache results (useful for ps, ls etc) */ 818 878 const char* get_cached_username(uid_t uid) FAST_FUNC; … … 820 880 void clear_username_cache(void) FAST_FUNC; 821 881 /* internally usernames are saved in fixed-sized char[] buffers */ 822 enum { USERNAME_MAX_SIZE = 16 - sizeof(int) };882 enum { USERNAME_MAX_SIZE = 32 - sizeof(uid_t) }; 823 883 #if ENABLE_FEATURE_CHECK_NAMES 824 884 void die_if_bad_username(const char* name) FAST_FUNC; … … 835 895 #endif 836 896 897 837 898 int execable_file(const char *name) FAST_FUNC; 838 899 char *find_execable(const char *filename, char **PATHp) FAST_FUNC; … … 843 904 */ 844 905 #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) 906 int BB_EXECVP(const char *file, char *const argv[]) FAST_FUNC; 847 907 #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) 850 913 #else 851 914 #define BB_EXECVP(prog,cmd) execvp(prog,cmd) 852 #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, 915 #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd,__VA_ARGS__) 853 916 #endif 854 917 int BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; … … 884 947 /* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */ 885 948 int 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;896 949 /* Does NOT check that applet is NOFORK, just blindly runs it */ 897 950 int 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;899 951 900 952 /* Helpers for daemonization. … … 926 978 DAEMON_CLOSE_EXTRA_FDS = 4, 927 979 DAEMON_ONLY_SANITIZE = 8, /* internal use */ 980 DAEMON_DOUBLE_FORK = 16, /* double fork to avoid controlling tty */ 928 981 }; 929 982 #if BB_MMU … … 934 987 #else 935 988 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 */ 936 992 void re_exec(char **argv) NORETURN FAST_FUNC; 937 993 pid_t fork_or_rexec(char **argv) FAST_FUNC; … … 963 1019 964 1020 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 */ 965 1025 typedef struct llist_t { 1026 struct llist_t *link; 966 1027 char *data; 967 struct llist_t *link;968 1028 } llist_t; 969 1029 void llist_add_to(llist_t **old_head, void *data) FAST_FUNC; … … 1116 1176 * malloc and return it in *devname. 1117 1177 * 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;1178 extern int set_loop(char **devname, const char *file, unsigned long long offset, int ro) FAST_FUNC; 1119 1179 1120 1180 /* Like bb_ask below, but asks on stdin with no timeout. */ … … 1137 1197 // keep a copy of current line 1138 1198 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 1140 1200 // NORMAL is: 1141 1201 // * remove leading and trailing delimiters and collapse … … 1143 1203 // * warn and continue if less than mintokens delimiters found 1144 1204 // * 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, 1146 1207 }; 1147 1208 typedef struct parser_t { 1148 1209 FILE *fp; 1149 char *line;1150 1210 char *data; 1211 char *line, *nline; 1212 size_t line_alloc, nline_alloc; 1151 1213 int lineno; 1152 1214 } parser_t; … … 1164 1226 * filename should not be NULL. */ 1165 1227 char *concat_path_file(const char *path, const char *filename) FAST_FUNC; 1228 /* Returns NULL on . and .. */ 1166 1229 char *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;1170 1230 1171 1231 … … 1180 1240 char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC; 1181 1241 1182 #define FAIL_DELAY 31242 #define LOGIN_FAIL_DELAY 3 1183 1243 extern void bb_do_delay(int seconds) FAST_FUNC; 1184 1244 extern void change_identity(const struct passwd *pw) FAST_FUNC; 1185 1245 extern 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 */ 1251 const char *get_shell_name(void) FAST_FUNC; 1252 1186 1253 #if ENABLE_SELINUX 1187 1254 extern void renew_current_security_context(void) FAST_FUNC; … … 1195 1262 #endif 1196 1263 extern void selinux_or_die(void) FAST_FUNC; 1264 1265 1266 /* systemd support */ 1267 #define SD_LISTEN_FDS_START 3 1268 int sd_listen_fds(void); 1269 1197 1270 1198 1271 /* setup_environment: … … 1214 1287 #define SETUP_ENV_CLEARENV (1 << 1) 1215 1288 #define SETUP_ENV_TO_TMP (1 << 2) 1289 #define SETUP_ENV_NO_CHDIR (1 << 4) 1216 1290 extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; 1217 1291 extern int correct_password(const struct passwd *pw) FAST_FUNC; … … 1222 1296 extern char *pw_encrypt(const char *clear, const char *salt, int cleanup) FAST_FUNC; 1223 1297 extern 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. 1225 1300 * Useful if you call crypt_make_salt many times in a row: 1226 1301 * rnd = crypt_make_salt(buf1, 4, 0); … … 1229 1304 * (otherwise we risk having same salt generated) 1230 1305 */ 1231 extern int crypt_make_salt(char *p, int cnt, int rnd) FAST_FUNC; 1306 extern 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) 1309 extern char* crypt_make_pw_salt(char p[MAX_PW_SALT_LEN], const char *algo) FAST_FUNC; 1310 1232 1311 1233 1312 /* Returns number of lines changed, or -1 on error */ … … 1276 1355 #ifdef __GLIBC__ 1277 1356 /* At least glibc has horrendously large inline for this, so wrap it */ 1278 unsigned long long bb_makedev(unsigned int major, unsigned intminor) FAST_FUNC;1357 unsigned long long bb_makedev(unsigned major, unsigned minor) FAST_FUNC; 1279 1358 #undef makedev 1280 1359 #define makedev(a,b) bb_makedev(a,b) … … 1297 1376 KEYCODE_PAGEUP = -10, 1298 1377 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, 1302 1402 KEYCODE_CTRL_RIGHT = KEYCODE_RIGHT & ~0x40, 1303 1403 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 1318 1409 KEYCODE_CURSOR_POS = -0x100, /* 0xfff..fff00 */ 1319 1410 /* How long is the longest ESC sequence we know? … … 1342 1433 #if ENABLE_FEATURE_EDITING 1343 1434 /* It's NOT just ENABLEd or disabled. It's a number: */ 1344 # if def CONFIG_FEATURE_EDITING_HISTORY1435 # if defined CONFIG_FEATURE_EDITING_HISTORY && CONFIG_FEATURE_EDITING_HISTORY > 0 1345 1436 # define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0) 1437 unsigned size_from_HISTFILESIZE(const char *hp); 1346 1438 # else 1347 1439 # define MAX_HISTORY 0 … … 1353 1445 int cnt_history; 1354 1446 int cur_history; 1447 int max_history; /* must never be <= 0 */ 1355 1448 # 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 */ 1356 1455 unsigned cnt_history_in_file; 1357 1456 const char *hist_file; … … 1361 1460 } line_input_t; 1362 1461 enum { 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, 1370 1468 }; 1371 1469 line_input_t *new_line_input_t(int flags) FAST_FUNC; 1372 1470 /* 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. 1374 1473 * Returns: 1375 1474 * -1 on read errors or EOF, or on bare Ctrl-D, … … 1377 1476 * >0 length of input string, including terminating '\n' 1378 1477 */ 1379 int read_line_input(const char* prompt, char* command, int maxsize, line_input_t *state) FAST_FUNC; 1478 int 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 1480 void save_history(line_input_t *st); 1481 # endif 1380 1482 #else 1381 1483 #define MAX_HISTORY 0 1382 1484 int 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) \ 1384 1486 read_line_input(prompt, command, maxsize) 1385 1487 #endif … … 1415 1517 #endif 1416 1518 int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, 1417 1519 void (*cb)(struct smaprec *, void *), void *data); 1418 1520 1419 1521 typedef struct procps_status_t { … … 1427 1529 char *exe; 1428 1530 IF_SELINUX(char *context;) 1531 IF_FEATURE_SHOW_THREADS(unsigned main_thread_pid;) 1429 1532 /* Everything below must contain no ptrs to malloc'ed data: 1430 1533 * it is memset(0) for each process in procps_scan() */ … … 1488 1591 PSSCAN_RUIDGID = (1 << 21) * ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS, 1489 1592 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_SID1492 /**/ | PSSCAN_COMM | PSSCAN_STATE1493 /**/ | PSSCAN_VSZ | PSSCAN_RSS1494 /**/ | PSSCAN_STIME | PSSCAN_UTIME | PSSCAN_START_TIME1495 /**/ | PSSCAN_TTY | PSSCAN_NICE1496 /**/ | PSSCAN_CPU1497 1593 }; 1498 1594 //procps_status_t* alloc_procps_scan(void) FAST_FUNC; … … 1508 1604 1509 1605 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 */ 1612 char *percent_decode_in_place(char *str, int strict) FAST_FUNC; 1613 1614 1615 extern const char bb_uuenc_tbl_base64[] ALIGN1; 1616 extern const char bb_uuenc_tbl_std[] ALIGN1; 1512 1617 void bb_uuencode(char *store, const void *s, int length, const char *tbl) FAST_FUNC; 1513 1618 enum { … … 1516 1621 BASE64_FLAG_NO_STOP_CHAR = 0x80, 1517 1622 }; 1518 void FAST_FUNC read_base64(FILE *src_stream, FILE *dst_stream, int flags); 1623 const char *decode_base64(char **pp_dst, const char *src) FAST_FUNC; 1624 void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC; 1519 1625 1520 1626 typedef struct md5_ctx_t { … … 1531 1637 uint8_t wbuffer[128]; /* always correctly aligned for uint64_t */ 1532 1638 } sha512_ctx_t; 1639 typedef struct sha3_ctx_t { 1640 uint64_t state[25]; 1641 unsigned bytes_queued; 1642 } sha3_ctx_t; 1533 1643 void md5_begin(md5_ctx_t *ctx) FAST_FUNC; 1534 void md5_hash(md5_ctx_t *ctx, const void * data, size_t length) FAST_FUNC;1644 void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; 1535 1645 void md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC; 1536 1646 void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC; … … 1543 1653 void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; 1544 1654 void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; 1655 void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; 1656 void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; 1657 void sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; 1545 1658 1546 1659 extern uint32_t *global_crc32_table; … … 1558 1671 1559 1672 typedef 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; 1562 1676 unsigned start_sec; 1563 smallint inited;1677 const char *curfile; 1564 1678 } bb_progress_t; 1565 1679 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) 1685 void bb_progress_init(bb_progress_t *p, const char *curfile) FAST_FUNC; 1686 void bb_progress_update(bb_progress_t *p, 1687 uoff_t beg_range, 1688 uoff_t transferred, 1689 uoff_t totalsize) FAST_FUNC; 1690 1570 1691 1571 1692 extern const char *applet_name; … … 1581 1702 */ 1582 1703 /* "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[] ;1704 extern const char bb_banner[] ALIGN1; 1705 extern const char bb_msg_memory_exhausted[] ALIGN1; 1706 extern const char bb_msg_invalid_date[] ALIGN1; 1586 1707 #define bb_msg_read_error "read error" 1587 1708 #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[] ;1709 extern const char bb_msg_unknown[] ALIGN1; 1710 extern const char bb_msg_can_not_create_raw_socket[] ALIGN1; 1711 extern const char bb_msg_perm_denied_are_you_root[] ALIGN1; 1712 extern const char bb_msg_you_must_be_root[] ALIGN1; 1713 extern const char bb_msg_requires_arg[] ALIGN1; 1714 extern const char bb_msg_invalid_arg[] ALIGN1; 1715 extern const char bb_msg_standard_input[] ALIGN1; 1716 extern const char bb_msg_standard_output[] ALIGN1; 1596 1717 1597 1718 /* 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[] ;1719 extern const char bb_hexdigits_upcase[] ALIGN1; 1720 1721 extern const char bb_path_wtmp_file[] ALIGN1; 1601 1722 1602 1723 /* Busybox mount uses either /proc/mounts or /etc/mtab to … … 1604 1725 #define bb_path_mtab_file IF_FEATURE_MTAB_SUPPORT("/etc/mtab")IF_NOT_FEATURE_MTAB_SUPPORT("/proc/mounts") 1605 1726 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_g roup_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 1610 1731 1611 1732 #define bb_path_motd_file "/etc/motd" 1612 1733 1613 1734 #define bb_dev_null "/dev/null" 1614 extern const char bb_busybox_exec_path[] ;1735 extern const char bb_busybox_exec_path[] ALIGN1; 1615 1736 /* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, 1616 1737 * but I want to save a few bytes here */ 1617 extern const char bb_PATH_root_path[] ; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */1738 extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr/bin" */ 1618 1739 #define bb_default_root_path (bb_PATH_root_path + sizeof("PATH")) 1619 1740 #define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin")) … … 1645 1766 * don't forget to change increment constant. */ 1646 1767 #define LIBBB_DEFAULT_LOGIN_SHELL "-/bin/sh" 1647 extern const char bb_default_login_shell[] ;1768 extern const char bb_default_login_shell[] ALIGN1; 1648 1769 /* "/bin/sh" */ 1649 1770 #define DEFAULT_SHELL (bb_default_login_shell+1)
Note:
See TracChangeset
for help on using the changeset viewer.