first bunch of patches with mkstemp()

Matus "fantomas" Uhlar uhlar at fantomas.sk
Mon Apr 3 19:01:53 UTC 2000


Hello,

FreeBSD (and possibly other systems) implement function mkstemp() whish
works like mptemp but doesn't return just filename but the opened file
descriptor. It's guaranteed to be safe (hmmm) and compiler writes warnings
when you use mktemp()

there are many programs using mktemp() in inn, this is patch to some of them
(those which were easier to patch)

OK, i didn't add any tests for HAVE_MKSTEMP into config, i dunno how to do
it :( and i'll mail infor about the rest later 

--- backends/innxmit.c.orig      Fri Nov 27 08:14:30 1998
+++ backends/innxmit.c   Tue Mar 28 01:23:03 2000
@@ -521,11 +521,20 @@
 Requeue(Article, MessageID)
     char       *Article;
     char       *MessageID;
+#ifdef HAVE_MKSTEMP
+    int fd;
+#endif /* HAVE_MKSTEMP */
 {
     /* Temp file already open? */
     if (BATCHfp == NULL) {
+#ifdef HAVE_MKSTEMP
+	if (((fd = mkstemp(BATCHtemp)) == -1) ||
+	    ((BATCHfp = fdopen(fd, "w")) == NULL))
+#else
 	(void)mktemp(BATCHtemp);
-	if ((BATCHfp = fopen(BATCHtemp, "w")) == NULL) {
+	if ((BATCHfp = fopen(BATCHtemp, "w")) == NULL)
+#endif
+	{
 	    (void)fprintf(stderr, "Can't open \"%s\", %s\n",
 		BATCHtemp, strerror(errno));
 		ExitWithStats(1);


--- backends/nntpget.c.orig      Fri Jan  8 23:03:32 1999
+++ backends/nntpget.c   Tue Mar 28 01:24:09 2000
@@ -217,6 +217,9 @@
     BOOL       Verbose = FALSE;
     char       *Update;
     char       *p;
+#ifdef HAVE_MKSTEMP
+    int         fd;
+#endif /* HAVE_MKSTEMP */
 
     /* First thing, set up logging and our identity. */
     openlog("nntpget", L_OPENLOG_FLAGS | LOG_PID, LOG_INN_PROG);           
@@ -330,8 +333,13 @@
 
 	/* Create a temporary file. */
 	(void)sprintf(temp, "%s/nntpgetXXXXXX", innconf->pathtmp);
+#ifdef HAVE_MKSTEMP
+	if (((fd = mkstemp(temp) == -1) || ((F = fdopen(fd, "w+")) ==
NULL))
+#else
 	(void)mktemp(temp);
-	if ((F = fopen(temp, "w+")) == NULL) {
+	if ((F = fopen(temp, "w+")) == NULL)
+#endif
+	{
 	    (void)fprintf(stderr, "Can't open \"%s\", %s\n",
 		temp, strerror(errno));
 	    exit(1);

--- backends/shrinkfile.c.orig   Sat Jan 29 12:27:09 2000
+++ backends/shrinkfile.c        Tue Mar 28 01:40:32 2000
@@ -49,10 +49,15 @@
 
     /* Get filename. */
     (void)sprintf(buff, "%s/shrinkXXXXXX", innconf->pathtmp);
-    (void)mktemp(buff);
 
     /* Open the file. */
-    if ((i = open(buff, O_RDWR | O_CREAT | O_EXCL | O_TRUNC, 0600)) < 0) {
+#ifdef HAVE_MKSTEMP
+    if ((i = mkstemp(buff)) == -1)
+#else
+    (void)mktemp(buff);
+    if ((i = open(buff, O_RDWR | O_CREAT | O_EXCL | O_TRUNC, 0600)) < 0)
+#endif
+    {
        (void)fprintf(stderr, "%s: Can't make temporary file, %s\n",
                program, strerror(errno));
        exit(1);

--- innfeed/misc.c.orig Fri Jun 12 01:00:19 1998
+++ innfeed/misc.c      Tue Mar 28 02:32:33 2000
@@ -784,10 +784,12 @@
   FILE *tmpFp ;
   int c ;
   int i ;
+#ifdef HAVE_MKSTEMP
+  int fd ;
+#endif
 
   tmpname = malloc (pathMax(NULL) + 1) ;
   sprintf (tmpname,"%s.XXXXXX",name) ;
-  mktemp (tmpname) ;
 
   if (currlen <= size)
     {
@@ -799,7 +801,12 @@
     }
 
   /* create a temp file that will go away when closed. */
+#ifdef HAVE_MKTEMP
+  if (((fd = mkstemp(tmpname)) == -1) || (tmpFp = fdopen(fd , "w")) ==
NULL))
+#else
+  mktemp (tmpname) ;
   if ((tmpFp = fopen (tmpname,"w")) == NULL)
+#endif /* HAVE_MKSTEMP */
     {
       syslog (LOG_ERR,SHRINK_TEMP_OPEN,tmpname) ;
       FREE (tmpname) ;


next bunch coming later... dunno when you'll release 2.3 so have at least
this.

-- 
 Matus "fantomas" Uhlar, sysadmin at NEXTRA, Slovakia; IRCNET admin of *.sk
 uhlar at fantomas.sk ; http://www.fantomas.sk/ ; http://www.nextra.sk/
 Enter any 12-digit prime number to continue.



More information about the inn-patches mailing list