ksh: __func__ in warnings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

ksh: __func__ in warnings

Michael W. Bombardieri-2
Hello,

Some errors and warnings printed by ksh have the function name
prefixed. __func__ could be used here instead of hard-coding
the name. The names are wrong for tty_init(), j_set_async(),
j_change(), x_file_glob() and c_ulimit() afaics.

- Michael


Index: c_ksh.c
===================================================================
RCS file: /cvs/src/bin/ksh/c_ksh.c,v
retrieving revision 1.58
diff -u -p -u -r1.58 c_ksh.c
--- c_ksh.c 16 Jan 2018 22:52:32 -0000 1.58
+++ c_ksh.c 13 Mar 2018 08:16:37 -0000
@@ -1273,7 +1273,7 @@ c_getopts(char **wp)
  }
 
  if (genv->loc->next == NULL) {
- internal_warningf("c_getopts: no argv");
+ internal_warningf("%s: no argv", __func__);
  return 1;
  }
  /* Which arguments are we parsing... */
Index: c_ulimit.c
===================================================================
RCS file: /cvs/src/bin/ksh/c_ulimit.c,v
retrieving revision 1.26
diff -u -p -u -r1.26 c_ulimit.c
--- c_ulimit.c 16 Jan 2018 22:52:32 -0000 1.26
+++ c_ulimit.c 13 Mar 2018 08:16:37 -0000
@@ -97,7 +97,7 @@ c_ulimit(char **wp)
  for (l = limits; l->name && l->option != optc; l++)
  ;
  if (!l->name) {
- internal_warningf("ulimit: %c", optc);
+ internal_warningf("%s: %c", __func__, optc);
  return 1;
  }
  if (builtin_opt.optarg) {
Index: edit.c
===================================================================
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.63
diff -u -p -u -r1.63 edit.c
--- edit.c 16 Jan 2018 22:52:32 -0000 1.63
+++ edit.c 13 Mar 2018 08:16:37 -0000
@@ -372,7 +372,7 @@ x_file_glob(int flags, const char *str,
  source = s;
  if (yylex(ONEWORD|UNESCAPE) != LWORD) {
  source = sold;
- internal_warningf("fileglob: substitute error");
+ internal_warningf("%s: substitute error", __func__);
  return 0;
  }
  source = sold;
Index: exec.c
===================================================================
RCS file: /cvs/src/bin/ksh/exec.c,v
retrieving revision 1.72
diff -u -p -u -r1.72 exec.c
--- exec.c 16 Jan 2018 22:52:32 -0000 1.72
+++ exec.c 13 Mar 2018 08:16:37 -0000
@@ -727,7 +727,7 @@ shcomexec(char **wp)
 
  tp = ktsearch(&builtins, *wp, hash(*wp));
  if (tp == NULL)
- internal_errorf("shcomexec: %s", *wp);
+ internal_errorf("%s: %s", __func__, *wp);
  return call_builtin(tp, wp);
 }
 
@@ -1221,7 +1221,7 @@ herein(const char *content, int sub)
  s->start = s->str = content;
  source = s;
  if (yylex(ONEWORD|HEREDOC) != LWORD)
- internal_errorf("herein: yylex");
+ internal_errorf("%s: yylex", __func__);
  source = osource;
  shf_puts(evalstr(yylval.cp, 0), shf);
  } else
@@ -1446,5 +1446,5 @@ static void
 dbteste_error(Test_env *te, int offset, const char *msg)
 {
  te->flags |= TEF_ERROR;
- internal_warningf("dbteste_error: %s (offset %d)", msg, offset);
+ internal_warningf("%s: %s (offset %d)", __func__, msg, offset);
 }
Index: jobs.c
===================================================================
RCS file: /cvs/src/bin/ksh/jobs.c,v
retrieving revision 1.59
diff -u -p -u -r1.59 jobs.c
--- jobs.c 16 Jan 2018 22:52:32 -0000 1.59
+++ jobs.c 13 Mar 2018 08:16:38 -0000
@@ -200,13 +200,13 @@ j_suspend(void)
  if (restore_ttypgrp >= 0) {
  if (tcsetpgrp(tty_fd, restore_ttypgrp) < 0) {
  warningf(false,
-    "j_suspend: tcsetpgrp() failed: %s",
-    strerror(errno));
+    "%s: tcsetpgrp() failed: %s",
+    __func__, strerror(errno));
  } else {
  if (setpgid(0, restore_ttypgrp) < 0) {
  warningf(false,
-    "j_suspend: setpgid() failed: %s",
-    strerror(errno));
+    "%s: setpgid() failed: %s",
+    __func__, strerror(errno));
  }
  }
  }
@@ -225,14 +225,14 @@ j_suspend(void)
  if (restore_ttypgrp >= 0) {
  if (setpgid(0, kshpid) < 0) {
  warningf(false,
-    "j_suspend: setpgid() failed: %s",
-    strerror(errno));
+    "%s: setpgid() failed: %s",
+    __func__, strerror(errno));
  ttypgrp_ok = 0;
  } else {
  if (tcsetpgrp(tty_fd, kshpid) < 0) {
  warningf(false,
-    "j_suspend: tcsetpgrp() failed: %s",
-    strerror(errno));
+    "%s: tcsetpgrp() failed: %s",
+    __func__, strerror(errno));
  ttypgrp_ok = 0;
  }
  }
@@ -309,8 +309,8 @@ j_change(void)
  ttypgrp_ok = use_tty && tty_fd >= 0 && tty_devtty;
 
  if (ttypgrp_ok && (our_pgrp = getpgrp()) < 0) {
- warningf(false, "j_init: getpgrp() failed: %s",
-    strerror(errno));
+ warningf(false, "%s: getpgrp() failed: %s",
+    __func__, strerror(errno));
  ttypgrp_ok = 0;
  }
  if (ttypgrp_ok) {
@@ -322,8 +322,8 @@ j_change(void)
 
  if ((ttypgrp = tcgetpgrp(tty_fd)) < 0) {
  warningf(false,
-    "j_init: tcgetpgrp() failed: %s",
-    strerror(errno));
+    "%s: tcgetpgrp() failed: %s",
+    __func__, strerror(errno));
  ttypgrp_ok = 0;
  break;
  }
@@ -338,14 +338,14 @@ j_change(void)
  if (ttypgrp_ok && our_pgrp != kshpid) {
  if (setpgid(0, kshpid) < 0) {
  warningf(false,
-    "j_init: setpgid() failed: %s",
-    strerror(errno));
+    "%s: setpgid() failed: %s",
+    __func__, strerror(errno));
  ttypgrp_ok = 0;
  } else {
  if (tcsetpgrp(tty_fd, kshpid) < 0) {
  warningf(false,
-    "j_init: tcsetpgrp() failed: %s",
-    strerror(errno));
+    "%s: tcsetpgrp() failed: %s",
+    __func__, strerror(errno));
  ttypgrp_ok = 0;
  } else
  restore_ttypgrp = our_pgrp;
@@ -412,8 +412,8 @@ exchild(struct op *t, int flags, volatil
  if (flags&XPIPEI) { /* continuing with a pipe */
  if (!last_job)
  internal_errorf(
-    "exchild: XPIPEI and no last_job - pid %d",
-    (int) procpid);
+    "%s: XPIPEI and no last_job - pid %d",
+    __func__, (int) procpid);
  j = last_job;
  last_proc->next = p;
  last_proc = p;
@@ -522,7 +522,7 @@ exchild(struct op *t, int flags, volatil
  tty_close();
  cleartraps();
  execute(t, (flags & XERROK) | XEXEC, NULL); /* no return */
- internal_warningf("exchild: execute() returned");
+ internal_warningf("%s: execute() returned", __func__);
  unwind(LLEAVE);
  /* NOTREACHED */
  }
@@ -588,9 +588,9 @@ waitlast(void)
  j = last_job;
  if (!j || !(j->flags & JF_STARTED)) {
  if (!j)
- warningf(true, "waitlast: no last job");
+ warningf(true, "%s: no last job", __func__);
  else
- internal_warningf("waitlast: not started");
+ internal_warningf("%s: not started", __func__);
  sigprocmask(SIG_SETMASK, &omask, NULL);
  return 125; /* not so arbitrary, non-zero value */
  }
@@ -931,7 +931,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_warningf("j_async: job not started");
+ internal_warningf("%s: job not started", __func__);
  return;
  }
  async_job = j;
@@ -945,8 +945,8 @@ j_set_async(Job *j)
  if (!oldest) {
  /* XXX debugging */
  if (!(async_job->flags & JF_ZOMBIE) || nzombie != 1) {
- internal_warningf("j_async: bad nzombie (%d)",
-    nzombie);
+ internal_warningf("%s: bad nzombie (%d)",
+    __func__, nzombie);
  nzombie = 0;
  }
  break;
@@ -1035,8 +1035,8 @@ j_waitj(Job *j,
  j->flags |= JF_SAVEDTTYPGRP;
  if (tcsetpgrp(tty_fd, our_pgrp) < 0) {
  warningf(true,
-    "j_waitj: tcsetpgrp(%d, %d) failed: %s",
-    tty_fd, (int) our_pgrp,
+    "%s: tcsetpgrp(%d, %d) failed: %s",
+    __func__, tty_fd, (int) our_pgrp,
  strerror(errno));
  }
  if (j->state == PSTOPPED) {
@@ -1186,8 +1186,8 @@ check_job(Job *j)
 
  /* XXX debugging (nasty - interrupt routine using shl_out) */
  if (!(j->flags & JF_STARTED)) {
- internal_warningf("check_job: job started (flags 0x%x)",
-    j->flags);
+ internal_warningf("%s: job started (flags 0x%x)",
+    __func__, j->flags);
  return;
  }
 
@@ -1546,7 +1546,7 @@ remove_job(Job *j, const char *where)
  for (; curr != NULL && curr != j; prev = &curr->next, curr = *prev)
  ;
  if (curr != j) {
- internal_warningf("remove_job: job not found (%s)", where);
+ internal_warningf("%s: job not found (%s)", __func__, where);
  return;
  }
  *prev = curr->next;
Index: main.c
===================================================================
RCS file: /cvs/src/bin/ksh/main.c,v
retrieving revision 1.89
diff -u -p -u -r1.89 main.c
--- main.c 16 Jan 2018 22:52:32 -0000 1.89
+++ main.c 13 Mar 2018 08:16:38 -0000
@@ -492,7 +492,7 @@ include(const char *name, int argc, char
  unwind(i);
  /* NOTREACHED */
  default:
- internal_errorf("include: %d", i);
+ internal_errorf("%s: %d", __func__, i);
  /* NOTREACHED */
  }
  }
@@ -579,7 +579,7 @@ shell(Source *volatile s, volatile int t
  default:
  source = old_source;
  quitenv(NULL);
- internal_errorf("shell: %d", i);
+ internal_errorf("%s: %d", __func__, i);
  /* NOTREACHED */
  }
  }
Index: misc.c
===================================================================
RCS file: /cvs/src/bin/ksh/misc.c,v
retrieving revision 1.68
diff -u -p -u -r1.68 misc.c
--- misc.c 16 Jan 2018 22:52:32 -0000 1.68
+++ misc.c 13 Mar 2018 08:16:38 -0000
@@ -407,7 +407,7 @@ parse_args(char **argv,
  break;
  }
  if (ele == NELEM(sh_options)) {
- internal_errorf("parse_args: `%c'", optc);
+ internal_errorf("%s: `%c'", __func__, optc);
  return -1; /* not reached */
  }
  }
Index: shf.c
===================================================================
RCS file: /cvs/src/bin/ksh/shf.c,v
retrieving revision 1.32
diff -u -p -u -r1.32 shf.c
--- shf.c 16 Jan 2018 22:52:32 -0000 1.32
+++ shf.c 13 Mar 2018 08:16:38 -0000
@@ -100,7 +100,7 @@ shf_fdopen(int fd, int sflags, struct sh
  }
 
  if (!(sflags & (SHF_RD | SHF_WR)))
