Only remove pidfile if one was written in the first place

This commit is contained in:
Thomas Bernard 2012-03-31 09:22:50 +02:00
parent 31d0dfa345
commit 70c5e194a3
2 changed files with 8 additions and 4 deletions

View File

@ -1,4 +1,7 @@
$Id: Changelog.txt,v 1.264 2012/03/19 21:14:12 nanard Exp $ $Id: Changelog.txt,v 1.265 2012/03/31 06:57:11 nanard Exp $
2012/03/31:
Only remove pidfile if one was written in the first place.
2012/03/19: 2012/03/19:
Fix ipfilter support (thanks dhowland https://github.com/dhowland) Fix ipfilter support (thanks dhowland https://github.com/dhowland)

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpd.c,v 1.147 2012/02/15 22:43:56 nanard Exp $ */ /* $Id: miniupnpd.c,v 1.149 2012/03/31 06:57:12 nanard Exp $ */
/* MiniUPnP project /* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard * (c) 2006-2012 Thomas Bernard
@ -1038,7 +1038,8 @@ init(int argc, char * * argv, struct runtime_vars * v)
return 1; return 1;
} }
writepidfile(pidfilename, pid); if(writepidfile(pidfilename, pid) < 0)
pidfilename = NULL;
#ifdef ENABLE_LEASEFILE #ifdef ENABLE_LEASEFILE
/*remove(lease_file);*/ /*remove(lease_file);*/
@ -1711,7 +1712,7 @@ shutdown:
close(snotify[i]); close(snotify[i]);
} }
if(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);
} }