Build and use roken's mkstemp
authorSimon Wilkinson <sxw@your-file-system.com>
Wed, 1 Dec 2010 17:42:23 +0000 (17:42 +0000)
committerDerrick Brashear <shadow@dementia.org>
Wed, 1 Dec 2010 21:09:27 +0000 (13:09 -0800)
Add roken's mkstemp to the build on all platforms, either through
configure (Unix) or explicitly (Windows). Change all callers so
that mkstemp is used unconditionally, rather than falling back
to more risky alternatives.

This is based on original change from Russ Allbery submitted as
http://gerrit.openafs.org/2146

Change-Id: Ia1def41e438e6517b3e7cd5790df3c99eddb8ef6
Reviewed-on: http://gerrit.openafs.org/3398
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

acinclude.m4
src/bucoord/ubik_db_if.c
src/budb/db_text.c
src/butc/tcudbprocs.c
src/roken/Makefile.in
src/roken/NTMakefile
src/roken/afsroken.def
src/roken/librokenafs.map

index 3165f1d..8375ed8 100644 (file)
@@ -1336,6 +1336,7 @@ AC_REPLACE_FUNCS([ \
        errx \
        getopt \
        getprogname \
+       mkstemp \
        strcasecmp \
        strlcat \
        strnlen \
index 45aa8ef..1c0a917 100644 (file)
@@ -1219,9 +1219,7 @@ int
 bc_openTextFile(udbClientTextP ctPtr, char *tmpFileName)
 {
     int code = 0;
-#ifdef HAVE_MKSTEMP
     int fd;
-#endif
 
     if (ctPtr->textStream != NULL) {
        fclose(ctPtr->textStream);
@@ -1229,15 +1227,10 @@ bc_openTextFile(udbClientTextP ctPtr, char *tmpFileName)
     }
 
     sprintf(tmpFileName, "%s/bu_XXXXXX", gettmpdir());
-#ifdef HAVE_MKSTEMP
     fd = mkstemp(tmpFileName);
     if (fd == -1)
        ERROR(BUDB_INTERNALERROR);
     ctPtr->textStream = fdopen(fd, "w+");
-#else
-    mktemp(tmpFileName);
-    ctPtr->textStream = fopen(tmpFileName, "w+");
-#endif
     if (ctPtr->textStream == NULL)
        ERROR(BUDB_INTERNALERROR);
 
index 72060d6..c5ceed6 100644 (file)
@@ -486,31 +486,3 @@ saveTextToFile(struct ubik_trans *ut, struct textBlock *tbPtr)
     printf("wrote debug file %s\n", filename);
 }
 
-
-#if (defined(AFS_HPUX_ENV)) || defined(AFS_NT40_ENV)
-
-/* mkstemp
- * entry:
- *     st - string containing template for a tmp file name
- * exit:
- *     -1 - failed
- *     0-n - open file descriptor
- * notes:
- *     1) missing in Ultrix, HP/UX and AIX 221 environment
- *      2) iterate some number of times to alleviate the race?
- */
-
-int
-mkstemp(char *st)
-{
-    int retval = -1;
-
-#ifdef AFS_LINUX20_ENV
-    retval = open(mkstemp(st), O_RDWR | O_CREAT | O_EXCL, 0600);
-#else
-    retval = open(mktemp(st), O_RDWR | O_CREAT | O_EXCL, 0600);
-#endif
-
-    return (retval);
-}
-#endif
index e51625c..1dcaf90 100644 (file)
@@ -1455,11 +1455,7 @@ restoreText(struct butm_tapeInfo *tapeInfo,
 
     /* open the text file */
     sprintf(filename, "%s/bu_XXXXXX", gettmpdir());
-#if defined (HAVE_MKSTEMP)
     fid = mkstemp(filename);
-#else
-    fid = open(mktemp(filename), O_RDWR | O_CREAT | O_EXCL, 0600);
-#endif
     if (fid < 0) {
        ErrorLog(0, rstTapeInfoPtr->taskId, errno, 0,
                 "Can't open temporary text file: %s\n", filename);
index 86788db..6a02158 100644 (file)
@@ -111,6 +111,9 @@ hex.o: ${UPSTREAM}/hex.c
 issuid.o: ${UPSTREAM}/issuid.c
        $(AFS_CCRULE) $(UPSTREAM)/issuid.c
 
+mkstemp.o: ${UPSTREAM}/mkstemp.c
+       $(AFS_CCRULE) $(UPSTREAM)/mkstemp.c
+
 net_read.o: ${UPSTREAM}/net_read.c
        $(AFS_CCRULE) $(UPSTREAM)/net_read.c
 
index 6fa4651..0a2f690 100644 (file)
@@ -37,6 +37,7 @@ ROKEN_OBJS = \
        $(OUT)\hex.obj \
         $(OUT)\issuid.obj \
        $(OUT)\localtime_r.obj \
+       $(OUT)\mkstemp.obj \
        $(OUT)\net_read.obj \
        $(OUT)\net_write.obj \
        $(OUT)\snprintf.obj \
index 257b510..43d598c 100644 (file)
@@ -30,3 +30,5 @@ EXPORTS
         rk_optarg               @34 DATA
         rk_optind               @35 DATA
         rk_opterr               @36 DATA
+       rk_mkstemp              @37
+
index d5a5704..f2abfce 100644 (file)
@@ -17,6 +17,7 @@
                rk_emalloc;
                rk_erealloc;
                rk_hex_encode;
+               rk_mkstemp;
                rk_print_version;
                rk_socket;
                rk_strcasecmp;