Add a new hook function into the opal_output system:
opal_output_set_output_file_info(). This allows getting and setting the default directory where output stream files will be opened (for all *new* streams). Before this function is not invoked, the default location is $TMPDIR or $HOME (if $TMPDIR is not defined). Added a call into orte_init_stage1() to call this function immediately after the session directory is created and set the default location of stream files to be the process' session directory. This commit was SVN r7254.
Этот коммит содержится в:
родитель
4aa75fa739
Коммит
7eadfc4bdc
@ -19,7 +19,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
@ -32,6 +31,7 @@
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#include "opal/util/opal_environ.h"
|
||||
#include "opal/util/output.h"
|
||||
#include "opal/threads/mutex.h"
|
||||
#include "ompi/include/constants.h"
|
||||
@ -41,6 +41,8 @@
|
||||
*/
|
||||
static int verbose_stream = -1;
|
||||
static opal_output_stream_t verbose;
|
||||
static char *output_dir = NULL;
|
||||
static char *output_prefix = NULL;
|
||||
|
||||
|
||||
/*
|
||||
@ -107,6 +109,7 @@ OBJ_CLASS_INSTANCE(opal_output_stream_t, opal_object_t, construct, NULL);
|
||||
bool opal_output_init(void)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
|
||||
if (initialized) {
|
||||
return true;
|
||||
@ -132,6 +135,17 @@ bool opal_output_init(void)
|
||||
OBJ_CONSTRUCT(&mutex, opal_mutex_t);
|
||||
initialized = true;
|
||||
|
||||
/* Set some defaults */
|
||||
|
||||
output_prefix = strdup("output-");
|
||||
if (NULL != (str = getenv("TMPDIR"))) {
|
||||
output_dir = strdup(str);
|
||||
} else if (NULL != (str = getenv("HOME"))) {
|
||||
output_dir = strdup(str);
|
||||
} else {
|
||||
output_dir = strdup(".");
|
||||
}
|
||||
|
||||
/* Open the default verbose stream */
|
||||
|
||||
verbose_stream = opal_output_open(&verbose);
|
||||
@ -306,6 +320,32 @@ void opal_output_set_verbosity(int output_id, int level)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Control where output flies will go
|
||||
*/
|
||||
void opal_output_set_output_file_info(const char *dir,
|
||||
const char *prefix,
|
||||
char **olddir,
|
||||
char **oldprefix)
|
||||
{
|
||||
if (NULL != olddir) {
|
||||
*olddir = strdup(output_dir);
|
||||
}
|
||||
if (NULL != oldprefix) {
|
||||
*oldprefix = strdup(output_prefix);
|
||||
}
|
||||
|
||||
if (NULL != dir) {
|
||||
free(output_dir);
|
||||
output_dir = strdup(dir);
|
||||
}
|
||||
if (NULL != prefix) {
|
||||
free(output_prefix);
|
||||
output_prefix = strdup(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Shut down the output stream system
|
||||
*/
|
||||
@ -448,19 +488,20 @@ static int do_open(int output_id, opal_output_stream_t * lds)
|
||||
static int open_file(int i)
|
||||
{
|
||||
int flags;
|
||||
char *dir, *filename;
|
||||
char *filename;
|
||||
|
||||
/* Setup the filename and open flags */
|
||||
|
||||
/* BWB - fix me! - used to look at orte_process_info */
|
||||
dir = NULL;
|
||||
if (NULL != dir) {
|
||||
if (NULL != output_dir) {
|
||||
filename = (char *) malloc(MAXPATHLEN);
|
||||
if (NULL == filename) {
|
||||
return OMPI_ERR_OUT_OF_RESOURCE;
|
||||
}
|
||||
strcpy(filename, dir);
|
||||
strcat(filename, "/output-");
|
||||
strcpy(filename, output_dir);
|
||||
strcat(filename, "/");
|
||||
if (NULL != output_prefix) {
|
||||
strcat(filename, output_prefix);
|
||||
}
|
||||
if (info[i].ldi_file_suffix != NULL) {
|
||||
strcat(filename, info[i].ldi_file_suffix);
|
||||
} else {
|
||||
|
@ -187,14 +187,13 @@ struct opal_output_stream_t {
|
||||
* When opal_output_stream_t::lds_want_file is true, this field
|
||||
* indicates the string suffix to add to the filename.
|
||||
*
|
||||
* The output file will be in the OPAL session directory and have a
|
||||
* OPAL-generated prefix (generally "$proc_sessiondir/output-").
|
||||
* The suffix is intended to give stream users a chance to write
|
||||
* their output into unique files. If this field is NULL, the
|
||||
* suffix "output.txt" is used.
|
||||
* The output file will be in the directory and begin with the
|
||||
* prefix set by opal_output_set_output_file_info() (e.g.,
|
||||
* "$dir/$prefix$suffix"). If this field is NULL and
|
||||
* lds_want_file is true, then the suffix "output.txt" is used.
|
||||
*
|
||||
* Note that it is possible that the process session directory does
|
||||
* not exist when opal_output_open() is invoked. See opal_output()
|
||||
* Note that it is possible that the output directory may not
|
||||
* exist when opal_output_open() is invoked. See opal_output()
|
||||
* for details on what happens in this situation.
|
||||
*/
|
||||
char *lds_file_suffix;
|
||||
@ -387,6 +386,46 @@ struct opal_output_stream_t {
|
||||
* will be used for all future invocations of opal_output_verbose().
|
||||
*/
|
||||
OMPI_DECLSPEC void opal_output_set_verbosity(int output_id, int level);
|
||||
|
||||
/**
|
||||
* Set characteristics for output files.
|
||||
*
|
||||
* @param dir Directory where output files will go
|
||||
* @param olddir If non-NULL, the directory where output files
|
||||
* were previously opened
|
||||
* @param prefix Prefix of files in the output directory
|
||||
* @param oldprefix If non-NULL, the old prefix
|
||||
*
|
||||
* This function controls the final filename used for all new
|
||||
* output streams that request output files. Specifically, when
|
||||
* opal_output_stream_t::lds_want_file is true, the output
|
||||
* filename will be of the form $dir/$prefix$suffix.
|
||||
*
|
||||
* The default value for the output directory is whatever is
|
||||
* specified in the TMPDIR environment variable if it exists, or
|
||||
* $HOME if it does not. The default value for the prefix is
|
||||
* "output-".
|
||||
*
|
||||
* If dir or prefix are NULL, new values are not set. The strings
|
||||
* represented by dir and prefix are copied into internal storage;
|
||||
* it is safe to free() these values after
|
||||
* opal_output_set_output_file_info() returns.
|
||||
*
|
||||
* If olddir or oldprefix are not NULL, copies of the old
|
||||
* directory and prefix (respectively) are returned in these
|
||||
* parameters. The caller is responsible for calling (free) on
|
||||
* these values. This allows one to get the old values, output an
|
||||
* output file in a specific directory and/or with a specific
|
||||
* prefix, and then restore the old values.
|
||||
*
|
||||
* Note that this function only affects the creation of \em new
|
||||
* streams -- streams that are already open are not affected
|
||||
* (i.e., their output files are not moved to the new directory).
|
||||
*/
|
||||
OMPI_DECLSPEC void opal_output_set_output_file_info(const char *dir,
|
||||
const char *prefix,
|
||||
char **olddir,
|
||||
char **oldprefix);
|
||||
|
||||
#if OMPI_ENABLE_DEBUG
|
||||
/**
|
||||
|
@ -279,6 +279,12 @@ int orte_init_stage1(bool infrastructure)
|
||||
free(procid_str);
|
||||
}
|
||||
|
||||
/* Once the session directory location has been established, set
|
||||
the opal_output default file location to be in the
|
||||
proc-specific session directory. */
|
||||
opal_output_set_output_file_info(orte_process_info.proc_session_dir, NULL,
|
||||
NULL, NULL);
|
||||
|
||||
/* if i'm the seed, get my contact info and write my setup file for others to find */
|
||||
if (orte_process_info.seed) {
|
||||
if (NULL != orte_universe_info.seed_uri) {
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user