Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/azatoth/minidlna.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Maggard <jmaggard@users.sourceforce.net>2012-02-23 09:55:50 +0400
committerJustin Maggard <jmaggard@users.sourceforce.net>2012-02-23 09:55:50 +0400
commitdb4998d6fbc7313e1a7a11553e85261c8d7aacfa (patch)
treefbbcfa55cddafdf16b8851d9d503e98ffd65f94a
parent9f8f6821d89e90d32aaf292f2dffcfe48e999899 (diff)
* Only remove the pidfile if one was written in the first place. (Thanks Andrea Biardi)
-rw-r--r--minidlna.c41
1 files 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<n_lan_addr; i++)
close(snotify[i]);
@@ -1281,10 +1276,8 @@ shutdown:
free(last_name);
}
- if(unlink(pidfilename) < 0)
- {
+ if(pidfilename && unlink(pidfilename) < 0)
DPRINTF(E_ERROR, L_GENERAL, "Failed to remove pidfile %s: %s\n", pidfilename, strerror(errno));
- }
freeoptions();