Debian Codegraph @

src/cli/unix/sighandler.c

raw
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7
8 #include <stdint.h>
9 #include <signal.h>
10 #include "git2_util.h"
11 #include "common.h"
12 #include "sighandler.h"
13
14 static void (*interrupt_handler)(void) = NULL;
15
16 static void interrupt_proxy(int signal)
17 {
18 GIT_UNUSED(signal);
19 interrupt_handler();
20 }
21
22 int cli_sighandler_set_interrupt(void (*handler)(void))
23 {
24 void (*result)(int);
25
26 if ((interrupt_handler = handler) != NULL)
27 result = signal(SIGINT, interrupt_proxy);
28 else
29 result = signal(SIGINT, SIG_DFL);
30
31 if (result == SIG_ERR) {
32 git_error_set(GIT_ERROR_OS, "could not set signal handler");
33 return -1;
34 }
35
36 return 0;
37 }