Skip to content

Commit

Permalink
Add keywords: SLURM_JOB_USERNAME, SLURM_JOBUID
Browse files Browse the repository at this point in the history
  • Loading branch information
fafik23 authored and grondo committed Sep 29, 2014
1 parent ddb37e5 commit 793658e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
PACKAGE ?= slurm-spank-plugins

sysconfdir ?= /etc/slurm/

LIBNAME ?= lib$(shell uname -m | grep -q x86_64 && echo 64)
LIBDIR ?= /usr/$(LIBNAME)
BINDIR ?= /usr/bin
Expand Down
7 changes: 5 additions & 2 deletions use-env/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

LIBDIR ?= /usr/lib$(shell uname -m | grep -q x86_64 && echo 64)

sysconfdir ?= /etc/slurm/

OBJS := lex.yy.o use-env-parser.o ../lib/list.o log_msg.o ../lib/split.o
HDRS := use-env.h ../lib/list.h ../lib/split.h log_msg.h use-env-parser.h
SHOPTS := -shared -Wl,--version-script=version.map
DEFS := -DSYSCONFDIR=\"$(sysconfdir)\"


all: use-env.so test
Expand All @@ -22,10 +25,10 @@ check: test
./test -f test.conf

.c.o :
$(CC) -ggdb -I../lib -Wall $(CFLAGS) -o $@ -fPIC -c $<
$(CC) $(DEFS) -ggdb -I../lib -Wall $(CFLAGS) -o $@ -fPIC -c $<

use-env-parser.c use-env-parser.h : use-env-parser.y
bison -d -o use-env-parser.c $<
bison -d -o use-env-parser.c $<

lex.yy.c : use-env-parser.l use-env-parser.h
lex $<
Expand Down
6 changes: 4 additions & 2 deletions use-env/use-env-parser.l
Original file line number Diff line number Diff line change
Expand Up @@ -870,13 +870,15 @@ int print_sym (struct sym *s, void *arg)
void dump_symbols (void)
{
log_msg ("Dumping symbols\n");
list_for_each (symtab, (ListForF) print_sym, NULL);
if (symtab)
list_for_each (symtab, (ListForF) print_sym, NULL);
}

void dump_keywords (void)
{
log_msg ("Dumping keywords\n");
list_for_each (keytab, (ListForF) print_sym, NULL);
if (keytab)
list_for_each (keytab, (ListForF) print_sym, NULL);
}

/****************************************************************************
Expand Down
27 changes: 24 additions & 3 deletions use-env/use-env.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <string.h>
#include <dlfcn.h>

#include <pwd.h>

#include <slurm/spank.h>

#include "use-env.h"
Expand All @@ -38,6 +40,11 @@
#define NO_SEARCH_SYSTEM 1<<0
#define NO_SEARCH_USER 1<<1

#ifndef SYSCONFDIR
#define SYSCONFDIR "/etc/slurm/"
#endif


SPANK_PLUGIN(use-env, 1)

/****************************************************************************
Expand Down Expand Up @@ -76,7 +83,7 @@ struct spank_option spank_options[] =
{
{ "use-env", "[name]",
"Read env from ~/.slurm/environment/[name] or "
"/etc/slurm/environment/[name]", 1, 0,
SYSCONFDIR "/environment/[name]", 1, 0,
(spank_opt_cb_f) use_env_opt_process
},
SPANK_OPTIONS_TABLE_END
Expand Down Expand Up @@ -265,10 +272,10 @@ env_override_file_search (char *path, size_t len, const char *name, int flags)
}

if (check_sys) {
snprintf (path, len, "/etc/slurm/environment/%s", name);
snprintf (path, len, SYSCONFDIR "/environment/%s", name);
if (access (path, R_OK) >= 0)
return (path);
snprintf (path, len, "/etc/slurm/env-%s.conf", name);
snprintf (path, len, SYSCONFDIR "/env-%s.conf", name);
if (access (path, R_OK) >= 0)
return (path);
}
Expand Down Expand Up @@ -415,6 +422,8 @@ static int set_argv_keywords (spank_t sp)

static int define_all_keywords (spank_t sp)
{
struct passwd *pw;
uid_t uid;
/*
* These keywords are only accessible from this context
*/
Expand All @@ -439,6 +448,18 @@ static int define_all_keywords (spank_t sp)
return (-1);
if (define_use_env_keyword (sp, "SLURM_NODEID", S_JOB_NODEID) < 0)
return (-1);
if (define_use_env_keyword (sp, "SLURM_JOBUID", S_JOB_UID) < 0)
return (-1);
if (spank_get_item (sp, S_JOB_UID, &uid) != ESPANK_SUCCESS) {
slurm_error ("use-env: spank_get_item failed for S_JOB_UID\n");
return (-1);
}
if (!(pw = getpwuid (uid))) {
slurm_error ("use-env: Error looking up uid in /etc/passwd");
return (-1);
}
if (keyword_define ("SLURM_JOB_USERNAME", pw->pw_name) == NULL)
return (-1);

return (0);
}
Expand Down

0 comments on commit 793658e

Please sign in to comment.