aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@0888f3d4-9f52-45d2-93bc-d00801ff5e46>2004-06-20 12:46:52 +0000
committertradke <tradke@0888f3d4-9f52-45d2-93bc-d00801ff5e46>2004-06-20 12:46:52 +0000
commit2b0a0731a03710e2f183f735d80eef4b652efe6b (patch)
tree9602342d54cd3cd0bf4786707870af0fbf701301
parente961965209efcaa0c7a227b946d7145e6eef79d4 (diff)
Use mkstemp(3) if available.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOStreamedHDF5/trunk@108 0888f3d4-9f52-45d2-93bc-d00801ff5e46
-rw-r--r--src/Startup.c78
-rw-r--r--src/ioStreamedHDF5GH.h2
2 files changed, 39 insertions, 41 deletions
diff --git a/src/Startup.c b/src/Startup.c
index fbef5bc..910faac 100644
--- a/src/Startup.c
+++ b/src/Startup.c
@@ -2,9 +2,9 @@
@file Startup.c
@date Mon Jun 19 2000
@author Thomas Radke
- @desc
+ @desc
Startup and termination routines for IOStreamedHDF5.
- @enddesc
+ @enddesc
@version $Id$
@@*/
@@ -25,6 +25,12 @@ CCTK_FILEVERSION(CactusPUGHIO_IOStreamedHDF5_Startup_c)
/********************************************************************
+ ******************** Macro Definitions ************************
+ ********************************************************************/
+#define FILENAME_TEMPLATE "fileXXXXXX"
+
+
+/********************************************************************
******************** External Routines ************************
********************************************************************/
void IOStreamedHDF5_Startup (void);
@@ -41,11 +47,11 @@ static void *SetupGH (tFleshConfig *config, int conv_level, cGH *GH);
@routine IOStreamedHDF5_Startup
@date Mon Jun 19 2000
@author Thomas Radke
- @desc
+ @desc
The startup registration routine for IOStreamedHDF5.
Registers the GH extensions needed for IOStreamedHDF5
along with its setup routine.
- @enddesc
+ @enddesc
@calls CCTK_RegisterGHExtension
CCTK_RegisterGHExtensionSetupGH
@@ -61,10 +67,10 @@ void IOStreamedHDF5_Startup (void)
@routine IOStreamedHDF5_Terminate
@date Mon Jun 19 2000
@author Thomas Radke
- @desc
+ @desc
IOStreamedHDF5's termination routine
Closes all open sockets and destroys the timers.
- @enddesc
+ @enddesc
@calls CCTK_TimerDestroyI
@@ -102,11 +108,10 @@ void IOStreamedHDF5_Terminate (const cGH *GH)
}
}
- /* remove advertised file and free filename */
- if (myGH->advertised_filename)
+ /* remove advertised file */
+ if (strcmp (myGH->advertised_filename, FILENAME_TEMPLATE))
{
remove (myGH->advertised_filename);
- free (myGH->advertised_filename);
}
}
}
@@ -119,9 +124,9 @@ void IOStreamedHDF5_Terminate (const cGH *GH)
@routine SetupGH
@date Mon Jun 19 2000
@author Thomas Radke
- @desc
+ @desc
Allocates and sets up IOStreamedHDF5's GH extension structure
- @enddesc
+ @enddesc
@calls CCTK_RegisterIOMethod
CCTK_RegisterIOMethodOutputGH
@@ -196,7 +201,7 @@ static void *SetupGH (tFleshConfig *config, int conv_level, cGH *GH)
myGH->requests = calloc (numvars, sizeof (ioRequest *));
myGH->out_last = malloc (numvars * sizeof (int));
- myGH->advertised_filename = NULL;
+ strcpy (myGH->advertised_filename, FILENAME_TEMPLATE);
myGH->out_vars = strdup ("");
myGH->out_every_default = out_every - 1;
@@ -244,37 +249,30 @@ static void *SetupGH (tFleshConfig *config, int conv_level, cGH *GH)
/* write the hostname/portnumber information in a temporary file
which gets advertised and then can be downloaded */
- myGH->advertised_filename = (char *) malloc (L_tmpnam);
- if (myGH->advertised_filename && tmpnam (myGH->advertised_filename))
+#ifdef HAVE_MKSTEMP
+ advertised_file_fd = fdopen (mkstemp (myGH->advertised_filename), "w");
+#else
+ advertised_file_fd = tmpnam (myGH->advertised_filename) ?
+ fopen (myGH->advertised_filename, "w") : NULL;
+#endif
+ if (advertised_file_fd)
{
- advertised_file_fd = fopen (myGH->advertised_filename, "w");
-
- if (advertised_file_fd)
- {
- fprintf (advertised_file_fd, "Hostname: %s\n", hostname);
- fprintf (advertised_file_fd, "Data port: %d", data_port);
- fclose (advertised_file_fd);
-
- advertised_file.slice = "";
- advertised_file.thorn = CCTK_THORNSTRING;
- advertised_file.varname = "All variables";
- advertised_file.description = "Streamed HDF5 data";
- advertised_file.mimetype = "data/x-streamed-hdf5";
-
- IOUtil_AdvertiseFile (GH, myGH->advertised_filename,&advertised_file);
- }
- else
- {
- CCTK_WARN (2, "Couldn't create unique temporary file ! "
- "HDF5 data streaming was not advertised.");
- }
+ fprintf (advertised_file_fd, "Hostname: %s\n", hostname);
+ fprintf (advertised_file_fd, "Data port: %d", data_port);
+ fclose (advertised_file_fd);
+
+ advertised_file.slice = "";
+ advertised_file.thorn = CCTK_THORNSTRING;
+ advertised_file.varname = "All variables";
+ advertised_file.description = "Streamed HDF5 data";
+ advertised_file.mimetype = "data/x-streamed-hdf5";
+
+ IOUtil_AdvertiseFile (GH, myGH->advertised_filename,&advertised_file);
}
else
{
- CCTK_WARN (2, "Couldn't create unique temporary filename "
- "for advertising the hostname/portnumber information !");
- free (myGH->advertised_filename);
- myGH->advertised_filename = NULL;
+ CCTK_WARN (2, "Couldn't create unique temporary file ! "
+ "HDF5 data streaming was not advertised.");
}
}
}
@@ -339,7 +337,7 @@ static void *SetupGH (tFleshConfig *config, int conv_level, cGH *GH)
fapl.broadcast_arg = NULL;
HDF5_ERROR (myGH->checkpoint_fapl = H5Pcreate (H5P_FILE_ACCESS));
HDF5_ERROR (H5Pset_fapl_stream (myGH->checkpoint_fapl, &fapl));
-
+
Util_GetHostName (hostname, sizeof (hostname));
CCTK_VInfo (CCTK_THORNSTRING,
"HDF5 checkpoint streaming service started on\n"
diff --git a/src/ioStreamedHDF5GH.h b/src/ioStreamedHDF5GH.h
index 7e337c8..5a78936 100644
--- a/src/ioStreamedHDF5GH.h
+++ b/src/ioStreamedHDF5GH.h
@@ -48,7 +48,7 @@ typedef struct
int timers[IOHDF5_NUM_TIMERS];
/* filename for advertising the hostname / port number information */
- char *advertised_filename;
+ char advertised_filename[L_tmpnam];
/* stop on I/O parameter parsing errors ? */
int stop_on_parse_errors;