mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
glib/tests/unix.c: Also test SIGTERM
We expect this to not kill the process, so it'd be a good one to test. https://bugzilla.gnome.org/show_bug.cgi?id=652072
This commit is contained in:
parent
c2364ce9a4
commit
b9c67b4369
@ -62,23 +62,23 @@ test_error (void)
|
|||||||
g_assert_error (error, G_UNIX_ERROR, 0);
|
g_assert_error (error, G_UNIX_ERROR, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean sighup_received = FALSE;
|
static gboolean sig_received = FALSE;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
on_sighup_received (gpointer user_data)
|
on_sig_received (gpointer user_data)
|
||||||
{
|
{
|
||||||
GMainLoop *loop = user_data;
|
GMainLoop *loop = user_data;
|
||||||
g_main_loop_quit (loop);
|
g_main_loop_quit (loop);
|
||||||
sighup_received = TRUE;
|
sig_received = TRUE;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
sighup_not_received (gpointer data)
|
sig_not_received (gpointer data)
|
||||||
{
|
{
|
||||||
GMainLoop *loop = data;
|
GMainLoop *loop = data;
|
||||||
(void) loop;
|
(void) loop;
|
||||||
g_error ("Timed out waiting for SIGHUP");
|
g_error ("Timed out waiting for signal");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,29 +91,42 @@ exit_mainloop (gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_sighup (void)
|
test_signal (int signum)
|
||||||
{
|
{
|
||||||
GMainLoop *mainloop;
|
GMainLoop *mainloop;
|
||||||
|
|
||||||
mainloop = g_main_loop_new (NULL, FALSE);
|
mainloop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
sighup_received = FALSE;
|
sig_received = FALSE;
|
||||||
g_unix_signal_add_watch_full (SIGHUP,
|
g_unix_signal_add_watch_full (signum,
|
||||||
G_PRIORITY_DEFAULT,
|
G_PRIORITY_DEFAULT,
|
||||||
on_sighup_received,
|
on_sig_received,
|
||||||
mainloop,
|
mainloop,
|
||||||
NULL);
|
NULL);
|
||||||
kill (getpid (), SIGHUP);
|
kill (getpid (), signum);
|
||||||
g_assert (!sighup_received);
|
g_assert (!sig_received);
|
||||||
g_timeout_add (5000, sighup_not_received, mainloop);
|
g_timeout_add (5000, sig_not_received, mainloop);
|
||||||
g_main_loop_run (mainloop);
|
g_main_loop_run (mainloop);
|
||||||
g_assert (sighup_received);
|
g_assert (sig_received);
|
||||||
sighup_received = FALSE;
|
sig_received = FALSE;
|
||||||
|
|
||||||
/* Ensure we don't get double delivery */
|
/* Ensure we don't get double delivery */
|
||||||
g_timeout_add (500, exit_mainloop, mainloop);
|
g_timeout_add (500, exit_mainloop, mainloop);
|
||||||
g_main_loop_run (mainloop);
|
g_main_loop_run (mainloop);
|
||||||
g_assert (!sighup_received);
|
g_assert (!sig_received);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_sighup (void)
|
||||||
|
{
|
||||||
|
test_signal (SIGHUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_sigterm (void)
|
||||||
|
{
|
||||||
|
test_signal (SIGTERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -124,15 +137,15 @@ test_sighup_add_remove (void)
|
|||||||
|
|
||||||
mainloop = g_main_loop_new (NULL, FALSE);
|
mainloop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
sighup_received = FALSE;
|
sig_received = FALSE;
|
||||||
id = g_unix_signal_add_watch_full (SIGHUP,
|
id = g_unix_signal_add_watch_full (SIGHUP,
|
||||||
G_PRIORITY_DEFAULT,
|
G_PRIORITY_DEFAULT,
|
||||||
on_sighup_received,
|
on_sig_received,
|
||||||
mainloop,
|
mainloop,
|
||||||
NULL);
|
NULL);
|
||||||
g_source_remove (id);
|
g_source_remove (id);
|
||||||
kill (getpid (), SIGHUP);
|
kill (getpid (), SIGHUP);
|
||||||
g_assert (!sighup_received);
|
g_assert (!sig_received);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +162,7 @@ main (int argc,
|
|||||||
g_test_add_func ("/glib-unix/pipe", test_pipe);
|
g_test_add_func ("/glib-unix/pipe", test_pipe);
|
||||||
g_test_add_func ("/glib-unix/error", test_error);
|
g_test_add_func ("/glib-unix/error", test_error);
|
||||||
g_test_add_func ("/glib-unix/sighup", test_sighup);
|
g_test_add_func ("/glib-unix/sighup", test_sighup);
|
||||||
|
g_test_add_func ("/glib-unix/sigterm", test_sigterm);
|
||||||
g_test_add_func ("/glib-unix/sighup_again", test_sighup);
|
g_test_add_func ("/glib-unix/sighup_again", test_sighup);
|
||||||
g_test_add_func ("/glib-unix/sighup_add_remove", test_sighup_add_remove);
|
g_test_add_func ("/glib-unix/sighup_add_remove", test_sighup_add_remove);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user