From 70e1cdf48dbfa86a4837fcf5c4fe3a0b24661804 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Fri, 9 May 2008 16:37:03 +0000
Subject: [PATCH] For srun/sbatch --get-user-env option (Moab use only) look
 for "env"     command in both /bin and /usr/sbin (for Suse Linux).

---
 NEWS                         |  6 ++++--
 contribs/env_cache_builder.c | 33 ++++++++++++++++++++++++++++++---
 src/common/env.c             |  4 ++++
 3 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index 3fcdcfc058c..53fdf4a58a6 100644
--- a/NEWS
+++ b/NEWS
@@ -31,8 +31,10 @@ documents those changes that are of interest to users and admins.
     HostFormat=2 in SLURM's wiki.conf for improved performance.
  -- NOTE: We needed to change an RPC from version 1.3.0. You must upgrade 
     all nodes in a cluster from v1.3.0 to v1.3.1 at the same time.
- -- Postgres plugin will work from job accounting, not for
-    association management yet.
+ -- Postgres plugin will work from job accounting, not for association 
+    management yet.
+ -- For srun/sbatch --get-user-env option (Moab use only) look for "env"
+    command in both /bin and /usr/sbin (for Suse Linux).
 
 * Changes in SLURM 1.3.1
 ========================
diff --git a/contribs/env_cache_builder.c b/contribs/env_cache_builder.c
index 51078e84120..d8560d104ee 100644
--- a/contribs/env_cache_builder.c
+++ b/contribs/env_cache_builder.c
@@ -77,14 +77,17 @@ static int	_get_cache_dir(char *buffer, int buf_size);
 static void	_log_failures(int failures, char *cache_dir);
 static int	_parse_line(char *in_line, char **user_name, int *user_id);
 
+char *env_loc = NULL;
+
 main (int argc, char **argv)
 {
 	FILE *passwd_fd;
 	char cache_dir[256], in_line[256], *user_name;
 	int i, failures = 0, user_cnt = 0, user_id;
 	long int delta_t;
+	struct stat buf;
 
-	if (geteuid() != (uid_t)0) {
+	if (geteuid() != (uid_t) 0) {
 		printf("Need to run as user root\n");
 		exit(1);
 	}
@@ -97,6 +100,30 @@ main (int argc, char **argv)
 			strerror(errno));
 		exit(1);
 	}
+
+	if (stat("/bgl", &buf) == 0) {
+		printf("BlueGene Note: Execute only a a front-end node, "
+			"not the service node\n");
+		printf("               User logins to the service node are "
+			"disabled\n\n");
+	}
+	if (stat("/bin/su", &buf)) {
+		printf("Could not locate command: /bin/su\n");
+		exit(1);
+	}
+	if (stat("/bin/echo", &buf)) {
+		printf("Could not locate command: /bin/echo\n");
+		exit(1);
+	}
+	if (stat("/bin/env", &buf) == 0)
+		env_loc = "/bin/env";
+	else if (stat("/usr/bin/env", &buf) == 0)
+		env_loc = "/usr/bin/env";
+	else {
+		printf("Could not location command: env\n");
+		exit(1);
+	}
+
 	printf("Building user environment cache files for Moab/Slurm.\n");
 	printf("This will take a while.\n\n");
 
@@ -230,8 +257,8 @@ static long int _build_cache(char *user_name, char *cache_dir)
 		open("/dev/null", O_WRONLY);
 		snprintf(buffer, sizeof(buffer),
 			 "/bin/echo; /bin/echo; /bin/echo; "
-			 "/bin/echo %s; /bin/env; /bin/echo %s",
-			 starttoken, stoptoken);
+			 "/bin/echo %s; %s; /bin/echo %s",
+			 starttoken, env_loc, stoptoken);
 #ifdef LOAD_ENV_NO_LOGIN
 		execl("/bin/su", "su", user_name, "-c", buffer, NULL);
 #else
diff --git a/src/common/env.c b/src/common/env.c
index 61bb6c47811..7d032d930a7 100644
--- a/src/common/env.c
+++ b/src/common/env.c
@@ -1326,6 +1326,10 @@ char **env_array_user_default(const char *username, int timeout, int mode)
 	struct pollfd ufds;
 	struct stat buf;
 
+	if (stat("/bin/su", &buf))
+		fatal("Could not locate command: /bin/su");
+	if (stat("/bin/echo", &buf))
+		fatal("Could not locate command: /bin/echo");
 	if (stat("/bin/env", &buf) == 0)
 		env_loc = "/bin/env";
 	else if (stat("/usr/bin/env", &buf) == 0)
-- 
GitLab