-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnodes.c
139 lines (118 loc) · 3.38 KB
/
nodes.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/***************************************************************************
* Description:
* List currently running and queued nodes. Node info is queried from
* lpjs_dispatchd.
*
* History:
* Date Name Modification
* 2021-09-25 Jason Bacon Begin
***************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sysexits.h>
#include <xtend/string.h> // strlcat() on linux
#include "node-list.h"
#include "config.h"
#include "network.h"
#include "lpjs.h"
#include "misc.h"
#include "nodes-protos.h"
int main (int argc, char *argv[])
{
int msg_fd;
// Terminates process if malloc() fails, no check required
node_list_t *node_list = node_list_new();
char outgoing_msg[LPJS_MSG_LEN_MAX + 1];
extern FILE *Log_stream;
switch(argc)
{
case 1: // lpjs nodes
outgoing_msg[0] = LPJS_DISPATCHD_REQUEST_NODE_LIST;
outgoing_msg[1] = '\0';
break;
default:
if ( (strcmp(argv[1], "paused") == 0) ||
(strcmp(argv[1], "updating") == 0) ||
(strcmp(argv[1], "up") == 0) )
lpjs_set_node_state(argc, argv, outgoing_msg, LPJS_MSG_LEN_MAX + 1);
else
usage(argv);
}
// Shared functions may use lpjs_log
Log_stream = stderr;
// Get hostname of head node
lpjs_load_config(node_list, LPJS_CONFIG_HEAD_ONLY, stderr);
if ( (msg_fd = lpjs_connect_to_dispatchd(node_list)) == -1 )
{
perror("lpjs-nodes: Failed to connect to dispatch");
return EX_IOERR;
}
if ( lpjs_send_munge(msg_fd, outgoing_msg, close) != LPJS_MSG_SENT )
{
perror("lpjs-nodes: Failed to send message to dispatch");
close(msg_fd);
return EX_IOERR;
}
// fprintf(stderr, "LPJS_DISPATCHD_REQUEST_NODE_STATUS sent.\n");
lpjs_print_response(msg_fd, "lpjs-nodes");
close(msg_fd);
return EX_OK;
}
/***************************************************************************
* Use auto-c2man to generate a man page from this comment
*
* Name:
* -
*
* Library:
* #include <>
* -l
*
* Description:
*
* Arguments:
*
* Returns:
*
* Examples:
*
* Files:
*
* Environment
*
* See also:
*
* History:
* Date Name Modification
* 2024-05-10 Jason Bacon Begin
***************************************************************************/
int lpjs_set_node_state(int argc, char *argv[],
char *msg, size_t msg_max)
{
// lpjs nodes pause all | nodename [nodename ...]
if ( argc < 3 )
usage(argv);
// paused and updating are basically the same. The latter is to
// facilitate integration with SPCM, so it can easily identify
// nodes that were paused specifically for updates.
if ( (strcmp(argv[1], "paused") == 0) ||
(strcmp(argv[1], "updating") == 0) )
snprintf(msg, msg_max, "%c%s", LPJS_DISPATCHD_REQUEST_PAUSE, argv[1]);
else
snprintf(msg, msg_max, "%c%s", LPJS_DISPATCHD_REQUEST_RESUME, argv[1]);
for (int c = 2; c < argc; ++c)
{
if ( (strcmp(argv[c], "all") == 0) && ((c > 2) || (argc > 3)) )
usage(argv);
strlcat(msg, " ", msg_max);
strlcat(msg, argv[c], msg_max);
}
return 0; // FIXME: Define return codes
}
void usage(char *argv[])
{
fprintf (stderr, "Usage: %s nodes [paused|updating|up all|nodename [nodename...]]\n", argv[0]);
exit(EX_USAGE);
}