You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gentoo-overlay/app-admin/logrotate/files/logrotate-3.8.3-atomic-crea...

47 lines
1.4 KiB

diff -Nur a/logrotate.c b/logrotate.c
--- a/logrotate.c 2012-10-04 09:59:14.000000000 +0200
+++ b/logrotate.c 2012-11-11 12:04:19.530008151 +0100
@@ -296,16 +296,22 @@
int createOutputFile(char *fileName, int flags, struct stat *sb, acl_type acl, int force_mode)
{
int fd;
- struct stat sb_create;
-
- fd = open(fileName, (flags | O_EXCL | O_NOFOLLOW),
- (S_IRUSR | S_IWUSR) & sb->st_mode);
+ struct stat sb_create;
+ char template[PATH_MAX + 1];
+ char *fname;
+ mode_t umask_value;
+ snprintf(template, PATH_MAX, "%s/logrotate_temp.XXXXXX", ourDirName(fileName));
+ umask_value = umask(0000);
+ fname = mktemp(template);
+ fd = open(fname, (flags | O_EXCL | O_NOFOLLOW), (S_IRUSR | S_IWUSR) & sb->st_mode);
+ umask(umask_value);
if (fd < 0) {
- message(MESS_ERROR, "error creating output file %s: %s\n",
- fileName, strerror(errno));
+ message(MESS_ERROR, "error creating unique temp file: %s\n",
+ strerror(errno));
return -1;
}
+
if (fchmod(fd, (S_IRUSR | S_IWUSR) & sb->st_mode)) {
message(MESS_ERROR, "error setting mode of %s: %s\n",
fileName, strerror(errno));
@@ -347,6 +353,13 @@
}
#endif
+ if (rename(template, fileName)) {
+ message(MESS_ERROR, "error renaming temp file to %s: %s\n",
+ fileName, strerror(errno));
+ close(fd);
+ return -1;
+ }
+
return fd;
}