]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-send.c
tty-ask-password: Split out password sending
[thirdparty/systemd.git] / src / journal / test-journal-send.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2011 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25
26 #include "sd-journal.h"
27
28 #include "macro.h"
29
30 int main(int argc, char *argv[]) {
31 char huge[4096*1024];
32
33 /* utf-8 and non-utf-8, message-less and message-ful iovecs */
34 struct iovec graph1[] = {
35 {(char*) "GRAPH=graph", strlen("GRAPH=graph")}
36 };
37 struct iovec graph2[] = {
38 {(char*) "GRAPH=graph\n", strlen("GRAPH=graph\n")}
39 };
40 struct iovec message1[] = {
41 {(char*) "MESSAGE=graph", strlen("MESSAGE=graph")}
42 };
43 struct iovec message2[] = {
44 {(char*) "MESSAGE=graph\n", strlen("MESSAGE=graph\n")}
45 };
46
47 assert_se(sd_journal_print(LOG_INFO, "piepapo") == 0);
48
49 assert_se(sd_journal_send("MESSAGE=foobar",
50 "VALUE=%i", 7,
51 NULL) == 0);
52
53 errno = ENOENT;
54 assert_se(sd_journal_perror("Foobar") == 0);
55
56 assert_se(sd_journal_perror("") == 0);
57
58 memset(huge, 'x', sizeof(huge));
59 memcpy(huge, "HUGE=", 5);
60 char_array_0(huge);
61
62 assert_se(sd_journal_send("MESSAGE=Huge field attached",
63 huge,
64 NULL) == 0);
65
66 assert_se(sd_journal_send("MESSAGE=uiui",
67 "VALUE=A",
68 "VALUE=B",
69 "VALUE=C",
70 "SINGLETON=1",
71 "OTHERVALUE=X",
72 "OTHERVALUE=Y",
73 "WITH_BINARY=this is a binary value \a",
74 NULL) == 0);
75
76 syslog(LOG_NOTICE, "Hello World!");
77
78 assert_se(sd_journal_print(LOG_NOTICE, "Hello World") == 0);
79
80 assert_se(sd_journal_send("MESSAGE=Hello World!",
81 "MESSAGE_ID=52fb62f99e2c49d89cfbf9d6de5e3555",
82 "PRIORITY=5",
83 "HOME=%s", getenv("HOME"),
84 "TERM=%s", getenv("TERM"),
85 "PAGE_SIZE=%li", sysconf(_SC_PAGESIZE),
86 "N_CPUS=%li", sysconf(_SC_NPROCESSORS_ONLN),
87 NULL) == 0);
88
89 assert_se(sd_journal_sendv(graph1, 1) == 0);
90 assert_se(sd_journal_sendv(graph2, 1) == 0);
91 assert_se(sd_journal_sendv(message1, 1) == 0);
92 assert_se(sd_journal_sendv(message2, 1) == 0);
93
94 /* test without location fields */
95 #undef sd_journal_sendv
96 assert_se(sd_journal_sendv(graph1, 1) == 0);
97 assert_se(sd_journal_sendv(graph2, 1) == 0);
98 assert_se(sd_journal_sendv(message1, 1) == 0);
99 assert_se(sd_journal_sendv(message2, 1) == 0);
100
101 sleep(1);
102
103 return 0;
104 }