* Rework how we do some very early-stage logging, and clean up a few warnings.

This commit is contained in:
Justin Maggard 2012-01-10 02:50:33 +00:00
parent 6eb9cc7054
commit 1aa540c4b5

View File

@ -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<n_lan_addr; j++)
{
@ -730,12 +727,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 'f':
i++; /* discarding, the config file is already read */
@ -744,15 +741,16 @@ init(int argc, char * * argv)
runtime_vars.port = 0; // triggers help display
break;
case 'R':
snprintf(real_path, sizeof(real_path), "rm -rf %s/files.db %s/art_cache", db_path, db_path);
system(real_path);
snprintf(buf, sizeof(buf), "rm -rf %s/files.db %s/art_cache", db_path, db_path);
if( system(buf) != 0 )
DPRINTF(E_WARN, L_GENERAL, "Failed to clean old file cache.\n");
break;
case 'V':
printf("Version " MINIDLNA_VERSION "\n");
exit(0);
break;
default:
fprintf(stderr, "Unknown option: %s\n", argv[i]);
DPRINTF(E_ERROR, L_GENERAL, "Unknown option: %s\n", argv[i]);
}
}
/* If no IP was specified, try to detect one */
@ -772,7 +770,7 @@ init(int argc, char * * argv)
if( (n_lan_addr==0) || (runtime_vars.port<=0) )
{
fprintf(stderr, "Usage:\n\t"
DPRINTF(E_ERROR, L_GENERAL, "Usage:\n\t"
"%s [-d] [-v] [-f config_file]\n"
"\t\t[-a listening_ip] [-p port]\n"
/*"[-l logfile] " not functionnal */
@ -806,8 +804,8 @@ init(int argc, char * * argv)
#else
if( access(db_path, F_OK) != 0 )
make_dir(db_path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
sprintf(real_path, "%s/minidlna.log", log_path);
log_init(real_path, log_str);
sprintf(buf, "%s/minidlna.log", log_path);
log_init(buf, log_str);
#endif
}
@ -837,7 +835,6 @@ init(int argc, char * * argv)
}
/* set signal handler */
signal(SIGCHLD, SIG_IGN);
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = sigterm;
if (sigaction(SIGTERM, &sa, NULL))
@ -886,6 +883,8 @@ main(int argc, char * * argv)
struct timeval lastbeacontime = {0, 0};
#endif
for (i = 0; i < L_MAX; i++)
log_level[i] = E_WARN;
#ifdef ENABLE_NLS
setlocale(LC_MESSAGES, "");
setlocale(LC_CTYPE, "en_US.utf8");
@ -893,7 +892,7 @@ main(int argc, char * * argv)
textdomain("minidlna");
#endif
if(init(argc, argv) != 0)
if (init(argc, argv) != 0)
return 1;
#ifdef READYNAS
@ -931,8 +930,15 @@ main(int argc, char * * argv)
}
sqlite3_close(db);
char *cmd;
asprintf(&cmd, "rm -rf %s/files.db %s/art_cache", db_path, db_path);
system(cmd);
i = asprintf(&cmd, "rm -rf %s/files.db %s/art_cache", db_path, db_path);
if( i > 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) )