mirror of
https://github.com/sheumann/hush.git
synced 2024-12-30 20:29:21 +00:00
ash: deal with some TODOs (mostly trivial)
function old new delta msg_illnum - 19 +19 evalvar 1365 1364 -1 illnum 19 - -19 subevalvar 1182 1158 -24 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/2 up/down: 19/-44) Total: -25 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
9f2e82ad2e
commit
ecc2a2e015
@ -45,6 +45,9 @@ char FAST_FUNC bb_process_escape_sequence(const char **ptr)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* bash requires leading 0 in octal escapes:
|
||||||
|
* \02 works, \2 does not (prints \ and 2).
|
||||||
|
* We treat \2 as a valid octal escape sequence. */
|
||||||
do {
|
do {
|
||||||
d = (unsigned char)(*q) - '0';
|
d = (unsigned char)(*q) - '0';
|
||||||
#ifdef WANT_HEX_ESCAPES
|
#ifdef WANT_HEX_ESCAPES
|
||||||
@ -80,7 +83,10 @@ char FAST_FUNC bb_process_escape_sequence(const char **ptr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (*++p);
|
} while (*++p);
|
||||||
n = *(p + (sizeof(charmap)/2));
|
/* p points to found escape char or NUL,
|
||||||
|
* advance it and find what it translates to */
|
||||||
|
p += sizeof(charmap) / 2;
|
||||||
|
n = *p;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ptr = q;
|
*ptr = q;
|
||||||
|
118
shell/ash.c
118
shell/ash.c
@ -112,7 +112,7 @@ enum { NOPTS = ARRAY_SIZE(optletters_optnames) };
|
|||||||
|
|
||||||
static const char homestr[] ALIGN1 = "HOME";
|
static const char homestr[] ALIGN1 = "HOME";
|
||||||
static const char snlfmt[] ALIGN1 = "%s\n";
|
static const char snlfmt[] ALIGN1 = "%s\n";
|
||||||
static const char illnum[] ALIGN1 = "Illegal number: %s";
|
static const char msg_illnum[] ALIGN1 = "Illegal number: %s";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We enclose jmp_buf in a structure so that we can declare pointers to
|
* We enclose jmp_buf in a structure so that we can declare pointers to
|
||||||
@ -142,17 +142,10 @@ struct globals_misc {
|
|||||||
|
|
||||||
struct jmploc *exception_handler;
|
struct jmploc *exception_handler;
|
||||||
|
|
||||||
// disabled by vda: cannot understand how it was supposed to work -
|
volatile int suppress_int; /* counter */
|
||||||
// cannot fix bugs. That's why you have to explain your non-trivial designs!
|
volatile /*sig_atomic_t*/ smallint pending_int; /* 1 = got SIGINT */
|
||||||
// /* do we generate EXSIG events */
|
|
||||||
// int exsig; /* counter */
|
|
||||||
volatile int suppressint; /* counter */
|
|
||||||
// TODO: rename
|
|
||||||
// pendingsig -> pending_sig
|
|
||||||
// intpending -> pending_int
|
|
||||||
volatile /*sig_atomic_t*/ smallint intpending; /* 1 = got SIGINT */
|
|
||||||
/* last pending signal */
|
/* last pending signal */
|
||||||
volatile /*sig_atomic_t*/ smallint pendingsig;
|
volatile /*sig_atomic_t*/ smallint pending_sig;
|
||||||
smallint exception_type; /* kind of exception (0..5) */
|
smallint exception_type; /* kind of exception (0..5) */
|
||||||
/* exceptions */
|
/* exceptions */
|
||||||
#define EXINT 0 /* SIGINT received */
|
#define EXINT 0 /* SIGINT received */
|
||||||
@ -220,10 +213,9 @@ extern struct globals_misc *const ash_ptr_to_globals_misc;
|
|||||||
#define arg0 (G_misc.arg0 )
|
#define arg0 (G_misc.arg0 )
|
||||||
#define exception_handler (G_misc.exception_handler)
|
#define exception_handler (G_misc.exception_handler)
|
||||||
#define exception_type (G_misc.exception_type )
|
#define exception_type (G_misc.exception_type )
|
||||||
#define suppressint (G_misc.suppressint )
|
#define suppress_int (G_misc.suppress_int )
|
||||||
#define intpending (G_misc.intpending )
|
#define pending_int (G_misc.pending_int )
|
||||||
//#define exsig (G_misc.exsig )
|
#define pending_sig (G_misc.pending_sig )
|
||||||
#define pendingsig (G_misc.pendingsig )
|
|
||||||
#define isloginsh (G_misc.isloginsh )
|
#define isloginsh (G_misc.isloginsh )
|
||||||
#define nullstr (G_misc.nullstr )
|
#define nullstr (G_misc.nullstr )
|
||||||
#define optlist (G_misc.optlist )
|
#define optlist (G_misc.optlist )
|
||||||
@ -283,7 +275,7 @@ static int isdigit_str9(const char *str)
|
|||||||
* more fun than worrying about efficiency and portability. :-))
|
* more fun than worrying about efficiency and portability. :-))
|
||||||
*/
|
*/
|
||||||
#define INT_OFF do { \
|
#define INT_OFF do { \
|
||||||
suppressint++; \
|
suppress_int++; \
|
||||||
xbarrier(); \
|
xbarrier(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -324,11 +316,11 @@ raise_interrupt(void)
|
|||||||
{
|
{
|
||||||
int ex_type;
|
int ex_type;
|
||||||
|
|
||||||
intpending = 0;
|
pending_int = 0;
|
||||||
/* Signal is not automatically unmasked after it is raised,
|
/* Signal is not automatically unmasked after it is raised,
|
||||||
* do it ourself - unmask all signals */
|
* do it ourself - unmask all signals */
|
||||||
sigprocmask_allsigs(SIG_UNBLOCK);
|
sigprocmask_allsigs(SIG_UNBLOCK);
|
||||||
/* pendingsig = 0; - now done in onsig() */
|
/* pending_sig = 0; - now done in onsig() */
|
||||||
|
|
||||||
ex_type = EXSIG;
|
ex_type = EXSIG;
|
||||||
if (gotsig[SIGINT - 1] && !trap[SIGINT]) {
|
if (gotsig[SIGINT - 1] && !trap[SIGINT]) {
|
||||||
@ -353,7 +345,7 @@ static IF_ASH_OPTIMIZE_FOR_SIZE(inline) void
|
|||||||
int_on(void)
|
int_on(void)
|
||||||
{
|
{
|
||||||
xbarrier();
|
xbarrier();
|
||||||
if (--suppressint == 0 && intpending) {
|
if (--suppress_int == 0 && pending_int) {
|
||||||
raise_interrupt();
|
raise_interrupt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,18 +354,18 @@ static IF_ASH_OPTIMIZE_FOR_SIZE(inline) void
|
|||||||
force_int_on(void)
|
force_int_on(void)
|
||||||
{
|
{
|
||||||
xbarrier();
|
xbarrier();
|
||||||
suppressint = 0;
|
suppress_int = 0;
|
||||||
if (intpending)
|
if (pending_int)
|
||||||
raise_interrupt();
|
raise_interrupt();
|
||||||
}
|
}
|
||||||
#define FORCE_INT_ON force_int_on()
|
#define FORCE_INT_ON force_int_on()
|
||||||
|
|
||||||
#define SAVE_INT(v) ((v) = suppressint)
|
#define SAVE_INT(v) ((v) = suppress_int)
|
||||||
|
|
||||||
#define RESTORE_INT(v) do { \
|
#define RESTORE_INT(v) do { \
|
||||||
xbarrier(); \
|
xbarrier(); \
|
||||||
suppressint = (v); \
|
suppress_int = (v); \
|
||||||
if (suppressint == 0 && intpending) \
|
if (suppress_int == 0 && pending_int) \
|
||||||
raise_interrupt(); \
|
raise_interrupt(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -685,7 +677,7 @@ trace_printf(const char *fmt, ...)
|
|||||||
if (DEBUG_PID)
|
if (DEBUG_PID)
|
||||||
fprintf(tracefile, "[%u] ", (int) getpid());
|
fprintf(tracefile, "[%u] ", (int) getpid());
|
||||||
if (DEBUG_SIG)
|
if (DEBUG_SIG)
|
||||||
fprintf(tracefile, "pending s:%d i:%d(supp:%d) ", pendingsig, intpending, suppressint);
|
fprintf(tracefile, "pending s:%d i:%d(supp:%d) ", pending_sig, pending_int, suppress_int);
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
vfprintf(tracefile, fmt, va);
|
vfprintf(tracefile, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
@ -701,7 +693,7 @@ trace_vprintf(const char *fmt, va_list va)
|
|||||||
if (DEBUG_PID)
|
if (DEBUG_PID)
|
||||||
fprintf(tracefile, "[%u] ", (int) getpid());
|
fprintf(tracefile, "[%u] ", (int) getpid());
|
||||||
if (DEBUG_SIG)
|
if (DEBUG_SIG)
|
||||||
fprintf(tracefile, "pending s:%d i:%d(supp:%d) ", pendingsig, intpending, suppressint);
|
fprintf(tracefile, "pending s:%d i:%d(supp:%d) ", pending_sig, pending_int, suppress_int);
|
||||||
vfprintf(tracefile, fmt, va);
|
vfprintf(tracefile, fmt, va);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1556,7 +1548,7 @@ static int
|
|||||||
number(const char *s)
|
number(const char *s)
|
||||||
{
|
{
|
||||||
if (!is_number(s))
|
if (!is_number(s))
|
||||||
ash_msg_and_raise_error(illnum, s);
|
ash_msg_and_raise_error(msg_illnum, s);
|
||||||
return atoi(s);
|
return atoi(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2351,8 +2343,6 @@ setprompt(int whichprompt)
|
|||||||
#define CD_PHYSICAL 1
|
#define CD_PHYSICAL 1
|
||||||
#define CD_PRINT 2
|
#define CD_PRINT 2
|
||||||
|
|
||||||
static int docd(const char *, int);
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cdopt(void)
|
cdopt(void)
|
||||||
{
|
{
|
||||||
@ -2360,7 +2350,7 @@ cdopt(void)
|
|||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
j = 'L';
|
j = 'L';
|
||||||
while ((i = nextopt("LP"))) {
|
while ((i = nextopt("LP")) != '\0') {
|
||||||
if (i != j) {
|
if (i != j) {
|
||||||
flags ^= CD_PHYSICAL;
|
flags ^= CD_PHYSICAL;
|
||||||
j = i;
|
j = i;
|
||||||
@ -3315,14 +3305,14 @@ onsig(int signo)
|
|||||||
{
|
{
|
||||||
gotsig[signo - 1] = 1;
|
gotsig[signo - 1] = 1;
|
||||||
|
|
||||||
if (/* exsig || */ (signo == SIGINT && !trap[SIGINT])) {
|
if (signo == SIGINT && !trap[SIGINT]) {
|
||||||
if (!suppressint) {
|
if (!suppress_int) {
|
||||||
pendingsig = 0;
|
pending_sig = 0;
|
||||||
raise_interrupt(); /* does not return */
|
raise_interrupt(); /* does not return */
|
||||||
}
|
}
|
||||||
intpending = 1;
|
pending_int = 1;
|
||||||
} else {
|
} else {
|
||||||
pendingsig = signo;
|
pending_sig = signo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3545,7 +3535,6 @@ getjob(const char *name, int getctl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_number(p)) {
|
if (is_number(p)) {
|
||||||
// TODO: number() instead? It does error checking...
|
|
||||||
num = atoi(p);
|
num = atoi(p);
|
||||||
if (num < njobs) {
|
if (num < njobs) {
|
||||||
jp = jobtab + num - 1;
|
jp = jobtab + num - 1;
|
||||||
@ -3917,7 +3906,7 @@ static int
|
|||||||
blocking_wait_with_raise_on_sig(struct job *job)
|
blocking_wait_with_raise_on_sig(struct job *job)
|
||||||
{
|
{
|
||||||
pid_t pid = dowait(DOWAIT_BLOCK, job);
|
pid_t pid = dowait(DOWAIT_BLOCK, job);
|
||||||
if (pid <= 0 && pendingsig)
|
if (pid <= 0 && pending_sig)
|
||||||
raise_exception(EXSIG);
|
raise_exception(EXSIG);
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
@ -4025,7 +4014,7 @@ jobscmd(int argc UNUSED_PARAM, char **argv)
|
|||||||
int mode, m;
|
int mode, m;
|
||||||
|
|
||||||
mode = 0;
|
mode = 0;
|
||||||
while ((m = nextopt("lp"))) {
|
while ((m = nextopt("lp")) != '\0') {
|
||||||
if (m == 'l')
|
if (m == 'l')
|
||||||
mode |= SHOW_PIDS;
|
mode |= SHOW_PIDS;
|
||||||
else
|
else
|
||||||
@ -4079,9 +4068,7 @@ waitcmd(int argc UNUSED_PARAM, char **argv)
|
|||||||
int retval;
|
int retval;
|
||||||
struct job *jp;
|
struct job *jp;
|
||||||
|
|
||||||
// exsig++;
|
if (pending_sig)
|
||||||
// xbarrier();
|
|
||||||
if (pendingsig)
|
|
||||||
raise_exception(EXSIG);
|
raise_exception(EXSIG);
|
||||||
|
|
||||||
nextopt(nullstr);
|
nextopt(nullstr);
|
||||||
@ -4317,7 +4304,7 @@ cmdputs(const char *s)
|
|||||||
if (!str)
|
if (!str)
|
||||||
continue;
|
continue;
|
||||||
dostr:
|
dostr:
|
||||||
while ((c = *str++)) {
|
while ((c = *str++) != '\0') {
|
||||||
USTPUTC(c, nextc);
|
USTPUTC(c, nextc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6126,15 +6113,15 @@ subevalvar(char *p, char *str, int strloc, int subtype,
|
|||||||
#if ENABLE_ASH_BASH_COMPAT
|
#if ENABLE_ASH_BASH_COMPAT
|
||||||
case VSSUBSTR:
|
case VSSUBSTR:
|
||||||
loc = str = stackblock() + strloc;
|
loc = str = stackblock() + strloc;
|
||||||
// TODO: number() instead? It does error checking...
|
/* Read POS in ${var:POS:LEN} */
|
||||||
pos = atoi(loc);
|
pos = atoi(loc); /* number(loc) errors out on "1:4" */
|
||||||
len = str - startp - 1;
|
len = str - startp - 1;
|
||||||
|
|
||||||
/* *loc != '\0', guaranteed by parser */
|
/* *loc != '\0', guaranteed by parser */
|
||||||
if (quotes) {
|
if (quotes) {
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
/* We must adjust the length by the number of escapes we find. */
|
/* Adjust the length by the number of escapes */
|
||||||
for (ptr = startp; ptr < (str - 1); ptr++) {
|
for (ptr = startp; ptr < (str - 1); ptr++) {
|
||||||
if (*ptr == CTLESC) {
|
if (*ptr == CTLESC) {
|
||||||
len--;
|
len--;
|
||||||
@ -6145,15 +6132,22 @@ subevalvar(char *p, char *str, int strloc, int subtype,
|
|||||||
orig_len = len;
|
orig_len = len;
|
||||||
|
|
||||||
if (*loc++ == ':') {
|
if (*loc++ == ':') {
|
||||||
// TODO: number() instead? It does error checking...
|
/* ${var::LEN} */
|
||||||
len = atoi(loc);
|
len = number(loc);
|
||||||
} else {
|
} else {
|
||||||
|
/* Skip POS in ${var:POS:LEN} */
|
||||||
len = orig_len;
|
len = orig_len;
|
||||||
while (*loc && *loc != ':')
|
while (*loc && *loc != ':') {
|
||||||
|
/* TODO?
|
||||||
|
* bash complains on: var=qwe; echo ${var:1a:123}
|
||||||
|
if (!isdigit(*loc))
|
||||||
|
ash_msg_and_raise_error(msg_illnum, str);
|
||||||
|
*/
|
||||||
loc++;
|
loc++;
|
||||||
if (*loc++ == ':')
|
}
|
||||||
// TODO: number() instead? It does error checking...
|
if (*loc++ == ':') {
|
||||||
len = atoi(loc);
|
len = number(loc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (pos >= orig_len) {
|
if (pos >= orig_len) {
|
||||||
pos = 0;
|
pos = 0;
|
||||||
@ -6372,7 +6366,7 @@ varvalue(char *name, int varflags, int flags, struct strlist *var_str_list)
|
|||||||
ap = shellparam.p;
|
ap = shellparam.p;
|
||||||
if (!ap)
|
if (!ap)
|
||||||
return -1;
|
return -1;
|
||||||
while ((p = *ap++)) {
|
while ((p = *ap++) != NULL) {
|
||||||
size_t partlen;
|
size_t partlen;
|
||||||
|
|
||||||
partlen = strlen(p);
|
partlen = strlen(p);
|
||||||
@ -6406,8 +6400,7 @@ varvalue(char *name, int varflags, int flags, struct strlist *var_str_list)
|
|||||||
case '7':
|
case '7':
|
||||||
case '8':
|
case '8':
|
||||||
case '9':
|
case '9':
|
||||||
// TODO: number() instead? It does error checking...
|
num = number(name);
|
||||||
num = atoi(name);
|
|
||||||
if (num < 0 || num > shellparam.nparam)
|
if (num < 0 || num > shellparam.nparam)
|
||||||
return -1;
|
return -1;
|
||||||
p = num ? shellparam.p[num - 1] : arg0;
|
p = num ? shellparam.p[num - 1] : arg0;
|
||||||
@ -6819,7 +6812,7 @@ expmeta(char *enddir, char *name)
|
|||||||
p++;
|
p++;
|
||||||
if (*p == '.')
|
if (*p == '.')
|
||||||
matchdot++;
|
matchdot++;
|
||||||
while (!intpending && (dp = readdir(dirp)) != NULL) {
|
while (!pending_int && (dp = readdir(dirp)) != NULL) {
|
||||||
if (dp->d_name[0] == '.' && !matchdot)
|
if (dp->d_name[0] == '.' && !matchdot)
|
||||||
continue;
|
continue;
|
||||||
if (pmatch(start, dp->d_name)) {
|
if (pmatch(start, dp->d_name)) {
|
||||||
@ -7213,8 +7206,8 @@ shellexec(char **argv, const char *path, int idx)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
exitstatus = exerrno;
|
exitstatus = exerrno;
|
||||||
TRACE(("shellexec failed for %s, errno %d, suppressint %d\n",
|
TRACE(("shellexec failed for %s, errno %d, suppress_int %d\n",
|
||||||
argv[0], e, suppressint));
|
argv[0], e, suppress_int));
|
||||||
ash_msg_and_raise(EXEXEC, "%s: %s", argv[0], errmsg(e, "not found"));
|
ash_msg_and_raise(EXEXEC, "%s: %s", argv[0], errmsg(e, "not found"));
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
@ -8016,7 +8009,7 @@ dotrap(void)
|
|||||||
uint8_t savestatus;
|
uint8_t savestatus;
|
||||||
|
|
||||||
savestatus = exitstatus;
|
savestatus = exitstatus;
|
||||||
pendingsig = 0;
|
pending_sig = 0;
|
||||||
xbarrier();
|
xbarrier();
|
||||||
|
|
||||||
TRACE(("dotrap entered\n"));
|
TRACE(("dotrap entered\n"));
|
||||||
@ -8196,7 +8189,7 @@ evaltree(union node *n, int flags)
|
|||||||
out1:
|
out1:
|
||||||
if (checkexit & exitstatus)
|
if (checkexit & exitstatus)
|
||||||
evalskip |= SKIPEVAL;
|
evalskip |= SKIPEVAL;
|
||||||
else if (pendingsig && dotrap())
|
else if (pending_sig && dotrap())
|
||||||
goto exexit;
|
goto exexit;
|
||||||
|
|
||||||
if (flags & EV_EXIT) {
|
if (flags & EV_EXIT) {
|
||||||
@ -9116,7 +9109,7 @@ evalcommand(union node *cmd, int flags)
|
|||||||
if (i == EXINT)
|
if (i == EXINT)
|
||||||
exit_status = 128 + SIGINT;
|
exit_status = 128 + SIGINT;
|
||||||
if (i == EXSIG)
|
if (i == EXSIG)
|
||||||
exit_status = 128 + pendingsig;
|
exit_status = 128 + pending_sig;
|
||||||
exitstatus = exit_status;
|
exitstatus = exit_status;
|
||||||
if (i == EXINT || spclbltin > 0) {
|
if (i == EXINT || spclbltin > 0) {
|
||||||
raise:
|
raise:
|
||||||
@ -9170,7 +9163,6 @@ evalbltin(const struct builtincmd *cmd, int argc, char **argv)
|
|||||||
exitstatus |= ferror(stdout);
|
exitstatus |= ferror(stdout);
|
||||||
clearerr(stdout);
|
clearerr(stdout);
|
||||||
commandname = savecmdname;
|
commandname = savecmdname;
|
||||||
// exsig = 0;
|
|
||||||
exception_handler = savehandler;
|
exception_handler = savehandler;
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
@ -9221,7 +9213,7 @@ breakcmd(int argc UNUSED_PARAM, char **argv)
|
|||||||
int n = argv[1] ? number(argv[1]) : 1;
|
int n = argv[1] ? number(argv[1]) : 1;
|
||||||
|
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
ash_msg_and_raise_error(illnum, argv[1]);
|
ash_msg_and_raise_error(msg_illnum, argv[1]);
|
||||||
if (n > loopnest)
|
if (n > loopnest)
|
||||||
n = loopnest;
|
n = loopnest;
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
@ -12712,7 +12704,7 @@ umaskcmd(int argc UNUSED_PARAM, char **argv)
|
|||||||
mask = 0;
|
mask = 0;
|
||||||
do {
|
do {
|
||||||
if (*ap >= '8' || *ap < '0')
|
if (*ap >= '8' || *ap < '0')
|
||||||
ash_msg_and_raise_error(illnum, argv[1]);
|
ash_msg_and_raise_error(msg_illnum, argv[1]);
|
||||||
mask = (mask << 3) + (*ap - '0');
|
mask = (mask << 3) + (*ap - '0');
|
||||||
} while (*++ap != '\0');
|
} while (*++ap != '\0');
|
||||||
umask(mask);
|
umask(mask);
|
||||||
|
Loading…
Reference in New Issue
Block a user