/* scary. better ideas? (but do *test* them first!) */
#define OFF_T_MAX ((off_t)~((off_t)1 << (sizeof(off_t)*8-1)))
-/* This structure defines protocol families and their handlers. */
-struct aftype {
- const char *name;
- const char *title;
- int af;
- int alen;
- char *(*print) (unsigned char *);
- const char *(*sprint) (struct sockaddr *, int numeric);
- int (*input) (/*int type,*/ const char *bufp, struct sockaddr *);
- void (*herror) (char *text);
- int (*rprint) (int options);
- int (*rinput) (int typ, int ext, char **argv);
-
- /* may modify src */
- int (*getmask) (char *src, struct sockaddr * mask, char *name);
-};
-
-/* This structure defines hardware protocols and their handlers. */
-struct hwtype {
- const char *name;
- const char *title;
- int type;
- int alen;
- char *(*print) (unsigned char *);
- int (*input) (const char *, struct sockaddr *);
- int (*activate) (int fd);
- int suppress_null_addr;
-};
-
/* Some useful definitions */
#undef FALSE
#define FALSE ((int) 0)
char *xmalloc_readlink_or_warn(const char *path);
char *xmalloc_realpath(const char *path);
+
+//TODO: signal(sid, f) is the same? then why?
extern void sig_catch(int,void (*)(int));
//#define sig_ignore(s) (sig_catch((s), SIG_IGN))
//#define sig_uncatch(s) (sig_catch((s), SIG_DFL))
extern void sig_pause(void);
-
void xsetgid(gid_t gid);
void xsetuid(uid_t uid);
void xchdir(const char *path);
void xstat(const char *pathname, struct stat *buf);
int xopen(const char *pathname, int flags);
int xopen3(const char *pathname, int flags, int mode);
+int open_or_warn(const char *pathname, int flags);
+int open3_or_warn(const char *pathname, int flags, int mode);
off_t xlseek(int fd, off_t offset, int whence);
off_t fdlength(int fd);
void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
void xlisten(int s, int backlog);
void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen);
+ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
+ socklen_t tolen);
int setsockopt_reuseaddr(int fd);
int setsockopt_broadcast(int fd);
/* NB: returns port in host byte order */
#define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1])
#define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1])
#define NOT_LONE_CHAR(s,c) ((s)[0] != (c) || (s)[1])
+#define DOT_OR_DOTDOT(s) ((s)[0] == '.' && (!(s)[1] || ((s)[1] == '.' && !(s)[2])))
/* dmalloc will redefine these to it's own implementation. It is safe
* to have the prototypes here unconditionally. */
+extern void *malloc_or_warn(size_t size);
extern void *xmalloc(size_t size);
-extern void *xrealloc(void *old, size_t size);
extern void *xzalloc(size_t size);
+extern void *xrealloc(void *old, size_t size);
extern ssize_t safe_read(int fd, void *buf, size_t count);
extern ssize_t full_read(int fd, void *buf, size_t count);
enum { USERNAME_MAX_SIZE = 16 - sizeof(int) };
+struct bb_applet;
int execable_file(const char *name);
char *find_execable(const char *filename);
int exists_execable(const char *filename);
-#if ENABLE_FEATURE_EXEC_PREFER_APPLETS
+#if ENABLE_FEATURE_PREFER_APPLETS
int bb_execvp(const char *file, char *const argv[]);
#define BB_EXECVP(prog,cmd) bb_execvp(prog,cmd)
#define BB_EXECLP(prog,cmd,...) \
/* Unlike waitpid, waits ONLY for one process,
* It's safe to pass negative 'pids' from failed [v]fork -
- * wait4pid will return -1 and ECHILD in errno.
+ * wait4pid will return -1 (and will not clobber [v]fork's errno).
* IOW: rc = wait4pid(spawn(argv));
* if (rc < 0) bb_perror_msg("%s", argv[0]);
* if (rc > 0) bb_error_msg("exit code: %d", rc);
*/
+int wait4pid(int pid);
int wait_pid(int *wstat, int pid);
int wait_nohang(int *wstat);
-int wait4pid(int pid);
-//TODO: signal(sid, f) is the same? then why?
#define wait_crashed(w) ((w) & 127)
#define wait_exitcode(w) ((w) >> 8)
#define wait_stopsig(w) ((w) >> 8)
#define wait_stopped(w) (((w) & 127) == 127)
/* wait4pid(spawn(argv)) + NOFORK/NOEXEC (if configured) */
int spawn_and_wait(char **argv);
+struct nofork_save_area {
+ const struct bb_applet *current_applet;
+ int xfunc_error_retval;
+ uint32_t option_mask32;
+ int die_sleep;
+ smallint saved;
+};
+void save_nofork_data(struct nofork_save_area *save);
+void restore_nofork_data(struct nofork_save_area *save);
+/* Does NOT check that applet is NOFORK, just blindly runs it */
+int run_nofork_applet(const struct bb_applet *a, char **argv);
+int run_nofork_applet_prime(struct nofork_save_area *old, const struct bb_applet *a, char **argv);
/* Helpers for daemonization.
*
DAEMON_CLOSE_EXTRA_FDS = 4,
DAEMON_ONLY_SANITIZE = 8, /* internal use */
};
-#ifndef BB_NOMMU
+#if BB_MMU
void forkexit_or_rexec(void);
# define forkexit_or_rexec(argv) forkexit_or_rexec()
# define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags)
int write_pidfile(const char *path);
#define remove_pidfile(f) ((void)unlink(f))
#else
-#define write_pidfile(f) 1
+/* Why? #defining it to 1 gives "warning: statement with no effect"... */
+static ATTRIBUTE_ALWAYS_INLINE int write_pidfile(const char *path) { return 1; }
#define remove_pidfile(f) ((void)0)
#endif
extern int die_sleep;
extern int xfunc_error_retval;
extern jmp_buf die_jmp;
-extern void sleep_and_die(void) ATTRIBUTE_NORETURN;
+extern void xfunc_die(void) ATTRIBUTE_NORETURN;
extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE;
extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
int bb_cat(char** argv);
int bb_echo(char** argv);
int bb_test(int argc, char** argv);
+int kill_main(int argc, char **argv);
#if ENABLE_ROUTE
void bb_displayroutes(int noresolve, int netstatfmt);
#endif
int create_icmp_socket(void);
int create_icmp6_socket(void);
/* interface.c */
+/* This structure defines protocol families and their handlers. */
+struct aftype {
+ const char *name;
+ const char *title;
+ int af;
+ int alen;
+ char *(*print) (unsigned char *);
+ const char *(*sprint) (struct sockaddr *, int numeric);
+ int (*input) (/*int type,*/ const char *bufp, struct sockaddr *);
+ void (*herror) (char *text);
+ int (*rprint) (int options);
+ int (*rinput) (int typ, int ext, char **argv);
+
+ /* may modify src */
+ int (*getmask) (char *src, struct sockaddr * mask, char *name);
+};
+/* This structure defines hardware protocols and their handlers. */
+struct hwtype {
+ const char *name;
+ const char *title;
+ int type;
+ int alen;
+ char *(*print) (unsigned char *);
+ int (*input) (const char *, struct sockaddr *);
+ int (*activate) (int fd);
+ int suppress_null_addr;
+};
extern int interface_opt_a;
int display_interfaces(char *ifname);
const struct aftype *get_aftype(const char *name);
#ifndef BUILD_INDIVIDUAL
-struct BB_applet;
-extern const struct BB_applet *find_applet_by_name(const char *name);
+extern const struct bb_applet *find_applet_by_name(const char *name);
/* Returns only if applet is not found. */
-extern void run_applet_by_name(const char *name, int argc, char **argv);
-extern void run_current_applet_and_exit(int argc, char **argv) ATTRIBUTE_NORETURN;
+extern void run_applet_and_exit(const char *name, char **argv);
+extern void run_current_applet_and_exit(char **argv) ATTRIBUTE_NORETURN;
#endif
extern int match_fstype(const struct mntent *mt, const char *fstypes);
char *concat_path_file(const char *path, const char *filename);
char *concat_subpath_file(const char *path, const char *filename);
+/* NB: can violate const-ness (similarly to strchr) */
char *last_char_is(const char *s, int c);
extern void print_login_issue(const char *issue_file, const char *tty);
extern void print_login_prompt(void);
+extern void crypt_make_salt(char *p, int cnt);
int get_terminal_width_height(const int fd, int *width, int *height);
DIR *dir;
/* Fields are set to 0/NULL if failed to determine (or not requested) */
char *cmd;
- unsigned long vsz;
+ unsigned vsz, rss; /* we round it to kbytes */
unsigned long stime, utime;
unsigned pid;
unsigned ppid;
unsigned sid;
unsigned uid;
unsigned gid;
- /* basename of executable file in call to exec(2), size from */
- /* sizeof(task_struct.comm) in /usr/include/linux/sched.h */
char state[4];
+ char tty_str[8]; /* "maj,min" or "?" */
+ /* basename of executable in exec(2), read from /proc/N/stat, */
+ /* size from sizeof(task_struct.comm) in /usr/include/linux/sched.h */
char comm[COMM_LEN];
/* user/group? - use passwd/group parsing functions */
} procps_status_t;
PSSCAN_CMD = 1 << 6,
PSSCAN_STATE = 1 << 7,
PSSCAN_VSZ = 1 << 8,
- PSSCAN_STIME = 1 << 9,
- PSSCAN_UTIME = 1 << 10,
+ PSSCAN_RSS = 1 << 9,
+ PSSCAN_STIME = 1 << 10,
+ PSSCAN_UTIME = 1 << 11,
+ PSSCAN_TTY = 1 << 12,
/* These are all retrieved from proc/NN/stat in one go: */
PSSCAN_STAT = PSSCAN_PPID | PSSCAN_PGID | PSSCAN_SID
| PSSCAN_COMM | PSSCAN_STATE
- | PSSCAN_VSZ | PSSCAN_STIME | PSSCAN_UTIME,
+ | PSSCAN_VSZ | PSSCAN_RSS
+ | PSSCAN_STIME | PSSCAN_UTIME
+ | PSSCAN_TTY,
};
procps_status_t* alloc_procps_scan(int flags);
void free_procps_scan(procps_status_t* sp);
void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
void *md5_end(void *resbuf, md5_ctx_t *ctx);
-uint32_t *crc32_filltable(int endian);
+uint32_t *crc32_filltable(uint32_t *tbl256, int endian);
enum { /* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depend on them. */
};
#define FILEUTILS_CP_OPTSTR "pdRfils" USE_SELINUX("c")
-extern const struct BB_applet *current_applet;
+extern const struct bb_applet *current_applet;
extern const char *applet_name;
extern const char BB_BANNER[];
#ifndef BUFSIZ
#define BUFSIZ 4096
#endif
-// TODO: provide hard guarantees on minimum size of bb_common_bufsiz1
-extern char bb_common_bufsiz1[BUFSIZ+1];
+/* Providing hard guarantee on minimum size (think of BUFSIZ == 128) */
+extern char bb_common_bufsiz1[(BUFSIZ > 256*sizeof(void*) ? BUFSIZ : 256*sizeof(void*)) + 1];
/* This struct is deliberately not defined. */
/* See docs/keep_data_small.txt */
struct globals;