summaryrefslogtreecommitdiffstats
path: root/patches/logrotate-3.7.1/rh-noTMPDIR.patch
blob: 73e5fa717b39008a1e25e5a54f5b2bff26a22df3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Do not use tmpfile to run script anymore (Closes: #149270)
From RedHat patches.

---
 logrotate.c |   31 +------------------------------
 1 file changed, 1 insertion(+), 30 deletions(-)

Index: logrotate-3.7.1/logrotate.c
===================================================================
--- logrotate-3.7.1.orig/logrotate.c
+++ logrotate-3.7.1/logrotate.c
@@ -88,10 +88,7 @@ static logState * findState(const char *
 }
 
 static int runScript(char * logfn, char * script) {
-    int fd;
-    char *filespec;
     int rc;
-    char buf[256];
 
     if (debug) {
 	message(MESS_DEBUG, "running script with arg %s: \"%s\"\n", 
@@ -99,38 +96,12 @@ static int runScript(char * logfn, char 
 	return 0;
     }
 
-    filespec = buf;
-    snprintf(buf, sizeof(buf), "%s/logrotate.XXXXXX", getenv("TMPDIR") ?: "/tmp");
-    fd = -1;
-    if (!filespec || (fd = mkstemp(filespec)) < 0 || fchmod(fd, 0700)) {
-	message(MESS_DEBUG, "error creating %s: %s\n", filespec,
-		strerror(errno));
-	if (fd >= 0) {
-	    close(fd);
-	    unlink(filespec);
-	}
-	return -1;
-    }
-
-    if (write(fd, "#!/bin/sh\n\n", 11) != 11 ||
-	write(fd, script, strlen(script)) != strlen(script)) {
-	message(MESS_DEBUG, "error writing %s\n", filespec);
-	close(fd);
-	unlink(filespec);
-	return -1;
-    }
-
-    close(fd);
-
     if (!fork()) {
-	execlp(filespec, filespec, logfn, NULL);
+	execl("/bin/sh", "sh", "-c", script, NULL);
 	exit(1);
     }
 
     wait(&rc);
-
-    unlink(filespec);
-
     return rc;
 }