Skip to content
Snippets Groups Projects
Commit 123557b3 authored by Kamil Dudka's avatar Kamil Dudka
Browse files

unlink of non-existing log file is now a warning only

Closes #144
parent 7729fe20
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -98,8 +98,6 @@ static time_t nowSecs = 0;
static uid_t save_euid;
static gid_t save_egid;
 
static int shred_file(int fd, char *filename, struct logInfo *log);
static int globerr(const char *pathname, int theerr)
{
message(MESS_ERROR, "error accessing %s: %s\n", pathname,
Loading
Loading
@@ -585,7 +583,7 @@ static int shred_file(int fd, char *filename, struct logInfo *log)
}
 
if (!(log->flags & LOG_FLAG_SHRED)) {
return unlink(filename);
goto unlink_file;
}
 
message(MESS_DEBUG, "Using shred to remove the file %s\n", filename);
Loading
Loading
@@ -628,7 +626,17 @@ static int shred_file(int fd, char *filename, struct logInfo *log)
 
/* We have to unlink it after shred anyway,
* because it doesn't remove the file itself */
return unlink(filename);
unlink_file:
if (unlink(filename) == 0)
return 0;
if (errno != ENOENT)
return 1;
/* unlink of log file that no longer exists is not a fatal error */
message(MESS_ERROR, "error unlinking log file %s: %s\n", filename,
strerror(errno));
return 0;
}
 
static int removeLogFile(char *name, struct logInfo *log)
Loading
Loading
Loading
Loading
@@ -72,6 +72,7 @@ TEST_CASES = \
test-0071.sh \
test-0072.sh \
test-0073.sh \
test-0074.sh \
test-0100.sh \
test-0101.sh
 
Loading
Loading
#!/bin/bash
. ./test-common.sh
cleanup 74
# ------------------------------- Test 74 ------------------------------------
# unlink of log file that no longer exists should be handled as a warning only
# https://github.com/logrotate/logrotate/issues/144
preptest test.log 74 1
$RLR test-config.74 --verbose
checkoutput <<EOF
test.log 0
test.log.1 0 zero
EOF
&DIR&/test.log {
create
rotate 1
size 0
postrotate
rm -fv &DIR&/test.log.2
endscript
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment