-
Notifications
You must be signed in to change notification settings - Fork 13
/
system-safe.c
123 lines (101 loc) · 3.03 KB
/
system-safe.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*****************************************************************************
*
* Copyright (C) 2007-2008 Lawrence Livermore National Security, LLC.
* Produced at Lawrence Livermore National Laboratory.
* Written by Mark Grondona <mgrondona@llnl.gov>.
*
* UCRL-CODE-235358
*
* This file is part of chaos-spankings, a set of spank plugins for SLURM.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <slurm/spank.h>
/*
* All spank plugins must define this macro for the SLURM plugin loader.
*/
SPANK_PLUGIN(system-safe, 1)
#define SYSTEM_SAFE_ENABLE 0x0
#define SYSTEM_SAFE_DISABLE 0x1
/*
* Disabled by default
*/
static int enabled = 0;
static int opt_enable = 0;
static int opt_disable = 0;
static int _opt_process (int val, const char *optarg, int remote);
/*
* Provide a --renice=[prio] option to srun:
*/
struct spank_option spank_options[] =
{
{ "system-safe", NULL, "Replace system(3) with version safe for MPI.",
0, SYSTEM_SAFE_ENABLE,
(spank_opt_cb_f) _opt_process
},
{ "no-system-safe", NULL, "Disable system(3) replacement.",
0, SYSTEM_SAFE_DISABLE,
(spank_opt_cb_f) _opt_process
},
SPANK_OPTIONS_TABLE_END
};
/*
* Called from both srun and slurmd.
*/
int slurm_spank_init (spank_t sp, int ac, char **av)
{
int i;
if (!spank_remote (sp))
return (0);
for (i = 0; i < ac; i++) {
if (strncmp ("enabled", av[i], 7) == 0) {
enabled = 1;
}
else if (strncmp ("disabled", av[i], 8) == 0) {
enabled = 0;
}
else {
slurm_error ("system-safe: Invalid option \"%s\"", av[i]);
}
}
return (0);
}
int slurm_spank_user_init (spank_t sp, int ac, char **av)
{
char buf [4096];
const char *preload = "system-safe-preload.so";
if (opt_disable || (!enabled && !opt_enable))
return (0);
if (spank_getenv (sp, "LD_PRELOAD", buf, sizeof (buf)) == ESPANK_SUCCESS)
snprintf (buf, sizeof (buf), "%s %s", buf, preload);
else
strncpy (buf, preload, strlen (preload));
if (spank_setenv (sp, "LD_PRELOAD", buf, 1) != ESPANK_SUCCESS)
slurm_error ("Failed to set LD_PRELOAD=%s\n", buf);
return (0);
}
static int _opt_process (int val, const char *optarg, int remote)
{
if (val == SYSTEM_SAFE_ENABLE)
opt_enable = 1;
else
opt_disable = 0;
return (0);
}
/*
* vi: ts=4 sw=4 expandtab
*/