Use SIGALRM instead of pthread for status script
This commit is contained in:
2
configure
vendored
2
configure
vendored
@@ -79,8 +79,6 @@ fi
|
|||||||
[ -n "$USE_XRANDR" ] && CFLAGS="$CFLAGS -DHAVE_XRANDR"
|
[ -n "$USE_XRANDR" ] && CFLAGS="$CFLAGS -DHAVE_XRANDR"
|
||||||
[ -n "$USE_IMLIB2" ] && CFLAGS="$CFLAGS -DHAVE_IMLIB"
|
[ -n "$USE_IMLIB2" ] && CFLAGS="$CFLAGS -DHAVE_IMLIB"
|
||||||
|
|
||||||
LDFLAGS="$LDFLAGS -lpthread"
|
|
||||||
|
|
||||||
cat > Makefile << EOF
|
cat > Makefile << EOF
|
||||||
PREFIX=$PREFIX
|
PREFIX=$PREFIX
|
||||||
XDG_CONFIG_DIR=$XDG_CONFIG_DIR
|
XDG_CONFIG_DIR=$XDG_CONFIG_DIR
|
||||||
|
|||||||
50
src/wmfs.c
50
src/wmfs.c
@@ -141,49 +141,19 @@ quit(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
|
||||||
thread_process(void *arg)
|
|
||||||
{
|
|
||||||
XEvent ev;
|
|
||||||
|
|
||||||
/* X event loop */
|
|
||||||
if(arg)
|
|
||||||
{
|
|
||||||
while(!exiting && !XNextEvent(dpy, &ev))
|
|
||||||
getevent(ev);
|
|
||||||
}
|
|
||||||
/* Status checking loop with timing */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pthread_detach(pthread_self());
|
|
||||||
do
|
|
||||||
{
|
|
||||||
conf.status_pid = spawn(conf.status_path);
|
|
||||||
sleep(conf.status_timing);
|
|
||||||
} while (!exiting && conf.status_timing != 0);
|
|
||||||
}
|
|
||||||
pthread_exit(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** WMFS main loop.
|
/** WMFS main loop.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
mainloop(void)
|
mainloop(void)
|
||||||
{
|
{
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
pthread_t evloop, evstatus;
|
|
||||||
void *ret;
|
|
||||||
|
|
||||||
if(!estatus)
|
/* launch status loop */
|
||||||
while(!exiting && !XNextEvent(dpy, &ev))
|
if (estatus)
|
||||||
getevent(ev);
|
signal_handle(SIGALRM);
|
||||||
else
|
|
||||||
{
|
|
||||||
pthread_create(&evloop, NULL, thread_process, "1");
|
|
||||||
pthread_create(&evstatus, NULL, thread_process, NULL);
|
|
||||||
|
|
||||||
(void)pthread_join(evloop, &ret);
|
while(!exiting && !XNextEvent(dpy, &ev))
|
||||||
}
|
getevent(ev);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -418,6 +388,16 @@ signal_handle(int sig)
|
|||||||
warn("signal(%d)", SIGCHLD);
|
warn("signal(%d)", SIGCHLD);
|
||||||
while (waitpid(-1, NULL, WNOHANG) > 0);
|
while (waitpid(-1, NULL, WNOHANG) > 0);
|
||||||
break;
|
break;
|
||||||
|
case SIGALRM:
|
||||||
|
/* re-set signal handler */
|
||||||
|
if (signal(SIGALRM, &signal_handle) == SIG_ERR)
|
||||||
|
warn("signal(%d)", SIGALRM);
|
||||||
|
/* exec status script */
|
||||||
|
conf.status_pid = spawn(conf.status_path);
|
||||||
|
/* re-set timer */
|
||||||
|
if (conf.status_timing > 0)
|
||||||
|
alarm(conf.status_timing);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user