integ/logging/logrotate/centos/patches/0001-createOutputFile-rename-already-existing-file.patch
Scott Little bab9bb6b69 Internal restructuring of stx-integ
Create new directories:
   ceph
   config
   config-files
   filesystem
   kernel
   kernel/kernel-modules
   ldap
   logging
   strorage-drivers
   tools
   utilities
   virt

Retire directories:
   connectivity
   core
   devtools
   support
   extended

Delete two packages:
   tgt
   irqbalance

Relocated packages:
   base/
      dhcp
      initscripts
      libevent
      lighttpd
      linuxptp
      memcached
      net-snmp
      novnc
      ntp
      openssh
      pam
      procps
      sanlock
      shadow
      sudo
      systemd
      util-linux
      vim
      watchdog

   ceph/
      python-cephclient

   config/
      facter
      puppet-4.8.2
      puppet-modules

   filesystem/
      e2fsprogs
      nfs-utils
      nfscheck

   kernel/
      kernel-std
      kernel-rt

   kernel/kernel-modules/
      mlnx-ofa_kernel

   ldap/
      nss-pam-ldapd
      openldap

   logging/
      syslog-ng
      logrotate

   networking/
      lldpd
      iproute
      mellanox
      python-ryu
      mlx4-config

   python/
      python-2.7.5
      python-django
      python-gunicorn
      python-setuptools
      python-smartpm
      python-voluptuous

   security/
      shim-signed
      shim-unsigned
      tboot

   strorage-drivers/
      python-3parclient
      python-lefthandclient

   virt/
      cloud-init
      libvirt
      libvirt-python
      qemu

   tools/
      storage-topology
      vm-topology

   utilities/
      tis-extensions
      namespace-utils
      nova-utils
      update-motd

Change-Id: I37ade764d873c701b35eac5881eb40412ba64a86
Story: 2002801
Task: 22687
Signed-off-by: Scott Little <scott.little@windriver.com>
2018-08-01 10:06:31 -04:00

105 lines
2.8 KiB
Diff

From e43ef5ea3ba1faffad5af528d37ac910e5c0407f Mon Sep 17 00:00:00 2001
From: Don Penney <don.penney@windriver.com>
Date: Fri, 19 Jan 2018 23:17:55 -0500
Subject: [PATCH] createOutputFile: rename already existing file
Upstream patch:
From fc1c3eff61edf8e9f0a4bfa980f3a6030a6b271f Mon Sep 17 00:00:00 2001
From: Mathieu Parent <Mathieu.PARENT@nantesmetropole.fr>
Date: Tue, 8 Mar 2016 16:56:50 +0100
Subject: [PATCH] createOutputFile: rename already existing file
See https://bugs.debian.org/734688
Closes #23
---
logrotate.c | 20 ++++++++++++++++++--
test/test | 26 ++++++++++++++++++++++++++
test/test-config.72.in | 7 +++++++
3 files changed, 51 insertions(+), 2 deletions(-)
create mode 100644 test/test-config.72.in
diff --git a/logrotate.c b/logrotate.c
index 20f6ea5..42c3eeb 100644
--- a/logrotate.c
+++ b/logrotate.c
@@ -395,8 +395,24 @@ static int runScript(struct logInfo *log, char *logfn, char *script)
int createOutputFile(char *fileName, int flags, struct stat *sb, acl_type acl, int force_mode)
{
int fd;
- struct stat sb_create;
- int acl_set = 0;
+ struct stat sb_create;
+ int acl_set = 0;
+
+ if (stat(fileName, &sb_create) == 0) {
+ /* the destination file already exists, while it should not */
+ struct tm now = *localtime(&nowSecs);
+ size_t fileName_size = strlen(fileName);
+ char* backupName = alloca(fileName_size + sizeof("-YYYYMMDDHH.backup"));
+ strncpy(backupName, fileName, fileName_size);
+ size_t date_size=strftime(backupName+fileName_size, 12, "-%Y%m%d%H", &now);
+ strncpy(backupName+fileName_size+date_size, ".backup\0", 8);
+ message(MESS_ERROR, "destination %s already exists, renaming to %s\n", fileName, backupName);
+ if (rename(fileName, backupName) != 0) {
+ message(MESS_ERROR, "error renaming already existing output file %s to %s: %s\n",
+ fileName, backupName, strerror(errno));
+ return -1;
+ }
+ }
fd = open(fileName, (flags | O_EXCL | O_NOFOLLOW),
(S_IRUSR | S_IWUSR) & sb->st_mode);
diff --git a/test/test b/test/test
index 54d57d2..755e582 100755
--- a/test/test
+++ b/test/test
@@ -1586,5 +1586,31 @@ EOF
rm -rf testdir adir
rm -rf testdir bdir
+cleanup 72
+
+# ------------------------------- Test 72 ------------------------------------
+preptest test.log 72 2
+
+$RLR test-config.72 --force
+
+checkoutput <<EOF
+test.log 0
+test.log.1 0 zero
+test.log.2.gz 1 first
+EOF
+
+echo 'unexpected' > test.log.1.gz
+
+$RLR test-config.72 --force
+dt="$(date +%Y%m%d%H)"
+
+checkoutput <<EOF
+test.log 0
+test.log.1 0
+test.log.1.gz-$dt.backup 0 unexpected
+test.log.2.gz 1 zero
+test.log.3.gz 1 first
+EOF
+
cleanup
diff --git a/test/test-config.72.in b/test/test-config.72.in
new file mode 100644
index 0000000..9fe50a2
--- /dev/null
+++ b/test/test-config.72.in
@@ -0,0 +1,7 @@
+&DIR&/test.log {
+ daily
+ rotate 3
+ compress
+ delaycompress
+ create
+}
--
1.8.3.1