diff --git a/src/srun/opt.c b/src/srun/opt.c index 3ce311e16d564c9e8ec27eeb4ce4cba6ac860fb3..f22d4b7ea0d9c1ae999d51dab4835f0d5787743f 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