From 1aa540c4b507f0a67d5e0fcd9dc6bbedfa334f3e Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Tue, 10 Jan 2012 02:50:33 +0000 Subject: [PATCH] * Rework how we do some very early-stage logging, and clean up a few warnings. --- minidlna.c | 81 +++++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/minidlna.c b/minidlna.c index 58ee34c..db757d3 100644 --- a/minidlna.c +++ b/minidlna.c @@ -351,7 +351,7 @@ init(int argc, char * * argv) char * string, * word; enum media_types type; char * path; - char real_path[PATH_MAX]; + char buf[PATH_MAX]; char ip_addr[INET_ADDRSTRLEN + 3] = {'\0'}; char log_str[72] = "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn"; @@ -387,7 +387,7 @@ init(int argc, char * * argv) { /* only error if file exists or using -f */ if(access(optionsfile, F_OK) == 0 || options_flag) - fprintf(stderr, "Error reading configuration file %s\n", optionsfile); + DPRINTF(E_ERROR, L_GENERAL, "Error reading configuration file %s\n", optionsfile); } else { @@ -406,12 +406,10 @@ init(int argc, char * * argv) if(n_lan_addr < MAX_LAN_ADDR) n_lan_addr++; } - else - fprintf(stderr, "Interface %s not found, ignoring.\n", word); } else { - fprintf(stderr, "Too many listening ips (max: %d), ignoring %s\n", + DPRINTF(E_ERROR, L_GENERAL, "Too many listening ips (max: %d), ignoring %s\n", MAX_LAN_ADDR, word); } } @@ -425,7 +423,7 @@ init(int argc, char * * argv) } else { - fprintf(stderr, "Too many listening ips (max: %d), ignoring %s\n", + DPRINTF(E_ERROR, L_GENERAL, "Too many listening ips (max: %d), ignoring %s\n", MAX_LAN_ADDR, ary_options[i].value); } break; @@ -473,13 +471,13 @@ init(int argc, char * * argv) type = IMAGES_ONLY; myval = index(ary_options[i].value, '/'); case '/': - path = realpath(myval ? myval:ary_options[i].value, real_path); + path = realpath(myval ? myval:ary_options[i].value, buf); if( !path ) path = (myval ? myval:ary_options[i].value); if( access(path, F_OK) != 0 ) { - fprintf(stderr, "Media directory not accessible! [%s]\n", - path); + DPRINTF(E_ERROR, L_GENERAL, "Media directory \"%s\" not accessible! [%s]\n", + path, strerror(errno)); break; } struct media_dir_s * this_dir = calloc(1, sizeof(struct media_dir_s)); @@ -498,7 +496,7 @@ init(int argc, char * * argv) } break; default: - fprintf(stderr, "Media directory entry not understood! [%s]\n", + DPRINTF(E_ERROR, L_GENERAL, "Media directory entry not understood! [%s]\n", ary_options[i].value); break; } @@ -528,7 +526,7 @@ init(int argc, char * * argv) } break; case UPNPDBDIR: - path = realpath(ary_options[i].value, real_path); + path = realpath(ary_options[i].value, buf); if( !path ) path = (ary_options[i].value); make_dir(path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO); @@ -540,7 +538,7 @@ init(int argc, char * * argv) strncpy(db_path, path, PATH_MAX); break; case UPNPLOGDIR: - path = realpath(ary_options[i].value, real_path); + path = realpath(ary_options[i].value, buf); if( !path ) path = (ary_options[i].value); make_dir(path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO); @@ -586,7 +584,7 @@ init(int argc, char * * argv) runtime_vars.root_container = IMAGE_ID; break; default: - fprintf(stderr, "Invalid root container! [%s]\n", + DPRINTF(E_ERROR, L_GENERAL, "Invalid root container! [%s]\n", ary_options[i].value); break; } @@ -595,7 +593,7 @@ init(int argc, char * * argv) minissdpdsocketpath = ary_options[i].value; break; default: - fprintf(stderr, "Unknown option in file %s\n", + DPRINTF(E_ERROR, L_GENERAL, "Unknown option in file %s\n", optionsfile); } } @@ -615,7 +613,7 @@ init(int argc, char * * argv) { if(argv[i][0]!='-') { - fprintf(stderr, "Unknown option: %s\n", argv[i]); + DPRINTF(E_ERROR, L_GENERAL, "Unknown option: %s\n", argv[i]); } else if(strcmp(argv[i], "--help")==0) { @@ -628,20 +626,20 @@ init(int argc, char * * argv) if(i+1 < argc) runtime_vars.notify_interval = atoi(argv[++i]); else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + DPRINTF(E_ERROR, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); break; case 's': if(i+1 < argc) strncpy(serialnumber, argv[++i], SERIALNUMBER_MAX_LEN); else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + DPRINTF(E_ERROR, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); serialnumber[SERIALNUMBER_MAX_LEN-1] = '\0'; break; case 'm': if(i+1 < argc) strncpy(modelnumber, argv[++i], MODELNUMBER_MAX_LEN); else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + DPRINTF(E_ERROR, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); modelnumber[MODELNUMBER_MAX_LEN-1] = '\0'; break; /*case 'l': @@ -651,13 +649,13 @@ init(int argc, char * * argv) if(i+1 < argc) runtime_vars.port = atoi(argv[++i]); else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + DPRINTF(E_ERROR, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); break; case 'P': if(i+1 < argc) pidfilename = argv[++i]; else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + DPRINTF(E_ERROR, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); break; case 'd': debug_flag = 1; @@ -671,7 +669,7 @@ init(int argc, char * * argv) if(i+1 < argc) presurl = argv[++i]; else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + DPRINTF(E_ERROR, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); break; case 'a': if(i+1 < argc) @@ -695,12 +693,12 @@ init(int argc, char * * argv) } else { - fprintf(stderr, "Too many listening ips (max: %d), ignoring %s\n", + DPRINTF(E_ERROR, L_GENERAL, "Too many listening ips (max: %d), ignoring %s\n", MAX_LAN_ADDR, argv[i]); } } else - fprintf(stderr, "Option -%c takes one argument.\n", argv[i][1]); + DPRINTF(E_ERROR, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); break; case 'i': if(i+1 < argc) @@ -710,9 +708,8 @@ init(int argc, char * * argv) i++; if( getifaddr(argv[i], ip_addr, sizeof(ip_addr)) < 0 ) { - fprintf(stderr, "Network interface '%s' not found.\n", + DPRINTF(E_FATAL, L_GENERAL, "Required network interface '%s' not found.\n", argv[i]); - exit(-1); } for(j=0; j 0 ) + i = system(cmd); + else + cmd = NULL; + if( i != 0 ) + { + DPRINTF(E_WARN, L_GENERAL, "Failed to clean old file cache.\n"); + } free(cmd); open_db(); if( CreateDatabase() != 0 ) @@ -971,6 +977,7 @@ main(int argc, char * * argv) start_scanner(); #endif } + signal(SIGCHLD, SIG_IGN); #ifdef HAVE_INOTIFY if( sqlite3_threadsafe() && sqlite3_libversion_number() >= 3005001 && GETFLAG(INOTIFY_MASK) && pthread_create(&inotify_thread, NULL, start_inotify, NULL) )