Clean up the signal mess, saves 172 Bytes:

* 'sigseen' in Build.sh goes away
* Signal name existence is checked in this order:
  have our own¹ -> sys_signame[] -> _sys_signame[] -> build our own²
* Signal description existence is checked in this order:
  sys_siglist[] -> _sys_siglist[] -> strsignal() -> NULL³
¹ Predefined list of items, for operating systems where we
  cannot build² them, i.e. Plan 9 and Minix 3 (e.g. no $CPP -dD)
² The usual cpp(1) stuff
³ Changed later, see below
* Make $CPP test dependent on $NEED_MKSH_SIGNAME (others can
  be added here, this is not absolute)
* Make signal name list generation² dependent on $NEED_MKSH_SIGNAME
* Fix check if the generation worked
* Guarantee that sigtraps[*].name and sigtraps[*].mess are valid
  C strings; this makes the code shorter *and* removes a few pos-
  sible nil pointer dereferences
* Embed autoconf'd usages of sys_sig* / strsignal / mksh_sigpairs
  into inittraps()
* Check for each signal 0<=i<=NSIG that
  name is not NULL or "" -> replace with ("%d", i)
  mess is not NULL or "" -> replace with ("Signal %d", i)
  name does not start (case-insensitive) with "SIG" -> name += 3
* In gettrap(), fix check if signal name starts, case-sensitive
  or case-insensitive, depending on need, with "SIG" (bug from millert@)

Other changes:
* Build.sh: ac_test[n]() are documented
* Build.sh: ac_test[n]() can have negative prereqs as well now
* Build.sh: use <<-'EOF' consistently
* bump patchlevel to today
This commit is contained in:
tg 2007-01-12 00:25:40 +00:00
parent 3b63b986c3
commit 2f15a11c55
7 changed files with 122 additions and 91 deletions

View File

