openbsd-ports/sysutils/anacron/patches/patch-runjob_c
naddy 1e3bf2b5aa - Don't leave files behind in /tmp.
- Fix a number of compiler warnings.
- Clean INSTALL a bit.
- Point HOMEPAGE to a more useful place.

From: Andreas Kahari <ak+openbsd@freeshell.org>
2004-05-17 00:22:54 +00:00

51 lines
1.2 KiB
Plaintext

$OpenBSD: patch-runjob_c,v 1.3 2004/05/17 00:22:54 naddy Exp $
--- runjob.c.orig 2000-06-21 00:12:18.000000000 +0100
+++ runjob.c 2004-05-12 20:50:11.000000000 +0100
@@ -34,11 +34,38 @@
#include <stdio.h>
#include <string.h>
#include "global.h"
+#include <limits.h>
static int
temp_file()
/* Open a temporary file and return its file descriptor */
{
+ char template[PATH_MAX];
+ char *tmpdir = getenv("TMPDIR");
+
+ int fd = -1;
+
+ if (tmpdir == NULL) {
+ tmpdir = "/tmp";
+ }
+ if (strlcpy(template, tmpdir, sizeof template) >=
+ sizeof template) {
+ die_e("TMPDIR too long.");
+ }
+ if (strlcat(template, "/anacronXXXXXXXX", sizeof template) >=
+ sizeof template) {
+ die_e("Temporary filename too long.");
+ }
+ if ((fd = mkstemp(template)) == -1) {
+ die_e("Could not create temporary file.");
+ }
+ if (unlink(template) == -1) {
+ complain("Tried to unlink temporary file '%s' but failed.",
+ template);
+ }
+ return fd;
+
+#if 0
const int max_retries = 50;
char *name;
int fd, i;
@@ -61,6 +88,7 @@ temp_file()
free(name);
fcntl(fd, F_SETFD, 1); /* set close-on-exec flag */
return fd;
+#endif
}
static off_t