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
|
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <mqueue.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
int
main(int argc, char* argv[]) {
struct message_t msg = {.action = nop, .element = ELEMENT_INVALID};
char* queue_identifier;
if (argc != 3) {
errx(EXIT_FAILURE, "Invalid argument(s): %s ACTION ELEMENT\n", argv[0]);
}
if (!strcmp(argv[1], "update")) {
msg.action = update;
} else {
errx(EXIT_FAILURE, "Invalid action\n");
}
#define ELEMENT(identifier, _function, _arg, _minutes, _seconds) \
else if (!strcmp(argv[2], #identifier)) { \
msg.element = ELEMENT_##identifier; \
}
if (!strcmp(argv[2], "all")) {
msg.element = ELEMENT_MAX;
}
#include "config.def.h"
#undef ELEMENT
else {
errx(EXIT_FAILURE, "Invalid element\n");
}
queue_identifier = "/status";
mqd_t msg_queue_id = mq_open(queue_identifier, O_WRONLY);
if (msg_queue_id == -1) {
errx(EXIT_FAILURE, "Failed to open mq\n");
}
if (mq_send(msg_queue_id, (char*)&msg, sizeof(struct message_t), 0) == -1) {
err(EXIT_FAILURE, "Failed to send message\n");
}
mq_close(msg_queue_id);
return 0;
}
|