diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-02-19 22:43:01 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-02-19 22:43:01 +0000 |
| commit | b012b10dbd1d0a476de8674e195eb008e505e608 (patch) | |
| tree | f74c91ae2b86de78c148cb6288baa1a23d288b49 /shell | |
| parent | e5570da2cffbec12b99d99a11d20c5f2371d5b0f (diff) | |
| download | busybox-w32-b012b10dbd1d0a476de8674e195eb008e505e608.tar.gz busybox-w32-b012b10dbd1d0a476de8674e195eb008e505e608.tar.bz2 busybox-w32-b012b10dbd1d0a476de8674e195eb008e505e608.zip | |
ash: rearrange code to reduce forward references, rename some functions
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/ash.c | 1225 |
1 files changed, 568 insertions, 657 deletions
diff --git a/shell/ash.c b/shell/ash.c index 242e3b765..ffe29e066 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -31,7 +31,6 @@ | |||
| 31 | * | 31 | * |
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | |||
| 35 | /* | 34 | /* |
| 36 | * The follow should be set to reflect the type of system you have: | 35 | * The follow should be set to reflect the type of system you have: |
| 37 | * JOBS -> 1 if you have Berkeley job control, 0 otherwise. | 36 | * JOBS -> 1 if you have Berkeley job control, 0 otherwise. |
| @@ -43,55 +42,29 @@ | |||
| 43 | * a quit signal will generate a core dump. | 42 | * a quit signal will generate a core dump. |
| 44 | */ | 43 | */ |
| 45 | #define DEBUG 0 | 44 | #define DEBUG 0 |
| 46 | |||
| 47 | |||
| 48 | #define IFS_BROKEN | 45 | #define IFS_BROKEN |
| 49 | |||
| 50 | #define PROFILE 0 | 46 | #define PROFILE 0 |
| 51 | 47 | #if ENABLE_ASH_JOB_CONTROL | |
| 52 | #include "busybox.h" | 48 | #define JOBS 1 |
| 49 | #else | ||
| 50 | #define JOBS 0 | ||
| 51 | #endif | ||
| 53 | 52 | ||
| 54 | #if DEBUG | 53 | #if DEBUG |
| 55 | #define _GNU_SOURCE | 54 | #define _GNU_SOURCE |
| 56 | #endif | 55 | #endif |
| 57 | 56 | #include "busybox.h" | |
| 58 | #include <sys/types.h> | ||
| 59 | #include <sys/ioctl.h> | ||
| 60 | #include <sys/param.h> | ||
| 61 | #include <sys/resource.h> | ||
| 62 | #include <sys/stat.h> | ||
| 63 | #include <sys/wait.h> | ||
| 64 | |||
| 65 | #include <stdio.h> | ||
| 66 | #include <stdlib.h> | ||
| 67 | #include <string.h> | ||
| 68 | #include <unistd.h> | ||
| 69 | |||
| 70 | #include <stdarg.h> | ||
| 71 | #include <stddef.h> | ||
| 72 | #include <assert.h> | ||
| 73 | #include <ctype.h> | ||
| 74 | #include <dirent.h> | ||
| 75 | #include <errno.h> | ||
| 76 | #include <fcntl.h> | ||
| 77 | #include <limits.h> | ||
| 78 | #include <paths.h> | 57 | #include <paths.h> |
| 79 | #include <setjmp.h> | 58 | #include <setjmp.h> |
| 80 | #include <signal.h> | ||
| 81 | /*#include <stdint.h>*/ | ||
| 82 | #include <time.h> | ||
| 83 | #include <fnmatch.h> | 59 | #include <fnmatch.h> |
| 84 | |||
| 85 | #if ENABLE_ASH_JOB_CONTROL | ||
| 86 | #define JOBS 1 | ||
| 87 | #else | ||
| 88 | #define JOBS 0 | ||
| 89 | #endif | ||
| 90 | |||
| 91 | #if JOBS || ENABLE_ASH_READ_NCHARS | 60 | #if JOBS || ENABLE_ASH_READ_NCHARS |
| 92 | #include <termios.h> | 61 | #include <termios.h> |
| 93 | #endif | 62 | #endif |
| 94 | 63 | ||
| 64 | #if defined(__uClinux__) | ||
| 65 | #error "Do not even bother, ash will not run on uClinux" | ||
| 66 | #endif | ||
| 67 | |||
| 95 | 68 | ||
| 96 | #ifdef __GLIBC__ | 69 | #ifdef __GLIBC__ |
| 97 | /* glibc sucks */ | 70 | /* glibc sucks */ |
| @@ -100,59 +73,90 @@ static int *dash_errno; | |||
| 100 | #define errno (*dash_errno) | 73 | #define errno (*dash_errno) |
| 101 | #endif | 74 | #endif |
| 102 | 75 | ||
| 103 | #if defined(__uClinux__) | ||
| 104 | #error "Do not even bother, ash will not run on uClinux" | ||
| 105 | #endif | ||
| 106 | |||
| 107 | #if DEBUG | ||
| 108 | #define _DIAGASSERT(assert_expr) assert(assert_expr) | ||
| 109 | #else | ||
| 110 | #define _DIAGASSERT(assert_expr) | ||
| 111 | #endif | ||
| 112 | |||
| 113 | 76 | ||
| 114 | #if ENABLE_ASH_ALIAS | 77 | #if ENABLE_ASH_ALIAS |
| 115 | /* alias.h */ | 78 | #define ALIASINUSE 1 |
| 116 | 79 | #define ALIASDEAD 2 | |
| 117 | #define ALIASINUSE 1 | ||
| 118 | #define ALIASDEAD 2 | ||
| 119 | |||
| 120 | struct alias { | 80 | struct alias { |
| 121 | struct alias *next; | 81 | struct alias *next; |
| 122 | char *name; | 82 | char *name; |
| 123 | char *val; | 83 | char *val; |
| 124 | int flag; | 84 | int flag; |
| 125 | }; | 85 | }; |
| 126 | |||
| 127 | static struct alias *lookupalias(const char *, int); | ||
| 128 | static int aliascmd(int, char **); | 86 | static int aliascmd(int, char **); |
| 129 | static int unaliascmd(int, char **); | 87 | static int unaliascmd(int, char **); |
| 130 | static void rmaliases(void); | ||
| 131 | static int unalias(const char *); | ||
| 132 | static void printalias(const struct alias *); | 88 | static void printalias(const struct alias *); |
| 133 | #endif | 89 | #endif |
| 134 | 90 | ||
| 135 | /* cd.h */ | ||
| 136 | 91 | ||
| 92 | /* ============ Shell options */ | ||
| 137 | 93 | ||
| 138 | static void setpwd(const char *, int); | 94 | static const char *const optletters_optnames[] = { |
| 95 | "e" "errexit", | ||
| 96 | "f" "noglob", | ||
| 97 | "I" "ignoreeof", | ||
| 98 | "i" "interactive", | ||
| 99 | "m" "monitor", | ||
| 100 | "n" "noexec", | ||
| 101 | "s" "stdin", | ||
| 102 | "x" "xtrace", | ||
| 103 | "v" "verbose", | ||
| 104 | "C" "noclobber", | ||
| 105 | "a" "allexport", | ||
| 106 | "b" "notify", | ||
| 107 | "u" "nounset", | ||
| 108 | "\0" "vi", | ||
| 109 | #if DEBUG | ||
| 110 | "\0" "nolog", | ||
| 111 | "\0" "debug", | ||
| 112 | #endif | ||
| 113 | }; | ||
| 139 | 114 | ||
| 140 | /* error.h */ | 115 | #define optletters(n) optletters_optnames[(n)][0] |
| 116 | #define optnames(n) (&optletters_optnames[(n)][1]) | ||
| 141 | 117 | ||
| 118 | #define NOPTS (sizeof(optletters_optnames)/sizeof(optletters_optnames[0])) | ||
| 142 | 119 | ||
| 143 | /* | 120 | static char optlist[NOPTS]; |
| 144 | * Types of operations (passed to the errmsg routine). | ||
| 145 | */ | ||
| 146 | 121 | ||
| 122 | #define eflag optlist[0] | ||
| 123 | #define fflag optlist[1] | ||
| 124 | #define Iflag optlist[2] | ||
| 125 | #define iflag optlist[3] | ||
| 126 | #define mflag optlist[4] | ||
| 127 | #define nflag optlist[5] | ||
| 128 | #define sflag optlist[6] | ||
| 129 | #define xflag optlist[7] | ||
| 130 | #define vflag optlist[8] | ||
| 131 | #define Cflag optlist[9] | ||
| 132 | #define aflag optlist[10] | ||
| 133 | #define bflag optlist[11] | ||
| 134 | #define uflag optlist[12] | ||
| 135 | #define viflag optlist[13] | ||
| 136 | #if DEBUG | ||
| 137 | #define nolog optlist[14] | ||
| 138 | #define debug optlist[15] | ||
| 139 | #endif | ||
| 147 | 140 | ||
| 148 | static const char not_found_msg[] = "%s: not found"; | ||
| 149 | 141 | ||
| 142 | /* ============ Misc data */ | ||
| 150 | 143 | ||
| 151 | #define E_OPEN "No such file" /* opening a file */ | 144 | /* pid of main shell */ |
| 152 | #define E_CREAT "Directory nonexistent" /* creating a file */ | 145 | static int rootpid; |
| 153 | #define E_EXEC not_found_msg+4 /* executing a program */ | 146 | /* shell level: 0 for the main shell, 1 for its children, and so on */ |
| 147 | static int shlvl; | ||
| 148 | #define rootshell (!shlvl) | ||
| 149 | /* trap handler commands */ | ||
| 150 | static char *trap[NSIG]; | ||
| 151 | /* current value of signal */ | ||
| 152 | static char sigmode[NSIG - 1]; | ||
| 153 | /* indicates specified signal received */ | ||
| 154 | static char gotsig[NSIG - 1]; | ||
| 155 | static char *arg0; /* value of $0 */ | ||
| 154 | 156 | ||
| 155 | /* | 157 | |
| 158 | /* ============ Interrupts / exceptions | ||
| 159 | * | ||
| 156 | * We enclose jmp_buf in a structure so that we can declare pointers to | 160 | * We enclose jmp_buf in a structure so that we can declare pointers to |
| 157 | * jump locations. The global variable handler contains the location to | 161 | * jump locations. The global variable handler contains the location to |
| 158 | * jump to when an exception occurs, and the global variable exception | 162 | * jump to when an exception occurs, and the global variable exception |
| @@ -161,16 +165,11 @@ static const char not_found_msg[] = "%s: not found"; | |||
| 161 | * to an inner scope, set handler to point to a jmploc structure for the | 165 | * to an inner scope, set handler to point to a jmploc structure for the |
| 162 | * inner scope, and restore handler on exit from the scope. | 166 | * inner scope, and restore handler on exit from the scope. |
| 163 | */ | 167 | */ |
| 164 | |||
| 165 | struct jmploc { | 168 | struct jmploc { |
| 166 | jmp_buf loc; | 169 | jmp_buf loc; |
| 167 | }; | 170 | }; |
| 168 | |||
| 169 | static struct jmploc *handler; | 171 | static struct jmploc *handler; |
| 170 | static int exception; | 172 | static int exception; |
| 171 | static volatile int suppressint; | ||
| 172 | static volatile sig_atomic_t intpending; | ||
| 173 | |||
| 174 | /* exceptions */ | 173 | /* exceptions */ |
| 175 | #define EXINT 0 /* SIGINT received */ | 174 | #define EXINT 0 /* SIGINT received */ |
| 176 | #define EXERROR 1 /* a generic error */ | 175 | #define EXERROR 1 /* a generic error */ |
| @@ -178,8 +177,8 @@ static volatile sig_atomic_t intpending; | |||
| 178 | #define EXEXEC 3 /* command execution failed */ | 177 | #define EXEXEC 3 /* command execution failed */ |
| 179 | #define EXEXIT 4 /* exit the shell */ | 178 | #define EXEXIT 4 /* exit the shell */ |
| 180 | #define EXSIG 5 /* trapped signal in wait(1) */ | 179 | #define EXSIG 5 /* trapped signal in wait(1) */ |
| 181 | 180 | static volatile int suppressint; | |
| 182 | 181 | static volatile sig_atomic_t intpending; | |
| 183 | /* do we generate EXSIG events */ | 182 | /* do we generate EXSIG events */ |
| 184 | static int exsig; | 183 | static int exsig; |
| 185 | /* last pending signal */ | 184 | /* last pending signal */ |
| @@ -191,73 +190,323 @@ static volatile sig_atomic_t pendingsigs; | |||
| 191 | * much more efficient and portable. (But hacking the kernel is so much | 190 | * much more efficient and portable. (But hacking the kernel is so much |
| 192 | * more fun than worrying about efficiency and portability. :-)) | 191 | * more fun than worrying about efficiency and portability. :-)) |
| 193 | */ | 192 | */ |
| 194 | |||
| 195 | #define xbarrier() ({ __asm__ __volatile__ ("": : :"memory"); }) | 193 | #define xbarrier() ({ __asm__ __volatile__ ("": : :"memory"); }) |
| 196 | #define INTOFF \ | 194 | #define INT_OFF \ |
| 197 | ({ \ | 195 | ({ \ |
| 198 | suppressint++; \ | 196 | suppressint++; \ |
| 199 | xbarrier(); \ | 197 | xbarrier(); \ |
| 200 | 0; \ | 198 | 0; \ |
| 201 | }) | 199 | }) |
| 202 | #define SAVEINT(v) ((v) = suppressint) | ||
| 203 | #define RESTOREINT(v) \ | ||
| 204 | ({ \ | ||
| 205 | xbarrier(); \ | ||
| 206 | suppressint = (v); \ | ||
| 207 | if (suppressint == 0 && intpending) onint(); \ | ||
| 208 | 0; \ | ||
| 209 | }) | ||
| 210 | #define EXSIGON() \ | ||
| 211 | ({ \ | ||
| 212 | exsig++; \ | ||
| 213 | xbarrier(); \ | ||
| 214 | if (pendingsigs) \ | ||
| 215 | exraise(EXSIG); \ | ||
| 216 | 0; \ | ||
| 217 | }) | ||
| 218 | /* EXSIG is turned off by evalbltin(). */ | ||
| 219 | 200 | ||
| 201 | /* | ||
| 202 | * Called to raise an exception. Since C doesn't include exceptions, we | ||
| 203 | * just do a longjmp to the exception handler. The type of exception is | ||
| 204 | * stored in the global variable "exception". | ||
| 205 | */ | ||
| 206 | static void raise_exception(int) ATTRIBUTE_NORETURN; | ||
| 207 | static void | ||
| 208 | raise_exception(int e) | ||
| 209 | { | ||
| 210 | #if DEBUG | ||
| 211 | if (handler == NULL) | ||
| 212 | abort(); | ||
| 213 | #endif | ||
| 214 | INT_OFF; | ||
| 215 | exception = e; | ||
| 216 | longjmp(handler->loc, 1); | ||
| 217 | } | ||
| 220 | 218 | ||
| 221 | static void exraise(int) ATTRIBUTE_NORETURN; | 219 | /* |
| 222 | static void onint(void) ATTRIBUTE_NORETURN; | 220 | * Called from trap.c when a SIGINT is received. (If the user specifies |
| 223 | 221 | * that SIGINT is to be trapped or ignored using the trap builtin, then | |
| 224 | static void sh_error(const char *, ...) ATTRIBUTE_NORETURN; | 222 | * this routine is not called.) Suppressint is nonzero when interrupts |
| 225 | static void exerror(int, const char *, ...) ATTRIBUTE_NORETURN; | 223 | * are held using the INT_OFF macro. (The test for iflag is just |
| 224 | * defensive programming.) | ||
| 225 | */ | ||
| 226 | static void raise_interrupt(void) ATTRIBUTE_NORETURN; | ||
| 227 | static void | ||
| 228 | raise_interrupt(void) | ||
| 229 | { | ||
| 230 | int i; | ||
| 226 | 231 | ||
| 227 | static void sh_warnx(const char *, ...); | 232 | intpending = 0; |
| 233 | i = EXSIG; | ||
| 234 | if (gotsig[SIGINT - 1] && !trap[SIGINT]) { | ||
| 235 | if (!(rootshell && iflag)) { | ||
| 236 | signal(SIGINT, SIG_DFL); | ||
| 237 | raise(SIGINT); | ||
| 238 | } | ||
| 239 | i = EXINT; | ||
| 240 | } | ||
| 241 | raise_exception(i); | ||
| 242 | /* NOTREACHED */ | ||
| 243 | } | ||
| 228 | 244 | ||
| 229 | #if ENABLE_ASH_OPTIMIZE_FOR_SIZE | 245 | #if ENABLE_ASH_OPTIMIZE_FOR_SIZE |
| 230 | static void | 246 | static void int_on(void) |
| 231 | inton(void) | ||
| 232 | { | 247 | { |
| 233 | if (--suppressint == 0 && intpending) { | 248 | if (--suppressint == 0 && intpending) { |
| 234 | onint(); | 249 | raise_interrupt(); |
| 235 | } | 250 | } |
| 236 | } | 251 | } |
| 237 | #define INTON inton() | 252 | #define INT_ON int_on() |
| 238 | static void forceinton(void) | 253 | static void force_int_on(void) |
| 239 | { | 254 | { |
| 240 | suppressint = 0; | 255 | suppressint = 0; |
| 241 | if (intpending) | 256 | if (intpending) |
| 242 | onint(); | 257 | raise_interrupt(); |
| 243 | } | 258 | } |
| 244 | #define FORCEINTON forceinton() | 259 | #define FORCE_INT_ON force_int_on() |
| 245 | #else | 260 | #else |
| 246 | #define INTON \ | 261 | #define INT_ON \ |
| 247 | ({ \ | 262 | ({ \ |
| 248 | xbarrier(); \ | 263 | xbarrier(); \ |
| 249 | if (--suppressint == 0 && intpending) onint(); \ | 264 | if (--suppressint == 0 && intpending) raise_interrupt(); \ |
| 250 | 0; \ | 265 | 0; \ |
| 251 | }) | 266 | }) |
| 252 | #define FORCEINTON \ | 267 | #define FORCE_INT_ON \ |
| 253 | ({ \ | 268 | ({ \ |
| 254 | xbarrier(); \ | 269 | xbarrier(); \ |
| 255 | suppressint = 0; \ | 270 | suppressint = 0; \ |
| 256 | if (intpending) onint(); \ | 271 | if (intpending) raise_interrupt(); \ |
| 257 | 0; \ | 272 | 0; \ |
| 258 | }) | 273 | }) |
| 259 | #endif /* ASH_OPTIMIZE_FOR_SIZE */ | 274 | #endif /* ASH_OPTIMIZE_FOR_SIZE */ |
| 260 | 275 | ||
| 276 | #define SAVE_INT(v) ((v) = suppressint) | ||
| 277 | |||
| 278 | #define RESTORE_INT(v) \ | ||
| 279 | ({ \ | ||
| 280 | xbarrier(); \ | ||
| 281 | suppressint = (v); \ | ||
| 282 | if (suppressint == 0 && intpending) raise_interrupt(); \ | ||
| 283 | 0; \ | ||
| 284 | }) | ||
| 285 | |||
| 286 | #define EXSIGON \ | ||
| 287 | ({ \ | ||
| 288 | exsig++; \ | ||
| 289 | xbarrier(); \ | ||
| 290 | if (pendingsigs) \ | ||
| 291 | raise_exception(EXSIG); \ | ||
| 292 | 0; \ | ||
| 293 | }) | ||
| 294 | /* EXSIG is turned off by evalbltin(). */ | ||
| 295 | |||
| 296 | |||
| 297 | /* ============ stdout/stderr output */ | ||
| 298 | |||
| 299 | static void | ||
| 300 | outstr(const char *p, FILE *file) | ||
| 301 | { | ||
| 302 | INT_OFF; | ||
| 303 | fputs(p, file); | ||
| 304 | INT_ON; | ||
| 305 | } | ||
| 306 | |||
| 307 | static void | ||
| 308 | flush_stdout_stderr(void) | ||
| 309 | { | ||
| 310 | INT_OFF; | ||
| 311 | fflush(stdout); | ||
| 312 | fflush(stderr); | ||
| 313 | INT_ON; | ||
| 314 | } | ||
| 315 | |||
| 316 | static void | ||
| 317 | flush_stderr(void) | ||
| 318 | { | ||
| 319 | INT_OFF; | ||
| 320 | fflush(stderr); | ||
| 321 | INT_ON; | ||
| 322 | } | ||
| 323 | |||
| 324 | static void | ||
| 325 | outcslow(int c, FILE *dest) | ||
| 326 | { | ||
| 327 | INT_OFF; | ||
| 328 | putc(c, dest); | ||
| 329 | fflush(dest); | ||
| 330 | INT_ON; | ||
| 331 | } | ||
| 332 | |||
| 333 | static int out1fmt(const char *, ...) __attribute__((__format__(__printf__,1,2))); | ||
| 334 | static int | ||
| 335 | out1fmt(const char *fmt, ...) | ||
| 336 | { | ||
| 337 | va_list ap; | ||
| 338 | int r; | ||
| 339 | |||
| 340 | INT_OFF; | ||
| 341 | va_start(ap, fmt); | ||
| 342 | r = vprintf(fmt, ap); | ||
| 343 | va_end(ap); | ||
| 344 | INT_ON; | ||
| 345 | return r; | ||
| 346 | } | ||
| 347 | |||
| 348 | static int fmtstr(char *, size_t, const char *, ...) __attribute__((__format__(__printf__,3,4))); | ||
| 349 | static int | ||
| 350 | fmtstr(char *outbuf, size_t length, const char *fmt, ...) | ||
| 351 | { | ||
| 352 | va_list ap; | ||
| 353 | int ret; | ||
| 354 | |||
| 355 | va_start(ap, fmt); | ||
| 356 | INT_OFF; | ||
| 357 | ret = vsnprintf(outbuf, length, fmt, ap); | ||
| 358 | va_end(ap); | ||
| 359 | INT_ON; | ||
| 360 | return ret; | ||
| 361 | } | ||
| 362 | |||
| 363 | static void | ||
| 364 | out1str(const char *p) | ||
| 365 | { | ||
| 366 | outstr(p, stdout); | ||
| 367 | } | ||
| 368 | |||
| 369 | static void | ||
| 370 | out2str(const char *p) | ||
| 371 | { | ||
| 372 | outstr(p, stderr); | ||
| 373 | flush_stderr(); | ||
| 374 | } | ||
| 375 | |||
| 376 | |||
| 377 | /* ============ Parser data | ||
| 378 | * | ||
| 379 | * ash_vmsg() needs parsefile->fd, hence parsefile definition is moved up. | ||
| 380 | */ | ||
| 381 | |||
| 382 | struct strpush { | ||
| 383 | struct strpush *prev; /* preceding string on stack */ | ||
| 384 | char *prevstring; | ||
| 385 | int prevnleft; | ||
| 386 | #if ENABLE_ASH_ALIAS | ||
| 387 | struct alias *ap; /* if push was associated with an alias */ | ||
| 388 | #endif | ||
| 389 | char *string; /* remember the string since it may change */ | ||
| 390 | }; | ||
| 391 | |||
| 392 | struct parsefile { | ||
| 393 | struct parsefile *prev; /* preceding file on stack */ | ||
| 394 | int linno; /* current line */ | ||
| 395 | int fd; /* file descriptor (or -1 if string) */ | ||
| 396 | int nleft; /* number of chars left in this line */ | ||
| 397 | int lleft; /* number of chars left in this buffer */ | ||
| 398 | char *nextc; /* next char in buffer */ | ||
| 399 | char *buf; /* input buffer */ | ||
| 400 | struct strpush *strpush; /* for pushing strings at this level */ | ||
| 401 | struct strpush basestrpush; /* so pushing one is fast */ | ||
| 402 | }; | ||
| 403 | |||
| 404 | static struct parsefile basepf; /* top level input file */ | ||
| 405 | static struct parsefile *parsefile = &basepf; /* current input file */ | ||
| 406 | static int startlinno; /* line # where last token started */ | ||
| 407 | static char *commandname; /* currently executing command */ | ||
| 408 | static struct strlist *cmdenviron; /* environment for builtin command */ | ||
| 409 | static int exitstatus; /* exit status of last command */ | ||
| 410 | static int back_exitstatus; /* exit status of backquoted command */ | ||
| 411 | |||
| 412 | |||
| 413 | /* ============ Message printing */ | ||
| 414 | |||
| 415 | static void | ||
| 416 | ash_vmsg(const char *msg, va_list ap) | ||
| 417 | { | ||
| 418 | fprintf(stderr, "%s: ", arg0); | ||
| 419 | if (commandname) { | ||
| 420 | const char *fmt = (!iflag || parsefile->fd) ? | ||
| 421 | "%s: %d: " : "%s: "; | ||
| 422 | fprintf(stderr, fmt, commandname, startlinno); | ||
| 423 | } | ||
| 424 | vfprintf(stderr, msg, ap); | ||
| 425 | outcslow('\n', stderr); | ||
| 426 | } | ||
| 427 | |||
| 428 | /* | ||
| 429 | * Exverror is called to raise the error exception. If the second argument | ||
| 430 | * is not NULL then error prints an error message using printf style | ||
| 431 | * formatting. It then raises the error exception. | ||
| 432 | */ | ||
| 433 | static void ash_vmsg_and_raise(int, const char *, va_list) ATTRIBUTE_NORETURN; | ||
| 434 | static void | ||
| 435 | ash_vmsg_and_raise(int cond, const char *msg, va_list ap) | ||
| 436 | { | ||
| 437 | #if DEBUG | ||
| 438 | if (msg) { | ||
| 439 | TRACE(("ash_vmsg_and_raise(%d, \"", cond)); | ||
| 440 | TRACEV((msg, ap)); | ||
| 441 | TRACE(("\") pid=%d\n", getpid())); | ||
| 442 | } else | ||
| 443 | TRACE(("ash_vmsg_and_raise(%d, NULL) pid=%d\n", cond, getpid())); | ||
| 444 | if (msg) | ||
| 445 | #endif | ||
| 446 | ash_vmsg(msg, ap); | ||
| 447 | |||
| 448 | flush_stdout_stderr(); | ||
| 449 | raise_exception(cond); | ||
| 450 | /* NOTREACHED */ | ||
| 451 | } | ||
| 452 | |||
| 453 | static void ash_msg_and_raise_error(const char *, ...) ATTRIBUTE_NORETURN; | ||
| 454 | static void | ||
| 455 | ash_msg_and_raise_error(const char *msg, ...) | ||
| 456 | { | ||
| 457 | va_list ap; | ||
| 458 | |||
| 459 | va_start(ap, msg); | ||
| 460 | ash_vmsg_and_raise(EXERROR, msg, ap); | ||
| 461 | /* NOTREACHED */ | ||
| 462 | va_end(ap); | ||
| 463 | } | ||
| 464 | |||
| 465 | static void ash_msg_and_raise(int, const char *, ...) ATTRIBUTE_NORETURN; | ||
| 466 | static void | ||
| 467 | ash_msg_and_raise(int cond, const char *msg, ...) | ||
| 468 | { | ||
| 469 | va_list ap; | ||
| 470 | |||
| 471 | va_start(ap, msg); | ||
| 472 | ash_vmsg_and_raise(cond, msg, ap); | ||
| 473 | /* NOTREACHED */ | ||
| 474 | va_end(ap); | ||
| 475 | } | ||
| 476 | |||
| 477 | /* | ||
| 478 | * error/warning routines for external builtins | ||
| 479 | */ | ||
| 480 | static void | ||
| 481 | ash_msg(const char *fmt, ...) | ||
| 482 | { | ||
| 483 | va_list ap; | ||
| 484 | |||
| 485 | va_start(ap, fmt); | ||
| 486 | ash_vmsg(fmt, ap); | ||
| 487 | va_end(ap); | ||
| 488 | } | ||
| 489 | |||
| 490 | /* | ||
| 491 | * Return a string describing an error. The returned string may be a | ||
| 492 | * pointer to a static buffer that will be overwritten on the next call. | ||
| 493 | * Action describes the operation that got the error. | ||
| 494 | */ | ||
| 495 | static const char * | ||
| 496 | errmsg(int e, const char *em) | ||
| 497 | { | ||
| 498 | if (e == ENOENT || e == ENOTDIR) { | ||
| 499 | return em; | ||
| 500 | } | ||
| 501 | return strerror(e); | ||
| 502 | } | ||
| 503 | |||
| 504 | |||
| 505 | /* ============ Unsorted yet */ | ||
| 506 | |||
| 507 | |||
| 508 | static void setpwd(const char *, int); | ||
| 509 | |||
| 261 | /* expand.h */ | 510 | /* expand.h */ |
| 262 | 511 | ||
| 263 | struct strlist { | 512 | struct strlist { |
| @@ -297,10 +546,6 @@ static void expari(int); | |||
| 297 | 546 | ||
| 298 | /* eval.h */ | 547 | /* eval.h */ |
| 299 | 548 | ||
| 300 | static char *commandname; /* currently executing command */ | ||
| 301 | static struct strlist *cmdenviron; /* environment for builtin command */ | ||
| 302 | static int exitstatus; /* exit status of last command */ | ||
| 303 | static int back_exitstatus; /* exit status of backquoted command */ | ||
| 304 | 549 | ||
| 305 | 550 | ||
| 306 | struct backcmd { /* result of evalbackcmd */ | 551 | struct backcmd { /* result of evalbackcmd */ |
| @@ -511,31 +756,7 @@ static int parselleft; /* copy of parsefile->lleft */ | |||
| 511 | /* next character in input buffer */ | 756 | /* next character in input buffer */ |
| 512 | static char *parsenextc; /* copy of parsefile->nextc */ | 757 | static char *parsenextc; /* copy of parsefile->nextc */ |
| 513 | 758 | ||
| 514 | struct strpush { | ||
| 515 | struct strpush *prev; /* preceding string on stack */ | ||
| 516 | char *prevstring; | ||
| 517 | int prevnleft; | ||
| 518 | #if ENABLE_ASH_ALIAS | ||
| 519 | struct alias *ap; /* if push was associated with an alias */ | ||
| 520 | #endif | ||
| 521 | char *string; /* remember the string since it may change */ | ||
| 522 | }; | ||
| 523 | |||
| 524 | struct parsefile { | ||
| 525 | struct parsefile *prev; /* preceding file on stack */ | ||
| 526 | int linno; /* current line */ | ||
| 527 | int fd; /* file descriptor (or -1 if string) */ | ||
| 528 | int nleft; /* number of chars left in this line */ | ||
| 529 | int lleft; /* number of chars left in this buffer */ | ||
| 530 | char *nextc; /* next char in buffer */ | ||
| 531 | char *buf; /* input buffer */ | ||
| 532 | struct strpush *strpush; /* for pushing strings at this level */ | ||
| 533 | struct strpush basestrpush; /* so pushing one is fast */ | ||
| 534 | }; | ||
| 535 | |||
| 536 | static struct parsefile basepf; /* top level input file */ | ||
| 537 | #define basebuf bb_common_bufsiz1 /* buffer for top level input file */ | 759 | #define basebuf bb_common_bufsiz1 /* buffer for top level input file */ |
| 538 | static struct parsefile *parsefile = &basepf; /* current input file */ | ||
| 539 | 760 | ||
| 540 | 761 | ||
| 541 | static int tokpushback; /* last token pushed back */ | 762 | static int tokpushback; /* last token pushed back */ |
| @@ -550,7 +771,6 @@ static struct nodelist *backquotelist; | |||
| 550 | static union node *redirnode; | 771 | static union node *redirnode; |
| 551 | static struct heredoc *heredoc; | 772 | static struct heredoc *heredoc; |
| 552 | static int quoteflag; /* set if (part of) last token was quoted */ | 773 | static int quoteflag; /* set if (part of) last token was quoted */ |
| 553 | static int startlinno; /* line # where last token started */ | ||
| 554 | 774 | ||
| 555 | static union node *parsecmd(int); | 775 | static union node *parsecmd(int); |
| 556 | static void fixredir(union node *, const char *, int); | 776 | static void fixredir(union node *, const char *, int); |
| @@ -1597,32 +1817,10 @@ static int nullredirs; | |||
| 1597 | 1817 | ||
| 1598 | extern char **environ; | 1818 | extern char **environ; |
| 1599 | 1819 | ||
| 1600 | /* output.h */ | ||
| 1601 | |||
| 1602 | |||
| 1603 | static void outstr(const char *, FILE *); | ||
| 1604 | static void outcslow(int, FILE *); | ||
| 1605 | static void flushall(void); | ||
| 1606 | static void flusherr(void); | ||
| 1607 | static int out1fmt(const char *, ...) | ||
| 1608 | __attribute__((__format__(__printf__,1,2))); | ||
| 1609 | static int fmtstr(char *, size_t, const char *, ...) | ||
| 1610 | __attribute__((__format__(__printf__,3,4))); | ||
| 1611 | 1820 | ||
| 1612 | static int preverrout_fd; /* save fd2 before print debug if xflag is set. */ | 1821 | static int preverrout_fd; /* save fd2 before print debug if xflag is set. */ |
| 1613 | 1822 | ||
| 1614 | 1823 | ||
| 1615 | static void out1str(const char *p) | ||
| 1616 | { | ||
| 1617 | outstr(p, stdout); | ||
| 1618 | } | ||
| 1619 | |||
| 1620 | static void out2str(const char *p) | ||
| 1621 | { | ||
| 1622 | outstr(p, stderr); | ||
| 1623 | flusherr(); | ||
| 1624 | } | ||
| 1625 | |||
| 1626 | /* | 1824 | /* |
| 1627 | * Initialization code. | 1825 | * Initialization code. |
| 1628 | */ | 1826 | */ |
| @@ -1790,12 +1988,6 @@ static void showjobs(FILE *, int); | |||
| 1790 | /* main.h */ | 1988 | /* main.h */ |
| 1791 | 1989 | ||
| 1792 | 1990 | ||
| 1793 | /* pid of main shell */ | ||
| 1794 | static int rootpid; | ||
| 1795 | /* shell level: 0 for the main shell, 1 for its children, and so on */ | ||
| 1796 | static int shlvl; | ||
| 1797 | #define rootshell (!shlvl) | ||
| 1798 | |||
| 1799 | static void readcmdfile(char *); | 1991 | static void readcmdfile(char *); |
| 1800 | static int cmdloop(int); | 1992 | static int cmdloop(int); |
| 1801 | 1993 | ||
| @@ -1871,8 +2063,6 @@ static char *_STPUTC(int c, char *p) | |||
| 1871 | #define ungrabstackstr(s, p) stunalloc((s)) | 2063 | #define ungrabstackstr(s, p) stunalloc((s)) |
| 1872 | #define stackstrend() ((void *)sstrend) | 2064 | #define stackstrend() ((void *)sstrend) |
| 1873 | 2065 | ||
| 1874 | #define ckfree(p) free((pointer)(p)) | ||
| 1875 | |||
| 1876 | /* mystring.h */ | 2066 | /* mystring.h */ |
| 1877 | 2067 | ||
| 1878 | 2068 | ||
| @@ -1900,59 +2090,6 @@ struct shparam { | |||
| 1900 | }; | 2090 | }; |
| 1901 | 2091 | ||
| 1902 | 2092 | ||
| 1903 | #define eflag optlist[0] | ||
| 1904 | #define fflag optlist[1] | ||
| 1905 | #define Iflag optlist[2] | ||
| 1906 | #define iflag optlist[3] | ||
| 1907 | #define mflag optlist[4] | ||
| 1908 | #define nflag optlist[5] | ||
| 1909 | #define sflag optlist[6] | ||
| 1910 | #define xflag optlist[7] | ||
| 1911 | #define vflag optlist[8] | ||
| 1912 | #define Cflag optlist[9] | ||
| 1913 | #define aflag optlist[10] | ||
| 1914 | #define bflag optlist[11] | ||
| 1915 | #define uflag optlist[12] | ||
| 1916 | #define viflag optlist[13] | ||
| 1917 | |||
| 1918 | #if DEBUG | ||
| 1919 | #define nolog optlist[14] | ||
| 1920 | #define debug optlist[15] | ||
| 1921 | #endif | ||
| 1922 | |||
| 1923 | /* options.c */ | ||
| 1924 | |||
| 1925 | |||
| 1926 | static const char *const optletters_optnames[] = { | ||
| 1927 | "e" "errexit", | ||
| 1928 | "f" "noglob", | ||
| 1929 | "I" "ignoreeof", | ||
| 1930 | "i" "interactive", | ||
| 1931 | "m" "monitor", | ||
| 1932 | "n" "noexec", | ||
| 1933 | "s" "stdin", | ||
| 1934 | "x" "xtrace", | ||
| 1935 | "v" "verbose", | ||
| 1936 | "C" "noclobber", | ||
| 1937 | "a" "allexport", | ||
| 1938 | "b" "notify", | ||
| 1939 | "u" "nounset", | ||
| 1940 | "\0" "vi", | ||
| 1941 | #if DEBUG | ||
| 1942 | "\0" "nolog", | ||
| 1943 | "\0" "debug", | ||
| 1944 | #endif | ||
| 1945 | }; | ||
| 1946 | |||
| 1947 | #define optletters(n) optletters_optnames[(n)][0] | ||
| 1948 | #define optnames(n) (&optletters_optnames[(n)][1]) | ||
| 1949 | |||
| 1950 | #define NOPTS (sizeof(optletters_optnames)/sizeof(optletters_optnames[0])) | ||
| 1951 | |||
| 1952 | static char optlist[NOPTS]; | ||
| 1953 | |||
| 1954 | |||
| 1955 | static char *arg0; /* value of $0 */ | ||
| 1956 | static struct shparam shellparam; /* $@ current positional parameters */ | 2093 | static struct shparam shellparam; /* $@ current positional parameters */ |
| 1957 | static char **argptr; /* argument list for builtin commands */ | 2094 | static char **argptr; /* argument list for builtin commands */ |
| 1958 | static char *optionarg; /* set by nextopt (like getopt) */ | 2095 | static char *optionarg; /* set by nextopt (like getopt) */ |
| @@ -1998,13 +2135,6 @@ static void opentrace(void); | |||
| 1998 | /* trap.h */ | 2135 | /* trap.h */ |
| 1999 | 2136 | ||
| 2000 | 2137 | ||
| 2001 | /* trap handler commands */ | ||
| 2002 | static char *trap[NSIG]; | ||
| 2003 | /* current value of signal */ | ||
| 2004 | static char sigmode[NSIG - 1]; | ||
| 2005 | /* indicates specified signal received */ | ||
| 2006 | static char gotsig[NSIG - 1]; | ||
| 2007 | |||
| 2008 | static void clear_traps(void); | 2138 | static void clear_traps(void); |
| 2009 | static void setsignal(int); | 2139 | static void setsignal(int); |
| 2010 | static void ignoresig(int); | 2140 | static void ignoresig(int); |
| @@ -2094,10 +2224,10 @@ setalias(const char *name, const char *val) | |||
| 2094 | 2224 | ||
| 2095 | app = __lookupalias(name); | 2225 | app = __lookupalias(name); |
| 2096 | ap = *app; | 2226 | ap = *app; |
| 2097 | INTOFF; | 2227 | INT_OFF; |
| 2098 | if (ap) { | 2228 | if (ap) { |
| 2099 | if (!(ap->flag & ALIASINUSE)) { | 2229 | if (!(ap->flag & ALIASINUSE)) { |
| 2100 | ckfree(ap->val); | 2230 | free(ap->val); |
| 2101 | } | 2231 | } |
| 2102 | ap->val = savestr(val); | 2232 | ap->val = savestr(val); |
| 2103 | ap->flag &= ~ALIASDEAD; | 2233 | ap->flag &= ~ALIASDEAD; |
| @@ -2110,7 +2240,7 @@ setalias(const char *name, const char *val) | |||
| 2110 | ap->next = 0; | 2240 | ap->next = 0; |
| 2111 | *app = ap; | 2241 | *app = ap; |
| 2112 | } | 2242 | } |
| 2113 | INTON; | 2243 | INT_ON; |
| 2114 | } | 2244 | } |
| 2115 | 2245 | ||
| 2116 | static int | 2246 | static int |
| @@ -2121,9 +2251,9 @@ unalias(const char *name) | |||
| 2121 | app = __lookupalias(name); | 2251 | app = __lookupalias(name); |
| 2122 | 2252 | ||
| 2123 | if (*app) { | 2253 | if (*app) { |
| 2124 | INTOFF; | 2254 | INT_OFF; |
| 2125 | *app = freealias(*app); | 2255 | *app = freealias(*app); |
| 2126 | INTON; | 2256 | INT_ON; |
| 2127 | return 0; | 2257 | return 0; |
| 2128 | } | 2258 | } |
| 2129 | 2259 | ||
| @@ -2136,7 +2266,7 @@ rmaliases(void) | |||
| 2136 | struct alias *ap, **app; | 2266 | struct alias *ap, **app; |
| 2137 | int i; | 2267 | int i; |
| 2138 | 2268 | ||
| 2139 | INTOFF; | 2269 | INT_OFF; |
| 2140 | for (i = 0; i < ATABSIZE; i++) { | 2270 | for (i = 0; i < ATABSIZE; i++) { |
| 2141 | app = &atab[i]; | 2271 | app = &atab[i]; |
| 2142 | for (ap = *app; ap; ap = *app) { | 2272 | for (ap = *app; ap; ap = *app) { |
| @@ -2146,7 +2276,7 @@ rmaliases(void) | |||
| 2146 | } | 2276 | } |
| 2147 | } | 2277 | } |
| 2148 | } | 2278 | } |
| 2149 | INTON; | 2279 | INT_ON; |
| 2150 | } | 2280 | } |
| 2151 | 2281 | ||
| 2152 | static struct alias * | 2282 | static struct alias * |
| @@ -2228,9 +2358,9 @@ freealias(struct alias *ap) | |||
| 2228 | } | 2358 | } |
| 2229 | 2359 | ||
| 2230 | next = ap->next; | 2360 | next = ap->next; |
| 2231 | ckfree(ap->name); | 2361 | free(ap->name); |
| 2232 | ckfree(ap->val); | 2362 | free(ap->val); |
| 2233 | ckfree(ap); | 2363 | free(ap); |
| 2234 | return next; | 2364 | return next; |
| 2235 | } | 2365 | } |
| 2236 | 2366 | ||
| @@ -2356,7 +2486,7 @@ cdcmd(int argc, char **argv) | |||
| 2356 | break; | 2486 | break; |
| 2357 | } | 2487 | } |
| 2358 | } while (path); | 2488 | } while (path); |
| 2359 | sh_error("can't cd to %s", dest); | 2489 | ash_msg_and_raise_error("can't cd to %s", dest); |
| 2360 | /* NOTREACHED */ | 2490 | /* NOTREACHED */ |
| 2361 | out: | 2491 | out: |
| 2362 | if (flags & CD_PRINT) | 2492 | if (flags & CD_PRINT) |
| @@ -2438,7 +2568,7 @@ docd(const char *dest, int flags) | |||
| 2438 | 2568 | ||
| 2439 | TRACE(("docd(\"%s\", %d) called\n", dest, flags)); | 2569 | TRACE(("docd(\"%s\", %d) called\n", dest, flags)); |
| 2440 | 2570 | ||
| 2441 | INTOFF; | 2571 | INT_OFF; |
| 2442 | if (!(flags & CD_PHYSICAL)) { | 2572 | if (!(flags & CD_PHYSICAL)) { |
| 2443 | dir = updatepwd(dest); | 2573 | dir = updatepwd(dest); |
| 2444 | if (dir) | 2574 | if (dir) |
| @@ -2450,7 +2580,7 @@ docd(const char *dest, int flags) | |||
| 2450 | setpwd(dir, 1); | 2580 | setpwd(dir, 1); |
| 2451 | hashcd(); | 2581 | hashcd(); |
| 2452 | out: | 2582 | out: |
| 2453 | INTON; | 2583 | INT_ON; |
| 2454 | return err; | 2584 | return err; |
| 2455 | } | 2585 | } |
| 2456 | 2586 | ||
| @@ -2490,7 +2620,7 @@ setpwd(const char *val, int setold) | |||
| 2490 | if (setold) { | 2620 | if (setold) { |
| 2491 | setvar("OLDPWD", oldcur, VEXPORT); | 2621 | setvar("OLDPWD", oldcur, VEXPORT); |
| 2492 | } | 2622 | } |
| 2493 | INTOFF; | 2623 | INT_OFF; |
| 2494 | if (physdir != nullstr) { | 2624 | if (physdir != nullstr) { |
| 2495 | if (physdir != oldcur) | 2625 | if (physdir != oldcur) |
| 2496 | free(physdir); | 2626 | free(physdir); |
| @@ -2507,161 +2637,10 @@ setpwd(const char *val, int setold) | |||
| 2507 | free(oldcur); | 2637 | free(oldcur); |
| 2508 | } | 2638 | } |
| 2509 | curdir = dir; | 2639 | curdir = dir; |
| 2510 | INTON; | 2640 | INT_ON; |
| 2511 | setvar("PWD", dir, VEXPORT); | 2641 | setvar("PWD", dir, VEXPORT); |
| 2512 | } | 2642 | } |
| 2513 | 2643 | ||
| 2514 | /* error.c */ | ||
| 2515 | |||
| 2516 | /* | ||
| 2517 | * Errors and exceptions. | ||
| 2518 | */ | ||
| 2519 | |||
| 2520 | /* | ||
| 2521 | * Code to handle exceptions in C. | ||
| 2522 | */ | ||
| 2523 | |||
| 2524 | |||
| 2525 | static void exverror(int, const char *, va_list) ATTRIBUTE_NORETURN; | ||
| 2526 | |||
| 2527 | /* | ||
| 2528 | * Called to raise an exception. Since C doesn't include exceptions, we | ||
| 2529 | * just do a longjmp to the exception handler. The type of exception is | ||
| 2530 | * stored in the global variable "exception". | ||
| 2531 | */ | ||
| 2532 | static void | ||
| 2533 | exraise(int e) | ||
| 2534 | { | ||
| 2535 | #if DEBUG | ||
| 2536 | if (handler == NULL) | ||
| 2537 | abort(); | ||
| 2538 | #endif | ||
| 2539 | INTOFF; | ||
| 2540 | |||
| 2541 | exception = e; | ||
| 2542 | longjmp(handler->loc, 1); | ||
| 2543 | } | ||
| 2544 | |||
| 2545 | |||
| 2546 | /* | ||
| 2547 | * Called from trap.c when a SIGINT is received. (If the user specifies | ||
| 2548 | * that SIGINT is to be trapped or ignored using the trap builtin, then | ||
| 2549 | * this routine is not called.) Suppressint is nonzero when interrupts | ||
| 2550 | * are held using the INTOFF macro. (The test for iflag is just | ||
| 2551 | * defensive programming.) | ||
| 2552 | */ | ||
| 2553 | static void | ||
| 2554 | onint(void) | ||
| 2555 | { | ||
| 2556 | int i; | ||
| 2557 | |||
| 2558 | intpending = 0; | ||
| 2559 | i = EXSIG; | ||
| 2560 | if (gotsig[SIGINT - 1] && !trap[SIGINT]) { | ||
| 2561 | if (!(rootshell && iflag)) { | ||
| 2562 | signal(SIGINT, SIG_DFL); | ||
| 2563 | raise(SIGINT); | ||
| 2564 | } | ||
| 2565 | i = EXINT; | ||
| 2566 | } | ||
| 2567 | exraise(i); | ||
| 2568 | /* NOTREACHED */ | ||
| 2569 | } | ||
| 2570 | |||
| 2571 | static void | ||
| 2572 | exvwarning(const char *msg, va_list ap) | ||
| 2573 | { | ||
| 2574 | FILE *errs; | ||
| 2575 | |||
| 2576 | errs = stderr; | ||
| 2577 | fprintf(errs, "%s: ", arg0); | ||
| 2578 | if (commandname) { | ||
| 2579 | const char *fmt = (!iflag || parsefile->fd) ? | ||
| 2580 | "%s: %d: " : "%s: "; | ||
| 2581 | fprintf(errs, fmt, commandname, startlinno); | ||
| 2582 | } | ||
| 2583 | vfprintf(errs, msg, ap); | ||
| 2584 | outcslow('\n', errs); | ||
| 2585 | } | ||
| 2586 | |||
| 2587 | /* | ||
| 2588 | * Exverror is called to raise the error exception. If the second argument | ||
| 2589 | * is not NULL then error prints an error message using printf style | ||
| 2590 | * formatting. It then raises the error exception. | ||
| 2591 | */ | ||
| 2592 | static void | ||
| 2593 | exverror(int cond, const char *msg, va_list ap) | ||
| 2594 | { | ||
| 2595 | #if DEBUG | ||
| 2596 | if (msg) { | ||
| 2597 | TRACE(("exverror(%d, \"", cond)); | ||
| 2598 | TRACEV((msg, ap)); | ||
| 2599 | TRACE(("\") pid=%d\n", getpid())); | ||
| 2600 | } else | ||
| 2601 | TRACE(("exverror(%d, NULL) pid=%d\n", cond, getpid())); | ||
| 2602 | if (msg) | ||
| 2603 | #endif | ||
| 2604 | exvwarning(msg, ap); | ||
| 2605 | |||
| 2606 | flushall(); | ||
| 2607 | exraise(cond); | ||
| 2608 | /* NOTREACHED */ | ||
| 2609 | } | ||
| 2610 | |||
| 2611 | |||
| 2612 | static void | ||
| 2613 | sh_error(const char *msg, ...) | ||
| 2614 | { | ||
| 2615 | va_list ap; | ||
| 2616 | |||
| 2617 | va_start(ap, msg); | ||
| 2618 | exverror(EXERROR, msg, ap); | ||
| 2619 | /* NOTREACHED */ | ||
| 2620 | va_end(ap); | ||
| 2621 | } | ||
| 2622 | |||
| 2623 | |||
| 2624 | static void | ||
| 2625 | exerror(int cond, const char *msg, ...) | ||
| 2626 | { | ||
| 2627 | va_list ap; | ||
| 2628 | |||
| 2629 | va_start(ap, msg); | ||
| 2630 | exverror(cond, msg, ap); | ||
| 2631 | /* NOTREACHED */ | ||
| 2632 | va_end(ap); | ||
| 2633 | } | ||
| 2634 | |||
| 2635 | |||
| 2636 | /* | ||
| 2637 | * error/warning routines for external builtins | ||
| 2638 | */ | ||
| 2639 | static void | ||
| 2640 | sh_warnx(const char *fmt, ...) | ||
| 2641 | { | ||
| 2642 | va_list ap; | ||
| 2643 | |||
| 2644 | va_start(ap, fmt); | ||
| 2645 | exvwarning(fmt, ap); | ||
| 2646 | va_end(ap); | ||
| 2647 | } | ||
| 2648 | |||
| 2649 | |||
| 2650 | /* | ||
| 2651 | * Return a string describing an error. The returned string may be a | ||
| 2652 | * pointer to a static buffer that will be overwritten on the next call. | ||
| 2653 | * Action describes the operation that got the error. | ||
| 2654 | */ | ||
| 2655 | static const char * | ||
| 2656 | errmsg(int e, const char *em) | ||
| 2657 | { | ||
| 2658 | if (e == ENOENT || e == ENOTDIR) { | ||
| 2659 | return em; | ||
| 2660 | } | ||
| 2661 | return strerror(e); | ||
| 2662 | } | ||
| 2663 | |||
| 2664 | |||
| 2665 | /* eval.c */ | 2644 | /* eval.c */ |
| 2666 | 2645 | ||
| 2667 | /* | 2646 | /* |
| @@ -2870,7 +2849,7 @@ evaltree(union node *n, int flags) | |||
| 2870 | 2849 | ||
| 2871 | if (flags & EV_EXIT) { | 2850 | if (flags & EV_EXIT) { |
| 2872 | exexit: | 2851 | exexit: |
| 2873 | exraise(EXEXIT); | 2852 | raise_exception(EXEXIT); |
| 2874 | } | 2853 | } |
| 2875 | } | 2854 | } |
| 2876 | 2855 | ||
| @@ -2998,10 +2977,10 @@ evalsubshell(union node *n, int flags) | |||
| 2998 | expredir(n->nredir.redirect); | 2977 | expredir(n->nredir.redirect); |
| 2999 | if (!backgnd && flags & EV_EXIT && !trap[0]) | 2978 | if (!backgnd && flags & EV_EXIT && !trap[0]) |
| 3000 | goto nofork; | 2979 | goto nofork; |
| 3001 | INTOFF; | 2980 | INT_OFF; |
| 3002 | jp = makejob(n, 1); | 2981 | jp = makejob(n, 1); |
| 3003 | if (forkshell(jp, n, backgnd) == 0) { | 2982 | if (forkshell(jp, n, backgnd) == 0) { |
| 3004 | INTON; | 2983 | INT_ON; |
| 3005 | flags |= EV_EXIT; | 2984 | flags |= EV_EXIT; |
| 3006 | if (backgnd) | 2985 | if (backgnd) |
| 3007 | flags &=~ EV_TESTED; | 2986 | flags &=~ EV_TESTED; |
| @@ -3014,7 +2993,7 @@ nofork: | |||
| 3014 | if (! backgnd) | 2993 | if (! backgnd) |
| 3015 | status = waitforjob(jp); | 2994 | status = waitforjob(jp); |
| 3016 | exitstatus = status; | 2995 | exitstatus = status; |
| 3017 | INTON; | 2996 | INT_ON; |
| 3018 | } | 2997 | } |
| 3019 | 2998 | ||
| 3020 | 2999 | ||
| @@ -3046,7 +3025,7 @@ expredir(union node *n) | |||
| 3046 | if (fn.list != NULL) | 3025 | if (fn.list != NULL) |
| 3047 | fixredir(redir, fn.list->text, 1); | 3026 | fixredir(redir, fn.list->text, 1); |
| 3048 | else | 3027 | else |
| 3049 | sh_error("redir error"); | 3028 | ash_msg_and_raise_error("redir error"); |
| 3050 | } | 3029 | } |
| 3051 | break; | 3030 | break; |
| 3052 | } | 3031 | } |
| @@ -3074,7 +3053,7 @@ evalpipe(union node *n, int flags) | |||
| 3074 | for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) | 3053 | for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) |
| 3075 | pipelen++; | 3054 | pipelen++; |
| 3076 | flags |= EV_EXIT; | 3055 | flags |= EV_EXIT; |
| 3077 | INTOFF; | 3056 | INT_OFF; |
| 3078 | jp = makejob(n, pipelen); | 3057 | jp = makejob(n, pipelen); |
| 3079 | prevfd = -1; | 3058 | prevfd = -1; |
| 3080 | for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) { | 3059 | for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) { |
| @@ -3083,11 +3062,11 @@ evalpipe(union node *n, int flags) | |||
| 3083 | if (lp->next) { | 3062 | if (lp->next) { |
| 3084 | if (pipe(pip) < 0) { | 3063 | if (pipe(pip) < 0) { |
| 3085 | close(prevfd); | 3064 | close(prevfd); |
| 3086 | sh_error("Pipe call failed"); | 3065 | ash_msg_and_raise_error("Pipe call failed"); |
| 3087 | } | 3066 | } |
| 3088 | } | 3067 | } |
| 3089 | if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) { | 3068 | if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) { |
| 3090 | INTON; | 3069 | INT_ON; |
| 3091 | if (pip[1] >= 0) { | 3070 | if (pip[1] >= 0) { |
| 3092 | close(pip[0]); | 3071 | close(pip[0]); |
| 3093 | } | 3072 | } |
| @@ -3111,7 +3090,7 @@ evalpipe(union node *n, int flags) | |||
| 3111 | exitstatus = waitforjob(jp); | 3090 | exitstatus = waitforjob(jp); |
| 3112 | TRACE(("evalpipe: job done exit status %d\n", exitstatus)); | 3091 | TRACE(("evalpipe: job done exit status %d\n", exitstatus)); |
| 3113 | } | 3092 | } |
| 3114 | INTON; | 3093 | INT_ON; |
| 3115 | } | 3094 | } |
| 3116 | 3095 | ||
| 3117 | 3096 | ||
| @@ -3142,10 +3121,10 @@ evalbackcmd(union node *n, struct backcmd *result) | |||
| 3142 | struct job *jp; | 3121 | struct job *jp; |
| 3143 | 3122 | ||
| 3144 | if (pipe(pip) < 0) | 3123 | if (pipe(pip) < 0) |
| 3145 | sh_error("Pipe call failed"); | 3124 | ash_msg_and_raise_error("Pipe call failed"); |
| 3146 | jp = makejob(n, 1); | 3125 | jp = makejob(n, 1); |
| 3147 | if (forkshell(jp, n, FORK_NOJOB) == 0) { | 3126 | if (forkshell(jp, n, FORK_NOJOB) == 0) { |
| 3148 | FORCEINTON; | 3127 | FORCE_INT_ON; |
| 3149 | close(pip[0]); | 3128 | close(pip[0]); |
| 3150 | if (pip[1] != 1) { | 3129 | if (pip[1] != 1) { |
| 3151 | close(1); | 3130 | close(1); |
| @@ -3250,8 +3229,7 @@ evalcommand(union node *cmd, int flags) | |||
| 3250 | *arglist.lastp = NULL; | 3229 | *arglist.lastp = NULL; |
| 3251 | 3230 | ||
| 3252 | argc = 0; | 3231 | argc = 0; |
| 3253 | if (cmd->ncmd.args) | 3232 | if (cmd->ncmd.args) { |
| 3254 | { | ||
| 3255 | bcmd = find_builtin(cmd->ncmd.args->narg.text); | 3233 | bcmd = find_builtin(cmd->ncmd.args->narg.text); |
| 3256 | pseudovarflag = bcmd && IS_BUILTIN_ASSIGN(bcmd); | 3234 | pseudovarflag = bcmd && IS_BUILTIN_ASSIGN(bcmd); |
| 3257 | } | 3235 | } |
| @@ -3337,7 +3315,7 @@ evalcommand(union node *cmd, int flags) | |||
| 3337 | find_command(argv[0], &cmdentry, cmd_flag, path); | 3315 | find_command(argv[0], &cmdentry, cmd_flag, path); |
| 3338 | if (cmdentry.cmdtype == CMDUNKNOWN) { | 3316 | if (cmdentry.cmdtype == CMDUNKNOWN) { |
| 3339 | status = 127; | 3317 | status = 127; |
| 3340 | flusherr(); | 3318 | flush_stderr(); |
| 3341 | goto bail; | 3319 | goto bail; |
| 3342 | } | 3320 | } |
| 3343 | 3321 | ||
| @@ -3367,7 +3345,7 @@ evalcommand(union node *cmd, int flags) | |||
| 3367 | if (status) { | 3345 | if (status) { |
| 3368 | /* We have a redirection error. */ | 3346 | /* We have a redirection error. */ |
| 3369 | if (spclbltin > 0) | 3347 | if (spclbltin > 0) |
| 3370 | exraise(EXERROR); | 3348 | raise_exception(EXERROR); |
| 3371 | bail: | 3349 | bail: |
| 3372 | exitstatus = status; | 3350 | exitstatus = status; |
| 3373 | goto out; | 3351 | goto out; |
| @@ -3378,14 +3356,14 @@ evalcommand(union node *cmd, int flags) | |||
| 3378 | default: | 3356 | default: |
| 3379 | /* Fork off a child process if necessary. */ | 3357 | /* Fork off a child process if necessary. */ |
| 3380 | if (!(flags & EV_EXIT) || trap[0]) { | 3358 | if (!(flags & EV_EXIT) || trap[0]) { |
| 3381 | INTOFF; | 3359 | INT_OFF; |
| 3382 | jp = makejob(cmd, 1); | 3360 | jp = makejob(cmd, 1); |
| 3383 | if (forkshell(jp, cmd, FORK_FG) != 0) { | 3361 | if (forkshell(jp, cmd, FORK_FG) != 0) { |
| 3384 | exitstatus = waitforjob(jp); | 3362 | exitstatus = waitforjob(jp); |
| 3385 | INTON; | 3363 | INT_ON; |
| 3386 | break; | 3364 | break; |
| 3387 | } | 3365 | } |
| 3388 | FORCEINTON; | 3366 | FORCE_INT_ON; |
| 3389 | } | 3367 | } |
| 3390 | listsetvar(varlist.list, VEXPORT|VSTACK); | 3368 | listsetvar(varlist.list, VEXPORT|VSTACK); |
| 3391 | shellexec(argv, path, cmdentry.u.index); | 3369 | shellexec(argv, path, cmdentry.u.index); |
| @@ -3425,7 +3403,7 @@ evalcommand(union node *cmd, int flags) | |||
| 3425 | raise: | 3403 | raise: |
| 3426 | longjmp(handler->loc, 1); | 3404 | longjmp(handler->loc, 1); |
| 3427 | } | 3405 | } |
| 3428 | FORCEINTON; | 3406 | FORCE_INT_ON; |
| 3429 | } | 3407 | } |
| 3430 | break; | 3408 | break; |
| 3431 | 3409 | ||
| @@ -3465,7 +3443,7 @@ evalbltin(const struct builtincmd *cmd, int argc, char **argv) | |||
| 3465 | argptr = argv + 1; | 3443 | argptr = argv + 1; |
| 3466 | optptr = NULL; /* initialize nextopt */ | 3444 | optptr = NULL; /* initialize nextopt */ |
| 3467 | exitstatus = (*cmd->builtin)(argc, argv); | 3445 | exitstatus = (*cmd->builtin)(argc, argv); |
| 3468 | flushall(); | 3446 | flush_stdout_stderr(); |
| 3469 | cmddone: | 3447 | cmddone: |
| 3470 | exitstatus |= ferror(stdout); | 3448 | exitstatus |= ferror(stdout); |
| 3471 | clearerr(stdout); | 3449 | clearerr(stdout); |
| @@ -3491,14 +3469,14 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags) | |||
| 3491 | if (e) { | 3469 | if (e) { |
| 3492 | goto funcdone; | 3470 | goto funcdone; |
| 3493 | } | 3471 | } |
| 3494 | INTOFF; | 3472 | INT_OFF; |
| 3495 | savehandler = handler; | 3473 | savehandler = handler; |
| 3496 | handler = &jmploc; | 3474 | handler = &jmploc; |
| 3497 | localvars = NULL; | 3475 | localvars = NULL; |
| 3498 | shellparam.malloc = 0; | 3476 | shellparam.malloc = 0; |
| 3499 | func->count++; | 3477 | func->count++; |
| 3500 | funcnest++; | 3478 | funcnest++; |
| 3501 | INTON; | 3479 | INT_ON; |
| 3502 | shellparam.nparam = argc - 1; | 3480 | shellparam.nparam = argc - 1; |
| 3503 | shellparam.p = argv + 1; | 3481 | shellparam.p = argv + 1; |
| 3504 | #if ENABLE_ASH_GETOPTS | 3482 | #if ENABLE_ASH_GETOPTS |
| @@ -3507,7 +3485,7 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags) | |||
| 3507 | #endif | 3485 | #endif |
| 3508 | evaltree(&func->n, flags & EV_TESTED); | 3486 | evaltree(&func->n, flags & EV_TESTED); |
| 3509 | funcdone: | 3487 | funcdone: |
| 3510 | INTOFF; | 3488 | INT_OFF; |
| 3511 | funcnest--; | 3489 | funcnest--; |
| 3512 | freefunc(func); | 3490 | freefunc(func); |
| 3513 | poplocalvars(); | 3491 | poplocalvars(); |
| @@ -3515,7 +3493,7 @@ funcdone: | |||
| 3515 | freeparam(&shellparam); | 3493 | freeparam(&shellparam); |
| 3516 | shellparam = saveparam; | 3494 | shellparam = saveparam; |
| 3517 | handler = savehandler; | 3495 | handler = savehandler; |
| 3518 | INTON; | 3496 | INT_ON; |
| 3519 | evalskip &= ~SKIPFUNC; | 3497 | evalskip &= ~SKIPFUNC; |
| 3520 | return e; | 3498 | return e; |
| 3521 | } | 3499 | } |
| @@ -3580,7 +3558,7 @@ breakcmd(int argc, char **argv) | |||
| 3580 | int n = argc > 1 ? number(argv[1]) : 1; | 3558 | int n = argc > 1 ? number(argv[1]) : 1; |
| 3581 | 3559 | ||
| 3582 | if (n <= 0) | 3560 | if (n <= 0) |
| 3583 | sh_error(illnum, argv[1]); | 3561 | ash_msg_and_raise_error(illnum, argv[1]); |
| 3584 | if (n > loopnest) | 3562 | if (n > loopnest) |
| 3585 | n = loopnest; | 3563 | n = loopnest; |
| 3586 | if (n > 0) { | 3564 | if (n > 0) { |
| @@ -3716,7 +3694,7 @@ shellexec(char **argv, const char *path, int idx) | |||
| 3716 | exitstatus = exerrno; | 3694 | exitstatus = exerrno; |
| 3717 | TRACE(("shellexec failed for %s, errno %d, suppressint %d\n", | 3695 | TRACE(("shellexec failed for %s, errno %d, suppressint %d\n", |
| 3718 | argv[0], e, suppressint )); | 3696 | argv[0], e, suppressint )); |
| 3719 | exerror(EXEXEC, "%s: %s", argv[0], errmsg(e, E_EXEC)); | 3697 | ash_msg_and_raise(EXEXEC, "%s: %s", argv[0], errmsg(e, "not found")); |
| 3720 | /* NOTREACHED */ | 3698 | /* NOTREACHED */ |
| 3721 | } | 3699 | } |
| 3722 | 3700 | ||
| @@ -3758,7 +3736,7 @@ tryexec(char *cmd, char **argv, char **envp) | |||
| 3758 | execve(cmd, argv, envp); | 3736 | execve(cmd, argv, envp); |
| 3759 | #endif | 3737 | #endif |
| 3760 | if (repeated++) { | 3738 | if (repeated++) { |
| 3761 | ckfree(argv); | 3739 | free(argv); |
| 3762 | } else if (errno == ENOEXEC) { | 3740 | } else if (errno == ENOEXEC) { |
| 3763 | char **ap; | 3741 | char **ap; |
| 3764 | char **new; | 3742 | char **new; |
| @@ -4020,7 +3998,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
| 4020 | readcmdfile(fullname); | 3998 | readcmdfile(fullname); |
| 4021 | cmdp = cmdlookup(name, 0); | 3999 | cmdp = cmdlookup(name, 0); |
| 4022 | if (cmdp == NULL || cmdp->cmdtype != CMDFUNCTION) | 4000 | if (cmdp == NULL || cmdp->cmdtype != CMDFUNCTION) |
| 4023 | sh_error("%s not defined in %s", name, fullname); | 4001 | ash_msg_and_raise_error("%s not defined in %s", name, fullname); |
| 4024 | stunalloc(fullname); | 4002 | stunalloc(fullname); |
| 4025 | goto success; | 4003 | goto success; |
| 4026 | } | 4004 | } |
| @@ -4030,11 +4008,11 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
| 4030 | entry->u.index = idx; | 4008 | entry->u.index = idx; |
| 4031 | return; | 4009 | return; |
| 4032 | } | 4010 | } |
| 4033 | INTOFF; | 4011 | INT_OFF; |
| 4034 | cmdp = cmdlookup(name, 1); | 4012 | cmdp = cmdlookup(name, 1); |
| 4035 | cmdp->cmdtype = CMDNORMAL; | 4013 | cmdp->cmdtype = CMDNORMAL; |
| 4036 | cmdp->param.index = idx; | 4014 | cmdp->param.index = idx; |
| 4037 | INTON; | 4015 | INT_ON; |
| 4038 | goto success; | 4016 | goto success; |
| 4039 | } | 4017 | } |
| 4040 | 4018 | ||
| @@ -4042,7 +4020,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
| 4042 | if (cmdp && updatetbl) | 4020 | if (cmdp && updatetbl) |
| 4043 | delete_cmd_entry(); | 4021 | delete_cmd_entry(); |
| 4044 | if (act & DO_ERR) | 4022 | if (act & DO_ERR) |
| 4045 | sh_warnx("%s: %s", name, errmsg(e, E_EXEC)); | 4023 | ash_msg("%s: %s", name, errmsg(e, "not found")); |
| 4046 | entry->cmdtype = CMDUNKNOWN; | 4024 | entry->cmdtype = CMDUNKNOWN; |
| 4047 | return; | 4025 | return; |
| 4048 | 4026 | ||
| @@ -4052,11 +4030,11 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
| 4052 | entry->u.cmd = bcmd; | 4030 | entry->u.cmd = bcmd; |
| 4053 | return; | 4031 | return; |
| 4054 | } | 4032 | } |
| 4055 | INTOFF; | 4033 | INT_OFF; |
| 4056 | cmdp = cmdlookup(name, 1); | 4034 | cmdp = cmdlookup(name, 1); |
| 4057 | cmdp->cmdtype = CMDBUILTIN; | 4035 | cmdp->cmdtype = CMDBUILTIN; |
| 4058 | cmdp->param.cmd = bcmd; | 4036 | cmdp->param.cmd = bcmd; |
| 4059 | INTON; | 4037 | INT_ON; |
| 4060 | success: | 4038 | success: |
| 4061 | cmdp->rehash = 0; | 4039 | cmdp->rehash = 0; |
| 4062 | entry->cmdtype = cmdp->cmdtype; | 4040 | entry->cmdtype = cmdp->cmdtype; |
| @@ -4168,7 +4146,7 @@ clearcmdentry(int firstchange) | |||
| 4168 | struct tblentry **pp; | 4146 | struct tblentry **pp; |
| 4169 | struct tblentry *cmdp; | 4147 | struct tblentry *cmdp; |
| 4170 | 4148 | ||
| 4171 | INTOFF; | 4149 | INT_OFF; |
| 4172 | for (tblp = cmdtable ; tblp < &cmdtable[CMDTABLESIZE] ; tblp++) { | 4150 | for (tblp = cmdtable ; tblp < &cmdtable[CMDTABLESIZE] ; tblp++) { |
| 4173 | pp = tblp; | 4151 | pp = tblp; |
| 4174 | while ((cmdp = *pp) != NULL) { | 4152 | while ((cmdp = *pp) != NULL) { |
| @@ -4178,13 +4156,13 @@ clearcmdentry(int firstchange) | |||
| 4178 | builtinloc >= firstchange) | 4156 | builtinloc >= firstchange) |
| 4179 | ) { | 4157 | ) { |
| 4180 | *pp = cmdp->next; | 4158 | *pp = cmdp->next; |
| 4181 | ckfree(cmdp); | 4159 | free(cmdp); |
| 4182 | } else { | 4160 | } else { |
| 4183 | pp = &cmdp->next; | 4161 | pp = &cmdp->next; |
| 4184 | } | 4162 | } |
| 4185 | } | 4163 | } |
| 4186 | } | 4164 | } |
| 4187 | INTON; | 4165 | INT_ON; |
| 4188 | } | 4166 | } |
| 4189 | 4167 | ||
| 4190 | 4168 | ||
| @@ -4238,13 +4216,13 @@ delete_cmd_entry(void) | |||
| 4238 | { | 4216 | { |
| 4239 | struct tblentry *cmdp; | 4217 | struct tblentry *cmdp; |
| 4240 | 4218 | ||
| 4241 | INTOFF; | 4219 | INT_OFF; |
| 4242 | cmdp = *lastcmdentry; | 4220 | cmdp = *lastcmdentry; |
| 4243 | *lastcmdentry = cmdp->next; | 4221 | *lastcmdentry = cmdp->next; |
| 4244 | if (cmdp->cmdtype == CMDFUNCTION) | 4222 | if (cmdp->cmdtype == CMDFUNCTION) |
| 4245 | freefunc(cmdp->param.func); | 4223 | freefunc(cmdp->param.func); |
| 4246 | ckfree(cmdp); | 4224 | free(cmdp); |
| 4247 | INTON; | 4225 | INT_ON; |
| 4248 | } | 4226 | } |
| 4249 | 4227 | ||
| 4250 | 4228 | ||
| @@ -4295,11 +4273,11 @@ defun(char *name, union node *func) | |||
| 4295 | { | 4273 | { |
| 4296 | struct cmdentry entry; | 4274 | struct cmdentry entry; |
| 4297 | 4275 | ||
| 4298 | INTOFF; | 4276 | INT_OFF; |
| 4299 | entry.cmdtype = CMDFUNCTION; | 4277 | entry.cmdtype = CMDFUNCTION; |
| 4300 | entry.u.func = copyfunc(func); | 4278 | entry.u.func = copyfunc(func); |
| 4301 | addcmdentry(name, &entry); | 4279 | addcmdentry(name, &entry); |
| 4302 | INTON; | 4280 | INT_ON; |
| 4303 | } | 4281 | } |
| 4304 | 4282 | ||
| 4305 | 4283 | ||
| @@ -4819,11 +4797,11 @@ removerecordregions(int endoff) | |||
| 4819 | if (ifsfirst.endoff > endoff) { | 4797 | if (ifsfirst.endoff > endoff) { |
| 4820 | while (ifsfirst.next != NULL) { | 4798 | while (ifsfirst.next != NULL) { |
| 4821 | struct ifsregion *ifsp; | 4799 | struct ifsregion *ifsp; |
| 4822 | INTOFF; | 4800 | INT_OFF; |
| 4823 | ifsp = ifsfirst.next->next; | 4801 | ifsp = ifsfirst.next->next; |
| 4824 | ckfree(ifsfirst.next); | 4802 | free(ifsfirst.next); |
| 4825 | ifsfirst.next = ifsp; | 4803 | ifsfirst.next = ifsp; |
| 4826 | INTON; | 4804 | INT_ON; |
| 4827 | } | 4805 | } |
| 4828 | if (ifsfirst.begoff > endoff) | 4806 | if (ifsfirst.begoff > endoff) |
| 4829 | ifslastp = NULL; | 4807 | ifslastp = NULL; |
| @@ -4839,11 +4817,11 @@ removerecordregions(int endoff) | |||
| 4839 | ifslastp=ifslastp->next; | 4817 | ifslastp=ifslastp->next; |
| 4840 | while (ifslastp->next != NULL) { | 4818 | while (ifslastp->next != NULL) { |
| 4841 | struct ifsregion *ifsp; | 4819 | struct ifsregion *ifsp; |
| 4842 | INTOFF; | 4820 | INT_OFF; |
| 4843 | ifsp = ifslastp->next->next; | 4821 | ifsp = ifslastp->next->next; |
| 4844 | ckfree(ifslastp->next); | 4822 | free(ifslastp->next); |
| 4845 | ifslastp->next = ifsp; | 4823 | ifslastp->next = ifsp; |
| 4846 | INTON; | 4824 | INT_ON; |
| 4847 | } | 4825 | } |
| 4848 | if (ifslastp->endoff > endoff) | 4826 | if (ifslastp->endoff > endoff) |
| 4849 | ifslastp->endoff = endoff; | 4827 | ifslastp->endoff = endoff; |
| @@ -4881,7 +4859,7 @@ expari(int quotes) | |||
| 4881 | p--; | 4859 | p--; |
| 4882 | #if DEBUG | 4860 | #if DEBUG |
| 4883 | if (p < start) { | 4861 | if (p < start) { |
| 4884 | sh_error("missing CTLARI (shouldn't happen)"); | 4862 | ash_msg_and_raise_error("missing CTLARI (shouldn't happen)"); |
| 4885 | } | 4863 | } |
| 4886 | #endif | 4864 | #endif |
| 4887 | } | 4865 | } |
| @@ -4928,7 +4906,7 @@ expbackq(union node *cmd, int quoted, int quotes) | |||
| 4928 | int syntax = quoted? DQSYNTAX : BASESYNTAX; | 4906 | int syntax = quoted? DQSYNTAX : BASESYNTAX; |
| 4929 | struct stackmark smark; | 4907 | struct stackmark smark; |
| 4930 | 4908 | ||
| 4931 | INTOFF; | 4909 | INT_OFF; |
| 4932 | setstackmark(&smark); | 4910 | setstackmark(&smark); |
| 4933 | dest = expdest; | 4911 | dest = expdest; |
| 4934 | startloc = dest - (char *)stackblock(); | 4912 | startloc = dest - (char *)stackblock(); |
| @@ -4953,12 +4931,12 @@ expbackq(union node *cmd, int quoted, int quotes) | |||
| 4953 | } | 4931 | } |
| 4954 | 4932 | ||
| 4955 | if (in.buf) | 4933 | if (in.buf) |
| 4956 | ckfree(in.buf); | 4934 | free(in.buf); |
| 4957 | if (in.fd >= 0) { | 4935 | if (in.fd >= 0) { |
| 4958 | close(in.fd); | 4936 | close(in.fd); |
| 4959 | back_exitstatus = waitforjob(in.jp); | 4937 | back_exitstatus = waitforjob(in.jp); |
| 4960 | } | 4938 | } |
| 4961 | INTON; | 4939 | INT_ON; |
| 4962 | 4940 | ||
| 4963 | /* Eat all trailing newlines */ | 4941 | /* Eat all trailing newlines */ |
| 4964 | dest = expdest; | 4942 | dest = expdest; |
| @@ -5408,11 +5386,11 @@ recordregion(int start, int end, int nulonly) | |||
| 5408 | if (ifslastp == NULL) { | 5386 | if (ifslastp == NULL) { |
| 5409 | ifsp = &ifsfirst; | 5387 | ifsp = &ifsfirst; |
| 5410 | } else { | 5388 | } else { |
| 5411 | INTOFF; | 5389 | INT_OFF; |
| 5412 | ifsp = (struct ifsregion *)ckmalloc(sizeof(struct ifsregion)); | 5390 | ifsp = (struct ifsregion *)ckmalloc(sizeof(struct ifsregion)); |
| 5413 | ifsp->next = NULL; | 5391 | ifsp->next = NULL; |
| 5414 | ifslastp->next = ifsp; | 5392 | ifslastp->next = ifsp; |
| 5415 | INTON; | 5393 | INT_ON; |
| 5416 | } | 5394 | } |
| 5417 | ifslastp = ifsp; | 5395 | ifslastp = ifsp; |
| 5418 | ifslastp->begoff = start; | 5396 | ifslastp->begoff = start; |
| @@ -5515,17 +5493,17 @@ ifsfree(void) | |||
| 5515 | { | 5493 | { |
| 5516 | struct ifsregion *p; | 5494 | struct ifsregion *p; |
| 5517 | 5495 | ||
| 5518 | INTOFF; | 5496 | INT_OFF; |
| 5519 | p = ifsfirst.next; | 5497 | p = ifsfirst.next; |
| 5520 | do { | 5498 | do { |
| 5521 | struct ifsregion *ifsp; | 5499 | struct ifsregion *ifsp; |
| 5522 | ifsp = p->next; | 5500 | ifsp = p->next; |
| 5523 | ckfree(p); | 5501 | free(p); |
| 5524 | p = ifsp; | 5502 | p = ifsp; |
| 5525 | } while (p); | 5503 | } while (p); |
| 5526 | ifslastp = NULL; | 5504 | ifslastp = NULL; |
| 5527 | ifsfirst.next = NULL; | 5505 | ifsfirst.next = NULL; |
| 5528 | INTON; | 5506 | INT_ON; |
| 5529 | } | 5507 | } |
| 5530 | 5508 | ||
| 5531 | static void expmeta(char *, char *); | 5509 | static void expmeta(char *, char *); |
| @@ -5554,7 +5532,7 @@ expandmeta(struct strlist *str, int flag) | |||
| 5554 | goto nometa; | 5532 | goto nometa; |
| 5555 | savelastp = exparg.lastp; | 5533 | savelastp = exparg.lastp; |
| 5556 | 5534 | ||
| 5557 | INTOFF; | 5535 | INT_OFF; |
| 5558 | p = preglob(str->text, 0, RMESCAPE_ALLOC | RMESCAPE_HEAP); | 5536 | p = preglob(str->text, 0, RMESCAPE_ALLOC | RMESCAPE_HEAP); |
| 5559 | { | 5537 | { |
| 5560 | int i = strlen(str->text); | 5538 | int i = strlen(str->text); |
| @@ -5562,10 +5540,10 @@ expandmeta(struct strlist *str, int flag) | |||
| 5562 | } | 5540 | } |
| 5563 | 5541 | ||
| 5564 | expmeta(expdir, p); | 5542 | expmeta(expdir, p); |
| 5565 | ckfree(expdir); | 5543 | free(expdir); |
| 5566 | if (p != str->text) | 5544 | if (p != str->text) |
| 5567 | ckfree(p); | 5545 | free(p); |
| 5568 | INTON; | 5546 | INT_ON; |
| 5569 | if (exparg.lastp == savelastp) { | 5547 | if (exparg.lastp == savelastp) { |
| 5570 | /* | 5548 | /* |
| 5571 | * no matches | 5549 | * no matches |
| @@ -5911,7 +5889,7 @@ varunset(const char *end, const char *var, const char *umsg, int varflags) | |||
| 5911 | } else | 5889 | } else |
| 5912 | msg = umsg; | 5890 | msg = umsg; |
| 5913 | } | 5891 | } |
| 5914 | sh_error("%.*s: %s%s", end - var - 1, var, msg, tail); | 5892 | ash_msg_and_raise_error("%.*s: %s%s", end - var - 1, var, msg, tail); |
| 5915 | } | 5893 | } |
| 5916 | 5894 | ||
| 5917 | 5895 | ||
| @@ -6104,7 +6082,7 @@ preadbuffer(void) | |||
| 6104 | } | 6082 | } |
| 6105 | if (parsenleft == EOF_NLEFT || parsefile->buf == NULL) | 6083 | if (parsenleft == EOF_NLEFT || parsefile->buf == NULL) |
| 6106 | return PEOF; | 6084 | return PEOF; |
| 6107 | flushall(); | 6085 | flush_stdout_stderr(); |
| 6108 | 6086 | ||
| 6109 | more = parselleft; | 6087 | more = parselleft; |
| 6110 | if (more <= 0) { | 6088 | if (more <= 0) { |
| @@ -6178,7 +6156,7 @@ pushstring(char *s, void *ap) | |||
| 6178 | size_t len; | 6156 | size_t len; |
| 6179 | 6157 | ||
| 6180 | len = strlen(s); | 6158 | len = strlen(s); |
| 6181 | INTOFF; | 6159 | INT_OFF; |
| 6182 | /*dprintf("*** calling pushstring: %s, %d\n", s, len);*/ | 6160 | /*dprintf("*** calling pushstring: %s, %d\n", s, len);*/ |
| 6183 | if (parsefile->strpush) { | 6161 | if (parsefile->strpush) { |
| 6184 | sp = ckmalloc(sizeof(struct strpush)); | 6162 | sp = ckmalloc(sizeof(struct strpush)); |
| @@ -6197,7 +6175,7 @@ pushstring(char *s, void *ap) | |||
| 6197 | #endif | 6175 | #endif |
| 6198 | parsenextc = s; | 6176 | parsenextc = s; |
| 6199 | parsenleft = len; | 6177 | parsenleft = len; |
| 6200 | INTON; | 6178 | INT_ON; |
| 6201 | } | 6179 | } |
| 6202 | 6180 | ||
| 6203 | static void | 6181 | static void |
| @@ -6205,14 +6183,14 @@ popstring(void) | |||
| 6205 | { | 6183 | { |
| 6206 | struct strpush *sp = parsefile->strpush; | 6184 | struct strpush *sp = parsefile->strpush; |
| 6207 | 6185 | ||
| 6208 | INTOFF; | 6186 | INT_OFF; |
| 6209 | #if ENABLE_ASH_ALIAS | 6187 | #if ENABLE_ASH_ALIAS |
| 6210 | if (sp->ap) { | 6188 | if (sp->ap) { |
| 6211 | if (parsenextc[-1] == ' ' || parsenextc[-1] == '\t') { | 6189 | if (parsenextc[-1] == ' ' || parsenextc[-1] == '\t') { |
| 6212 | checkkwd |= CHKALIAS; | 6190 | checkkwd |= CHKALIAS; |
| 6213 | } | 6191 | } |
| 6214 | if (sp->string != sp->ap->val) { | 6192 | if (sp->string != sp->ap->val) { |
| 6215 | ckfree(sp->string); | 6193 | free(sp->string); |
| 6216 | } | 6194 | } |
| 6217 | sp->ap->flag &= ~ALIASINUSE; | 6195 | sp->ap->flag &= ~ALIASINUSE; |
| 6218 | if (sp->ap->flag & ALIASDEAD) { | 6196 | if (sp->ap->flag & ALIASDEAD) { |
| @@ -6225,8 +6203,8 @@ popstring(void) | |||
| 6225 | /*dprintf("*** calling popstring: restoring to '%s'\n", parsenextc);*/ | 6203 | /*dprintf("*** calling popstring: restoring to '%s'\n", parsenextc);*/ |
| 6226 | parsefile->strpush = sp->prev; | 6204 | parsefile->strpush = sp->prev; |
| 6227 | if (sp != &(parsefile->basestrpush)) | 6205 | if (sp != &(parsefile->basestrpush)) |
| 6228 | ckfree(sp); | 6206 | free(sp); |
| 6229 | INTON; | 6207 | INT_ON; |
| 6230 | } | 6208 | } |
| 6231 | 6209 | ||
| 6232 | 6210 | ||
| @@ -6240,23 +6218,23 @@ setinputfile(const char *fname, int flags) | |||
| 6240 | int fd; | 6218 | int fd; |
| 6241 | int fd2; | 6219 | int fd2; |
| 6242 | 6220 | ||
| 6243 | INTOFF; | 6221 | INT_OFF; |
| 6244 | fd = open(fname, O_RDONLY); | 6222 | fd = open(fname, O_RDONLY); |
| 6245 | if (fd < 0) { | 6223 | if (fd < 0) { |
| 6246 | if (flags & INPUT_NOFILE_OK) | 6224 | if (flags & INPUT_NOFILE_OK) |
| 6247 | goto out; | 6225 | goto out; |
| 6248 | sh_error("Can't open %s", fname); | 6226 | ash_msg_and_raise_error("Can't open %s", fname); |
| 6249 | } | 6227 | } |
| 6250 | if (fd < 10) { | 6228 | if (fd < 10) { |
| 6251 | fd2 = copyfd(fd, 10); | 6229 | fd2 = copyfd(fd, 10); |
| 6252 | close(fd); | 6230 | close(fd); |
| 6253 | if (fd2 < 0) | 6231 | if (fd2 < 0) |
| 6254 | sh_error("Out of file descriptors"); | 6232 | ash_msg_and_raise_error("Out of file descriptors"); |
| 6255 | fd = fd2; | 6233 | fd = fd2; |
| 6256 | } | 6234 | } |
| 6257 | setinputfd(fd, flags & INPUT_PUSH_FILE); | 6235 | setinputfd(fd, flags & INPUT_PUSH_FILE); |
| 6258 | out: | 6236 | out: |
| 6259 | INTON; | 6237 | INT_ON; |
| 6260 | return fd; | 6238 | return fd; |
| 6261 | } | 6239 | } |
| 6262 | 6240 | ||
| @@ -6287,13 +6265,13 @@ setinputfd(int fd, int push) | |||
| 6287 | static void | 6265 | static void |
| 6288 | setinputstring(char *string) | 6266 | setinputstring(char *string) |
| 6289 | { | 6267 | { |
| 6290 | INTOFF; | 6268 | INT_OFF; |
| 6291 | pushfile(); | 6269 | pushfile(); |
| 6292 | parsenextc = string; | 6270 | parsenextc = string; |
| 6293 | parsenleft = strlen(string); | 6271 | parsenleft = strlen(string); |
| 6294 | parsefile->buf = NULL; | 6272 | parsefile->buf = NULL; |
| 6295 | plinno = 1; | 6273 | plinno = 1; |
| 6296 | INTON; | 6274 | INT_ON; |
| 6297 | } | 6275 | } |
| 6298 | 6276 | ||
| 6299 | 6277 | ||
| @@ -6324,20 +6302,20 @@ popfile(void) | |||
| 6324 | { | 6302 | { |
| 6325 | struct parsefile *pf = parsefile; | 6303 | struct parsefile *pf = parsefile; |
| 6326 | 6304 | ||
| 6327 | INTOFF; | 6305 | INT_OFF; |
| 6328 | if (pf->fd >= 0) | 6306 | if (pf->fd >= 0) |
| 6329 | close(pf->fd); | 6307 | close(pf->fd); |
| 6330 | if (pf->buf) | 6308 | if (pf->buf) |
| 6331 | ckfree(pf->buf); | 6309 | free(pf->buf); |
| 6332 | while (pf->strpush) | 6310 | while (pf->strpush) |
| 6333 | popstring(); | 6311 | popstring(); |
| 6334 | parsefile = pf->prev; | 6312 | parsefile = pf->prev; |
| 6335 | ckfree(pf); | 6313 | free(pf); |
| 6336 | parsenleft = parsefile->nleft; | 6314 | parsenleft = parsefile->nleft; |
| 6337 | parselleft = parsefile->lleft; | 6315 | parselleft = parsefile->lleft; |
| 6338 | parsenextc = parsefile->nextc; | 6316 | parsenextc = parsefile->nextc; |
| 6339 | plinno = parsefile->linno; | 6317 | plinno = parsefile->linno; |
| 6340 | INTON; | 6318 | INT_ON; |
| 6341 | } | 6319 | } |
| 6342 | 6320 | ||
| 6343 | 6321 | ||
| @@ -6497,7 +6475,7 @@ setjobctl(int on) | |||
| 6497 | pgrp = tcgetpgrp(fd); | 6475 | pgrp = tcgetpgrp(fd); |
| 6498 | if (pgrp < 0) { | 6476 | if (pgrp < 0) { |
| 6499 | out: | 6477 | out: |
| 6500 | sh_warnx("can't access tty; job control turned off"); | 6478 | ash_msg("can't access tty; job control turned off"); |
| 6501 | mflag = on = 0; | 6479 | mflag = on = 0; |
| 6502 | goto close; | 6480 | goto close; |
| 6503 | } | 6481 | } |
| @@ -6541,7 +6519,7 @@ killcmd(int argc, char **argv) | |||
| 6541 | 6519 | ||
| 6542 | if (argc <= 1) { | 6520 | if (argc <= 1) { |
| 6543 | usage: | 6521 | usage: |
| 6544 | sh_error( | 6522 | ash_msg_and_raise_error( |
| 6545 | "Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or\n" | 6523 | "Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or\n" |
| 6546 | "kill -l [exitstatus]" | 6524 | "kill -l [exitstatus]" |
| 6547 | ); | 6525 | ); |
| @@ -6564,7 +6542,7 @@ killcmd(int argc, char **argv) | |||
| 6564 | case 's': | 6542 | case 's': |
| 6565 | signo = get_signum(optionarg); | 6543 | signo = get_signum(optionarg); |
| 6566 | if (signo < 0) { | 6544 | if (signo < 0) { |
| 6567 | sh_error( | 6545 | ash_msg_and_raise_error( |
| 6568 | "invalid signal number or name: %s", | 6546 | "invalid signal number or name: %s", |
| 6569 | optionarg | 6547 | optionarg |
| 6570 | ); | 6548 | ); |
| @@ -6598,7 +6576,7 @@ killcmd(int argc, char **argv) | |||
| 6598 | if (isdigit(*name)) | 6576 | if (isdigit(*name)) |
| 6599 | out1fmt(snlfmt, name); | 6577 | out1fmt(snlfmt, name); |
| 6600 | else | 6578 | else |
| 6601 | sh_error("invalid signal number or exit status: %s", *argptr); | 6579 | ash_msg_and_raise_error("invalid signal number or exit status: %s", *argptr); |
| 6602 | return 0; | 6580 | return 0; |
| 6603 | } | 6581 | } |
| 6604 | 6582 | ||
| @@ -6612,7 +6590,7 @@ killcmd(int argc, char **argv) | |||
| 6612 | -number(*argv + 1) : number(*argv); | 6590 | -number(*argv + 1) : number(*argv); |
| 6613 | } | 6591 | } |
| 6614 | if (kill(pid, signo) != 0) { | 6592 | if (kill(pid, signo) != 0) { |
| 6615 | sh_warnx("(%d) - %m", pid); | 6593 | ash_msg("(%d) - %m", pid); |
| 6616 | i = 1; | 6594 | i = 1; |
| 6617 | } | 6595 | } |
| 6618 | } while (*++argv); | 6596 | } while (*++argv); |
| @@ -6666,7 +6644,7 @@ restartjob(struct job *jp, int mode) | |||
| 6666 | int status; | 6644 | int status; |
| 6667 | pid_t pgid; | 6645 | pid_t pgid; |
| 6668 | 6646 | ||
| 6669 | INTOFF; | 6647 | INT_OFF; |
| 6670 | if (jp->state == JOBDONE) | 6648 | if (jp->state == JOBDONE) |
| 6671 | goto out; | 6649 | goto out; |
| 6672 | jp->state = JOBRUNNING; | 6650 | jp->state = JOBRUNNING; |
| @@ -6683,7 +6661,7 @@ restartjob(struct job *jp, int mode) | |||
| 6683 | } while (ps++, --i); | 6661 | } while (ps++, --i); |
| 6684 | out: | 6662 | out: |
| 6685 | status = (mode == FORK_FG) ? waitforjob(jp) : 0; | 6663 | status = (mode == FORK_FG) ? waitforjob(jp) : 0; |
| 6686 | INTON; | 6664 | INT_ON; |
| 6687 | return status; | 6665 | return status; |
| 6688 | } | 6666 | } |
| 6689 | #endif | 6667 | #endif |
| @@ -6855,16 +6833,16 @@ freejob(struct job *jp) | |||
| 6855 | struct procstat *ps; | 6833 | struct procstat *ps; |
| 6856 | int i; | 6834 | int i; |
| 6857 | 6835 | ||
| 6858 | INTOFF; | 6836 | INT_OFF; |
| 6859 | for (i = jp->nprocs, ps = jp->ps ; --i >= 0 ; ps++) { | 6837 | for (i = jp->nprocs, ps = jp->ps ; --i >= 0 ; ps++) { |
| 6860 | if (ps->cmd != nullstr) | 6838 | if (ps->cmd != nullstr) |
| 6861 | ckfree(ps->cmd); | 6839 | free(ps->cmd); |
| 6862 | } | 6840 | } |
| 6863 | if (jp->ps != &jp->ps0) | 6841 | if (jp->ps != &jp->ps0) |
| 6864 | ckfree(jp->ps); | 6842 | free(jp->ps); |
| 6865 | jp->used = 0; | 6843 | jp->used = 0; |
| 6866 | set_curjob(jp, CUR_DELETE); | 6844 | set_curjob(jp, CUR_DELETE); |
| 6867 | INTON; | 6845 | INT_ON; |
| 6868 | } | 6846 | } |
| 6869 | 6847 | ||
| 6870 | 6848 | ||
| @@ -6875,7 +6853,7 @@ waitcmd(int argc, char **argv) | |||
| 6875 | int retval; | 6853 | int retval; |
| 6876 | struct job *jp; | 6854 | struct job *jp; |
| 6877 | 6855 | ||
| 6878 | EXSIGON(); | 6856 | EXSIGON; |
| 6879 | 6857 | ||
| 6880 | nextopt(nullstr); | 6858 | nextopt(nullstr); |
| 6881 | retval = 0; | 6859 | retval = 0; |
| @@ -7008,7 +6986,7 @@ getjob(const char *name, int getctl) | |||
| 7008 | #endif | 6986 | #endif |
| 7009 | return jp; | 6987 | return jp; |
| 7010 | err: | 6988 | err: |
| 7011 | sh_error(err_msg, name); | 6989 | ash_msg_and_raise_error(err_msg, name); |
| 7012 | } | 6990 | } |
| 7013 | 6991 | ||
| 7014 | 6992 | ||
| @@ -7150,7 +7128,7 @@ static void forkchild(struct job *jp, union node *n, int mode) | |||
| 7150 | if (jp->nprocs == 0) { | 7128 | if (jp->nprocs == 0) { |
| 7151 | close(0); | 7129 | close(0); |
| 7152 | if (open(bb_dev_null, O_RDONLY) != 0) | 7130 | if (open(bb_dev_null, O_RDONLY) != 0) |
| 7153 | sh_error("Can't open %s", bb_dev_null); | 7131 | ash_msg_and_raise_error("Can't open %s", bb_dev_null); |
| 7154 | } | 7132 | } |
| 7155 | } | 7133 | } |
| 7156 | if (!oldlvl && iflag) { | 7134 | if (!oldlvl && iflag) { |
| @@ -7210,7 +7188,7 @@ forkshell(struct job *jp, union node *n, int mode) | |||
| 7210 | TRACE(("Fork failed, errno=%d", errno)); | 7188 | TRACE(("Fork failed, errno=%d", errno)); |
| 7211 | if (jp) | 7189 | if (jp) |
| 7212 | freejob(jp); | 7190 | freejob(jp); |
| 7213 | sh_error("Cannot fork"); | 7191 | ash_msg_and_raise_error("Cannot fork"); |
| 7214 | } | 7192 | } |
| 7215 | if (pid == 0) | 7193 | if (pid == 0) |
| 7216 | forkchild(jp, n, mode); | 7194 | forkchild(jp, n, mode); |
| @@ -7330,7 +7308,7 @@ dowait(int block, struct job *job) | |||
| 7330 | TRACE(("wait returns pid %d, status=%d\n", pid, status)); | 7308 | TRACE(("wait returns pid %d, status=%d\n", pid, status)); |
| 7331 | if (pid <= 0) | 7309 | if (pid <= 0) |
| 7332 | return pid; | 7310 | return pid; |
| 7333 | INTOFF; | 7311 | INT_OFF; |
| 7334 | thisjob = NULL; | 7312 | thisjob = NULL; |
| 7335 | for (jp = curjob; jp; jp = jp->prev_job) { | 7313 | for (jp = curjob; jp; jp = jp->prev_job) { |
| 7336 | struct procstat *sp; | 7314 | struct procstat *sp; |
| @@ -7386,7 +7364,7 @@ dowait(int block, struct job *job) | |||
| 7386 | } | 7364 | } |
| 7387 | 7365 | ||
| 7388 | out: | 7366 | out: |
| 7389 | INTON; | 7367 | INT_ON; |
| 7390 | 7368 | ||
| 7391 | if (thisjob && thisjob == job) { | 7369 | if (thisjob && thisjob == job) { |
| 7392 | char s[48 + 1]; | 7370 | char s[48 + 1]; |
| @@ -7716,14 +7694,14 @@ showpipe(struct job *jp, FILE *out) | |||
| 7716 | for (sp = jp->ps + 1; sp < spend; sp++) | 7694 | for (sp = jp->ps + 1; sp < spend; sp++) |
| 7717 | fprintf(out, " | %s", sp->cmd); | 7695 | fprintf(out, " | %s", sp->cmd); |
| 7718 | outcslow('\n', out); | 7696 | outcslow('\n', out); |
| 7719 | flushall(); | 7697 | flush_stdout_stderr(); |
| 7720 | } | 7698 | } |
| 7721 | 7699 | ||
| 7722 | static void | 7700 | static void |
| 7723 | xtcsetpgrp(int fd, pid_t pgrp) | 7701 | xtcsetpgrp(int fd, pid_t pgrp) |
| 7724 | { | 7702 | { |
| 7725 | if (tcsetpgrp(fd, pgrp)) | 7703 | if (tcsetpgrp(fd, pgrp)) |
| 7726 | sh_error("Cannot set tty process group (%m)"); | 7704 | ash_msg_and_raise_error("Cannot set tty process group (%m)"); |
| 7727 | } | 7705 | } |
| 7728 | #endif /* JOBS */ | 7706 | #endif /* JOBS */ |
| 7729 | 7707 | ||
| @@ -7881,7 +7859,7 @@ int ash_main(int argc, char **argv) | |||
| 7881 | outcslow('\n', stderr); | 7859 | outcslow('\n', stderr); |
| 7882 | } | 7860 | } |
| 7883 | popstackmark(&smark); | 7861 | popstackmark(&smark); |
| 7884 | FORCEINTON; /* enable interrupts */ | 7862 | FORCE_INT_ON; /* enable interrupts */ |
| 7885 | if (s == 1) | 7863 | if (s == 1) |
| 7886 | goto state1; | 7864 | goto state1; |
| 7887 | else if (s == 2) | 7865 | else if (s == 2) |
| @@ -8085,7 +8063,7 @@ static char * find_dot_file(char *name) | |||
| 8085 | } | 8063 | } |
| 8086 | 8064 | ||
| 8087 | /* not found in the PATH */ | 8065 | /* not found in the PATH */ |
| 8088 | sh_error(not_found_msg, name); | 8066 | ash_msg_and_raise_error("%s: not found", name); |
| 8089 | /* NOTREACHED */ | 8067 | /* NOTREACHED */ |
| 8090 | } | 8068 | } |
| 8091 | 8069 | ||
| @@ -8132,7 +8110,7 @@ exitcmd(int argc, char **argv) | |||
| 8132 | return 0; | 8110 | return 0; |
| 8133 | if (argc > 1) | 8111 | if (argc > 1) |
| 8134 | exitstatus = number(argv[1]); | 8112 | exitstatus = number(argv[1]); |
| 8135 | exraise(EXEXIT); | 8113 | raise_exception(EXEXIT); |
| 8136 | /* NOTREACHED */ | 8114 | /* NOTREACHED */ |
| 8137 | } | 8115 | } |
| 8138 | 8116 | ||
| @@ -8162,7 +8140,7 @@ ckrealloc(pointer p, size_t nbytes) | |||
| 8162 | { | 8140 | { |
| 8163 | p = realloc(p, nbytes); | 8141 | p = realloc(p, nbytes); |
| 8164 | if (p == NULL) | 8142 | if (p == NULL) |
| 8165 | sh_error(bb_msg_memory_exhausted); | 8143 | ash_msg_and_raise_error(bb_msg_memory_exhausted); |
| 8166 | return p; | 8144 | return p; |
| 8167 | } | 8145 | } |
| 8168 | 8146 | ||
| @@ -8180,7 +8158,7 @@ savestr(const char *s) | |||
| 8180 | { | 8158 | { |
| 8181 | char *p = strdup(s); | 8159 | char *p = strdup(s); |
| 8182 | if (!p) | 8160 | if (!p) |
| 8183 | sh_error(bb_msg_memory_exhausted); | 8161 | ash_msg_and_raise_error(bb_msg_memory_exhausted); |
| 8184 | return p; | 8162 | return p; |
| 8185 | } | 8163 | } |
| 8186 | 8164 | ||
| @@ -8210,15 +8188,15 @@ stalloc(size_t nbytes) | |||
| 8210 | blocksize = MINSIZE; | 8188 | blocksize = MINSIZE; |
| 8211 | len = sizeof(struct stack_block) - MINSIZE + blocksize; | 8189 | len = sizeof(struct stack_block) - MINSIZE + blocksize; |
| 8212 | if (len < blocksize) | 8190 | if (len < blocksize) |
| 8213 | sh_error(bb_msg_memory_exhausted); | 8191 | ash_msg_and_raise_error(bb_msg_memory_exhausted); |
| 8214 | INTOFF; | 8192 | INT_OFF; |
| 8215 | sp = ckmalloc(len); | 8193 | sp = ckmalloc(len); |
| 8216 | sp->prev = stackp; | 8194 | sp->prev = stackp; |
| 8217 | stacknxt = sp->space; | 8195 | stacknxt = sp->space; |
| 8218 | stacknleft = blocksize; | 8196 | stacknleft = blocksize; |
| 8219 | sstrend = stacknxt + blocksize; | 8197 | sstrend = stacknxt + blocksize; |
| 8220 | stackp = sp; | 8198 | stackp = sp; |
| 8221 | INTON; | 8199 | INT_ON; |
| 8222 | } | 8200 | } |
| 8223 | p = stacknxt; | 8201 | p = stacknxt; |
| 8224 | stacknxt += aligned; | 8202 | stacknxt += aligned; |
| @@ -8257,17 +8235,17 @@ popstackmark(struct stackmark *mark) | |||
| 8257 | { | 8235 | { |
| 8258 | struct stack_block *sp; | 8236 | struct stack_block *sp; |
| 8259 | 8237 | ||
| 8260 | INTOFF; | 8238 | INT_OFF; |
| 8261 | markp = mark->marknext; | 8239 | markp = mark->marknext; |
| 8262 | while (stackp != mark->stackp) { | 8240 | while (stackp != mark->stackp) { |
| 8263 | sp = stackp; | 8241 | sp = stackp; |
| 8264 | stackp = sp->prev; | 8242 | stackp = sp->prev; |
| 8265 | ckfree(sp); | 8243 | free(sp); |
| 8266 | } | 8244 | } |
| 8267 | stacknxt = mark->stacknxt; | 8245 | stacknxt = mark->stacknxt; |
| 8268 | stacknleft = mark->stacknleft; | 8246 | stacknleft = mark->stacknleft; |
| 8269 | sstrend = mark->stacknxt + mark->stacknleft; | 8247 | sstrend = mark->stacknxt + mark->stacknleft; |
| 8270 | INTON; | 8248 | INT_ON; |
| 8271 | } | 8249 | } |
| 8272 | 8250 | ||
| 8273 | 8251 | ||
| @@ -8287,7 +8265,7 @@ growstackblock(void) | |||
| 8287 | 8265 | ||
| 8288 | newlen = stacknleft * 2; | 8266 | newlen = stacknleft * 2; |
| 8289 | if (newlen < stacknleft) | 8267 | if (newlen < stacknleft) |
| 8290 | sh_error(bb_msg_memory_exhausted); | 8268 | ash_msg_and_raise_error(bb_msg_memory_exhausted); |
| 8291 | if (newlen < 128) | 8269 | if (newlen < 128) |
| 8292 | newlen += 128; | 8270 | newlen += 128; |
| 8293 | 8271 | ||
| @@ -8298,7 +8276,7 @@ growstackblock(void) | |||
| 8298 | struct stack_block *prevstackp; | 8276 | struct stack_block *prevstackp; |
| 8299 | size_t grosslen; | 8277 | size_t grosslen; |
| 8300 | 8278 | ||
| 8301 | INTOFF; | 8279 | INT_OFF; |
| 8302 | oldstackp = stackp; | 8280 | oldstackp = stackp; |
| 8303 | sp = stackp; | 8281 | sp = stackp; |
| 8304 | prevstackp = sp->prev; | 8282 | prevstackp = sp->prev; |
| @@ -8321,7 +8299,7 @@ growstackblock(void) | |||
| 8321 | xmark->stacknleft = stacknleft; | 8299 | xmark->stacknleft = stacknleft; |
| 8322 | xmark = xmark->marknext; | 8300 | xmark = xmark->marknext; |
| 8323 | } | 8301 | } |
| 8324 | INTON; | 8302 | INT_ON; |
| 8325 | } else { | 8303 | } else { |
| 8326 | char *oldspace = stacknxt; | 8304 | char *oldspace = stacknxt; |
| 8327 | int oldlen = stacknleft; | 8305 | int oldlen = stacknleft; |
| @@ -8436,7 +8414,7 @@ static int | |||
| 8436 | number(const char *s) | 8414 | number(const char *s) |
| 8437 | { | 8415 | { |
| 8438 | if (! is_number(s)) | 8416 | if (! is_number(s)) |
| 8439 | sh_error(illnum, s); | 8417 | ash_msg_and_raise_error(illnum, s); |
| 8440 | return atoi(s); | 8418 | return atoi(s); |
| 8441 | } | 8419 | } |
| 8442 | 8420 | ||
| @@ -8729,7 +8707,7 @@ static void | |||
| 8729 | freefunc(struct funcnode *f) | 8707 | freefunc(struct funcnode *f) |
| 8730 | { | 8708 | { |
| 8731 | if (f && --f->count < 0) | 8709 | if (f && --f->count < 0) |
| 8732 | ckfree(f); | 8710 | free(f); |
| 8733 | } | 8711 | } |
| 8734 | 8712 | ||
| 8735 | 8713 | ||
| @@ -8759,7 +8737,7 @@ procargs(int argc, char **argv) | |||
| 8759 | xminusc = minusc; | 8737 | xminusc = minusc; |
| 8760 | if (*xargv == NULL) { | 8738 | if (*xargv == NULL) { |
| 8761 | if (xminusc) | 8739 | if (xminusc) |
| 8762 | sh_error(bb_msg_requires_arg, "-c"); | 8740 | ash_msg_and_raise_error(bb_msg_requires_arg, "-c"); |
| 8763 | sflag = 1; | 8741 | sflag = 1; |
| 8764 | } | 8742 | } |
| 8765 | if (iflag == 2 && sflag == 1 && isatty(0) && isatty(1)) | 8743 | if (iflag == 2 && sflag == 1 && isatty(0) && isatty(1)) |
| @@ -8824,7 +8802,7 @@ static void minus_o(char *name, int val) | |||
| 8824 | optlist[i] = val; | 8802 | optlist[i] = val; |
| 8825 | return; | 8803 | return; |
| 8826 | } | 8804 | } |
| 8827 | sh_error("Illegal option -o %s", name); | 8805 | ash_msg_and_raise_error("Illegal option -o %s", name); |
| 8828 | } | 8806 | } |
| 8829 | } | 8807 | } |
| 8830 | 8808 | ||
| @@ -8893,7 +8871,7 @@ setoption(int flag, int val) | |||
| 8893 | optlist[i] = val; | 8871 | optlist[i] = val; |
| 8894 | return; | 8872 | return; |
| 8895 | } | 8873 | } |
| 8896 | sh_error("Illegal option -%c", flag); | 8874 | ash_msg_and_raise_error("Illegal option -%c", flag); |
| 8897 | /* NOTREACHED */ | 8875 | /* NOTREACHED */ |
| 8898 | } | 8876 | } |
| 8899 | 8877 | ||
| @@ -8935,8 +8913,8 @@ freeparam(volatile struct shparam *param) | |||
| 8935 | 8913 | ||
| 8936 | if (param->malloc) { | 8914 | if (param->malloc) { |
| 8937 | for (ap = param->p ; *ap ; ap++) | 8915 | for (ap = param->p ; *ap ; ap++) |
| 8938 | ckfree(*ap); | 8916 | free(*ap); |
| 8939 | ckfree(param->p); | 8917 | free(param->p); |
| 8940 | } | 8918 | } |
| 8941 | } | 8919 | } |
| 8942 | 8920 | ||
| @@ -8954,12 +8932,12 @@ shiftcmd(int argc, char **argv) | |||
| 8954 | if (argc > 1) | 8932 | if (argc > 1) |
| 8955 | n = number(argv[1]); | 8933 | n = number(argv[1]); |
| 8956 | if (n > shellparam.nparam) | 8934 | if (n > shellparam.nparam) |
| 8957 | sh_error("can't shift that many"); | 8935 | ash_msg_and_raise_error("can't shift that many"); |
| 8958 | INTOFF; | 8936 | INT_OFF; |
| 8959 | shellparam.nparam -= n; | 8937 | shellparam.nparam -= n; |
| 8960 | for (ap1 = shellparam.p ; --n >= 0 ; ap1++) { | 8938 | for (ap1 = shellparam.p ; --n >= 0 ; ap1++) { |
| 8961 | if (shellparam.malloc) | 8939 | if (shellparam.malloc) |
| 8962 | ckfree(*ap1); | 8940 | free(*ap1); |
| 8963 | } | 8941 | } |
| 8964 | ap2 = shellparam.p; | 8942 | ap2 = shellparam.p; |
| 8965 | while ((*ap2++ = *ap1++) != NULL); | 8943 | while ((*ap2++ = *ap1++) != NULL); |
| @@ -8967,7 +8945,7 @@ shiftcmd(int argc, char **argv) | |||
| 8967 | shellparam.optind = 1; | 8945 | shellparam.optind = 1; |
| 8968 | shellparam.optoff = -1; | 8946 | shellparam.optoff = -1; |
| 8969 | #endif | 8947 | #endif |
| 8970 | INTON; | 8948 | INT_ON; |
| 8971 | return 0; | 8949 | return 0; |
| 8972 | } | 8950 | } |
| 8973 | 8951 | ||
| @@ -8980,13 +8958,13 @@ setcmd(int argc, char **argv) | |||
| 8980 | { | 8958 | { |
| 8981 | if (argc == 1) | 8959 | if (argc == 1) |
| 8982 | return showvars(nullstr, 0, VUNSET); | 8960 | return showvars(nullstr, 0, VUNSET); |
| 8983 | INTOFF; | 8961 | INT_OFF; |
| 8984 | options(0); | 8962 | options(0); |
| 8985 | optschanged(); | 8963 | optschanged(); |
| 8986 | if (*argptr != NULL) { | 8964 | if (*argptr != NULL) { |
| 8987 | setparam(argptr); | 8965 | setparam(argptr); |
| 8988 | } | 8966 | } |
| 8989 | INTON; | 8967 | INT_ON; |
| 8990 | return 0; | 8968 | return 0; |
| 8991 | } | 8969 | } |
| 8992 | 8970 | ||
| @@ -9119,8 +9097,8 @@ getopts(char *optstr, char *optvar, char **optfirst, int *param_optind, int *opt | |||
| 9119 | if (err) { | 9097 | if (err) { |
| 9120 | *param_optind = 1; | 9098 | *param_optind = 1; |
| 9121 | *optoff = -1; | 9099 | *optoff = -1; |
| 9122 | flushall(); | 9100 | flush_stdout_stderr(); |
| 9123 | exraise(EXERROR); | 9101 | raise_exception(EXERROR); |
| 9124 | } | 9102 | } |
| 9125 | return done; | 9103 | return done; |
| 9126 | } | 9104 | } |
| @@ -9138,7 +9116,7 @@ getoptscmd(int argc, char **argv) | |||
| 9138 | char **optbase; | 9116 | char **optbase; |
| 9139 | 9117 | ||
| 9140 | if (argc < 3) | 9118 | if (argc < 3) |
| 9141 | sh_error("Usage: getopts optstring var [arg]"); | 9119 | ash_msg_and_raise_error("Usage: getopts optstring var [arg]"); |
| 9142 | else if (argc == 3) { | 9120 | else if (argc == 3) { |
| 9143 | optbase = shellparam.p; | 9121 | optbase = shellparam.p; |
| 9144 | if (shellparam.optind > shellparam.nparam + 1) { | 9122 | if (shellparam.optind > shellparam.nparam + 1) { |
| @@ -9187,13 +9165,13 @@ nextopt(const char *optstring) | |||
| 9187 | c = *p++; | 9165 | c = *p++; |
| 9188 | for (q = optstring ; *q != c ; ) { | 9166 | for (q = optstring ; *q != c ; ) { |
| 9189 | if (*q == '\0') | 9167 | if (*q == '\0') |
| 9190 | sh_error("Illegal option -%c", c); | 9168 | ash_msg_and_raise_error("Illegal option -%c", c); |
| 9191 | if (*++q == ':') | 9169 | if (*++q == ':') |
| 9192 | q++; | 9170 | q++; |
| 9193 | } | 9171 | } |
| 9194 | if (*++q == ':') { | 9172 | if (*++q == ':') { |
| 9195 | if (*p == '\0' && (p = *argptr++) == NULL) | 9173 | if (*p == '\0' && (p = *argptr++) == NULL) |
| 9196 | sh_error("No arg for -%c option", c); | 9174 | ash_msg_and_raise_error("No arg for -%c option", c); |
| 9197 | optionarg = p; | 9175 | optionarg = p; |
| 9198 | p = NULL; | 9176 | p = NULL; |
| 9199 | } | 9177 | } |
| @@ -9202,73 +9180,6 @@ nextopt(const char *optstring) | |||
| 9202 | } | 9180 | } |
| 9203 | 9181 | ||
| 9204 | 9182 | ||
| 9205 | /* output.c */ | ||
| 9206 | |||
| 9207 | static void | ||
| 9208 | outstr(const char *p, FILE *file) | ||
| 9209 | { | ||
| 9210 | INTOFF; | ||
| 9211 | fputs(p, file); | ||
| 9212 | INTON; | ||
| 9213 | } | ||
| 9214 | |||
| 9215 | static void | ||
| 9216 | flushall(void) | ||
| 9217 | { | ||
| 9218 | INTOFF; | ||
| 9219 | fflush(stdout); | ||
| 9220 | fflush(stderr); | ||
| 9221 | INTON; | ||
| 9222 | } | ||
| 9223 | |||
| 9224 | static void | ||
| 9225 | flusherr(void) | ||
| 9226 | { | ||
| 9227 | INTOFF; | ||
| 9228 | fflush(stderr); | ||
| 9229 | INTON; | ||
| 9230 | } | ||
| 9231 | |||
| 9232 | static void | ||
| 9233 | outcslow(int c, FILE *dest) | ||
| 9234 | { | ||
| 9235 | INTOFF; | ||
| 9236 | putc(c, dest); | ||
| 9237 | fflush(dest); | ||
| 9238 | INTON; | ||
| 9239 | } | ||
| 9240 | |||
| 9241 | |||
| 9242 | static int | ||
| 9243 | out1fmt(const char *fmt, ...) | ||
| 9244 | { | ||
| 9245 | va_list ap; | ||
| 9246 | int r; | ||
| 9247 | |||
| 9248 | INTOFF; | ||
| 9249 | va_start(ap, fmt); | ||
| 9250 | r = vprintf(fmt, ap); | ||
| 9251 | va_end(ap); | ||
| 9252 | INTON; | ||
| 9253 | return r; | ||
| 9254 | } | ||
| 9255 | |||
| 9256 | |||
| 9257 | static int | ||
| 9258 | fmtstr(char *outbuf, size_t length, const char *fmt, ...) | ||
| 9259 | { | ||
| 9260 | va_list ap; | ||
| 9261 | int ret; | ||
| 9262 | |||
| 9263 | va_start(ap, fmt); | ||
| 9264 | INTOFF; | ||
| 9265 | ret = vsnprintf(outbuf, length, fmt, ap); | ||
| 9266 | va_end(ap); | ||
| 9267 | INTON; | ||
| 9268 | return ret; | ||
| 9269 | } | ||
| 9270 | |||
| 9271 | |||
| 9272 | /* parser.c */ | 9183 | /* parser.c */ |
| 9273 | 9184 | ||
| 9274 | 9185 | ||
| @@ -10551,12 +10462,12 @@ parsebackq: { | |||
| 10551 | savepbq = parsebackquote; | 10462 | savepbq = parsebackquote; |
| 10552 | if (setjmp(jmploc.loc)) { | 10463 | if (setjmp(jmploc.loc)) { |
| 10553 | if (str) | 10464 | if (str) |
| 10554 | ckfree(str); | 10465 | free(str); |
| 10555 | parsebackquote = 0; | 10466 | parsebackquote = 0; |
| 10556 | handler = savehandler; | 10467 | handler = savehandler; |
| 10557 | longjmp(handler->loc, 1); | 10468 | longjmp(handler->loc, 1); |
| 10558 | } | 10469 | } |
| 10559 | INTOFF; | 10470 | INT_OFF; |
| 10560 | str = NULL; | 10471 | str = NULL; |
| 10561 | savelen = out - (char *)stackblock(); | 10472 | savelen = out - (char *)stackblock(); |
| 10562 | if (savelen > 0) { | 10473 | if (savelen > 0) { |
| @@ -10565,7 +10476,7 @@ parsebackq: { | |||
| 10565 | } | 10476 | } |
| 10566 | savehandler = handler; | 10477 | savehandler = handler; |
| 10567 | handler = &jmploc; | 10478 | handler = &jmploc; |
| 10568 | INTON; | 10479 | INT_ON; |
| 10569 | if (oldstyle) { | 10480 | if (oldstyle) { |
| 10570 | /* We must read until the closing backquote, giving special | 10481 | /* We must read until the closing backquote, giving special |
| 10571 | treatment to some slashes, and then push the string and | 10482 | treatment to some slashes, and then push the string and |
| @@ -10669,10 +10580,10 @@ parsebackq: { | |||
| 10669 | if (str) { | 10580 | if (str) { |
| 10670 | memcpy(out, str, savelen); | 10581 | memcpy(out, str, savelen); |
| 10671 | STADJUST(savelen, out); | 10582 | STADJUST(savelen, out); |
| 10672 | INTOFF; | 10583 | INT_OFF; |
| 10673 | ckfree(str); | 10584 | free(str); |
| 10674 | str = NULL; | 10585 | str = NULL; |
| 10675 | INTON; | 10586 | INT_ON; |
| 10676 | } | 10587 | } |
| 10677 | parsebackquote = savepbq; | 10588 | parsebackquote = savepbq; |
| 10678 | handler = savehandler; | 10589 | handler = savehandler; |
| @@ -10776,7 +10687,7 @@ static void synexpect(int token) | |||
| 10776 | static void | 10687 | static void |
| 10777 | synerror(const char *msg) | 10688 | synerror(const char *msg) |
| 10778 | { | 10689 | { |
| 10779 | sh_error("Syntax error: %s", msg); | 10690 | ash_msg_and_raise_error("Syntax error: %s", msg); |
| 10780 | /* NOTREACHED */ | 10691 | /* NOTREACHED */ |
| 10781 | } | 10692 | } |
| 10782 | 10693 | ||
| @@ -10925,7 +10836,7 @@ static int openhere(union node *redir) | |||
| 10925 | size_t len = 0; | 10836 | size_t len = 0; |
| 10926 | 10837 | ||
| 10927 | if (pipe(pip) < 0) | 10838 | if (pipe(pip) < 0) |
| 10928 | sh_error("Pipe call failed"); | 10839 | ash_msg_and_raise_error("Pipe call failed"); |
| 10929 | if (redir->type == NHERE) { | 10840 | if (redir->type == NHERE) { |
| 10930 | len = strlen(redir->nhere.doc->narg.text); | 10841 | len = strlen(redir->nhere.doc->narg.text); |
| 10931 | if (len <= PIPESIZE) { | 10842 | if (len <= PIPESIZE) { |
| @@ -11011,9 +10922,9 @@ openredirect(union node *redir) | |||
| 11011 | 10922 | ||
| 11012 | return f; | 10923 | return f; |
| 11013 | ecreate: | 10924 | ecreate: |
| 11014 | sh_error("cannot create %s: %s", fname, errmsg(errno, E_CREAT)); | 10925 | ash_msg_and_raise_error("cannot create %s: %s", fname, errmsg(errno, "Directory nonexistent")); |
| 11015 | eopen: | 10926 | eopen: |
| 11016 | sh_error("cannot open %s: %s", fname, errmsg(errno, E_OPEN)); | 10927 | ash_msg_and_raise_error("cannot open %s: %s", fname, errmsg(errno, "No such file")); |
| 11017 | } | 10928 | } |
| 11018 | 10929 | ||
| 11019 | static void dupredirect(union node *redir, int f) | 10930 | static void dupredirect(union node *redir, int f) |
| @@ -11055,7 +10966,7 @@ redirect(union node *redir, int flags) | |||
| 11055 | return; | 10966 | return; |
| 11056 | } | 10967 | } |
| 11057 | sv = NULL; | 10968 | sv = NULL; |
| 11058 | INTOFF; | 10969 | INT_OFF; |
| 11059 | if (flags & REDIR_PUSH) { | 10970 | if (flags & REDIR_PUSH) { |
| 11060 | struct redirtab *q; | 10971 | struct redirtab *q; |
| 11061 | q = ckmalloc(sizeof(struct redirtab)); | 10972 | q = ckmalloc(sizeof(struct redirtab)); |
| @@ -11085,7 +10996,7 @@ redirect(union node *redir, int flags) | |||
| 11085 | if (i != EBADF) { | 10996 | if (i != EBADF) { |
| 11086 | close(newfd); | 10997 | close(newfd); |
| 11087 | errno = i; | 10998 | errno = i; |
| 11088 | sh_error("%d: %m", fd); | 10999 | ash_msg_and_raise_error("%d: %m", fd); |
| 11089 | /* NOTREACHED */ | 11000 | /* NOTREACHED */ |
| 11090 | } | 11001 | } |
| 11091 | } else { | 11002 | } else { |
| @@ -11097,7 +11008,7 @@ redirect(union node *redir, int flags) | |||
| 11097 | } | 11008 | } |
| 11098 | dupredirect(n, newfd); | 11009 | dupredirect(n, newfd); |
| 11099 | } while ((n = n->nfile.next)); | 11010 | } while ((n = n->nfile.next)); |
| 11100 | INTON; | 11011 | INT_ON; |
| 11101 | if (flags & REDIR_SAVEFD2 && sv && sv->renamed[2] >= 0) | 11012 | if (flags & REDIR_SAVEFD2 && sv && sv->renamed[2] >= 0) |
| 11102 | preverrout_fd = sv->renamed[2]; | 11013 | preverrout_fd = sv->renamed[2]; |
| 11103 | } | 11014 | } |
| @@ -11114,7 +11025,7 @@ popredir(int drop) | |||
| 11114 | 11025 | ||
| 11115 | if (--nullredirs >= 0) | 11026 | if (--nullredirs >= 0) |
| 11116 | return; | 11027 | return; |
| 11117 | INTOFF; | 11028 | INT_OFF; |
| 11118 | rp = redirlist; | 11029 | rp = redirlist; |
| 11119 | for (i = 0 ; i < 10 ; i++) { | 11030 | for (i = 0 ; i < 10 ; i++) { |
| 11120 | if (rp->renamed[i] != EMPTY) { | 11031 | if (rp->renamed[i] != EMPTY) { |
| @@ -11127,8 +11038,8 @@ popredir(int drop) | |||
| 11127 | } | 11038 | } |
| 11128 | redirlist = rp->next; | 11039 | redirlist = rp->next; |
| 11129 | nullredirs = rp->nullredirs; | 11040 | nullredirs = rp->nullredirs; |
| 11130 | ckfree(rp); | 11041 | free(rp); |
| 11131 | INTON; | 11042 | INT_ON; |
| 11132 | } | 11043 | } |
| 11133 | 11044 | ||
| 11134 | /* | 11045 | /* |
| @@ -11165,7 +11076,7 @@ copyfd(int from, int to) | |||
| 11165 | if (errno == EMFILE) | 11076 | if (errno == EMFILE) |
| 11166 | return EMPTY; | 11077 | return EMPTY; |
| 11167 | else | 11078 | else |
| 11168 | sh_error("%d: %m", from); | 11079 | ash_msg_and_raise_error("%d: %m", from); |
| 11169 | } | 11080 | } |
| 11170 | return newfd; | 11081 | return newfd; |
| 11171 | } | 11082 | } |
| @@ -11179,7 +11090,7 @@ redirectsafe(union node *redir, int flags) | |||
| 11179 | struct jmploc *volatile savehandler = handler; | 11090 | struct jmploc *volatile savehandler = handler; |
| 11180 | struct jmploc jmploc; | 11091 | struct jmploc jmploc; |
| 11181 | 11092 | ||
| 11182 | SAVEINT(saveint); | 11093 | SAVE_INT(saveint); |
| 11183 | err = setjmp(jmploc.loc) * 2; | 11094 | err = setjmp(jmploc.loc) * 2; |
| 11184 | if (!err) { | 11095 | if (!err) { |
| 11185 | handler = &jmploc; | 11096 | handler = &jmploc; |
| @@ -11188,7 +11099,7 @@ redirectsafe(union node *redir, int flags) | |||
| 11188 | handler = savehandler; | 11099 | handler = savehandler; |
| 11189 | if (err && exception != EXERROR) | 11100 | if (err && exception != EXERROR) |
| 11190 | longjmp(handler->loc, 1); | 11101 | longjmp(handler->loc, 1); |
| 11191 | RESTOREINT(saveint); | 11102 | RESTORE_INT(saveint); |
| 11192 | return err; | 11103 | return err; |
| 11193 | } | 11104 | } |
| 11194 | 11105 | ||
| @@ -11585,8 +11496,8 @@ trapcmd(int argc, char **argv) | |||
| 11585 | while (*ap) { | 11496 | while (*ap) { |
| 11586 | signo = get_signum(*ap); | 11497 | signo = get_signum(*ap); |
| 11587 | if (signo < 0) | 11498 | if (signo < 0) |
| 11588 | sh_error("%s: bad trap", *ap); | 11499 | ash_msg_and_raise_error("%s: bad trap", *ap); |
| 11589 | INTOFF; | 11500 | INT_OFF; |
| 11590 | if (action) { | 11501 | if (action) { |
| 11591 | if (LONE_DASH(action)) | 11502 | if (LONE_DASH(action)) |
| 11592 | action = NULL; | 11503 | action = NULL; |
| @@ -11594,11 +11505,11 @@ trapcmd(int argc, char **argv) | |||
| 11594 | action = savestr(action); | 11505 | action = savestr(action); |
| 11595 | } | 11506 | } |
| 11596 | if (trap[signo]) | 11507 | if (trap[signo]) |
| 11597 | ckfree(trap[signo]); | 11508 | free(trap[signo]); |
| 11598 | trap[signo] = action; | 11509 | trap[signo] = action; |
| 11599 | if (signo != 0) | 11510 | if (signo != 0) |
| 11600 | setsignal(signo); | 11511 | setsignal(signo); |
| 11601 | INTON; | 11512 | INT_ON; |
| 11602 | ap++; | 11513 | ap++; |
| 11603 | } | 11514 | } |
| 11604 | return 0; | 11515 | return 0; |
| @@ -11615,12 +11526,12 @@ clear_traps(void) | |||
| 11615 | 11526 | ||
| 11616 | for (tp = trap ; tp < &trap[NSIG] ; tp++) { | 11527 | for (tp = trap ; tp < &trap[NSIG] ; tp++) { |
| 11617 | if (*tp && **tp) { /* trap not NULL or SIG_IGN */ | 11528 | if (*tp && **tp) { /* trap not NULL or SIG_IGN */ |
| 11618 | INTOFF; | 11529 | INT_OFF; |
| 11619 | ckfree(*tp); | 11530 | free(*tp); |
| 11620 | *tp = NULL; | 11531 | *tp = NULL; |
| 11621 | if (tp != &trap[0]) | 11532 | if (tp != &trap[0]) |
| 11622 | setsignal(tp - trap); | 11533 | setsignal(tp - trap); |
| 11623 | INTON; | 11534 | INT_ON; |
| 11624 | } | 11535 | } |
| 11625 | } | 11536 | } |
| 11626 | } | 11537 | } |
| @@ -11738,7 +11649,7 @@ onsig(int signo) | |||
| 11738 | 11649 | ||
| 11739 | if (exsig || (signo == SIGINT && !trap[SIGINT])) { | 11650 | if (exsig || (signo == SIGINT && !trap[SIGINT])) { |
| 11740 | if (!suppressint) | 11651 | if (!suppressint) |
| 11741 | onint(); | 11652 | raise_interrupt(); |
| 11742 | intpending = 1; | 11653 | intpending = 1; |
| 11743 | } | 11654 | } |
| 11744 | } | 11655 | } |
| @@ -11868,7 +11779,7 @@ exitshell(void) | |||
| 11868 | trap[0] = NULL; | 11779 | trap[0] = NULL; |
| 11869 | evalstring(p, 0); | 11780 | evalstring(p, 0); |
| 11870 | } | 11781 | } |
| 11871 | flushall(); | 11782 | flush_stdout_stderr(); |
| 11872 | out: | 11783 | out: |
| 11873 | setjobctl(0); | 11784 | setjobctl(0); |
| 11874 | _exit(status); | 11785 | _exit(status); |
| @@ -11899,7 +11810,7 @@ setvarsafe(const char *name, const char *val, int flags) | |||
| 11899 | struct jmploc *volatile savehandler = handler; | 11810 | struct jmploc *volatile savehandler = handler; |
| 11900 | struct jmploc jmploc; | 11811 | struct jmploc jmploc; |
| 11901 | 11812 | ||
| 11902 | SAVEINT(saveint); | 11813 | SAVE_INT(saveint); |
| 11903 | if (setjmp(jmploc.loc)) | 11814 | if (setjmp(jmploc.loc)) |
| 11904 | err = 1; | 11815 | err = 1; |
| 11905 | else { | 11816 | else { |
| @@ -11908,7 +11819,7 @@ setvarsafe(const char *name, const char *val, int flags) | |||
| 11908 | err = 0; | 11819 | err = 0; |
| 11909 | } | 11820 | } |
| 11910 | handler = savehandler; | 11821 | handler = savehandler; |
| 11911 | RESTOREINT(saveint); | 11822 | RESTORE_INT(saveint); |
| 11912 | return err; | 11823 | return err; |
| 11913 | } | 11824 | } |
| 11914 | #endif | 11825 | #endif |
| @@ -11930,14 +11841,14 @@ setvar(const char *name, const char *val, int flags) | |||
| 11930 | p = strchrnul(q, '='); | 11841 | p = strchrnul(q, '='); |
| 11931 | namelen = p - name; | 11842 | namelen = p - name; |
| 11932 | if (!namelen || p != q) | 11843 | if (!namelen || p != q) |
| 11933 | sh_error("%.*s: bad variable name", namelen, name); | 11844 | ash_msg_and_raise_error("%.*s: bad variable name", namelen, name); |
| 11934 | vallen = 0; | 11845 | vallen = 0; |
| 11935 | if (val == NULL) { | 11846 | if (val == NULL) { |
| 11936 | flags |= VUNSET; | 11847 | flags |= VUNSET; |
| 11937 | } else { | 11848 | } else { |
| 11938 | vallen = strlen(val); | 11849 | vallen = strlen(val); |
| 11939 | } | 11850 | } |
| 11940 | INTOFF; | 11851 | INT_OFF; |
| 11941 | nameeq = ckmalloc(namelen + vallen + 2); | 11852 | nameeq = ckmalloc(namelen + vallen + 2); |
| 11942 | p = memcpy(nameeq, name, namelen) + namelen; | 11853 | p = memcpy(nameeq, name, namelen) + namelen; |
| 11943 | if (val) { | 11854 | if (val) { |
| @@ -11946,7 +11857,7 @@ setvar(const char *name, const char *val, int flags) | |||
| 11946 | } | 11857 | } |
| 11947 | *p = '\0'; | 11858 | *p = '\0'; |
| 11948 | setvareq(nameeq, flags | VNOSAVE); | 11859 | setvareq(nameeq, flags | VNOSAVE); |
| 11949 | INTON; | 11860 | INT_ON; |
| 11950 | } | 11861 | } |
| 11951 | 11862 | ||
| 11952 | 11863 | ||
| @@ -11972,7 +11883,7 @@ setvareq(char *s, int flags) | |||
| 11972 | if (flags & VNOSAVE) | 11883 | if (flags & VNOSAVE) |
| 11973 | free(s); | 11884 | free(s); |
| 11974 | n = vp->text; | 11885 | n = vp->text; |
| 11975 | sh_error("%.*s: is read only", strchrnul(n, '=') - n, n); | 11886 | ash_msg_and_raise_error("%.*s: is read only", strchrnul(n, '=') - n, n); |
| 11976 | } | 11887 | } |
| 11977 | 11888 | ||
| 11978 | if (flags & VNOSET) | 11889 | if (flags & VNOSET) |
| @@ -11982,7 +11893,7 @@ setvareq(char *s, int flags) | |||
| 11982 | (*vp->func)(strchrnul(s, '=') + 1); | 11893 | (*vp->func)(strchrnul(s, '=') + 1); |
| 11983 | 11894 | ||
| 11984 | if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0) | 11895 | if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0) |
| 11985 | ckfree(vp->text); | 11896 | free((char*)vp->text); |
| 11986 | 11897 | ||
| 11987 | flags |= vp->flags & ~(VTEXTFIXED|VSTACK|VNOSAVE|VUNSET); | 11898 | flags |= vp->flags & ~(VTEXTFIXED|VSTACK|VNOSAVE|VUNSET); |
| 11988 | } else { | 11899 | } else { |
| @@ -12011,11 +11922,11 @@ listsetvar(struct strlist *list_set_var, int flags) | |||
| 12011 | 11922 | ||
| 12012 | if (!lp) | 11923 | if (!lp) |
| 12013 | return; | 11924 | return; |
| 12014 | INTOFF; | 11925 | INT_OFF; |
| 12015 | do { | 11926 | do { |
| 12016 | setvareq(lp->text, flags); | 11927 | setvareq(lp->text, flags); |
| 12017 | } while ((lp = lp->next)); | 11928 | } while ((lp = lp->next)); |
| 12018 | INTON; | 11929 | INT_ON; |
| 12019 | } | 11930 | } |
| 12020 | 11931 | ||
| 12021 | 11932 | ||
| @@ -12175,7 +12086,7 @@ static void mklocal(char *name) | |||
| 12175 | struct var **vpp; | 12086 | struct var **vpp; |
| 12176 | struct var *vp; | 12087 | struct var *vp; |
| 12177 | 12088 | ||
| 12178 | INTOFF; | 12089 | INT_OFF; |
| 12179 | lvp = ckmalloc(sizeof(struct localvar)); | 12090 | lvp = ckmalloc(sizeof(struct localvar)); |
| 12180 | if (LONE_DASH(name)) { | 12091 | if (LONE_DASH(name)) { |
| 12181 | char *p; | 12092 | char *p; |
| @@ -12206,7 +12117,7 @@ static void mklocal(char *name) | |||
| 12206 | lvp->vp = vp; | 12117 | lvp->vp = vp; |
| 12207 | lvp->next = localvars; | 12118 | lvp->next = localvars; |
| 12208 | localvars = lvp; | 12119 | localvars = lvp; |
| 12209 | INTON; | 12120 | INT_ON; |
| 12210 | } | 12121 | } |
| 12211 | 12122 | ||
| 12212 | 12123 | ||
| @@ -12242,7 +12153,7 @@ poplocalvars(void) | |||
| 12242 | TRACE(("poplocalvar %s", vp ? vp->text : "-")); | 12153 | TRACE(("poplocalvar %s", vp ? vp->text : "-")); |
| 12243 | if (vp == NULL) { /* $- saved */ | 12154 | if (vp == NULL) { /* $- saved */ |
| 12244 | memcpy(optlist, lvp->text, sizeof(optlist)); | 12155 | memcpy(optlist, lvp->text, sizeof(optlist)); |
| 12245 | ckfree(lvp->text); | 12156 | free((char*)lvp->text); |
| 12246 | optschanged(); | 12157 | optschanged(); |
| 12247 | } else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) { | 12158 | } else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) { |
| 12248 | unsetvar(vp->text); | 12159 | unsetvar(vp->text); |
| @@ -12250,11 +12161,11 @@ poplocalvars(void) | |||
| 12250 | if (vp->func) | 12161 | if (vp->func) |
| 12251 | (*vp->func)(strchrnul(lvp->text, '=') + 1); | 12162 | (*vp->func)(strchrnul(lvp->text, '=') + 1); |
| 12252 | if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0) | 12163 | if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0) |
| 12253 | ckfree(vp->text); | 12164 | free((char*)vp->text); |
| 12254 | vp->flags = lvp->flags; | 12165 | vp->flags = lvp->flags; |
| 12255 | vp->text = lvp->text; | 12166 | vp->text = lvp->text; |
| 12256 | } | 12167 | } |
| 12257 | ckfree(lvp); | 12168 | free(lvp); |
| 12258 | } | 12169 | } |
| 12259 | } | 12170 | } |
| 12260 | 12171 | ||
| @@ -12315,17 +12226,17 @@ unsetvar(const char *s) | |||
| 12315 | if (flags & VUNSET) | 12226 | if (flags & VUNSET) |
| 12316 | goto ok; | 12227 | goto ok; |
| 12317 | if ((flags & VSTRFIXED) == 0) { | 12228 | if ((flags & VSTRFIXED) == 0) { |
| 12318 | INTOFF; | 12229 | INT_OFF; |
| 12319 | if ((flags & (VTEXTFIXED|VSTACK)) == 0) | 12230 | if ((flags & (VTEXTFIXED|VSTACK)) == 0) |
| 12320 | ckfree(vp->text); | 12231 | free((char*)vp->text); |
| 12321 | *vpp = vp->next; | 12232 | *vpp = vp->next; |
| 12322 | ckfree(vp); | 12233 | free(vp); |
| 12323 | INTON; | 12234 | INT_ON; |
| 12324 | } else { | 12235 | } else { |
| 12325 | setvar(s, 0, 0); | 12236 | setvar(s, 0, 0); |
| 12326 | vp->flags &= ~VEXPORT; | 12237 | vp->flags &= ~VEXPORT; |
| 12327 | } | 12238 | } |
| 12328 | ok: | 12239 | ok: |
| 12329 | retval = 0; | 12240 | retval = 0; |
| 12330 | } | 12241 | } |
| 12331 | out: | 12242 | out: |
| @@ -12429,19 +12340,19 @@ dash_arith(const char *s) | |||
| 12429 | arith_t result; | 12340 | arith_t result; |
| 12430 | int errcode = 0; | 12341 | int errcode = 0; |
| 12431 | 12342 | ||
| 12432 | INTOFF; | 12343 | INT_OFF; |
| 12433 | result = arith(s, &errcode); | 12344 | result = arith(s, &errcode); |
| 12434 | if (errcode < 0) { | 12345 | if (errcode < 0) { |
| 12435 | if (errcode == -3) | 12346 | if (errcode == -3) |
| 12436 | sh_error("exponent less than 0"); | 12347 | ash_msg_and_raise_error("exponent less than 0"); |
| 12437 | else if (errcode == -2) | 12348 | else if (errcode == -2) |
| 12438 | sh_error("divide by zero"); | 12349 | ash_msg_and_raise_error("divide by zero"); |
| 12439 | else if (errcode == -5) | 12350 | else if (errcode == -5) |
| 12440 | sh_error("expression recursion loop detected"); | 12351 | ash_msg_and_raise_error("expression recursion loop detected"); |
| 12441 | else | 12352 | else |
| 12442 | synerror(s); | 12353 | synerror(s); |
| 12443 | } | 12354 | } |
| 12444 | INTON; | 12355 | INT_ON; |
| 12445 | 12356 | ||
| 12446 | return result; | 12357 | return result; |
| 12447 | } | 12358 | } |
| @@ -12461,7 +12372,7 @@ letcmd(int argc, char **argv) | |||
| 12461 | 12372 | ||
| 12462 | ap = argv + 1; | 12373 | ap = argv + 1; |
| 12463 | if (!*ap) | 12374 | if (!*ap) |
| 12464 | sh_error("expression expected"); | 12375 | ash_msg_and_raise_error("expression expected"); |
| 12465 | for (ap = argv + 1; *ap; ap++) { | 12376 | for (ap = argv + 1; *ap; ap++) { |
| 12466 | i = dash_arith(*ap); | 12377 | i = dash_arith(*ap); |
| 12467 | } | 12378 | } |
| @@ -12535,7 +12446,7 @@ readcmd(int argc, char **argv) | |||
| 12535 | case 'n': | 12446 | case 'n': |
| 12536 | nchars = strtol(optionarg, &p, 10); | 12447 | nchars = strtol(optionarg, &p, 10); |
| 12537 | if (*p) | 12448 | if (*p) |
| 12538 | sh_error("invalid count"); | 12449 | ash_msg_and_raise_error("invalid count"); |
| 12539 | nch_flag = (nchars > 0); | 12450 | nch_flag = (nchars > 0); |
| 12540 | break; | 12451 | break; |
| 12541 | case 's': | 12452 | case 's': |
| @@ -12552,19 +12463,19 @@ readcmd(int argc, char **argv) | |||
| 12552 | int scale; | 12463 | int scale; |
| 12553 | ts.tv_usec = strtol(p, &p2, 10); | 12464 | ts.tv_usec = strtol(p, &p2, 10); |
| 12554 | if (*p2) | 12465 | if (*p2) |
| 12555 | sh_error("invalid timeout"); | 12466 | ash_msg_and_raise_error("invalid timeout"); |
| 12556 | scale = p2 - p; | 12467 | scale = p2 - p; |
| 12557 | /* normalize to usec */ | 12468 | /* normalize to usec */ |
| 12558 | if (scale > 6) | 12469 | if (scale > 6) |
| 12559 | sh_error("invalid timeout"); | 12470 | ash_msg_and_raise_error("invalid timeout"); |
| 12560 | while (scale++ < 6) | 12471 | while (scale++ < 6) |
| 12561 | ts.tv_usec *= 10; | 12472 | ts.tv_usec *= 10; |
| 12562 | } | 12473 | } |
| 12563 | } else if (*p) { | 12474 | } else if (*p) { |
| 12564 | sh_error("invalid timeout"); | 12475 | ash_msg_and_raise_error("invalid timeout"); |
| 12565 | } | 12476 | } |
| 12566 | if ( ! ts.tv_sec && ! ts.tv_usec) | 12477 | if ( ! ts.tv_sec && ! ts.tv_usec) |
| 12567 | sh_error("invalid timeout"); | 12478 | ash_msg_and_raise_error("invalid timeout"); |
| 12568 | break; | 12479 | break; |
| 12569 | #endif | 12480 | #endif |
| 12570 | case 'r': | 12481 | case 'r': |
| @@ -12579,7 +12490,7 @@ readcmd(int argc, char **argv) | |||
| 12579 | } | 12490 | } |
| 12580 | ap = argptr; | 12491 | ap = argptr; |
| 12581 | if (*ap == NULL) | 12492 | if (*ap == NULL) |
| 12582 | sh_error("arg count"); | 12493 | ash_msg_and_raise_error("arg count"); |
| 12583 | ifs = bltinlookup("IFS"); | 12494 | ifs = bltinlookup("IFS"); |
| 12584 | if (ifs == NULL) | 12495 | if (ifs == NULL) |
| 12585 | ifs = defifs; | 12496 | ifs = defifs; |
| @@ -12691,10 +12602,10 @@ static int umaskcmd(int argc, char **argv) | |||
| 12691 | symbolic_mode = 1; | 12602 | symbolic_mode = 1; |
| 12692 | } | 12603 | } |
| 12693 | 12604 | ||
| 12694 | INTOFF; | 12605 | INT_OFF; |
| 12695 | mask = umask(0); | 12606 | mask = umask(0); |
| 12696 | umask(mask); | 12607 | umask(mask); |
| 12697 | INTON; | 12608 | INT_ON; |
| 12698 | 12609 | ||
| 12699 | ap = *argptr; | 12610 | ap = *argptr; |
| 12700 | if (ap == NULL) { | 12611 | if (ap == NULL) { |
| @@ -12724,14 +12635,14 @@ static int umaskcmd(int argc, char **argv) | |||
| 12724 | mask = 0; | 12635 | mask = 0; |
| 12725 | do { | 12636 | do { |
| 12726 | if (*ap >= '8' || *ap < '0') | 12637 | if (*ap >= '8' || *ap < '0') |
| 12727 | sh_error(illnum, argv[1]); | 12638 | ash_msg_and_raise_error(illnum, argv[1]); |
| 12728 | mask = (mask << 3) + (*ap - '0'); | 12639 | mask = (mask << 3) + (*ap - '0'); |
| 12729 | } while (*++ap != '\0'); | 12640 | } while (*++ap != '\0'); |
| 12730 | umask(mask); | 12641 | umask(mask); |
| 12731 | } else { | 12642 | } else { |
| 12732 | mask = ~mask & 0777; | 12643 | mask = ~mask & 0777; |
| 12733 | if (!bb_parse_mode(ap, &mask)) { | 12644 | if (!bb_parse_mode(ap, &mask)) { |
| 12734 | sh_error("Illegal mode: %s", ap); | 12645 | ash_msg_and_raise_error("Illegal mode: %s", ap); |
| 12735 | } | 12646 | } |
| 12736 | umask(~mask & 0777); | 12647 | umask(~mask & 0777); |
| 12737 | } | 12648 | } |
| @@ -12881,7 +12792,7 @@ ulimitcmd(int argc, char **argv) | |||
| 12881 | char *p = *argptr; | 12792 | char *p = *argptr; |
| 12882 | 12793 | ||
| 12883 | if (all || argptr[1]) | 12794 | if (all || argptr[1]) |
| 12884 | sh_error("too many arguments"); | 12795 | ash_msg_and_raise_error("too many arguments"); |
| 12885 | if (strncmp(p, "unlimited\n", 9) == 0) | 12796 | if (strncmp(p, "unlimited\n", 9) == 0) |
| 12886 | val = RLIM_INFINITY; | 12797 | val = RLIM_INFINITY; |
| 12887 | else { | 12798 | else { |
| @@ -12893,7 +12804,7 @@ ulimitcmd(int argc, char **argv) | |||
| 12893 | break; | 12804 | break; |
| 12894 | } | 12805 | } |
| 12895 | if (c) | 12806 | if (c) |
| 12896 | sh_error("bad number"); | 12807 | ash_msg_and_raise_error("bad number"); |
| 12897 | val *= l->factor; | 12808 | val *= l->factor; |
| 12898 | } | 12809 | } |
| 12899 | } | 12810 | } |
| @@ -12913,7 +12824,7 @@ ulimitcmd(int argc, char **argv) | |||
| 12913 | if (how & SOFT) | 12824 | if (how & SOFT) |
| 12914 | limit.rlim_cur = val; | 12825 | limit.rlim_cur = val; |
| 12915 | if (setrlimit(l->cmd, &limit) < 0) | 12826 | if (setrlimit(l->cmd, &limit) < 0) |
| 12916 | sh_error("error setting limit (%m)"); | 12827 | ash_msg_and_raise_error("error setting limit (%m)"); |
| 12917 | } else { | 12828 | } else { |
| 12918 | printlim(how, &limit, l); | 12829 | printlim(how, &limit, l); |
| 12919 | } | 12830 | } |