@ -1,8 +1,8 @@
#!/bin/sh
# $MirOS: src/bin/mksh/Build.sh,v 1.93 2007/01/11 03:03:34 tg Exp $
# $MirOS: src/bin/mksh/Build.sh,v 1.94 2007/01/12 00:25:38 tg Exp $
#-
# Environment: CC, CFLAGS, CPPFLAGS, LDFLAGS, LIBS, NOWARN, NROFF
# With -x: SRCS (extra), sigseen (XXX go away), TARGET_OS (uname -s)
# With -x: SRCS (extra), TARGET_OS (uname -s)
# XXX TODO: check for __attribute__ (Minix 3 ACK probably doesn't)
# and other gccisms in the code, handle appropriately. Note that I
@ -21,13 +21,19 @@ upper()
echo "$@" | tr qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM
}
# pipe .c | ac_test[n] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
ac_testn()
{
f=$1
fu=`upper $f`
fc=0
if test x"$2" = x""; then
ft=1
else
if test x"$2" = x"!"; then
fc=1
shift
fi
eval ft=\$HAVE_`upper $2`
shift
fi
@ -42,7 +48,7 @@ ac_testn()
$e "==> $fd... yes (cached)"
return
fi
if test 0 = "$ft"; then
if test $fc = "$ft"; then
fv=$2
eval HAVE_$fu=$fv
test 0 = "$fv" && fv=no
@ -121,7 +127,6 @@ done
if test $x = 0; then
SRCS=
sigseen=
TARGET_OS=`uname -s 2>/dev/null || uname`
fi
SRCS="$SRCS alloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c"
@ -130,7 +135,6 @@ SRCS="$SRCS jobs.c lex.c main.c misc.c shf.c syn.c tree.c var.c"
case $TARGET_OS in
CYGWIN*)
LDSTATIC=
sigseen=:
;;
Darwin)
LDSTATIC=
@ -143,13 +147,11 @@ Linux)
CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=2 -D_BSD_SOURCE -D_GNU_SOURCE"
CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
LDSTATIC=
sigseen=:
;;
SunOS)
CPPFLAGS="$CPPFLAGS -D_BSD_SOURCE -D__EXTENSIONS__"
CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
LDSTATIC=
sigseen=:
r=1
;;
esac
@ -199,6 +201,45 @@ ac_test sys_param_h '' '<sys/param.h>' <<'EOF'
int main(void) { return (0); }
EOF
ac_test mksh_signame '' 'our own list of signal names' <<-'EOF'
#include <stdlib.h> /* for NULL */
#define MKSH_SIGNAMES_CHECK
#include "signames.c"
int main(void) { return (mksh_sigpair[0].nr); }
EOF
ac_test sys_signame '!' mksh_signame 0 'the sys_signame[] array' <<-'EOF'
extern const char *const sys_signame[];
int main(void) { return (sys_signame[0][0]); }
EOF
ac_test _sys_signame '!' sys_signame 0 'the _sys_signame[] array' <<-'EOF'
extern const char *const _sys_signame[];
int main(void) { return (_sys_signame[0][0]); }
EOF
if test 000 = $HAVE_SYS_SIGNAME$HAVE__SYS_SIGNAME$HAVE_MKSH_SIGNAME; then
NEED_MKSH_SIGNAME=1
else
NEED_MKSH_SIGNAME=0
fi
ac_test sys_siglist '' 'the sys_siglist[] array' <<-'EOF'
extern const char *const sys_siglist[];
int main(void) { return (sys_siglist[0][0]); }
EOF
ac_test _sys_siglist '!' sys_siglist 0 'the _sys_siglist[] array' <<-'EOF'
extern const char *const _sys_siglist[];
int main(void) { return (_sys_siglist[0][0]); }
EOF
ac_test strsignal '!' _sys_siglist 0 <<-'EOF'
#include <string.h>
#include <signal.h>
int main(void) { return (strsignal(1)[0]); }
EOF
ac_test arc4random <<-'EOF'
#include <stdlib.h>
int main(void) { return (arc4random()); }
@ -209,13 +250,13 @@ ac_test arc4random_push arc4random 0 <<-'EOF'
int main(void) { arc4random_push(1); return (0); }
EOF
ac_test setlocale_ctype '' 'setlocale(LC_CTYPE, "")' <<'EOF'
ac_test setlocale_ctype '' 'setlocale(LC_CTYPE, "")' <<-'EOF'
#include <locale.h>
#include <stddef.h>
int main(void) { return ((ptrdiff_t)(void *)setlocale(LC_CTYPE, "")); }
EOF
ac_test langinfo_codeset setlocale_ctype 0 'nl_langinfo(CODESET)' <<'EOF'
ac_test langinfo_codeset setlocale_ctype 0 'nl_langinfo(CODESET)' <<-'EOF'
#include <langinfo.h>
#include <stddef.h>
int main(void) { return ((ptrdiff_t)(void *)nl_langinfo(CODESET)); }
@ -256,12 +297,7 @@ ac_test strlcpy <<-'EOF'
int main(int ac, char *av[]) { return (strlcpy(*av, av[1], ac)); }
EOF
if test x"$sigseen" = x:; then # XXX for now
HAVE_SYS_SIGNAME=0 # XXX
else # XXX
HAVE_SYS_SIGNAME=1 # XXX
fi # XXX
if test 0 = $HAVE_SYS_SIGNAME; then
if test 1 = $NEED_MKSH_SIGNAME; then
$e "... checking how to run the C Preprocessor"
rm -f a.out
( ( echo '#if (23 * 2 - 2) == (fnord + 2)'
@ -285,8 +321,9 @@ fi
$e ... done.
if test x"$sigseen" = x:; then
if test 1 = $NEED_MKSH_SIGNAME; then
$e Generating list of signal names...
sigseen=:
NSIG=`( echo '#include <signal.h>'; echo "mksh_cfg: NSIG" ) | \
$CPP $CPPFLAGS | grep mksh_cfg: | \
sed 's/^mksh_cfg: \([0-9x]*\).*$/\1/'`
@ -309,7 +346,7 @@ if test x"$sigseen" = x:; then
;;
esac
done >signames.inc
test -f signames.inc || exit 1
grep ', ' signames.inc || exit 1
$e done.
fi

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/Makefile,v 1.20 2006/11/12 13:21:50 tg Exp $
# $MirOS: src/bin/mksh/Makefile,v 1.21 2007/01/12 00:25:39 tg Exp $
PROG= mksh
SRCS= alloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c \
@ -7,6 +7,7 @@ CPPFLAGS+= -DHAVE_SYS_PARAM_H -DHAVE_ARC4RANDOM -DHAVE_ARC4RANDOM_PUSH
CPPFLAGS+= -DHAVE_SETLOCALE_CTYPE -DHAVE_LANGINFO_CODESET
CPPFLAGS+= -DHAVE_SETMODE -DHAVE_SETRESUGID -DHAVE_SETGROUPS
CPPFLAGS+= -DHAVE_STRCASESTR -DHAVE_STRLCPY
CPPFLAGS+= -DHAVE_SYS_SIGLIST -DHAVE_SYS_SIGNAME
CDIAGFLAGS+= -Wno-cast-qual
LINKS+= ${BINDIR}/${PROG} ${BINDIR}/sh

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.80 2007/01/11 02:08:50 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.81 2007/01/12 00:25:39 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -7,7 +7,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R29 2007/01/11
@(#)MIRBSD KSH R29 2007/01/12
description:
Check version of shell.
category: pdksh

24
funcs.c
View File

@ -5,7 +5,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.40 2007/01/11 00:32:31 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.41 2007/01/12 00:25:39 tg Exp $");
int
c_cd(char **wp)
@ -1085,16 +1085,10 @@ kill_fmt_entry(const void *arg, int i, char *buf, int buflen)
const struct kill_info *ki = (const struct kill_info *)arg;
i++;
if (sigtraps[i].name)
shf_snprintf(buf, buflen, "%*d %*s %s",
ki->num_width, i,
ki->name_width, sigtraps[i].name,
sigtraps[i].mess);
else
shf_snprintf(buf, buflen, "%*d %*d %s",
ki->num_width, i,
ki->name_width, sigtraps[i].signal,
sigtraps[i].mess);
shf_snprintf(buf, buflen, "%*d %*s %s",
ki->num_width, i,
ki->name_width, sigtraps[i].name,
sigtraps[i].mess);
return buf;
}
@ -1152,7 +1146,7 @@ c_kill(char **wp)
return 1;
if (n > 128 && n < 128 + NSIG)
n -= 128;
if (n > 0 && n < NSIG && sigtraps[n].name)
if (n > 0 && n < NSIG)
shprintf("%s\n", sigtraps[n].name);
else
shprintf("%d\n", n);
@ -1166,9 +1160,7 @@ c_kill(char **wp)
ki.num_width++;
ki.name_width = mess_width = 0;
for (j = 0; j < NSIG; j++) {
w = sigtraps[j].name ?
(int)strlen(sigtraps[j].name) :
ki.num_width;
w = strlen(sigtraps[j].name);
if (w > ki.name_width)
ki.name_width = w;
w = strlen(sigtraps[j].mess);
@ -1177,7 +1169,7 @@ c_kill(char **wp)
}
print_columns(shl_stdout, NSIG - 1,
kill_fmt_entry, (void *) &ki,
kill_fmt_entry, (void *)&ki,
ki.num_width + ki.name_width + mess_width + 3, 1);
}
return 0;

View File

@ -3,22 +3,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.34 2006/11/12 12:49:25 tg Exp $");
#ifndef mksh_siglist
#if defined(BSD) || defined(__APPLE__)
#define mksh_signame(x) sys_signame[(x)]
#define mksh_siglist(x) sys_siglist[(x)]
#elif defined(__INTERIX)
#define mksh_signame(x) _sys_signame[(x)]
#define mksh_siglist(x) _sys_siglist[(x)]
#elif defined(__gnu_linux__) || defined(__sun__) || defined(__CYGWIN__)
#define NEED_MKSH_SIGNAME /* sync the list above with Build.sh */
#define mksh_siglist(x) strsignal(x)
#else
# error "Define sys_sig{name,list} for this platform!"
#endif
#endif /* ndef mksh_siglist */
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.35 2007/01/12 00:25:40 tg Exp $");
Trap sigtraps[NSIG + 1];
static struct sigaction Sigact_ign, Sigact_trap;
@ -965,25 +950,11 @@ sprinkle(int fd)
}
#endif
#ifdef NEED_MKSH_SIGNAME
static const char *
mksh_signame(int s)
{
int i = 0;
static const struct _mksh_sigpair {
int nr;
const char *name;
} mksh_sigpair[] = {
#include "signames.inc"
{ 0, NULL }
};
mksh_sigscan:
if ((mksh_sigpair[i].nr == s) || !mksh_sigpair[i].name)
return (mksh_sigpair[i].name);
++i;
goto mksh_sigscan;
}
#if HAVE_SYS_SIGNAME
#elif HAVE__SYS_SIGNAME
#define sys_signame _sys_signame
#else
#include "signames.c"
#endif
void
@ -998,8 +969,31 @@ inittraps(void)
sigtraps[i].name = "ERR";
sigtraps[i].mess = "Error handler";
} else {
sigtraps[i].name = mksh_signame(i);
sigtraps[i].mess = mksh_siglist(i);
#if HAVE_SYS_SIGNAME || HAVE_SYS_SIGNAME
sigtraps[i].name = sys_signame[i];
#else
const struct mksh_sigpair *pair = mksh_sigpairs;
while ((pair->nr != i) && (pair->name != NULL))
++pair;
sigtraps[i].name = pair->name;
#endif
#if HAVE_SYS_SIGLIST
sigtraps[i].mess = sys_siglist[i];
#elif HAVE__SYS_SIGLIST
sigtraps[i].mess = _sys_siglist[i];
#elif HAVE_STRSIGNAL
sigtraps[i].mess = strsignal(i);
#else
sigtraps[i].mess = NULL;
#endif
if ((sigtraps[i].name == NULL) ||
(sigtraps[i].name[0] == '\0'))
sigtraps[i].name = shf_smprintf("%d", i);
if ((sigtraps[i].mess == NULL) ||
(sigtraps[i].mess[0] == '\0'))
sigtraps[i].mess = shf_smprintf("Signal %d", i);
if (!strncasecmp(sigtraps[i].name, "SIG", 3))
sigtraps[i].name += 3;
}
}
sigtraps[SIGEXIT_].name = "EXIT"; /* our name for signal 0 */
@ -1065,22 +1059,10 @@ gettrap(const char *name, int igncase)
return NULL;
}
for (p = sigtraps, i = NSIG+1; --i >= 0; p++)
if (p->name) {
if (igncase) {
if (p->name && (!strcasecmp(p->name, name) ||
(strlen(name) > 3 &&
(p->name[0] == 's' || p->name[0] == 'S') &&
(p->name[1] == 'i' || p->name[1] == 'I') &&
(p->name[2] == 'g' || p->name[2] == 'G') &&
!strcasecmp(p->name, name + 3))))
return p;
} else {
if (p->name && (!strcmp(p->name, name) ||
(strlen(name) > 3 && !strncmp("SIG",
p->name, 3) && !strcmp(p->name, name + 3))))
return p;
}
}
if (!(igncase ? strcasecmp : strcmp)(p->name, name) ||
(!strncasecmp(name, "SIG", 3) &&
!(igncase ? strcasecmp : strcmp)(p->name, name + 3)))
return (p);
return NULL;
}

4
sh.h
View File

@ -8,8 +8,8 @@
/* $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.92 2007/01/11 00:32:31 tg Exp $"
#define MKSH_VERSION "R29 2007/01/11"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.93 2007/01/12 00:25:40 tg Exp $"
#define MKSH_VERSION "R29 2007/01/12"
#if HAVE_SYS_PARAM_H
#include <sys/param.h>

19
signames.c Normal file
View File

@ -0,0 +1,19 @@
#ifndef MKSH_SIGNAMES_CHECK
__RCSID("$MirOS: src/bin/mksh/signames.c,v 1.1 2007/01/12 00:25:40 tg Exp $");
#endif
static const struct mksh_sigpair {
int nr;
const char *const name;
} mksh_sigpairs[] = {
#ifdef __Plan9__
...
#elif defined(__minix)
...
#elif defined(MKSH_SIGNAMES_CHECK)
#error no, must be OS supplied
#elif !defined(__IN_MKDEP)
#include "signames.inc"
#endif
{ 0, NULL }
};