- internal_errorf("shf_fdopen: missing read/write");
+ internal_errorf("%s: missing read/write", __func__);
 
  if (shf) {
  if (bsize) {
@@ -157,9 +157,9 @@ shf_reopen(int fd, int sflags, struct sh
  }
 
  if (!(sflags & (SHF_RD | SHF_WR)))
- internal_errorf("shf_reopen: missing read/write");
+ internal_errorf("%s: missing read/write", __func__);
  if (!shf || !shf->buf || shf->bsize < bsize)
- internal_errorf("shf_reopen: bad shf/buf/bsize");
+ internal_errorf("%s: bad shf/buf/bsize", __func__);
 
  /* assumes shf->buf and shf->bsize already set up */
  shf->fd = fd;
@@ -189,7 +189,7 @@ shf_sopen(char *buf, int bsize, int sfla
  /* can't have a read+write string */
  if (!(sflags & (SHF_RD | SHF_WR)) ||
     (sflags & (SHF_RD | SHF_WR)) == (SHF_RD | SHF_WR))
- internal_errorf("shf_sopen: flags 0x%x", sflags);
+ internal_errorf("%s: flags 0x%x", __func__, sflags);
 
  if (!shf) {
  shf = alloc(sizeof(struct shf), ATEMP);
@@ -282,7 +282,7 @@ shf_flush(struct shf *shf)
  return (shf->flags & SHF_WR) ? EOF : 0;
 
  if (shf->fd < 0)
- internal_errorf("shf_flush: no fd");
+ internal_errorf("%s: no fd", __func__);
 
  if (shf->flags & SHF_ERROR) {
  errno = shf->errno_;
@@ -312,7 +312,7 @@ shf_emptybuf(struct shf *shf, int flags)
  int ret = 0;
 
  if (!(shf->flags & SHF_STRING) && shf->fd < 0)
- internal_errorf("shf_emptybuf: no fd");
+ internal_errorf("%s: no fd", __func__);
 
  if (shf->flags & SHF_ERROR) {
  errno = shf->errno_;
@@ -392,7 +392,7 @@ shf_fillbuf(struct shf *shf)
  return 0;
 
  if (shf->fd < 0)
- internal_errorf("shf_fillbuf: no fd");
+ internal_errorf("%s: no fd", __func__);
 
  if (shf->flags & (SHF_EOF | SHF_ERROR)) {
  if (shf->flags & SHF_ERROR)
@@ -438,10 +438,10 @@ shf_read(char *buf, int bsize, struct sh
  int ncopy;
 
  if (!(shf->flags & SHF_RD))
- internal_errorf("shf_read: flags %x", shf->flags);
+ internal_errorf("%s: flags %x", __func__, shf->flags);
 
  if (bsize <= 0)
- internal_errorf("shf_read: bsize %d", bsize);
+ internal_errorf("%s: bsize %d", __func__, bsize);
 
  while (bsize > 0) {
  if (shf->rnleft == 0 &&
@@ -473,7 +473,7 @@ shf_getse(char *buf, int bsize, struct s
  char *orig_buf = buf;
 
  if (!(shf->flags & SHF_RD))
- internal_errorf("shf_getse: flags %x", shf->flags);
+ internal_errorf("%s: flags %x", __func__, shf->flags);
 
  if (bsize <= 0)
  return NULL;
@@ -508,7 +508,7 @@ int
 shf_getchar(struct shf *shf)
 {
  if (!(shf->flags & SHF_RD))
- internal_errorf("shf_getchar: flags %x", shf->flags);
+ internal_errorf("%s: flags %x", __func__, shf->flags);
 
  if (shf->rnleft == 0 && (shf_fillbuf(shf) == EOF || shf->rnleft == 0))
  return EOF;
@@ -523,7 +523,7 @@ int
 shf_ungetc(int c, struct shf *shf)
 {
  if (!(shf->flags & SHF_RD))
- internal_errorf("shf_ungetc: flags %x", shf->flags);
+ internal_errorf("%s: flags %x", __func__, shf->flags);
 
  if ((shf->flags & SHF_ERROR) || c == EOF ||
     (shf->rp == shf->buf && shf->rnleft))
@@ -558,7 +558,7 @@ int
 shf_putchar(int c, struct shf *shf)
 {
  if (!(shf->flags & SHF_WR))
- internal_errorf("shf_putchar: flags %x", shf->flags);
+ internal_errorf("%s: flags %x", __func__, shf->flags);
 
  if (c == EOF)
  return EOF;
@@ -568,7 +568,7 @@ shf_putchar(int c, struct shf *shf)
  int n;
 
  if (shf->fd < 0)
- internal_errorf("shf_putchar: no fd");
+ internal_errorf("%s: no fd", __func__);
  if (shf->flags & SHF_ERROR) {
  errno = shf->errno_;
  return EOF;
@@ -614,10 +614,10 @@ shf_write(const char *buf, int nbytes, s
  int ncopy;
 
  if (!(shf->flags & SHF_WR))
- internal_errorf("shf_write: flags %x", shf->flags);
+ internal_errorf("%s: flags %x", __func__, shf->flags);
 
  if (nbytes < 0)
- internal_errorf("shf_write: nbytes %d", nbytes);
+ internal_errorf("%s: nbytes %d", __func__, nbytes);
 
  /* Don't buffer if buffer is empty and we're writting a large amount. */
  if ((ncopy = shf->wnleft) &&
@@ -687,8 +687,8 @@ shf_snprintf(char *buf, int bsize, const
  int n;
 
  if (!buf || bsize <= 0)
- internal_errorf("shf_snprintf: buf %lx, bsize %d",
- (long) buf, bsize);
+ internal_errorf("%s: buf %lx, bsize %d",
+ __func__, (long) buf, bsize);
 
  shf_sopen(buf, bsize, SHF_WR, &shf);
  va_start(args, fmt);
Index: trap.c
===================================================================
RCS file: /cvs/src/bin/ksh/trap.c,v
retrieving revision 1.31
diff -u -p -u -r1.31 trap.c
--- trap.c 16 Jan 2018 22:52:32 -0000 1.31
+++ trap.c 13 Mar 2018 08:16:38 -0000
@@ -402,8 +402,8 @@ setexecsig(Trap *p, int restore)
 {
  /* XXX debugging */
  if (!(p->flags & (TF_ORIG_IGN|TF_ORIG_DFL)))
- internal_errorf("setexecsig: unset signal %d(%s)",
-    p->signal, p->name);
+ internal_errorf("%s: unset signal %d(%s)",
+    __func__, p->signal, p->name);
 
  /* restore original value for exec'd kids */
  p->flags &= ~(TF_EXEC_IGN|TF_EXEC_DFL);
Index: tree.c
===================================================================
RCS file: /cvs/src/bin/ksh/tree.c,v
retrieving revision 1.32
diff -u -p -u -r1.32 tree.c
--- tree.c 20 Jan 2018 15:32:20 -0000 1.32
+++ tree.c 13 Mar 2018 08:16:38 -0000
@@ -533,8 +533,8 @@ wdscan(const char *wp, int c)
  break;
  default:
  internal_warningf(
-    "wdscan: unknown char 0x%x (carrying on)",
-    wp[-1]);
+    "%s: unknown char 0x%x (carrying on)",
+    __func__, wp[-1]);
  }
 }
 
Index: tty.c
===================================================================
RCS file: /cvs/src/bin/ksh/tty.c,v
retrieving revision 1.16
diff -u -p -u -r1.16 tty.c
--- tty.c 14 Dec 2015 13:59:42 -0000 1.16
+++ tty.c 13 Mar 2018 08:16:38 -0000
@@ -50,8 +50,8 @@ tty_init(int init_ttystate)
  }
  }
  if ((tty_fd = fcntl(tfd, F_DUPFD_CLOEXEC, FDBASE)) < 0) {
- warningf(false, "j_ttyinit: dup of tty fd failed: %s",
-    strerror(errno));
+ warningf(false, "%s: dup of tty fd failed: %s",
+    __func__, strerror(errno));
  } else if (init_ttystate)
  tcgetattr(tty_fd, &tty_state);
  if (do_close)
Index: var.c
===================================================================
RCS file: /cvs/src/bin/ksh/var.c,v
retrieving revision 1.65
diff -u -p -u -r1.65 var.c
--- var.c 16 Jan 2018 22:52:32 -0000 1.65
+++ var.c 13 Mar 2018 08:16:38 -0000
@@ -367,8 +367,8 @@ setstr(struct tbl *vq, const char *s, in
  if (s >= vq->val.s &&
     s <= vq->val.s + strlen(vq->val.s))
  internal_errorf(
-    "setstr: %s=%s: assigning to self",
-    vq->name, s);
+    "%s: %s=%s: assigning to self",
+    __func__, vq->name, s);
  afree(vq->val.s, vq->areap);
  }
  vq->flag &= ~(ISSET|ALLOC);
Index: vi.c
===================================================================
RCS file: /cvs/src/bin/ksh/vi.c,v
retrieving revision 1.55
diff -u -p -u -r1.55 vi.c
--- vi.c 16 Jan 2018 22:52:32 -0000 1.55
+++ vi.c 13 Mar 2018 08:16:39 -0000
@@ -1669,7 +1669,7 @@ grabhist(int save, int n)
  }
  (void) histnum(n);
  if ((hptr = *histpos()) == NULL) {
- internal_warningf("grabhist: bad history array");
+ internal_warningf("%s: bad history array", __func__);
  return -1;
  }
  if (save)

Reply | Threaded
Open this post in threaded view
|

Re: ksh: __func__ in warnings

Klemens Nanni-2
On Tue, Mar 13, 2018 at 04:39:16PM +0800, Michael W. Bombardieri wrote:
> Some errors and warnings printed by ksh have the function name
> prefixed. __func__ could be used here instead of hard-coding
> the name. The names are wrong for tty_init(), j_set_async(),
> j_change(), x_file_glob() and c_ulimit() afaics.
Wrong error messages should definitely be corrected, although I'd either
fix them literally or use __func__ consistently. This diff would
introduce the macro for only a handful of functions while leaving the
vast majority names untouched.

Not sure if touching all error messages for __func__ is worth it or just
too much churn in the end.

Reply | Threaded
Open this post in threaded view
|

Re: ksh: __func__ in warnings

Boris Radulov
 >Not sure if touching all error messages for __func__ is worth it or just
>too much churn in the end.

He already converted some so I don't see a reason to not introduce at least
that diff. If someone comes across something, he could just fix it then and
there if this issue is well-known.

On Tue, Mar 13, 2018 at 1:33 PM, Klemens Nanni <[hidden email]> wrote:

> On Tue, Mar 13, 2018 at 04:39:16PM +0800, Michael W. Bombardieri wrote:
> > Some errors and warnings printed by ksh have the function name
> > prefixed. __func__ could be used here instead of hard-coding
> > the name. The names are wrong for tty_init(), j_set_async(),
> > j_change(), x_file_glob() and c_ulimit() afaics.
> Wrong error messages should definitely be corrected, although I'd either
> fix them literally or use __func__ consistently. This diff would
> introduce the macro for only a handful of functions while leaving the
> vast majority names untouched.
>
> Not sure if touching all error messages for __func__ is worth it or just
> too much churn in the end.
>
>


--
Best Regards,
Bobby
Reply | Threaded
Open this post in threaded view
|

Re: ksh: __func__ in warnings

Klemens Nanni-2
In reply to this post by Klemens Nanni-2
On Tue, Mar 13, 2018 at 12:33:36PM +0100, Klemens Nanni wrote:

> On Tue, Mar 13, 2018 at 04:39:16PM +0800, Michael W. Bombardieri wrote:
> > Some errors and warnings printed by ksh have the function name
> > prefixed. __func__ could be used here instead of hard-coding
> > the name. The names are wrong for tty_init(), j_set_async(),
> > j_change(), x_file_glob() and c_ulimit() afaics.
> Wrong error messages should definitely be corrected, although I'd either
> fix them literally or use __func__ consistently. This diff would
> introduce the macro for only a handful of functions while leaving the
> vast majority names untouched.
>
> Not sure if touching all error messages for __func__ is worth it or just
> too much churn in the end.
Please disregard my concern about consistency, I was missing someting,
not you.

Reply | Threaded
Open this post in threaded view
|

Re: ksh: __func__ in warnings

Boris Radulov
> Please disregard my concern about consistency, I was missing something,
> not you

Sorry if it came out as out of place. I just feel like starting to
introduce the macro
in places where the function name is outright wrong might be a good idea,
since
if the function was changed once it makes sense that it might be changed
again.
Then, the macro usage would mitigate another potential error/source of
confusion.
Ultimately, I'm not going to go around changing stuff unless I see
something like this
by accident so it's not my decision to make at all. I don't think
introducing this diff
would do any harm though.

On Tue, Mar 13, 2018 at 2:44 PM, Klemens Nanni <[hidden email]> wrote:

> On Tue, Mar 13, 2018 at 12:33:36PM +0100, Klemens Nanni wrote:
> > On Tue, Mar 13, 2018 at 04:39:16PM +0800, Michael W. Bombardieri wrote:
> > > Some errors and warnings printed by ksh have the function name
> > > prefixed. __func__ could be used here instead of hard-coding
> > > the name. The names are wrong for tty_init(), j_set_async(),
> > > j_change(), x_file_glob() and c_ulimit() afaics.
> > Wrong error messages should definitely be corrected, although I'd either
> > fix them literally or use __func__ consistently. This diff would
> > introduce the macro for only a handful of functions while leaving the
> > vast majority names untouched.
> >
> > Not sure if touching all error messages for __func__ is worth it or just
> > too much churn in the end.
> Please disregard my concern about consistency, I was missing someting,
> not you.
>
>


--
Best Regards,
Bobby
Reply | Threaded
Open this post in threaded view
|

Re: ksh: __func__ in warnings

Anton Lindqvist-2
In reply to this post by Michael W. Bombardieri-2
On Tue, Mar 13, 2018 at 04:39:16PM +0800, Michael W. Bombardieri wrote:
> Hello,
>
> Some errors and warnings printed by ksh have the function name
> prefixed. __func__ could be used here instead of hard-coding
> the name. The names are wrong for tty_init(), j_set_async(),
> j_change(), x_file_glob() and c_ulimit() afaics.
>
> - Michael

Looks good, just some minor cosmetic nits where the format string in
some cases now fits on the previous line.

Anyone else willing to OK?

>
>
> Index: c_ksh.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/c_ksh.c,v
> retrieving revision 1.58
> diff -u -p -u -r1.58 c_ksh.c
> --- c_ksh.c 16 Jan 2018 22:52:32 -0000 1.58
> +++ c_ksh.c 13 Mar 2018 08:16:37 -0000
> @@ -1273,7 +1273,7 @@ c_getopts(char **wp)
>   }
>  
>   if (genv->loc->next == NULL) {
> - internal_warningf("c_getopts: no argv");
> + internal_warningf("%s: no argv", __func__);
>   return 1;
>   }
>   /* Which arguments are we parsing... */
> Index: c_ulimit.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/c_ulimit.c,v
> retrieving revision 1.26
> diff -u -p -u -r1.26 c_ulimit.c
> --- c_ulimit.c 16 Jan 2018 22:52:32 -0000 1.26
> +++ c_ulimit.c 13 Mar 2018 08:16:37 -0000
> @@ -97,7 +97,7 @@ c_ulimit(char **wp)
>   for (l = limits; l->name && l->option != optc; l++)
>   ;
>   if (!l->name) {
> - internal_warningf("ulimit: %c", optc);
> + internal_warningf("%s: %c", __func__, optc);
>   return 1;
>   }
>   if (builtin_opt.optarg) {
> Index: edit.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/edit.c,v
> retrieving revision 1.63
> diff -u -p -u -r1.63 edit.c
> --- edit.c 16 Jan 2018 22:52:32 -0000 1.63
> +++ edit.c 13 Mar 2018 08:16:37 -0000
> @@ -372,7 +372,7 @@ x_file_glob(int flags, const char *str,
>   source = s;
>   if (yylex(ONEWORD|UNESCAPE) != LWORD) {
>   source = sold;
> - internal_warningf("fileglob: substitute error");
> + internal_warningf("%s: substitute error", __func__);
>   return 0;
>   }
>   source = sold;
> Index: exec.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/exec.c,v
> retrieving revision 1.72
> diff -u -p -u -r1.72 exec.c
> --- exec.c 16 Jan 2018 22:52:32 -0000 1.72
> +++ exec.c 13 Mar 2018 08:16:37 -0000
> @@ -727,7 +727,7 @@ shcomexec(char **wp)
>  
>   tp = ktsearch(&builtins, *wp, hash(*wp));
>   if (tp == NULL)
> - internal_errorf("shcomexec: %s", *wp);
> + internal_errorf("%s: %s", __func__, *wp);
>   return call_builtin(tp, wp);
>  }
>  
> @@ -1221,7 +1221,7 @@ herein(const char *content, int sub)
>   s->start = s->str = content;
>   source = s;
>   if (yylex(ONEWORD|HEREDOC) != LWORD)
> - internal_errorf("herein: yylex");
> + internal_errorf("%s: yylex", __func__);
>   source = osource;
>   shf_puts(evalstr(yylval.cp, 0), shf);
>   } else
> @@ -1446,5 +1446,5 @@ static void
>  dbteste_error(Test_env *te, int offset, const char *msg)
>  {
>   te->flags |= TEF_ERROR;
> - internal_warningf("dbteste_error: %s (offset %d)", msg, offset);
> + internal_warningf("%s: %s (offset %d)", __func__, msg, offset);
>  }
> Index: jobs.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/jobs.c,v
> retrieving revision 1.59
> diff -u -p -u -r1.59 jobs.c
> --- jobs.c 16 Jan 2018 22:52:32 -0000 1.59
> +++ jobs.c 13 Mar 2018 08:16:38 -0000
> @@ -200,13 +200,13 @@ j_suspend(void)
>   if (restore_ttypgrp >= 0) {
>   if (tcsetpgrp(tty_fd, restore_ttypgrp) < 0) {
>   warningf(false,
> -    "j_suspend: tcsetpgrp() failed: %s",
> -    strerror(errno));
> +    "%s: tcsetpgrp() failed: %s",
> +    __func__, strerror(errno));
>   } else {
>   if (setpgid(0, restore_ttypgrp) < 0) {
>   warningf(false,
> -    "j_suspend: setpgid() failed: %s",
> -    strerror(errno));
> +    "%s: setpgid() failed: %s",
> +    __func__, strerror(errno));
>   }
>   }
>   }
> @@ -225,14 +225,14 @@ j_suspend(void)
>   if (restore_ttypgrp >= 0) {
>   if (setpgid(0, kshpid) < 0) {
>   warningf(false,
> -    "j_suspend: setpgid() failed: %s",
> -    strerror(errno));
> +    "%s: setpgid() failed: %s",
> +    __func__, strerror(errno));
>   ttypgrp_ok = 0;
>   } else {
>   if (tcsetpgrp(tty_fd, kshpid) < 0) {
>   warningf(false,
> -    "j_suspend: tcsetpgrp() failed: %s",
> -    strerror(errno));
> +    "%s: tcsetpgrp() failed: %s",
> +    __func__, strerror(errno));
>   ttypgrp_ok = 0;
>   }
>   }
> @@ -309,8 +309,8 @@ j_change(void)
>   ttypgrp_ok = use_tty && tty_fd >= 0 && tty_devtty;
>  
>   if (ttypgrp_ok && (our_pgrp = getpgrp()) < 0) {
> - warningf(false, "j_init: getpgrp() failed: %s",
> -    strerror(errno));
> + warningf(false, "%s: getpgrp() failed: %s",
> +    __func__, strerror(errno));
>   ttypgrp_ok = 0;
>   }
>   if (ttypgrp_ok) {
> @@ -322,8 +322,8 @@ j_change(void)
>  
>   if ((ttypgrp = tcgetpgrp(tty_fd)) < 0) {
>   warningf(false,
> -    "j_init: tcgetpgrp() failed: %s",
> -    strerror(errno));
> +    "%s: tcgetpgrp() failed: %s",
> +    __func__, strerror(errno));
>   ttypgrp_ok = 0;
>   break;
>   }
> @@ -338,14 +338,14 @@ j_change(void)
>   if (ttypgrp_ok && our_pgrp != kshpid) {
>   if (setpgid(0, kshpid) < 0) {
>   warningf(false,
> -    "j_init: setpgid() failed: %s",
> -    strerror(errno));
> +    "%s: setpgid() failed: %s",
> +    __func__, strerror(errno));
>   ttypgrp_ok = 0;
>   } else {
>   if (tcsetpgrp(tty_fd, kshpid) < 0) {
>   warningf(false,
> -    "j_init: tcsetpgrp() failed: %s",
> -    strerror(errno));
> +    "%s: tcsetpgrp() failed: %s",
> +    __func__, strerror(errno));
>   ttypgrp_ok = 0;
>   } else
>   restore_ttypgrp = our_pgrp;
> @@ -412,8 +412,8 @@ exchild(struct op *t, int flags, volatil
>   if (flags&XPIPEI) { /* continuing with a pipe */
>   if (!last_job)
>   internal_errorf(
> -    "exchild: XPIPEI and no last_job - pid %d",
> -    (int) procpid);
> +    "%s: XPIPEI and no last_job - pid %d",
> +    __func__, (int) procpid);
>   j = last_job;
>   last_proc->next = p;
>   last_proc = p;
> @@ -522,7 +522,7 @@ exchild(struct op *t, int flags, volatil
>   tty_close();
>   cleartraps();
>   execute(t, (flags & XERROK) | XEXEC, NULL); /* no return */
> - internal_warningf("exchild: execute() returned");
> + internal_warningf("%s: execute() returned", __func__);
>   unwind(LLEAVE);
>   /* NOTREACHED */
>   }
> @@ -588,9 +588,9 @@ waitlast(void)
>   j = last_job;
>   if (!j || !(j->flags & JF_STARTED)) {
>   if (!j)
> - warningf(true, "waitlast: no last job");
> + warningf(true, "%s: no last job", __func__);
>   else
> - internal_warningf("waitlast: not started");
> + internal_warningf("%s: not started", __func__);
>   sigprocmask(SIG_SETMASK, &omask, NULL);
>   return 125; /* not so arbitrary, non-zero value */
>   }
> @@ -931,7 +931,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_warningf("j_async: job not started");
> + internal_warningf("%s: job not started", __func__);
>   return;
>   }
>   async_job = j;
> @@ -945,8 +945,8 @@ j_set_async(Job *j)
>   if (!oldest) {
>   /* XXX debugging */
>   if (!(async_job->flags & JF_ZOMBIE) || nzombie != 1) {
> - internal_warningf("j_async: bad nzombie (%d)",
> -    nzombie);
> + internal_warningf("%s: bad nzombie (%d)",
> +    __func__, nzombie);
>   nzombie = 0;
>   }
>   break;
> @@ -1035,8 +1035,8 @@ j_waitj(Job *j,
>   j->flags |= JF_SAVEDTTYPGRP;
>   if (tcsetpgrp(tty_fd, our_pgrp) < 0) {
>   warningf(true,
> -    "j_waitj: tcsetpgrp(%d, %d) failed: %s",
> -    tty_fd, (int) our_pgrp,
> +    "%s: tcsetpgrp(%d, %d) failed: %s",
> +    __func__, tty_fd, (int) our_pgrp,
>   strerror(errno));
>   }
>   if (j->state == PSTOPPED) {
> @@ -1186,8 +1186,8 @@ check_job(Job *j)
>  
>   /* XXX debugging (nasty - interrupt routine using shl_out) */
>   if (!(j->flags & JF_STARTED)) {
> - internal_warningf("check_job: job started (flags 0x%x)",
> -    j->flags);
> + internal_warningf("%s: job started (flags 0x%x)",
> +    __func__, j->flags);
>   return;
>   }
>  
> @@ -1546,7 +1546,7 @@ remove_job(Job *j, const char *where)
>   for (; curr != NULL && curr != j; prev = &curr->next, curr = *prev)
>   ;
>   if (curr != j) {
> - internal_warningf("remove_job: job not found (%s)", where);
> + internal_warningf("%s: job not found (%s)", __func__, where);
>   return;
>   }
>   *prev = curr->next;
> Index: main.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/main.c,v
> retrieving revision 1.89
> diff -u -p -u -r1.89 main.c
> --- main.c 16 Jan 2018 22:52:32 -0000 1.89
> +++ main.c 13 Mar 2018 08:16:38 -0000
> @@ -492,7 +492,7 @@ include(const char *name, int argc, char
>   unwind(i);
>   /* NOTREACHED */
>   default:
> - internal_errorf("include: %d", i);
> + internal_errorf("%s: %d", __func__, i);
>   /* NOTREACHED */
>   }
>   }
> @@ -579,7 +579,7 @@ shell(Source *volatile s, volatile int t
>   default:
>   source = old_source;
>   quitenv(NULL);
> - internal_errorf("shell: %d", i);
> + internal_errorf("%s: %d", __func__, i);
>   /* NOTREACHED */
>   }
>   }
> Index: misc.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/misc.c,v
> retrieving revision 1.68
> diff -u -p -u -r1.68 misc.c
> --- misc.c 16 Jan 2018 22:52:32 -0000 1.68
> +++ misc.c 13 Mar 2018 08:16:38 -0000
> @@ -407,7 +407,7 @@ parse_args(char **argv,
>   break;
>   }
>   if (ele == NELEM(sh_options)) {
> - internal_errorf("parse_args: `%c'", optc);
> + internal_errorf("%s: `%c'", __func__, optc);
>   return -1; /* not reached */
>   }
>   }
> Index: shf.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/shf.c,v
> retrieving revision 1.32
> diff -u -p -u -r1.32 shf.c
> --- shf.c 16 Jan 2018 22:52:32 -0000 1.32
> +++ shf.c 13 Mar 2018 08:16:38 -0000
> @@ -100,7 +100,7 @@ shf_fdopen(int fd, int sflags, struct sh
>   }
>  
>   if (!(sflags & (SHF_RD | SHF_WR)))
> - internal_errorf("shf_fdopen: missing read/write");
> + internal_errorf("%s: missing read/write", __func__);
>  
>   if (shf) {
>   if (bsize) {
> @@ -157,9 +157,9 @@ shf_reopen(int fd, int sflags, struct sh
>   }
>  
>   if (!(sflags & (SHF_RD | SHF_WR)))
> - internal_errorf("shf_reopen: missing read/write");
> + internal_errorf("%s: missing read/write", __func__);
>   if (!shf || !shf->buf || shf->bsize < bsize)
> - internal_errorf("shf_reopen: bad shf/buf/bsize");
> + internal_errorf("%s: bad shf/buf/bsize", __func__);
>  
>   /* assumes shf->buf and shf->bsize already set up */
>   shf->fd = fd;
> @@ -189,7 +189,7 @@ shf_sopen(char *buf, int bsize, int sfla
>   /* can't have a read+write string */
>   if (!(sflags & (SHF_RD | SHF_WR)) ||
>      (sflags & (SHF_RD | SHF_WR)) == (SHF_RD | SHF_WR))
> - internal_errorf("shf_sopen: flags 0x%x", sflags);
> + internal_errorf("%s: flags 0x%x", __func__, sflags);
>  
>   if (!shf) {
>   shf = alloc(sizeof(struct shf), ATEMP);
> @@ -282,7 +282,7 @@ shf_flush(struct shf *shf)
>   return (shf->flags & SHF_WR) ? EOF : 0;
>  
>   if (shf->fd < 0)
> - internal_errorf("shf_flush: no fd");
> + internal_errorf("%s: no fd", __func__);
>  
>   if (shf->flags & SHF_ERROR) {
>   errno = shf->errno_;
> @@ -312,7 +312,7 @@ shf_emptybuf(struct shf *shf, int flags)
>   int ret = 0;
>  
>   if (!(shf->flags & SHF_STRING) && shf->fd < 0)
> - internal_errorf("shf_emptybuf: no fd");
> + internal_errorf("%s: no fd", __func__);
>  
>   if (shf->flags & SHF_ERROR) {
>   errno = shf->errno_;
> @@ -392,7 +392,7 @@ shf_fillbuf(struct shf *shf)
>   return 0;
>  
>   if (shf->fd < 0)
> - internal_errorf("shf_fillbuf: no fd");
> + internal_errorf("%s: no fd", __func__);
>  
>   if (shf->flags & (SHF_EOF | SHF_ERROR)) {
>   if (shf->flags & SHF_ERROR)
> @@ -438,10 +438,10 @@ shf_read(char *buf, int bsize, struct sh
>   int ncopy;
>  
>   if (!(shf->flags & SHF_RD))
> - internal_errorf("shf_read: flags %x", shf->flags);
> + internal_errorf("%s: flags %x", __func__, shf->flags);
>  
>   if (bsize <= 0)
> - internal_errorf("shf_read: bsize %d", bsize);
> + internal_errorf("%s: bsize %d", __func__, bsize);
>  
>   while (bsize > 0) {
>   if (shf->rnleft == 0 &&
> @@ -473,7 +473,7 @@ shf_getse(char *buf, int bsize, struct s
>   char *orig_buf = buf;
>  
>   if (!(shf->flags & SHF_RD))
> - internal_errorf("shf_getse: flags %x", shf->flags);
> + internal_errorf("%s: flags %x", __func__, shf->flags);
>  
>   if (bsize <= 0)
>   return NULL;
> @@ -508,7 +508,7 @@ int
>  shf_getchar(struct shf *shf)
>  {
>   if (!(shf->flags & SHF_RD))
> - internal_errorf("shf_getchar: flags %x", shf->flags);
> + internal_errorf("%s: flags %x", __func__, shf->flags);
>  
>   if (shf->rnleft == 0 && (shf_fillbuf(shf) == EOF || shf->rnleft == 0))
>   return EOF;
> @@ -523,7 +523,7 @@ int
>  shf_ungetc(int c, struct shf *shf)
>  {
>   if (!(shf->flags & SHF_RD))
> - internal_errorf("shf_ungetc: flags %x", shf->flags);
> + internal_errorf("%s: flags %x", __func__, shf->flags);
>  
>   if ((shf->flags & SHF_ERROR) || c == EOF ||
>      (shf->rp == shf->buf && shf->rnleft))
> @@ -558,7 +558,7 @@ int
>  shf_putchar(int c, struct shf *shf)
>  {
>   if (!(shf->flags & SHF_WR))
> - internal_errorf("shf_putchar: flags %x", shf->flags);
> + internal_errorf("%s: flags %x", __func__, shf->flags);
>  
>   if (c == EOF)
>   return EOF;
> @@ -568,7 +568,7 @@ shf_putchar(int c, struct shf *shf)
>   int n;
>  
>   if (shf->fd < 0)
> - internal_errorf("shf_putchar: no fd");
> + internal_errorf("%s: no fd", __func__);
>   if (shf->flags & SHF_ERROR) {
>   errno = shf->errno_;
>   return EOF;
> @@ -614,10 +614,10 @@ shf_write(const char *buf, int nbytes, s
>   int ncopy;
>  
>   if (!(shf->flags & SHF_WR))
> - internal_errorf("shf_write: flags %x", shf->flags);
> + internal_errorf("%s: flags %x", __func__, shf->flags);
>  
>   if (nbytes < 0)
> - internal_errorf("shf_write: nbytes %d", nbytes);
> + internal_errorf("%s: nbytes %d", __func__, nbytes);
>  
>   /* Don't buffer if buffer is empty and we're writting a large amount. */
>   if ((ncopy = shf->wnleft) &&
> @@ -687,8 +687,8 @@ shf_snprintf(char *buf, int bsize, const
>   int n;
>  
>   if (!buf || bsize <= 0)
> - internal_errorf("shf_snprintf: buf %lx, bsize %d",
> - (long) buf, bsize);
> + internal_errorf("%s: buf %lx, bsize %d",
> + __func__, (long) buf, bsize);
>  
>   shf_sopen(buf, bsize, SHF_WR, &shf);
>   va_start(args, fmt);
> Index: trap.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/trap.c,v
> retrieving revision 1.31
> diff -u -p -u -r1.31 trap.c
> --- trap.c 16 Jan 2018 22:52:32 -0000 1.31
> +++ trap.c 13 Mar 2018 08:16:38 -0000
> @@ -402,8 +402,8 @@ setexecsig(Trap *p, int restore)
>  {
>   /* XXX debugging */
>   if (!(p->flags & (TF_ORIG_IGN|TF_ORIG_DFL)))
> - internal_errorf("setexecsig: unset signal %d(%s)",
> -    p->signal, p->name);
> + internal_errorf("%s: unset signal %d(%s)",
> +    __func__, p->signal, p->name);
>  
>   /* restore original value for exec'd kids */
>   p->flags &= ~(TF_EXEC_IGN|TF_EXEC_DFL);
> Index: tree.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/tree.c,v
> retrieving revision 1.32
> diff -u -p -u -r1.32 tree.c
> --- tree.c 20 Jan 2018 15:32:20 -0000 1.32
> +++ tree.c 13 Mar 2018 08:16:38 -0000
> @@ -533,8 +533,8 @@ wdscan(const char *wp, int c)
>   break;
>   default:
>   internal_warningf(
> -    "wdscan: unknown char 0x%x (carrying on)",
> -    wp[-1]);
> +    "%s: unknown char 0x%x (carrying on)",
> +    __func__, wp[-1]);
>   }
>  }
>  
> Index: tty.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/tty.c,v
> retrieving revision 1.16
> diff -u -p -u -r1.16 tty.c
> --- tty.c 14 Dec 2015 13:59:42 -0000 1.16
> +++ tty.c 13 Mar 2018 08:16:38 -0000
> @@ -50,8 +50,8 @@ tty_init(int init_ttystate)
>   }
>   }
>   if ((tty_fd = fcntl(tfd, F_DUPFD_CLOEXEC, FDBASE)) < 0) {
> - warningf(false, "j_ttyinit: dup of tty fd failed: %s",
> -    strerror(errno));
> + warningf(false, "%s: dup of tty fd failed: %s",
> +    __func__, strerror(errno));
>   } else if (init_ttystate)
>   tcgetattr(tty_fd, &tty_state);
>   if (do_close)
> Index: var.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/var.c,v
> retrieving revision 1.65
> diff -u -p -u -r1.65 var.c
> --- var.c 16 Jan 2018 22:52:32 -0000 1.65
> +++ var.c 13 Mar 2018 08:16:38 -0000
> @@ -367,8 +367,8 @@ setstr(struct tbl *vq, const char *s, in
>   if (s >= vq->val.s &&
>      s <= vq->val.s + strlen(vq->val.s))
>   internal_errorf(
> -    "setstr: %s=%s: assigning to self",
> -    vq->name, s);
> +    "%s: %s=%s: assigning to self",
> +    __func__, vq->name, s);
>   afree(vq->val.s, vq->areap);
>   }
>   vq->flag &= ~(ISSET|ALLOC);
> Index: vi.c
> ===================================================================
> RCS file: /cvs/src/bin/ksh/vi.c,v
> retrieving revision 1.55
> diff -u -p -u -r1.55 vi.c
> --- vi.c 16 Jan 2018 22:52:32 -0000 1.55
> +++ vi.c 13 Mar 2018 08:16:39 -0000
> @@ -1669,7 +1669,7 @@ grabhist(int save, int n)
>   }
>   (void) histnum(n);
>   if ((hptr = *histpos()) == NULL) {
> - internal_warningf("grabhist: bad history array");
> + internal_warningf("%s: bad history array", __func__);
>   return -1;
>   }
>   if (save)
>

Reply | Threaded
Open this post in threaded view
|

Re: ksh: __func__ in warnings

Sebastian Benoit-3
Anton Lindqvist([hidden email]) on 2018.03.15 08:37:06 +0100:

> On Tue, Mar 13, 2018 at 04:39:16PM +0800, Michael W. Bombardieri wrote:
> > Hello,
> >
> > Some errors and warnings printed by ksh have the function name
> > prefixed. __func__ could be used here instead of hard-coding
> > the name. The names are wrong for tty_init(), j_set_async(),
> > j_change(), x_file_glob() and c_ulimit() afaics.
> >
> > - Michael
>
> Looks good, just some minor cosmetic nits where the format string in
> some cases now fits on the previous line.
>
> Anyone else willing to OK?

ok

>
> >
> >
> > Index: c_ksh.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/c_ksh.c,v
> > retrieving revision 1.58
> > diff -u -p -u -r1.58 c_ksh.c
> > --- c_ksh.c 16 Jan 2018 22:52:32 -0000 1.58
> > +++ c_ksh.c 13 Mar 2018 08:16:37 -0000
> > @@ -1273,7 +1273,7 @@ c_getopts(char **wp)
> >   }
> >  
> >   if (genv->loc->next == NULL) {
> > - internal_warningf("c_getopts: no argv");
> > + internal_warningf("%s: no argv", __func__);
> >   return 1;
> >   }
> >   /* Which arguments are we parsing... */
> > Index: c_ulimit.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/c_ulimit.c,v
> > retrieving revision 1.26
> > diff -u -p -u -r1.26 c_ulimit.c
> > --- c_ulimit.c 16 Jan 2018 22:52:32 -0000 1.26
> > +++ c_ulimit.c 13 Mar 2018 08:16:37 -0000
> > @@ -97,7 +97,7 @@ c_ulimit(char **wp)
> >   for (l = limits; l->name && l->option != optc; l++)
> >   ;
> >   if (!l->name) {
> > - internal_warningf("ulimit: %c", optc);
> > + internal_warningf("%s: %c", __func__, optc);
> >   return 1;
> >   }
> >   if (builtin_opt.optarg) {
> > Index: edit.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/edit.c,v
> > retrieving revision 1.63
> > diff -u -p -u -r1.63 edit.c
> > --- edit.c 16 Jan 2018 22:52:32 -0000 1.63
> > +++ edit.c 13 Mar 2018 08:16:37 -0000
> > @@ -372,7 +372,7 @@ x_file_glob(int flags, const char *str,
> >   source = s;
> >   if (yylex(ONEWORD|UNESCAPE) != LWORD) {
> >   source = sold;
> > - internal_warningf("fileglob: substitute error");
> > + internal_warningf("%s: substitute error", __func__);
> >   return 0;
> >   }
> >   source = sold;
> > Index: exec.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/exec.c,v
> > retrieving revision 1.72
> > diff -u -p -u -r1.72 exec.c
> > --- exec.c 16 Jan 2018 22:52:32 -0000 1.72
> > +++ exec.c 13 Mar 2018 08:16:37 -0000
> > @@ -727,7 +727,7 @@ shcomexec(char **wp)
> >  
> >   tp = ktsearch(&builtins, *wp, hash(*wp));
> >   if (tp == NULL)
> > - internal_errorf("shcomexec: %s", *wp);
> > + internal_errorf("%s: %s", __func__, *wp);
> >   return call_builtin(tp, wp);
> >  }
> >  
> > @@ -1221,7 +1221,7 @@ herein(const char *content, int sub)
> >   s->start = s->str = content;
> >   source = s;
> >   if (yylex(ONEWORD|HEREDOC) != LWORD)
> > - internal_errorf("herein: yylex");
> > + internal_errorf("%s: yylex", __func__);
> >   source = osource;
> >   shf_puts(evalstr(yylval.cp, 0), shf);
> >   } else
> > @@ -1446,5 +1446,5 @@ static void
> >  dbteste_error(Test_env *te, int offset, const char *msg)
> >  {
> >   te->flags |= TEF_ERROR;
> > - internal_warningf("dbteste_error: %s (offset %d)", msg, offset);
> > + internal_warningf("%s: %s (offset %d)", __func__, msg, offset);
> >  }
> > Index: jobs.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/jobs.c,v
> > retrieving revision 1.59
> > diff -u -p -u -r1.59 jobs.c
> > --- jobs.c 16 Jan 2018 22:52:32 -0000 1.59
> > +++ jobs.c 13 Mar 2018 08:16:38 -0000
> > @@ -200,13 +200,13 @@ j_suspend(void)
> >   if (restore_ttypgrp >= 0) {
> >   if (tcsetpgrp(tty_fd, restore_ttypgrp) < 0) {
> >   warningf(false,
> > -    "j_suspend: tcsetpgrp() failed: %s",
> > -    strerror(errno));
> > +    "%s: tcsetpgrp() failed: %s",
> > +    __func__, strerror(errno));
> >   } else {
> >   if (setpgid(0, restore_ttypgrp) < 0) {
> >   warningf(false,
> > -    "j_suspend: setpgid() failed: %s",
> > -    strerror(errno));
> > +    "%s: setpgid() failed: %s",
> > +    __func__, strerror(errno));
> >   }
> >   }
> >   }
> > @@ -225,14 +225,14 @@ j_suspend(void)
> >   if (restore_ttypgrp >= 0) {
> >   if (setpgid(0, kshpid) < 0) {
> >   warningf(false,
> > -    "j_suspend: setpgid() failed: %s",
> > -    strerror(errno));
> > +    "%s: setpgid() failed: %s",
> > +    __func__, strerror(errno));
> >   ttypgrp_ok = 0;
> >   } else {
> >   if (tcsetpgrp(tty_fd, kshpid) < 0) {
> >   warningf(false,
> > -    "j_suspend: tcsetpgrp() failed: %s",
> > -    strerror(errno));
> > +    "%s: tcsetpgrp() failed: %s",
> > +    __func__, strerror(errno));
> >   ttypgrp_ok = 0;
> >   }
> >   }
> > @@ -309,8 +309,8 @@ j_change(void)
> >   ttypgrp_ok = use_tty && tty_fd >= 0 && tty_devtty;
> >  
> >   if (ttypgrp_ok && (our_pgrp = getpgrp()) < 0) {
> > - warningf(false, "j_init: getpgrp() failed: %s",
> > -    strerror(errno));
> > + warningf(false, "%s: getpgrp() failed: %s",
> > +    __func__, strerror(errno));
> >   ttypgrp_ok = 0;
> >   }
> >   if (ttypgrp_ok) {
> > @@ -322,8 +322,8 @@ j_change(void)
> >  
> >   if ((ttypgrp = tcgetpgrp(tty_fd)) < 0) {
> >   warningf(false,
> > -    "j_init: tcgetpgrp() failed: %s",
> > -    strerror(errno));
> > +    "%s: tcgetpgrp() failed: %s",
> > +    __func__, strerror(errno));
> >   ttypgrp_ok = 0;
> >   break;
> >   }
> > @@ -338,14 +338,14 @@ j_change(void)
> >   if (ttypgrp_ok && our_pgrp != kshpid) {
> >   if (setpgid(0, kshpid) < 0) {
> >   warningf(false,
> > -    "j_init: setpgid() failed: %s",
> > -    strerror(errno));
> > +    "%s: setpgid() failed: %s",
> > +    __func__, strerror(errno));
> >   ttypgrp_ok = 0;
> >   } else {
> >   if (tcsetpgrp(tty_fd, kshpid) < 0) {
> >   warningf(false,
> > -    "j_init: tcsetpgrp() failed: %s",
> > -    strerror(errno));
> > +    "%s: tcsetpgrp() failed: %s",
> > +    __func__, strerror(errno));
> >   ttypgrp_ok = 0;
> >   } else
> >   restore_ttypgrp = our_pgrp;
> > @@ -412,8 +412,8 @@ exchild(struct op *t, int flags, volatil
> >   if (flags&XPIPEI) { /* continuing with a pipe */
> >   if (!last_job)
> >   internal_errorf(
> > -    "exchild: XPIPEI and no last_job - pid %d",
> > -    (int) procpid);
> > +    "%s: XPIPEI and no last_job - pid %d",
> > +    __func__, (int) procpid);
> >   j = last_job;
> >   last_proc->next = p;
> >   last_proc = p;
> > @@ -522,7 +522,7 @@ exchild(struct op *t, int flags, volatil
> >   tty_close();
> >   cleartraps();
> >   execute(t, (flags & XERROK) | XEXEC, NULL); /* no return */
> > - internal_warningf("exchild: execute() returned");
> > + internal_warningf("%s: execute() returned", __func__);
> >   unwind(LLEAVE);
> >   /* NOTREACHED */
> >   }
> > @@ -588,9 +588,9 @@ waitlast(void)
> >   j = last_job;
> >   if (!j || !(j->flags & JF_STARTED)) {
> >   if (!j)
> > - warningf(true, "waitlast: no last job");
> > + warningf(true, "%s: no last job", __func__);
> >   else
> > - internal_warningf("waitlast: not started");
> > + internal_warningf("%s: not started", __func__);
> >   sigprocmask(SIG_SETMASK, &omask, NULL);
> >   return 125; /* not so arbitrary, non-zero value */
> >   }
> > @@ -931,7 +931,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_warningf("j_async: job not started");
> > + internal_warningf("%s: job not started", __func__);
> >   return;
> >   }
> >   async_job = j;
> > @@ -945,8 +945,8 @@ j_set_async(Job *j)
> >   if (!oldest) {
> >   /* XXX debugging */
> >   if (!(async_job->flags & JF_ZOMBIE) || nzombie != 1) {
> > - internal_warningf("j_async: bad nzombie (%d)",
> > -    nzombie);
> > + internal_warningf("%s: bad nzombie (%d)",
> > +    __func__, nzombie);
> >   nzombie = 0;
> >   }
> >   break;
> > @@ -1035,8 +1035,8 @@ j_waitj(Job *j,
> >   j->flags |= JF_SAVEDTTYPGRP;
> >   if (tcsetpgrp(tty_fd, our_pgrp) < 0) {
> >   warningf(true,
> > -    "j_waitj: tcsetpgrp(%d, %d) failed: %s",
> > -    tty_fd, (int) our_pgrp,
> > +    "%s: tcsetpgrp(%d, %d) failed: %s",
> > +    __func__, tty_fd, (int) our_pgrp,
> >   strerror(errno));
> >   }
> >   if (j->state == PSTOPPED) {
> > @@ -1186,8 +1186,8 @@ check_job(Job *j)
> >  
> >   /* XXX debugging (nasty - interrupt routine using shl_out) */
> >   if (!(j->flags & JF_STARTED)) {
> > - internal_warningf("check_job: job started (flags 0x%x)",
> > -    j->flags);
> > + internal_warningf("%s: job started (flags 0x%x)",
> > +    __func__, j->flags);
> >   return;
> >   }
> >  
> > @@ -1546,7 +1546,7 @@ remove_job(Job *j, const char *where)
> >   for (; curr != NULL && curr != j; prev = &curr->next, curr = *prev)
> >   ;
> >   if (curr != j) {
> > - internal_warningf("remove_job: job not found (%s)", where);
> > + internal_warningf("%s: job not found (%s)", __func__, where);
> >   return;
> >   }
> >   *prev = curr->next;
> > Index: main.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/main.c,v
> > retrieving revision 1.89
> > diff -u -p -u -r1.89 main.c
> > --- main.c 16 Jan 2018 22:52:32 -0000 1.89
> > +++ main.c 13 Mar 2018 08:16:38 -0000
> > @@ -492,7 +492,7 @@ include(const char *name, int argc, char
> >   unwind(i);
> >   /* NOTREACHED */
> >   default:
> > - internal_errorf("include: %d", i);
> > + internal_errorf("%s: %d", __func__, i);
> >   /* NOTREACHED */
> >   }
> >   }
> > @@ -579,7 +579,7 @@ shell(Source *volatile s, volatile int t
> >   default:
> >   source = old_source;
> >   quitenv(NULL);
> > - internal_errorf("shell: %d", i);
> > + internal_errorf("%s: %d", __func__, i);
> >   /* NOTREACHED */
> >   }
> >   }
> > Index: misc.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/misc.c,v
> > retrieving revision 1.68
> > diff -u -p -u -r1.68 misc.c
> > --- misc.c 16 Jan 2018 22:52:32 -0000 1.68
> > +++ misc.c 13 Mar 2018 08:16:38 -0000
> > @@ -407,7 +407,7 @@ parse_args(char **argv,
> >   break;
> >   }
> >   if (ele == NELEM(sh_options)) {
> > - internal_errorf("parse_args: `%c'", optc);
> > + internal_errorf("%s: `%c'", __func__, optc);
> >   return -1; /* not reached */
> >   }
> >   }
> > Index: shf.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/shf.c,v
> > retrieving revision 1.32
> > diff -u -p -u -r1.32 shf.c
> > --- shf.c 16 Jan 2018 22:52:32 -0000 1.32
> > +++ shf.c 13 Mar 2018 08:16:38 -0000
> > @@ -100,7 +100,7 @@ shf_fdopen(int fd, int sflags, struct sh
> >   }
> >  
> >   if (!(sflags & (SHF_RD | SHF_WR)))
> > - internal_errorf("shf_fdopen: missing read/write");
> > + internal_errorf("%s: missing read/write", __func__);
> >  
> >   if (shf) {
> >   if (bsize) {
> > @@ -157,9 +157,9 @@ shf_reopen(int fd, int sflags, struct sh
> >   }
> >  
> >   if (!(sflags & (SHF_RD | SHF_WR)))
> > - internal_errorf("shf_reopen: missing read/write");
> > + internal_errorf("%s: missing read/write", __func__);
> >   if (!shf || !shf->buf || shf->bsize < bsize)
> > - internal_errorf("shf_reopen: bad shf/buf/bsize");
> > + internal_errorf("%s: bad shf/buf/bsize", __func__);
> >  
> >   /* assumes shf->buf and shf->bsize already set up */
> >   shf->fd = fd;
> > @@ -189,7 +189,7 @@ shf_sopen(char *buf, int bsize, int sfla
> >   /* can't have a read+write string */
> >   if (!(sflags & (SHF_RD | SHF_WR)) ||
> >      (sflags & (SHF_RD | SHF_WR)) == (SHF_RD | SHF_WR))
> > - internal_errorf("shf_sopen: flags 0x%x", sflags);
> > + internal_errorf("%s: flags 0x%x", __func__, sflags);
> >  
> >   if (!shf) {
> >   shf = alloc(sizeof(struct shf), ATEMP);
> > @@ -282,7 +282,7 @@ shf_flush(struct shf *shf)
> >   return (shf->flags & SHF_WR) ? EOF : 0;
> >  
> >   if (shf->fd < 0)
> > - internal_errorf("shf_flush: no fd");
> > + internal_errorf("%s: no fd", __func__);
> >  
> >   if (shf->flags & SHF_ERROR) {
> >   errno = shf->errno_;
> > @@ -312,7 +312,7 @@ shf_emptybuf(struct shf *shf, int flags)
> >   int ret = 0;
> >  
> >   if (!(shf->flags & SHF_STRING) && shf->fd < 0)
> > - internal_errorf("shf_emptybuf: no fd");
> > + internal_errorf("%s: no fd", __func__);
> >  
> >   if (shf->flags & SHF_ERROR) {
> >   errno = shf->errno_;
> > @@ -392,7 +392,7 @@ shf_fillbuf(struct shf *shf)
> >   return 0;
> >  
> >   if (shf->fd < 0)
> > - internal_errorf("shf_fillbuf: no fd");
> > + internal_errorf("%s: no fd", __func__);
> >  
> >   if (shf->flags & (SHF_EOF | SHF_ERROR)) {
> >   if (shf->flags & SHF_ERROR)
> > @@ -438,10 +438,10 @@ shf_read(char *buf, int bsize, struct sh
> >   int ncopy;
> >  
> >   if (!(shf->flags & SHF_RD))
> > - internal_errorf("shf_read: flags %x", shf->flags);
> > + internal_errorf("%s: flags %x", __func__, shf->flags);
> >  
> >   if (bsize <= 0)
> > - internal_errorf("shf_read: bsize %d", bsize);
> > + internal_errorf("%s: bsize %d", __func__, bsize);
> >  
> >   while (bsize > 0) {
> >   if (shf->rnleft == 0 &&
> > @@ -473,7 +473,7 @@ shf_getse(char *buf, int bsize, struct s
> >   char *orig_buf = buf;
> >  
> >   if (!(shf->flags & SHF_RD))
> > - internal_errorf("shf_getse: flags %x", shf->flags);
> > + internal_errorf("%s: flags %x", __func__, shf->flags);
> >  
> >   if (bsize <= 0)
> >   return NULL;
> > @@ -508,7 +508,7 @@ int
> >  shf_getchar(struct shf *shf)
> >  {
> >   if (!(shf->flags & SHF_RD))
> > - internal_errorf("shf_getchar: flags %x", shf->flags);
> > + internal_errorf("%s: flags %x", __func__, shf->flags);
> >  
> >   if (shf->rnleft == 0 && (shf_fillbuf(shf) == EOF || shf->rnleft == 0))
> >   return EOF;
> > @@ -523,7 +523,7 @@ int
> >  shf_ungetc(int c, struct shf *shf)
> >  {
> >   if (!(shf->flags & SHF_RD))
> > - internal_errorf("shf_ungetc: flags %x", shf->flags);
> > + internal_errorf("%s: flags %x", __func__, shf->flags);
> >  
> >   if ((shf->flags & SHF_ERROR) || c == EOF ||
> >      (shf->rp == shf->buf && shf->rnleft))
> > @@ -558,7 +558,7 @@ int
> >  shf_putchar(int c, struct shf *shf)
> >  {
> >   if (!(shf->flags & SHF_WR))
> > - internal_errorf("shf_putchar: flags %x", shf->flags);
> > + internal_errorf("%s: flags %x", __func__, shf->flags);
> >  
> >   if (c == EOF)
> >   return EOF;
> > @@ -568,7 +568,7 @@ shf_putchar(int c, struct shf *shf)
> >   int n;
> >  
> >   if (shf->fd < 0)
> > - internal_errorf("shf_putchar: no fd");
> > + internal_errorf("%s: no fd", __func__);
> >   if (shf->flags & SHF_ERROR) {
> >   errno = shf->errno_;
> >   return EOF;
> > @@ -614,10 +614,10 @@ shf_write(const char *buf, int nbytes, s
> >   int ncopy;
> >  
> >   if (!(shf->flags & SHF_WR))
> > - internal_errorf("shf_write: flags %x", shf->flags);
> > + internal_errorf("%s: flags %x", __func__, shf->flags);
> >  
> >   if (nbytes < 0)
> > - internal_errorf("shf_write: nbytes %d", nbytes);
> > + internal_errorf("%s: nbytes %d", __func__, nbytes);
> >  
> >   /* Don't buffer if buffer is empty and we're writting a large amount. */
> >   if ((ncopy = shf->wnleft) &&
> > @@ -687,8 +687,8 @@ shf_snprintf(char *buf, int bsize, const
> >   int n;
> >  
> >   if (!buf || bsize <= 0)
> > - internal_errorf("shf_snprintf: buf %lx, bsize %d",
> > - (long) buf, bsize);
> > + internal_errorf("%s: buf %lx, bsize %d",
> > + __func__, (long) buf, bsize);
> >  
> >   shf_sopen(buf, bsize, SHF_WR, &shf);
> >   va_start(args, fmt);
> > Index: trap.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/trap.c,v
> > retrieving revision 1.31
> > diff -u -p -u -r1.31 trap.c
> > --- trap.c 16 Jan 2018 22:52:32 -0000 1.31
> > +++ trap.c 13 Mar 2018 08:16:38 -0000
> > @@ -402,8 +402,8 @@ setexecsig(Trap *p, int restore)
> >  {
> >   /* XXX debugging */
> >   if (!(p->flags & (TF_ORIG_IGN|TF_ORIG_DFL)))
> > - internal_errorf("setexecsig: unset signal %d(%s)",
> > -    p->signal, p->name);
> > + internal_errorf("%s: unset signal %d(%s)",
> > +    __func__, p->signal, p->name);
> >  
> >   /* restore original value for exec'd kids */
> >   p->flags &= ~(TF_EXEC_IGN|TF_EXEC_DFL);
> > Index: tree.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/tree.c,v
> > retrieving revision 1.32
> > diff -u -p -u -r1.32 tree.c
> > --- tree.c 20 Jan 2018 15:32:20 -0000 1.32
> > +++ tree.c 13 Mar 2018 08:16:38 -0000
> > @@ -533,8 +533,8 @@ wdscan(const char *wp, int c)
> >   break;
> >   default:
> >   internal_warningf(
> > -    "wdscan: unknown char 0x%x (carrying on)",
> > -    wp[-1]);
> > +    "%s: unknown char 0x%x (carrying on)",
> > +    __func__, wp[-1]);
> >   }
> >  }
> >  
> > Index: tty.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/tty.c,v
> > retrieving revision 1.16
> > diff -u -p -u -r1.16 tty.c
> > --- tty.c 14 Dec 2015 13:59:42 -0000 1.16
> > +++ tty.c 13 Mar 2018 08:16:38 -0000
> > @@ -50,8 +50,8 @@ tty_init(int init_ttystate)
> >   }
> >   }
> >   if ((tty_fd = fcntl(tfd, F_DUPFD_CLOEXEC, FDBASE)) < 0) {
> > - warningf(false, "j_ttyinit: dup of tty fd failed: %s",
> > -    strerror(errno));
> > + warningf(false, "%s: dup of tty fd failed: %s",
> > +    __func__, strerror(errno));
> >   } else if (init_ttystate)
> >   tcgetattr(tty_fd, &tty_state);
> >   if (do_close)
> > Index: var.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/var.c,v
> > retrieving revision 1.65
> > diff -u -p -u -r1.65 var.c
> > --- var.c 16 Jan 2018 22:52:32 -0000 1.65
> > +++ var.c 13 Mar 2018 08:16:38 -0000
> > @@ -367,8 +367,8 @@ setstr(struct tbl *vq, const char *s, in
> >   if (s >= vq->val.s &&
> >      s <= vq->val.s + strlen(vq->val.s))
> >   internal_errorf(
> > -    "setstr: %s=%s: assigning to self",
> > -    vq->name, s);
> > +    "%s: %s=%s: assigning to self",
> > +    __func__, vq->name, s);
> >   afree(vq->val.s, vq->areap);
> >   }
> >   vq->flag &= ~(ISSET|ALLOC);
> > Index: vi.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/vi.c,v
> > retrieving revision 1.55
> > diff -u -p -u -r1.55 vi.c
> > --- vi.c 16 Jan 2018 22:52:32 -0000 1.55
> > +++ vi.c 13 Mar 2018 08:16:39 -0000
> > @@ -1669,7 +1669,7 @@ grabhist(int save, int n)
> >   }
> >   (void) histnum(n);
> >   if ((hptr = *histpos()) == NULL) {
> > - internal_warningf("grabhist: bad history array");
> > + internal_warningf("%s: bad history array", __func__);
> >   return -1;
> >   }
> >   if (save)
> >
>

Reply | Threaded
Open this post in threaded view
|

Re: ksh: __func__ in warnings

Anton Lindqvist-2
In reply to this post by Anton Lindqvist-2
On Thu, Mar 15, 2018 at 08:37:06AM +0100, Anton Lindqvist wrote:

> On Tue, Mar 13, 2018 at 04:39:16PM +0800, Michael W. Bombardieri wrote:
> > Hello,
> >
> > Some errors and warnings printed by ksh have the function name
> > prefixed. __func__ could be used here instead of hard-coding
> > the name. The names are wrong for tty_init(), j_set_async(),
> > j_change(), x_file_glob() and c_ulimit() afaics.
> >
> > - Michael
>
> Looks good, just some minor cosmetic nits where the format string in
> some cases now fits on the previous line.
>
> Anyone else willing to OK?

This has now been committed, thanks!

> > Index: c_ksh.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/c_ksh.c,v
> > retrieving revision 1.58
> > diff -u -p -u -r1.58 c_ksh.c
> > --- c_ksh.c 16 Jan 2018 22:52:32 -0000 1.58
> > +++ c_ksh.c 13 Mar 2018 08:16:37 -0000
> > @@ -1273,7 +1273,7 @@ c_getopts(char **wp)
> >   }
> >  
> >   if (genv->loc->next == NULL) {
> > - internal_warningf("c_getopts: no argv");
> > + internal_warningf("%s: no argv", __func__);
> >   return 1;
> >   }
> >   /* Which arguments are we parsing... */
> > Index: c_ulimit.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/c_ulimit.c,v
> > retrieving revision 1.26
> > diff -u -p -u -r1.26 c_ulimit.c
> > --- c_ulimit.c 16 Jan 2018 22:52:32 -0000 1.26
> > +++ c_ulimit.c 13 Mar 2018 08:16:37 -0000
> > @@ -97,7 +97,7 @@ c_ulimit(char **wp)
> >   for (l = limits; l->name && l->option != optc; l++)
> >   ;
> >   if (!l->name) {
> > - internal_warningf("ulimit: %c", optc);
> > + internal_warningf("%s: %c", __func__, optc);
> >   return 1;
> >   }
> >   if (builtin_opt.optarg) {
> > Index: edit.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/edit.c,v
> > retrieving revision 1.63
> > diff -u -p -u -r1.63 edit.c
> > --- edit.c 16 Jan 2018 22:52:32 -0000 1.63
> > +++ edit.c 13 Mar 2018 08:16:37 -0000
> > @@ -372,7 +372,7 @@ x_file_glob(int flags, const char *str,
> >   source = s;
> >   if (yylex(ONEWORD|UNESCAPE) != LWORD) {
> >   source = sold;
> > - internal_warningf("fileglob: substitute error");
> > + internal_warningf("%s: substitute error", __func__);
> >   return 0;
> >   }
> >   source = sold;
> > Index: exec.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/exec.c,v
> > retrieving revision 1.72
> > diff -u -p -u -r1.72 exec.c
> > --- exec.c 16 Jan 2018 22:52:32 -0000 1.72
> > +++ exec.c 13 Mar 2018 08:16:37 -0000
> > @@ -727,7 +727,7 @@ shcomexec(char **wp)
> >  
> >   tp = ktsearch(&builtins, *wp, hash(*wp));
> >   if (tp == NULL)
> > - internal_errorf("shcomexec: %s", *wp);
> > + internal_errorf("%s: %s", __func__, *wp);
> >   return call_builtin(tp, wp);
> >  }
> >  
> > @@ -1221,7 +1221,7 @@ herein(const char *content, int sub)
> >   s->start = s->str = content;
> >   source = s;
> >   if (yylex(ONEWORD|HEREDOC) != LWORD)
> > - internal_errorf("herein: yylex");
> > + internal_errorf("%s: yylex", __func__);
> >   source = osource;
> >   shf_puts(evalstr(yylval.cp, 0), shf);
> >   } else
> > @@ -1446,5 +1446,5 @@ static void
> >  dbteste_error(Test_env *te, int offset, const char *msg)
> >  {
> >   te->flags |= TEF_ERROR;
> > - internal_warningf("dbteste_error: %s (offset %d)", msg, offset);
> > + internal_warningf("%s: %s (offset %d)", __func__, msg, offset);
> >  }
> > Index: jobs.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/jobs.c,v
> > retrieving revision 1.59
> > diff -u -p -u -r1.59 jobs.c
> > --- jobs.c 16 Jan 2018 22:52:32 -0000 1.59
> > +++ jobs.c 13 Mar 2018 08:16:38 -0000
> > @@ -200,13 +200,13 @@ j_suspend(void)
> >   if (restore_ttypgrp >= 0) {
> >   if (tcsetpgrp(tty_fd, restore_ttypgrp) < 0) {
> >   warningf(false,
> > -    "j_suspend: tcsetpgrp() failed: %s",
> > -    strerror(errno));
> > +    "%s: tcsetpgrp() failed: %s",
> > +    __func__, strerror(errno));
> >   } else {
> >   if (setpgid(0, restore_ttypgrp) < 0) {
> >   warningf(false,
> > -    "j_suspend: setpgid() failed: %s",
> > -    strerror(errno));
> > +    "%s: setpgid() failed: %s",
> > +    __func__, strerror(errno));
> >   }
> >   }
> >   }
> > @@ -225,14 +225,14 @@ j_suspend(void)
> >   if (restore_ttypgrp >= 0) {
> >   if (setpgid(0, kshpid) < 0) {
> >   warningf(false,
> > -    "j_suspend: setpgid() failed: %s",
> > -    strerror(errno));
> > +    "%s: setpgid() failed: %s",
> > +    __func__, strerror(errno));
> >   ttypgrp_ok = 0;
> >   } else {
> >   if (tcsetpgrp(tty_fd, kshpid) < 0) {
> >   warningf(false,
> > -    "j_suspend: tcsetpgrp() failed: %s",
> > -    strerror(errno));
> > +    "%s: tcsetpgrp() failed: %s",
> > +    __func__, strerror(errno));
> >   ttypgrp_ok = 0;
> >   }
> >   }
> > @@ -309,8 +309,8 @@ j_change(void)
> >   ttypgrp_ok = use_tty && tty_fd >= 0 && tty_devtty;
> >  
> >   if (ttypgrp_ok && (our_pgrp = getpgrp()) < 0) {
> > - warningf(false, "j_init: getpgrp() failed: %s",
> > -    strerror(errno));
> > + warningf(false, "%s: getpgrp() failed: %s",
> > +    __func__, strerror(errno));
> >   ttypgrp_ok = 0;
> >   }
> >   if (ttypgrp_ok) {
> > @@ -322,8 +322,8 @@ j_change(void)
> >  
> >   if ((ttypgrp = tcgetpgrp(tty_fd)) < 0) {
> >   warningf(false,
> > -    "j_init: tcgetpgrp() failed: %s",
> > -    strerror(errno));
> > +    "%s: tcgetpgrp() failed: %s",
> > +    __func__, strerror(errno));
> >   ttypgrp_ok = 0;
> >   break;
> >   }
> > @@ -338,14 +338,14 @@ j_change(void)
> >   if (ttypgrp_ok && our_pgrp != kshpid) {
> >   if (setpgid(0, kshpid) < 0) {
> >   warningf(false,
> > -    "j_init: setpgid() failed: %s",
> > -    strerror(errno));
> > +    "%s: setpgid() failed: %s",
> > +    __func__, strerror(errno));
> >   ttypgrp_ok = 0;
> >   } else {
> >   if (tcsetpgrp(tty_fd, kshpid) < 0) {
> >   warningf(false,
> > -    "j_init: tcsetpgrp() failed: %s",
> > -    strerror(errno));
> > +    "%s: tcsetpgrp() failed: %s",
> > +    __func__, strerror(errno));
> >   ttypgrp_ok = 0;
> >   } else
> >   restore_ttypgrp = our_pgrp;
> > @@ -412,8 +412,8 @@ exchild(struct op *t, int flags, volatil
> >   if (flags&XPIPEI) { /* continuing with a pipe */
> >   if (!last_job)
> >   internal_errorf(
> > -    "exchild: XPIPEI and no last_job - pid %d",
> > -    (int) procpid);
> > +    "%s: XPIPEI and no last_job - pid %d",
> > +    __func__, (int) procpid);
> >   j = last_job;
> >   last_proc->next = p;
> >   last_proc = p;
> > @@ -522,7 +522,7 @@ exchild(struct op *t, int flags, volatil
> >   tty_close();
> >   cleartraps();
> >   execute(t, (flags & XERROK) | XEXEC, NULL); /* no return */
> > - internal_warningf("exchild: execute() returned");
> > + internal_warningf("%s: execute() returned", __func__);
> >   unwind(LLEAVE);
> >   /* NOTREACHED */
> >   }
> > @@ -588,9 +588,9 @@ waitlast(void)
> >   j = last_job;
> >   if (!j || !(j->flags & JF_STARTED)) {
> >   if (!j)
> > - warningf(true, "waitlast: no last job");
> > + warningf(true, "%s: no last job", __func__);
> >   else
> > - internal_warningf("waitlast: not started");
> > + internal_warningf("%s: not started", __func__);
> >   sigprocmask(SIG_SETMASK, &omask, NULL);
> >   return 125; /* not so arbitrary, non-zero value */
> >   }
> > @@ -931,7 +931,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_warningf("j_async: job not started");
> > + internal_warningf("%s: job not started", __func__);
> >   return;
> >   }
> >   async_job = j;
> > @@ -945,8 +945,8 @@ j_set_async(Job *j)
> >   if (!oldest) {
> >   /* XXX debugging */
> >   if (!(async_job->flags & JF_ZOMBIE) || nzombie != 1) {
> > - internal_warningf("j_async: bad nzombie (%d)",
> > -    nzombie);
> > + internal_warningf("%s: bad nzombie (%d)",
> > +    __func__, nzombie);
> >   nzombie = 0;
> >   }
> >   break;
> > @@ -1035,8 +1035,8 @@ j_waitj(Job *j,
> >   j->flags |= JF_SAVEDTTYPGRP;
> >   if (tcsetpgrp(tty_fd, our_pgrp) < 0) {
> >   warningf(true,
> > -    "j_waitj: tcsetpgrp(%d, %d) failed: %s",
> > -    tty_fd, (int) our_pgrp,
> > +    "%s: tcsetpgrp(%d, %d) failed: %s",
> > +    __func__, tty_fd, (int) our_pgrp,
> >   strerror(errno));
> >   }
> >   if (j->state == PSTOPPED) {
> > @@ -1186,8 +1186,8 @@ check_job(Job *j)
> >  
> >   /* XXX debugging (nasty - interrupt routine using shl_out) */
> >   if (!(j->flags & JF_STARTED)) {
> > - internal_warningf("check_job: job started (flags 0x%x)",
> > -    j->flags);
> > + internal_warningf("%s: job started (flags 0x%x)",
> > +    __func__, j->flags);
> >   return;
> >   }
> >  
> > @@ -1546,7 +1546,7 @@ remove_job(Job *j, const char *where)
> >   for (; curr != NULL && curr != j; prev = &curr->next, curr = *prev)
> >   ;
> >   if (curr != j) {
> > - internal_warningf("remove_job: job not found (%s)", where);
> > + internal_warningf("%s: job not found (%s)", __func__, where);
> >   return;
> >   }
> >   *prev = curr->next;
> > Index: main.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/main.c,v
> > retrieving revision 1.89
> > diff -u -p -u -r1.89 main.c
> > --- main.c 16 Jan 2018 22:52:32 -0000 1.89
> > +++ main.c 13 Mar 2018 08:16:38 -0000
> > @@ -492,7 +492,7 @@ include(const char *name, int argc, char
> >   unwind(i);
> >   /* NOTREACHED */
> >   default:
> > - internal_errorf("include: %d", i);
> > + internal_errorf("%s: %d", __func__, i);
> >   /* NOTREACHED */
> >   }
> >   }
> > @@ -579,7 +579,7 @@ shell(Source *volatile s, volatile int t
> >   default:
> >   source = old_source;
> >   quitenv(NULL);
> > - internal_errorf("shell: %d", i);
> > + internal_errorf("%s: %d", __func__, i);
> >   /* NOTREACHED */
> >   }
> >   }
> > Index: misc.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/misc.c,v
> > retrieving revision 1.68
> > diff -u -p -u -r1.68 misc.c
> > --- misc.c 16 Jan 2018 22:52:32 -0000 1.68
> > +++ misc.c 13 Mar 2018 08:16:38 -0000
> > @@ -407,7 +407,7 @@ parse_args(char **argv,
> >   break;
> >   }
> >   if (ele == NELEM(sh_options)) {
> > - internal_errorf("parse_args: `%c'", optc);
> > + internal_errorf("%s: `%c'", __func__, optc);
> >   return -1; /* not reached */
> >   }
> >   }
> > Index: shf.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/shf.c,v
> > retrieving revision 1.32
> > diff -u -p -u -r1.32 shf.c
> > --- shf.c 16 Jan 2018 22:52:32 -0000 1.32
> > +++ shf.c 13 Mar 2018 08:16:38 -0000
> > @@ -100,7 +100,7 @@ shf_fdopen(int fd, int sflags, struct sh
> >   }
> >  
> >   if (!(sflags & (SHF_RD | SHF_WR)))
> > - internal_errorf("shf_fdopen: missing read/write");
> > + internal_errorf("%s: missing read/write", __func__);
> >  
> >   if (shf) {
> >   if (bsize) {
> > @@ -157,9 +157,9 @@ shf_reopen(int fd, int sflags, struct sh
> >   }
> >  
> >   if (!(sflags & (SHF_RD | SHF_WR)))
> > - internal_errorf("shf_reopen: missing read/write");
> > + internal_errorf("%s: missing read/write", __func__);
> >   if (!shf || !shf->buf || shf->bsize < bsize)
> > - internal_errorf("shf_reopen: bad shf/buf/bsize");
> > + internal_errorf("%s: bad shf/buf/bsize", __func__);
> >  
> >   /* assumes shf->buf and shf->bsize already set up */
> >   shf->fd = fd;
> > @@ -189,7 +189,7 @@ shf_sopen(char *buf, int bsize, int sfla
> >   /* can't have a read+write string */
> >   if (!(sflags & (SHF_RD | SHF_WR)) ||
> >      (sflags & (SHF_RD | SHF_WR)) == (SHF_RD | SHF_WR))
> > - internal_errorf("shf_sopen: flags 0x%x", sflags);
> > + internal_errorf("%s: flags 0x%x", __func__, sflags);
> >  
> >   if (!shf) {
> >   shf = alloc(sizeof(struct shf), ATEMP);
> > @@ -282,7 +282,7 @@ shf_flush(struct shf *shf)
> >   return (shf->flags & SHF_WR) ? EOF : 0;
> >  
> >   if (shf->fd < 0)
> > - internal_errorf("shf_flush: no fd");
> > + internal_errorf("%s: no fd", __func__);
> >  
> >   if (shf->flags & SHF_ERROR) {
> >   errno = shf->errno_;
> > @@ -312,7 +312,7 @@ shf_emptybuf(struct shf *shf, int flags)
> >   int ret = 0;
> >  
> >   if (!(shf->flags & SHF_STRING) && shf->fd < 0)
> > - internal_errorf("shf_emptybuf: no fd");
> > + internal_errorf("%s: no fd", __func__);
> >  
> >   if (shf->flags & SHF_ERROR) {
> >   errno = shf->errno_;
> > @@ -392,7 +392,7 @@ shf_fillbuf(struct shf *shf)
> >   return 0;
> >  
> >   if (shf->fd < 0)
> > - internal_errorf("shf_fillbuf: no fd");
> > + internal_errorf("%s: no fd", __func__);
> >  
> >   if (shf->flags & (SHF_EOF | SHF_ERROR)) {
> >   if (shf->flags & SHF_ERROR)
> > @@ -438,10 +438,10 @@ shf_read(char *buf, int bsize, struct sh
> >   int ncopy;
> >  
> >   if (!(shf->flags & SHF_RD))
> > - internal_errorf("shf_read: flags %x", shf->flags);
> > + internal_errorf("%s: flags %x", __func__, shf->flags);
> >  
> >   if (bsize <= 0)
> > - internal_errorf("shf_read: bsize %d", bsize);
> > + internal_errorf("%s: bsize %d", __func__, bsize);
> >  
> >   while (bsize > 0) {
> >   if (shf->rnleft == 0 &&
> > @@ -473,7 +473,7 @@ shf_getse(char *buf, int bsize, struct s
> >   char *orig_buf = buf;
> >  
> >   if (!(shf->flags & SHF_RD))
> > - internal_errorf("shf_getse: flags %x", shf->flags);
> > + internal_errorf("%s: flags %x", __func__, shf->flags);
> >  
> >   if (bsize <= 0)
> >   return NULL;
> > @@ -508,7 +508,7 @@ int
> >  shf_getchar(struct shf *shf)
> >  {
> >   if (!(shf->flags & SHF_RD))
> > - internal_errorf("shf_getchar: flags %x", shf->flags);
> > + internal_errorf("%s: flags %x", __func__, shf->flags);
> >  
> >   if (shf->rnleft == 0 && (shf_fillbuf(shf) == EOF || shf->rnleft == 0))
> >   return EOF;
> > @@ -523,7 +523,7 @@ int
> >  shf_ungetc(int c, struct shf *shf)
> >  {
> >   if (!(shf->flags & SHF_RD))
> > - internal_errorf("shf_ungetc: flags %x", shf->flags);
> > + internal_errorf("%s: flags %x", __func__, shf->flags);
> >  
> >   if ((shf->flags & SHF_ERROR) || c == EOF ||
> >      (shf->rp == shf->buf && shf->rnleft))
> > @@ -558,7 +558,7 @@ int
> >  shf_putchar(int c, struct shf *shf)
> >  {
> >   if (!(shf->flags & SHF_WR))
> > - internal_errorf("shf_putchar: flags %x", shf->flags);
> > + internal_errorf("%s: flags %x", __func__, shf->flags);
> >  
> >   if (c == EOF)
> >   return EOF;
> > @@ -568,7 +568,7 @@ shf_putchar(int c, struct shf *shf)
> >   int n;
> >  
> >   if (shf->fd < 0)
> > - internal_errorf("shf_putchar: no fd");
> > + internal_errorf("%s: no fd", __func__);
> >   if (shf->flags & SHF_ERROR) {
> >   errno = shf->errno_;
> >   return EOF;
> > @@ -614,10 +614,10 @@ shf_write(const char *buf, int nbytes, s
> >   int ncopy;
> >  
> >   if (!(shf->flags & SHF_WR))
> > - internal_errorf("shf_write: flags %x", shf->flags);
> > + internal_errorf("%s: flags %x", __func__, shf->flags);
> >  
> >   if (nbytes < 0)
> > - internal_errorf("shf_write: nbytes %d", nbytes);
> > + internal_errorf("%s: nbytes %d", __func__, nbytes);
> >  
> >   /* Don't buffer if buffer is empty and we're writting a large amount. */
> >   if ((ncopy = shf->wnleft) &&
> > @@ -687,8 +687,8 @@ shf_snprintf(char *buf, int bsize, const
> >   int n;
> >  
> >   if (!buf || bsize <= 0)
> > - internal_errorf("shf_snprintf: buf %lx, bsize %d",
> > - (long) buf, bsize);
> > + internal_errorf("%s: buf %lx, bsize %d",
> > + __func__, (long) buf, bsize);
> >  
> >   shf_sopen(buf, bsize, SHF_WR, &shf);
> >   va_start(args, fmt);
> > Index: trap.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/trap.c,v
> > retrieving revision 1.31
> > diff -u -p -u -r1.31 trap.c
> > --- trap.c 16 Jan 2018 22:52:32 -0000 1.31
> > +++ trap.c 13 Mar 2018 08:16:38 -0000
> > @@ -402,8 +402,8 @@ setexecsig(Trap *p, int restore)
> >  {
> >   /* XXX debugging */
> >   if (!(p->flags & (TF_ORIG_IGN|TF_ORIG_DFL)))
> > - internal_errorf("setexecsig: unset signal %d(%s)",
> > -    p->signal, p->name);
> > + internal_errorf("%s: unset signal %d(%s)",
> > +    __func__, p->signal, p->name);
> >  
> >   /* restore original value for exec'd kids */
> >   p->flags &= ~(TF_EXEC_IGN|TF_EXEC_DFL);
> > Index: tree.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/tree.c,v
> > retrieving revision 1.32
> > diff -u -p -u -r1.32 tree.c
> > --- tree.c 20 Jan 2018 15:32:20 -0000 1.32
> > +++ tree.c 13 Mar 2018 08:16:38 -0000
> > @@ -533,8 +533,8 @@ wdscan(const char *wp, int c)
> >   break;
> >   default:
> >   internal_warningf(
> > -    "wdscan: unknown char 0x%x (carrying on)",
> > -    wp[-1]);
> > +    "%s: unknown char 0x%x (carrying on)",
> > +    __func__, wp[-1]);
> >   }
> >  }
> >  
> > Index: tty.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/tty.c,v
> > retrieving revision 1.16
> > diff -u -p -u -r1.16 tty.c
> > --- tty.c 14 Dec 2015 13:59:42 -0000 1.16
> > +++ tty.c 13 Mar 2018 08:16:38 -0000
> > @@ -50,8 +50,8 @@ tty_init(int init_ttystate)
> >   }
> >   }
> >   if ((tty_fd = fcntl(tfd, F_DUPFD_CLOEXEC, FDBASE)) < 0) {
> > - warningf(false, "j_ttyinit: dup of tty fd failed: %s",
> > -    strerror(errno));
> > + warningf(false, "%s: dup of tty fd failed: %s",
> > +    __func__, strerror(errno));
> >   } else if (init_ttystate)
> >   tcgetattr(tty_fd, &tty_state);
> >   if (do_close)
> > Index: var.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/var.c,v
> > retrieving revision 1.65
> > diff -u -p -u -r1.65 var.c
> > --- var.c 16 Jan 2018 22:52:32 -0000 1.65
> > +++ var.c 13 Mar 2018 08:16:38 -0000
> > @@ -367,8 +367,8 @@ setstr(struct tbl *vq, const char *s, in
> >   if (s >= vq->val.s &&
> >      s <= vq->val.s + strlen(vq->val.s))
> >   internal_errorf(
> > -    "setstr: %s=%s: assigning to self",
> > -    vq->name, s);
> > +    "%s: %s=%s: assigning to self",
> > +    __func__, vq->name, s);
> >   afree(vq->val.s, vq->areap);
> >   }
> >   vq->flag &= ~(ISSET|ALLOC);
> > Index: vi.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ksh/vi.c,v
> > retrieving revision 1.55
> > diff -u -p -u -r1.55 vi.c
> > --- vi.c 16 Jan 2018 22:52:32 -0000 1.55
> > +++ vi.c 13 Mar 2018 08:16:39 -0000
> > @@ -1669,7 +1669,7 @@ grabhist(int save, int n)
> >   }
> >   (void) histnum(n);
> >   if ((hptr = *histpos()) == NULL) {
> > - internal_warningf("grabhist: bad history array");
> > + internal_warningf("%s: bad history array", __func__);
> >   return -1;
> >   }
> >   if (save)
> >