Merge branch 'master' of git+ssh://vda@busybox.net/var/lib/git/busybox
This commit is contained in:
commit
e18255d1da
@ -326,6 +326,7 @@ IF_RUNSV(APPLET(runsv, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
|||||||
IF_RUNSVDIR(APPLET(runsvdir, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
IF_RUNSVDIR(APPLET(runsvdir, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
||||||
IF_RX(APPLET(rx, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
IF_RX(APPLET(rx, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
||||||
IF_SCRIPT(APPLET(script, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
IF_SCRIPT(APPLET(script, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
|
||||||
|
IF_SCRIPTREPLAY(APPLET(scriptreplay, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||||
IF_SED(APPLET(sed, _BB_DIR_BIN, _BB_SUID_NEVER))
|
IF_SED(APPLET(sed, _BB_DIR_BIN, _BB_SUID_NEVER))
|
||||||
IF_SELINUXENABLED(APPLET(selinuxenabled, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
|
IF_SELINUXENABLED(APPLET(selinuxenabled, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
|
||||||
IF_SENDMAIL(APPLET(sendmail, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
|
IF_SENDMAIL(APPLET(sendmail, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
/* __restrict is known in EGCS 1.2 and above. */
|
/* __restrict is known in EGCS 1.2 and above. */
|
||||||
#if !__GNUC_PREREQ(2,92)
|
#if !__GNUC_PREREQ(2,92)
|
||||||
# ifndef __restrict
|
# ifndef __restrict
|
||||||
# define __restrict /* Ignore */
|
# define __restrict
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -61,14 +61,14 @@
|
|||||||
# define DEPRECATED __attribute__ ((__deprecated__))
|
# define DEPRECATED __attribute__ ((__deprecated__))
|
||||||
# define UNUSED_PARAM_RESULT __attribute__ ((warn_unused_result))
|
# define UNUSED_PARAM_RESULT __attribute__ ((warn_unused_result))
|
||||||
# else
|
# else
|
||||||
# define DEPRECATED /* n/a */
|
# define DEPRECATED
|
||||||
# define UNUSED_PARAM_RESULT /* n/a */
|
# define UNUSED_PARAM_RESULT
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
# define ALWAYS_INLINE inline /* n/a */
|
# define ALWAYS_INLINE inline
|
||||||
# define NOINLINE /* n/a */
|
# define NOINLINE
|
||||||
# define DEPRECATED /* n/a */
|
# define DEPRECATED
|
||||||
# define UNUSED_PARAM_RESULT /* n/a */
|
# define UNUSED_PARAM_RESULT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* -fwhole-program makes all symbols local. The attribute externally_visible
|
/* -fwhole-program makes all symbols local. The attribute externally_visible
|
||||||
@ -144,19 +144,19 @@
|
|||||||
|
|
||||||
/* SWAP_LEnn means "convert CPU<->little_endian by swapping bytes" */
|
/* SWAP_LEnn means "convert CPU<->little_endian by swapping bytes" */
|
||||||
#if BB_BIG_ENDIAN
|
#if BB_BIG_ENDIAN
|
||||||
#define SWAP_BE16(x) (x)
|
# define SWAP_BE16(x) (x)
|
||||||
#define SWAP_BE32(x) (x)
|
# define SWAP_BE32(x) (x)
|
||||||
#define SWAP_BE64(x) (x)
|
# define SWAP_BE64(x) (x)
|
||||||
#define SWAP_LE16(x) bswap_16(x)
|
# define SWAP_LE16(x) bswap_16(x)
|
||||||
#define SWAP_LE32(x) bswap_32(x)
|
# define SWAP_LE32(x) bswap_32(x)
|
||||||
#define SWAP_LE64(x) bswap_64(x)
|
# define SWAP_LE64(x) bswap_64(x)
|
||||||
#else
|
#else
|
||||||
#define SWAP_BE16(x) bswap_16(x)
|
# define SWAP_BE16(x) bswap_16(x)
|
||||||
#define SWAP_BE32(x) bswap_32(x)
|
# define SWAP_BE32(x) bswap_32(x)
|
||||||
#define SWAP_BE64(x) bswap_64(x)
|
# define SWAP_BE64(x) bswap_64(x)
|
||||||
#define SWAP_LE16(x) (x)
|
# define SWAP_LE16(x) (x)
|
||||||
#define SWAP_LE32(x) (x)
|
# define SWAP_LE32(x) (x)
|
||||||
#define SWAP_LE64(x) (x)
|
# define SWAP_LE64(x) (x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ---- Unaligned access ------------------------------------ */
|
/* ---- Unaligned access ------------------------------------ */
|
||||||
@ -165,15 +165,15 @@
|
|||||||
* a lvalue. This makes it more likely to not swap them by mistake
|
* a lvalue. This makes it more likely to not swap them by mistake
|
||||||
*/
|
*/
|
||||||
#if defined(i386) || defined(__x86_64__)
|
#if defined(i386) || defined(__x86_64__)
|
||||||
#define move_from_unaligned16(v, u16p) ((v) = *(uint16_t*)(u16p))
|
# define move_from_unaligned16(v, u16p) ((v) = *(uint16_t*)(u16p))
|
||||||
#define move_from_unaligned32(v, u32p) ((v) = *(uint32_t*)(u32p))
|
# define move_from_unaligned32(v, u32p) ((v) = *(uint32_t*)(u32p))
|
||||||
#define move_to_unaligned32(u32p, v) (*(uint32_t*)(u32p) = (v))
|
# define move_to_unaligned32(u32p, v) (*(uint32_t*)(u32p) = (v))
|
||||||
/* #elif ... - add your favorite arch today! */
|
/* #elif ... - add your favorite arch today! */
|
||||||
#else
|
#else
|
||||||
/* performs reasonably well (gcc usually inlines memcpy here) */
|
/* performs reasonably well (gcc usually inlines memcpy here) */
|
||||||
#define move_from_unaligned16(v, u16p) (memcpy(&(v), (u16p), 2))
|
# define move_from_unaligned16(v, u16p) (memcpy(&(v), (u16p), 2))
|
||||||
#define move_from_unaligned32(v, u32p) (memcpy(&(v), (u32p), 4))
|
# define move_from_unaligned32(v, u32p) (memcpy(&(v), (u32p), 4))
|
||||||
#define move_to_unaligned32(u32p, v) do { \
|
# define move_to_unaligned32(u32p, v) do { \
|
||||||
uint32_t __t = (v); \
|
uint32_t __t = (v); \
|
||||||
memcpy((u32p), &__t, 4); \
|
memcpy((u32p), &__t, 4); \
|
||||||
} while (0)
|
} while (0)
|
||||||
@ -225,21 +225,21 @@ __extension__ typedef unsigned long long __u64;
|
|||||||
|
|
||||||
#if defined __GLIBC__ || defined __UCLIBC__ \
|
#if defined __GLIBC__ || defined __UCLIBC__ \
|
||||||
|| defined __dietlibc__ || defined _NEWLIB_VERSION
|
|| defined __dietlibc__ || defined _NEWLIB_VERSION
|
||||||
#include <features.h>
|
# include <features.h>
|
||||||
#define HAVE_FEATURES_H
|
# define HAVE_FEATURES_H
|
||||||
#include <stdint.h>
|
# include <stdint.h>
|
||||||
#define HAVE_STDINT_H
|
# define HAVE_STDINT_H
|
||||||
#elif !defined __APPLE__
|
#elif !defined __APPLE__
|
||||||
/* Largest integral types. */
|
/* Largest integral types. */
|
||||||
#if __BIG_ENDIAN__
|
# if __BIG_ENDIAN__
|
||||||
typedef long intmax_t;
|
typedef long intmax_t;
|
||||||
typedef unsigned long uintmax_t;
|
typedef unsigned long uintmax_t;
|
||||||
#else
|
# else
|
||||||
__extension__
|
__extension__
|
||||||
typedef long long intmax_t;
|
typedef long long intmax_t;
|
||||||
__extension__
|
__extension__
|
||||||
typedef unsigned long long uintmax_t;
|
typedef unsigned long long uintmax_t;
|
||||||
#endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Size-saving "small" ints (arch-dependent) */
|
/* Size-saving "small" ints (arch-dependent) */
|
||||||
@ -256,20 +256,20 @@ typedef unsigned smalluint;
|
|||||||
/* ISO C Standard: 7.16 Boolean type and values <stdbool.h> */
|
/* ISO C Standard: 7.16 Boolean type and values <stdbool.h> */
|
||||||
#if (defined __digital__ && defined __unix__)
|
#if (defined __digital__ && defined __unix__)
|
||||||
/* old system without (proper) C99 support */
|
/* old system without (proper) C99 support */
|
||||||
#define bool smalluint
|
# define bool smalluint
|
||||||
#else
|
#else
|
||||||
/* modern system, so use it */
|
/* modern system, so use it */
|
||||||
#include <stdbool.h>
|
# include <stdbool.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Try to defeat gcc's alignment of "char message[]"-like data */
|
/* Try to defeat gcc's alignment of "char message[]"-like data */
|
||||||
#if 1 /* if needed: !defined(arch1) && !defined(arch2) */
|
#if 1 /* if needed: !defined(arch1) && !defined(arch2) */
|
||||||
#define ALIGN1 __attribute__((aligned(1)))
|
# define ALIGN1 __attribute__((aligned(1)))
|
||||||
#define ALIGN2 __attribute__((aligned(2)))
|
# define ALIGN2 __attribute__((aligned(2)))
|
||||||
#else
|
#else
|
||||||
/* Arches which MUST have 2 or 4 byte alignment for everything are here */
|
/* Arches which MUST have 2 or 4 byte alignment for everything are here */
|
||||||
#define ALIGN1
|
# define ALIGN1
|
||||||
#define ALIGN2
|
# define ALIGN2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -281,13 +281,13 @@ typedef unsigned smalluint;
|
|||||||
#if ENABLE_NOMMU || \
|
#if ENABLE_NOMMU || \
|
||||||
(defined __UCLIBC__ && __UCLIBC_MAJOR__ >= 0 && __UCLIBC_MINOR__ >= 9 && \
|
(defined __UCLIBC__ && __UCLIBC_MAJOR__ >= 0 && __UCLIBC_MINOR__ >= 9 && \
|
||||||
__UCLIBC_SUBLEVEL__ > 28 && !defined __ARCH_USE_MMU__)
|
__UCLIBC_SUBLEVEL__ > 28 && !defined __ARCH_USE_MMU__)
|
||||||
#define BB_MMU 0
|
# define BB_MMU 0
|
||||||
#define USE_FOR_NOMMU(...) __VA_ARGS__
|
# define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||||
#define USE_FOR_MMU(...)
|
# define USE_FOR_MMU(...)
|
||||||
#else
|
#else
|
||||||
#define BB_MMU 1
|
# define BB_MMU 1
|
||||||
#define USE_FOR_NOMMU(...)
|
# define USE_FOR_NOMMU(...)
|
||||||
#define USE_FOR_MMU(...) __VA_ARGS__
|
# define USE_FOR_MMU(...) __VA_ARGS__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Platforms that haven't got dprintf need to implement fdprintf() in
|
/* Platforms that haven't got dprintf need to implement fdprintf() in
|
||||||
@ -297,7 +297,7 @@ typedef unsigned smalluint;
|
|||||||
/* Needed for: glibc */
|
/* Needed for: glibc */
|
||||||
/* Not needed for: dietlibc */
|
/* Not needed for: dietlibc */
|
||||||
/* Others: ?? (add as needed) */
|
/* Others: ?? (add as needed) */
|
||||||
#define fdprintf dprintf
|
# define fdprintf dprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__dietlibc__)
|
#if defined(__dietlibc__)
|
||||||
@ -323,7 +323,6 @@ static ALWAYS_INLINE char* strchrnul(const char *s, char c)
|
|||||||
# define PRIu32 "u"
|
# define PRIu32 "u"
|
||||||
/* use legacy setpgrp(pid_t,pid_t) for now. move to platform.c */
|
/* use legacy setpgrp(pid_t,pid_t) for now. move to platform.c */
|
||||||
# define bb_setpgrp() do { pid_t __me = getpid(); setpgrp(__me,__me); } while (0)
|
# define bb_setpgrp() do { pid_t __me = getpid(); setpgrp(__me,__me); } while (0)
|
||||||
|
|
||||||
# if !defined ADJ_OFFSET_SINGLESHOT && defined MOD_CLKA && defined MOD_OFFSET
|
# if !defined ADJ_OFFSET_SINGLESHOT && defined MOD_CLKA && defined MOD_OFFSET
|
||||||
# define ADJ_OFFSET_SINGLESHOT (MOD_CLKA | MOD_OFFSET)
|
# define ADJ_OFFSET_SINGLESHOT (MOD_CLKA | MOD_OFFSET)
|
||||||
# endif
|
# endif
|
||||||
@ -344,44 +343,53 @@ static ALWAYS_INLINE char* strchrnul(const char *s, char c)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
#include <sys/mount.h>
|
# include <sys/mount.h>
|
||||||
/* Make sure we have all the new mount flags we actually try to use. */
|
/* Make sure we have all the new mount flags we actually try to use. */
|
||||||
#ifndef MS_BIND
|
# ifndef MS_BIND
|
||||||
#define MS_BIND (1<<12)
|
# define MS_BIND (1 << 12)
|
||||||
#endif
|
# endif
|
||||||
#ifndef MS_MOVE
|
# ifndef MS_MOVE
|
||||||
#define MS_MOVE (1<<13)
|
# define MS_MOVE (1 << 13)
|
||||||
#endif
|
# endif
|
||||||
#ifndef MS_RECURSIVE
|
# ifndef MS_RECURSIVE
|
||||||
#define MS_RECURSIVE (1<<14)
|
# define MS_RECURSIVE (1 << 14)
|
||||||
#endif
|
# endif
|
||||||
#ifndef MS_SILENT
|
# ifndef MS_SILENT
|
||||||
#define MS_SILENT (1<<15)
|
# define MS_SILENT (1 << 15)
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
/* The shared subtree stuff, which went in around 2.6.15. */
|
/* The shared subtree stuff, which went in around 2.6.15. */
|
||||||
#ifndef MS_UNBINDABLE
|
# ifndef MS_UNBINDABLE
|
||||||
#define MS_UNBINDABLE (1<<17)
|
# define MS_UNBINDABLE (1 << 17)
|
||||||
#endif
|
# endif
|
||||||
#ifndef MS_PRIVATE
|
# ifndef MS_PRIVATE
|
||||||
#define MS_PRIVATE (1<<18)
|
# define MS_PRIVATE (1 << 18)
|
||||||
#endif
|
# endif
|
||||||
#ifndef MS_SLAVE
|
# ifndef MS_SLAVE
|
||||||
#define MS_SLAVE (1<<19)
|
# define MS_SLAVE (1 << 19)
|
||||||
#endif
|
# endif
|
||||||
#ifndef MS_SHARED
|
# ifndef MS_SHARED
|
||||||
#define MS_SHARED (1<<20)
|
# define MS_SHARED (1 << 20)
|
||||||
#endif
|
# endif
|
||||||
#ifndef MS_RELATIME
|
# ifndef MS_RELATIME
|
||||||
#define MS_RELATIME (1 << 21)
|
# define MS_RELATIME (1 << 21)
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if !defined(BLKSSZGET)
|
||||||
|
# define BLKSSZGET _IO(0x12, 104)
|
||||||
|
# endif
|
||||||
|
# if !defined(BLKGETSIZE64)
|
||||||
|
# define BLKGETSIZE64 _IOR(0x12,114,size_t)
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(BLKSSZGET)
|
/* The field domainname of struct utsname is Linux specific. */
|
||||||
#define BLKSSZGET _IO(0x12, 104)
|
#if !defined(__linux__)
|
||||||
#endif
|
# define HAVE_NO_UTSNAME_DOMAINNAME
|
||||||
#if !defined(BLKGETSIZE64)
|
|
||||||
#define BLKGETSIZE64 _IOR(0x12,114,size_t)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* If this system doesn't have IUCLC bit in struct termios::c_iflag... */
|
||||||
|
#ifndef IUCLC
|
||||||
|
# define IUCLC 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -3512,6 +3512,11 @@
|
|||||||
"\n -g Process group id(s)" \
|
"\n -g Process group id(s)" \
|
||||||
"\n -u Process user name(s) and/or id(s)" \
|
"\n -u Process user name(s) and/or id(s)" \
|
||||||
|
|
||||||
|
#define scriptreplay_trivial_usage \
|
||||||
|
"timingfile [typescript [divisor]]"
|
||||||
|
#define scriptreplay_full_usage "\n\n" \
|
||||||
|
"Play back typescripts, using timing information"
|
||||||
|
|
||||||
#define reset_trivial_usage \
|
#define reset_trivial_usage \
|
||||||
""
|
""
|
||||||
#define reset_full_usage "\n\n" \
|
#define reset_full_usage "\n\n" \
|
||||||
@ -3706,13 +3711,16 @@
|
|||||||
"$ rx /tmp/foo\n"
|
"$ rx /tmp/foo\n"
|
||||||
|
|
||||||
#define script_trivial_usage \
|
#define script_trivial_usage \
|
||||||
"[-afq] [-c COMMAND] [OUTFILE]"
|
"[-afq" IF_SCRIPTREPLAY("t") "] [-c COMMAND] [OUTFILE]"
|
||||||
#define script_full_usage "\n\n" \
|
#define script_full_usage "\n\n" \
|
||||||
"Options:" \
|
"Options:" \
|
||||||
"\n -a Append output" \
|
"\n -a Append output" \
|
||||||
"\n -c Run COMMAND, not shell" \
|
"\n -c Run COMMAND, not shell" \
|
||||||
"\n -f Flush output after each write" \
|
"\n -f Flush output after each write" \
|
||||||
"\n -q Quiet" \
|
"\n -q Quiet" \
|
||||||
|
IF_SCRIPTREPLAY( \
|
||||||
|
"\n -t Send timing to stderr" \
|
||||||
|
)
|
||||||
|
|
||||||
#define sed_trivial_usage \
|
#define sed_trivial_usage \
|
||||||
"[-efinr] pattern [files...]"
|
"[-efinr] pattern [files...]"
|
||||||
|
@ -62,10 +62,12 @@ void FAST_FUNC print_login_issue(const char *issue_file, const char *tty)
|
|||||||
case 'm':
|
case 'm':
|
||||||
outbuf = uts.machine;
|
outbuf = uts.machine;
|
||||||
break;
|
break;
|
||||||
|
#ifndef HAVE_NO_UTSNAME_DOMAINNAME
|
||||||
case 'D':
|
case 'D':
|
||||||
case 'o':
|
case 'o':
|
||||||
outbuf = uts.domainname;
|
outbuf = uts.domainname;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case 'd':
|
case 'd':
|
||||||
strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
|
strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
|
||||||
break;
|
break;
|
||||||
|
35
shell/hush.c
35
shell/hush.c
@ -445,6 +445,9 @@ struct globals {
|
|||||||
int last_jobid;
|
int last_jobid;
|
||||||
pid_t saved_tty_pgrp;
|
pid_t saved_tty_pgrp;
|
||||||
struct pipe *job_list;
|
struct pipe *job_list;
|
||||||
|
# define G_saved_tty_pgrp (G.saved_tty_pgrp)
|
||||||
|
#else
|
||||||
|
# define G_saved_tty_pgrp 0
|
||||||
#endif
|
#endif
|
||||||
smallint flag_SIGINT;
|
smallint flag_SIGINT;
|
||||||
#if ENABLE_HUSH_LOOPS
|
#if ENABLE_HUSH_LOOPS
|
||||||
@ -1055,8 +1058,8 @@ enum {
|
|||||||
| (1 << SIGINT)
|
| (1 << SIGINT)
|
||||||
| (1 << SIGHUP)
|
| (1 << SIGHUP)
|
||||||
,
|
,
|
||||||
#if ENABLE_HUSH_JOB
|
|
||||||
SPECIAL_JOB_SIGS = 0
|
SPECIAL_JOB_SIGS = 0
|
||||||
|
#if ENABLE_HUSH_JOB
|
||||||
| (1 << SIGTTIN)
|
| (1 << SIGTTIN)
|
||||||
| (1 << SIGTTOU)
|
| (1 << SIGTTOU)
|
||||||
| (1 << SIGTSTP)
|
| (1 << SIGTSTP)
|
||||||
@ -1088,8 +1091,8 @@ static void sigexit(int sig)
|
|||||||
|
|
||||||
/* Careful: we can end up here after [v]fork. Do not restore
|
/* Careful: we can end up here after [v]fork. Do not restore
|
||||||
* tty pgrp then, only top-level shell process does that */
|
* tty pgrp then, only top-level shell process does that */
|
||||||
if (G.saved_tty_pgrp && getpid() == G.root_pid)
|
if (G_saved_tty_pgrp && getpid() == G.root_pid)
|
||||||
tcsetpgrp(G_interactive_fd, G.saved_tty_pgrp);
|
tcsetpgrp(G_interactive_fd, G_saved_tty_pgrp);
|
||||||
|
|
||||||
/* Not a signal, just exit */
|
/* Not a signal, just exit */
|
||||||
if (sig <= 0)
|
if (sig <= 0)
|
||||||
@ -3400,7 +3403,7 @@ static int checkjobs_and_fg_shell(struct pipe* fg_pipe)
|
|||||||
{
|
{
|
||||||
pid_t p;
|
pid_t p;
|
||||||
int rcode = checkjobs(fg_pipe);
|
int rcode = checkjobs(fg_pipe);
|
||||||
if (G.saved_tty_pgrp) {
|
if (G_saved_tty_pgrp) {
|
||||||
/* Job finished, move the shell to the foreground */
|
/* Job finished, move the shell to the foreground */
|
||||||
p = getpgrp(); /* our process group id */
|
p = getpgrp(); /* our process group id */
|
||||||
debug_printf_jobs("fg'ing ourself: getpgrp()=%d\n", (int)p);
|
debug_printf_jobs("fg'ing ourself: getpgrp()=%d\n", (int)p);
|
||||||
@ -3656,7 +3659,7 @@ static int run_pipe(struct pipe *pi)
|
|||||||
pgrp = getpid();
|
pgrp = getpid();
|
||||||
if (setpgid(0, pgrp) == 0
|
if (setpgid(0, pgrp) == 0
|
||||||
&& pi->followup != PIPE_BG
|
&& pi->followup != PIPE_BG
|
||||||
&& G.saved_tty_pgrp /* we have ctty */
|
&& G_saved_tty_pgrp /* we have ctty */
|
||||||
) {
|
) {
|
||||||
/* We do it in *every* child, not just first,
|
/* We do it in *every* child, not just first,
|
||||||
* to avoid races */
|
* to avoid races */
|
||||||
@ -5954,7 +5957,7 @@ static void block_signals(int second_time)
|
|||||||
mask = (1 << SIGQUIT);
|
mask = (1 << SIGQUIT);
|
||||||
if (G_interactive_fd) {
|
if (G_interactive_fd) {
|
||||||
mask = (1 << SIGQUIT) | SPECIAL_INTERACTIVE_SIGS;
|
mask = (1 << SIGQUIT) | SPECIAL_INTERACTIVE_SIGS;
|
||||||
if (G.saved_tty_pgrp) /* we have ctty, job control sigs work */
|
if (G_saved_tty_pgrp) /* we have ctty, job control sigs work */
|
||||||
mask |= SPECIAL_JOB_SIGS;
|
mask |= SPECIAL_JOB_SIGS;
|
||||||
}
|
}
|
||||||
G.non_DFL_mask = mask;
|
G.non_DFL_mask = mask;
|
||||||
@ -6235,10 +6238,10 @@ int hush_main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
#if ENABLE_HUSH_JOB
|
#if ENABLE_HUSH_JOB
|
||||||
if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) {
|
if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) {
|
||||||
G.saved_tty_pgrp = tcgetpgrp(STDIN_FILENO);
|
G_saved_tty_pgrp = tcgetpgrp(STDIN_FILENO);
|
||||||
debug_printf("saved_tty_pgrp:%d\n", G.saved_tty_pgrp);
|
debug_printf("saved_tty_pgrp:%d\n", G_saved_tty_pgrp);
|
||||||
if (G.saved_tty_pgrp < 0)
|
if (G_saved_tty_pgrp < 0)
|
||||||
G.saved_tty_pgrp = 0;
|
G_saved_tty_pgrp = 0;
|
||||||
|
|
||||||
/* try to dup stdin to high fd#, >= 255 */
|
/* try to dup stdin to high fd#, >= 255 */
|
||||||
G_interactive_fd = fcntl(STDIN_FILENO, F_DUPFD, 255);
|
G_interactive_fd = fcntl(STDIN_FILENO, F_DUPFD, 255);
|
||||||
@ -6248,7 +6251,7 @@ int hush_main(int argc, char **argv)
|
|||||||
if (G_interactive_fd < 0) {
|
if (G_interactive_fd < 0) {
|
||||||
/* give up */
|
/* give up */
|
||||||
G_interactive_fd = 0;
|
G_interactive_fd = 0;
|
||||||
G.saved_tty_pgrp = 0;
|
G_saved_tty_pgrp = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: track & disallow any attempts of user
|
// TODO: track & disallow any attempts of user
|
||||||
@ -6258,7 +6261,7 @@ int hush_main(int argc, char **argv)
|
|||||||
if (G_interactive_fd) {
|
if (G_interactive_fd) {
|
||||||
close_on_exec_on(G_interactive_fd);
|
close_on_exec_on(G_interactive_fd);
|
||||||
|
|
||||||
if (G.saved_tty_pgrp) {
|
if (G_saved_tty_pgrp) {
|
||||||
/* If we were run as 'hush &', sleep until we are
|
/* If we were run as 'hush &', sleep until we are
|
||||||
* in the foreground (tty pgrp == our pgrp).
|
* in the foreground (tty pgrp == our pgrp).
|
||||||
* If we get started under a job aware app (like bash),
|
* If we get started under a job aware app (like bash),
|
||||||
@ -6266,8 +6269,8 @@ int hush_main(int argc, char **argv)
|
|||||||
* who gets the foreground */
|
* who gets the foreground */
|
||||||
while (1) {
|
while (1) {
|
||||||
pid_t shell_pgrp = getpgrp();
|
pid_t shell_pgrp = getpgrp();
|
||||||
G.saved_tty_pgrp = tcgetpgrp(G_interactive_fd);
|
G_saved_tty_pgrp = tcgetpgrp(G_interactive_fd);
|
||||||
if (G.saved_tty_pgrp == shell_pgrp)
|
if (G_saved_tty_pgrp == shell_pgrp)
|
||||||
break;
|
break;
|
||||||
/* send TTIN to ourself (should stop us) */
|
/* send TTIN to ourself (should stop us) */
|
||||||
kill(- shell_pgrp, SIGTTIN);
|
kill(- shell_pgrp, SIGTTIN);
|
||||||
@ -6277,7 +6280,7 @@ int hush_main(int argc, char **argv)
|
|||||||
/* Block some signals */
|
/* Block some signals */
|
||||||
block_signals(signal_mask_is_inited);
|
block_signals(signal_mask_is_inited);
|
||||||
|
|
||||||
if (G.saved_tty_pgrp) {
|
if (G_saved_tty_pgrp) {
|
||||||
/* Set other signals to restore saved_tty_pgrp */
|
/* Set other signals to restore saved_tty_pgrp */
|
||||||
set_fatal_handlers();
|
set_fatal_handlers();
|
||||||
/* Put ourselves in our own process group
|
/* Put ourselves in our own process group
|
||||||
@ -6690,7 +6693,7 @@ static int builtin_fg_bg(char **argv)
|
|||||||
found:
|
found:
|
||||||
/* TODO: bash prints a string representation
|
/* TODO: bash prints a string representation
|
||||||
* of job being foregrounded (like "sleep 1 | cat") */
|
* of job being foregrounded (like "sleep 1 | cat") */
|
||||||
if (argv[0][0] == 'f' && G.saved_tty_pgrp) {
|
if (argv[0][0] == 'f' && G_saved_tty_pgrp) {
|
||||||
/* Put the job into the foreground. */
|
/* Put the job into the foreground. */
|
||||||
tcsetpgrp(G_interactive_fd, pi->pgrp);
|
tcsetpgrp(G_interactive_fd, pi->pgrp);
|
||||||
}
|
}
|
||||||
|
@ -764,6 +764,13 @@ config SCRIPT
|
|||||||
help
|
help
|
||||||
The script makes typescript of terminal session.
|
The script makes typescript of terminal session.
|
||||||
|
|
||||||
|
config SCRIPTREPLAY
|
||||||
|
bool "scriptreplay"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
This program replays a typescript, using timing information
|
||||||
|
given by script -t.
|
||||||
|
|
||||||
config SETARCH
|
config SETARCH
|
||||||
bool "setarch"
|
bool "setarch"
|
||||||
default n
|
default n
|
||||||
|
@ -33,6 +33,7 @@ lib-$(CONFIG_RDEV) += rdev.o
|
|||||||
lib-$(CONFIG_READPROFILE) += readprofile.o
|
lib-$(CONFIG_READPROFILE) += readprofile.o
|
||||||
lib-$(CONFIG_RTCWAKE) += rtcwake.o
|
lib-$(CONFIG_RTCWAKE) += rtcwake.o
|
||||||
lib-$(CONFIG_SCRIPT) += script.o
|
lib-$(CONFIG_SCRIPT) += script.o
|
||||||
|
lib-$(CONFIG_SCRIPTREPLAY) += scriptreplay.o
|
||||||
lib-$(CONFIG_SETARCH) += setarch.o
|
lib-$(CONFIG_SETARCH) += setarch.o
|
||||||
lib-$(CONFIG_SWAPONOFF) += swaponoff.o
|
lib-$(CONFIG_SWAPONOFF) += swaponoff.o
|
||||||
lib-$(CONFIG_SWITCH_ROOT) += switch_root.o
|
lib-$(CONFIG_SWITCH_ROOT) += switch_root.o
|
||||||
|
@ -10,16 +10,8 @@
|
|||||||
*
|
*
|
||||||
* Licensed under GPLv2 or later, see file License in this tarball for details.
|
* Licensed under GPLv2 or later, see file License in this tarball for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
static smallint fd_count = 2;
|
|
||||||
|
|
||||||
static void handle_sigchld(int sig UNUSED_PARAM)
|
|
||||||
{
|
|
||||||
fd_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int script_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int script_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
int script_main(int argc UNUSED_PARAM, char **argv)
|
int script_main(int argc UNUSED_PARAM, char **argv)
|
||||||
{
|
{
|
||||||
@ -36,6 +28,15 @@ int script_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
const char *shell;
|
const char *shell;
|
||||||
char shell_opt[] = "-i";
|
char shell_opt[] = "-i";
|
||||||
char *shell_arg = NULL;
|
char *shell_arg = NULL;
|
||||||
|
enum {
|
||||||
|
OPT_a = (1 << 0),
|
||||||
|
OPT_c = (1 << 1),
|
||||||
|
OPT_f = (1 << 2),
|
||||||
|
OPT_q = (1 << 3),
|
||||||
|
#if ENABLE_SCRIPTREPLAY
|
||||||
|
OPT_t = (1 << 4),
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
#if ENABLE_GETOPT_LONG
|
#if ENABLE_GETOPT_LONG
|
||||||
static const char getopt_longopts[] ALIGN1 =
|
static const char getopt_longopts[] ALIGN1 =
|
||||||
@ -43,25 +44,28 @@ int script_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
"command\0" Required_argument "c"
|
"command\0" Required_argument "c"
|
||||||
"flush\0" No_argument "f"
|
"flush\0" No_argument "f"
|
||||||
"quiet\0" No_argument "q"
|
"quiet\0" No_argument "q"
|
||||||
|
# if ENABLE_SCRIPTREPLAY
|
||||||
|
"timing\0" No_argument "t"
|
||||||
|
# endif
|
||||||
;
|
;
|
||||||
|
|
||||||
applet_long_options = getopt_longopts;
|
applet_long_options = getopt_longopts;
|
||||||
#endif
|
#endif
|
||||||
opt_complementary = "?1"; /* max one arg */
|
opt_complementary = "?1"; /* max one arg */
|
||||||
opt = getopt32(argv, "ac:fq", &shell_arg);
|
opt = getopt32(argv, "ac:fq" IF_SCRIPTREPLAY("t") , &shell_arg);
|
||||||
//argc -= optind;
|
//argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
if (argv[0]) {
|
if (argv[0]) {
|
||||||
fname = argv[0];
|
fname = argv[0];
|
||||||
}
|
}
|
||||||
mode = O_CREAT|O_TRUNC|O_WRONLY;
|
mode = O_CREAT|O_TRUNC|O_WRONLY;
|
||||||
if (opt & 1) {
|
if (opt & OPT_a) {
|
||||||
mode = O_CREAT|O_APPEND|O_WRONLY;
|
mode = O_CREAT|O_APPEND|O_WRONLY;
|
||||||
}
|
}
|
||||||
if (opt & 2) {
|
if (opt & OPT_c) {
|
||||||
shell_opt[1] = 'c';
|
shell_opt[1] = 'c';
|
||||||
}
|
}
|
||||||
if (!(opt & 8)) { /* not -q */
|
if (!(opt & OPT_q)) {
|
||||||
printf("Script started, file is %s\n", fname);
|
printf("Script started, file is %s\n", fname);
|
||||||
}
|
}
|
||||||
shell = getenv("SHELL");
|
shell = getenv("SHELL");
|
||||||
@ -83,7 +87,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
/* "script" from util-linux exits when child exits,
|
/* "script" from util-linux exits when child exits,
|
||||||
* we wouldn't wait for EOF from slave pty
|
* we wouldn't wait for EOF from slave pty
|
||||||
* (output may be produced by grandchildren of child) */
|
* (output may be produced by grandchildren of child) */
|
||||||
signal(SIGCHLD, handle_sigchld);
|
signal(SIGCHLD, record_signo);
|
||||||
|
|
||||||
/* TODO: SIGWINCH? pass window size changes down to slave? */
|
/* TODO: SIGWINCH? pass window size changes down to slave? */
|
||||||
|
|
||||||
@ -97,19 +101,23 @@ int script_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
#define buf bb_common_bufsiz1
|
#define buf bb_common_bufsiz1
|
||||||
struct pollfd pfd[2];
|
struct pollfd pfd[2];
|
||||||
int outfd, count, loop;
|
int outfd, count, loop;
|
||||||
|
#if ENABLE_SCRIPTREPLAY
|
||||||
|
double oldtime = time(NULL);
|
||||||
|
#endif
|
||||||
|
smallint fd_count = 2;
|
||||||
|
|
||||||
outfd = xopen(fname, mode);
|
outfd = xopen(fname, mode);
|
||||||
pfd[0].fd = pty;
|
pfd[0].fd = pty;
|
||||||
pfd[0].events = POLLIN;
|
pfd[0].events = POLLIN;
|
||||||
pfd[1].fd = 0;
|
pfd[1].fd = STDIN_FILENO;
|
||||||
pfd[1].events = POLLIN;
|
pfd[1].events = POLLIN;
|
||||||
ndelay_on(pty); /* this descriptor is not shared, can do this */
|
ndelay_on(pty); /* this descriptor is not shared, can do this */
|
||||||
/* ndelay_on(0); - NO, stdin can be shared! Pity :( */
|
/* ndelay_on(STDIN_FILENO); - NO, stdin can be shared! Pity :( */
|
||||||
|
|
||||||
/* copy stdin to pty master input,
|
/* copy stdin to pty master input,
|
||||||
* copy pty master output to stdout and file */
|
* copy pty master output to stdout and file */
|
||||||
/* TODO: don't use full_write's, use proper write buffering */
|
/* TODO: don't use full_write's, use proper write buffering */
|
||||||
while (fd_count) {
|
while (fd_count && !bb_got_signal) {
|
||||||
/* not safe_poll! we want SIGCHLD to EINTR poll */
|
/* not safe_poll! we want SIGCHLD to EINTR poll */
|
||||||
if (poll(pfd, fd_count, -1) < 0 && errno != EINTR) {
|
if (poll(pfd, fd_count, -1) < 0 && errno != EINTR) {
|
||||||
/* If child exits too quickly, we may get EIO:
|
/* If child exits too quickly, we may get EIO:
|
||||||
@ -124,9 +132,20 @@ int script_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
goto restore;
|
goto restore;
|
||||||
}
|
}
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
|
#if ENABLE_SCRIPTREPLAY
|
||||||
|
if (opt & OPT_t) {
|
||||||
|
struct timeval tv;
|
||||||
|
double newtime;
|
||||||
|
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
newtime = tv.tv_sec + (double) tv.tv_usec / 1000000;
|
||||||
|
fprintf(stderr, "%f %u\n", newtime - oldtime, count);
|
||||||
|
oldtime = newtime;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
full_write(STDOUT_FILENO, buf, count);
|
full_write(STDOUT_FILENO, buf, count);
|
||||||
full_write(outfd, buf, count);
|
full_write(outfd, buf, count);
|
||||||
if (opt & 4) { /* -f */
|
if (opt & OPT_f) {
|
||||||
fsync(outfd);
|
fsync(outfd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,8 +161,8 @@ int script_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* If loop was exited because SIGCHLD handler set fd_count to 0,
|
/* If loop was exited because SIGCHLD handler set bb_got_signal,
|
||||||
* there still can be some buffered output. But not loop forever:
|
* there still can be some buffered output. But dont loop forever:
|
||||||
* we won't pump orphaned grandchildren's output indefinitely.
|
* we won't pump orphaned grandchildren's output indefinitely.
|
||||||
* Testcase: running this in script:
|
* Testcase: running this in script:
|
||||||
* exec dd if=/dev/zero bs=1M count=1
|
* exec dd if=/dev/zero bs=1M count=1
|
||||||
@ -158,7 +177,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
restore:
|
restore:
|
||||||
if (attr_ok == 0)
|
if (attr_ok == 0)
|
||||||
tcsetattr(0, TCSAFLUSH, &tt);
|
tcsetattr(0, TCSAFLUSH, &tt);
|
||||||
if (!(opt & 8)) /* not -q */
|
if (!(opt & OPT_q))
|
||||||
printf("Script done, file is %s\n", fname);
|
printf("Script done, file is %s\n", fname);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
38
util-linux/scriptreplay.c
Normal file
38
util-linux/scriptreplay.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/* vi: set sw=4 ts=4: */
|
||||||
|
/*
|
||||||
|
* scriptreplay - play back typescripts, using timing information
|
||||||
|
*
|
||||||
|
* pascal.bellard@ads-lu.com
|
||||||
|
*
|
||||||
|
* Licensed under GPLv2 or later, see file License in this tarball for details.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "libbb.h"
|
||||||
|
|
||||||
|
int scriptreplay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
|
int scriptreplay_main(int argc UNUSED_PARAM, char **argv)
|
||||||
|
{
|
||||||
|
const char *script = "typescript";
|
||||||
|
double delay, factor = 1000000.0;
|
||||||
|
int fd;
|
||||||
|
unsigned long count;
|
||||||
|
FILE *tfp;
|
||||||
|
|
||||||
|
if (argv[2]) {
|
||||||
|
script = argv[2];
|
||||||
|
if (argv[3])
|
||||||
|
factor /= atof(argv[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
tfp = xfopen_for_read(argv[1]);
|
||||||
|
fd = xopen(script, O_RDONLY);
|
||||||
|
while (fscanf(tfp, "%lf %lu\n", &delay, &count) == 2) {
|
||||||
|
usleep(delay * factor);
|
||||||
|
bb_copyfd_exact_size(fd, STDOUT_FILENO, count);
|
||||||
|
}
|
||||||
|
#if ENABLE_FEATURE_CLEAN_UP
|
||||||
|
close(fd);
|
||||||
|
fclose(tfp);
|
||||||
|
#endif
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user