From ef7f537bee6a79d847da62e4574728ae4df7f107 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Thu, 23 Feb 2012 05:55:50 +0000 Subject: [PATCH] * Only remove the pidfile if one was written in the first place. (Thanks Andrea Biardi) --- minidlna.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/minidlna.c b/minidlna.c index f35519d..c884f05 100644 --- a/minidlna.c +++ b/minidlna.c @@ -807,7 +807,7 @@ init(int argc, char * * argv) #endif } - if(checkforrunning(pidfilename) < 0) + if (checkforrunning(pidfilename) < 0) { DPRINTF(E_ERROR, L_GENERAL, "MiniDLNA is already running. EXITING.\n"); return 1; @@ -816,7 +816,7 @@ init(int argc, char * * argv) set_startup_time(); /* presentation url */ - if(presurl) + if (presurl) strncpyt(presentationurl, presurl, PRESENTATIONURL_MAX_LEN); else strcpy(presentationurl, "/"); @@ -825,19 +825,14 @@ init(int argc, char * * argv) memset(&sa, 0, sizeof(struct sigaction)); sa.sa_handler = sigterm; if (sigaction(SIGTERM, &sa, NULL)) - { - DPRINTF(E_FATAL, L_GENERAL, "Failed to set SIGTERM handler. EXITING.\n"); - } + DPRINTF(E_FATAL, L_GENERAL, "Failed to set %s handler. EXITING.\n", SIGTERM); if (sigaction(SIGINT, &sa, NULL)) - { - DPRINTF(E_FATAL, L_GENERAL, "Failed to set SIGINT handler. EXITING.\n"); - } + DPRINTF(E_FATAL, L_GENERAL, "Failed to set %s handler. EXITING.\n", SIGINT); + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) + DPRINTF(E_FATAL, L_GENERAL, "Failed to set %s handler. EXITING.\n", SIGPIPE); - if(signal(SIGPIPE, SIG_IGN) == SIG_ERR) { - DPRINTF(E_FATAL, L_GENERAL, "Failed to ignore SIGPIPE signals. EXITING.\n"); - } - - writepidfile(pidfilename, pid); + if (writepidfile(pidfilename, pid) != 0) + pidfilename = NULL; return 0; } @@ -1232,9 +1227,8 @@ main(int argc, char * * argv) shutdown: /* kill the scanner */ if( scanning && scanner_pid ) - { kill(scanner_pid, 9); - } + /* close out open sockets */ while(upnphttphead.lh_first != NULL) { @@ -1242,17 +1236,18 @@ shutdown: LIST_REMOVE(e, entries); Delete_upnphttp(e); } - - if (sudp >= 0) close(sudp); - if (shttpl >= 0) close(shttpl); + if (sudp >= 0) + close(sudp); + if (shttpl >= 0) + close(shttpl); #ifdef TIVO_SUPPORT - if (sbeacon >= 0) close(sbeacon); + if (sbeacon >= 0) + close(sbeacon); #endif if(SendSSDPGoodbye(snotify, n_lan_addr) < 0) - { DPRINTF(E_ERROR, L_GENERAL, "Failed to broadcast good-bye notifications\n"); - } + for(i=0; i