#include <stdio.h>
#include <string.h>
#include <fcntl.h>
+#include <signal.h>
/* #include ELFUTILS_HEADER(dwfl) */
#include "../libdwfl/libdwflP.h"
/* XXX: Private header needed for sysprof_find_procfile, sysprof_init_dwfl. */
static char *output_path = NULL;
static int output_fd = -1;
+static int signal_count = 0;
+
#define MODE_OPTS "none/passthru/naive"
#define MODE_NONE 0x0
#define MODE_PASSTHRU 0x1
#endif /* HAVE_SYSPROF_HEADERS */
+/* Required to match our signal handling with that of a sysprof parent process. */
+static void sigint_handler (int /* signo */)
+{
+ if (signal_count >= 2)
+ {
+ exit(1);
+ }
+
+ if (signal_count == 0)
+ {
+ fprintf (stderr, "%s\n", "Waiting for input to finish. Press twice more ^C to force exit.");
+ }
+
+ signal_count ++;
+}
+
/* Main program. */
static error_t
if (output_fd < 0)
error (EXIT_BAD, errno, N_("Cannot open output file or FIFO '%s'"), output_path);
+ /* TODO: Only really needed if launched from sysprof and inheriting its signals. */
+ if (signal (SIGINT, sigint_handler) == SIG_ERR)
+ error (EXIT_BAD, errno, N_("Cannot set signal handler for SIGINT"));
#if !(HAVE_SYSPROF_HEADERS)
/* TODO: Should hide corresponding command line options when this is the case. */
error (EXIT_BAD, 0, N_("Sysprof support is not available in this version."));