summaryrefslogtreecommitdiffstats
path: root/src/testdisk.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testdisk.c')
-rw-r--r--src/testdisk.c64
1 files changed, 33 insertions, 31 deletions
diff --git a/src/testdisk.c b/src/testdisk.c
index 891833a..8d2f5ba 100644
--- a/src/testdisk.c
+++ b/src/testdisk.c
@@ -23,6 +23,13 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP) || !defined(HAVE_GETEUID)
+#undef SUDO_BIN
+#endif
+
+#if defined(__FRAMAC__)
+#undef HAVE_LIBEWF
+#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
@@ -43,9 +50,7 @@
#include "types.h"
#include "common.h"
#include "intrf.h"
-#ifdef HAVE_NCURSES
#include "intrfn.h"
-#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -69,19 +74,26 @@
#include "hidden.h"
#ifdef HAVE_SIGACTION
+int need_to_stop=0;
static struct sigaction action;
-static void sighup_hdlr(int sig);
static void sighup_hdlr(int sig)
{
if(sig == SIGINT)
- log_critical("SIGINT detected! TestDisk has been killed.\n");
+ log_critical("SIGINT detected! PhotoRec has been killed.\n");
+ else if(sig == SIGHUP)
+ log_critical("SIGHUP detected! PhotoRec has been killed.\n");
else
- log_critical("SIGHUP detected! TestDisk has been killed.\n");
+ 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
@@ -136,15 +148,12 @@ static int display_disk_list(list_disk_t *list_disk, const int testdisk_mode,
if(list_disk==NULL)
{
printf("No disk detected.\n");
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP)
-#else
-#ifdef HAVE_GETEUID
+#if defined(HAVE_GETEUID) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(DJGPP)
if(geteuid()!=0)
{
printf("You need to be root to use TestDisk.\n");
}
#endif
-#endif
return 1;
}
@@ -231,14 +240,12 @@ 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)
- {
- printf("Error on SIGACTION call\n");
- return -1;
- }
- if(sigaction(SIGHUP, &action, NULL)==-1)
+ if( sigaction(SIGINT, &action, NULL)==-1 ||
+ sigaction(SIGHUP, &action, NULL)==-1 ||
+ sigaction(SIGTERM, &action, NULL)==-1 )
{
printf("Error on SIGACTION call\n");
return -1;
@@ -259,6 +266,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)
@@ -413,15 +424,12 @@ int main( int argc, char **argv )
#endif
log_info("ext2fs lib: %s, ntfs lib: %s, reiserfs lib: %s, ewf lib: %s, curses lib: %s\n",
td_ext2fs_version(), td_ntfs_version(), td_reiserfs_version(), td_ewf_version(), td_curses_version());
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(DJGPP)
-#else
-#ifdef HAVE_GETEUID
+#if defined(HAVE_GETEUID) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(DJGPP)
if(geteuid()!=0)
{
log_warning("User is not root!\n");
}
#endif
-#endif
log_flush();
#ifdef HAVE_NCURSES
aff_copy(stdscr);
@@ -447,15 +455,9 @@ int main( int argc, char **argv )
hd_update_all_geometry(list_disk, verbose);
log_disk_list(list_disk);
#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)
use_sudo=do_curses_testdisk(verbose,dump_ind,list_disk,saveheader,cmd_device,&cmd_run);
@@ -515,7 +517,7 @@ int main( int argc, char **argv )
printf("TestDisk 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
return 0;