mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
Put logfiles in subdir
This commit is contained in:
parent
f54f8103ac
commit
a6f76444de
5 changed files with 46 additions and 7 deletions
|
@ -32,7 +32,7 @@ static int setCmdHelp(const char *Cmd);
|
|||
static char *prefGetFilename(void) {
|
||||
char *path;
|
||||
|
||||
if (searchHomeFilePath(&path, preferencesFilename, false) == PM3_SUCCESS)
|
||||
if (searchHomeFilePath(&path, NULL, preferencesFilename, false) == PM3_SUCCESS)
|
||||
return path;
|
||||
else
|
||||
return strdup(preferencesFilename);
|
||||
|
|
|
@ -206,7 +206,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
|
|||
}
|
||||
|
||||
char *my_history_path = NULL;
|
||||
if (searchHomeFilePath(&my_history_path, PROXHISTORY, true) != PM3_SUCCESS) {
|
||||
if (searchHomeFilePath(&my_history_path, NULL, PROXHISTORY, true) != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "No history will be recorded");
|
||||
my_history_path = NULL;
|
||||
} else {
|
||||
|
|
|
@ -54,7 +54,7 @@ pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER;
|
|||
static void fPrintAndLog(FILE *stream, const char *fmt, ...);
|
||||
|
||||
// needed by flasher, so let's put it here instead of fileutils.c
|
||||
int searchHomeFilePath(char **foundpath, const char *filename, bool create_home) {
|
||||
int searchHomeFilePath(char **foundpath, const char *subdir, const char *filename, bool create_home) {
|
||||
if (foundpath == NULL)
|
||||
return PM3_EINVARG;
|
||||
const char *user_path = get_my_user_directory();
|
||||
|
@ -62,7 +62,8 @@ int searchHomeFilePath(char **foundpath, const char *filename, bool create_home)
|
|||
fprintf(stderr, "Could not retrieve $HOME from the environment\n");
|
||||
return PM3_EFILE;
|
||||
}
|
||||
char *path = calloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + 1, sizeof(char));
|
||||
size_t pathlen = strlen(user_path) + strlen(PM3_USER_DIRECTORY) + 1;
|
||||
char *path = calloc(pathlen, sizeof(char));
|
||||
if (path == NULL)
|
||||
return PM3_EMALLOC;
|
||||
strcpy(path, user_path);
|
||||
|
@ -96,11 +97,48 @@ int searchHomeFilePath(char **foundpath, const char *filename, bool create_home)
|
|||
return PM3_EFILE;
|
||||
}
|
||||
}
|
||||
if (subdir != NULL) {
|
||||
pathlen += strlen(subdir);
|
||||
path = realloc(path, pathlen * sizeof(char));
|
||||
if (path == NULL)
|
||||
return PM3_EMALLOC;
|
||||
strcat(path, subdir);
|
||||
|
||||
#ifdef _WIN32
|
||||
// Mingw _stat fails if path ends with /, so let's use a stripped path
|
||||
if (path[strlen(path) - 1] == '/') {
|
||||
path[strlen(path) - 1] = '\0';
|
||||
result = _stat(path, &st);
|
||||
path[strlen(path)] = '/';
|
||||
} else {
|
||||
result = _stat(path, &st);
|
||||
}
|
||||
#else
|
||||
result = stat(path, &st);
|
||||
#endif
|
||||
if ((result != 0) && create_home) {
|
||||
|
||||
#ifdef _WIN32
|
||||
if (_mkdir(path))
|
||||
#else
|
||||
if (mkdir(path, 0700))
|
||||
#endif
|
||||
{
|
||||
fprintf(stderr, "Could not create user directory %s\n", path);
|
||||
free(path);
|
||||
return PM3_EFILE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (filename == NULL) {
|
||||
*foundpath = path;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
path = realloc(path, (strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(filename) + 1) * sizeof(char));
|
||||
pathlen += strlen(filename);
|
||||
path = realloc(path, pathlen * sizeof(char));
|
||||
if (path == NULL)
|
||||
return PM3_EMALLOC;
|
||||
strcat(path, filename);
|
||||
*foundpath = path;
|
||||
return PM3_SUCCESS;
|
||||
|
@ -266,7 +304,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
|
|||
time_t now = time(NULL);
|
||||
timenow = gmtime(&now);
|
||||
strftime(filename, sizeof(filename), PROXLOG, timenow);
|
||||
if (searchHomeFilePath(&my_logfile_path, filename, true) != PM3_SUCCESS) {
|
||||
if (searchHomeFilePath(&my_logfile_path, LOGS_SUBDIR, filename, true) != PM3_SUCCESS) {
|
||||
fprintf(stderr, "[-] Logging disabled!\n\n");
|
||||
my_logfile_path = NULL;
|
||||
logging = 0;
|
||||
|
|
|
@ -59,7 +59,7 @@ void memcpy_filter_ansi(void *dest, const void *src, size_t n, bool filter);
|
|||
void memcpy_filter_rlmarkers(void *dest, const void *src, size_t n);
|
||||
void memcpy_filter_emoji(void *dest, const void *src, size_t n, emojiMode_t mode);
|
||||
|
||||
int searchHomeFilePath(char **foundpath, const char *filename, bool create_home);
|
||||
int searchHomeFilePath(char **foundpath, const char *subdir, const char *filename, bool create_home);
|
||||
|
||||
extern pthread_mutex_t print_lock;
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#define LUA_SCRIPTS_SUBDIR "luascripts" PATHSEP
|
||||
#define RESOURCES_SUBDIR "resources" PATHSEP
|
||||
#define TRACES_SUBDIR "traces" PATHSEP
|
||||
#define LOGS_SUBDIR "logs" PATHSEP
|
||||
#define FIRMWARES_SUBDIR "firmware" PATHSEP
|
||||
#define BOOTROM_SUBDIR "bootrom" PATHSEP "obj" PATHSEP
|
||||
#define FULLIMAGE_SUBDIR "armsrc" PATHSEP "obj" PATHSEP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue