forked from yqin/slurm-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spank_demo.c
107 lines (87 loc) · 2.63 KB
/
spank_demo.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
/*
* Copyright (c) 2016, Yong Qin <[email protected]>. All rights reserved.
*
* spank_demo.c : SPANK plugin to demonstrate when and where and by whom the
* function is called.
*
*
* gcc -shared -fPIC -o spank_demo.so spank_demo.c
*
* plugstack.conf:
* required /etc/slurm/spank/spank_demo.so
*
*/
#include <stdio.h>
#include <unistd.h>
#include <slurm/spank.h>
SPANK_PLUGIN (spank_demo, 1);
const char *myname = "spank_demo";
/* Display a message through Slurm SPANK system. */
int _display_msg(spank_t sp, char const *caller, char const *msg) {
uid_t uid = getuid();
gid_t gid = getgid();
char hostname[1024];
int ctx = spank_context();
char *ctx_str[] = {"ERROR", "LOCAL", "REMOTE", "ALLOCATOR", "SLURMD", "JOB_SCRIPT"};
hostname[1023] = '\0';
gethostname(hostname, 1023);
if (msg && msg[0]) {
slurm_info("%s: %s, %s, %s (uid=%d, gid=%d): %s", myname, ctx_str[ctx], hostname, caller, uid, gid, msg);
}
else {
slurm_info("%s: %s, %s, %s (uid=%d, gid=%d)", myname, ctx_str[ctx], hostname, caller, uid, gid);
}
return 0;
}
int slurm_spank_init (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}
int slurm_spank_slurmd_init (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}
int slurm_spank_job_prolog (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}
int slurm_spank_init_post_opt (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}
int slurm_spank_local_user_init (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}
int slurm_spank_user_init (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}
int slurm_spank_task_init_privileged (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}
int slurm_spank_task_init (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}
int slurm_spank_task_post_fork (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}
int slurm_spank_task_exit (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}
int slurm_spank_exit (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}
int slurm_spank_job_epilog (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}
int slurm_spank_slurmd_exit (spank_t sp, int ac, char **av) {
_display_msg(sp, __FUNCTION__, NULL);
return 0;
}