*) slight code cleanup

*) now --kill will not check for /proc/<pid>/exe (this is linux specific)

git-svn-id: https://svn.musicpd.org/mpd/trunk@3063 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2005-03-12 22:38:49 +00:00
parent 41b5fedaf0
commit aa7b698086
2 changed files with 20 additions and 15 deletions

View File

@ -393,21 +393,28 @@ int doIOForInterfaces() {
struct timeval tv; struct timeval tv;
int i; int i;
int selret; int selret;
int fdmax = 0; int fdmax;
tv.tv_sec = 1; tv.tv_sec = 1;
tv.tv_usec = 0; tv.tv_usec = 0;
addInterfacesReadyToReadAndListenSocketToFdSet(&rfds,&fdmax); while(1) {
addInterfacesForBufferFlushToFdSet(&wfds,&fdmax); fdmax = 0;
while((selret = select(fdmax+1,&rfds,&wfds,NULL,&tv))) { addInterfacesReadyToReadAndListenSocketToFdSet(&rfds,&fdmax);
getConnections(&rfds); addInterfacesForBufferFlushToFdSet(&wfds,&fdmax);
if(selret<0 && errno==EINTR) break;
else if(selret<0) { selret = select(fdmax+1,&rfds,&wfds,NULL,&tv);
if(selret == 0 || (selret<0 && errno==EINTR)) break;
if(selret<0) {
closeNextErroredInterface(); closeNextErroredInterface();
continue; continue;
} }
getConnections(&rfds);
for(i=0;i<interface_max_connections;i++) { for(i=0;i<interface_max_connections;i++) {
if(interfaces[i].open && FD_ISSET(interfaces[i].fd,&rfds)) { if(interfaces[i].open && FD_ISSET(interfaces[i].fd,&rfds)) {
if(COMMAND_RETURN_KILL==interfaceReadInput(&(interfaces[i]))) { if(COMMAND_RETURN_KILL==interfaceReadInput(&(interfaces[i]))) {
@ -420,11 +427,9 @@ int doIOForInterfaces() {
interfaces[i].lastTime = time(NULL); interfaces[i].lastTime = time(NULL);
} }
} }
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 0;
fdmax = 0;
addInterfacesReadyToReadAndListenSocketToFdSet(&rfds,&fdmax);
addInterfacesForBufferFlushToFdSet(&wfds,&fdmax);
} }
return 1; return 1;

View File

@ -385,11 +385,11 @@ void cleanUpPidFile() {
} }
void killFromPidFile(char * cmd, int killOption) { void killFromPidFile(char * cmd, int killOption) {
/*char buf[32];
struct stat st_cmd; struct stat st_cmd;
struct stat st_exe; struct stat st_exe;*/
ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 1); ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 1);
int pid; int pid;
char buf[32];
FILE * fp = fopen(pidFileParam->value,"r"); FILE * fp = fopen(pidFileParam->value,"r");
if(!fp) { if(!fp) {
@ -405,7 +405,7 @@ void killFromPidFile(char * cmd, int killOption) {
} }
fclose(fp); fclose(fp);
memset(buf, 0, 32); /*memset(buf, 0, 32);
snprintf(buf, 31, "/proc/%i/exe", pid); snprintf(buf, 31, "/proc/%i/exe", pid);
if(killOption == 1) { if(killOption == 1) {
@ -430,7 +430,7 @@ void killFromPidFile(char * cmd, int killOption) {
cmd, pid); cmd, pid);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }*/
if(kill(pid, SIGTERM)) { if(kill(pid, SIGTERM)) {
ERROR("unable to kill proccess %i: %s\n", pid, strerror(errno)); ERROR("unable to kill proccess %i: %s\n", pid, strerror(errno));
@ -492,9 +492,9 @@ int main(int argc, char * argv[]) {
readPlaylistState(); readPlaylistState();
while(COMMAND_RETURN_KILL!=doIOForInterfaces()) { while(COMMAND_RETURN_KILL!=doIOForInterfaces()) {
if(COMMAND_RETURN_KILL==handlePendingSignals()) break;
syncPlayerAndPlaylist(); syncPlayerAndPlaylist();
closeOldInterfaces(); closeOldInterfaces();
if(COMMAND_RETURN_KILL==handlePendingSignals()) break;
readDirectoryDBIfUpdateIsFinished(); readDirectoryDBIfUpdateIsFinished();
} }