From effe992472c9327241bb48e553e6ba3a19d2e15b Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Mon, 24 Apr 2006 16:33:54 +0000
Subject: [PATCH] Added support for mapping "%h" in configured SlurmdLog to the
 hostname.

---
 NEWS                       |  1 +
 doc/html/configurator.html |  9 +++++----
 doc/man/man5/slurm.conf.5  |  2 ++
 src/slurmd/slurmd/slurmd.c | 21 +++++++++++++++++++++
 4 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 2d6d0c09314..9294256b7d5 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ documents those changes that are of interest to users and admins.
     job.step 
  -- removed jobacct/bluegene (no real need for this) meaning, I don't think 
     there is a way to gather the data yet.
+ -- Added support for mapping "%h" in configured SlurmdLog to the hostname.
  
 * Changes in SLURM 1.1.0-pre5
 =============================
diff --git a/doc/html/configurator.html b/doc/html/configurator.html
index 55f8430e395..76a1c601a59 100644
--- a/doc/html/configurator.html
+++ b/doc/html/configurator.html
@@ -369,7 +369,8 @@ pathnames for the files.
 <P>
 <input type="text" name="slurmd_debug" value="3"> <B>SlurmdDebug</B> (0 to 7)
 <P>
-<input type="text" name="slurmd_logfile" value=""> <B>SlurmdLogFile</B> (default is none, log goes to syslog)
+<input type="text" name="slurmd_logfile" value=""> <B>SlurmdLogFile</B> (default is none, 
+log goes to syslog, string "%h" in name gets replaced with hostname)
 <P>
 
 <H2>Job Completion Logging</H2>
@@ -399,8 +400,8 @@ Linux proc table information gathered, use with Linux systems only<BR>
 polling interval in seconds.<BR>
 <input type="text" name="job_acct_logfile" value=""> <B>JobAcctLogFile</B>:
 Location specification.
-This is the location of the text file to be written to (used by Log only).Use a fully 
-qualified pathname.
+This is the location of the text file to be written to (used by Log only).
+Use a fully qualified pathname.
 <P>
 
 <H2>Process ID Logging</H2>
@@ -456,6 +457,6 @@ before terminating all remaining tasks. A value of zero indicates unlimited wait
 </FORM>
 <HR>
 <p class="footer">UCRL-WEB-217616<br>
-Last modified 11 April 2006</p>
+Last modified 23 April 2006</p>
 </BODY>
 
diff --git a/doc/man/man5/slurm.conf.5 b/doc/man/man5/slurm.conf.5
index cc03977227a..032b884e1b2 100644
--- a/doc/man/man5/slurm.conf.5
+++ b/doc/man/man5/slurm.conf.5
@@ -377,6 +377,8 @@ The default value is 3.
 Fully qualified pathname of a file into which the  \fBslurmd\fR daemon's 
 logs are written.
 The default value is none (performs logging via syslog).
+Any "%h" within the name is replaced with the hostname on which the 
+\fBslurmd\fR is running.
 .TP
 \fBSlurmdPidFile\fR
 Fully qualified pathname of a file into which the  \fBslurmd\fR daemon may write 
diff --git a/src/slurmd/slurmd/slurmd.c b/src/slurmd/slurmd/slurmd.c
index 4fad1d9451f..58a1897eefe 100644
--- a/src/slurmd/slurmd/slurmd.c
+++ b/src/slurmd/slurmd/slurmd.c
@@ -141,6 +141,7 @@ main (int argc, char *argv[])
 
 	init_setproctitle(argc, argv);
 
+	/* NOTE: conf->logfile always NULL at this point */
 	log_init(argv[0], conf->log_opts, LOG_DAEMON, conf->logfile);
 
 	xsignal(SIGTERM, &_term_handler);
@@ -486,6 +487,25 @@ _free_and_set(char **confvar, char *newval)
 		return 0;
 }
 
+/* Replace any "%h" in logfile name with actual hostname */
+static void
+_massage_logfile(void)
+{
+	char *ptr, *new_fname;
+	int new_len;
+
+	if ((ptr = strstr(conf->logfile, "%h")) == NULL)
+		return;
+
+	new_len = strlen(conf->logfile) + strlen(conf->hostname);
+	new_fname = xmalloc(new_len);
+	*ptr = '\0';
+	snprintf(new_fname, new_len, "%s%s%s", conf->logfile, conf->hostname, 
+		&ptr[2]);
+	xfree(conf->logfile);
+	conf->logfile = new_fname;
+}
+
 /*
  * Read the slurm configuration file (slurm.conf) and substitute some
  * values into the slurmd configuration in preference of the defaults.
@@ -510,6 +530,7 @@ _read_config()
 
 	if (!conf->logfile)
 		conf->logfile = xstrdup(cf->slurmd_logfile);
+	_massage_logfile();	
 
 	slurm_conf_unlock();
 	/* node_name may already be set from a command line parameter */
-- 
GitLab