configure --disable-fork to disable going to background

fixes #468
This commit is contained in:
Thomas Bernard 2020-06-03 23:43:58 +02:00
parent eaf23f0d10
commit 8a665a1c8e
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
3 changed files with 37 additions and 4 deletions

View File

@ -1,5 +1,8 @@
$Id: Changelog.txt,v 1.464 2020/05/10 17:57:56 nanard Exp $ $Id: Changelog.txt,v 1.464 2020/05/10 17:57:56 nanard Exp $
2020/06/03:
configure --disable-fork to disable going to background
2020/05/07: 2020/05/07:
Linux: use libcap or libcap-ng to drop unnecessary capabilities Linux: use libcap or libcap-ng to drop unnecessary capabilities

11
miniupnpd/configure vendored
View File

@ -16,7 +16,7 @@ UPNP_VERSION_MINOR=1
# input environment variables : # input environment variables :
# IPV6, IGD2, STRICT, DEBUG, LEASFILE, VENDORCFG, PCP_PEER, # IPV6, IGD2, STRICT, DEBUG, LEASFILE, VENDORCFG, PCP_PEER,
# PORTINUSE, DISABLEPPPCONN, FW, IPTABLESPATH, TARGET_OPENWRT, # PORTINUSE, DISABLEPPPCONN, FW, IPTABLESPATH, TARGET_OPENWRT,
# PKG_CONFIG # PKG_CONFIG, NO_BACKGROUND_NO_PIDFILE
for argv; do for argv; do
case "$argv" in case "$argv" in
@ -38,6 +38,7 @@ case "$argv" in
exit 1 exit 1
fi ;; fi ;;
--disable-pppconn) DISABLEPPPCONN=1 ;; --disable-pppconn) DISABLEPPPCONN=1 ;;
--disable-fork) NO_BACKGROUND_NO_PIDFILE=1 ;;
--firewall=*) --firewall=*)
FW=$(echo $argv | cut -d= -f2) ;; FW=$(echo $argv | cut -d= -f2) ;;
--iptablespath=*) --iptablespath=*)
@ -56,6 +57,7 @@ case "$argv" in
echo " --disable-pppconn disable WANPPPConnection" echo " --disable-pppconn disable WANPPPConnection"
echo " --firewall=<name> force the firewall type (nftables, iptables, pf, ipf, ipfw)" echo " --firewall=<name> force the firewall type (nftables, iptables, pf, ipf, ipfw)"
echo " --iptablespath=/path/to/iptables use a specific version of iptables" echo " --iptablespath=/path/to/iptables use a specific version of iptables"
echo " --disable-fork Do not go to background and do not write pid file"
exit 1 exit 1
;; ;;
*) *)
@ -827,6 +829,13 @@ cat >> ${CONFIGFILE} <<EOF
EOF EOF
echo "/* disable forking to the background and writing the pid file */" >> ${CONFIGFILE}
if [ -n "$NO_BACKGROUND_NO_PIDFILE" ] && [ $NO_BACKGROUND_NO_PIDFILE -eq 1 ] ; then
echo "#define NO_BACKGROUND_NO_PIDFILE" >> ${CONFIGFILE}
else
echo "/*#define NO_BACKGROUND_NO_PIDFILE*/" >> ${CONFIGFILE}
fi
echo "#endif /* ${CONFIGMACRO} */" >> ${CONFIGFILE} echo "#endif /* ${CONFIGMACRO} */" >> ${CONFIGFILE}
${MV} ${CONFIGFILE} ${CONFIGFILE_FINAL} ${MV} ${CONFIGFILE} ${CONFIGFILE_FINAL}

View File

