Replace signal with sigaction
This commit is contained in:
parent
615c28d737
commit
466651958d
1 changed files with 20 additions and 16 deletions
34
herbe.c
34
herbe.c
|
@ -68,21 +68,15 @@ int get_max_len(char *body, XftFont *font, int max_text_width)
|
||||||
return ++eol;
|
return ++eol;
|
||||||
}
|
}
|
||||||
|
|
||||||
void expire()
|
void expire(int sig)
|
||||||
{
|
{
|
||||||
XEvent event;
|
XEvent event;
|
||||||
event.type = ButtonPress;
|
event.type = ButtonPress;
|
||||||
event.xbutton.button = DISMISS_BUTTON;
|
event.xbutton.button = (sig == SIGUSR2) ? (ACTION_BUTTON) : (DISMISS_BUTTON);
|
||||||
XSendEvent(display, window, 0, 0, &event);
|
XSendEvent(display, window, 0, 0, &event);
|
||||||
XFlush(display);
|
XFlush(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void action()
|
|
||||||
{
|
|
||||||
exit_code = EXIT_ACTION;
|
|
||||||
expire();
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
|
@ -91,11 +85,21 @@ int main(int argc, char *argv[])
|
||||||
die("Usage: %s body", argv[0]);
|
die("Usage: %s body", argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGALRM, expire);
|
struct sigaction act_expire, act_ignore;
|
||||||
signal(SIGTERM, expire);
|
act_expire.sa_handler = expire;
|
||||||
signal(SIGINT, expire);
|
act_expire.sa_flags = SA_RESTART;
|
||||||
signal(SIGUSR1, SIG_IGN);
|
sigemptyset(&act_expire.sa_mask);
|
||||||
signal(SIGUSR2, SIG_IGN);
|
|
||||||
|
act_ignore.sa_handler = SIG_IGN;
|
||||||
|
act_ignore.sa_flags = 0;
|
||||||
|
sigemptyset(&act_ignore.sa_mask);
|
||||||
|
|
||||||
|
sigaction(SIGALRM, &act_expire, 0);
|
||||||
|
sigaction(SIGTERM, &act_expire, 0);
|
||||||
|
sigaction(SIGINT, &act_expire, 0);
|
||||||
|
|
||||||
|
sigaction(SIGUSR1, &act_ignore, 0);
|
||||||
|
sigaction(SIGUSR2, &act_ignore, 0);
|
||||||
|
|
||||||
display = XOpenDisplay(0);
|
display = XOpenDisplay(0);
|
||||||
|
|
||||||
|
@ -171,8 +175,8 @@ int main(int argc, char *argv[])
|
||||||
sem_t *mutex = sem_open("/herbe", O_CREAT, 0644, 1);
|
sem_t *mutex = sem_open("/herbe", O_CREAT, 0644, 1);
|
||||||
sem_wait(mutex);
|
sem_wait(mutex);
|
||||||
|
|
||||||
signal(SIGUSR1, expire);
|
sigaction(SIGUSR1, &act_expire, 0);
|
||||||
signal(SIGUSR2, action);
|
sigaction(SIGUSR2, &act_expire, 0);
|
||||||
|
|
||||||
if (duration != 0)
|
if (duration != 0)
|
||||||
alarm(duration);
|
alarm(duration);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue