New way of handling signals.
This commit is contained in:
parent
5dcc213c16
commit
d2c766a137
@ -7,6 +7,9 @@
|
|||||||
* src/event.c
|
* src/event.c
|
||||||
* src/io.c
|
* src/io.c
|
||||||
* src/recur.c: make use of erase_note() whenever possible
|
* src/recur.c: make use of erase_note() whenever possible
|
||||||
|
|
||||||
|
* src/calcurse.c
|
||||||
|
* src/sigs.[ch]: new way of handling signals
|
||||||
|
|
||||||
2009-07-15 Frederic Culot <frederic@culot.org>
|
2009-07-15 Frederic Culot <frederic@culot.org>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $calcurse: calcurse.c,v 1.83 2009/07/12 20:37:41 culot Exp $ */
|
/* $calcurse: calcurse.c,v 1.84 2009/07/19 16:51:36 culot Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calcurse - text-based organizer
|
* Calcurse - text-based organizer
|
||||||
@ -37,7 +37,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -73,7 +72,6 @@ main (int argc, char **argv)
|
|||||||
int sav_hilt_app = 0;
|
int sav_hilt_app = 0;
|
||||||
int sav_hilt_tod = 0;
|
int sav_hilt_tod = 0;
|
||||||
int cut_item = 0;
|
int cut_item = 0;
|
||||||
struct sigaction sigact;
|
|
||||||
unsigned do_storage = 0;
|
unsigned do_storage = 0;
|
||||||
unsigned do_update = 1;
|
unsigned do_update = 1;
|
||||||
unsigned day_changed = 0;
|
unsigned day_changed = 0;
|
||||||
@ -107,11 +105,11 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Begin of interactive mode with ncurses interface. */
|
/* Begin of interactive mode with ncurses interface. */
|
||||||
sigs_init (&sigact); /* signal handling init */
|
sigs_init (); /* signal handling init */
|
||||||
initscr (); /* start the curses mode */
|
initscr (); /* start the curses mode */
|
||||||
cbreak (); /* control chars generate a signal */
|
cbreak (); /* control chars generate a signal */
|
||||||
noecho (); /* controls echoing of typed chars */
|
noecho (); /* controls echoing of typed chars */
|
||||||
curs_set (0); /* make cursor invisible */
|
curs_set (0); /* make cursor invisible */
|
||||||
calendar_set_current_date ();
|
calendar_set_current_date ();
|
||||||
notify_init_vars ();
|
notify_init_vars ();
|
||||||
wins_get_config ();
|
wins_get_config ();
|
||||||
|
59
src/sigs.c
59
src/sigs.c
@ -1,4 +1,4 @@
|
|||||||
/* $calcurse: sigs.c,v 1.8 2009/07/05 20:33:23 culot Exp $ */
|
/* $calcurse: sigs.c,v 1.9 2009/07/19 16:51:36 culot Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calcurse - text-based organizer
|
* Calcurse - text-based organizer
|
||||||
@ -38,10 +38,12 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <signal.h>
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "sigs.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* General signal handling routine.
|
* General signal handling routine.
|
||||||
@ -50,7 +52,7 @@
|
|||||||
* Also catch CTRL-C (SIGINT), and SIGWINCH to resize screen automatically.
|
* Also catch CTRL-C (SIGINT), and SIGWINCH to resize screen automatically.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
signal_handler (int sig)
|
generic_hdlr (int sig)
|
||||||
{
|
{
|
||||||
switch (sig)
|
switch (sig)
|
||||||
{
|
{
|
||||||
@ -65,34 +67,31 @@ signal_handler (int sig)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned
|
||||||
|
sigs_set_hdlr (int sig, void (*handler)(int))
|
||||||
|
{
|
||||||
|
struct sigaction sa;
|
||||||
|
|
||||||
|
memset (&sa, 0, sizeof sa);
|
||||||
|
sigemptyset (&sa.sa_mask);
|
||||||
|
sa.sa_handler = handler;
|
||||||
|
sa.sa_flags = 0;
|
||||||
|
if (sigaction (sig, &sa, (struct sigaction *)0) == -1)
|
||||||
|
{
|
||||||
|
ERROR_MSG (_("Error setting signal #%d : %s\n"),
|
||||||
|
sig, strerror (errno));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Signal handling init. */
|
/* Signal handling init. */
|
||||||
void
|
void
|
||||||
sigs_init (struct sigaction *sa)
|
sigs_init ()
|
||||||
{
|
{
|
||||||
sa->sa_handler = signal_handler;
|
if (!sigs_set_hdlr (SIGCHLD, generic_hdlr)
|
||||||
sa->sa_flags = 0;
|
|| !sigs_set_hdlr (SIGWINCH, generic_hdlr)
|
||||||
sigemptyset (&sa->sa_mask);
|
|| !sigs_set_hdlr (SIGINT, SIG_IGN))
|
||||||
if (sigaction (SIGCHLD, sa, NULL) != 0)
|
exit_calcurse (1);
|
||||||
{
|
|
||||||
ERROR_MSG (_("Error handling SIGCHLD signal"));
|
|
||||||
exit_calcurse (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
sa->sa_handler = signal_handler;
|
|
||||||
sa->sa_flags = 0;
|
|
||||||
sigemptyset (&sa->sa_mask);
|
|
||||||
if (sigaction (SIGWINCH, sa, NULL) != 0)
|
|
||||||
{
|
|
||||||
ERROR_MSG (_("Error handling SIGWINCH signal"));
|
|
||||||
exit_calcurse (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
sa->sa_handler = SIG_IGN;
|
|
||||||
sa->sa_flags = 0;
|
|
||||||
sigemptyset (&(sa->sa_mask));
|
|
||||||
if (sigaction (SIGINT, sa, NULL) != 0)
|
|
||||||
{
|
|
||||||
ERROR_MSG (_("Error handling SIGINT signal"));
|
|
||||||
exit_calcurse (1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $calcurse: sigs.h,v 1.4 2009/07/05 20:33:23 culot Exp $ */
|
/* $calcurse: sigs.h,v 1.5 2009/07/19 16:51:36 culot Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calcurse - text-based organizer
|
* Calcurse - text-based organizer
|
||||||
@ -39,6 +39,9 @@
|
|||||||
#ifndef CALCURSE_SIGS_H
|
#ifndef CALCURSE_SIGS_H
|
||||||
#define CALCURSE_SIGS_H
|
#define CALCURSE_SIGS_H
|
||||||
|
|
||||||
void sigs_init (struct sigaction *);
|
#include <signal.h>
|
||||||
|
|
||||||
|
void sigs_init (void);
|
||||||
|
unsigned sigs_set_hdlr (int, void (*)(int));
|
||||||
|
|
||||||
#endif /* CALCURSE_SIGS_H */
|
#endif /* CALCURSE_SIGS_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user