Compare commits

...
3 Commits
18 changed files with 180 additions and 90 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 8
SUBLEVEL = 0
SUBLEVEL = 3
EXTRAVERSION =
NAME = Unnamed
+1 -1
View File
@@ -17,7 +17,7 @@
#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
#warning Note that glibc is unsuitable for static linking anyway.
#warning If you still want to do it, remove -Wl,--gc-sections
#warning from top-level Makefile and remove this warning.
#warning from file scripts/trylink and remove this warning.
#error Aborting compilation.
#endif
+1
View File
@@ -1178,6 +1178,7 @@ unpack_gz_stream(int in, int out)
ALLOC_STATE;
bytebuffer_max = 0x8000;
bytebuffer = xmalloc(bytebuffer_max);
gunzip_src_fd = in;
again:
if (!check_header_gzip(PASS_STATE_ONLY)) {
+3 -2
View File
@@ -59,8 +59,9 @@ char get_header_tar(archive_handle_t *archive_handle)
char chksum[8]; /* 148-155 */
char typeflag; /* 156-156 */
char linkname[100]; /* 157-256 */
char magic[6]; /* 257-262 */
char version[2]; /* 263-264 */
/* POSIX: "ustar" NUL "00" */
/* GNU tar: "ustar " NUL */
char magic[8]; /* 257-264 */
char uname[32]; /* 265-296 */
char gname[32]; /* 297-328 */
char devmajor[8]; /* 329-336 */
+3 -2
View File
@@ -50,8 +50,9 @@ struct TarHeader { /* byte offset */
char chksum[8]; /* 148-155 */
char typeflag; /* 156-156 */
char linkname[NAME_SIZE]; /* 157-256 */
char magic[6]; /* 257-262 */
char version[2]; /* 263-264 */
/* POSIX: "ustar" NUL "00" */
/* GNU tar: "ustar " NUL */
char magic[8]; /* 257-264 */
char uname[32]; /* 265-296 */
char gname[32]; /* 297-328 */
char devmajor[8]; /* 329-336 */
+11 -3
View File
@@ -41,8 +41,10 @@ enum {
#endif
};
#define ZIP_HEADER_LEN 26
typedef union {
uint8_t raw[26];
uint8_t raw[ZIP_HEADER_LEN];
struct {
uint16_t version; /* 0-1 */
uint16_t flags; /* 2-3 */
@@ -57,8 +59,14 @@ typedef union {
} formatted ATTRIBUTE_PACKED;
} zip_header_t;
/* Check the offset of the last element, not the length. This leniency
* allows for poor packing, whereby the overall struct may be too long,
* even though the elements are all in the right place.
*/
struct BUG_zip_header_must_be_26_bytes {
char BUG_zip_header_must_be_26_bytes[sizeof(zip_header_t) == 26 ? 1 : -1];
char BUG_zip_header_must_be_26_bytes[
offsetof(zip_header_t, formatted.extra_len) + 2 ==
ZIP_HEADER_LEN ? 1 : -1];
};
#define FIX_ENDIANNESS(zip_header) do { \
@@ -256,7 +264,7 @@ int unzip_main(int argc, char **argv)
bb_error_msg_and_die("invalid zip magic %08X", magic);
/* Read the file header */
xread(src_fd, zip_header.raw, sizeof(zip_header));
xread(src_fd, zip_header.raw, ZIP_HEADER_LEN);
FIX_ENDIANNESS(zip_header);
if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method);
+5 -3
View File
@@ -173,7 +173,8 @@ int tr_main(int argc, char **argv)
int idx = 1;
int i;
smalluint flags = 0;
size_t read_chars = 0, in_index = 0, out_index = 0, c, coded, last = -1;
ssize_t read_chars = 0;
size_t in_index = 0, out_index = 0, c, coded, last = -1;
RESERVE_CONFIG_UBUFFER(output, BUFSIZ);
RESERVE_CONFIG_BUFFER(vector, ASCII+1);
RESERVE_CONFIG_BUFFER(invec, ASCII+1);
@@ -223,8 +224,9 @@ int tr_main(int argc, char **argv)
}
read_chars = read(STDIN_FILENO, tr_buf, BUFSIZ);
if (read_chars <= 0) {
if (write(STDOUT_FILENO, (char *)output, out_index) != out_index)
bb_perror_msg(bb_msg_write_error);
xwrite(STDOUT_FILENO, (char *)output, out_index);
if (read_chars < 0)
bb_perror_msg_and_die(bb_msg_read_error);
exit(EXIT_SUCCESS);
}
in_index = 0;
+6 -3
View File
@@ -184,6 +184,7 @@ struct globals {
#if ENABLE_FEATURE_VI_COLON
char *initial_cmds[3]; // currently 2 entries, NULL terminated
#endif
char readbuffer[MAX_LINELEN];
};
#define G (*ptr_to_globals)
#define text (G.text )
@@ -200,6 +201,10 @@ struct globals {
#define term_orig (G.term_orig )
#define term_vi (G.term_vi )
#define initial_cmds (G.initial_cmds )
#define readbuffer (G.readbuffer )
#define INIT_G() do { \
PTR_TO_GLOBALS = xzalloc(sizeof(G)); \
} while (0)
static int init_text_buffer(char *); // init from file or create new
static void edit_file(char *); // edit one file
@@ -321,7 +326,7 @@ int vi_main(int argc, char **argv)
my_pid = getpid();
#endif
PTR_TO_GLOBALS = xzalloc(sizeof(G));
INIT_G();
#if ENABLE_FEATURE_VI_CRASHME
srand((long) my_pid);
@@ -2142,8 +2147,6 @@ static int mysleep(int hund) // sleep for 'h' 1/100 seconds
return safe_poll(pfd, 1, hund*10) > 0;
}
#define readbuffer bb_common_bufsiz1
static int readed_for_parse;
//----- IO Routines --------------------------------------------
+5 -4
View File
@@ -1211,7 +1211,7 @@ static void parse_prompt(const char *prmt_ptr)
#endif
#define setTermSettings(fd, argp) tcsetattr(fd, TCSANOW, argp)
#define getTermSettings(fd, argp) tcgetattr(fd, argp);
#define getTermSettings(fd, argp) tcgetattr(fd, argp)
static sighandler_t previous_SIGWINCH_handler;
@@ -1270,9 +1270,10 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
smalluint prevc;
#endif
getTermSettings(0, (void *) &initial_settings);
/* Happens when e.g. stty -echo was run before */
if (!(initial_settings.c_lflag & ECHO)) {
if (getTermSettings(0, (void *) &initial_settings) < 0
/* Happens when e.g. stty -echo was run before */
|| !(initial_settings.c_lflag & ECHO)
) {
parse_prompt(prompt);
fflush(stdout);
fgets(command, maxsize, stdin);
+42 -23
View File
@@ -239,9 +239,14 @@ int login_main(int argc, char **argv)
char full_tty[TTYNAME_SIZE];
USE_SELINUX(security_context_t user_sid = NULL;)
USE_FEATURE_UTMP(struct utmp utent;)
USE_PAM(pam_handle_t *pamh;)
USE_PAM(int pamret;)
USE_PAM(const char *failed_msg;)
#if ENABLE_PAM
int pamret;
pam_handle_t *pamh;
const char *pamuser;
const char *failed_msg;
struct passwd pwdstruct;
char pwdbuf[256];
#endif
short_tty = full_tty;
username[0] = '\0';
@@ -297,18 +302,18 @@ int login_main(int argc, char **argv)
#if ENABLE_PAM
pamret = pam_start("login", username, &conv, &pamh);
if (pamret != PAM_SUCCESS) {
failed_msg = "pam_start";
failed_msg = "start";
goto pam_auth_failed;
}
/* set TTY (so things like securetty work) */
pamret = pam_set_item(pamh, PAM_TTY, short_tty);
if (pamret != PAM_SUCCESS) {
failed_msg = "pam_set_item(TTY)";
failed_msg = "set_item(TTY)";
goto pam_auth_failed;
}
pamret = pam_authenticate(pamh, 0);
if (pamret != PAM_SUCCESS) {
failed_msg = "pam_authenticate";
failed_msg = "authenticate";
goto pam_auth_failed;
/* TODO: or just "goto auth_failed"
* since user seems to enter wrong password
@@ -318,28 +323,42 @@ int login_main(int argc, char **argv)
/* check that the account is healthy */
pamret = pam_acct_mgmt(pamh, 0);
if (pamret != PAM_SUCCESS) {
failed_msg = "account setup";
failed_msg = "acct_mgmt";
goto pam_auth_failed;
}
/* read user back */
{
const char *pamuser;
/* gcc: "dereferencing type-punned pointer breaks aliasing rules..."
* thus we cast to (void*) */
if (pam_get_item(pamh, PAM_USER, (void*)&pamuser) != PAM_SUCCESS) {
failed_msg = "pam_get_item(USER)";
goto pam_auth_failed;
}
safe_strncpy(username, pamuser, sizeof(username));
pamuser = NULL;
/* gcc: "dereferencing type-punned pointer breaks aliasing rules..."
* thus we cast to (void*) */
if (pam_get_item(pamh, PAM_USER, (void*)&pamuser) != PAM_SUCCESS) {
failed_msg = "get_item(USER)";
goto pam_auth_failed;
}
/* If we get here, the user was authenticated, and is
* granted access. */
pw = getpwnam(username);
if (pw)
break;
goto auth_failed;
if (!pamuser || !pamuser[0])
goto auth_failed;
safe_strncpy(username, pamuser, sizeof(username));
/* Don't use "pw = getpwnam(username);",
* PAM is said to be capable of destroying static storage
* used by getpwnam(). We are using safe(r) function */
pw = NULL;
getpwnam_r(username, &pwdstruct, pwdbuf, sizeof(pwdbuf), &pw);
if (!pw)
goto auth_failed;
pamret = pam_open_session(pamh, 0);
if (pamret != PAM_SUCCESS) {
failed_msg = "open_session";
goto pam_auth_failed;
}
pamret = pam_setcred(pamh, PAM_ESTABLISH_CRED);
if (pamret != PAM_SUCCESS) {
failed_msg = "setcred";
goto pam_auth_failed;
}
break; /* success, continue login process */
pam_auth_failed:
bb_error_msg("%s failed: %s (%d)", failed_msg, pam_strerror(pamh, pamret), pamret);
bb_error_msg("pam_%s call failed: %s (%d)", failed_msg,
pam_strerror(pamh, pamret), pamret);
safe_strncpy(username, "UNKNOWN", sizeof(username));
#else /* not PAM */
pw = getpwnam(username);
+1 -1
View File
@@ -791,7 +791,7 @@ static void check_dep(char *mod, struct mod_list_t **head, struct mod_list_t **t
if (*tail)
(*tail)->m_next = find;
find->m_prev = *tail;
/*find->m_next = NULL; - xzalloc did it */
find->m_next = NULL; /* possibly NOT done by xzalloc! */
if (!*head)
*head = find;
+2 -1
View File
@@ -207,7 +207,8 @@ static int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
}
if (last) {
printf(" %u.%03ums\n", last / 1000, last % 1000);
unsigned diff = MONOTONIC_US() - last;
printf(" %u.%03ums\n", diff / 1000, diff % 1000);
} else {
printf(" UNSOLICITED?\n");
}
+1 -1
View File
@@ -813,7 +813,7 @@ static servtab_t *getconfigent(void)
sep->se_bi = NULL;
#endif
argc = 0;
for (; cp; arg = skip(&cp)) {
for (arg = skip(&cp); cp; arg = skip(&cp)) {
if (argc < MAXARGV)
sep->se_argv[argc++] = xxstrdup(arg);
}
+23 -11
View File
@@ -279,6 +279,10 @@ make_new_session(
/* make new session and process group */
setsid();
/* Restore default signal handling */
signal(SIGCHLD, SIG_DFL);
signal(SIGPIPE, SIG_DFL);
/* open the child's side of the tty. */
/* NB: setsid() disconnects from any previous ctty's. Therefore
* we must open child's side of the tty AFTER setsid! */
@@ -302,14 +306,18 @@ make_new_session(
/* Uses FILE-based I/O to stdout, but does fflush(stdout),
* so should be safe with vfork.
* I fear, though, that some users will have ridiculously big
* issue files, and they may block writing to fd 1. */
* issue files, and they may block writing to fd 1,
* (parent is supposed to read it, but parent waits
* for vforked child to exec!) */
print_login_issue(issuefile, NULL);
/* Exec shell / login / whatever */
login_argv[0] = loginpath;
login_argv[1] = NULL;
execvp(loginpath, (char **)login_argv);
/* Safer with vfork, and we shouldn't send message
/* exec busybox applet (if PREFER_APPLETS=y), if that fails,
* exec external program */
BB_EXECVP(loginpath, (char **)login_argv);
/* _exit is safer with vfork, and we shouldn't send message
* to remote clients anyway */
_exit(1); /*bb_perror_msg_and_die("execv %s", loginpath);*/
}
@@ -374,7 +382,7 @@ free_session(struct tsession *ts)
#else /* !FEATURE_TELNETD_STANDALONE */
/* Used in main() only, thus exits. */
/* Used in main() only, thus "return 0" actually is exit(0). */
#define free_session(ts) return 0
#endif
@@ -384,20 +392,22 @@ static void handle_sigchld(int sig)
pid_t pid;
struct tsession *ts;
pid = waitpid(-1, &sig, WNOHANG);
if (pid > 0) {
/* Looping: more than one child may have exited */
while (1) {
pid = waitpid(-1, NULL, WNOHANG);
if (pid <= 0)
break;
ts = sessions;
while (ts) {
if (ts->shell_pid == pid) {
ts->shell_pid = -1;
return;
break;
}
ts = ts->next;
}
}
}
int telnetd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int telnetd_main(int argc, char **argv)
{
@@ -430,7 +440,7 @@ int telnetd_main(int argc, char **argv)
if (!(opt & OPT_FOREGROUND)) {
/* DAEMON_CHDIR_ROOT was giving inconsistent
* behavior with/without -F, -i */
bb_daemonize_or_rexec(0 /*DAEMON_CHDIR_ROOT*/, argv);
bb_daemonize_or_rexec(0 /*was DAEMON_CHDIR_ROOT*/, argv);
}
}
/* Redirect log to syslog early, if needed */
@@ -466,6 +476,8 @@ int telnetd_main(int argc, char **argv)
if (opt & OPT_WATCHCHILD)
signal(SIGCHLD, handle_sigchld);
else /* prevent dead children from becoming zombies */
signal(SIGCHLD, SIG_IGN);
/*
This is how the buffers are used. The arrows indicate the movement
@@ -497,7 +509,7 @@ int telnetd_main(int argc, char **argv)
while (ts) {
struct tsession *next = ts->next; /* in case we free ts. */
if (ts->shell_pid == -1) {
/* Child died ad we detected that */
/* Child died and we detected that */
free_session(ts);
} else {
if (ts->size1 > 0) /* can write to pty */
@@ -514,7 +526,7 @@ int telnetd_main(int argc, char **argv)
if (!IS_INETD) {
FD_SET(master_fd, &rdfdset);
/* This is needed because free_session() does not
* take into account master_fd when it finds new
* take master_fd into account when it finds new
* maxfd among remaining fd's */
if (master_fd > maxfd)
maxfd = master_fd;
+15 -3
View File
@@ -1,5 +1,4 @@
#
#
CONFIG_HAVE_DOT_CONFIG=y
#
@@ -37,10 +36,9 @@ CONFIG_FEATURE_HAVE_RPC=y
#
# CONFIG_STATIC is not set
# CONFIG_BUILD_LIBBUSYBOX is not set
# CONFIG_FEATURE_FULL_LIBBUSYBOX is not set
# CONFIG_FEATURE_INDIVIDUAL is not set
# CONFIG_FEATURE_SHARED_BUSYBOX is not set
CONFIG_LFS=y
# CONFIG_BUILD_AT_ONCE is not set
#
# Debugging Options
@@ -58,7 +56,11 @@ CONFIG_INCLUDE_SUSv2=y
# CONFIG_INSTALL_NO_USR is not set
CONFIG_INSTALL_APPLET_SYMLINKS=y
# CONFIG_INSTALL_APPLET_HARDLINKS is not set
# CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS is not set
# CONFIG_INSTALL_APPLET_DONT is not set
# CONFIG_INSTALL_SH_APPLET_SYMLINK is not set
# CONFIG_INSTALL_SH_APPLET_HARDLINK is not set
# CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set
CONFIG_PREFIX="./_install"
#
@@ -90,6 +92,7 @@ CONFIG_IOCTL_HEX2STR_ERROR=y
CONFIG_AR=y
CONFIG_FEATURE_AR_LONG_FILENAMES=y
CONFIG_BUNZIP2=y
CONFIG_BZIP2=y
CONFIG_CPIO=y
# CONFIG_DPKG is not set
# CONFIG_DPKG_DEB is not set
@@ -261,6 +264,7 @@ CONFIG_CHVT=y
CONFIG_CLEAR=y
CONFIG_DEALLOCVT=y
CONFIG_DUMPKMAP=y
CONFIG_KBD_MODE=y
CONFIG_LOADFONT=y
CONFIG_LOADKMAP=y
CONFIG_OPENVT=y
@@ -465,6 +469,7 @@ CONFIG_FEATURE_MKSWAP_V0=y
CONFIG_MORE=y
CONFIG_FEATURE_USE_TERMIOS=y
CONFIG_MOUNT=y
CONFIG_FEATURE_MOUNT_HELPERS=y
CONFIG_FEATURE_MOUNT_NFS=y
CONFIG_FEATURE_MOUNT_CIFS=y
CONFIG_FEATURE_MOUNT_FLAGS=y
@@ -549,6 +554,7 @@ CONFIG_FTPPUT=y
CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS=y
CONFIG_HOSTNAME=y
CONFIG_HTTPD=y
CONFIG_FEATURE_HTTPD_RANGES=y
CONFIG_FEATURE_HTTPD_USE_SENDFILE=y
# CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP is not set
# CONFIG_FEATURE_HTTPD_SETUID is not set
@@ -560,6 +566,7 @@ CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR=y
CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV=y
CONFIG_FEATURE_HTTPD_ENCODE_URL_STR=y
CONFIG_FEATURE_HTTPD_ERROR_PAGES=y
CONFIG_FEATURE_HTTPD_PROXY=y
CONFIG_IFCONFIG=y
CONFIG_FEATURE_IFCONFIG_STATUS=y
CONFIG_FEATURE_IFCONFIG_SLIP=y
@@ -589,6 +596,7 @@ CONFIG_FEATURE_IP_ROUTE=y
CONFIG_FEATURE_IP_TUNNEL=y
CONFIG_FEATURE_IP_RULE=y
CONFIG_FEATURE_IP_SHORT_FORMS=y
CONFIG_FEATURE_IP_RARE_PROTOCOLS=y
CONFIG_IPADDR=y
CONFIG_IPLINK=y
CONFIG_IPROUTE=y
@@ -647,9 +655,11 @@ CONFIG_KILL=y
CONFIG_KILLALL=y
CONFIG_KILLALL5=y
CONFIG_NMETER=y
CONFIG_PGREP=y
CONFIG_PIDOF=y
CONFIG_FEATURE_PIDOF_SINGLE=y
CONFIG_FEATURE_PIDOF_OMIT=y
CONFIG_PKILL=y
CONFIG_PS=y
CONFIG_FEATURE_PS_WIDE=y
CONFIG_RENICE=y
@@ -658,6 +668,7 @@ CONFIG_TOP=y
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
# CONFIG_FEATURE_TOP_DECIMALS is not set
CONFIG_FEATURE_TOPMEM=y
CONFIG_UPTIME=y
CONFIG_WATCH=y
@@ -743,6 +754,7 @@ CONFIG_SOFTLIMIT=y
# CONFIG_SETENFORCE is not set
# CONFIG_SETFILES is not set
# CONFIG_FEATURE_SETFILES_CHECK_OPTION is not set
# CONFIG_SETSEBOOL is not set
#
# ipsvd utilities
+18 -7
View File
@@ -46,6 +46,14 @@ try() {
return $exitcode
}
check_cc() {
if $CC $1 -shared -o /dev/null -xc /dev/null > /dev/null 2>&1; then
echo "$1";
else
echo "$2";
fi
}
EXE="$1"
CC="$2"
LDFLAGS="$3"
@@ -53,6 +61,9 @@ O_FILES="$4"
A_FILES="$5"
LDLIBS="$6"
# The -Wl,--sort-section option is not supported by older versions of ld
SORT_SECTION=`check_cc "-Wl,--sort-section -Wl,alignment" ""`
# Sanitize lib list (dups, extra spaces etc)
LDLIBS=`echo "$LDLIBS" | xargs -n1 | sort | uniq | xargs`
@@ -64,7 +75,7 @@ test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group"
try $CC $LDFLAGS \
-o $EXE \
-Wl,--sort-common \
-Wl,--sort-section -Wl,alignment \
$SORT_SECTION \
-Wl,--gc-sections \
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
$l_list \
@@ -88,7 +99,7 @@ while test "$LDLIBS"; do
try $CC $LDFLAGS \
-o $EXE \
-Wl,--sort-common \
-Wl,--sort-section -Wl,alignment \
$SORT_SECTION \
-Wl,--gc-sections \
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
$l_list
@@ -117,7 +128,7 @@ if ! test -f busybox_ldscript; then
try $CC $LDFLAGS \
-o $EXE \
-Wl,--sort-common \
-Wl,--sort-section -Wl,alignment \
$SORT_SECTION \
-Wl,--gc-sections \
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
$l_list \
@@ -139,7 +150,7 @@ else
try $CC $LDFLAGS \
-o $EXE \
-Wl,--sort-common \
-Wl,--sort-section -Wl,alignment \
$SORT_SECTION \
-Wl,--gc-sections \
-Wl,-T -Wl,busybox_ldscript \
-Wl,--start-group $O_FILES $A_FILES -Wl,--end-group \
@@ -174,7 +185,7 @@ if test "$CONFIG_BUILD_LIBBUSYBOX" = y; then
-Wl,-soname="libbusybox.so.$BB_VER" \
-Wl,--undefined=lbb_main \
-Wl,--sort-common \
-Wl,--sort-section -Wl,alignment \
$SORT_SECTION \
-Wl,--start-group $A_FILES -Wl,--end-group \
$l_list \
-Wl,--warn-common \
@@ -195,7 +206,7 @@ if test "$CONFIG_FEATURE_SHARED_BUSYBOX" = y; then
try $CC $LDFLAGS \
-o $EXE \
-Wl,--sort-common \
-Wl,--sort-section -Wl,alignment \
$SORT_SECTION \
-Wl,--gc-sections \
-Wl,--start-group $O_FILES -Wl,--end-group \
-L"$sharedlib_dir" -lbusybox \
@@ -234,7 +245,7 @@ int main(int argc, char **argv)
try $CC $LDFLAGS "$sharedlib_dir/applet.c" \
-o $EXE \
-Wl,--sort-common \
-Wl,--sort-section -Wl,alignment \
$SORT_SECTION \
-Wl,--gc-sections \
-L"$sharedlib_dir" -lbusybox \
-Wl,--warn-common \
+15 -14
View File
@@ -157,8 +157,8 @@ static int shell_context; /* Type prompt trigger (PS1 or PS2) */
static char *cwd;
static char *local_pending_command;
static struct jobset job_list = { NULL, NULL };
static int argc;
static char **argv;
static int global_argc;
static char **global_argv;
static llist_t *close_me_list;
static int last_return_code;
static int last_bg_pid;
@@ -810,16 +810,16 @@ static int expand_arguments(char *command)
var = itoa(getpid());
break;
case '#':
var = itoa(argc-1);
var = itoa(global_argc - 1);
break;
case '0':case '1':case '2':case '3':case '4':
case '5':case '6':case '7':case '8':case '9':
{
int ixx = *(dst+1)-48+1;
if (ixx >= argc) {
if (ixx >= global_argc) {
var = '\0';
} else {
var = argv[ixx];
var = global_argv[ixx];
}
}
break;
@@ -1492,12 +1492,13 @@ static inline void setup_job_control(void)
#endif
int lash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int lash_main(int argc_l, char **argv_l)
int lash_main(int argc, char **argv)
{
unsigned opt;
FILE *input = stdin;
argc = argc_l;
argv = argv_l;
global_argc = argc;
global_argv = argv;
#if ENABLE_FEATURE_EDITING
line_input_state = new_line_input_t(FOR_SHELL);
@@ -1510,7 +1511,7 @@ int lash_main(int argc_l, char **argv_l)
job_list.fg = NULL;
last_return_code = 1;
if (argv[0] && argv[0][0] == '-') {
if (global_argv[0] && global_argv[0][0] == '-') {
FILE *prof_input;
prof_input = fopen("/etc/profile", "r");
if (prof_input) {
@@ -1522,13 +1523,13 @@ int lash_main(int argc_l, char **argv_l)
}
}
opt = getopt32(argv_l, "+ic:", &local_pending_command);
opt = getopt32(argv, "+ic:", &local_pending_command);
#define LASH_OPT_i (1<<0)
#define LASH_OPT_c (1<<1)
if (opt & LASH_OPT_c) {
input = NULL;
optind++;
argv += optind;
global_argv += optind;
}
/* A shell is interactive if the `-i' flag was given, or if all of
* the following conditions are met:
@@ -1537,7 +1538,7 @@ int lash_main(int argc_l, char **argv_l)
* standard input is a terminal
* standard output is a terminal
* Refer to Posix.2, the description of the `sh' utility. */
if (argv[optind] == NULL && input == stdin
if (global_argv[optind] == NULL && input == stdin
&& isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)
) {
opt |= LASH_OPT_i;
@@ -1550,9 +1551,9 @@ int lash_main(int argc_l, char **argv_l)
"Enter 'help' for a list of built-in commands.\n\n",
bb_banner);
}
} else if (!local_pending_command && argv[optind]) {
} else if (!local_pending_command && global_argv[optind]) {
//printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
input = xfopen(argv[optind], "r");
input = xfopen(global_argv[optind], "r");
/* be lazy, never mark this closed */
llist_add_to(&close_me_list, (void *)(long)fileno(input));
}
+27 -10
View File
@@ -381,8 +381,8 @@ static void parse_fac_prio_20(int pri, char *res20)
}
/* len parameter is used only for "is there a timestamp?" check.
* NB: some callers cheat and supply 0 when they know
* that there is no timestamp, short-cutting the test. */
* NB: some callers cheat and supply len==0 when they know
* that there is no timestamp, short-circuiting the test. */
static void timestamp_and_log(int pri, char *msg, int len)
{
char *timestamp;
@@ -427,10 +427,10 @@ static void split_escape_and_log(char *tmpbuf, int len)
if (*p == '<') {
/* Parse the magic priority number */
pri = bb_strtou(p + 1, &p, 10);
if (*p == '>') p++;
if (pri & ~(LOG_FACMASK | LOG_PRIMASK)) {
if (*p == '>')
p++;
if (pri & ~(LOG_FACMASK | LOG_PRIMASK))
pri = (LOG_USER | LOG_NOTICE);
}
}
while ((c = *p++)) {
@@ -526,14 +526,32 @@ static void do_syslogd(void)
for (;;) {
size_t sz;
read_again:
sz = safe_read(sock_fd, G.recvbuf, MAX_READ - 1);
if (sz <= 0) {
//if (sz == 0)
// continue; /* EOF from unix socket??? */
if (sz < 0) {
bb_perror_msg_and_die("read from /dev/log");
}
/* Drop trailing NULs (typically there is one NUL) */
while (1) {
if (sz == 0)
goto read_again;
/* man 3 syslog says: "A trailing newline is added when needed".
* However, neither glibc nor uclibc do this:
* syslog(prio, "test") sends "test\0" to /dev/log,
* syslog(prio, "test\n") sends "test\n\0",
* IOW: newline is passed verbatim!
* I take it to mean that it's syslogd's job
* to make those look identical in the log files */
if (G.recvbuf[sz-1] && G.recvbuf[sz-1] != '\n')
break;
sz--;
}
/* Maybe we need to add '\n' here, not later?
* It looks like stock syslogd does send '\n' over network,
* but we do not (see sendto below) */
G.recvbuf[sz] = '\0'; /* make sure it *is* NUL terminated */
/* TODO: maybe suppress duplicates? */
#if ENABLE_FEATURE_REMOTE_LOG
/* We are not modifying log messages in any way before send */
@@ -549,7 +567,6 @@ static void do_syslogd(void)
}
}
#endif
G.recvbuf[sz] = '\0';
split_escape_and_log(G.recvbuf, sz);
} /* for */
}