-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathshm_example_reader.c
More file actions
42 lines (34 loc) · 1008 Bytes
/
shm_example_reader.c
File metadata and controls
42 lines (34 loc) · 1008 Bytes
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
#include <libchronicle.h>
#include <stdarg.h>
#include <signal.h>
static volatile int keepRunning = 1;
// This is a stand-alone tool for reading a queue
// queue data is null-terminated strings, embedded nulls will truncate printing
void* parse_msg(unsigned char* base, int lim) {
char* msg = calloc(1, lim+1);
memcpy(msg, base, lim);
return msg;
}
void free_msg(void* msg) {
free(msg);
}
int print_msg(void* ctx, uint64_t index, void* msg) {
printf("[%" PRIu64 "] %s\n", index, (char*)msg);
return 0;
}
void sigint_handler(int dummy) {
keepRunning = 0;
}
int main(const int argc, char **argv) {
signal(SIGINT, sigint_handler);
queue_t* queue = chronicle_init(argv[1]);
chronicle_set_decoder(queue, &parse_msg, &free_msg);
if (chronicle_open(queue) != 0) exit(-1);
chronicle_tailer(queue, &print_msg, NULL, 0);
while (keepRunning) {
usleep(500*1000);
chronicle_peek();
}
printf("exiting\n");
chronicle_cleanup(queue);
}