diff options
| author | "Vladimir N. Oleynik" <dzo@simtreas.ru> | 2006-01-15 14:21:01 +0000 |
|---|---|---|
| committer | "Vladimir N. Oleynik" <dzo@simtreas.ru> | 2006-01-15 14:21:01 +0000 |
| commit | fb29b462012e43d2559f0cdf7b1051d4a7f82ef6 (patch) | |
| tree | 19d6f5ee551fb129cc186e8bbf4543a06cd67059 /shell | |
| parent | 7ca61b6f3379bf66b446617b8834d92c13b366dd (diff) | |
| download | busybox-w32-fb29b462012e43d2559f0cdf7b1051d4a7f82ef6.tar.gz busybox-w32-fb29b462012e43d2559f0cdf7b1051d4a7f82ef6.tar.bz2 busybox-w32-fb29b462012e43d2559f0cdf7b1051d4a7f82ef6.zip | |
sync with dash_0.5.3-1
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/ash.c | 569 |
1 files changed, 267 insertions, 302 deletions
diff --git a/shell/ash.c b/shell/ash.c index 4fc3e0e15..0697a4785 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -36,7 +36,7 @@ | |||
| 36 | * Modified by Paul Mundt <lethal@linux-sh.org> (c) 2004 to support | 36 | * Modified by Paul Mundt <lethal@linux-sh.org> (c) 2004 to support |
| 37 | * dynamic variables. | 37 | * dynamic variables. |
| 38 | * | 38 | * |
| 39 | * Modified by Vladimir Oleynik <dzo@simtreas.ru> (c) 2001-2004 to be | 39 | * Modified by Vladimir Oleynik <dzo@simtreas.ru> (c) 2001-2005 to be |
| 40 | * used in busybox and size optimizations, | 40 | * used in busybox and size optimizations, |
| 41 | * rewrote arith (see notes to this), added locale support, | 41 | * rewrote arith (see notes to this), added locale support, |
| 42 | * rewrote dynamic variables. | 42 | * rewrote dynamic variables. |
| @@ -66,7 +66,6 @@ | |||
| 66 | #endif | 66 | #endif |
| 67 | 67 | ||
| 68 | #include <sys/types.h> | 68 | #include <sys/types.h> |
| 69 | #include <sys/cdefs.h> | ||
| 70 | #include <sys/ioctl.h> | 69 | #include <sys/ioctl.h> |
| 71 | #include <sys/param.h> | 70 | #include <sys/param.h> |
| 72 | #include <sys/resource.h> | 71 | #include <sys/resource.h> |
| @@ -91,7 +90,6 @@ | |||
| 91 | #include <setjmp.h> | 90 | #include <setjmp.h> |
| 92 | #include <signal.h> | 91 | #include <signal.h> |
| 93 | #include <stdint.h> | 92 | #include <stdint.h> |
| 94 | #include <sysexits.h> | ||
| 95 | #include <time.h> | 93 | #include <time.h> |
| 96 | #include <fnmatch.h> | 94 | #include <fnmatch.h> |
| 97 | 95 | ||
| @@ -130,7 +128,7 @@ static int *dash_errno; | |||
| 130 | 128 | ||
| 131 | 129 | ||
| 132 | #ifdef CONFIG_ASH_ALIAS | 130 | #ifdef CONFIG_ASH_ALIAS |
| 133 | /* $NetBSD: alias.h,v 1.5 2002/11/24 22:35:38 christos Exp $ */ | 131 | /* alias.h */ |
| 134 | 132 | ||
| 135 | #define ALIASINUSE 1 | 133 | #define ALIASINUSE 1 |
| 136 | #define ALIASDEAD 2 | 134 | #define ALIASDEAD 2 |
| @@ -150,12 +148,12 @@ static int unalias(const char *); | |||
| 150 | static void printalias(const struct alias *); | 148 | static void printalias(const struct alias *); |
| 151 | #endif | 149 | #endif |
| 152 | 150 | ||
| 153 | /* $NetBSD: cd.h,v 1.3 2002/11/24 22:35:39 christos Exp $ */ | 151 | /* cd.h */ |
| 154 | 152 | ||
| 155 | 153 | ||
| 156 | static void setpwd(const char *, int); | 154 | static void setpwd(const char *, int); |
| 157 | 155 | ||
| 158 | /* $NetBSD: error.h,v 1.15 2002/11/24 22:35:39 christos Exp $ */ | 156 | /* error.h */ |
| 159 | 157 | ||
| 160 | 158 | ||
| 161 | /* | 159 | /* |
| @@ -189,8 +187,6 @@ static int exception; | |||
| 189 | static volatile int suppressint; | 187 | static volatile int suppressint; |
| 190 | static volatile sig_atomic_t intpending; | 188 | static volatile sig_atomic_t intpending; |
| 191 | 189 | ||
| 192 | static int exerrno; /* Last exec error, error for EXEXEC */ | ||
| 193 | |||
| 194 | /* exceptions */ | 190 | /* exceptions */ |
| 195 | #define EXINT 0 /* SIGINT received */ | 191 | #define EXINT 0 /* SIGINT received */ |
| 196 | #define EXERROR 1 /* a generic error */ | 192 | #define EXERROR 1 /* a generic error */ |
| @@ -240,7 +236,7 @@ static volatile sig_atomic_t pendingsigs; | |||
| 240 | static void exraise(int) __attribute__((__noreturn__)); | 236 | static void exraise(int) __attribute__((__noreturn__)); |
| 241 | static void onint(void) __attribute__((__noreturn__)); | 237 | static void onint(void) __attribute__((__noreturn__)); |
| 242 | 238 | ||
| 243 | static void error(const char *, ...) __attribute__((__noreturn__)); | 239 | static void sh_error(const char *, ...) __attribute__((__noreturn__)); |
| 244 | static void exerror(int, const char *, ...) __attribute__((__noreturn__)); | 240 | static void exerror(int, const char *, ...) __attribute__((__noreturn__)); |
| 245 | 241 | ||
| 246 | static void sh_warnx(const char *, ...); | 242 | static void sh_warnx(const char *, ...); |
| @@ -276,7 +272,7 @@ static void forceinton(void) | |||
| 276 | }) | 272 | }) |
| 277 | #endif /* CONFIG_ASH_OPTIMIZE_FOR_SIZE */ | 273 | #endif /* CONFIG_ASH_OPTIMIZE_FOR_SIZE */ |
| 278 | 274 | ||
| 279 | /* $NetBSD: expand.h,v 1.13 2002/11/24 22:35:40 christos Exp $ */ | 275 | /* expand.h */ |
| 280 | 276 | ||
| 281 | struct strlist { | 277 | struct strlist { |
| 282 | struct strlist *next; | 278 | struct strlist *next; |
| @@ -313,7 +309,7 @@ static int casematch(union node *, char *); | |||
| 313 | static void expari(int); | 309 | static void expari(int); |
| 314 | #endif | 310 | #endif |
| 315 | 311 | ||
| 316 | /* $NetBSD: eval.h,v 1.13 2002/11/24 22:35:39 christos Exp $ */ | 312 | /* eval.h */ |
| 317 | 313 | ||
| 318 | static char *commandname; /* currently executing command */ | 314 | static char *commandname; /* currently executing command */ |
| 319 | static struct strlist *cmdenviron; /* environment for builtin command */ | 315 | static struct strlist *cmdenviron; /* environment for builtin command */ |
| @@ -492,7 +488,7 @@ struct funcnode { | |||
| 492 | 488 | ||
| 493 | 489 | ||
| 494 | static void freefunc(struct funcnode *); | 490 | static void freefunc(struct funcnode *); |
| 495 | /* $NetBSD: parser.h,v 1.15 2002/11/24 22:35:42 christos Exp $ */ | 491 | /* parser.h */ |
| 496 | 492 | ||
| 497 | /* control characters in argument strings */ | 493 | /* control characters in argument strings */ |
| 498 | #define CTL_FIRST '\201' /* first 'special' character */ | 494 | #define CTL_FIRST '\201' /* first 'special' character */ |
| @@ -591,7 +587,7 @@ static void fixredir(union node *, const char *, int); | |||
| 591 | static const char *const *findkwd(const char *); | 587 | static const char *const *findkwd(const char *); |
| 592 | static char *endofname(const char *); | 588 | static char *endofname(const char *); |
| 593 | 589 | ||
| 594 | /* $NetBSD: shell.h,v 1.16 2003/01/22 20:36:04 dsl Exp $ */ | 590 | /* shell.h */ |
| 595 | 591 | ||
| 596 | typedef void *pointer; | 592 | typedef void *pointer; |
| 597 | 593 | ||
| @@ -693,7 +689,7 @@ static const char *tokname(int tok) | |||
| 693 | return buf; | 689 | return buf; |
| 694 | } | 690 | } |
| 695 | 691 | ||
| 696 | /* $NetBSD: machdep.h,v 1.10 2002/10/07 14:26:08 christos Exp $ */ | 692 | /* machdep.h */ |
| 697 | 693 | ||
| 698 | /* | 694 | /* |
| 699 | * Most machines require the value returned from malloc to be aligned | 695 | * Most machines require the value returned from malloc to be aligned |
| @@ -1160,7 +1156,7 @@ static const char syntax_index_table[258] = { | |||
| 1160 | 1156 | ||
| 1161 | #endif /* USE_SIT_FUNCTION */ | 1157 | #endif /* USE_SIT_FUNCTION */ |
| 1162 | 1158 | ||
| 1163 | /* $NetBSD: alias.c,v 1.11 2002/11/24 22:35:38 christos Exp $ */ | 1159 | /* alias.c */ |
| 1164 | 1160 | ||
| 1165 | 1161 | ||
| 1166 | #define ATABSIZE 39 | 1162 | #define ATABSIZE 39 |
| @@ -1207,29 +1203,27 @@ static struct nodelist *copynodelist(struct nodelist *); | |||
| 1207 | static char *nodesavestr(char *); | 1203 | static char *nodesavestr(char *); |
| 1208 | 1204 | ||
| 1209 | 1205 | ||
| 1210 | 1206 | static int evalstring(char *, int mask); | |
| 1211 | static void evalstring(char *); | ||
| 1212 | union node; /* BLETCH for ansi C */ | 1207 | union node; /* BLETCH for ansi C */ |
| 1213 | static void evaltree(union node *, int); | 1208 | static void evaltree(union node *, int); |
| 1214 | static void evalbackcmd(union node *, struct backcmd *); | 1209 | static void evalbackcmd(union node *, struct backcmd *); |
| 1215 | 1210 | ||
| 1216 | /* in_function returns nonzero if we are currently evaluating a function */ | ||
| 1217 | #define in_function() funcnest | ||
| 1218 | static int evalskip; /* set if we are skipping commands */ | 1211 | static int evalskip; /* set if we are skipping commands */ |
| 1219 | static int skipcount; /* number of levels to skip */ | 1212 | static int skipcount; /* number of levels to skip */ |
| 1220 | static int funcnest; /* depth of function calls */ | 1213 | static int funcnest; /* depth of function calls */ |
| 1221 | 1214 | ||
| 1222 | /* reasons for skipping commands (see comment on breakcmd routine) */ | 1215 | /* reasons for skipping commands (see comment on breakcmd routine) */ |
| 1223 | #define SKIPBREAK 1 | 1216 | #define SKIPBREAK (1 << 0) |
| 1224 | #define SKIPCONT 2 | 1217 | #define SKIPCONT (1 << 1) |
| 1225 | #define SKIPFUNC 3 | 1218 | #define SKIPFUNC (1 << 2) |
| 1226 | #define SKIPFILE 4 | 1219 | #define SKIPFILE (1 << 3) |
| 1220 | #define SKIPEVAL (1 << 4) | ||
| 1227 | 1221 | ||
| 1228 | /* | 1222 | /* |
| 1229 | * This file was generated by the mkbuiltins program. | 1223 | * This file was generated by the mkbuiltins program. |
| 1230 | */ | 1224 | */ |
| 1231 | 1225 | ||
| 1232 | #ifdef JOBS | 1226 | #if JOBS |
| 1233 | static int bgcmd(int, char **); | 1227 | static int bgcmd(int, char **); |
| 1234 | #endif | 1228 | #endif |
| 1235 | static int breakcmd(int, char **); | 1229 | static int breakcmd(int, char **); |
| @@ -1246,7 +1240,7 @@ static int execcmd(int, char **); | |||
| 1246 | static int exitcmd(int, char **); | 1240 | static int exitcmd(int, char **); |
| 1247 | static int exportcmd(int, char **); | 1241 | static int exportcmd(int, char **); |
| 1248 | static int falsecmd(int, char **); | 1242 | static int falsecmd(int, char **); |
| 1249 | #ifdef JOBS | 1243 | #if JOBS |
| 1250 | static int fgcmd(int, char **); | 1244 | static int fgcmd(int, char **); |
| 1251 | #endif | 1245 | #endif |
| 1252 | #ifdef CONFIG_ASH_GETOPTS | 1246 | #ifdef CONFIG_ASH_GETOPTS |
| @@ -1256,7 +1250,7 @@ static int hashcmd(int, char **); | |||
| 1256 | #ifndef CONFIG_FEATURE_SH_EXTRA_QUIET | 1250 | #ifndef CONFIG_FEATURE_SH_EXTRA_QUIET |
| 1257 | static int helpcmd(int argc, char **argv); | 1251 | static int helpcmd(int argc, char **argv); |
| 1258 | #endif | 1252 | #endif |
| 1259 | #ifdef JOBS | 1253 | #if JOBS |
| 1260 | static int jobscmd(int, char **); | 1254 | static int jobscmd(int, char **); |
| 1261 | #endif | 1255 | #endif |
| 1262 | #ifdef CONFIG_ASH_MATH_SUPPORT | 1256 | #ifdef CONFIG_ASH_MATH_SUPPORT |
| @@ -1276,18 +1270,18 @@ static int umaskcmd(int, char **); | |||
| 1276 | static int unsetcmd(int, char **); | 1270 | static int unsetcmd(int, char **); |
| 1277 | static int waitcmd(int, char **); | 1271 | static int waitcmd(int, char **); |
| 1278 | static int ulimitcmd(int, char **); | 1272 | static int ulimitcmd(int, char **); |
| 1279 | #ifdef JOBS | 1273 | #if JOBS |
| 1280 | static int killcmd(int, char **); | 1274 | static int killcmd(int, char **); |
| 1281 | #endif | 1275 | #endif |
| 1282 | 1276 | ||
| 1283 | /* $NetBSD: mail.h,v 1.9 2002/11/24 22:35:40 christos Exp $ */ | 1277 | /* mail.h */ |
| 1284 | 1278 | ||
| 1285 | #ifdef CONFIG_ASH_MAIL | 1279 | #ifdef CONFIG_ASH_MAIL |
| 1286 | static void chkmail(void); | 1280 | static void chkmail(void); |
| 1287 | static void changemail(const char *); | 1281 | static void changemail(const char *); |
| 1288 | #endif | 1282 | #endif |
| 1289 | 1283 | ||
| 1290 | /* $NetBSD: exec.h,v 1.20 2003/01/22 20:36:04 dsl Exp $ */ | 1284 | /* exec.h */ |
| 1291 | 1285 | ||
| 1292 | /* values of cmdtype */ | 1286 | /* values of cmdtype */ |
| 1293 | #define CMDUNKNOWN -1 /* no entry in table for command */ | 1287 | #define CMDUNKNOWN -1 /* no entry in table for command */ |
| @@ -1327,7 +1321,7 @@ static const struct builtincmd builtincmd[] = { | |||
| 1327 | #ifdef CONFIG_ASH_ALIAS | 1321 | #ifdef CONFIG_ASH_ALIAS |
| 1328 | { BUILTIN_REG_ASSG "alias", aliascmd }, | 1322 | { BUILTIN_REG_ASSG "alias", aliascmd }, |
| 1329 | #endif | 1323 | #endif |
| 1330 | #ifdef JOBS | 1324 | #if JOBS |
| 1331 | { BUILTIN_REGULAR "bg", bgcmd }, | 1325 | { BUILTIN_REGULAR "bg", bgcmd }, |
| 1332 | #endif | 1326 | #endif |
| 1333 | { BUILTIN_SPEC_REG "break", breakcmd }, | 1327 | { BUILTIN_SPEC_REG "break", breakcmd }, |
| @@ -1345,7 +1339,7 @@ static const struct builtincmd builtincmd[] = { | |||
| 1345 | { BUILTIN_SPEC_REG "exit", exitcmd }, | 1339 | { BUILTIN_SPEC_REG "exit", exitcmd }, |
| 1346 | { BUILTIN_SPEC_REG_ASSG "export", exportcmd }, | 1340 | { BUILTIN_SPEC_REG_ASSG "export", exportcmd }, |
| 1347 | { BUILTIN_REGULAR "false", falsecmd }, | 1341 | { BUILTIN_REGULAR "false", falsecmd }, |
| 1348 | #ifdef JOBS | 1342 | #if JOBS |
| 1349 | { BUILTIN_REGULAR "fg", fgcmd }, | 1343 | { BUILTIN_REGULAR "fg", fgcmd }, |
| 1350 | #endif | 1344 | #endif |
| 1351 | #ifdef CONFIG_ASH_GETOPTS | 1345 | #ifdef CONFIG_ASH_GETOPTS |
| @@ -1355,7 +1349,7 @@ static const struct builtincmd builtincmd[] = { | |||
| 1355 | #ifndef CONFIG_FEATURE_SH_EXTRA_QUIET | 1349 | #ifndef CONFIG_FEATURE_SH_EXTRA_QUIET |
| 1356 | { BUILTIN_NOSPEC "help", helpcmd }, | 1350 | { BUILTIN_NOSPEC "help", helpcmd }, |
| 1357 | #endif | 1351 | #endif |
| 1358 | #ifdef JOBS | 1352 | #if JOBS |
| 1359 | { BUILTIN_REGULAR "jobs", jobscmd }, | 1353 | { BUILTIN_REGULAR "jobs", jobscmd }, |
| 1360 | { BUILTIN_REGULAR "kill", killcmd }, | 1354 | { BUILTIN_REGULAR "kill", killcmd }, |
| 1361 | #endif | 1355 | #endif |
| @@ -1434,11 +1428,11 @@ static void change_random(const char *); | |||
| 1434 | # endif | 1428 | # endif |
| 1435 | #endif | 1429 | #endif |
| 1436 | 1430 | ||
| 1437 | /* $NetBSD: init.h,v 1.9 2002/11/24 22:35:40 christos Exp $ */ | 1431 | /* init.h */ |
| 1438 | 1432 | ||
| 1439 | static void reset(void); | 1433 | static void reset(void); |
| 1440 | 1434 | ||
| 1441 | /* $NetBSD: var.h,v 1.21 2003/01/22 20:36:04 dsl Exp $ */ | 1435 | /* var.h */ |
| 1442 | 1436 | ||
| 1443 | /* | 1437 | /* |
| 1444 | * Shell variables. | 1438 | * Shell variables. |
| @@ -1613,7 +1607,7 @@ static int nullredirs; | |||
| 1613 | 1607 | ||
| 1614 | extern char **environ; | 1608 | extern char **environ; |
| 1615 | 1609 | ||
| 1616 | /* $NetBSD: output.h,v 1.16 2002/11/24 22:35:42 christos Exp $ */ | 1610 | /* output.h */ |
| 1617 | 1611 | ||
| 1618 | 1612 | ||
| 1619 | static void outstr(const char *, FILE *); | 1613 | static void outstr(const char *, FILE *); |
| @@ -1714,6 +1708,11 @@ init(void) | |||
| 1714 | 1708 | ||
| 1715 | /* PEOF (the end of file marker) */ | 1709 | /* PEOF (the end of file marker) */ |
| 1716 | 1710 | ||
| 1711 | enum { | ||
| 1712 | INPUT_PUSH_FILE = 1, | ||
| 1713 | INPUT_NOFILE_OK = 2, | ||
| 1714 | }; | ||
| 1715 | |||
| 1717 | /* | 1716 | /* |
| 1718 | * The input line number. Input.c just defines this variable, and saves | 1717 | * The input line number. Input.c just defines this variable, and saves |
| 1719 | * and restores it when files are pushed and popped. The user of this | 1718 | * and restores it when files are pushed and popped. The user of this |
| @@ -1726,7 +1725,6 @@ static int preadbuffer(void); | |||
| 1726 | static void pungetc(void); | 1725 | static void pungetc(void); |
| 1727 | static void pushstring(char *, void *); | 1726 | static void pushstring(char *, void *); |
| 1728 | static void popstring(void); | 1727 | static void popstring(void); |
| 1729 | static void setinputfile(const char *, int); | ||
| 1730 | static void setinputfd(int, int); | 1728 | static void setinputfd(int, int); |
| 1731 | static void setinputstring(char *); | 1729 | static void setinputstring(char *); |
| 1732 | static void popfile(void); | 1730 | static void popfile(void); |
| @@ -1734,7 +1732,7 @@ static void popallfiles(void); | |||
| 1734 | static void closescript(void); | 1732 | static void closescript(void); |
| 1735 | 1733 | ||
| 1736 | 1734 | ||
| 1737 | /* $NetBSD: jobs.h,v 1.17 2003/01/22 20:36:04 dsl Exp $ */ | 1735 | /* jobs.h */ |
| 1738 | 1736 | ||
| 1739 | 1737 | ||
| 1740 | /* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */ | 1738 | /* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */ |
| @@ -1801,18 +1799,19 @@ static void setjobctl(int); | |||
| 1801 | static void showjobs(FILE *, int); | 1799 | static void showjobs(FILE *, int); |
| 1802 | #endif | 1800 | #endif |
| 1803 | 1801 | ||
| 1804 | /* $NetBSD: main.h,v 1.9 2002/11/24 22:35:41 christos Exp $ */ | 1802 | /* main.h */ |
| 1805 | 1803 | ||
| 1806 | 1804 | ||
| 1807 | /* pid of main shell */ | 1805 | /* pid of main shell */ |
| 1808 | static int rootpid; | 1806 | static int rootpid; |
| 1809 | /* true if we aren't a child of the main shell */ | 1807 | /* shell level: 0 for the main shell, 1 for its children, and so on */ |
| 1810 | static int rootshell; | 1808 | static int shlvl; |
| 1809 | #define rootshell (!shlvl) | ||
| 1811 | 1810 | ||
| 1812 | static void readcmdfile(char *); | 1811 | static void readcmdfile(char *); |
| 1813 | static void cmdloop(int); | 1812 | static int cmdloop(int); |
| 1814 | 1813 | ||
| 1815 | /* $NetBSD: memalloc.h,v 1.13 2003/01/22 20:36:04 dsl Exp $ */ | 1814 | /* memalloc.h */ |
| 1816 | 1815 | ||
| 1817 | 1816 | ||
| 1818 | struct stackmark { | 1817 | struct stackmark { |
| @@ -1853,7 +1852,7 @@ static char *stnputs(const char *, size_t, char *); | |||
| 1853 | static char *stputs(const char *, char *); | 1852 | static char *stputs(const char *, char *); |
| 1854 | 1853 | ||
| 1855 | 1854 | ||
| 1856 | static inline char *_STPUTC(char c, char *p) { | 1855 | static inline char *_STPUTC(int c, char *p) { |
| 1857 | if (p == sstrend) | 1856 | if (p == sstrend) |
| 1858 | p = growstackstr(); | 1857 | p = growstackstr(); |
| 1859 | *p++ = c; | 1858 | *p++ = c; |
| @@ -1885,7 +1884,7 @@ static inline char *_STPUTC(char c, char *p) { | |||
| 1885 | 1884 | ||
| 1886 | #define ckfree(p) free((pointer)(p)) | 1885 | #define ckfree(p) free((pointer)(p)) |
| 1887 | 1886 | ||
| 1888 | /* $NetBSD: mystring.h,v 1.10 2002/11/24 22:35:42 christos Exp $ */ | 1887 | /* mystring.h */ |
| 1889 | 1888 | ||
| 1890 | 1889 | ||
| 1891 | #define DOLATSTRLEN 4 | 1890 | #define DOLATSTRLEN 4 |
| @@ -1899,7 +1898,7 @@ static char *sstrdup(const char *); | |||
| 1899 | #define equal(s1, s2) (strcmp(s1, s2) == 0) | 1898 | #define equal(s1, s2) (strcmp(s1, s2) == 0) |
| 1900 | #define scopy(s1, s2) ((void)strcpy(s2, s1)) | 1899 | #define scopy(s1, s2) ((void)strcpy(s2, s1)) |
| 1901 | 1900 | ||
| 1902 | /* $NetBSD: options.h,v 1.16 2003/01/22 20:36:04 dsl Exp $ */ | 1901 | /* options.h */ |
| 1903 | 1902 | ||
| 1904 | struct shparam { | 1903 | struct shparam { |
| 1905 | int nparam; /* # of positional parameters (without $0) */ | 1904 | int nparam; /* # of positional parameters (without $0) */ |
| @@ -1925,19 +1924,18 @@ struct shparam { | |||
| 1925 | #define aflag optlist[10] | 1924 | #define aflag optlist[10] |
| 1926 | #define bflag optlist[11] | 1925 | #define bflag optlist[11] |
| 1927 | #define uflag optlist[12] | 1926 | #define uflag optlist[12] |
| 1928 | #define qflag optlist[13] | 1927 | #define viflag optlist[13] |
| 1929 | #define viflag optlist[14] | ||
| 1930 | 1928 | ||
| 1931 | #ifdef DEBUG | 1929 | #ifdef DEBUG |
| 1932 | #define nolog optlist[15] | 1930 | #define nolog optlist[14] |
| 1933 | #define debug optlist[16] | 1931 | #define debug optlist[15] |
| 1934 | #endif | 1932 | #endif |
| 1935 | 1933 | ||
| 1936 | #ifndef CONFIG_FEATURE_COMMAND_EDITING_VI | 1934 | #ifndef CONFIG_FEATURE_COMMAND_EDITING_VI |
| 1937 | #define setvimode(on) viflag = 0 /* forcibly keep the option off */ | 1935 | #define setvimode(on) viflag = 0 /* forcibly keep the option off */ |
| 1938 | #endif | 1936 | #endif |
| 1939 | 1937 | ||
| 1940 | /* $NetBSD: options.c,v 1.33 2003/01/22 20:36:04 dsl Exp $ */ | 1938 | /* options.c */ |
| 1941 | 1939 | ||
| 1942 | 1940 | ||
| 1943 | static const char *const optletters_optnames[] = { | 1941 | static const char *const optletters_optnames[] = { |
| @@ -1954,7 +1952,6 @@ static const char *const optletters_optnames[] = { | |||
| 1954 | "a" "allexport", | 1952 | "a" "allexport", |
| 1955 | "b" "notify", | 1953 | "b" "notify", |
| 1956 | "u" "nounset", | 1954 | "u" "nounset", |
| 1957 | "q" "quietprofile", | ||
| 1958 | "\0" "vi", | 1955 | "\0" "vi", |
| 1959 | #ifdef DEBUG | 1956 | #ifdef DEBUG |
| 1960 | "\0" "nolog", | 1957 | "\0" "nolog", |
| @@ -1987,7 +1984,7 @@ static int shiftcmd(int, char **); | |||
| 1987 | static int setcmd(int, char **); | 1984 | static int setcmd(int, char **); |
| 1988 | static int nextopt(const char *); | 1985 | static int nextopt(const char *); |
| 1989 | 1986 | ||
| 1990 | /* $NetBSD: redir.h,v 1.14 2002/11/24 22:35:43 christos Exp $ */ | 1987 | /* redir.h */ |
| 1991 | 1988 | ||
| 1992 | /* flags passed to redirect */ | 1989 | /* flags passed to redirect */ |
| 1993 | #define REDIR_PUSH 01 /* save previous values of file descriptors */ | 1990 | #define REDIR_PUSH 01 /* save previous values of file descriptors */ |
| @@ -2000,7 +1997,7 @@ static void clearredir(int); | |||
| 2000 | static int copyfd(int, int); | 1997 | static int copyfd(int, int); |
| 2001 | static int redirectsafe(union node *, int); | 1998 | static int redirectsafe(union node *, int); |
| 2002 | 1999 | ||
| 2003 | /* $NetBSD: show.h,v 1.6 2003/01/22 20:36:04 dsl Exp $ */ | 2000 | /* show.h */ |
| 2004 | 2001 | ||
| 2005 | 2002 | ||
| 2006 | #ifdef DEBUG | 2003 | #ifdef DEBUG |
| @@ -2013,7 +2010,7 @@ static void trputs(const char *); | |||
| 2013 | static void opentrace(void); | 2010 | static void opentrace(void); |
| 2014 | #endif | 2011 | #endif |
| 2015 | 2012 | ||
| 2016 | /* $NetBSD: trap.h,v 1.16 2002/11/24 22:35:43 christos Exp $ */ | 2013 | /* trap.h */ |
| 2017 | 2014 | ||
| 2018 | 2015 | ||
| 2019 | /* trap handler commands */ | 2016 | /* trap handler commands */ |
| @@ -2027,7 +2024,7 @@ static void clear_traps(void); | |||
| 2027 | static void setsignal(int); | 2024 | static void setsignal(int); |
| 2028 | static void ignoresig(int); | 2025 | static void ignoresig(int); |
| 2029 | static void onsig(int); | 2026 | static void onsig(int); |
| 2030 | static void dotrap(void); | 2027 | static int dotrap(void); |
| 2031 | static void setinteractive(int); | 2028 | static void setinteractive(int); |
| 2032 | static void exitshell(void) __attribute__((__noreturn__)); | 2029 | static void exitshell(void) __attribute__((__noreturn__)); |
| 2033 | static int decode_signal(const char *, int); | 2030 | static int decode_signal(const char *, int); |
| @@ -2044,7 +2041,6 @@ reset(void) | |||
| 2044 | { | 2041 | { |
| 2045 | evalskip = 0; | 2042 | evalskip = 0; |
| 2046 | loopnest = 0; | 2043 | loopnest = 0; |
| 2047 | funcnest = 0; | ||
| 2048 | } | 2044 | } |
| 2049 | 2045 | ||
| 2050 | /* from input.c: */ | 2046 | /* from input.c: */ |
| @@ -2250,7 +2246,7 @@ __lookupalias(const char *name) { | |||
| 2250 | #endif /* CONFIG_ASH_ALIAS */ | 2246 | #endif /* CONFIG_ASH_ALIAS */ |
| 2251 | 2247 | ||
| 2252 | 2248 | ||
| 2253 | /* $NetBSD: cd.c,v 1.30 2003/01/22 20:36:03 dsl Exp $ */ | 2249 | /* cd.c */ |
| 2254 | 2250 | ||
| 2255 | /* | 2251 | /* |
| 2256 | * The cd and pwd commands. | 2252 | * The cd and pwd commands. |
| @@ -2337,7 +2333,7 @@ docd: | |||
| 2337 | break; | 2333 | break; |
| 2338 | } | 2334 | } |
| 2339 | } while (path); | 2335 | } while (path); |
| 2340 | error("can't cd to %s", dest); | 2336 | sh_error("can't cd to %s", dest); |
| 2341 | /* NOTREACHED */ | 2337 | /* NOTREACHED */ |
| 2342 | out: | 2338 | out: |
| 2343 | if (flags & CD_PRINT) | 2339 | if (flags & CD_PRINT) |
| @@ -2495,7 +2491,7 @@ setpwd(const char *val, int setold) | |||
| 2495 | setvar("PWD", dir, VEXPORT); | 2491 | setvar("PWD", dir, VEXPORT); |
| 2496 | } | 2492 | } |
| 2497 | 2493 | ||
| 2498 | /* $NetBSD: error.c,v 1.30 2003/01/22 20:36:03 dsl Exp $ */ | 2494 | /* error.c */ |
| 2499 | 2495 | ||
| 2500 | /* | 2496 | /* |
| 2501 | * Errors and exceptions. | 2497 | * Errors and exceptions. |
| @@ -2602,7 +2598,7 @@ exverror(int cond, const char *msg, va_list ap) | |||
| 2602 | 2598 | ||
| 2603 | 2599 | ||
| 2604 | static void | 2600 | static void |
| 2605 | error(const char *msg, ...) | 2601 | sh_error(const char *msg, ...) |
| 2606 | { | 2602 | { |
| 2607 | va_list ap; | 2603 | va_list ap; |
| 2608 | 2604 | ||
| @@ -2656,7 +2652,7 @@ errmsg(int e, const char *em) | |||
| 2656 | } | 2652 | } |
| 2657 | 2653 | ||
| 2658 | 2654 | ||
| 2659 | /* $NetBSD: eval.c,v 1.71 2003/01/23 03:33:16 rafal Exp $ */ | 2655 | /* eval.c */ |
| 2660 | 2656 | ||
| 2661 | /* | 2657 | /* |
| 2662 | * Evaluate a command. | 2658 | * Evaluate a command. |
| @@ -2715,7 +2711,8 @@ evalcmd(int argc, char **argv) | |||
| 2715 | STPUTC('\0', concat); | 2711 | STPUTC('\0', concat); |
| 2716 | p = grabstackstr(concat); | 2712 | p = grabstackstr(concat); |
| 2717 | } | 2713 | } |
| 2718 | evalstring(p); | 2714 | evalstring(p, ~SKIPEVAL); |
| 2715 | |||
| 2719 | } | 2716 | } |
| 2720 | return exitstatus; | 2717 | return exitstatus; |
| 2721 | } | 2718 | } |
| @@ -2725,23 +2722,29 @@ evalcmd(int argc, char **argv) | |||
| 2725 | * Execute a command or commands contained in a string. | 2722 | * Execute a command or commands contained in a string. |
| 2726 | */ | 2723 | */ |
| 2727 | 2724 | ||
| 2728 | static void | 2725 | static int |
| 2729 | evalstring(char *s) | 2726 | evalstring(char *s, int mask) |
| 2730 | { | 2727 | { |
| 2731 | union node *n; | 2728 | union node *n; |
| 2732 | struct stackmark smark; | 2729 | struct stackmark smark; |
| 2730 | int skip; | ||
| 2733 | 2731 | ||
| 2734 | setstackmark(&smark); | ||
| 2735 | setinputstring(s); | 2732 | setinputstring(s); |
| 2733 | setstackmark(&smark); | ||
| 2736 | 2734 | ||
| 2735 | skip = 0; | ||
| 2737 | while ((n = parsecmd(0)) != NEOF) { | 2736 | while ((n = parsecmd(0)) != NEOF) { |
| 2738 | evaltree(n, 0); | 2737 | evaltree(n, 0); |
| 2739 | popstackmark(&smark); | 2738 | popstackmark(&smark); |
| 2740 | if (evalskip) | 2739 | skip = evalskip; |
| 2740 | if (skip) | ||
| 2741 | break; | 2741 | break; |
| 2742 | } | 2742 | } |
| 2743 | popfile(); | 2743 | popfile(); |
| 2744 | popstackmark(&smark); | 2744 | |
| 2745 | skip &= mask; | ||
| 2746 | evalskip = skip; | ||
| 2747 | return skip; | ||
| 2745 | } | 2748 | } |
| 2746 | 2749 | ||
| 2747 | 2750 | ||
| @@ -2853,10 +2856,15 @@ setstatus: | |||
| 2853 | break; | 2856 | break; |
| 2854 | } | 2857 | } |
| 2855 | out: | 2858 | out: |
| 2856 | if (pendingsigs) | 2859 | if ((checkexit & exitstatus)) |
| 2857 | dotrap(); | 2860 | evalskip |= SKIPEVAL; |
| 2858 | if (flags & EV_EXIT || checkexit & exitstatus) | 2861 | else if (pendingsigs && dotrap()) |
| 2862 | goto exexit; | ||
| 2863 | |||
| 2864 | if (flags & EV_EXIT) { | ||
| 2865 | exexit: | ||
| 2859 | exraise(EXEXIT); | 2866 | exraise(EXEXIT); |
| 2867 | } | ||
| 2860 | } | 2868 | } |
| 2861 | 2869 | ||
| 2862 | 2870 | ||
| @@ -3071,7 +3079,7 @@ evalpipe(union node *n, int flags) | |||
| 3071 | if (lp->next) { | 3079 | if (lp->next) { |
| 3072 | if (pipe(pip) < 0) { | 3080 | if (pipe(pip) < 0) { |
| 3073 | close(prevfd); | 3081 | close(prevfd); |
| 3074 | error("Pipe call failed"); | 3082 | sh_error("Pipe call failed"); |
| 3075 | } | 3083 | } |
| 3076 | } | 3084 | } |
| 3077 | if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) { | 3085 | if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) { |
| @@ -3132,7 +3140,7 @@ evalbackcmd(union node *n, struct backcmd *result) | |||
| 3132 | struct job *jp; | 3140 | struct job *jp; |
| 3133 | 3141 | ||
| 3134 | if (pipe(pip) < 0) | 3142 | if (pipe(pip) < 0) |
| 3135 | error("Pipe call failed"); | 3143 | sh_error("Pipe call failed"); |
| 3136 | jp = makejob(n, 1); | 3144 | jp = makejob(n, 1); |
| 3137 | if (forkshell(jp, n, FORK_NOJOB) == 0) { | 3145 | if (forkshell(jp, n, FORK_NOJOB) == 0) { |
| 3138 | FORCEINTON; | 3146 | FORCEINTON; |
| @@ -3485,6 +3493,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags) | |||
| 3485 | localvars = NULL; | 3493 | localvars = NULL; |
| 3486 | shellparam.malloc = 0; | 3494 | shellparam.malloc = 0; |
| 3487 | func->count++; | 3495 | func->count++; |
| 3496 | funcnest++; | ||
| 3488 | INTON; | 3497 | INTON; |
| 3489 | shellparam.nparam = argc - 1; | 3498 | shellparam.nparam = argc - 1; |
| 3490 | shellparam.p = argv + 1; | 3499 | shellparam.p = argv + 1; |
| @@ -3492,11 +3501,10 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags) | |||
| 3492 | shellparam.optind = 1; | 3501 | shellparam.optind = 1; |
| 3493 | shellparam.optoff = -1; | 3502 | shellparam.optoff = -1; |
| 3494 | #endif | 3503 | #endif |
| 3495 | funcnest++; | ||
| 3496 | evaltree(&func->n, flags & EV_TESTED); | 3504 | evaltree(&func->n, flags & EV_TESTED); |
| 3497 | funcnest--; | ||
| 3498 | funcdone: | 3505 | funcdone: |
| 3499 | INTOFF; | 3506 | INTOFF; |
| 3507 | funcnest--; | ||
| 3500 | freefunc(func); | 3508 | freefunc(func); |
| 3501 | poplocalvars(); | 3509 | poplocalvars(); |
| 3502 | localvars = savelocalvars; | 3510 | localvars = savelocalvars; |
| @@ -3504,10 +3512,7 @@ funcdone: | |||
| 3504 | shellparam = saveparam; | 3512 | shellparam = saveparam; |
| 3505 | handler = savehandler; | 3513 | handler = savehandler; |
| 3506 | INTON; | 3514 | INTON; |
| 3507 | if (evalskip == SKIPFUNC) { | 3515 | evalskip &= ~SKIPFUNC; |
| 3508 | evalskip = 0; | ||
| 3509 | skipcount = 0; | ||
| 3510 | } | ||
| 3511 | return e; | 3516 | return e; |
| 3512 | } | 3517 | } |
| 3513 | 3518 | ||
| @@ -3575,7 +3580,7 @@ breakcmd(int argc, char **argv) | |||
| 3575 | int n = argc > 1 ? number(argv[1]) : 1; | 3580 | int n = argc > 1 ? number(argv[1]) : 1; |
| 3576 | 3581 | ||
| 3577 | if (n <= 0) | 3582 | if (n <= 0) |
| 3578 | error(illnum, argv[1]); | 3583 | sh_error(illnum, argv[1]); |
| 3579 | if (n > loopnest) | 3584 | if (n > loopnest) |
| 3580 | n = loopnest; | 3585 | n = loopnest; |
| 3581 | if (n > 0) { | 3586 | if (n > 0) { |
| @@ -3593,19 +3598,12 @@ breakcmd(int argc, char **argv) | |||
| 3593 | static int | 3598 | static int |
| 3594 | returncmd(int argc, char **argv) | 3599 | returncmd(int argc, char **argv) |
| 3595 | { | 3600 | { |
| 3596 | int ret = argc > 1 ? number(argv[1]) : exitstatus; | 3601 | /* |
| 3597 | 3602 | * If called outside a function, do what ksh does; | |
| 3598 | if (funcnest) { | 3603 | * skip the rest of the file. |
| 3599 | evalskip = SKIPFUNC; | 3604 | */ |
| 3600 | skipcount = 1; | 3605 | evalskip = funcnest ? SKIPFUNC : SKIPFILE; |
| 3601 | return ret; | 3606 | return argv[1] ? number(argv[1]) : exitstatus; |
| 3602 | } | ||
| 3603 | else { | ||
| 3604 | /* Do what ksh does; skip the rest of the file */ | ||
| 3605 | evalskip = SKIPFILE; | ||
| 3606 | skipcount = 1; | ||
| 3607 | return ret; | ||
| 3608 | } | ||
| 3609 | } | 3607 | } |
| 3610 | 3608 | ||
| 3611 | 3609 | ||
| @@ -3636,7 +3634,7 @@ execcmd(int argc, char **argv) | |||
| 3636 | } | 3634 | } |
| 3637 | 3635 | ||
| 3638 | 3636 | ||
| 3639 | /* $NetBSD: exec.c,v 1.35 2003/01/22 20:36:04 dsl Exp $ */ | 3637 | /* exec.c */ |
| 3640 | 3638 | ||
| 3641 | /* | 3639 | /* |
| 3642 | * When commands are first encountered, they are entered in a hash table. | 3640 | * When commands are first encountered, they are entered in a hash table. |
| @@ -3682,6 +3680,7 @@ shellexec(char **argv, const char *path, int idx) | |||
| 3682 | char *cmdname; | 3680 | char *cmdname; |
| 3683 | int e; | 3681 | int e; |
| 3684 | char **envp; | 3682 | char **envp; |
| 3683 | int exerrno; | ||
| 3685 | 3684 | ||
| 3686 | clearredir(1); | 3685 | clearredir(1); |
| 3687 | envp = environment(); | 3686 | envp = environment(); |
| @@ -3716,6 +3715,7 @@ shellexec(char **argv, const char *path, int idx) | |||
| 3716 | exerrno = 2; | 3715 | exerrno = 2; |
| 3717 | break; | 3716 | break; |
| 3718 | } | 3717 | } |
| 3718 | exitstatus = exerrno; | ||
| 3719 | TRACE(("shellexec failed for %s, errno %d, suppressint %d\n", | 3719 | TRACE(("shellexec failed for %s, errno %d, suppressint %d\n", |
| 3720 | argv[0], e, suppressint )); | 3720 | argv[0], e, suppressint )); |
| 3721 | exerror(EXEXEC, "%s: %s", argv[0], errmsg(e, E_EXEC)); | 3721 | exerror(EXEXEC, "%s: %s", argv[0], errmsg(e, E_EXEC)); |
| @@ -4004,7 +4004,7 @@ loop: | |||
| 4004 | readcmdfile(fullname); | 4004 | readcmdfile(fullname); |
| 4005 | if ((cmdp = cmdlookup(name, 0)) == NULL || | 4005 | if ((cmdp = cmdlookup(name, 0)) == NULL || |
| 4006 | cmdp->cmdtype != CMDFUNCTION) | 4006 | cmdp->cmdtype != CMDFUNCTION) |
| 4007 | error("%s not defined in %s", name, fullname); | 4007 | sh_error("%s not defined in %s", name, fullname); |
| 4008 | stunalloc(fullname); | 4008 | stunalloc(fullname); |
| 4009 | goto success; | 4009 | goto success; |
| 4010 | } | 4010 | } |
| @@ -4438,46 +4438,28 @@ static int | |||
| 4438 | commandcmd(int argc, char **argv) | 4438 | commandcmd(int argc, char **argv) |
| 4439 | { | 4439 | { |
| 4440 | int c; | 4440 | int c; |
| 4441 | int default_path = 0; | 4441 | enum { |
| 4442 | int verify_only = 0; | 4442 | VERIFY_BRIEF = 1, |
| 4443 | int verbose_verify_only = 0; | 4443 | VERIFY_VERBOSE = 2, |
| 4444 | } verify = 0; | ||
| 4444 | 4445 | ||
| 4445 | while ((c = nextopt("pvV")) != '\0') | 4446 | while ((c = nextopt("pvV")) != '\0') |
| 4446 | switch (c) { | 4447 | if (c == 'V') |
| 4447 | default: | 4448 | verify |= VERIFY_VERBOSE; |
| 4449 | else if (c == 'v') | ||
| 4450 | verify |= VERIFY_BRIEF; | ||
| 4448 | #ifdef DEBUG | 4451 | #ifdef DEBUG |
| 4449 | fprintf(stderr, | 4452 | else if (c != 'p') |
| 4450 | "command: nextopt returned character code 0%o\n", c); | 4453 | abort(); |
| 4451 | return EX_SOFTWARE; | ||
| 4452 | #endif | 4454 | #endif |
| 4453 | case 'p': | 4455 | if (verify) |
| 4454 | default_path = 1; | 4456 | return describe_command(*argptr, verify - VERIFY_BRIEF); |
| 4455 | break; | ||
| 4456 | case 'v': | ||
| 4457 | verify_only = 1; | ||
| 4458 | break; | ||
| 4459 | case 'V': | ||
| 4460 | verbose_verify_only = 1; | ||
| 4461 | break; | ||
| 4462 | } | ||
| 4463 | |||
| 4464 | if (default_path + verify_only + verbose_verify_only > 1 || | ||
| 4465 | !*argptr) { | ||
| 4466 | fprintf(stderr, | ||
| 4467 | "command [-p] command [arg ...]\n" | ||
| 4468 | "command {-v|-V} command\n"); | ||
| 4469 | return EX_USAGE; | ||
| 4470 | } | ||
| 4471 | |||
| 4472 | if (verify_only || verbose_verify_only) { | ||
| 4473 | return describe_command(*argptr, verbose_verify_only); | ||
| 4474 | } | ||
| 4475 | 4457 | ||
| 4476 | return 0; | 4458 | return 0; |
| 4477 | } | 4459 | } |
| 4478 | #endif | 4460 | #endif |
| 4479 | 4461 | ||
| 4480 | /* $NetBSD: expand.c,v 1.56 2002/11/24 22:35:39 christos Exp $ */ | 4462 | /* expand.c */ |
| 4481 | 4463 | ||
| 4482 | /* | 4464 | /* |
| 4483 | * Routines to expand arguments to commands. We have to deal with | 4465 | * Routines to expand arguments to commands. We have to deal with |
| @@ -4806,14 +4788,13 @@ exptilde(char *startp, char *p, int flag) | |||
| 4806 | done: | 4788 | done: |
| 4807 | *p = '\0'; | 4789 | *p = '\0'; |
| 4808 | if (*name == '\0') { | 4790 | if (*name == '\0') { |
| 4809 | if ((home = lookupvar(homestr)) == NULL) | 4791 | home = lookupvar(homestr); |
| 4810 | goto lose; | ||
| 4811 | } else { | 4792 | } else { |
| 4812 | if ((pw = getpwnam(name)) == NULL) | 4793 | if ((pw = getpwnam(name)) == NULL) |
| 4813 | goto lose; | 4794 | goto lose; |
| 4814 | home = pw->pw_dir; | 4795 | home = pw->pw_dir; |
| 4815 | } | 4796 | } |
| 4816 | if (*home == '\0') | 4797 | if (!home || !*home) |
| 4817 | goto lose; | 4798 | goto lose; |
| 4818 | *p = c; | 4799 | *p = c; |
| 4819 | startloc = expdest - (char *)stackblock(); | 4800 | startloc = expdest - (char *)stackblock(); |
| @@ -4897,7 +4878,7 @@ expari(int quotes) | |||
| 4897 | p--; | 4878 | p--; |
| 4898 | #ifdef DEBUG | 4879 | #ifdef DEBUG |
| 4899 | if (p < start) { | 4880 | if (p < start) { |
| 4900 | error("missing CTLARI (shouldn't happen)"); | 4881 | sh_error("missing CTLARI (shouldn't happen)"); |
| 4901 | } | 4882 | } |
| 4902 | #endif | 4883 | #endif |
| 4903 | } | 4884 | } |
| @@ -5275,7 +5256,7 @@ memtodest(const char *p, size_t len, int syntax, int quotes) { | |||
| 5275 | q = makestrspace(len * 2, q); | 5256 | q = makestrspace(len * 2, q); |
| 5276 | 5257 | ||
| 5277 | while (len--) { | 5258 | while (len--) { |
| 5278 | int c = *p++; | 5259 | int c = (unsigned char)*p++; |
| 5279 | if (!c) | 5260 | if (!c) |
| 5280 | continue; | 5261 | continue; |
| 5281 | if (quotes && (SIT(c, syntax) == CCTL || SIT(c, syntax) == CBACK)) | 5262 | if (quotes && (SIT(c, syntax) == CCTL || SIT(c, syntax) == CBACK)) |
| @@ -5932,11 +5913,11 @@ varunset(const char *end, const char *var, const char *umsg, int varflags) | |||
| 5932 | } else | 5913 | } else |
| 5933 | msg = umsg; | 5914 | msg = umsg; |
| 5934 | } | 5915 | } |
| 5935 | error("%.*s: %s%s", end - var - 1, var, msg, tail); | 5916 | sh_error("%.*s: %s%s", end - var - 1, var, msg, tail); |
| 5936 | } | 5917 | } |
| 5937 | 5918 | ||
| 5938 | 5919 | ||
| 5939 | /* $NetBSD: input.c,v 1.37 2002/11/24 22:35:40 christos Exp $ */ | 5920 | /* input.c */ |
| 5940 | 5921 | ||
| 5941 | /* | 5922 | /* |
| 5942 | * This implements the input routines used by the parser. | 5923 | * This implements the input routines used by the parser. |
| @@ -6103,7 +6084,7 @@ retry: | |||
| 6103 | int | 6084 | int |
| 6104 | preadbuffer(void) | 6085 | preadbuffer(void) |
| 6105 | { | 6086 | { |
| 6106 | char *p, *q; | 6087 | char *q; |
| 6107 | int more; | 6088 | int more; |
| 6108 | char savec; | 6089 | char savec; |
| 6109 | 6090 | ||
| @@ -6122,39 +6103,42 @@ preadbuffer(void) | |||
| 6122 | return PEOF; | 6103 | return PEOF; |
| 6123 | flushall(); | 6104 | flushall(); |
| 6124 | 6105 | ||
| 6106 | more = parselleft; | ||
| 6107 | if (more <= 0) { | ||
| 6125 | again: | 6108 | again: |
| 6126 | if (parselleft <= 0) { | 6109 | if ((more = preadfd()) <= 0) { |
| 6127 | if ((parselleft = preadfd()) <= 0) { | ||
| 6128 | parselleft = parsenleft = EOF_NLEFT; | 6110 | parselleft = parsenleft = EOF_NLEFT; |
| 6129 | return PEOF; | 6111 | return PEOF; |
| 6130 | } | 6112 | } |
| 6131 | } | 6113 | } |
| 6132 | 6114 | ||
| 6133 | q = p = parsenextc; | 6115 | q = parsenextc; |
| 6134 | 6116 | ||
| 6135 | /* delete nul characters */ | 6117 | /* delete nul characters */ |
| 6136 | for (more = 1; more;) { | 6118 | for (;;) { |
| 6137 | switch (*p) { | 6119 | int c; |
| 6138 | case '\0': | ||
| 6139 | p++; /* Skip nul */ | ||
| 6140 | goto check; | ||
| 6141 | 6120 | ||
| 6142 | case '\n': | 6121 | more--; |
| 6143 | parsenleft = q - parsenextc; | 6122 | c = *q; |
| 6144 | more = 0; /* Stop processing here */ | ||
| 6145 | break; | ||
| 6146 | 6123 | ||
| 6124 | if (!c) | ||
| 6125 | memmove(q, q + 1, more); | ||
| 6126 | else { | ||
| 6127 | q++; | ||
| 6128 | if (c == '\n') { | ||
| 6129 | parsenleft = q - parsenextc - 1; | ||
| 6130 | break; | ||
| 6131 | } | ||
| 6147 | } | 6132 | } |
| 6148 | 6133 | ||
| 6149 | *q++ = *p++; | 6134 | if (more <= 0) { |
| 6150 | check: | ||
| 6151 | if (--parselleft <= 0 && more) { | ||
| 6152 | parsenleft = q - parsenextc - 1; | 6135 | parsenleft = q - parsenextc - 1; |
| 6153 | if (parsenleft < 0) | 6136 | if (parsenleft < 0) |
| 6154 | goto again; | 6137 | goto again; |
| 6155 | more = 0; | 6138 | break; |
| 6156 | } | 6139 | } |
| 6157 | } | 6140 | } |
| 6141 | parselleft = more; | ||
| 6158 | 6142 | ||
| 6159 | savec = *q; | 6143 | savec = *q; |
| 6160 | *q = '\0'; | 6144 | *q = '\0'; |
| @@ -6247,24 +6231,29 @@ popstring(void) | |||
| 6247 | * old input onto the stack first. | 6231 | * old input onto the stack first. |
| 6248 | */ | 6232 | */ |
| 6249 | 6233 | ||
| 6250 | void | 6234 | static int |
| 6251 | setinputfile(const char *fname, int push) | 6235 | setinputfile(const char *fname, int flags) |
| 6252 | { | 6236 | { |
| 6253 | int fd; | 6237 | int fd; |
| 6254 | int fd2; | 6238 | int fd2; |
| 6255 | 6239 | ||
| 6256 | INTOFF; | 6240 | INTOFF; |
| 6257 | if ((fd = open(fname, O_RDONLY)) < 0) | 6241 | if ((fd = open(fname, O_RDONLY)) < 0) { |
| 6258 | error("Can't open %s", fname); | 6242 | if (flags & INPUT_NOFILE_OK) |
| 6243 | goto out; | ||
| 6244 | sh_error("Can't open %s", fname); | ||
| 6245 | } | ||
| 6259 | if (fd < 10) { | 6246 | if (fd < 10) { |
| 6260 | fd2 = copyfd(fd, 10); | 6247 | fd2 = copyfd(fd, 10); |
| 6261 | close(fd); | 6248 | close(fd); |
| 6262 | if (fd2 < 0) | 6249 | if (fd2 < 0) |
| 6263 | error("Out of file descriptors"); | 6250 | sh_error("Out of file descriptors"); |
| 6264 | fd = fd2; | 6251 | fd = fd2; |
| 6265 | } | 6252 | } |
| 6266 | setinputfd(fd, push); | 6253 | setinputfd(fd, flags & INPUT_PUSH_FILE); |
| 6254 | out: | ||
| 6267 | INTON; | 6255 | INTON; |
| 6256 | return fd; | ||
| 6268 | } | 6257 | } |
| 6269 | 6258 | ||
| 6270 | 6259 | ||
| @@ -6378,7 +6367,7 @@ closescript(void) | |||
| 6378 | } | 6367 | } |
| 6379 | } | 6368 | } |
| 6380 | 6369 | ||
| 6381 | /* $NetBSD: jobs.c,v 1.56 2002/11/25 12:13:03 agc Exp $ */ | 6370 | /* jobs.c */ |
| 6382 | 6371 | ||
| 6383 | /* mode flags for set_curjob */ | 6372 | /* mode flags for set_curjob */ |
| 6384 | #define CUR_DELETE 2 | 6373 | #define CUR_DELETE 2 |
| @@ -6453,14 +6442,14 @@ set_curjob(struct job *jp, unsigned mode) | |||
| 6453 | put after all stopped jobs. */ | 6442 | put after all stopped jobs. */ |
| 6454 | do { | 6443 | do { |
| 6455 | jp1 = *jpp; | 6444 | jp1 = *jpp; |
| 6456 | #ifdef JOBS | 6445 | #if JOBS |
| 6457 | if (!jp1 || jp1->state != JOBSTOPPED) | 6446 | if (!jp1 || jp1->state != JOBSTOPPED) |
| 6458 | #endif | 6447 | #endif |
| 6459 | break; | 6448 | break; |
| 6460 | jpp = &jp1->prev_job; | 6449 | jpp = &jp1->prev_job; |
| 6461 | } while (1); | 6450 | } while (1); |
| 6462 | /* FALLTHROUGH */ | 6451 | /* FALLTHROUGH */ |
| 6463 | #ifdef JOBS | 6452 | #if JOBS |
| 6464 | case CUR_STOPPED: | 6453 | case CUR_STOPPED: |
| 6465 | #endif | 6454 | #endif |
| 6466 | /* newly stopped job - becomes curjob */ | 6455 | /* newly stopped job - becomes curjob */ |
| @@ -6549,7 +6538,7 @@ killcmd(int argc, char **argv) | |||
| 6549 | 6538 | ||
| 6550 | if (argc <= 1) { | 6539 | if (argc <= 1) { |
| 6551 | usage: | 6540 | usage: |
| 6552 | error( | 6541 | sh_error( |
| 6553 | "Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or\n" | 6542 | "Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or\n" |
| 6554 | "kill -l [exitstatus]" | 6543 | "kill -l [exitstatus]" |
| 6555 | ); | 6544 | ); |
| @@ -6572,7 +6561,7 @@ usage: | |||
| 6572 | case 's': | 6561 | case 's': |
| 6573 | signo = decode_signal(optionarg, 1); | 6562 | signo = decode_signal(optionarg, 1); |
| 6574 | if (signo < 0) { | 6563 | if (signo < 0) { |
| 6575 | error( | 6564 | sh_error( |
| 6576 | "invalid signal number or name: %s", | 6565 | "invalid signal number or name: %s", |
| 6577 | optionarg | 6566 | optionarg |
| 6578 | ); | 6567 | ); |
| @@ -6606,7 +6595,7 @@ usage: | |||
| 6606 | if (name) | 6595 | if (name) |
| 6607 | out1fmt(snlfmt, name); | 6596 | out1fmt(snlfmt, name); |
| 6608 | else | 6597 | else |
| 6609 | error("invalid signal number or exit status: %s", *argptr); | 6598 | sh_error("invalid signal number or exit status: %s", *argptr); |
| 6610 | return 0; | 6599 | return 0; |
| 6611 | } | 6600 | } |
| 6612 | 6601 | ||
| @@ -6637,7 +6626,7 @@ jobno(const struct job *jp) | |||
| 6637 | } | 6626 | } |
| 6638 | #endif | 6627 | #endif |
| 6639 | 6628 | ||
| 6640 | #ifdef JOBS | 6629 | #if JOBS |
| 6641 | static int | 6630 | static int |
| 6642 | fgcmd(int argc, char **argv) | 6631 | fgcmd(int argc, char **argv) |
| 6643 | { | 6632 | { |
| @@ -7020,7 +7009,7 @@ gotit: | |||
| 7020 | #endif | 7009 | #endif |
| 7021 | return jp; | 7010 | return jp; |
| 7022 | err: | 7011 | err: |
| 7023 | error(err_msg, name); | 7012 | sh_error(err_msg, name); |
| 7024 | } | 7013 | } |
| 7025 | 7014 | ||
| 7026 | 7015 | ||
| @@ -7132,18 +7121,18 @@ growjobtab(void) | |||
| 7132 | static inline void | 7121 | static inline void |
| 7133 | forkchild(struct job *jp, union node *n, int mode) | 7122 | forkchild(struct job *jp, union node *n, int mode) |
| 7134 | { | 7123 | { |
| 7135 | int wasroot; | 7124 | int oldlvl; |
| 7136 | 7125 | ||
| 7137 | TRACE(("Child shell %d\n", getpid())); | 7126 | TRACE(("Child shell %d\n", getpid())); |
| 7138 | wasroot = rootshell; | 7127 | oldlvl = shlvl; |
| 7139 | rootshell = 0; | 7128 | shlvl++; |
| 7140 | 7129 | ||
| 7141 | closescript(); | 7130 | closescript(); |
| 7142 | clear_traps(); | 7131 | clear_traps(); |
| 7143 | #if JOBS | 7132 | #if JOBS |
| 7144 | /* do job control only in root shell */ | 7133 | /* do job control only in root shell */ |
| 7145 | jobctl = 0; | 7134 | jobctl = 0; |
| 7146 | if (mode != FORK_NOJOB && jp->jobctl && wasroot) { | 7135 | if (mode != FORK_NOJOB && jp->jobctl && !oldlvl) { |
| 7147 | pid_t pgrp; | 7136 | pid_t pgrp; |
| 7148 | 7137 | ||
| 7149 | if (jp->nprocs == 0) | 7138 | if (jp->nprocs == 0) |
| @@ -7164,10 +7153,10 @@ forkchild(struct job *jp, union node *n, int mode) | |||
| 7164 | if (jp->nprocs == 0) { | 7153 | if (jp->nprocs == 0) { |
| 7165 | close(0); | 7154 | close(0); |
| 7166 | if (open(_PATH_DEVNULL, O_RDONLY) != 0) | 7155 | if (open(_PATH_DEVNULL, O_RDONLY) != 0) |
| 7167 | error("Can't open %s", _PATH_DEVNULL); | 7156 | sh_error("Can't open %s", _PATH_DEVNULL); |
| 7168 | } | 7157 | } |
| 7169 | } | 7158 | } |
| 7170 | if (wasroot && iflag) { | 7159 | if (!oldlvl && iflag) { |
| 7171 | setsignal(SIGINT); | 7160 | setsignal(SIGINT); |
| 7172 | setsignal(SIGQUIT); | 7161 | setsignal(SIGQUIT); |
| 7173 | setsignal(SIGTERM); | 7162 | setsignal(SIGTERM); |
| @@ -7225,7 +7214,7 @@ forkshell(struct job *jp, union node *n, int mode) | |||
| 7225 | TRACE(("Fork failed, errno=%d", errno)); | 7214 | TRACE(("Fork failed, errno=%d", errno)); |
| 7226 | if (jp) | 7215 | if (jp) |
| 7227 | freejob(jp); | 7216 | freejob(jp); |
| 7228 | error("Cannot fork"); | 7217 | sh_error("Cannot fork"); |
| 7229 | } | 7218 | } |
| 7230 | if (pid == 0) | 7219 | if (pid == 0) |
| 7231 | forkchild(jp, n, mode); | 7220 | forkchild(jp, n, mode); |
| @@ -7365,7 +7354,7 @@ dowait(int block, struct job *job) | |||
| 7365 | } | 7354 | } |
| 7366 | if (sp->status == -1) | 7355 | if (sp->status == -1) |
| 7367 | state = JOBRUNNING; | 7356 | state = JOBRUNNING; |
| 7368 | #ifdef JOBS | 7357 | #if JOBS |
| 7369 | if (state == JOBRUNNING) | 7358 | if (state == JOBRUNNING) |
| 7370 | continue; | 7359 | continue; |
| 7371 | if (WIFSTOPPED(sp->status)) { | 7360 | if (WIFSTOPPED(sp->status)) { |
| @@ -7377,7 +7366,7 @@ dowait(int block, struct job *job) | |||
| 7377 | if (thisjob) | 7366 | if (thisjob) |
| 7378 | goto gotjob; | 7367 | goto gotjob; |
| 7379 | } | 7368 | } |
| 7380 | #ifdef JOBS | 7369 | #if JOBS |
| 7381 | if (!WIFSTOPPED(status)) | 7370 | if (!WIFSTOPPED(status)) |
| 7382 | #endif | 7371 | #endif |
| 7383 | 7372 | ||
| @@ -7391,7 +7380,7 @@ gotjob: | |||
| 7391 | if (thisjob->state != state) { | 7380 | if (thisjob->state != state) { |
| 7392 | TRACE(("Job %d: changing state from %d to %d\n", jobno(thisjob), thisjob->state, state)); | 7381 | TRACE(("Job %d: changing state from %d to %d\n", jobno(thisjob), thisjob->state, state)); |
| 7393 | thisjob->state = state; | 7382 | thisjob->state = state; |
| 7394 | #ifdef JOBS | 7383 | #if JOBS |
| 7395 | if (state == JOBSTOPPED) { | 7384 | if (state == JOBSTOPPED) { |
| 7396 | set_curjob(thisjob, CUR_STOPPED); | 7385 | set_curjob(thisjob, CUR_STOPPED); |
| 7397 | } | 7386 | } |
| @@ -7739,7 +7728,7 @@ static void | |||
| 7739 | xtcsetpgrp(int fd, pid_t pgrp) | 7728 | xtcsetpgrp(int fd, pid_t pgrp) |
| 7740 | { | 7729 | { |
| 7741 | if (tcsetpgrp(fd, pgrp)) | 7730 | if (tcsetpgrp(fd, pgrp)) |
| 7742 | error("Cannot set tty process group (%m)"); | 7731 | sh_error("Cannot set tty process group (%m)"); |
| 7743 | } | 7732 | } |
| 7744 | #endif /* JOBS */ | 7733 | #endif /* JOBS */ |
| 7745 | 7734 | ||
| @@ -7771,7 +7760,7 @@ getstatus(struct job *job) { | |||
| 7771 | } | 7760 | } |
| 7772 | 7761 | ||
| 7773 | #ifdef CONFIG_ASH_MAIL | 7762 | #ifdef CONFIG_ASH_MAIL |
| 7774 | /* $NetBSD: mail.c,v 1.15 2002/11/24 22:35:40 christos Exp $ */ | 7763 | /* mail.c */ |
| 7775 | 7764 | ||
| 7776 | /* | 7765 | /* |
| 7777 | * Routines to check for mail. (Perhaps make part of main.c?) | 7766 | * Routines to check for mail. (Perhaps make part of main.c?) |
| @@ -7842,7 +7831,7 @@ changemail(const char *val) | |||
| 7842 | 7831 | ||
| 7843 | #endif /* CONFIG_ASH_MAIL */ | 7832 | #endif /* CONFIG_ASH_MAIL */ |
| 7844 | 7833 | ||
| 7845 | /* $NetBSD: main.c,v 1.46 2002/12/11 19:12:18 christos Exp $ */ | 7834 | /* main.c */ |
| 7846 | 7835 | ||
| 7847 | 7836 | ||
| 7848 | #if PROFILE | 7837 | #if PROFILE |
| @@ -7879,28 +7868,16 @@ ash_main(int argc, char **argv) | |||
| 7879 | #endif | 7868 | #endif |
| 7880 | state = 0; | 7869 | state = 0; |
| 7881 | if (setjmp(jmploc.loc)) { | 7870 | if (setjmp(jmploc.loc)) { |
| 7882 | int status; | ||
| 7883 | int e; | 7871 | int e; |
| 7872 | int s; | ||
| 7884 | 7873 | ||
| 7885 | reset(); | 7874 | reset(); |
| 7886 | 7875 | ||
| 7887 | e = exception; | 7876 | e = exception; |
| 7888 | switch (exception) { | 7877 | if (e == EXERROR) |
| 7889 | case EXEXEC: | 7878 | exitstatus = 2; |
| 7890 | status = exerrno; | 7879 | s = state; |
| 7891 | break; | 7880 | if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) |
| 7892 | |||
| 7893 | case EXERROR: | ||
| 7894 | status = 2; | ||
| 7895 | break; | ||
| 7896 | |||
| 7897 | default: | ||
| 7898 | status = exitstatus; | ||
| 7899 | break; | ||
| 7900 | } | ||
| 7901 | exitstatus = status; | ||
| 7902 | |||
| 7903 | if (e == EXEXIT || state == 0 || iflag == 0 || ! rootshell) | ||
| 7904 | exitshell(); | 7881 | exitshell(); |
| 7905 | 7882 | ||
| 7906 | if (e == EXINT) { | 7883 | if (e == EXINT) { |
| @@ -7908,11 +7885,11 @@ ash_main(int argc, char **argv) | |||
| 7908 | } | 7885 | } |
| 7909 | popstackmark(&smark); | 7886 | popstackmark(&smark); |
| 7910 | FORCEINTON; /* enable interrupts */ | 7887 | FORCEINTON; /* enable interrupts */ |
| 7911 | if (state == 1) | 7888 | if (s == 1) |
| 7912 | goto state1; | 7889 | goto state1; |
| 7913 | else if (state == 2) | 7890 | else if (s == 2) |
| 7914 | goto state2; | 7891 | goto state2; |
| 7915 | else if (state == 3) | 7892 | else if (s == 3) |
| 7916 | goto state3; | 7893 | goto state3; |
| 7917 | else | 7894 | else |
| 7918 | goto state4; | 7895 | goto state4; |
| @@ -7927,7 +7904,6 @@ ash_main(int argc, char **argv) | |||
| 7927 | #ifdef CONFIG_ASH_RANDOM_SUPPORT | 7904 | #ifdef CONFIG_ASH_RANDOM_SUPPORT |
| 7928 | rseed = rootpid + ((time_t)time((time_t *)0)); | 7905 | rseed = rootpid + ((time_t)time((time_t *)0)); |
| 7929 | #endif | 7906 | #endif |
| 7930 | rootshell = 1; | ||
| 7931 | init(); | 7907 | init(); |
| 7932 | setstackmark(&smark); | 7908 | setstackmark(&smark); |
| 7933 | procargs(argc, argv); | 7909 | procargs(argc, argv); |
| @@ -7969,7 +7945,7 @@ state2: | |||
| 7969 | state3: | 7945 | state3: |
| 7970 | state = 4; | 7946 | state = 4; |
| 7971 | if (minusc) | 7947 | if (minusc) |
| 7972 | evalstring(minusc); | 7948 | evalstring(minusc, 0); |
| 7973 | 7949 | ||
| 7974 | if (sflag || minusc == NULL) { | 7950 | if (sflag || minusc == NULL) { |
| 7975 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY | 7951 | #ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY |
| @@ -8002,7 +7978,7 @@ state4: /* XXX ??? - why isn't this before the "if" statement */ | |||
| 8002 | * loop; it turns on prompting if the shell is interactive. | 7978 | * loop; it turns on prompting if the shell is interactive. |
| 8003 | */ | 7979 | */ |
| 8004 | 7980 | ||
| 8005 | static void | 7981 | static int |
| 8006 | cmdloop(int top) | 7982 | cmdloop(int top) |
| 8007 | { | 7983 | { |
| 8008 | union node *n; | 7984 | union node *n; |
| @@ -8012,9 +7988,9 @@ cmdloop(int top) | |||
| 8012 | 7988 | ||
| 8013 | TRACE(("cmdloop(%d) called\n", top)); | 7989 | TRACE(("cmdloop(%d) called\n", top)); |
| 8014 | for (;;) { | 7990 | for (;;) { |
| 7991 | int skip; | ||
| 7992 | |||
| 8015 | setstackmark(&smark); | 7993 | setstackmark(&smark); |
| 8016 | if (pendingsigs) | ||
| 8017 | dotrap(); | ||
| 8018 | #if JOBS | 7994 | #if JOBS |
| 8019 | if (jobctl) | 7995 | if (jobctl) |
| 8020 | showjobs(stderr, SHOW_CHANGED); | 7996 | showjobs(stderr, SHOW_CHANGED); |
| @@ -8037,17 +8013,21 @@ cmdloop(int top) | |||
| 8037 | out2str("\nUse \"exit\" to leave shell.\n"); | 8013 | out2str("\nUse \"exit\" to leave shell.\n"); |
| 8038 | } | 8014 | } |
| 8039 | numeof++; | 8015 | numeof++; |
| 8040 | } else if (n != NULL && nflag == 0) { | 8016 | } else if (nflag == 0) { |
| 8041 | job_warning = (job_warning == 2) ? 1 : 0; | 8017 | job_warning = (job_warning == 2) ? 1 : 0; |
| 8042 | numeof = 0; | 8018 | numeof = 0; |
| 8043 | evaltree(n, 0); | 8019 | evaltree(n, 0); |
| 8044 | } | 8020 | } |
| 8045 | popstackmark(&smark); | 8021 | popstackmark(&smark); |
| 8046 | if (evalskip) { | 8022 | skip = evalskip; |
| 8023 | |||
| 8024 | if (skip) { | ||
| 8047 | evalskip = 0; | 8025 | evalskip = 0; |
| 8048 | break; | 8026 | return skip & SKIPEVAL; |
| 8049 | } | 8027 | } |
| 8050 | } | 8028 | } |
| 8029 | |||
| 8030 | return 0; | ||
| 8051 | } | 8031 | } |
| 8052 | 8032 | ||
| 8053 | 8033 | ||
| @@ -8058,31 +8038,16 @@ cmdloop(int top) | |||
| 8058 | static void | 8038 | static void |
| 8059 | read_profile(const char *name) | 8039 | read_profile(const char *name) |
| 8060 | { | 8040 | { |
| 8061 | int fd; | 8041 | int skip; |
| 8062 | int xflag_set = 0; | ||
| 8063 | int vflag_set = 0; | ||
| 8064 | 8042 | ||
| 8065 | INTOFF; | 8043 | if (setinputfile(name, INPUT_PUSH_FILE | INPUT_NOFILE_OK) < 0) |
| 8066 | if ((fd = open(name, O_RDONLY)) >= 0) | ||
| 8067 | setinputfd(fd, 1); | ||
| 8068 | INTON; | ||
| 8069 | if (fd < 0) | ||
| 8070 | return; | 8044 | return; |
| 8071 | /* -q turns off -x and -v just when executing init files */ | 8045 | |
| 8072 | if (qflag) { | 8046 | skip = cmdloop(0); |
| 8073 | if (xflag) | ||
| 8074 | xflag = 0, xflag_set = 1; | ||
| 8075 | if (vflag) | ||
| 8076 | vflag = 0, vflag_set = 1; | ||
| 8077 | } | ||
| 8078 | cmdloop(0); | ||
| 8079 | if (qflag) { | ||
| 8080 | if (xflag_set) | ||
| 8081 | xflag = 1; | ||
| 8082 | if (vflag_set) | ||
| 8083 | vflag = 1; | ||
| 8084 | } | ||
| 8085 | popfile(); | 8047 | popfile(); |
| 8048 | |||
| 8049 | if (skip) | ||
| 8050 | exitshell(); | ||
| 8086 | } | 8051 | } |
| 8087 | 8052 | ||
| 8088 | 8053 | ||
| @@ -8093,14 +8058,7 @@ read_profile(const char *name) | |||
| 8093 | static void | 8058 | static void |
| 8094 | readcmdfile(char *name) | 8059 | readcmdfile(char *name) |
| 8095 | { | 8060 | { |
| 8096 | int fd; | 8061 | setinputfile(name, INPUT_PUSH_FILE); |
| 8097 | |||
| 8098 | INTOFF; | ||
| 8099 | if ((fd = open(name, O_RDONLY)) >= 0) | ||
| 8100 | setinputfd(fd, 1); | ||
| 8101 | else | ||
| 8102 | error("Can't open %s", name); | ||
| 8103 | INTON; | ||
| 8104 | cmdloop(0); | 8062 | cmdloop(0); |
| 8105 | popfile(); | 8063 | popfile(); |
| 8106 | } | 8064 | } |
| @@ -8134,7 +8092,7 @@ find_dot_file(char *name) | |||
| 8134 | } | 8092 | } |
| 8135 | 8093 | ||
| 8136 | /* not found in the PATH */ | 8094 | /* not found in the PATH */ |
| 8137 | error(not_found_msg, name); | 8095 | sh_error(not_found_msg, name); |
| 8138 | /* NOTREACHED */ | 8096 | /* NOTREACHED */ |
| 8139 | } | 8097 | } |
| 8140 | 8098 | ||
| @@ -8142,17 +8100,14 @@ static int dotcmd(int argc, char **argv) | |||
| 8142 | { | 8100 | { |
| 8143 | struct strlist *sp; | 8101 | struct strlist *sp; |
| 8144 | volatile struct shparam saveparam; | 8102 | volatile struct shparam saveparam; |
| 8145 | 8103 | int status = 0; | |
| 8146 | exitstatus = 0; | ||
| 8147 | 8104 | ||
| 8148 | for (sp = cmdenviron; sp; sp = sp->next) | 8105 | for (sp = cmdenviron; sp; sp = sp->next) |
| 8149 | setvareq(bb_xstrdup(sp->text), VSTRFIXED | VTEXTFIXED); | 8106 | setvareq(bb_xstrdup(sp->text), VSTRFIXED | VTEXTFIXED); |
| 8150 | 8107 | ||
| 8151 | if (argc >= 2) { /* That's what SVR2 does */ | 8108 | if (argc >= 2) { /* That's what SVR2 does */ |
| 8152 | char *fullname; | 8109 | char *fullname; |
| 8153 | struct stackmark smark; | ||
| 8154 | 8110 | ||
| 8155 | setstackmark(&smark); | ||
| 8156 | fullname = find_dot_file(argv[1]); | 8111 | fullname = find_dot_file(argv[1]); |
| 8157 | 8112 | ||
| 8158 | if (argc > 2) { | 8113 | if (argc > 2) { |
| @@ -8162,7 +8117,7 @@ static int dotcmd(int argc, char **argv) | |||
| 8162 | shellparam.p = argv + 2; | 8117 | shellparam.p = argv + 2; |
| 8163 | }; | 8118 | }; |
| 8164 | 8119 | ||
| 8165 | setinputfile(fullname, 1); | 8120 | setinputfile(fullname, INPUT_PUSH_FILE); |
| 8166 | commandname = fullname; | 8121 | commandname = fullname; |
| 8167 | cmdloop(0); | 8122 | cmdloop(0); |
| 8168 | popfile(); | 8123 | popfile(); |
| @@ -8171,10 +8126,9 @@ static int dotcmd(int argc, char **argv) | |||
| 8171 | freeparam(&shellparam); | 8126 | freeparam(&shellparam); |
| 8172 | shellparam = saveparam; | 8127 | shellparam = saveparam; |
| 8173 | }; | 8128 | }; |
| 8174 | 8129 | status = exitstatus; | |
| 8175 | popstackmark(&smark); | ||
| 8176 | } | 8130 | } |
| 8177 | return exitstatus; | 8131 | return status; |
| 8178 | } | 8132 | } |
| 8179 | 8133 | ||
| 8180 | 8134 | ||
| @@ -8196,7 +8150,7 @@ echocmd(int argc, char **argv) | |||
| 8196 | return bb_echo(argc, argv); | 8150 | return bb_echo(argc, argv); |
| 8197 | } | 8151 | } |
| 8198 | #endif | 8152 | #endif |
| 8199 | /* $NetBSD: memalloc.c,v 1.27 2003/01/22 20:36:04 dsl Exp $ */ | 8153 | /* memalloc.c */ |
| 8200 | 8154 | ||
| 8201 | /* | 8155 | /* |
| 8202 | * Same for malloc, realloc, but returns an error when out of space. | 8156 | * Same for malloc, realloc, but returns an error when out of space. |
| @@ -8207,7 +8161,7 @@ ckrealloc(pointer p, size_t nbytes) | |||
| 8207 | { | 8161 | { |
| 8208 | p = realloc(p, nbytes); | 8162 | p = realloc(p, nbytes); |
| 8209 | if (p == NULL) | 8163 | if (p == NULL) |
| 8210 | error(bb_msg_memory_exhausted); | 8164 | sh_error(bb_msg_memory_exhausted); |
| 8211 | return p; | 8165 | return p; |
| 8212 | } | 8166 | } |
| 8213 | 8167 | ||
| @@ -8226,7 +8180,7 @@ savestr(const char *s) | |||
| 8226 | { | 8180 | { |
| 8227 | char *p = strdup(s); | 8181 | char *p = strdup(s); |
| 8228 | if (!p) | 8182 | if (!p) |
| 8229 | error(bb_msg_memory_exhausted); | 8183 | sh_error(bb_msg_memory_exhausted); |
| 8230 | return p; | 8184 | return p; |
| 8231 | } | 8185 | } |
| 8232 | 8186 | ||
| @@ -8258,7 +8212,7 @@ stalloc(size_t nbytes) | |||
| 8258 | blocksize = MINSIZE; | 8212 | blocksize = MINSIZE; |
| 8259 | len = sizeof(struct stack_block) - MINSIZE + blocksize; | 8213 | len = sizeof(struct stack_block) - MINSIZE + blocksize; |
| 8260 | if (len < blocksize) | 8214 | if (len < blocksize) |
| 8261 | error(bb_msg_memory_exhausted); | 8215 | sh_error(bb_msg_memory_exhausted); |
| 8262 | INTOFF; | 8216 | INTOFF; |
| 8263 | sp = ckmalloc(len); | 8217 | sp = ckmalloc(len); |
| 8264 | sp->prev = stackp; | 8218 | sp->prev = stackp; |
| @@ -8336,7 +8290,7 @@ growstackblock(void) | |||
| 8336 | 8290 | ||
| 8337 | newlen = stacknleft * 2; | 8291 | newlen = stacknleft * 2; |
| 8338 | if (newlen < stacknleft) | 8292 | if (newlen < stacknleft) |
| 8339 | error(bb_msg_memory_exhausted); | 8293 | sh_error(bb_msg_memory_exhausted); |
| 8340 | if (newlen < 128) | 8294 | if (newlen < 128) |
| 8341 | newlen += 128; | 8295 | newlen += 128; |
| 8342 | 8296 | ||
| @@ -8456,7 +8410,7 @@ stputs(const char *s, char *p) | |||
| 8456 | return stnputs(s, strlen(s), p); | 8410 | return stnputs(s, strlen(s), p); |
| 8457 | } | 8411 | } |
| 8458 | 8412 | ||
| 8459 | /* $NetBSD: mystring.c,v 1.15 2002/11/24 22:35:42 christos Exp $ */ | 8413 | /* mystring.c */ |
| 8460 | 8414 | ||
| 8461 | /* | 8415 | /* |
| 8462 | * String functions. | 8416 | * String functions. |
| @@ -8490,7 +8444,7 @@ number(const char *s) | |||
| 8490 | { | 8444 | { |
| 8491 | 8445 | ||
| 8492 | if (! is_number(s)) | 8446 | if (! is_number(s)) |
| 8493 | error(illnum, s); | 8447 | sh_error(illnum, s); |
| 8494 | return atoi(s); | 8448 | return atoi(s); |
| 8495 | } | 8449 | } |
| 8496 | 8450 | ||
| @@ -8815,7 +8769,7 @@ procargs(int argc, char **argv) | |||
| 8815 | xminusc = minusc; | 8769 | xminusc = minusc; |
| 8816 | if (*xargv == NULL) { | 8770 | if (*xargv == NULL) { |
| 8817 | if (xminusc) | 8771 | if (xminusc) |
| 8818 | error("-c requires an argument"); | 8772 | sh_error("-c requires an argument"); |
| 8819 | sflag = 1; | 8773 | sflag = 1; |
| 8820 | } | 8774 | } |
| 8821 | if (iflag == 2 && sflag == 1 && isatty(0) && isatty(1)) | 8775 | if (iflag == 2 && sflag == 1 && isatty(0) && isatty(1)) |
| @@ -8881,7 +8835,7 @@ minus_o(char *name, int val) | |||
| 8881 | optlist[i] = val; | 8835 | optlist[i] = val; |
| 8882 | return; | 8836 | return; |
| 8883 | } | 8837 | } |
| 8884 | error("Illegal option -o %s", name); | 8838 | sh_error("Illegal option -o %s", name); |
| 8885 | } | 8839 | } |
| 8886 | } | 8840 | } |
| 8887 | 8841 | ||
| @@ -8949,7 +8903,7 @@ setoption(int flag, int val) | |||
| 8949 | optlist[i] = val; | 8903 | optlist[i] = val; |
| 8950 | return; | 8904 | return; |
| 8951 | } | 8905 | } |
| 8952 | error("Illegal option -%c", flag); | 8906 | sh_error("Illegal option -%c", flag); |
| 8953 | /* NOTREACHED */ | 8907 | /* NOTREACHED */ |
| 8954 | } | 8908 | } |
| 8955 | 8909 | ||
| @@ -9015,7 +8969,7 @@ shiftcmd(int argc, char **argv) | |||
| 9015 | if (argc > 1) | 8969 | if (argc > 1) |
| 9016 | n = number(argv[1]); | 8970 | n = number(argv[1]); |
| 9017 | if (n > shellparam.nparam) | 8971 | if (n > shellparam.nparam) |
| 9018 | error("can't shift that many"); | 8972 | sh_error("can't shift that many"); |
| 9019 | INTOFF; | 8973 | INTOFF; |
| 9020 | shellparam.nparam -= n; | 8974 | shellparam.nparam -= n; |
| 9021 | for (ap1 = shellparam.p ; --n >= 0 ; ap1++) { | 8975 | for (ap1 = shellparam.p ; --n >= 0 ; ap1++) { |
| @@ -9203,7 +9157,7 @@ getoptscmd(int argc, char **argv) | |||
| 9203 | char **optbase; | 9157 | char **optbase; |
| 9204 | 9158 | ||
| 9205 | if (argc < 3) | 9159 | if (argc < 3) |
| 9206 | error("Usage: getopts optstring var [arg]"); | 9160 | sh_error("Usage: getopts optstring var [arg]"); |
| 9207 | else if (argc == 3) { | 9161 | else if (argc == 3) { |
| 9208 | optbase = shellparam.p; | 9162 | optbase = shellparam.p; |
| 9209 | if (shellparam.optind > shellparam.nparam + 1) { | 9163 | if (shellparam.optind > shellparam.nparam + 1) { |
| @@ -9253,13 +9207,13 @@ nextopt(const char *optstring) | |||
| 9253 | c = *p++; | 9207 | c = *p++; |
| 9254 | for (q = optstring ; *q != c ; ) { | 9208 | for (q = optstring ; *q != c ; ) { |
| 9255 | if (*q == '\0') | 9209 | if (*q == '\0') |
| 9256 | error("Illegal option -%c", c); | 9210 | sh_error("Illegal option -%c", c); |
| 9257 | if (*++q == ':') | 9211 | if (*++q == ':') |
| 9258 | q++; | 9212 | q++; |
| 9259 | } | 9213 | } |
| 9260 | if (*++q == ':') { | 9214 | if (*++q == ':') { |
| 9261 | if (*p == '\0' && (p = *argptr++) == NULL) | 9215 | if (*p == '\0' && (p = *argptr++) == NULL) |
| 9262 | error("No arg for -%c option", c); | 9216 | sh_error("No arg for -%c option", c); |
| 9263 | optionarg = p; | 9217 | optionarg = p; |
| 9264 | p = NULL; | 9218 | p = NULL; |
| 9265 | } | 9219 | } |
| @@ -9268,7 +9222,7 @@ nextopt(const char *optstring) | |||
| 9268 | } | 9222 | } |
| 9269 | 9223 | ||
| 9270 | 9224 | ||
| 9271 | /* $NetBSD: output.c,v 1.27 2002/11/24 22:35:42 christos Exp $ */ | 9225 | /* output.c */ |
| 9272 | 9226 | ||
| 9273 | void | 9227 | void |
| 9274 | outstr(const char *p, FILE *file) | 9228 | outstr(const char *p, FILE *file) |
| @@ -9336,7 +9290,7 @@ fmtstr(char *outbuf, size_t length, const char *fmt, ...) | |||
| 9336 | 9290 | ||
| 9337 | 9291 | ||
| 9338 | 9292 | ||
| 9339 | /* $NetBSD: parser.c,v 1.54 2002/11/24 22:35:42 christos Exp $ */ | 9293 | /* parser.c */ |
| 9340 | 9294 | ||
| 9341 | 9295 | ||
| 9342 | /* | 9296 | /* |
| @@ -10855,7 +10809,7 @@ static void synexpect(int token) | |||
| 10855 | static void | 10809 | static void |
| 10856 | synerror(const char *msg) | 10810 | synerror(const char *msg) |
| 10857 | { | 10811 | { |
| 10858 | error("Syntax error: %s", msg); | 10812 | sh_error("Syntax error: %s", msg); |
| 10859 | /* NOTREACHED */ | 10813 | /* NOTREACHED */ |
| 10860 | } | 10814 | } |
| 10861 | 10815 | ||
| @@ -10923,7 +10877,7 @@ static const char *const *findkwd(const char *s) | |||
| 10923 | sizeof(const char *), pstrcmp); | 10877 | sizeof(const char *), pstrcmp); |
| 10924 | } | 10878 | } |
| 10925 | 10879 | ||
| 10926 | /* $NetBSD: redir.c,v 1.27 2002/11/24 22:35:42 christos Exp $ */ | 10880 | /* redir.c */ |
| 10927 | 10881 | ||
| 10928 | /* | 10882 | /* |
| 10929 | * Code for dealing with input/output redirection. | 10883 | * Code for dealing with input/output redirection. |
| @@ -11007,7 +10961,7 @@ openhere(union node *redir) | |||
| 11007 | size_t len = 0; | 10961 | size_t len = 0; |
| 11008 | 10962 | ||
| 11009 | if (pipe(pip) < 0) | 10963 | if (pipe(pip) < 0) |
| 11010 | error("Pipe call failed"); | 10964 | sh_error("Pipe call failed"); |
| 11011 | if (redir->type == NHERE) { | 10965 | if (redir->type == NHERE) { |
| 11012 | len = strlen(redir->nhere.doc->narg.text); | 10966 | len = strlen(redir->nhere.doc->narg.text); |
| 11013 | if (len <= PIPESIZE) { | 10967 | if (len <= PIPESIZE) { |
| @@ -11088,9 +11042,9 @@ openredirect(union node *redir) | |||
| 11088 | 11042 | ||
| 11089 | return f; | 11043 | return f; |
| 11090 | ecreate: | 11044 | ecreate: |
| 11091 | error("cannot create %s: %s", fname, errmsg(errno, E_CREAT)); | 11045 | sh_error("cannot create %s: %s", fname, errmsg(errno, E_CREAT)); |
| 11092 | eopen: | 11046 | eopen: |
| 11093 | error("cannot open %s: %s", fname, errmsg(errno, E_OPEN)); | 11047 | sh_error("cannot open %s: %s", fname, errmsg(errno, E_OPEN)); |
| 11094 | } | 11048 | } |
| 11095 | 11049 | ||
| 11096 | static inline void | 11050 | static inline void |
| @@ -11164,7 +11118,7 @@ redirect(union node *redir, int flags) | |||
| 11164 | if (i != EBADF) { | 11118 | if (i != EBADF) { |
| 11165 | close(newfd); | 11119 | close(newfd); |
| 11166 | errno = i; | 11120 | errno = i; |
| 11167 | error("%d: %m", fd); | 11121 | sh_error("%d: %m", fd); |
| 11168 | /* NOTREACHED */ | 11122 | /* NOTREACHED */ |
| 11169 | } | 11123 | } |
| 11170 | } else { | 11124 | } else { |
| @@ -11247,7 +11201,7 @@ copyfd(int from, int to) | |||
| 11247 | if (errno == EMFILE) | 11201 | if (errno == EMFILE) |
| 11248 | return EMPTY; | 11202 | return EMPTY; |
| 11249 | else | 11203 | else |
| 11250 | error("%d: %m", from); | 11204 | sh_error("%d: %m", from); |
| 11251 | } | 11205 | } |
| 11252 | return newfd; | 11206 | return newfd; |
| 11253 | } | 11207 | } |
| @@ -11273,7 +11227,7 @@ redirectsafe(union node *redir, int flags) | |||
| 11273 | return err; | 11227 | return err; |
| 11274 | } | 11228 | } |
| 11275 | 11229 | ||
| 11276 | /* $NetBSD: show.c,v 1.24 2003/01/22 20:36:04 dsl Exp $ */ | 11230 | /* show.c */ |
| 11277 | 11231 | ||
| 11278 | #ifdef DEBUG | 11232 | #ifdef DEBUG |
| 11279 | static void shtree(union node *, int, char *, FILE*); | 11233 | static void shtree(union node *, int, char *, FILE*); |
| @@ -11620,7 +11574,7 @@ opentrace(void) | |||
| 11620 | #endif /* DEBUG */ | 11574 | #endif /* DEBUG */ |
| 11621 | 11575 | ||
| 11622 | 11576 | ||
| 11623 | /* $NetBSD: trap.c,v 1.28 2002/11/24 22:35:43 christos Exp $ */ | 11577 | /* trap.c */ |
| 11624 | 11578 | ||
| 11625 | /* | 11579 | /* |
| 11626 | * Sigmode records the current value of the signal handlers for the various | 11580 | * Sigmode records the current value of the signal handlers for the various |
| @@ -11669,7 +11623,7 @@ trapcmd(int argc, char **argv) | |||
| 11669 | action = *ap++; | 11623 | action = *ap++; |
| 11670 | while (*ap) { | 11624 | while (*ap) { |
| 11671 | if ((signo = decode_signal(*ap, 0)) < 0) | 11625 | if ((signo = decode_signal(*ap, 0)) < 0) |
| 11672 | error("%s: bad trap", *ap); | 11626 | sh_error("%s: bad trap", *ap); |
| 11673 | INTOFF; | 11627 | INTOFF; |
| 11674 | if (action) { | 11628 | if (action) { |
| 11675 | if (action[0] == '-' && action[1] == '\0') | 11629 | if (action[0] == '-' && action[1] == '\0') |
| @@ -11834,23 +11788,34 @@ onsig(int signo) | |||
| 11834 | * handlers while we are executing a trap handler. | 11788 | * handlers while we are executing a trap handler. |
| 11835 | */ | 11789 | */ |
| 11836 | 11790 | ||
| 11837 | void | 11791 | int |
| 11838 | dotrap(void) | 11792 | dotrap(void) |
| 11839 | { | 11793 | { |
| 11840 | char *p; | 11794 | char *p; |
| 11841 | char *q; | 11795 | char *q; |
| 11796 | int i; | ||
| 11842 | int savestatus; | 11797 | int savestatus; |
| 11798 | int skip = 0; | ||
| 11843 | 11799 | ||
| 11844 | savestatus = exitstatus; | 11800 | savestatus = exitstatus; |
| 11845 | q = gotsig; | 11801 | pendingsigs = 0; |
| 11846 | while (pendingsigs = 0, xbarrier(), (p = memchr(q, 1, NSIG - 1))) { | 11802 | xbarrier(); |
| 11847 | *p = 0; | 11803 | |
| 11848 | p = trap[p - q + 1]; | 11804 | for (i = 0, q = gotsig; i < NSIG - 1; i++, q++) { |
| 11805 | if (!*q) | ||
| 11806 | continue; | ||
| 11807 | *q = 0; | ||
| 11808 | |||
| 11809 | p = trap[i + 1]; | ||
| 11849 | if (!p) | 11810 | if (!p) |
| 11850 | continue; | 11811 | continue; |
| 11851 | evalstring(p); | 11812 | skip = evalstring(p, SKIPEVAL); |
| 11852 | exitstatus = savestatus; | 11813 | exitstatus = savestatus; |
| 11814 | if (skip) | ||
| 11815 | break; | ||
| 11853 | } | 11816 | } |
| 11817 | |||
| 11818 | return skip; | ||
| 11854 | } | 11819 | } |
| 11855 | 11820 | ||
| 11856 | 11821 | ||
| @@ -11931,17 +11896,18 @@ exitshell(void) | |||
| 11931 | struct jmploc loc; | 11896 | struct jmploc loc; |
| 11932 | char *p; | 11897 | char *p; |
| 11933 | int status; | 11898 | int status; |
| 11934 | int jmp; | ||
| 11935 | 11899 | ||
| 11936 | jmp = setjmp(loc.loc); | ||
| 11937 | status = exitstatus; | 11900 | status = exitstatus; |
| 11938 | TRACE(("pid %d, exitshell(%d)\n", getpid(), status)); | 11901 | TRACE(("pid %d, exitshell(%d)\n", getpid(), status)); |
| 11939 | if (jmp) | 11902 | if (setjmp(loc.loc)) { |
| 11903 | if (exception == EXEXIT) | ||
| 11904 | _exit(exitstatus); | ||
| 11940 | goto out; | 11905 | goto out; |
| 11906 | } | ||
| 11941 | handler = &loc; | 11907 | handler = &loc; |
| 11942 | if ((p = trap[0]) != NULL && *p != '\0') { | 11908 | if ((p = trap[0])) { |
| 11943 | trap[0] = NULL; | 11909 | trap[0] = NULL; |
| 11944 | evalstring(p); | 11910 | evalstring(p, 0); |
| 11945 | } | 11911 | } |
| 11946 | flushall(); | 11912 | flushall(); |
| 11947 | setjobctl(0); | 11913 | setjobctl(0); |
| @@ -11966,7 +11932,7 @@ static int decode_signal(const char *string, int minsig) | |||
| 11966 | return name ? signo : -1; | 11932 | return name ? signo : -1; |
| 11967 | } | 11933 | } |
| 11968 | 11934 | ||
| 11969 | /* $NetBSD: var.c,v 1.32 2003/01/22 20:36:04 dsl Exp $ */ | 11935 | /* var.c */ |
| 11970 | 11936 | ||
| 11971 | static struct var *vartab[VTABSIZE]; | 11937 | static struct var *vartab[VTABSIZE]; |
| 11972 | 11938 | ||
| @@ -12022,7 +11988,7 @@ setvar(const char *name, const char *val, int flags) | |||
| 12022 | p = strchrnul(q, '='); | 11988 | p = strchrnul(q, '='); |
| 12023 | namelen = p - name; | 11989 | namelen = p - name; |
| 12024 | if (!namelen || p != q) | 11990 | if (!namelen || p != q) |
| 12025 | error("%.*s: bad variable name", namelen, name); | 11991 | sh_error("%.*s: bad variable name", namelen, name); |
| 12026 | vallen = 0; | 11992 | vallen = 0; |
| 12027 | if (val == NULL) { | 11993 | if (val == NULL) { |
| 12028 | flags |= VUNSET; | 11994 | flags |= VUNSET; |
| @@ -12031,9 +11997,8 @@ setvar(const char *name, const char *val, int flags) | |||
| 12031 | } | 11997 | } |
| 12032 | INTOFF; | 11998 | INTOFF; |
| 12033 | p = mempcpy(nameeq = ckmalloc(namelen + vallen + 2), name, namelen); | 11999 | p = mempcpy(nameeq = ckmalloc(namelen + vallen + 2), name, namelen); |
| 12034 | *p++ = '\0'; | ||
| 12035 | if (val) { | 12000 | if (val) { |
| 12036 | p[-1] = '='; | 12001 | *p++ = '='; |
| 12037 | p = mempcpy(p, val, vallen); | 12002 | p = mempcpy(p, val, vallen); |
| 12038 | } | 12003 | } |
| 12039 | *p = '\0'; | 12004 | *p = '\0'; |
| @@ -12065,7 +12030,7 @@ setvareq(char *s, int flags) | |||
| 12065 | if (flags & VNOSAVE) | 12030 | if (flags & VNOSAVE) |
| 12066 | free(s); | 12031 | free(s); |
| 12067 | n = vp->text; | 12032 | n = vp->text; |
| 12068 | error("%.*s: is read only", strchrnul(n, '=') - n, n); | 12033 | sh_error("%.*s: is read only", strchrnul(n, '=') - n, n); |
| 12069 | } | 12034 | } |
| 12070 | 12035 | ||
| 12071 | if (flags & VNOSET) | 12036 | if (flags & VNOSET) |
| @@ -12495,7 +12460,7 @@ findvar(struct var **vpp, const char *name) | |||
| 12495 | } | 12460 | } |
| 12496 | return vpp; | 12461 | return vpp; |
| 12497 | } | 12462 | } |
| 12498 | /* $NetBSD: setmode.c,v 1.29 2003/01/15 23:58:03 kleink Exp $ */ | 12463 | /* setmode.c */ |
| 12499 | 12464 | ||
| 12500 | #include <sys/times.h> | 12465 | #include <sys/times.h> |
| 12501 | 12466 | ||
| @@ -12540,11 +12505,11 @@ dash_arith(const char *s) | |||
| 12540 | result = arith(s, &errcode); | 12505 | result = arith(s, &errcode); |
| 12541 | if (errcode < 0) { | 12506 | if (errcode < 0) { |
| 12542 | if (errcode == -3) | 12507 | if (errcode == -3) |
| 12543 | error("exponent less than 0"); | 12508 | sh_error("exponent less than 0"); |
| 12544 | else if (errcode == -2) | 12509 | else if (errcode == -2) |
| 12545 | error("divide by zero"); | 12510 | sh_error("divide by zero"); |
| 12546 | else if (errcode == -5) | 12511 | else if (errcode == -5) |
| 12547 | error("expression recursion loop detected"); | 12512 | sh_error("expression recursion loop detected"); |
| 12548 | else | 12513 | else |
| 12549 | synerror(s); | 12514 | synerror(s); |
| 12550 | } | 12515 | } |
| @@ -12569,7 +12534,7 @@ letcmd(int argc, char **argv) | |||
| 12569 | 12534 | ||
| 12570 | ap = argv + 1; | 12535 | ap = argv + 1; |
| 12571 | if(!*ap) | 12536 | if(!*ap) |
| 12572 | error("expression expected"); | 12537 | sh_error("expression expected"); |
| 12573 | for (ap = argv + 1; *ap; ap++) { | 12538 | for (ap = argv + 1; *ap; ap++) { |
| 12574 | i = dash_arith(*ap); | 12539 | i = dash_arith(*ap); |
| 12575 | } | 12540 | } |
| @@ -12578,7 +12543,7 @@ letcmd(int argc, char **argv) | |||
| 12578 | } | 12543 | } |
| 12579 | #endif /* CONFIG_ASH_MATH_SUPPORT */ | 12544 | #endif /* CONFIG_ASH_MATH_SUPPORT */ |
| 12580 | 12545 | ||
| 12581 | /* $NetBSD: miscbltin.c,v 1.31 2002/11/24 22:35:41 christos Exp $ */ | 12546 | /* miscbltin.c */ |
| 12582 | 12547 | ||
| 12583 | /* | 12548 | /* |
| 12584 | * Miscellaneous builtins. | 12549 | * Miscellaneous builtins. |
| @@ -12646,7 +12611,7 @@ readcmd(int argc, char **argv) | |||
| 12646 | case 'n': | 12611 | case 'n': |
| 12647 | nchars = strtol(optionarg, &p, 10); | 12612 | nchars = strtol(optionarg, &p, 10); |
| 12648 | if (*p) | 12613 | if (*p) |
| 12649 | error("invalid count"); | 12614 | sh_error("invalid count"); |
| 12650 | nch_flag = (nchars > 0); | 12615 | nch_flag = (nchars > 0); |
| 12651 | break; | 12616 | break; |
| 12652 | case 's': | 12617 | case 's': |
| @@ -12663,19 +12628,19 @@ readcmd(int argc, char **argv) | |||
| 12663 | int scale; | 12628 | int scale; |
| 12664 | ts.tv_usec = strtol(p, &p2, 10); | 12629 | ts.tv_usec = strtol(p, &p2, 10); |
| 12665 | if (*p2) | 12630 | if (*p2) |
| 12666 | error("invalid timeout"); | 12631 | sh_error("invalid timeout"); |
| 12667 | scale = p2 - p; | 12632 | scale = p2 - p; |
| 12668 | /* normalize to usec */ | 12633 | /* normalize to usec */ |
| 12669 | if (scale > 6) | 12634 | if (scale > 6) |
| 12670 | error("invalid timeout"); | 12635 | sh_error("invalid timeout"); |
| 12671 | while (scale++ < 6) | 12636 | while (scale++ < 6) |
| 12672 | ts.tv_usec *= 10; | 12637 | ts.tv_usec *= 10; |
| 12673 | } | 12638 | } |
| 12674 | } else if (*p) { | 12639 | } else if (*p) { |
| 12675 | error("invalid timeout"); | 12640 | sh_error("invalid timeout"); |
| 12676 | } | 12641 | } |
| 12677 | if ( ! ts.tv_sec && ! ts.tv_usec) | 12642 | if ( ! ts.tv_sec && ! ts.tv_usec) |
| 12678 | error("invalid timeout"); | 12643 | sh_error("invalid timeout"); |
| 12679 | break; | 12644 | break; |
| 12680 | #endif | 12645 | #endif |
| 12681 | case 'r': | 12646 | case 'r': |
| @@ -12689,7 +12654,7 @@ readcmd(int argc, char **argv) | |||
| 12689 | out2str(prompt); | 12654 | out2str(prompt); |
| 12690 | } | 12655 | } |
| 12691 | if (*(ap = argptr) == NULL) | 12656 | if (*(ap = argptr) == NULL) |
| 12692 | error("arg count"); | 12657 | sh_error("arg count"); |
| 12693 | if ((ifs = bltinlookup("IFS")) == NULL) | 12658 | if ((ifs = bltinlookup("IFS")) == NULL) |
| 12694 | ifs = defifs; | 12659 | ifs = defifs; |
| 12695 | #if defined(CONFIG_ASH_READ_NCHARS) | 12660 | #if defined(CONFIG_ASH_READ_NCHARS) |
| @@ -12832,14 +12797,14 @@ static int umaskcmd(int argc, char **argv) | |||
| 12832 | mask = 0; | 12797 | mask = 0; |
| 12833 | do { | 12798 | do { |
| 12834 | if (*ap >= '8' || *ap < '0') | 12799 | if (*ap >= '8' || *ap < '0') |
| 12835 | error(illnum, argv[1]); | 12800 | sh_error(illnum, argv[1]); |
| 12836 | mask = (mask << 3) + (*ap - '0'); | 12801 | mask = (mask << 3) + (*ap - '0'); |
| 12837 | } while (*++ap != '\0'); | 12802 | } while (*++ap != '\0'); |
| 12838 | umask(mask); | 12803 | umask(mask); |
| 12839 | } else { | 12804 | } else { |
| 12840 | mask = ~mask & 0777; | 12805 | mask = ~mask & 0777; |
| 12841 | if (!bb_parse_mode(ap, &mask)) { | 12806 | if (!bb_parse_mode(ap, &mask)) { |
| 12842 | error("Illegal mode: %s", ap); | 12807 | sh_error("Illegal mode: %s", ap); |
| 12843 | } | 12808 | } |
| 12844 | umask(~mask & 0777); | 12809 | umask(~mask & 0777); |
| 12845 | } | 12810 | } |
| @@ -12989,7 +12954,7 @@ ulimitcmd(int argc, char **argv) | |||
| 12989 | char *p = *argptr; | 12954 | char *p = *argptr; |
| 12990 | 12955 | ||
| 12991 | if (all || argptr[1]) | 12956 | if (all || argptr[1]) |
| 12992 | error("too many arguments"); | 12957 | sh_error("too many arguments"); |
| 12993 | if (strncmp(p, "unlimited\n", 9) == 0) | 12958 | if (strncmp(p, "unlimited\n", 9) == 0) |
| 12994 | val = RLIM_INFINITY; | 12959 | val = RLIM_INFINITY; |
| 12995 | else { | 12960 | else { |
| @@ -13002,7 +12967,7 @@ ulimitcmd(int argc, char **argv) | |||
| 13002 | break; | 12967 | break; |
| 13003 | } | 12968 | } |
| 13004 | if (c) | 12969 | if (c) |
| 13005 | error("bad number"); | 12970 | sh_error("bad number"); |
| 13006 | val *= l->factor; | 12971 | val *= l->factor; |
| 13007 | } | 12972 | } |
| 13008 | } | 12973 | } |
| @@ -13022,7 +12987,7 @@ ulimitcmd(int argc, char **argv) | |||
| 13022 | if (how & SOFT) | 12987 | if (how & SOFT) |
| 13023 | limit.rlim_cur = val; | 12988 | limit.rlim_cur = val; |
| 13024 | if (setrlimit(l->cmd, &limit) < 0) | 12989 | if (setrlimit(l->cmd, &limit) < 0) |
| 13025 | error("error setting limit (%m)"); | 12990 | sh_error("error setting limit (%m)"); |
| 13026 | } else { | 12991 | } else { |
| 13027 | printlim(how, &limit, l); | 12992 | printlim(how, &limit, l); |
| 13028 | } | 12993 | } |
