#include "http-client.h"
#include <unistd.h>
+#include <sys/signal.h>
#define CLIENT_PROGRESS_TIMEOUT 10
#define SERVER_KILL_TIMEOUT_SECS 20
{
i_close_fd(&fd_listen);
- test_subprocess_notify_signal_send_parent();
+ test_subprocess_notify_signal_send_parent(SIGUSR1);
}
/* client */
struct _connection_refused *ctx;
/* wait for the server side to close the socket */
- test_subprocess_notify_signal_wait(10000);
+ test_subprocess_notify_signal_wait(SIGUSR1, 10000);
ctx = i_new(struct _connection_refused, 1);
ctx->count = 2;
{
unsigned int i;
- test_subprocess_notify_signal_reset();
+ test_subprocess_notify_signal_reset(SIGHUP);
test_server_init = NULL;
test_server_deinit = NULL;
test_server_input = NULL;
volatile sig_atomic_t test_subprocess_is_child = 0;
static bool test_subprocess_lib_init = FALSE;
-static volatile bool test_subprocess_notification_signal_received = FALSE;
+static volatile bool test_subprocess_notification_signal_received[SIGUSR1 + 1];
static struct event *test_subprocess_event = NULL;
static ARRAY(struct test_subprocess *) test_subprocesses = ARRAY_INIT;
static void (*test_subprocess_cleanup_callback)(void) = NULL;
test_subprocess_cleanup_callback = callback;
}
-void test_subprocess_notify_signal_send(pid_t pid)
+void test_subprocess_notify_signal_send(int signo, pid_t pid)
{
- if (kill(pid, SIGHUP) < 0)
+ if (kill(pid, signo) < 0)
i_fatal("kill(%ld, SIGHUP) failed: %m", (long)pid);
}
-void test_subprocess_notify_signal_send_parent(void)
+void test_subprocess_notify_signal_send_parent(int signo)
{
- test_subprocess_notify_signal_send(getppid());
+ test_subprocess_notify_signal_send(signo, getppid());
}
-void test_subprocess_notify_signal_reset(void)
+void test_subprocess_notify_signal_reset(int signo)
{
- test_subprocess_notification_signal_received = FALSE;
+ i_assert(signo >= 0 &&
+ (unsigned int)signo < N_ELEMENTS(test_subprocess_notification_signal_received));
+ test_subprocess_notification_signal_received[signo] = FALSE;
}
-void test_subprocess_notify_signal_wait(unsigned int timeout_msecs)
+void test_subprocess_notify_signal_wait(int signo, unsigned int timeout_msecs)
{
unsigned int i, count = timeout_msecs / 10;
for (i = 0; i < count; i++) {
- if (test_subprocess_notification_signal_received)
+ if (test_subprocess_notification_signal_received[signo])
return;
i_sleep_msecs(10);
}
}
static void
-test_subprocess_notification_signal(const siginfo_t *si ATTR_UNUSED,
+test_subprocess_notification_signal(const siginfo_t *si,
void *context ATTR_UNUSED)
{
- test_subprocess_notification_signal_received = TRUE;
+ int signo = si->si_signo;
+
+ i_assert(signo >= 0 &&
+ (unsigned int)signo < N_ELEMENTS(test_subprocess_notification_signal_received));
+ test_subprocess_notification_signal_received[signo] = TRUE;
}
void test_subprocesses_init(bool debug)
lib_signals_set_handler(SIGABRT, 0, test_subprocess_terminate, NULL);
lib_signals_set_handler(SIGHUP, LIBSIG_FLAG_RESTART,
test_subprocess_notification_signal, NULL);
+ lib_signals_set_handler(SIGUSR1, LIBSIG_FLAG_RESTART,
+ test_subprocess_notification_signal, NULL);
i_array_init(&test_subprocesses, 8);
void test_subprocess_set_cleanup_callback(void (*callback)(void));
/* Send a notification signal (SIGHUP) to the given PID */
-void test_subprocess_notify_signal_send(pid_t pid);
+void test_subprocess_notify_signal_send(int signo, pid_t pid);
/* Send a notificatino signal to the parent process. */
-void test_subprocess_notify_signal_send_parent(void);
+void test_subprocess_notify_signal_send_parent(int signo);
/* Reset any previously sent notification signals. */
-void test_subprocess_notify_signal_reset(void);
+void test_subprocess_notify_signal_reset(int signo);
/* Wait until a notification signal is sent, or return immediately if it was
already sent. test_subprocess_notify_signal_reset() should be called before
this to make sure it's not returning due to a previously sent signal.
If the timeout is reached, i_fatal() is called. */
-void test_subprocess_notify_signal_wait(unsigned int timeout_msecs);
+void test_subprocess_notify_signal_wait(int signo, unsigned int timeout_msecs);
void test_subprocesses_init(bool debug);
void test_subprocesses_deinit(void);