Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */
2 :
3 : #include <errno.h>
4 : #include <stdlib.h>
5 : #include <unistd.h>
6 :
7 : #include "sd-journal.h"
8 :
9 : #include "macro.h"
10 :
11 1 : int main(int argc, char *argv[]) {
12 : char huge[4096*1024];
13 :
14 : /* utf-8 and non-utf-8, message-less and message-ful iovecs */
15 1 : struct iovec graph1[] = {
16 : {(char*) "GRAPH=graph", STRLEN("GRAPH=graph")}
17 : };
18 1 : struct iovec graph2[] = {
19 : {(char*) "GRAPH=graph\n", STRLEN("GRAPH=graph\n")}
20 : };
21 1 : struct iovec message1[] = {
22 : {(char*) "MESSAGE=graph", STRLEN("MESSAGE=graph")}
23 : };
24 1 : struct iovec message2[] = {
25 : {(char*) "MESSAGE=graph\n", STRLEN("MESSAGE=graph\n")}
26 : };
27 :
28 1 : assert_se(sd_journal_print(LOG_INFO, "piepapo") == 0);
29 :
30 1 : assert_se(sd_journal_send("MESSAGE=foobar",
31 : "VALUE=%i", 7,
32 : NULL) == 0);
33 :
34 1 : errno = ENOENT;
35 1 : assert_se(sd_journal_perror("Foobar") == 0);
36 :
37 1 : assert_se(sd_journal_perror("") == 0);
38 :
39 1 : memset(huge, 'x', sizeof(huge));
40 1 : memcpy(huge, "HUGE=", 5);
41 1 : char_array_0(huge);
42 :
43 1 : assert_se(sd_journal_send("MESSAGE=Huge field attached",
44 : huge,
45 : NULL) == 0);
46 :
47 1 : assert_se(sd_journal_send("MESSAGE=uiui",
48 : "VALUE=A",
49 : "VALUE=B",
50 : "VALUE=C",
51 : "SINGLETON=1",
52 : "OTHERVALUE=X",
53 : "OTHERVALUE=Y",
54 : "WITH_BINARY=this is a binary value \a",
55 : NULL) == 0);
56 :
57 1 : syslog(LOG_NOTICE, "Hello World!");
58 :
59 1 : assert_se(sd_journal_print(LOG_NOTICE, "Hello World") == 0);
60 :
61 1 : assert_se(sd_journal_send("MESSAGE=Hello World!",
62 : "MESSAGE_ID=52fb62f99e2c49d89cfbf9d6de5e3555",
63 : "PRIORITY=5",
64 : "HOME=%s", getenv("HOME"),
65 : "TERM=%s", getenv("TERM"),
66 : "PAGE_SIZE=%li", sysconf(_SC_PAGESIZE),
67 : "N_CPUS=%li", sysconf(_SC_NPROCESSORS_ONLN),
68 : NULL) == 0);
69 :
70 1 : assert_se(sd_journal_sendv(graph1, 1) == 0);
71 1 : assert_se(sd_journal_sendv(graph2, 1) == 0);
72 1 : assert_se(sd_journal_sendv(message1, 1) == 0);
73 1 : assert_se(sd_journal_sendv(message2, 1) == 0);
74 :
75 : /* test without location fields */
76 : #undef sd_journal_sendv
77 1 : assert_se(sd_journal_sendv(graph1, 1) == 0);
78 1 : assert_se(sd_journal_sendv(graph2, 1) == 0);
79 1 : assert_se(sd_journal_sendv(message1, 1) == 0);
80 1 : assert_se(sd_journal_sendv(message2, 1) == 0);
81 :
82 1 : sleep(1);
83 :
84 1 : return 0;
85 : }
|