]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/journal-util.c
2 This file is part of systemd.
4 Copyright 2013 Zbigniew Jędrzejewski-Szmek
5 Copyright 2015 Lennart Poettering
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "journal-internal.h"
25 #include "journal-util.h"
28 #include "user-util.h"
30 static int access_check_var_log_journal(sd_journal
*j
) {
32 _cleanup_strv_free_
char **g
= NULL
;
39 /* If we are root, we should have access, don't warn. */
43 /* If we are in the 'systemd-journal' group, we should have
45 r
= in_group("systemd-journal");
47 return log_error_errno(r
, "Failed to check if we are in the 'systemd-journal' group: %m");
52 if (laccess("/run/log/journal", F_OK
) >= 0)
53 dir
= "/run/log/journal";
55 dir
= "/var/log/journal";
57 /* If we are in any of the groups listed in the journal ACLs,
58 * then all is good, too. Let's enumerate all groups from the
59 * default ACL of the directory, which generally should allow
60 * access to most journal files too. */
61 r
= acl_search_groups(dir
, &g
);
63 return log_error_errno(r
, "Failed to search journal ACL: %m");
67 /* Print a pretty list, if there were ACLs set. */
68 if (!strv_isempty(g
)) {
69 _cleanup_free_
char *s
= NULL
;
71 /* Thre are groups in the ACL, let's list them */
72 r
= strv_extend(&g
, "systemd-journal");
79 s
= strv_join(g
, "', '");
83 log_notice("Hint: You are currently not seeing messages from other users and the system.\n"
84 " Users in groups '%s' can see all messages.\n"
85 " Pass -q to turn off this notice.", s
);
90 /* If no ACLs were found, print a short version of the message. */
91 log_notice("Hint: You are currently not seeing messages from other users and the system.\n"
92 " Users in the 'systemd-journal' group can see all messages. Pass -q to\n"
93 " turn off this notice.");
98 int journal_access_check_and_warn(sd_journal
*j
, bool quiet
) {
106 if (hashmap_isempty(j
->errors
)) {
107 if (ordered_hashmap_isempty(j
->files
) && !quiet
)
108 log_notice("No journal files were found.");
113 if (hashmap_contains(j
->errors
, INT_TO_PTR(-EACCES
))) {
115 (void) access_check_var_log_journal(j
);
117 if (ordered_hashmap_isempty(j
->files
))
118 r
= log_error_errno(EACCES
, "No journal files were opened due to insufficient permissions.");
121 HASHMAP_FOREACH_KEY(path
, code
, j
->errors
, it
) {
124 err
= abs(PTR_TO_INT(code
));
131 log_warning_errno(err
, "Journal file %s is truncated, ignoring file.", path
);
134 case EPROTONOSUPPORT
:
135 log_warning_errno(err
, "Journal file %1$s uses an unsupported feature, ignoring file.\n"
136 "Use SYSTEMD_LOG_LEVEL=debug journalctl --file=%1$s to see the details.",
141 log_warning_errno(err
, "Journal file %s corrupted, ignoring file.", path
);
145 log_warning_errno(err
, "An error was encountered while opening journal file or directory %s, ignoring file: %m", path
);