@ -1,7 +1,7 @@
/* $Id: miniupnpd.c,v 1.243 2020/04/12 17:43:13 nanard Exp $ */ /* $Id: miniupnpd.c,v 1.243 2020/04/12 17:43:13 nanard Exp $ */
/* vim: tabstop=4 shiftwidth=4 noexpandtab /* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project * MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* (c) 2006-2020 Thomas Bernard * (c) 2006-2020 Thomas Bernard
* This software is subject to the conditions detailed * This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */ * in the LICENCE file provided within the distribution */
@ -1149,7 +1149,9 @@ static int
init(int argc, char * * argv, struct runtime_vars * v) init(int argc, char * * argv, struct runtime_vars * v)
{ {
int i; int i;
#ifndef NO_BACKGROUND_NO_PIDFILE
int pid; int pid;
#endif
int debug_flag = 0; int debug_flag = 0;
int openlog_option; int openlog_option;
struct in_addr addr; struct in_addr addr;
@ -1621,12 +1623,14 @@ init(int argc, char * * argv, struct runtime_vars * v)
} }
break; break;
#endif /* ENABLE_NFQUEUE */ #endif /* ENABLE_NFQUEUE */
#ifndef NO_BACKGROUND_NO_PIDFILE
case 'P': case 'P':
if(i+1 < argc) if(i+1 < argc)
pidfilename = argv[++i]; pidfilename = argv[++i];
else else
fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]);
break; break;
#endif
case 'd': case 'd':
debug_flag = 1; debug_flag = 1;
break; break;
@ -1769,6 +1773,7 @@ init(int argc, char * * argv, struct runtime_vars * v)
} }
} }
#ifndef NO_BACKGROUND_NO_PIDFILE
if(debug_flag) if(debug_flag)
{ {
pid = getpid(); pid = getpid();
@ -1784,6 +1789,7 @@ init(int argc, char * * argv, struct runtime_vars * v)
pid = daemonize(); pid = daemonize();
#endif #endif
} }
#endif
openlog_option = LOG_PID|LOG_CONS; openlog_option = LOG_PID|LOG_CONS;
if(debug_flag) if(debug_flag)
@ -1799,11 +1805,13 @@ init(int argc, char * * argv, struct runtime_vars * v)
setlogmask(LOG_UPTO(LOG_NOTICE)); setlogmask(LOG_UPTO(LOG_NOTICE));
} }
#ifndef NO_BACKGROUND_NO_PIDFILE
if(checkforrunning(pidfilename) < 0) if(checkforrunning(pidfilename) < 0)
{ {
syslog(LOG_ERR, "MiniUPnPd is already running. EXITING"); syslog(LOG_ERR, "MiniUPnPd is already running. EXITING");
return 1; return 1;
} }
#endif
#ifdef TOMATO #ifdef TOMATO
syslog(LOG_NOTICE, "version " MINIUPNPD_VERSION " started"); syslog(LOG_NOTICE, "version " MINIUPNPD_VERSION " started");
@ -1880,8 +1888,10 @@ init(int argc, char * * argv, struct runtime_vars * v)
#endif #endif
#endif #endif
#ifndef NO_BACKGROUND_NO_PIDFILE
if(writepidfile(pidfilename, pid) < 0) if(writepidfile(pidfilename, pid) < 0)
pidfilename = NULL; pidfilename = NULL;
#endif
#ifdef ENABLE_LEASEFILE #ifdef ENABLE_LEASEFILE
/*remove(lease_file);*/ /*remove(lease_file);*/
@ -1925,7 +1935,10 @@ print_usage:
"\n" "\n"
/*"[-l logfile] " not functionnal */ /*"[-l logfile] " not functionnal */
"\t\t[-u uuid] [-s serial] [-m model_number] \n" "\t\t[-u uuid] [-s serial] [-m model_number] \n"
"\t\t[-t notify_interval] [-P pid_filename] " "\t\t[-t notify_interval] "
#ifndef NO_BACKGROUND_NO_PIDFILE
"[-P pid_filename] "
#endif
#ifdef ENABLE_MANUFACTURER_INFO_CONFIGURATION #ifdef ENABLE_MANUFACTURER_INFO_CONFIGURATION
"[-z fiendly_name]" "[-z fiendly_name]"
#endif #endif
@ -1943,7 +1956,9 @@ print_usage:
"\n" "\n"
"\nNotes:\n\tThere can be one or several listening_ips.\n" "\nNotes:\n\tThere can be one or several listening_ips.\n"
"\tNotify interval is in seconds. Default is 30 seconds.\n" "\tNotify interval is in seconds. Default is 30 seconds.\n"
#ifndef NO_BACKGROUND_NO_PIDFILE
"\tDefault pid file is '%s'.\n" "\tDefault pid file is '%s'.\n"
#endif
"\tDefault config file is '%s'.\n" "\tDefault config file is '%s'.\n"
"\tWith -d miniupnpd will run as a standard program.\n" "\tWith -d miniupnpd will run as a standard program.\n"
"\t-o argument is either an IPv4 address or \"STUN:host[:port]\".\n" "\t-o argument is either an IPv4 address or \"STUN:host[:port]\".\n"
@ -1979,7 +1994,11 @@ print_usage:
"\t-1 force reporting IGDv1 in rootDesc *use with care*\n" "\t-1 force reporting IGDv1 in rootDesc *use with care*\n"
#endif #endif
"\t-h prints this help and quits.\n" "\t-h prints this help and quits.\n"
"", argv[0], argv[0], pidfilename, DEFAULT_CONFIG); "", argv[0], argv[0],
#ifndef NO_BACKGROUND_NO_PIDFILE
pidfilename,
#endif
DEFAULT_CONFIG);
return 1; return 1;
} }
@ -3033,10 +3052,12 @@ shutdown:
} }
/* remove pidfile */ /* remove pidfile */
#ifndef NO_BACKGROUND_NO_PIDFILE
if(pidfilename && (unlink(pidfilename) < 0)) if(pidfilename && (unlink(pidfilename) < 0))
{ {
syslog(LOG_ERR, "Failed to remove pidfile %s: %m", pidfilename); syslog(LOG_ERR, "Failed to remove pidfile %s: %m", pidfilename);
} }
#endif
/* delete lists */ /* delete lists */
while(lan_addrs.lh_first != NULL) while(lan_addrs.lh_first != NULL)