From 6c3383c302e0103f6a62d20976be4b66ef79bf08 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Thu, 8 May 2008 22:38:14 +0000
Subject: [PATCH] look for env executable in both /bin/env and /usr/bin/env
 (for SLES)

---
 src/common/env.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/common/env.c b/src/common/env.c
index bb0eac3570f..61bb6c47811 100644
--- a/src/common/env.c
+++ b/src/common/env.c
@@ -48,6 +48,7 @@
 #include <strings.h>
 #include <unistd.h>
 #include <sys/poll.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/param.h>		/* MAXPATHLEN */
 #include "src/common/macros.h"
@@ -1317,12 +1318,20 @@ char **env_array_user_default(const char *username, int timeout, int mode)
 	char **env = NULL;
 	char *starttoken = "XXXXSLURMSTARTPARSINGHEREXXXX";
 	char *stoptoken  = "XXXXSLURMSTOPPARSINGHEREXXXXX";
-	char cmdstr[256];
+	char cmdstr[256], *env_loc = NULL;
 	int fildes[2], found, fval, len, rc, timeleft;
 	int buf_read, buf_rem;
 	pid_t child;
 	struct timeval begin, now;
 	struct pollfd ufds;
+	struct stat buf;
+
+	if (stat("/bin/env", &buf) == 0)
+		env_loc = "/bin/env";
+	else if (stat("/usr/bin/env", &buf) == 0)
+		env_loc = "/usr/bin/env";
+	else
+		fatal("Could not location command: env");
 
 	if (geteuid() != (uid_t)0) {
 		fatal("WARNING: you must be root to use --get-user-env");
@@ -1347,8 +1356,8 @@ char **env_array_user_default(const char *username, int timeout, int mode)
 		open("/dev/null", O_WRONLY);
 		snprintf(cmdstr, sizeof(cmdstr),
 			 "/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);
 		if      (mode == 1)
 			execl("/bin/su", "su", username, "-c", cmdstr, NULL);
 		else if (mode == 2)
-- 
GitLab