From f0f4770ab2ec60b18091594608b3f6e2e0fba148 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Wed, 1 Dec 2010 17:42:23 +0000 Subject: [PATCH] Build and use roken's mkstemp 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 Reviewed-by: Derrick Brashear --- acinclude.m4 | 1 + src/bucoord/ubik_db_if.c | 7 ------- src/budb/db_text.c | 28 ---------------------------- src/butc/tcudbprocs.c | 4 ---- src/roken/Makefile.in | 3 +++ src/roken/NTMakefile | 1 + src/roken/afsroken.def | 2 ++ src/roken/librokenafs.map | 1 + 8 files changed, 8 insertions(+), 39 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 3165f1dde..8375ed8b0 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1336,6 +1336,7 @@ AC_REPLACE_FUNCS([ \ errx \ getopt \ getprogname \ + mkstemp \ strcasecmp \ strlcat \ strnlen \ diff --git a/src/bucoord/ubik_db_if.c b/src/bucoord/ubik_db_if.c index 45aa8ef94..1c0a917d1 100644 --- a/src/bucoord/ubik_db_if.c +++ b/src/bucoord/ubik_db_if.c @@ -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); diff --git a/src/budb/db_text.c b/src/budb/db_text.c index 72060d610..c5ceed68d 100644 --- a/src/budb/db_text.c +++ b/src/budb/db_text.c @@ -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 diff --git a/src/butc/tcudbprocs.c b/src/butc/tcudbprocs.c index e51625cc9..1dcaf90f8 100644 --- a/src/butc/tcudbprocs.c +++ b/src/butc/tcudbprocs.c @@ -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); diff --git a/src/roken/Makefile.in b/src/roken/Makefile.in index 86788dba3..6a0215801 100644 --- a/src/roken/Makefile.in +++ b/src/roken/Makefile.in @@ -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 diff --git a/src/roken/NTMakefile b/src/roken/NTMakefile index 6fa465105..0a2f690ef 100644 --- a/src/roken/NTMakefile +++ b/src/roken/NTMakefile @@ -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 \ diff --git a/src/roken/afsroken.def b/src/roken/afsroken.def index 257b51017..43d598c40 100644 --- a/src/roken/afsroken.def +++ b/src/roken/afsroken.def @@ -30,3 +30,5 @@ EXPORTS rk_optarg @34 DATA rk_optind @35 DATA rk_opterr @36 DATA + rk_mkstemp @37 + diff --git a/src/roken/librokenafs.map b/src/roken/librokenafs.map index d5a5704ab..f2abfce0d 100644 --- a/src/roken/librokenafs.map +++ b/src/roken/librokenafs.map @@ -17,6 +17,7 @@ rk_emalloc; rk_erealloc; rk_hex_encode; + rk_mkstemp; rk_print_version; rk_socket; rk_strcasecmp; -- 2.39.5