summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/fat_unformat.c9
-rw-r--r--src/phbf.c3
-rw-r--r--src/phbs.c6
-rw-r--r--src/phmain.c22
-rw-r--r--src/phrecn.c6
-rw-r--r--src/psearchn.c3
6 files changed, 43 insertions, 6 deletions
diff --git a/src/fat_unformat.c b/src/fat_unformat.c
index 4cf6a83..a31883c 100644
--- a/src/fat_unformat.c
+++ b/src/fat_unformat.c
@@ -55,6 +55,8 @@
#include "fat_common.h"
#include <assert.h>
+extern int need_to_stop;
+
#define READ_SIZE 4*1024*1024
static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const int verbose, unsigned int *sectors_per_cluster, uint64_t *offset_org, alloc_data_t *list_search_space)
{
@@ -386,6 +388,13 @@ static pstatus_t fat_unformat_aux(struct ph_param *params, const struct ph_optio
}
}
#endif
+ if(need_to_stop!=0)
+ {
+ log_info("PhotoRec has been stopped\n");
+ params->offset=offset;
+ offset = offset_end;
+ ind_stop=PSTATUS_STOP;
+ }
}
}
free(buffer_start);
diff --git a/src/phbf.c b/src/phbf.c
index 523abe4..f5e1103 100644
--- a/src/phbf.c
+++ b/src/phbf.c
@@ -76,6 +76,7 @@
#define READ_SIZE 1024*512
extern file_check_list_t file_check_list;
extern uint64_t free_list_allocation_end;
+extern int need_to_stop;
typedef enum { BF_OK=0, BF_STOP=1, BF_EACCES=2, BF_ENOSPC=3, BF_FRAG_FOUND=4, BF_EOF=5, BF_ENOENT=6, BF_ERANGE=7} bf_status_t;
@@ -643,6 +644,8 @@ static bf_status_t photorec_bf_frag(struct ph_param *params, file_recovery_t *fi
ind_stop=photorec_progressbar(stdscr, testbf, params,
file_recovery->location.start, current_time);
#endif
+ if(need_to_stop!=0)
+ ind_stop=PSTATUS_STOP;
if(ind_stop!=PSTATUS_OK)
{
file_recovery->flags=0;
diff --git a/src/phbs.c b/src/phbs.c
index 9ce2d0d..dbc63d5 100644
--- a/src/phbs.c
+++ b/src/phbs.c
@@ -56,6 +56,7 @@
#define READ_SIZE 1024*512
extern const file_hint_t file_hint_tar;
extern file_check_list_t file_check_list;
+extern int need_to_stop;
static inline void file_recovery_cpy(file_recovery_t *dst, file_recovery_t *src)
{
@@ -203,6 +204,11 @@ pstatus_t photorec_find_blocksize(struct ph_param *params, const struct ph_optio
}
}
#endif
+ if(need_to_stop!=0)
+ {
+ log_info("PhotoRec has been stopped\n");
+ current_search_space=list_search_space;
+ }
}
} /* end while(current_search_space!=list_search_space) */
free(buffer_start);
diff --git a/src/phmain.c b/src/phmain.c
index 0949376..2205ceb 100644
--- a/src/phmain.c
+++ b/src/phmain.c
@@ -77,6 +77,7 @@
#include "pdiskseln.h"
#include "dfxml.h"
+int need_to_stop=0;
extern file_enable_t list_file_enable[];
#ifdef HAVE_SIGACTION
@@ -87,12 +88,19 @@ static void sighup_hdlr(int sig)
{
if(sig == SIGINT)
log_critical("SIGINT detected! PhotoRec has been killed.\n");
- else
+ else if(sig == SIGHUP)
log_critical("SIGHUP detected! PhotoRec has been killed.\n");
+ else
+ log_critical("SIGTERM detected! PhotoRec has been killed.\n");
log_flush();
- action.sa_handler=SIG_DFL;
- sigaction(sig,&action,NULL);
- kill(0, sig);
+ if(need_to_stop==1)
+ {
+ action.sa_handler=SIG_DFL;
+ sigaction(sig,&action,NULL);
+ kill(0, sig);
+ return ;
+ }
+ need_to_stop=1;
}
#endif
@@ -156,6 +164,7 @@ int main( int argc, char **argv )
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGINT);
sigaddset(&action.sa_mask, SIGHUP);
+ sigaddset(&action.sa_mask, SIGTERM);
action.sa_handler = &sighup_hdlr;
action.sa_flags = 0;
if(sigaction(SIGINT, &action, NULL)==-1)
@@ -168,6 +177,11 @@ int main( int argc, char **argv )
printf("Error on SIGACTION call\n");
return -1;
}
+ if(sigaction(SIGTERM, &action, NULL)==-1)
+ {
+ printf("Error on SIGACTION call\n");
+ return -1;
+ }
#endif
printf("PhotoRec %s, Data Recovery Utility, %s\nChristophe GRENIER <grenier@cgsecurity.org>\nhttps://www.cgsecurity.org\n",VERSION,TESTDISKDATE);
for(i=1;i<argc;i++)
diff --git a/src/phrecn.c b/src/phrecn.c
index 5599078..972de61 100644
--- a/src/phrecn.c
+++ b/src/phrecn.c
@@ -85,6 +85,7 @@
#define DEFAULT_IMAGE_NAME "image_remaining.dd"
extern file_check_list_t file_check_list;
+extern int need_to_stop;
static int interface_cannot_create_file(void);
@@ -347,7 +348,8 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
break;
}
session_save(list_search_space, params, options);
-
+ if(need_to_stop!=0)
+ ind_stop=PSTATUS_STOP;
switch(ind_stop)
{
case PSTATUS_ENOSPC:
@@ -400,7 +402,7 @@ int photorec(struct ph_param *params, const struct ph_options *options, alloc_da
{
log_flush();
#ifdef HAVE_NCURSES
- if(ask_confirmation("Answer Y to really Quit, N to resume the recovery")!=0)
+ if(need_to_stop!=0 || ask_confirmation("Answer Y to really Quit, N to resume the recovery")!=0)
#endif
params->status=STATUS_QUIT;
}
diff --git a/src/psearchn.c b/src/psearchn.c
index 553d050..70e50de 100644
--- a/src/psearchn.c
+++ b/src/psearchn.c
@@ -70,6 +70,7 @@
#include "psearchn.h"
#include "photorec_check_header.h"
#define READ_SIZE 1024*512
+extern int need_to_stop;
pstatus_t photorec_aux(struct ph_param *params, const struct ph_options *options, alloc_data_t *list_search_space)
{
@@ -282,6 +283,8 @@ pstatus_t photorec_aux(struct ph_param *params, const struct ph_options *options
#ifdef HAVE_NCURSES
ind_stop=photorec_progressbar(stdscr, params->pass, params, offset, current_time);
#endif
+ if(need_to_stop!=0)
+ ind_stop=PSTATUS_STOP;
params->offset=offset;
if(ind_stop!=PSTATUS_OK)
{