Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Attempt to create log file if it does not exist. #1322

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Escape after the last slash, otherwise a directory will be created wh…
…ile we want a file.
  • Loading branch information
userwiths committed Jul 29, 2024
commit 76a31a261a684c005926fb46db4615beb8a7a8a9
4 changes: 3 additions & 1 deletion common/output.c
Original file line number Diff line number Diff line change
@@ -350,6 +350,9 @@ int logg(loglevel_t loglevel, const char *str, ...)
current_dir = (char*)realloc(current_dir, strlen(current_dir) + strlen(token) + 2);
strcat(current_dir, token);
token = strtok(NULL, "/");
if(token == NULL) {
break;
}
if(LSTAT(current_dir, &sb) == -1) {
if(mkdir(current_dir, 0755) == -1) {
printf("ERROR: Failed to create required directory %s. Will continue without writing in %s.\n", current_dir, logg_file);
@@ -360,7 +363,6 @@ int logg(loglevel_t loglevel, const char *str, ...)
}
strcat(current_dir, "/");
}
//create file
if ((logg_fp = fopen(logg_file, "at")) == NULL) {
printf("ERROR: Can't open %s in append mode (check permissions!).\n", logg_file);
free(current_dir);