summaryrefslogtreecommitdiffstats
path: root/src/phmain.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/phmain.c')
-rw-r--r--src/phmain.c72
1 files changed, 49 insertions, 23 deletions
diff --git a/src/phmain.c b/src/phmain.c
index 6a9c382..943b153 100644
--- a/src/phmain.c
+++ b/src/phmain.c
@@ -24,6 +24,15 @@
#include <config.h>
#endif
+#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP) || !defined(HAVE_GETEUID)
+#undef SUDO_BIN
+#endif
+
+#if defined(__FRAMAC__) || defined(MAIN_photorec)
+#undef HAVE_DUP2
+#undef HAVE_LIBEWF
+#endif
+
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
@@ -77,7 +86,8 @@
#include "pdiskseln.h"
#include "dfxml.h"
-extern file_enable_t list_file_enable[];
+int need_to_stop=0;
+extern file_enable_t array_file_enable[];
#ifdef HAVE_SIGACTION
static struct sigaction action;
@@ -87,12 +97,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
@@ -125,7 +142,7 @@ int main( int argc, char **argv )
{
int i;
#ifdef SUDO_BIN
- int use_sudo=0;
+ int use_sudo;
#endif
int create_log=TD_LOG_NONE;
int run_setlocale=1;
@@ -142,7 +159,7 @@ int main( int argc, char **argv )
.expert=0,
.lowmem=0,
.verbose=0,
- .list_file_format=list_file_enable
+ .list_file_format=array_file_enable
};
struct ph_param params;
params.recup_dir=NULL;
@@ -156,6 +173,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 +186,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++)
@@ -182,6 +205,10 @@ int main( int argc, char **argv )
}
logfile=argv[++i];
}
+ else if((strcmp(argv[i],"/nolog")==0) ||(strcmp(argv[i],"-nolog")==0))
+ {
+ create_log=TD_LOG_NONE;
+ }
else if((strcmp(argv[i],"/log")==0) ||(strcmp(argv[i],"-log")==0))
{
if(create_log==TD_LOG_NONE)
@@ -227,6 +254,10 @@ int main( int argc, char **argv )
}
else if((strcmp(argv[i],"/nosetlocale")==0) || (strcmp(argv[i],"-nosetlocale")==0))
run_setlocale=0;
+ else if(i+1 <= argc && strcmp(argv[i],"/cmd")==0 && strcmp(argv[i+1],"resume")==0)
+ {
+ params.cmd_device=argv[++i];
+ }
else if(strcmp(argv[i],"/cmd")==0)
{
if(i+2>=argc)
@@ -309,7 +340,7 @@ int main( int argc, char **argv )
if(log_handle!=NULL)
{
time_t my_time;
-#ifdef HAVE_DUP2
+#if defined(HAVE_DUP2)
dup2(fileno(log_handle),2);
#endif
my_time=time(NULL);
@@ -325,17 +356,16 @@ int main( int argc, char **argv )
#ifdef RECORD_COMPILATION_DATE
log_info("Compilation date: %s\n", get_compilation_date());
#endif
+#ifndef MAIN_photorec
log_info("ext2fs lib: %s, ntfs lib: %s, ewf lib: %s, libjpeg: %s, curses lib: %s\n",
td_ext2fs_version(), td_ntfs_version(), td_ewf_version(), td_jpeg_version(), td_curses_version());
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP)
-#else
-#ifdef HAVE_GETEUID
+#endif
+#if defined(HAVE_GETEUID) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(DJGPP)
if(geteuid()!=0)
{
log_warning("User is not root!\n");
}
#endif
-#endif
log_flush();
screen_buffer_reset();
/* Scan for available device only if no device or image has been supplied in parameter */
@@ -348,21 +378,17 @@ int main( int argc, char **argv )
element_disk->disk=new_diskcache(element_disk->disk, testdisk_mode);
}
log_disk_list(list_disk);
- reset_list_file_enable(options.list_file_format);
+ reset_array_file_enable(options.list_file_format);
file_options_load(options.list_file_format);
#ifdef SUDO_BIN
- if(list_disk==NULL)
+ if(list_disk==NULL && geteuid()!=0)
{
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP)
-#else
-#ifdef HAVE_GETEUID
- if(geteuid()!=0)
- use_sudo=2;
-#endif
-#endif
+ use_sudo=2;
}
- if(use_sudo==0)
+ else
+ {
use_sudo=do_curses_photorec(&params, &options, list_disk);
+ }
#else
do_curses_photorec(&params, &options, list_disk);
#endif
@@ -387,7 +413,7 @@ int main( int argc, char **argv )
printf("PhotoRec will try to restart itself using the sudo command to get\n");
printf("root (superuser) privileges.\n");
printf("\n");
- run_sudo(argc, argv);
+ run_sudo(argc, argv, create_log);
}
#endif
delete_list_disk(list_disk);