summaryrefslogtreecommitdiff
path: root/www/mod_dtcl/files/patch-tmp
blob: 66570a1381e2eec75086f07dd6604e186efe88c3 (plain) (blame)
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
--- apache_request.c	Sat Jun 23 10:11:03 2001
+++ apache_request.c	Tue Aug  7 22:37:51 2001
@@ -341,22 +341,33 @@
 {
     request_rec *r = req->r;
     FILE *fp;
-    char prefix[] = "apreq";
+#define PREFIX "apreq"
     char *name = NULL;
-    int fd = 0; 
-    int tries = 100;
+    int fd;
+    char *dirs[5], **dir;
 
-    while (--tries > 0) {
-	if ( (name = tempnam(req->temp_dir, prefix)) == NULL )
-	    continue;
-	fd = ap_popenf(r->pool, name, O_CREAT|O_EXCL|O_RDWR|O_BINARY, 0600);
-	if ( fd >= 0 )
-	    break; /* success */
-	else
-	    free(name);
+    dirs[0] = getenv("TMPDIR"); dirs[1] = req->temp_dir;
+    dirs[2] = P_tmpdir; dirs[3] = "/tmp"; dirs[4] = NULL;
+
+    /*
+     * Look for the non-NULL directory. The order
+     * above is dictated by the tempnam(3) spec
+     */
+    for (dir = dirs; *dir == NULL; dir++) /* Nothing */;
+
+    /* Now, try to create the temporary file in one of the directories: */
+    for (fd = -1; fd == -1 && *dir; dir++) {
+	name = malloc(strlen(*dir) + sizeof PREFIX + 8);
+	if (!name) {
+	    ap_log_rerror(REQ_ERROR, "[libapreq] could not allocate memory");
+	    return(NULL);
+	}
+	sprintf(name, "%s/%s.XXXXXX", *dir, PREFIX);
+	fd = mkstemp(name);
+	if (fd == -1) free(name);
     }
 
-    if ( tries == 0  || (fp = ap_pfdopen(r->pool, fd, "w+" "b") ) == NULL ) {
+    if ( fd == -1 || (fp = ap_pfdopen(r->pool, fd, "w+" "b") ) == NULL ) {
 	ap_log_rerror(REQ_ERROR, "[libapreq] could not create/open temp file");
 	if ( fd >= 0 ) { remove(name); free(name); }
 	return NULL;