File: | build-scan/../src/journal/cat.c |
Warning: | line 121, column 9 Value stored to 'fd' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | |
3 | #include <errno(*__errno_location ()).h> |
4 | #include <fcntl.h> |
5 | #include <getopt.h> |
6 | #include <stdio.h> |
7 | #include <stdlib.h> |
8 | #include <unistd.h> |
9 | |
10 | #include "sd-journal.h" |
11 | |
12 | #include "fd-util.h" |
13 | #include "parse-util.h" |
14 | #include "string-util.h" |
15 | #include "syslog-util.h" |
16 | #include "util.h" |
17 | |
18 | static const char *arg_identifier = NULL((void*)0); |
19 | static int arg_priority = LOG_INFO6; |
20 | static bool_Bool arg_level_prefix = true1; |
21 | |
22 | static void help(void) { |
23 | printf("%s [OPTIONS...] {COMMAND} ...\n\n" |
24 | "Execute process with stdout/stderr connected to the journal.\n\n" |
25 | " -h --help Show this help\n" |
26 | " --version Show package version\n" |
27 | " -t --identifier=STRING Set syslog identifier\n" |
28 | " -p --priority=PRIORITY Set priority value (0..7)\n" |
29 | " --level-prefix=BOOL Control whether level prefix shall be parsed\n" |
30 | , program_invocation_short_name); |
31 | } |
32 | |
33 | static int parse_argv(int argc, char *argv[]) { |
34 | |
35 | enum { |
36 | ARG_VERSION = 0x100, |
37 | ARG_LEVEL_PREFIX |
38 | }; |
39 | |
40 | static const struct option options[] = { |
41 | { "help", no_argument0, NULL((void*)0), 'h' }, |
42 | { "version", no_argument0, NULL((void*)0), ARG_VERSION }, |
43 | { "identifier", required_argument1, NULL((void*)0), 't' }, |
44 | { "priority", required_argument1, NULL((void*)0), 'p' }, |
45 | { "level-prefix", required_argument1, NULL((void*)0), ARG_LEVEL_PREFIX }, |
46 | {} |
47 | }; |
48 | |
49 | int c; |
50 | |
51 | assert(argc >= 0)do { if ((__builtin_expect(!!(!(argc >= 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("argc >= 0"), "../src/journal/cat.c", 51, __PRETTY_FUNCTION__); } while (0); |
52 | assert(argv)do { if ((__builtin_expect(!!(!(argv)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("argv"), "../src/journal/cat.c", 52, __PRETTY_FUNCTION__ ); } while (0); |
53 | |
54 | while ((c = getopt_long(argc, argv, "+ht:p:", options, NULL((void*)0))) >= 0) |
55 | |
56 | switch (c) { |
57 | |
58 | case 'h': |
59 | help(); |
60 | return 0; |
61 | |
62 | case ARG_VERSION: |
63 | return version(); |
64 | |
65 | case 't': |
66 | if (isempty(optarg)) |
67 | arg_identifier = NULL((void*)0); |
68 | else |
69 | arg_identifier = optarg; |
70 | break; |
71 | |
72 | case 'p': |
73 | arg_priority = log_level_from_string(optarg); |
74 | if (arg_priority < 0) { |
75 | log_error("Failed to parse priority value.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/journal/cat.c", 75, __func__, "Failed to parse priority value." ) : -abs(_e); }); |
76 | return -EINVAL22; |
77 | } |
78 | break; |
79 | |
80 | case ARG_LEVEL_PREFIX: { |
81 | int k; |
82 | |
83 | k = parse_boolean(optarg); |
84 | if (k < 0) |
85 | return log_error_errno(k, "Failed to parse level prefix value.")({ int _level = ((3)), _e = ((k)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/journal/cat.c", 85, __func__, "Failed to parse level prefix value." ) : -abs(_e); }); |
86 | |
87 | arg_level_prefix = k; |
88 | break; |
89 | } |
90 | |
91 | case '?': |
92 | return -EINVAL22; |
93 | |
94 | default: |
95 | assert_not_reached("Unhandled option")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, ( "Unhandled option"), "../src/journal/cat.c", 95, __PRETTY_FUNCTION__ ); } while (0); |
96 | } |
97 | |
98 | return 1; |
99 | } |
100 | |
101 | int main(int argc, char *argv[]) { |
102 | _cleanup_close___attribute__((cleanup(closep))) int fd = -1, saved_stderr = -1; |
103 | int r; |
104 | |
105 | log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD); |
106 | log_open(); |
107 | |
108 | r = parse_argv(argc, argv); |
109 | if (r <= 0) |
110 | goto finish; |
111 | |
112 | fd = sd_journal_stream_fd(arg_identifier, arg_priority, arg_level_prefix); |
113 | if (fd < 0) { |
114 | r = log_error_errno(fd, "Failed to create stream fd: %m")({ int _level = ((3)), _e = ((fd)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/journal/cat.c", 114, __func__, "Failed to create stream fd: %m" ) : -abs(_e); }); |
115 | goto finish; |
116 | } |
117 | |
118 | saved_stderr = fcntl(STDERR_FILENO2, F_DUPFD_CLOEXEC1030, 3); |
119 | |
120 | r = rearrange_stdio(STDIN_FILENO0, fd, fd); /* Invalidates fd on succcess + error! */ |
121 | fd = -1; |
Value stored to 'fd' is never read | |
122 | if (r < 0) { |
123 | log_error_errno(r, "Failed to rearrange stdout/stderr: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/journal/cat.c", 123, __func__, "Failed to rearrange stdout/stderr: %m" ) : -abs(_e); }); |
124 | goto finish; |
125 | } |
126 | |
127 | if (argc <= optind) |
128 | (void) execl("/bin/cat", "/bin/cat", NULL((void*)0)); |
129 | else |
130 | (void) execvp(argv[optind], argv + optind); |
131 | r = -errno(*__errno_location ()); |
132 | |
133 | /* Let's try to restore a working stderr, so we can print the error message */ |
134 | if (saved_stderr >= 0) |
135 | (void) dup3(saved_stderr, STDERR_FILENO2, 0); |
136 | |
137 | log_error_errno(r, "Failed to execute process: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/journal/cat.c", 137, __func__, "Failed to execute process: %m" ) : -abs(_e); }); |
138 | |
139 | finish: |
140 | return r < 0 ? EXIT_FAILURE1 : EXIT_SUCCESS0; |
141 | } |