user dir: rework err msgs

This commit is contained in:
Philippe Teuwen 2019-08-29 10:31:37 +02:00
parent fcd9b42dca
commit b10edbaddc
2 changed files with 6 additions and 3 deletions

View file

@ -104,7 +104,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) {
PrintAndLogEx(ERR, "could not create $HOME/" PROXHISTORY ", no history will be recorded");
PrintAndLogEx(ERR, "No history will be recorded");
my_history_path = NULL;
} else {
read_history(my_history_path);

View file

@ -50,8 +50,10 @@ int searchHomeFilePath(char **foundpath, const char *filename, bool create_home)
if (foundpath == NULL)
return PM3_EINVARG;
char *user_path = getenv("HOME");
if (user_path == NULL)
if (user_path == NULL) {
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));
if (path == NULL)
return PM3_EMALLOC;
@ -80,6 +82,7 @@ int searchHomeFilePath(char **foundpath, const char *filename, bool create_home)
#else
if (mkdir(path, 0700)) {
#endif
fprintf(stderr, "Could not create user directory %s\n", path);
free(path);
return PM3_EFILE;
}
@ -228,7 +231,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
timenow = gmtime(&now);
strftime(filename, sizeof(filename), PROXLOG, timenow);
if (searchHomeFilePath(&my_logfile_path, filename, true) != PM3_SUCCESS) {
fprintf(stderr, "Could not create $HOME" PM3_USER_DIRECTORY "%s, no log will be recorded\n", filename);
fprintf(stderr, "Logging disabled!\n\n");
my_logfile_path = NULL;
logging = 0;
} else {