Bump version number to 1.1.0

Sat Sep 24 14:41:23 2005  Soeren Sandmann  <sandmann@redhat.com>

	* configure.ac: Bump version number to 1.1.0

	* signal-handler.c: Many, mostly cosmetic, cleanups

	* sysprof-text.c: uninstall signal handlers when exiting
This commit is contained in:
Soeren Sandmann
2005-09-24 18:42:24 +00:00
committed by Søren Sandmann Pedersen
parent e2fb3b2985
commit 665d680c46
5 changed files with 116 additions and 68 deletions

View File

@ -1,3 +1,11 @@
Sat Sep 24 14:41:23 2005 Soeren Sandmann <sandmann@redhat.com>
* configure.ac: Bump version number to 1.1.0
* signal-handler.c: Many, mostly cosmetic, cleanups
* sysprof-text.c: uninstall signal handlers when exiting
Sat Sep 24 00:01:42 2005 Soeren Sandmann <sandmann@redhat.com> Sat Sep 24 00:01:42 2005 Soeren Sandmann <sandmann@redhat.com>
* Nakefile.am, sysprof-text.c: New non-GUI version, written * Nakefile.am, sysprof-text.c: New non-GUI version, written

View File

@ -1,6 +1,6 @@
AC_PREREQ(2.54) AC_PREREQ(2.54)
AC_INIT([sysprof], [1.0]) AC_INIT([sysprof], [1.1.0])
AC_CONFIG_SRCDIR(sysprof.glade) AC_CONFIG_SRCDIR(sysprof.glade)
AM_INIT_AUTOMAKE(no-define) AM_INIT_AUTOMAKE(no-define)

View File

@ -140,4 +140,4 @@ gboolean sfile_output_save (SFileOutput *sfile,
const char *filename, const char *filename,
GError **err); GError **err);
void sfile_output_free (SFileOutput *sfile); void sfile_output_free (SFileOutput *sfile);

View File

@ -27,48 +27,48 @@
typedef struct SignalWatch SignalWatch; typedef struct SignalWatch SignalWatch;
struct SignalWatch struct SignalWatch
{ {
int signo; int signo;
int pipe_read_end; SignalFunc handler;
int pipe_write_end; gpointer user_data;
struct sigaction old_action;
SignalFunc handler; int read_end;
gpointer user_data; int write_end;
struct sigaction old_action;
SignalWatch *next;
SignalWatch * next;
}; };
/* This is not a GHashTable because I don't trust g_hash_table_lookup()
* to be callable from a signal handler.
*/
static SignalWatch *signal_watches; static SignalWatch *signal_watches;
static SignalWatch * static SignalWatch *
lookup_watch (int signo) lookup_signal_watch (int signo)
{ {
SignalWatch *w; SignalWatch *w;
for (w = signal_watches; w != NULL; w = w->next) for (w = signal_watches; w != NULL; w = w->next)
{ {
if (w->signo == signo) if (w->signo == signo)
return w; return w;
} }
return NULL; return NULL;
} }
static void static void
add_watch (SignalWatch *watch) add_signal_watch (SignalWatch *watch)
{ {
g_return_if_fail (lookup_watch (watch->signo) == NULL); g_return_if_fail (lookup_signal_watch (watch->signo) == NULL);
watch->next = signal_watches; watch->next = signal_watches;
signal_watches = watch; signal_watches = watch;
} }
static void static void
remove_watch (SignalWatch *watch) remove_signal_watch (SignalWatch *watch)
{ {
/* it's either the first one in the list, or it is the ->next g_return_if_fail (watch != NULL);
/* It's either the first one in the list, or it is the ->next
* for some other watch * for some other watch
*/ */
if (watch == signal_watches) if (watch == signal_watches)
@ -79,7 +79,7 @@ remove_watch (SignalWatch *watch)
else else
{ {
SignalWatch *w; SignalWatch *w;
for (w = signal_watches; w && w->next; w = w->next) for (w = signal_watches; w && w->next; w = w->next)
{ {
if (watch == w->next) if (watch == w->next)
@ -93,13 +93,15 @@ remove_watch (SignalWatch *watch)
} }
static void static void
signal_handler (int signo, siginfo_t *info, void *data) signal_handler (int signo,
siginfo_t *info,
void *data)
{ {
SignalWatch *watch; SignalWatch *watch;
char x = 'x'; char x = 'x';
watch = lookup_watch (signo); watch = lookup_signal_watch (signo);
write (watch->pipe_write_end, &x, 1); write (watch->write_end, &x, 1);
} }
static void static void
@ -108,63 +110,105 @@ on_read (gpointer data)
SignalWatch *watch = data; SignalWatch *watch = data;
char x; char x;
read (watch->pipe_read_end, &x, 1); read (watch->read_end, &x, 1);
/* This is a callback to the application, so things like
* signal_unset_handler() can be called here.
*/
watch->handler (watch->signo, watch->user_data); watch->handler (watch->signo, watch->user_data);
} }
static void static gboolean
create_pipe (int *read_end, create_pipe (int *read_end,
int *write_end) int *write_end,
GError **err)
{ {
int p[2]; int p[2];
pipe (p); if (pipe (p) < 0)
{
/* FIXME - create an error */
return FALSE;
}
if (read_end) if (read_end)
*read_end = p[0]; *read_end = p[0];
if (write_end) if (write_end)
*write_end = p[1]; *write_end = p[1];
return TRUE;
}
static gboolean
install_signal_handler (int signo,
struct sigaction *old_action,
GError **err)
{
struct sigaction action;
memset (&action, 0, sizeof (action));
action.sa_sigaction = signal_handler;
sigemptyset (&action.sa_mask);
action.sa_flags = SA_SIGINFO;
if (sigaction (signo, &action, old_action) < 0)
{
/* FIXME - create an error */
return TRUE;
}
return TRUE;
} }
static void static void
install_signal_handler (int signo, struct sigaction *old_action) signal_watch_free (SignalWatch *watch)
{ {
struct sigaction action; fd_remove_watch (watch->read_end);
memset (&action, 0, sizeof (action)); close (watch->write_end);
close (watch->read_end);
action.sa_sigaction = signal_handler;
action.sa_flags = SA_SIGINFO; remove_signal_watch (watch);
sigaction (signo, &action, old_action); g_free (watch);
} }
gboolean gboolean
signal_set_handler (int signo, signal_set_handler (int signo,
SignalFunc handler, SignalFunc handler,
gpointer data, gpointer data,
GError **err) GError **err)
{ {
SignalWatch *watch; SignalWatch *watch;
int read_end, write_end;
g_return_val_if_fail (lookup_watch (signo) == NULL, FALSE); g_return_val_if_fail (lookup_signal_watch (signo) == NULL, FALSE);
if (!create_pipe (&read_end, &write_end, err))
return FALSE;
watch = g_new0 (SignalWatch, 1); watch = g_new0 (SignalWatch, 1);
create_pipe (&watch->pipe_read_end, &watch->pipe_write_end);
watch->signo = signo; watch->signo = signo;
watch->handler = handler; watch->handler = handler;
watch->user_data = data; watch->user_data = data;
watch->read_end = read_end;
add_watch (watch); watch->write_end = write_end;
fd_add_watch (watch->pipe_read_end, watch); fd_add_watch (watch->read_end, watch);
fd_set_read_callback (watch->pipe_read_end, on_read); fd_set_read_callback (watch->read_end, on_read);
install_signal_handler (signo, &watch->old_action); add_signal_watch (watch);
if (!install_signal_handler (signo, &watch->old_action, err))
{
signal_watch_free (watch);
return FALSE;
}
return TRUE; return TRUE;
} }
@ -173,18 +217,11 @@ signal_unset_handler (int signo)
{ {
SignalWatch *watch; SignalWatch *watch;
watch = lookup_watch (signo); watch = lookup_signal_watch (signo);
g_return_if_fail (watch != NULL); g_return_if_fail (watch != NULL);
sigaction (signo, &watch->old_action, NULL); sigaction (signo, &watch->old_action, NULL);
fd_remove_watch (watch->pipe_read_end);
close (watch->pipe_read_end); signal_watch_free (watch);
close (watch->pipe_write_end);
remove_watch (watch);
g_free (watch);
} }

View File

@ -178,5 +178,8 @@ main (int argc,
fd_set_read_callback (app->fd, on_read); fd_set_read_callback (app->fd, on_read);
g_main_loop_run (app->main_loop); g_main_loop_run (app->main_loop);
signal_unset_handler (SIGTERM);
signal_unset_handler (SIGINT);
return 0; return 0;
} }