diff --git a/alloc.c b/alloc.c index db16f9a..68c4b8c 100644 --- a/alloc.c +++ b/alloc.c @@ -29,7 +29,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/alloc.c,v 1.4 2007/03/04 03:04:23 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/alloc.c,v 1.5 2007/05/13 17:51:20 tg Exp $"); struct link { struct link *prev; @@ -64,7 +64,7 @@ alloc(size_t size, Area *ap) struct link *l; if ((l = malloc(sizeof (struct link) + size)) == NULL) - internal_errorf(1, "unable to allocate memory"); + internal_errorf("unable to allocate memory"); l->next = ap->freelist; l->prev = NULL; if (ap->freelist) @@ -87,7 +87,7 @@ aresize(void *ptr, size_t size, Area *ap) lnext = l->next; if ((l2 = realloc(l, sizeof (struct link) + size)) == NULL) - internal_errorf(1, "unable to allocate memory"); + internal_errorf("unable to allocate memory"); if (lprev) lprev->next = l2; else diff --git a/edit.c b/edit.c index d3303e9..cc8c7a0 100644 --- a/edit.c +++ b/edit.c @@ -5,7 +5,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.90 2007/05/10 19:08:48 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.91 2007/05/13 17:51:20 tg Exp $"); /* tty driver characters we are interested in */ typedef struct { @@ -303,7 +303,7 @@ x_file_glob(int flags __unused, const char *str, int slen, char ***wordsp) source = s; if (yylex(ONEWORD | LQCHAR) != LWORD) { source = sold; - internal_errorf(0, "fileglob: substitute error"); + internal_warningf("fileglob: substitute error"); return 0; } source = sold; @@ -4943,7 +4943,7 @@ grabhist(int save, int n) } (void)histnum(n); if ((hptr = *histpos()) == NULL) { - internal_errorf(0, "grabhist: bad history array"); + internal_warningf("grabhist: bad history array"); return -1; } if (save) diff --git a/eval.c b/eval.c index 0dcf363..24c3d17 100644 --- a/eval.c +++ b/eval.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.25 2007/03/14 02:41:08 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.26 2007/05/13 17:51:21 tg Exp $"); #ifdef MKSH_SMALL #define MKSH_NOPWNAM @@ -63,7 +63,7 @@ substitute(const char *cp, int f) s->start = s->str = cp; source = s; if (yylex(ONEWORD) != LWORD) - internal_errorf(1, "substitute"); + internal_errorf("substitute"); source = sold; afree(s, ATEMP); return evalstr(yylval.cp, f); @@ -168,7 +168,7 @@ expand(const char *cp, /* input word */ size_t len; if (cp == NULL) - internal_errorf(1, "expand(NULL)"); + internal_errorf("expand(NULL)"); /* for alias, readonly, set, typeset commands */ if ((f & DOVACHECK) && is_wdvarassign(cp)) { f &= ~(DOVACHECK|DOBLANK|DOGLOB|DOTILDE); @@ -580,7 +580,7 @@ expand(const char *cp, /* input word */ if ((p = str_nsave(null, 0, ATEMP)) == NULL) - internal_errorf(1, "unable " + internal_errorf("unable " "to allocate memory"); XPput(*wp, p); } diff --git a/exec.c b/exec.c index f47ea20..880c355 100644 --- a/exec.c +++ b/exec.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.29 2007/04/18 00:59:20 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.30 2007/05/13 17:51:21 tg Exp $"); static int comexec(struct op *, struct tbl *volatile, const char **, int volatile); @@ -617,7 +617,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, /* NOTREACHED */ default: quitenv(NULL); - internal_errorf(1, "CFUNC %d", i); + internal_errorf("CFUNC %d", i); } break; } @@ -756,7 +756,7 @@ shcomexec(const char **wp) tp = ktsearch(&builtins, *wp, hash(*wp)); if (tp == NULL) - internal_errorf(1, "shcomexec: %s", *wp); + internal_errorf("shcomexec: %s", *wp); return (call_builtin(tp, wp)); } @@ -1236,7 +1236,7 @@ herein(const char *content, int sub) s->start = s->str = content; source = s; if (yylex(ONEWORD|HEREDOC) != LWORD) - internal_errorf(1, "herein: yylex"); + internal_errorf("herein: yylex"); source = osource; shf_puts(evalstr(yylval.cp, 0), shf); } else @@ -1459,5 +1459,5 @@ static void dbteste_error(Test_env *te, int offset, const char *msg) { te->flags |= TEF_ERROR; - internal_errorf(0, "dbteste_error: %s (offset %d)", msg, offset); + internal_warningf("dbteste_error: %s (offset %d)", msg, offset); } diff --git a/funcs.c b/funcs.c index d166112..2617e8f 100644 --- a/funcs.c +++ b/funcs.c @@ -5,7 +5,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.49 2007/03/10 18:16:26 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.50 2007/05/13 17:51:21 tg Exp $"); int c_cd(const char **wp) @@ -1245,7 +1245,7 @@ c_getopts(const char **wp) } if (e->loc->next == NULL) { - internal_errorf(0, "c_getopts: no argv"); + internal_warningf("c_getopts: no argv"); return 1; } /* Which arguments are we parsing... */ @@ -2952,7 +2952,7 @@ c_ulimit(const char **wp) for (l = limits; l->name && l->option != what; l++) ; if (!l->name) { - internal_errorf(0, "ulimit: %c", what); + internal_warningf("ulimit: %c", what); return 1; } diff --git a/histrap.c b/histrap.c index c9a8d79..ba6736d 100644 --- a/histrap.c +++ b/histrap.c @@ -3,7 +3,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.45 2007/03/04 03:04:25 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.46 2007/05/13 17:51:22 tg Exp $"); Trap sigtraps[NSIG + 1]; static struct sigaction Sigact_ign, Sigact_trap; @@ -1359,7 +1359,7 @@ setexecsig(Trap *p, int restore) { /* XXX debugging */ if (!(p->flags & (TF_ORIG_IGN|TF_ORIG_DFL))) - internal_errorf(1, "setexecsig: unset signal %d(%s)", + internal_errorf("setexecsig: unset signal %d(%s)", p->signal, p->name); /* restore original value for exec'd kids */ diff --git a/jobs.c b/jobs.c index 53dc12f..5f7ea3b 100644 --- a/jobs.c +++ b/jobs.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.21 2007/04/19 12:07:46 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.22 2007/05/13 17:51:22 tg Exp $"); /* Order important! */ #define PRUNNING 0 @@ -319,11 +319,11 @@ exchild(struct op *t, int flags, p->pid = 0; /* link process into jobs list */ - if (flags&XPIPEI) { /* continuing with a pipe */ + if (flags & XPIPEI) { /* continuing with a pipe */ if (!last_job) - internal_errorf(1, + internal_errorf( "exchild: XPIPEI and no last_job - pid %d", - (int) procpid); + (int)procpid); j = last_job; last_proc->next = p; last_proc = p; @@ -427,7 +427,7 @@ exchild(struct op *t, int flags, tty_close(); cleartraps(); execute(t, (flags & XERROK) | XEXEC); /* no return */ - internal_errorf(0, "exchild: execute() returned"); + internal_warningf("exchild: execute() returned"); #ifndef MKSH_SMALL fptreef(shl_out, 2, "exchild: tried to execute {\n%T\n}\n", t); shf_flush(shl_out); @@ -496,7 +496,7 @@ waitlast(void) if (!j) warningf(true, "waitlast: no last job"); else - internal_errorf(0, "waitlast: not started"); + internal_warningf("waitlast: not started"); sigprocmask(SIG_SETMASK, &omask, NULL); return 125; /* not so arbitrary, non-zero value */ } @@ -838,7 +838,7 @@ j_set_async(Job *j) if (async_job && (async_job->flags & (JF_KNOWN|JF_ZOMBIE)) == JF_ZOMBIE) remove_job(async_job, "async"); if (!(j->flags & JF_STARTED)) { - internal_errorf(0, "j_async: job not started"); + internal_warningf("j_async: job not started"); return; } async_job = j; @@ -852,8 +852,8 @@ j_set_async(Job *j) if (!oldest) { /* XXX debugging */ if (!(async_job->flags & JF_ZOMBIE) || nzombie != 1) { - internal_errorf(0, - "j_async: bad nzombie (%d)", nzombie); + internal_warningf("j_async: bad nzombie (%d)", + nzombie); nzombie = 0; } break; @@ -1094,7 +1094,7 @@ check_job(Job *j) /* XXX debugging (nasty - interrupt routine using shl_out) */ if (!(j->flags & JF_STARTED)) { - internal_errorf(0, "check_job: job started (flags 0x%x)", + internal_warningf("check_job: job started (flags 0x%x)", j->flags); return; } @@ -1448,7 +1448,7 @@ remove_job(Job *j, const char *where) for (; curr != NULL && curr != j; prev = &curr->next, curr = *prev) ; if (curr != j) { - internal_errorf(0, "remove_job: job not found (%s)", where); + internal_warningf("remove_job: job not found (%s)", where); return; } *prev = curr->next; diff --git a/main.c b/main.c index c4d37ab..ef29a52 100644 --- a/main.c +++ b/main.c @@ -13,7 +13,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.74 2007/04/15 10:45:59 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.75 2007/05/13 17:51:22 tg Exp $"); extern char **environ; @@ -414,7 +414,7 @@ include(const char *name, int argc, const char **argv, int intr_ok) unwind(i); /* NOTREACHED */ default: - internal_errorf(1, "include: %d", i); + internal_errorf("include: %d", i); /* NOTREACHED */ } } @@ -498,7 +498,7 @@ shell(Source * volatile s, volatile int toplevel) default: source = old_source; quitenv(NULL); - internal_errorf(1, "shell: %d", i); + internal_errorf("shell: %d", i); /* NOTREACHED */ } } @@ -825,20 +825,36 @@ bi_errorf(const char *fmt, ...) } /* Called when something that shouldn't happen does */ +static void internal_verrorf(const char *, va_list) + __attribute__((format (printf, 1, 0))); +static void +internal_verrorf(const char *fmt, va_list ap) +{ + shf_fprintf(shl_out, "internal error: "); + shf_vfprintf(shl_out, fmt, ap); + shf_putchar('\n', shl_out); + shf_flush(shl_out); +} + void -internal_errorf(int jump, const char *fmt, ...) +internal_errorf(const char *fmt, ...) { va_list va; - error_prefix(true); - shf_fprintf(shl_out, "internal error: "); va_start(va, fmt); - shf_vfprintf(shl_out, fmt, va); + internal_verrorf(fmt, va); + va_end(va); + unwind(LERROR); +} + +void +internal_warningf(const char *fmt, ...) +{ + va_list va; + + va_start(va, fmt); + internal_verrorf(fmt, va); va_end(va); - shf_putchar('\n', shl_out); - shf_flush(shl_out); - if (jump) - unwind(LERROR); } /* used by error reporting functions to print "ksh: .kshrc[25]: " */ @@ -877,7 +893,7 @@ shprintf(const char *fmt, ...) va_list va; if (!shl_stdout_ok) - internal_errorf(1, "shl_stdout not valid"); + internal_errorf("shl_stdout not valid"); va_start(va, fmt); shf_vfprintf(shl_stdout, fmt, va); va_end(va); diff --git a/misc.c b/misc.c index b4215d7..b12b4fb 100644 --- a/misc.c +++ b/misc.c @@ -6,7 +6,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.52 2007/03/04 03:04:26 tg Exp $\t" +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.53 2007/05/13 17:51:23 tg Exp $\t" MKSH_SH_H_ID); #undef USE_CHVT @@ -396,10 +396,8 @@ parse_args(const char **argv, set); break; } - if (i == NELEM(options)) { - internal_errorf(1, "parse_args: '%c'", optc); - return -1; /* not reached */ - } + if (i == NELEM(options)) + internal_errorf("parse_args: '%c'", optc); } } if (!(go.info & GI_MINUSMINUS) && argv[go.optind] && diff --git a/sh.h b/sh.h index d457d67..a02e97f 100644 --- a/sh.h +++ b/sh.h @@ -8,7 +8,7 @@ /* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */ -#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.128 2007/05/10 19:08:48 tg Exp $" +#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.129 2007/05/13 17:51:23 tg Exp $" #define MKSH_VERSION "R29 2007/05/10" #if HAVE_SYS_PARAM_H @@ -1344,8 +1344,11 @@ void warningf(bool, const char *, ...) __attribute__((format (printf, 2, 3))); void bi_errorf(const char *, ...) __attribute__((format (printf, 1, 2))); -void internal_errorf(int, const char *, ...) - __attribute__((format (printf, 2, 3))); +void internal_errorf(const char *, ...) + __attribute__((noreturn)) + __attribute__((format (printf, 1, 2))); +void internal_warningf(const char *, ...) + __attribute__((format (printf, 1, 2))); void error_prefix(bool); void shellf(const char *, ...) __attribute__((format (printf, 1, 2))); diff --git a/shf.c b/shf.c index e201256..44730c8 100644 --- a/shf.c +++ b/shf.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.13 2007/03/10 18:16:28 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.14 2007/05/13 17:51:23 tg Exp $"); /* flags to shf_emptybuf() */ #define EB_READSW 0x01 /* about to switch to reading */ @@ -88,7 +88,7 @@ shf_fdopen(int fd, int sflags, struct shf *shf) } if (!(sflags & (SHF_RD | SHF_WR))) - internal_errorf(1, "shf_fdopen: missing read/write"); + internal_errorf("shf_fdopen: missing read/write"); if (shf) { if (bsize) { @@ -145,9 +145,9 @@ shf_reopen(int fd, int sflags, struct shf *shf) } if (!(sflags & (SHF_RD | SHF_WR))) - internal_errorf(1, "shf_reopen: missing read/write"); + internal_errorf("shf_reopen: missing read/write"); if (!shf || !shf->buf || shf->bsize < bsize) - internal_errorf(1, "shf_reopen: bad shf/buf/bsize"); + internal_errorf("shf_reopen: bad shf/buf/bsize"); /* assumes shf->buf and shf->bsize already set up */ shf->fd = fd; @@ -177,7 +177,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf) /* can't have a read+write string */ if (!(sflags & (SHF_RD | SHF_WR)) || (sflags & (SHF_RD | SHF_WR)) == (SHF_RD | SHF_WR)) - internal_errorf(1, "shf_sopen: flags 0x%x", sflags); + internal_errorf("shf_sopen: flags 0x%x", sflags); if (!shf) { shf = (struct shf *) alloc(sizeof(struct shf), ATEMP); @@ -270,7 +270,7 @@ shf_flush(struct shf *shf) return (shf->flags & SHF_WR) ? EOF : 0; if (shf->fd < 0) - internal_errorf(1, "shf_flush: no fd"); + internal_errorf("shf_flush: no fd"); if (shf->flags & SHF_ERROR) { errno = shf->errno_; @@ -300,7 +300,7 @@ shf_emptybuf(struct shf *shf, int flags) int ret = 0; if (!(shf->flags & SHF_STRING) && shf->fd < 0) - internal_errorf(1, "shf_emptybuf: no fd"); + internal_errorf("shf_emptybuf: no fd"); if (shf->flags & SHF_ERROR) { errno = shf->errno_; @@ -381,7 +381,7 @@ shf_fillbuf(struct shf *shf) return 0; if (shf->fd < 0) - internal_errorf(1, "shf_fillbuf: no fd"); + internal_errorf("shf_fillbuf: no fd"); if (shf->flags & (SHF_EOF | SHF_ERROR)) { if (shf->flags & SHF_ERROR) @@ -427,10 +427,10 @@ shf_read(char *buf, int bsize, struct shf *shf) int ncopy; if (!(shf->flags & SHF_RD)) - internal_errorf(1, "shf_read: flags %x", shf->flags); + internal_errorf("shf_read: flags %x", shf->flags); if (bsize <= 0) - internal_errorf(1, "shf_read: bsize %d", bsize); + internal_errorf("shf_read: bsize %d", bsize); while (bsize > 0) { if (shf->rnleft == 0 && @@ -462,7 +462,7 @@ shf_getse(char *buf, int bsize, struct shf *shf) char *orig_buf = buf; if (!(shf->flags & SHF_RD)) - internal_errorf(1, "shf_getse: flags %x", shf->flags); + internal_errorf("shf_getse: flags %x", shf->flags); if (bsize <= 0) return NULL; @@ -497,7 +497,7 @@ int shf_getchar(struct shf *shf) { if (!(shf->flags & SHF_RD)) - internal_errorf(1, "shf_getchar: flags %x", shf->flags); + internal_errorf("shf_getchar: flags %x", shf->flags); if (shf->rnleft == 0 && (shf_fillbuf(shf) == EOF || shf->rnleft == 0)) return EOF; @@ -512,7 +512,7 @@ int shf_ungetc(int c, struct shf *shf) { if (!(shf->flags & SHF_RD)) - internal_errorf(1, "shf_ungetc: flags %x", shf->flags); + internal_errorf("shf_ungetc: flags %x", shf->flags); if ((shf->flags & SHF_ERROR) || c == EOF || (shf->rp == shf->buf && shf->rnleft)) @@ -547,7 +547,7 @@ int shf_putchar(int c, struct shf *shf) { if (!(shf->flags & SHF_WR)) - internal_errorf(1, "shf_putchar: flags %x", shf->flags); + internal_errorf("shf_putchar: flags %x", shf->flags); if (c == EOF) return EOF; @@ -557,7 +557,7 @@ shf_putchar(int c, struct shf *shf) int n; if (shf->fd < 0) - internal_errorf(1, "shf_putchar: no fd"); + internal_errorf("shf_putchar: no fd"); if (shf->flags & SHF_ERROR) { errno = shf->errno_; return EOF; @@ -603,10 +603,10 @@ shf_write(const char *buf, int nbytes, struct shf *shf) int ncopy; if (!(shf->flags & SHF_WR)) - internal_errorf(1, "shf_write: flags %x", shf->flags); + internal_errorf("shf_write: flags %x", shf->flags); if (nbytes < 0) - internal_errorf(1, "shf_write: nbytes %d", nbytes); + internal_errorf("shf_write: nbytes %d", nbytes); /* Don't buffer if buffer is empty and we're writting a large amount. */ if ((ncopy = shf->wnleft) && @@ -676,8 +676,8 @@ shf_snprintf(char *buf, int bsize, const char *fmt, ...) int n; if (!buf || bsize <= 0) - internal_errorf(1, "shf_snprintf: buf %lx, bsize %d", - (long) buf, bsize); + internal_errorf("shf_snprintf: buf %lx, bsize %d", + (long)buf, bsize); shf_sopen(buf, bsize, SHF_WR, &shf); va_start(args, fmt); diff --git a/tree.c b/tree.c index f035ab2..8f63179 100644 --- a/tree.c +++ b/tree.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.9 2007/03/04 03:04:28 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.10 2007/05/13 17:51:24 tg Exp $"); #define INDENT 4 @@ -519,7 +519,7 @@ wdscan(const char *wp, int c) nest--; break; default: - internal_errorf(0, + internal_warningf( "wdscan: unknown char 0x%x (carrying on)", wp[-1]); } diff --git a/var.c b/var.c index d9e6e60..8ad939d 100644 --- a/var.c +++ b/var.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.37 2007/03/04 03:04:28 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.38 2007/05/13 17:51:24 tg Exp $"); /* * Variables @@ -349,7 +349,7 @@ setstr(struct tbl *vq, const char *s, int error_ok) /* debugging */ if (s >= vq->val.s && s <= vq->val.s + strlen(vq->val.s)) - internal_errorf(true, + internal_errorf( "setstr: %s=%s: assigning to self", vq->name, s); afree((void*)vq->val.s, vq->areap);