summaryrefslogtreecommitdiffstats
path: root/src/phmain.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2009-04-18 18:12:40 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2009-04-18 18:12:40 +0200
commit77d476a5ca79f234b5d9840fe83be9637ce94f53 (patch)
treea7cb1a394881a9524839dccbf53fdfb02e8ca0f6 /src/phmain.c
parenta6c4be00b5500f7faf833872755f6861d3f13378 (diff)
Handle Ctrl+C
Diffstat (limited to 'src/phmain.c')
-rw-r--r--src/phmain.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/phmain.c b/src/phmain.c
index 1df9731..ed88174 100644
--- a/src/phmain.c
+++ b/src/phmain.c
@@ -85,6 +85,23 @@ extern const arch_fnct_t arch_sun;
extern const arch_fnct_t arch_xbox;
extern file_enable_t list_file_enable[];
+#ifdef HAVE_SIGACTION
+struct sigaction action;
+void sighup_hdlr(int sig);
+
+void sighup_hdlr(int sig)
+{
+ if(sig == SIGINT)
+ log_critical("SIGINT detected! PhotoRec has been killed.\n");
+ else
+ log_critical("SIGHUP detected! PhotoRec has been killed.\n");
+ log_flush();
+ action.sa_handler=SIG_DFL;
+ sigaction(sig,&action,NULL);
+ kill(0, sig);
+}
+#endif
+
int main( int argc, char **argv )
{
int i;
@@ -106,17 +123,22 @@ int main( int argc, char **argv )
#else
const arch_fnct_t *arch=&arch_i386;
#endif
-#ifdef HAVE_SIGACTION
- struct sigaction action, old_action;
-#endif
FILE *log_handle=NULL;
/* random (weak is ok) is need fot GPT */
srand(time(NULL));
#ifdef HAVE_SIGACTION
- /* set up the signal handler for SIGHUP */
+ /* set up the signal handler for SIGINT & SIGHUP */
+ sigemptyset(&action.sa_mask);
+ sigaddset(&action.sa_mask, SIGINT);
+ sigaddset(&action.sa_mask, SIGHUP);
action.sa_handler = sighup_hdlr;
action.sa_flags = 0;
- if(sigaction(SIGHUP, &action, &old_action)==-1)
+ if(sigaction(SIGINT, &action, NULL)==-1)
+ {
+ printf("Error on SIGACTION call\n");
+ return -1;
+ }
+ if(sigaction(SIGHUP, &action, NULL)==-1)
{
printf("Error on SIGACTION call\n");
return -1;