compat/regress/glob/files
compat/regress/glob/globtest.c
compat/regress/glob/globtest.in
+compat/sig2str.c
compat/siglist.in
compat/snprintf.c
compat/stdbool.h
compat/strlcat.c
compat/strlcpy.c
compat/strsignal.c
-compat/strsigname.c
compat/timespec.h
compat/utime.h
compat/utimes.c
TEST_PROGS = @COMPAT_TEST_PROGS@
-LIBOBJDIR =
+LIBOBJDIR =
LTLIBOBJS = @LTLIBOBJS@
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/nanosleep.c
pw_dup.lo: $(srcdir)/pw_dup.c $(top_builddir)/config.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/pw_dup.c
+sig2str.lo: $(srcdir)/sig2str.c $(top_builddir)/config.h $(incdir)/missing.h \
+ $(incdir)/gettext.h
+ $(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/sig2str.c
siglist.lo: siglist.c $(top_builddir)/config.h $(incdir)/missing.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) siglist.c
snprintf.lo: $(srcdir)/snprintf.c $(top_builddir)/config.h $(incdir)/missing.h
strsignal.lo: $(srcdir)/strsignal.c $(top_builddir)/config.h \
$(incdir)/missing.h $(incdir)/gettext.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/strsignal.c
-strsigname.lo: $(srcdir)/strsigname.c $(top_builddir)/config.h \
- $(incdir)/missing.h $(incdir)/gettext.h
- $(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/strsigname.c
utimes.lo: $(srcdir)/utimes.c $(top_builddir)/config.h \
$(top_srcdir)/compat/utime.h $(incdir)/missing.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/utimes.c
/*
- * Copyright (c) 2009-2012 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2012 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
#include <sys/types.h>
+#include <errno.h>
#include <stdio.h>
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
+#endif /* STDC_HEADERS */
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif /* HAVE_STRING_H */
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
#include <signal.h>
#include "missing.h"
-#define DEFAULT_TEXT_DOMAIN "sudo"
-#include "gettext.h"
-
#if defined(HAVE_DECL_SYS_SIGNAME) && HAVE_DECL_SYS_SIGNAME == 1
-# define sudo_sys_signame sys_signame
+# define sudo_sys_signame sys_signame
#elif defined(HAVE_DECL__SYS_SIGNAME) && HAVE_DECL__SYS_SIGNAME == 1
-# define sudo_sys_signame _sys_signame
+# define sudo_sys_signame _sys_signame
#elif defined(HAVE_DECL___SYS_SIGNAME) && HAVE_DECL___SYS_SIGNAME == 1
-# define sudo_sys_signame __sys_signame
+# define sudo_sys_signame __sys_signame
#elif defined(HAVE_DECL_SYS_SIGABBREV) && HAVE_DECL_SYS_SIGABBREV == 1
-# define sudo_sys_signame sys_sigabbrev
+# define sudo_sys_signame sys_sigabbrev
#else
# ifdef HAVE_SYS_SIGABBREV
/* sys_sigabbrev is not declared by glibc */
#endif
/*
- * Return signal name
+ * Translate signal number to name.
*/
-char *
-strsigname(int signo)
+int
+sig2str(int signo, char *signame)
{
- if (signo > 0 && signo < NSIG && sudo_sys_signame[signo] != NULL)
- return (char *)sudo_sys_signame[signo];
- /* XXX - should be "Unknown signal: %d" */
- return _("Unknown signal");
+#if defined(SIGRTMIN) && defined(SIGRTMAX)
+ /* Realtime signal support as per Solaris. */
+ if (signo >= SIGRTMIN && signo <= SIGRTMAX) {
+ snprintf(signame, SIG2STR_MAX, "RTMIN+%d", (signo - SIGRTMIN));
+ return 0;
+ }
+#endif
+ if (signo > 0 && signo < NSIG && sudo_sys_signame[signo] != NULL) {
+ strlcpy(signame, sudo_sys_signame[signo], SIG2STR_MAX);
+ return 0;
+ }
+ errno = EINVAL;
+ return -1;
}
/* Define to 1 if you have the `sia_ses_init' function. */
#undef HAVE_SIA_SES_INIT
+/* Define to 1 if you have the `sig2str' function. */
+#undef HAVE_SIG2STR
+
/* Define to 1 if the system has the type `sigaction_t'. */
#undef HAVE_SIGACTION_T
/* Define to 1 if you have the `strsignal' function. */
#undef HAVE_STRSIGNAL
-/* Define to 1 if you have the `strsigname' function. */
-#undef HAVE_STRSIGNAME
-
/* Define to 1 if `d_type' is a member of `struct dirent'. */
#undef HAVE_STRUCT_DIRENT_D_TYPE
done
-for ac_func in strsigname
+for ac_func in sig2str
do :
- ac_fn_c_check_func "$LINENO" "strsigname" "ac_cv_func_strsigname"
-if test "x$ac_cv_func_strsigname" = xyes; then :
+ ac_fn_c_check_func "$LINENO" "sig2str" "ac_cv_func_sig2str"
+if test "x$ac_cv_func_sig2str" = xyes; then :
cat >>confdefs.h <<_ACEOF
-#define HAVE_STRSIGNAME 1
+#define HAVE_SIG2STR 1
_ACEOF
else
case " $LIBOBJS " in
- *" strsigname.$ac_objext "* ) ;;
- *) LIBOBJS="$LIBOBJS strsigname.$ac_objext"
+ *" sig2str.$ac_objext "* ) ;;
+ *) LIBOBJS="$LIBOBJS sig2str.$ac_objext"
;;
esac
])
dnl
-dnl Check for strsigname() or sys_signame
+dnl Check for sig2str(), sys_signame or sys_sigabbrev
dnl
-AC_CHECK_FUNCS(strsigname, [], [
- AC_LIBOBJ(strsigname)
+AC_CHECK_FUNCS(sig2str, [], [
+ AC_LIBOBJ(sig2str)
HAVE_SIGNAME="false"
AC_CHECK_DECLS([sys_signame, _sys_signame, __sys_signame, sys_sigabbrev], [
HAVE_SIGNAME="true"
# endif
#endif
+/* For sig2str() */
+#ifndef SIG2STR_MAX
+# define SIG2STR_MAX 32
+#endif
+
#ifndef WCOREDUMP
# define WCOREDUMP(x) ((x) & 0x80)
#endif
#ifndef HAVE_STRSIGNAL
char *strsignal(int);
#endif
-#ifndef HAVE_STRSIGNAME
-char *strsigname(int);
+#ifndef HAVE_SIG2STR
+int sig2str(int, char *);
#endif
#endif /* _SUDO_MISSING_H */
$makefile =~ s:\@SUDOERS_OBJS\@:bsm_audit.lo linux_audit.lo ldap.lo plugin_error.lo sssd.lo:;
# XXX - fill in AUTH_OBJS from contents of the auth dir instead
$makefile =~ s:\@AUTH_OBJS\@:afs.lo aix_auth.lo bsdauth.lo dce.lo fwtk.lo getspwuid.lo kerb5.lo pam.lo passwd.lo rfc1938.lo secureware.lo securid5.lo sia.lo:;
- $makefile =~ s:\@LTLIBOBJS\@:closefrom.lo dlopen.lo fnmatch.lo getcwd.lo getgrouplist.lo getline.lo getprogname.lo glob.lo isblank.lo memrchr.lo mksiglist.lo mksigname.lo mktemp.lo nanosleep.lo pw_dup.lo siglist.lo snprintf.lo strlcat.lo strlcpy.lo strsignal.lo strsigname.lo utimes.lo globtest.o fnm_test.o:;
+ $makefile =~ s:\@LTLIBOBJS\@:closefrom.lo dlopen.lo fnmatch.lo getcwd.lo getgrouplist.lo getline.lo getprogname.lo glob.lo isblank.lo memrchr.lo mksiglist.lo mksigname.lo mktemp.lo nanosleep.lo pw_dup.lo sig2str.lo siglist.lo snprintf.lo strlcat.lo strlcpy.lo strsignal.lo utimes.lo globtest.o fnm_test.o:;
# Parse OBJS lines
my %objs;
static int
handle_signals(int sv[2], pid_t child, int log_io, struct command_status *cstat)
{
+ char signame[SIG2STR_MAX];
unsigned char signo;
ssize_t nread;
int status;
cstat->val = errno;
debug_return_int(-1);
}
- sudo_debug_printf(SUDO_DEBUG_DIAG, "received SIG%s", strsigname(signo));
+ if (sig2str(signo, signame) == -1)
+ snprintf(signame, sizeof(signame), "%d", signo);
+ sudo_debug_printf(SUDO_DEBUG_DIAG, "received SIG%s", signame);
if (signo == SIGCHLD) {
/*
* If logging I/O, child is the intermediate process,
sa.sa_handler = SIG_DFL;
sigaction(SIGTSTP, &sa, NULL);
}
- if (kill(getpid(), signo) != 0) {
- warning("kill(%d, SIG%s)", (int)getpid(),
- strsigname(signo));
- }
+ if (kill(getpid(), signo) != 0)
+ warning("kill(%d, SIG%s)", (int)getpid(), signame);
if (signo == SIGTSTP)
sigaction(SIGTSTP, &osa, NULL);
if (fd != -1) {
if (signo == SIGALRM)
terminate_command(child, false);
else if (kill(child, signo) != 0)
- warning("kill(%d, SIG%s)", (int)child, strsigname(signo));
+ warning("kill(%d, SIG%s)", (int)child, signame);
}
}
}
static void
forward_signals(int sock)
{
+ char signame[SIG2STR_MAX];
struct sigforward *sigfwd;
struct command_status cstat;
ssize_t nsent;
while (!tq_empty(&sigfwd_list)) {
sigfwd = tq_first(&sigfwd_list);
+ if (sig2str(sigfwd->signo, signame) == -1)
+ snprintf(signame, sizeof(signame), "%d", sigfwd->signo);
sudo_debug_printf(SUDO_DEBUG_INFO,
- "sending SIG%s to child over backchannel",
- strsigname(sigfwd->signo));
+ "sending SIG%s to child over backchannel", signame);
cstat.type = CMD_SIGNO;
cstat.val = sigfwd->signo;
do {
schedule_signal(int signo)
{
struct sigforward *sigfwd;
+ char signame[SIG2STR_MAX];
debug_decl(schedule_signal, SUDO_DEBUG_EXEC)
- sudo_debug_printf(SUDO_DEBUG_DIAG, "forwarding SIG%s to child",
- strsigname(signo));
+ if (sig2str(signo, signame) == -1)
+ snprintf(signame, sizeof(signame), "%d", signo);
+ sudo_debug_printf(SUDO_DEBUG_DIAG, "forwarding SIG%s to child", signame);
sigfwd = ecalloc(1, sizeof(*sigfwd));
sigfwd->prev = sigfwd;
int
suspend_parent(int signo)
{
+ char signame[SIG2STR_MAX];
sigaction_t sa, osa;
int n, oldmode = ttymode, rval = 0;
debug_decl(suspend_parent, SUDO_DEBUG_EXEC);
} while (!n && errno == EINTR);
}
+ if (sig2str(signo, signame) == -1)
+ snprintf(signame, sizeof(signame), "%d", signo);
+
/* Suspend self and continue command when we resume. */
zero_bytes(&sa, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_INTERRUPT; /* do not restart syscalls */
sa.sa_handler = SIG_DFL;
sigaction(signo, &sa, &osa);
- sudo_debug_printf(SUDO_DEBUG_INFO, "kill parent SIG%s",
- strsigname(signo));
+ sudo_debug_printf(SUDO_DEBUG_INFO, "kill parent SIG%s", signame);
if (killpg(ppgrp, signo) != 0)
- warning("killpg(%d, SIG%s)", (int)ppgrp, strsigname(signo));
+ warning("killpg(%d, SIG%s)", (int)ppgrp, signame);
/* Check foreground/background status on resume. */
check_foreground();
static void
deliver_signal(pid_t pid, int signo, bool from_parent)
{
+ char signame[SIG2STR_MAX];
int status;
debug_decl(deliver_signal, SUDO_DEBUG_EXEC);
+ if (sig2str(signo, signame) == -1)
+ snprintf(signame, sizeof(signame), "%d", signo);
+
/* Handle signal from parent. */
sudo_debug_printf(SUDO_DEBUG_INFO, "received SIG%s%s",
- strsigname(signo), from_parent ? " from parent" : "");
+ signame, from_parent ? " from parent" : "");
switch (signo) {
case SIGALRM:
terminate_command(pid, true);
} while (pid == -1 && errno == EINTR);
if (pid == cmnd_pid) {
if (cstat->type != CMD_ERRNO) {
+ char signame[SIG2STR_MAX];
+
cstat->type = CMD_WSTATUS;
cstat->val = status;
if (WIFSTOPPED(status)) {
+ if (sig2str(WSTOPSIG(status), signame) == -1)
+ snprintf(signame, sizeof(signame), "%d", WSTOPSIG(status));
sudo_debug_printf(SUDO_DEBUG_INFO,
- "command stopped, SIG%s", strsigname(WSTOPSIG(status)));
+ "command stopped, SIG%s", signame);
do {
cmnd_pgrp = tcgetpgrp(io_fds[SFD_SLAVE]);
} while (cmnd_pgrp == -1 && errno == EINTR);
if (send_status(backchannel, cstat) == -1)
return alive; /* XXX */
} else if (WIFSIGNALED(status)) {
+ if (sig2str(WTERMSIG(status), signame) == -1)
+ snprintf(signame, sizeof(signame), "%d", WTERMSIG(status));
sudo_debug_printf(SUDO_DEBUG_INFO,
- "command killed, SIG%s", strsigname(WTERMSIG(status)));
+ "command killed, SIG%s", signame);
} else {
sudo_debug_printf(SUDO_DEBUG_INFO, "command exited: %d",
WEXITSTATUS(status));