-
Notifications
You must be signed in to change notification settings - Fork 3
/
env-test.c
91 lines (70 loc) · 2.14 KB
/
env-test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Plugin to log the environment the job receives, for testing purposes.
*
* (C) 2018 Ghent University
*
* Author: Andy Georges
*
* Loosely based on Spank plugin private-tmpdir (c) HPC2N.umu.se
*
*/
/* Needs to be defined before first invocation of features.h so enable
* it early. */
#define _GNU_SOURCE /* See feature_test_macros(7) */
#define _XOPEN_SOURCE 500
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <slurm/spank.h>
#include <unistd.h>
SPANK_PLUGIN(env-test, 1);
// Default
// Globals
/*
* Called from both srun and slurmd.
*/
int slurm_spank_init(spank_t sp, int ac, char **av)
{
char **env = environ;
slurm_debug("spank: [env-test]: slurm_spank_init");
if (spank_context() == S_CTX_LOCAL) {
slurm_debug("spank: [env-test]: executing in local context");
} else if (spank_context() == S_CTX_REMOTE) {
slurm_debug("spank: [env-test]: executing in remote context");
}
while (*env != NULL) {
slurm_debug2("spank: [env-test]: %s", *env);
env++;
}
return ESPANK_SUCCESS;
}
int slurm_spank_exit(spank_t sp, int ac, char **av) {
return ESPANK_SUCCESS;
}
int slurm_spank_init_post_opt(spank_t sp, int ac, char **av)
{
char nodelist[8192];
spank_err_t err;
slurm_debug("spank: [env-test]: slurm_spank_init_post_op");
if (err = spank_getenv(sp, "SLURM_NODELIST", nodelist, 8192) != ESPANK_SUCCESS) {
slurm_error("spank: [env-test]: could not get SLURM_NODELIST");
return err;
}
slurm_debug("spank: [env-test]: SLURM_NODELIST: %s", nodelist);
return ESPANK_SUCCESS;
}
int slurm_spank_job_prolog(spank_t sp, int ac, char**av) {
char **env = environ;
slurm_debug("spank: [env-test]: slurm_spank_job_prolog");
if (spank_context() == S_CTX_LOCAL) {
slurm_debug("spank: [env-test]: executing in local context");
} else if (spank_context() == S_CTX_REMOTE) {
slurm_debug("spank: [env-test]: executing in remote context");
}
while (*env != NULL) {
slurm_debug2("spank: [env-test]: env var: %s", *env);
env++;
}
return ESPANK_SUCCESS;
}