* Improve how we clean up after ourselves during exit.

This commit is contained in:
Justin Maggard 2012-11-16 07:40:40 +00:00
parent 035fd35ffd
commit aee83a3ee6
4 changed files with 34 additions and 38 deletions

7
log.c
View File

@ -56,6 +56,13 @@ char *level_name[] = {
0 0
}; };
void
log_close(void)
{
if (log_fp)
fclose(log_fp);
}
int int
log_init(const char *fname, const char *debug) log_init(const char *fname, const char *debug)
{ {

1
log.h
View File

@ -45,6 +45,7 @@ enum _log_facility
extern int log_level[L_MAX]; extern int log_level[L_MAX];
extern int log_init(const char *fname, const char *debug); extern int log_init(const char *fname, const char *debug);
extern void log_close(void);
extern void log_err(int level, enum _log_facility facility, char *fname, int lineno, char *fmt, ...); extern void log_err(int level, enum _log_facility facility, char *fname, int lineno, char *fmt, ...);
#define DPRINTF(level, facility, fmt, arg...) do { log_err(level, facility, __FILE__, __LINE__, fmt, ##arg); } while (0) #define DPRINTF(level, facility, fmt, arg...) do { log_err(level, facility, __FILE__, __LINE__, fmt, ##arg); } while (0)

View File

@ -3,7 +3,7 @@
* http://sourceforge.net/projects/minidlna/ * http://sourceforge.net/projects/minidlna/
* *
* MiniDLNA media server * MiniDLNA media server
* Copyright (C) 2008-2009 Justin Maggard * Copyright (C) 2008-2012 Justin Maggard
* *
* This file is part of MiniDLNA. * This file is part of MiniDLNA.
* *
@ -384,26 +384,11 @@ check_db(sqlite3 *db, int new_db, pid_t *scanner_pid)
sqlite3_close(db); sqlite3_close(db);
*scanner_pid = fork(); *scanner_pid = fork();
open_db(&db); open_db(&db);
if( !(*scanner_pid) ) // child (scanner) process if (!(*scanner_pid)) /* child (scanner) process */
{ {
start_scanner(); start_scanner();
sqlite3_close(db); sqlite3_close(db);
media_path = media_dirs; log_close();
art_names = album_art_names;
while( media_path )
{
free(media_path->path);
last_path = media_path;
media_path = media_path->next;
free(last_path);
}
while( art_names )
{
free(art_names->name);
last_name = art_names;
art_names = art_names->next;
free(last_name);
}
freeoptions(); freeoptions();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
@ -1076,8 +1061,6 @@ main(int argc, char * * argv)
int last_changecnt = 0; int last_changecnt = 0;
pid_t scanner_pid = 0; pid_t scanner_pid = 0;
pthread_t inotify_thread = 0; pthread_t inotify_thread = 0;
struct media_dir_s *media_path, *last_path;
struct album_art_name_s *art_names, *last_name;
#ifdef TIVO_SUPPORT #ifdef TIVO_SUPPORT
uint8_t beacon_interval = 5; uint8_t beacon_interval = 5;
int sbeacon = -1; int sbeacon = -1;
@ -1417,26 +1400,10 @@ shutdown:
upnpevents_removeSubscribers(); upnpevents_removeSubscribers();
media_path = media_dirs; if (pidfilename && unlink(pidfilename) < 0)
art_names = album_art_names;
while( media_path )
{
free(media_path->path);
last_path = media_path;
media_path = media_path->next;
free(last_path);
}
while( art_names )
{
free(art_names->name);
last_name = art_names;
art_names = art_names->next;
free(last_name);
}
if(pidfilename && unlink(pidfilename) < 0)
DPRINTF(E_ERROR, L_GENERAL, "Failed to remove pidfile %s: %s\n", pidfilename, strerror(errno)); DPRINTF(E_ERROR, L_GENERAL, "Failed to remove pidfile %s: %s\n", pidfilename, strerror(errno));
log_close();
freeoptions(); freeoptions();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);

View File

@ -183,6 +183,27 @@ readoptionsfile(const char * fname)
void void
freeoptions(void) freeoptions(void)
{ {
struct media_dir_s *media_path, *last_path;
struct album_art_name_s *art_names, *last_name;
media_path = media_dirs;
while (media_path)
{
free(media_path->path);
last_path = media_path;
media_path = media_path->next;
free(last_path);
}
art_names = album_art_names;
while (art_names)
{
free(art_names->name);
last_name = art_names;
art_names = art_names->next;
free(last_name);
}
if(ary_options) if(ary_options)
{ {
free(ary_options); free(ary_options);