From: Todd C. Miller Date: Thu, 10 Jun 2010 19:18:23 +0000 (-0400) Subject: Remove sigaction emulation X-Git-Tag: SUDO_1_8_0~490 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=047fc3876d5eacba404a2a0b401c4edbeb2ae07d;p=sudo Remove sigaction emulation Use SA_INTERRUPT in sa_flags --- diff --git a/compat/sigaction.c b/compat/sigaction.c deleted file mode 100644 index 34c128e7a..000000000 --- a/compat/sigaction.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2001-2005 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Sponsored in part by the Defense Advanced Research Projects - * Agency (DARPA) and Air Force Research Laboratory, Air Force - * Materiel Command, USAF, under agreement number F39502-99-1-0512. - */ - -#include -#include - -#include - -int -sigaction(int signo, const sigaction_t *sa, sigaction_t *osa) -{ - sigaction_t nsa; - int error; - - /* We must reverse SV_INTERRUPT since it is the opposite of SA_RESTART */ - if (sa) { - nsa = *sa; - nsa.sa_flags ^= SV_INTERRUPT; - sa = &nsa; - } - - error = sigvec(signo, sa, osa); - if (!error && osa) - osa->sa_flags ^= SV_INTERRUPT; /* flip SV_INTERRUPT as above */ - - return(error); -} - -int -sigemptyset(sigset_t *set) -{ - - *set = 0; - return(0); -} - -int -sigfillset(sigset_t *set) -{ - - *set = ~0;; - return(0); -} - -int -sigaddset(sigset_t *set, int signo) -{ - - if (signo <= 0 || signo >= NSIG) { - errno = EINVAL; - return(-1); - } - - SET(*set, sigmask(signo)); - return(0); -} - -int -sigdelset(sigset_t *set, int signo) -{ - - if (signo <= 0 || signo >= NSIG) { - errno = EINVAL; - return(-1); - } - - CLR(*set, sigmask(signo)); - return(0); -} - -int -sigismember(sigset_t *set, int signo) -{ - - return(ISSET(*set, sigmask(signo))); -} - -int -sigprocmask(int how, const sigset_t *set, sigset_t *oset) -{ - int mask; - - /* If 'set' is NULL the user just wants the current signal mask. */ - if (set == 0) - mask = sigblock(0); - else - switch (how) { - case SIG_BLOCK: - mask = sigblock(*set); - break; - case SIG_UNBLOCK: - mask = sigsetmask(~*set); - break; - case SIG_SETMASK: - mask = sigsetmask(*set); - break; - default: - return(-1); - } - - if (mask == -1) - return(-1); - if (oset) - *oset = mask; - return(0); -} diff --git a/config.h.in b/config.h.in index 26f560a5e..623cd4a2f 100644 --- a/config.h.in +++ b/config.h.in @@ -433,9 +433,6 @@ /* Define to 1 if you have the `sia_ses_init' function. */ #undef HAVE_SIA_SES_INIT -/* Define to 1 if you have the `sigaction' function. */ -#undef HAVE_SIGACTION - /* Define to 1 if has the sigaction_t typedef. */ #undef HAVE_SIGACTION_T diff --git a/configure.in b/configure.in index 8f9e379c8..1beb04955 100644 --- a/configure.in +++ b/configure.in @@ -1957,7 +1957,7 @@ AC_CHECK_FUNCS(utimes, [AC_CHECK_FUNCS(futimes futimesat, [break])], [AC_CHECK_F AC_CHECK_FUNCS(killpg, [], [AC_LIBOBJ(killpg)]) SUDO_FUNC_FNMATCH([AC_DEFINE(HAVE_FNMATCH)], [AC_LIBOBJ(fnmatch)]) SUDO_FUNC_ISBLANK -AC_REPLACE_FUNCS(memrchr strerror strcasecmp sigaction strlcpy strlcat) +AC_REPLACE_FUNCS(memrchr strerror strcasecmp strlcpy strlcat) AC_CHECK_FUNCS(nanosleep, [], [ # On Solaris, nanosleep is in librt AC_CHECK_LIB(rt, nanosleep, [REPLAY_LIBS="${REPLAY_LIBS} -lrt"], [AC_LIBOBJ(nanosleep)]) diff --git a/include/compat.h b/include/compat.h index 400484566..2ce7c3f7a 100644 --- a/include/compat.h +++ b/include/compat.h @@ -181,41 +181,17 @@ int isblank(int); #endif /* O_NOCTTY */ /* - * Emulate POSIX signals via sigvec(2) + * Add IRIX-like sigaction_t for those without it. + * SA_RESTART is not required by POSIX; SunOS has SA_INTERRUPT instead. */ -#ifndef HAVE_SIGACTION -# define SA_ONSTACK SV_ONSTACK -# define SA_RESTART SV_INTERRUPT /* opposite effect */ -# define SA_RESETHAND SV_RESETHAND -# define SA_NOCLDSTOP SV_NOCLDSTOP -# define sa_handler sv_handler -# define sa_mask sv_mask -# define sa_flags sv_flags -typedef struct sigvec sigaction_t; -typedef int sigset_t; -int sigaction(int sig, const sigaction_t *act, sigaction_t *oact); -int sigemptyset(sigset_t *); -int sigfillset(sigset_t *); -int sigaddset(sigset_t *, int); -int sigdelset(sigset_t *, int); -int sigismember(sigset_t *, int); -int sigprocmask(int, const sigset_t *, sigset_t *); -#endif - -/* - * Extra sugar for POSIX signals to deal with the above emulation - * as well as the fact that SunOS has a SA_INTERRUPT flag. - */ -#ifdef HAVE_SIGACTION -# ifndef HAVE_SIGACTION_T +#ifndef HAVE_SIGACTION_T typedef struct sigaction sigaction_t; -# endif -# ifndef SA_INTERRUPT -# define SA_INTERRUPT 0 -# endif -# ifndef SA_RESTART -# define SA_RESTART 0 -# endif +#endif +#ifndef SA_INTERRUPT +# define SA_INTERRUPT 0 +#endif +#ifndef SA_RESTART +# define SA_RESTART 0 #endif /* diff --git a/plugins/sudoers/logging.c b/plugins/sudoers/logging.c index 98756e00f..bf9077e62 100644 --- a/plugins/sudoers/logging.c +++ b/plugins/sudoers/logging.c @@ -478,7 +478,7 @@ send_mail(const char *fmt, ...) /* Ignore SIGPIPE in case mailer exits prematurely (or is missing). */ zero_bytes(&sa, sizeof(sa)); sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; + sa.sa_flags = SA_INTERRUPT; sa.sa_handler = SIG_IGN; (void) sigaction(SIGPIPE, &sa, NULL); diff --git a/plugins/sudoers/mon_systrace.c b/plugins/sudoers/mon_systrace.c index 83eb0e4f5..5bae00a98 100644 --- a/plugins/sudoers/mon_systrace.c +++ b/plugins/sudoers/mon_systrace.c @@ -113,7 +113,7 @@ systrace_attach(pid) error(1, "sigprocmask"); zero_bytes(&sa, sizeof(sa)); sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; + sa.sa_flags = SA_INTERRUPT; sa.sa_handler = catchsig; if (sigaction(SIGUSR1, &sa, &osa) != 0) error(1, "sigaction"); @@ -151,7 +151,7 @@ systrace_attach(pid) dodetach = 0; zero_bytes(&sa, sizeof(sa)); sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; + sa.sa_flags = SA_INTERRUPT; sa.sa_handler = catchsig; if (sigaction(SIGUSR1, &osa, NULL) != 0 || sigaction(SIGHUP, &sa, NULL) != 0 || diff --git a/src/exec.c b/src/exec.c index 25af3440b..ccc7fb482 100644 --- a/src/exec.c +++ b/src/exec.c @@ -176,7 +176,7 @@ sudo_execve(struct command_details *details, char *argv[], char *envp[], sigemptyset(&sa.sa_mask); /* Note: HP-UX select() will not be interrupted if SA_RESTART set */ - sa.sa_flags = 0; /* do not restart syscalls */ + sa.sa_flags = SA_INTERRUPT; /* do not restart syscalls */ sa.sa_handler = handler; sigaction(SIGALRM, &sa, NULL); sigaction(SIGCHLD, &sa, NULL); diff --git a/src/exec_pty.c b/src/exec_pty.c index a1e72478b..9e960f55d 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -532,7 +532,7 @@ fork_pty(struct command_details *details, char *argv[], char *envp[], } /* Job control signals to relay from parent to child. */ - sa.sa_flags = 0; /* do not restart syscalls */ + sa.sa_flags = SA_INTERRUPT; /* do not restart syscalls */ sa.sa_handler = handler; sigaction(SIGTSTP, &sa, NULL); #if 0 /* XXX - add these? */ @@ -823,7 +823,7 @@ exec_monitor(struct command_details *details, char *argv[], char *envp[], sigaction(SIGTTOU, &sa, NULL); /* Note: HP-UX select() will not be interrupted if SA_RESTART set */ - sa.sa_flags = 0; + sa.sa_flags = SA_INTERRUPT; sa.sa_handler = handler; sigaction(SIGCHLD, &sa, NULL); diff --git a/src/tgetpass.c b/src/tgetpass.c index 7c690de2f..8fd965da7 100644 --- a/src/tgetpass.c +++ b/src/tgetpass.c @@ -241,7 +241,7 @@ sudo_askpass(const char *askpass, const char *prompt) /* Ignore SIGPIPE in case child exits prematurely */ zero_bytes(&sa, sizeof(sa)); sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; + sa.sa_flags = SA_INTERRUPT; sa.sa_handler = SIG_IGN; (void) sigaction(SIGPIPE, &sa, &saved_sa_pipe);