From e6ef17db7130e0a02978f763663425fe6e50a932 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Mon, 14 Oct 2002 19:47:44 +0000
Subject: [PATCH] Set job's default name to that of the executable.

---
 src/srun/opt.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/srun/opt.c b/src/srun/opt.c
index 3ce311e16d5..f22d4b7ea0d 100644
--- a/src/srun/opt.c
+++ b/src/srun/opt.c
@@ -283,6 +283,9 @@ static void opt_args(int, char **);
  */
 static bool opt_verify(poptContext, bool, bool, bool);
 
+/* return command name from its full path name */
+static char * base_name(char* command);
+
 /* list known options and their settings 
  */
 #if	__DEBUG
@@ -365,6 +368,27 @@ static enum distribution_t verify_dist_type(const char *arg)
 	return result;
 }
 
+/* return command name from its full path name */
+char * base_name(char* command)
+{
+	char *char_ptr, *name;
+	int i;
+
+	if (command == NULL)
+		return NULL;
+
+	char_ptr = strrchr(command, (int)'/');
+	if (char_ptr == NULL)
+		char_ptr = command;
+	else
+		char_ptr++;
+
+	i = strlen(char_ptr);
+	name = xmalloc(i+1);
+	strcpy(name, char_ptr);
+	return name;
+}
+
 /*
  * to_bytes(): verify that arg is numeric with optional "G" or "M" at end
  * if "G" or "M" is there, multiply by proper power of 2 and return
@@ -493,7 +517,7 @@ static void opt_default()
 	opt.time_limit = -1;
 	opt.partition = NULL;
 
-	opt.job_name = "";
+	opt.job_name = NULL;
 
 	opt.distribution = SRUN_DIST_BLOCK;
 
@@ -823,6 +847,9 @@ opt_verify(poptContext optctx,
 		verified = false;
 	}
 
+	if ((opt.job_name == NULL) && (remote_argc > 0))
+		opt.job_name = base_name(remote_argv[0]);
+
 	if (mode == MODE_ATTACH) {	/* attach to a running job */
 		if (nodes_set || cpus_set || procs_set) {
 			error("do not specific a node allocation "
@@ -1031,7 +1058,6 @@ print_commandline()
 	return xstrdup(buf);
 }
 
-
 #define tf_(b) (b == true) ? "true" : "false"
 
 static 
-- 
GitLab