* Update coding style.

This commit is contained in:
Justin Maggard 2012-11-16 08:01:05 +00:00
parent aee83a3ee6
commit 1320eb4ea6

View File

@ -111,16 +111,15 @@ OpenAndConfHTTPSocket(unsigned short port)
/* Initialize client type cache */ /* Initialize client type cache */
memset(&clients, 0, sizeof(struct client_cache_s)); memset(&clients, 0, sizeof(struct client_cache_s));
if( (s = socket(PF_INET, SOCK_STREAM, 0)) < 0) s = socket(PF_INET, SOCK_STREAM, 0);
if (s < 0)
{ {
DPRINTF(E_ERROR, L_GENERAL, "socket(http): %s\n", strerror(errno)); DPRINTF(E_ERROR, L_GENERAL, "socket(http): %s\n", strerror(errno));
return -1; return -1;
} }
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)) < 0) if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)) < 0)
{
DPRINTF(E_WARN, L_GENERAL, "setsockopt(http, SO_REUSEADDR): %s\n", strerror(errno)); DPRINTF(E_WARN, L_GENERAL, "setsockopt(http, SO_REUSEADDR): %s\n", strerror(errno));
}
memset(&listenname, 0, sizeof(struct sockaddr_in)); memset(&listenname, 0, sizeof(struct sockaddr_in));
listenname.sin_family = AF_INET; listenname.sin_family = AF_INET;
@ -214,22 +213,19 @@ parselanaddr(struct lan_addr_s * lan_addr, const char * str)
static void static void
getfriendlyname(char *buf, int len) getfriendlyname(char *buf, int len)
{ {
char * dot = NULL; char *p = NULL;
char * hn = calloc(1, 256); char hn[256];
int off; int off;
if( gethostname(hn, 256) == 0 ) if (gethostname(hn, sizeof(hn)) == 0)
{ {
strncpyt(buf, hn, len); strncpyt(buf, hn, len);
dot = strchr(buf, '.'); p = strchr(buf, '.');
if( dot ) if (p)
*dot = '\0'; *p = '\0';
} }
else else
{
strcpy(buf, "Unknown"); strcpy(buf, "Unknown");
}
free(hn);
off = strlen(buf); off = strlen(buf);
off += snprintf(buf+off, len-off, ": "); off += snprintf(buf+off, len-off, ": ");
@ -312,7 +308,7 @@ getfriendlyname(char * buf, int len)
} }
static int static int
open_db(sqlite3 **thisdb) open_db(sqlite3 **sq3)
{ {
char path[PATH_MAX]; char path[PATH_MAX];
int new_db = 0; int new_db = 0;
@ -324,11 +320,9 @@ open_db(sqlite3 **thisdb)
make_dir(db_path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO); make_dir(db_path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
} }
if (sqlite3_open(path, &db) != SQLITE_OK) if (sqlite3_open(path, &db) != SQLITE_OK)
{
DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to open sqlite database! Exiting...\n"); DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to open sqlite database! Exiting...\n");
} if (sq3)
if (thisdb) *sq3 = db;
*thisdb = db;
sqlite3_busy_timeout(db, 5000); sqlite3_busy_timeout(db, 5000);
sql_exec(db, "pragma page_size = 4096"); sql_exec(db, "pragma page_size = 4096");
sql_exec(db, "pragma journal_mode = OFF"); sql_exec(db, "pragma journal_mode = OFF");
@ -496,7 +490,7 @@ init(int argc, char * * argv)
/* first check if "-f" option is used */ /* first check if "-f" option is used */
for (i=2; i<argc; i++) for (i=2; i<argc; i++)
{ {
if(0 == strcmp(argv[i-1], "-f")) if (strcmp(argv[i-1], "-f") == 0)
{ {
optionsfile = argv[i]; optionsfile = argv[i];
options_flag = 1; options_flag = 1;
@ -527,8 +521,7 @@ init(int argc, char * * argv)
if(access(optionsfile, F_OK) == 0 || options_flag) if(access(optionsfile, F_OK) == 0 || options_flag)
DPRINTF(E_FATAL, L_GENERAL, "Error reading configuration file %s\n", optionsfile); DPRINTF(E_FATAL, L_GENERAL, "Error reading configuration file %s\n", optionsfile);
} }
else
{
for (i=0; i<num_options; i++) for (i=0; i<num_options; i++)
{ {
switch (ary_options[i].id) switch (ary_options[i].id)
@ -546,24 +539,19 @@ init(int argc, char * * argv)
} }
} }
else else
{
DPRINTF(E_ERROR, L_GENERAL, "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); MAX_LAN_ADDR, word);
} }
}
break; break;
case UPNPLISTENING_IP: case UPNPLISTENING_IP:
if (n_lan_addr < MAX_LAN_ADDR) if (n_lan_addr < MAX_LAN_ADDR)
{ {
if(parselanaddr(&lan_addr[n_lan_addr], if (parselanaddr(&lan_addr[n_lan_addr], ary_options[i].value) == 0)
ary_options[i].value) == 0)
n_lan_addr++; n_lan_addr++;
} }
else else
{
DPRINTF(E_ERROR, L_GENERAL, "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); MAX_LAN_ADDR, ary_options[i].value);
}
break; break;
case UPNPPORT: case UPNPPORT:
runtime_vars.port = atoi(ary_options[i].value); runtime_vars.port = atoi(ary_options[i].value);
@ -595,29 +583,20 @@ init(int argc, char * * argv)
types = 0; types = 0;
while (*path) while (*path)
{ {
if( *path == 'A' || *path == 'a' ) if (*path == ',')
{
types |= TYPE_AUDIO;
}
else if( *path == 'V' || *path == 'v' )
{
types |= TYPE_VIDEO;
}
else if( *path == 'P' || *path == 'p' )
{
types |= TYPE_IMAGES;
}
else if( *path == ',' )
{ {
path++; path++;
break; break;
} }
else if (*path == 'A' || *path == 'a')
types |= TYPE_AUDIO;
else if (*path == 'V' || *path == 'v')
types |= TYPE_VIDEO;
else if (*path == 'P' || *path == 'p')
types |= TYPE_IMAGES;
else else
{
DPRINTF(E_FATAL, L_GENERAL, "Media directory entry not understood [%s]\n", DPRINTF(E_FATAL, L_GENERAL, "Media directory entry not understood [%s]\n",
ary_options[i].value); ary_options[i].value);
break;
}
path++; path++;
} }
} }
@ -631,17 +610,15 @@ init(int argc, char * * argv)
media_dir = calloc(1, sizeof(struct media_dir_s)); media_dir = calloc(1, sizeof(struct media_dir_s));
media_dir->path = strdup(path); media_dir->path = strdup(path);
media_dir->types = types; media_dir->types = types;
if( !media_dirs ) if (media_dirs)
{
media_dirs = media_dir;
}
else
{ {
struct media_dir_s *all_dirs = media_dirs; struct media_dir_s *all_dirs = media_dirs;
while( all_dirs->next ) while( all_dirs->next )
all_dirs = all_dirs->next; all_dirs = all_dirs->next;
all_dirs->next = media_dir; all_dirs->next = media_dir;
} }
else
media_dirs = media_dir;
break; break;
case UPNPALBUMART_NAMES: case UPNPALBUMART_NAMES:
for (string = ary_options[i].value; (word = strtok(string, "/")); string = NULL) for (string = ary_options[i].value; (word = strtok(string, "/")); string = NULL)
@ -654,17 +631,15 @@ init(int argc, char * * argv)
this_name->wildcard = 1; this_name->wildcard = 1;
} }
this_name->name = strdup(word); this_name->name = strdup(word);
if( !album_art_names ) if (album_art_names)
{
album_art_names = this_name;
}
else
{ {
struct album_art_name_s * all_names = album_art_names; struct album_art_name_s * all_names = album_art_names;
while( all_names->next ) while( all_names->next )
all_names = all_names->next; all_names = all_names->next;
all_names->next = this_name; all_names->next = this_name;
} }
else
album_art_names = this_name;
} }
break; break;
case UPNPDBDIR: case UPNPDBDIR:
@ -673,10 +648,7 @@ init(int argc, char * * argv)
path = (ary_options[i].value); path = (ary_options[i].value);
make_dir(path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO); make_dir(path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
if (access(path, F_OK) != 0) if (access(path, F_OK) != 0)
{
DPRINTF(E_FATAL, L_GENERAL, "Database path not accessible! [%s]\n", path); DPRINTF(E_FATAL, L_GENERAL, "Database path not accessible! [%s]\n", path);
break;
}
strncpyt(db_path, path, PATH_MAX); strncpyt(db_path, path, PATH_MAX);
break; break;
case UPNPLOGDIR: case UPNPLOGDIR:
@ -685,10 +657,7 @@ init(int argc, char * * argv)
path = (ary_options[i].value); path = (ary_options[i].value);
make_dir(path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO); make_dir(path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
if (access(path, F_OK) != 0) if (access(path, F_OK) != 0)
{
DPRINTF(E_FATAL, L_GENERAL, "Log path not accessible! [%s]\n", path); DPRINTF(E_FATAL, L_GENERAL, "Log path not accessible! [%s]\n", path);
break;
}
strncpyt(log_path, path, PATH_MAX); strncpyt(log_path, path, PATH_MAX);
break; break;
case UPNPLOGLEVEL: case UPNPLOGLEVEL:
@ -707,8 +676,7 @@ init(int argc, char * * argv)
SETFLAG(DLNA_STRICT_MASK); SETFLAG(DLNA_STRICT_MASK);
break; break;
case ROOT_CONTAINER: case ROOT_CONTAINER:
switch( ary_options[i].value[0] ) switch (ary_options[i].value[0]) {
{
case '.': case '.':
runtime_vars.root_container = NULL; runtime_vars.root_container = NULL;
break; break;
@ -742,7 +710,8 @@ init(int argc, char * * argv)
break; break;
case USER_ACCOUNT: case USER_ACCOUNT:
uid = strtol(ary_options[i].value, &string, 0); uid = strtol(ary_options[i].value, &string, 0);
if (*string) { if (*string)
{
/* Symbolic username given, not UID. */ /* Symbolic username given, not UID. */
struct passwd *entry = getpwnam(ary_options[i].value); struct passwd *entry = getpwnam(ary_options[i].value);
if (!entry) if (!entry)
@ -755,7 +724,6 @@ init(int argc, char * * argv)
optionsfile); optionsfile);
} }
} }
}
if (log_path[0] == '\0') if (log_path[0] == '\0')
{ {
if (db_path[0] == '\0') if (db_path[0] == '\0')
@ -850,11 +818,9 @@ init(int argc, char * * argv)
n_lan_addr++; n_lan_addr++;
} }
else else
{
DPRINTF(E_ERROR, L_GENERAL, "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]); MAX_LAN_ADDR, argv[i]);
} }
}
else else
DPRINTF(E_FATAL, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); DPRINTF(E_FATAL, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]);
break; break;
@ -865,15 +831,13 @@ init(int argc, char * * argv)
int j; int j;
i++; i++;
if (getifaddr(argv[i], ip_addr, sizeof(ip_addr)) < 0) if (getifaddr(argv[i], ip_addr, sizeof(ip_addr)) < 0)
{
DPRINTF(E_FATAL, L_GENERAL, "Required network interface '%s' not found.\n", DPRINTF(E_FATAL, L_GENERAL, "Required network interface '%s' not found.\n",
argv[i]); argv[i]);
}
for (j=0; j<n_lan_addr; j++) for (j=0; j<n_lan_addr; j++)
{ {
struct lan_addr_s tmpaddr; struct lan_addr_s tmpaddr;
parselanaddr(&tmpaddr, ip_addr); parselanaddr(&tmpaddr, ip_addr);
if(0 == strcmp(lan_addr[j].str, tmpaddr.str)) if(strcmp(lan_addr[j].str, tmpaddr.str) == 0)
address_already_there = 1; address_already_there = 1;
} }
if (address_already_there) if (address_already_there)
@ -884,11 +848,9 @@ init(int argc, char * * argv)
n_lan_addr++; n_lan_addr++;
} }
else else
{
DPRINTF(E_ERROR, L_GENERAL, "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]); MAX_LAN_ADDR, argv[i]);
} }
}
else else
DPRINTF(E_FATAL, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); DPRINTF(E_FATAL, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]);
break; break;
@ -904,12 +866,12 @@ init(int argc, char * * argv)
DPRINTF(E_FATAL, L_GENERAL, "Failed to clean old file cache. EXITING\n"); DPRINTF(E_FATAL, L_GENERAL, "Failed to clean old file cache. EXITING\n");
break; break;
case 'u': case 'u':
if(i+1 == argc) if (i+1 != argc)
DPRINTF(E_FATAL, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); {
else {
i++; i++;
uid = strtol(argv[i], &string, 0); uid = strtol(argv[i], &string, 0);
if (*string) { if (*string)
{
/* Symbolic username given, not UID. */ /* Symbolic username given, not UID. */
struct passwd *entry = getpwnam(argv[i]); struct passwd *entry = getpwnam(argv[i]);
if (!entry) if (!entry)
@ -917,6 +879,9 @@ init(int argc, char * * argv)
uid = entry->pw_uid; uid = entry->pw_uid;
} }
} }
else
DPRINTF(E_FATAL, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]);
break;
break; break;
#ifdef __linux__ #ifdef __linux__
case 'S': case 'S':
@ -938,15 +903,13 @@ init(int argc, char * * argv)
(getifaddr("eth0", ip_addr, sizeof(ip_addr)) < 0) && (getifaddr("eth0", ip_addr, sizeof(ip_addr)) < 0) &&
(getifaddr("eth1", ip_addr, sizeof(ip_addr)) < 0)) (getifaddr("eth1", ip_addr, sizeof(ip_addr)) < 0))
{ {
DPRINTF(E_OFF, L_GENERAL, "No IP address automatically detected!\n"); DPRINTF(E_OFF, L_GENERAL, "No IP address automatically detected\n");
} }
if (*ip_addr && parselanaddr(&lan_addr[n_lan_addr], ip_addr) == 0) if (*ip_addr && parselanaddr(&lan_addr[n_lan_addr], ip_addr) == 0)
{
n_lan_addr++; n_lan_addr++;
} }
}
if( (n_lan_addr==0) || (runtime_vars.port<=0) ) if (!n_lan_addr || runtime_vars.port <= 0)
{ {
DPRINTF(E_ERROR, L_GENERAL, "Usage:\n\t" DPRINTF(E_ERROR, L_GENERAL, "Usage:\n\t"
"%s [-d] [-v] [-f config_file]\n" "%s [-d] [-v] [-f config_file]\n"
@ -977,9 +940,7 @@ init(int argc, char * * argv)
log_level = log_str; log_level = log_str;
} }
else if (!log_level) else if (!log_level)
{
log_level = log_str; log_level = log_str;
}
/* Set the default log file path to NULL (stdout) */ /* Set the default log file path to NULL (stdout) */
path = NULL; path = NULL;
@ -1022,7 +983,7 @@ init(int argc, char * * argv)
else else
strcpy(presentationurl, "/"); strcpy(presentationurl, "/");
/* set signal handler */ /* set signal handlers */
memset(&sa, 0, sizeof(struct sigaction)); memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = sigterm; sa.sa_handler = sigterm;
if (sigaction(SIGTERM, &sa, NULL)) if (sigaction(SIGTERM, &sa, NULL))
@ -1047,7 +1008,7 @@ init(int argc, char * * argv)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int i; int ret, i;
int sudp = -1, shttpl = -1; int sudp = -1, shttpl = -1;
int snotify[MAX_LAN_ADDR]; int snotify[MAX_LAN_ADDR];
LIST_HEAD(httplisthead, upnphttp) upnphttphead; LIST_HEAD(httplisthead, upnphttp) upnphttphead;
@ -1077,7 +1038,8 @@ main(int argc, char * * argv)
textdomain("minidlna"); textdomain("minidlna");
#endif #endif
if (init(argc, argv) != 0) ret = init(argc, argv);
if (ret != 0)
return 1; return 1;
DPRINTF(E_WARN, L_GENERAL, "Starting " SERVER_NAME " version " MINIDLNA_VERSION ".\n"); DPRINTF(E_WARN, L_GENERAL, "Starting " SERVER_NAME " version " MINIDLNA_VERSION ".\n");
@ -1088,73 +1050,62 @@ main(int argc, char * * argv)
LIST_INIT(&upnphttphead); LIST_INIT(&upnphttphead);
i = open_db(NULL); ret = open_db(NULL);
if( i == 0 ) if (ret == 0)
{
updateID = sql_get_int_field(db, "SELECT UPDATE_ID from SETTINGS"); updateID = sql_get_int_field(db, "SELECT UPDATE_ID from SETTINGS");
check_db(db, i, &scanner_pid); if (updateID == -1)
ret = -1;
}
check_db(db, ret, &scanner_pid);
signal(SIGCHLD, &sigchld); signal(SIGCHLD, &sigchld);
#ifdef HAVE_INOTIFY #ifdef HAVE_INOTIFY
if( GETFLAG(INOTIFY_MASK) ) if( GETFLAG(INOTIFY_MASK) )
{ {
if (!sqlite3_threadsafe() || sqlite3_libversion_number() < 3005001) if (!sqlite3_threadsafe() || sqlite3_libversion_number() < 3005001)
{
DPRINTF(E_ERROR, L_GENERAL, "SQLite library is not threadsafe! " DPRINTF(E_ERROR, L_GENERAL, "SQLite library is not threadsafe! "
"Inotify will be disabled.\n"); "Inotify will be disabled.\n");
} else if (pthread_create(&inotify_thread, NULL, start_inotify, NULL) != 0)
else if( pthread_create(&inotify_thread, NULL, start_inotify, NULL) )
{
DPRINTF(E_FATAL, L_GENERAL, "ERROR: pthread_create() failed for start_inotify. EXITING\n"); DPRINTF(E_FATAL, L_GENERAL, "ERROR: pthread_create() failed for start_inotify. EXITING\n");
} }
}
#endif #endif
sudp = OpenAndConfSSDPReceiveSocket(); sudp = OpenAndConfSSDPReceiveSocket();
if (sudp < 0) if (sudp < 0)
{ {
DPRINTF(E_INFO, L_GENERAL, "Failed to open socket for receiving SSDP. Trying to use MiniSSDPd\n"); DPRINTF(E_INFO, L_GENERAL, "Failed to open socket for receiving SSDP. Trying to use MiniSSDPd\n");
if(SubmitServicesToMiniSSDPD(lan_addr[0].str, runtime_vars.port) < 0) { if (SubmitServicesToMiniSSDPD(lan_addr[0].str, runtime_vars.port) < 0)
DPRINTF(E_FATAL, L_GENERAL, "Failed to connect to MiniSSDPd. EXITING"); DPRINTF(E_FATAL, L_GENERAL, "Failed to connect to MiniSSDPd. EXITING");
return 1;
}
} }
/* open socket for HTTP connections. Listen on the 1st LAN address */ /* open socket for HTTP connections. Listen on the 1st LAN address */
shttpl = OpenAndConfHTTPSocket(runtime_vars.port); shttpl = OpenAndConfHTTPSocket(runtime_vars.port);
if (shttpl < 0) if (shttpl < 0)
{
DPRINTF(E_FATAL, L_GENERAL, "Failed to open socket for HTTP. EXITING\n"); DPRINTF(E_FATAL, L_GENERAL, "Failed to open socket for HTTP. EXITING\n");
}
DPRINTF(E_WARN, L_GENERAL, "HTTP listening on port %d\n", runtime_vars.port); DPRINTF(E_WARN, L_GENERAL, "HTTP listening on port %d\n", runtime_vars.port);
/* open socket for sending notifications */ /* open socket for sending notifications */
if (OpenAndConfSSDPNotifySockets(snotify) < 0) if (OpenAndConfSSDPNotifySockets(snotify) < 0)
{
DPRINTF(E_FATAL, L_GENERAL, "Failed to open sockets for sending SSDP notify " DPRINTF(E_FATAL, L_GENERAL, "Failed to open sockets for sending SSDP notify "
"messages. EXITING\n"); "messages. EXITING\n");
}
#ifdef TIVO_SUPPORT #ifdef TIVO_SUPPORT
if (GETFLAG(TIVO_MASK)) if (GETFLAG(TIVO_MASK))
{ {
DPRINTF(E_WARN, L_GENERAL, "TiVo support is enabled.\n"); DPRINTF(E_WARN, L_GENERAL, "TiVo support is enabled.\n");
/* Add TiVo-specific randomize function to sqlite */ /* Add TiVo-specific randomize function to sqlite */
if( sqlite3_create_function(db, "tivorandom", 1, SQLITE_UTF8, NULL, &TiVoRandomSeedFunc, NULL, NULL) != SQLITE_OK ) ret = sqlite3_create_function(db, "tivorandom", 1, SQLITE_UTF8, NULL, &TiVoRandomSeedFunc, NULL, NULL);
{ if (ret != SQLITE_OK)
DPRINTF(E_ERROR, L_TIVO, "ERROR: Failed to add sqlite randomize function for TiVo!\n"); DPRINTF(E_ERROR, L_TIVO, "ERROR: Failed to add sqlite randomize function for TiVo!\n");
}
/* open socket for sending Tivo notifications */ /* open socket for sending Tivo notifications */
sbeacon = OpenAndConfTivoBeaconSocket(); sbeacon = OpenAndConfTivoBeaconSocket();
if(sbeacon < 0) if(sbeacon < 0)
{
DPRINTF(E_FATAL, L_GENERAL, "Failed to open sockets for sending Tivo beacon notify " DPRINTF(E_FATAL, L_GENERAL, "Failed to open sockets for sending Tivo beacon notify "
"messages. EXITING\n"); "messages. EXITING\n");
}
tivo_bcast.sin_family = AF_INET; tivo_bcast.sin_family = AF_INET;
tivo_bcast.sin_addr.s_addr = htonl(getBcastAddress()); tivo_bcast.sin_addr.s_addr = htonl(getBcastAddress());
tivo_bcast.sin_port = htons(2190); tivo_bcast.sin_port = htons(2190);
} }
else else
{
sbeacon = -1; sbeacon = -1;
}
#endif #endif
SendSSDPGoodbye(snotify, n_lan_addr); SendSSDPGoodbye(snotify, n_lan_addr);
@ -1193,10 +1144,8 @@ main(int argc, char * * argv)
timeout.tv_sec--; timeout.tv_sec--;
} }
else else
{
timeout.tv_usec = lastnotifytime.tv_usec - timeofday.tv_usec; timeout.tv_usec = lastnotifytime.tv_usec - timeofday.tv_usec;
} }
}
#ifdef TIVO_SUPPORT #ifdef TIVO_SUPPORT
if (GETFLAG(TIVO_MASK)) if (GETFLAG(TIVO_MASK))
{ {
@ -1212,21 +1161,17 @@ main(int argc, char * * argv)
/* Beacons should be sent every 5 seconds or so for the first minute, /* Beacons should be sent every 5 seconds or so for the first minute,
* then every minute or so thereafter. */ * then every minute or so thereafter. */
if (beacon_interval == 5 && (timeofday.tv_sec - startup_time) > 60) if (beacon_interval == 5 && (timeofday.tv_sec - startup_time) > 60)
{
beacon_interval = 60; beacon_interval = 60;
} }
}
else if (timeout.tv_sec > (lastbeacontime.tv_sec + beacon_interval + 1 - timeofday.tv_sec)) else if (timeout.tv_sec > (lastbeacontime.tv_sec + beacon_interval + 1 - timeofday.tv_sec))
{
timeout.tv_sec = lastbeacontime.tv_sec + beacon_interval - timeofday.tv_sec; timeout.tv_sec = lastbeacontime.tv_sec + beacon_interval - timeofday.tv_sec;
} }
}
#endif #endif
} }
if (scanning) if (scanning)
{ {
if( !scanner_pid || kill(scanner_pid, 0) ) if (!scanner_pid || kill(scanner_pid, 0) != 0)
{ {
scanning = 0; scanning = 0;
updateID++; updateID++;
@ -1267,14 +1212,13 @@ main(int argc, char * * argv)
#ifdef DEBUG #ifdef DEBUG
/* for debug */ /* for debug */
if (i > 1) if (i > 1)
{
DPRINTF(E_DEBUG, L_GENERAL, "%d active incoming HTTP connections\n", i); DPRINTF(E_DEBUG, L_GENERAL, "%d active incoming HTTP connections\n", i);
}
#endif #endif
FD_ZERO(&writeset); FD_ZERO(&writeset);
upnpevents_selectfds(&readset, &writeset, &max_fd); upnpevents_selectfds(&readset, &writeset, &max_fd);
if(select(max_fd+1, &readset, &writeset, 0, &timeout) < 0) ret = select(max_fd+1, &readset, &writeset, 0, &timeout);
if (ret < 0)
{ {
if(quitting) goto shutdown; if(quitting) goto shutdown;
if(errno == EINTR) continue; if(errno == EINTR) continue;
@ -1310,12 +1254,9 @@ main(int argc, char * * argv)
/* process active HTTP connections */ /* process active HTTP connections */
for (e = upnphttphead.lh_first; e != NULL; e = e->entries.le_next) for (e = upnphttphead.lh_first; e != NULL; e = e->entries.le_next)
{ {
if( (e->socket >= 0) && (e->state <= 2) if ((e->socket >= 0) && (e->state <= 2) && (FD_ISSET(e->socket, &readset)))
&&(FD_ISSET(e->socket, &readset)) )
{
Process_upnphttp(e); Process_upnphttp(e);
} }
}
/* process incoming HTTP connections */ /* process incoming HTTP connections */
if (shttpl >= 0 && FD_ISSET(shttpl, &readset)) if (shttpl >= 0 && FD_ISSET(shttpl, &readset))
{ {
@ -1353,7 +1294,7 @@ main(int argc, char * * argv)
} }
} }
/* delete finished HTTP connections */ /* delete finished HTTP connections */
for(e = upnphttphead.lh_first; e != NULL; ) for (e = upnphttphead.lh_first; e != NULL; e = next)
{ {
next = e->entries.le_next; next = e->entries.le_next;
if(e->state >= 100) if(e->state >= 100)
@ -1361,7 +1302,6 @@ main(int argc, char * * argv)
LIST_REMOVE(e, entries); LIST_REMOVE(e, entries);
Delete_upnphttp(e); Delete_upnphttp(e);
} }
e = next;
} }
} }