]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-init.c
util-lib: split string parsing related calls from util.[ch] into parse-util.[ch]
[thirdparty/systemd.git] / src / journal / test-journal-init.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2013 Zbigniew Jędrzejewski-Szmek
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 "sd-journal.h"
23
24 #include "log.h"
25 #include "parse-util.h"
26 #include "rm-rf.h"
27 #include "util.h"
28
29 int main(int argc, char *argv[]) {
30 sd_journal *j;
31 int r, i, I = 100;
32 char t[] = "/tmp/journal-stream-XXXXXX";
33
34 log_set_max_level(LOG_DEBUG);
35
36 if (argc >= 2) {
37 r = safe_atoi(argv[1], &I);
38 if (r < 0)
39 log_info("Could not parse loop count argument. Using default.");
40 }
41
42 log_info("Running %d loops", I);
43
44 assert_se(mkdtemp(t));
45
46 for (i = 0; i < I; i++) {
47 r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
48 assert_se(r == 0);
49
50 sd_journal_close(j);
51
52 r = sd_journal_open_directory(&j, t, 0);
53 assert_se(r == 0);
54
55 sd_journal_close(j);
56
57 j = NULL;
58 r = sd_journal_open_directory(&j, t, SD_JOURNAL_LOCAL_ONLY);
59 assert_se(r == -EINVAL);
60 assert_se(j == NULL);
61 }
62
63 assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
64
65 return 0;
66 }