rpcbind: Do not use signal-unsafe functions in SIGTERM handler
syslog(3), routines used in write_warmstart(), and exit(3) are all signal-unsafe. Instead, set a signal-safe flag and check the flag in the rpcbind main loop to shutdown safely. PR: 224503 Reviewed by: kib, markj Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D13728
This commit is contained in:
parent
9fbe631a1a
commit
055569f608
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=327482
@ -1136,6 +1136,16 @@ my_svc_run(void)
|
|||||||
* that it was set by the signal handlers (or any
|
* that it was set by the signal handlers (or any
|
||||||
* other outside event) and not caused by poll().
|
* other outside event) and not caused by poll().
|
||||||
*/
|
*/
|
||||||
|
if (doterminate != 0) {
|
||||||
|
close(rpcbindlockfd);
|
||||||
|
#ifdef WARMSTART
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"rpcbind terminating on signal %d. Restart with \"rpcbind -w\"",
|
||||||
|
(int)doterminate);
|
||||||
|
write_warmstart(); /* Dump yourself */
|
||||||
|
#endif
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
case 0:
|
case 0:
|
||||||
cleanfds = svc_fdset;
|
cleanfds = svc_fdset;
|
||||||
__svc_clean_idle(&cleanfds, 30, FALSE);
|
__svc_clean_idle(&cleanfds, 30, FALSE);
|
||||||
|
@ -79,7 +79,9 @@ static char sccsid[] = "@(#)rpcbind.c 1.35 89/04/21 Copyr 1984 Sun Micro";
|
|||||||
/* Global variables */
|
/* Global variables */
|
||||||
int debugging = 0; /* Tell me what's going on */
|
int debugging = 0; /* Tell me what's going on */
|
||||||
int doabort = 0; /* When debugging, do an abort on errors */
|
int doabort = 0; /* When debugging, do an abort on errors */
|
||||||
|
volatile sig_atomic_t doterminate = 0; /* Terminal signal received */
|
||||||
rpcblist_ptr list_rbl; /* A list of version 3/4 rpcbind services */
|
rpcblist_ptr list_rbl; /* A list of version 3/4 rpcbind services */
|
||||||
|
int rpcbindlockfd;
|
||||||
|
|
||||||
/* who to suid to if -s is given */
|
/* who to suid to if -s is given */
|
||||||
#define RUN_AS "daemon"
|
#define RUN_AS "daemon"
|
||||||
@ -99,7 +101,6 @@ static struct sockaddr **bound_sa;
|
|||||||
static int ipv6_only = 0;
|
static int ipv6_only = 0;
|
||||||
static int nhosts = 0;
|
static int nhosts = 0;
|
||||||
static int on = 1;
|
static int on = 1;
|
||||||
static int rpcbindlockfd;
|
|
||||||
|
|
||||||
#ifdef WARMSTART
|
#ifdef WARMSTART
|
||||||
/* Local Variable */
|
/* Local Variable */
|
||||||
@ -758,16 +759,10 @@ rbllist_add(rpcprog_t prog, rpcvers_t vers, struct netconfig *nconf,
|
|||||||
* Catch the signal and die
|
* Catch the signal and die
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
terminate(int signum __unused)
|
terminate(int signum)
|
||||||
{
|
{
|
||||||
close(rpcbindlockfd);
|
|
||||||
#ifdef WARMSTART
|
doterminate = signum;
|
||||||
syslog(LOG_ERR,
|
|
||||||
"rpcbind terminating on signal %d. Restart with \"rpcbind -w\"",
|
|
||||||
signum);
|
|
||||||
write_warmstart(); /* Dump yourself */
|
|
||||||
#endif
|
|
||||||
exit(2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -44,6 +44,8 @@
|
|||||||
#ifndef rpcbind_h
|
#ifndef rpcbind_h
|
||||||
#define rpcbind_h
|
#define rpcbind_h
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#ifdef PORTMAP
|
#ifdef PORTMAP
|
||||||
#include <rpc/pmap_prot.h>
|
#include <rpc/pmap_prot.h>
|
||||||
#endif
|
#endif
|
||||||
@ -68,6 +70,7 @@ struct r_rmtcall_args {
|
|||||||
|
|
||||||
extern int debugging;
|
extern int debugging;
|
||||||
extern int doabort;
|
extern int doabort;
|
||||||
|
extern volatile sig_atomic_t doterminate;
|
||||||
#ifdef LIBWRAP
|
#ifdef LIBWRAP
|
||||||
extern int libwrap;
|
extern int libwrap;
|
||||||
#endif
|
#endif
|
||||||
@ -75,6 +78,7 @@ extern int verboselog;
|
|||||||
extern int insecure;
|
extern int insecure;
|
||||||
extern int oldstyle_local;
|
extern int oldstyle_local;
|
||||||
extern rpcblist_ptr list_rbl; /* A list of version 3 & 4 rpcbind services */
|
extern rpcblist_ptr list_rbl; /* A list of version 3 & 4 rpcbind services */
|
||||||
|
extern int rpcbindlockfd;
|
||||||
|
|
||||||
#ifdef PORTMAP
|
#ifdef PORTMAP
|
||||||
extern struct pmaplist *list_pml; /* A list of version 2 rpcbind services */
|
extern struct pmaplist *list_pml; /* A list of version 2 rpcbind services */
|
||||||
|
Loading…
Reference in New Issue
Block a user