]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/analyze/analyze.c
analyze: set reverse_offset for containerized system
[thirdparty/systemd.git] / src / analyze / analyze.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright © 2013 Simon Peeters
4 ***/
5
6 #include <getopt.h>
7 #include <locale.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 #include "sd-bus.h"
12
13 #include "alloc-util.h"
14 #include "analyze-verify.h"
15 #include "bus-error.h"
16 #include "bus-unit-util.h"
17 #include "bus-util.h"
18 #include "calendarspec.h"
19 #include "def.h"
20 #include "conf-files.h"
21 #include "copy.h"
22 #include "fd-util.h"
23 #include "glob-util.h"
24 #include "hashmap.h"
25 #include "locale-util.h"
26 #include "log.h"
27 #include "pager.h"
28 #include "parse-util.h"
29 #include "path-util.h"
30 #if HAVE_SECCOMP
31 #include "seccomp-util.h"
32 #endif
33 #include "special.h"
34 #include "strv.h"
35 #include "strxcpyx.h"
36 #include "terminal-util.h"
37 #include "unit-name.h"
38 #include "util.h"
39 #include "verbs.h"
40
41 #define SCALE_X (0.1 / 1000.0) /* pixels per us */
42 #define SCALE_Y (20.0)
43
44 #define compare(a, b) (((a) > (b))? 1 : (((b) > (a))? -1 : 0))
45
46 #define svg(...) printf(__VA_ARGS__)
47
48 #define svg_bar(class, x1, x2, y) \
49 svg(" <rect class=\"%s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n", \
50 (class), \
51 SCALE_X * (x1), SCALE_Y * (y), \
52 SCALE_X * ((x2) - (x1)), SCALE_Y - 1.0)
53
54 #define svg_text(b, x, y, format, ...) \
55 do { \
56 svg(" <text class=\"%s\" x=\"%.03f\" y=\"%.03f\">", (b) ? "left" : "right", SCALE_X * (x) + (b ? 5.0 : -5.0), SCALE_Y * (y) + 14.0); \
57 svg(format, ## __VA_ARGS__); \
58 svg("</text>\n"); \
59 } while (false)
60
61 static enum dot {
62 DEP_ALL,
63 DEP_ORDER,
64 DEP_REQUIRE
65 } arg_dot = DEP_ALL;
66 static char** arg_dot_from_patterns = NULL;
67 static char** arg_dot_to_patterns = NULL;
68 static usec_t arg_fuzz = 0;
69 static bool arg_no_pager = false;
70 static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
71 static const char *arg_host = NULL;
72 static UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
73 static bool arg_man = true;
74 static bool arg_generators = false;
75 static const char *arg_root = NULL;
76
77 struct boot_times {
78 usec_t firmware_time;
79 usec_t loader_time;
80 usec_t kernel_time;
81 usec_t kernel_done_time;
82 usec_t initrd_time;
83 usec_t userspace_time;
84 usec_t finish_time;
85 usec_t security_start_time;
86 usec_t security_finish_time;
87 usec_t generators_start_time;
88 usec_t generators_finish_time;
89 usec_t unitsload_start_time;
90 usec_t unitsload_finish_time;
91 usec_t initrd_security_start_time;
92 usec_t initrd_security_finish_time;
93 usec_t initrd_generators_start_time;
94 usec_t initrd_generators_finish_time;
95 usec_t initrd_unitsload_start_time;
96 usec_t initrd_unitsload_finish_time;
97
98 /*
99 * If we're analyzing the user instance, all timestamps will be offset
100 * by its own start-up timestamp, which may be arbitrarily big.
101 * With "plot", this causes arbitrarily wide output SVG files which almost
102 * completely consist of empty space. Thus we cancel out this offset.
103 *
104 * This offset is subtracted from times above by acquire_boot_times(),
105 * but it still needs to be subtracted from unit-specific timestamps
106 * (so it is stored here for reference).
107 */
108 usec_t reverse_offset;
109 };
110
111 struct unit_times {
112 bool has_data;
113 char *name;
114 usec_t activating;
115 usec_t activated;
116 usec_t deactivated;
117 usec_t deactivating;
118 usec_t time;
119 };
120
121 struct host_info {
122 char *hostname;
123 char *kernel_name;
124 char *kernel_release;
125 char *kernel_version;
126 char *os_pretty_name;
127 char *virtualization;
128 char *architecture;
129 };
130
131 static int acquire_bus(sd_bus **bus, bool *use_full_bus) {
132 bool user = arg_scope != UNIT_FILE_SYSTEM;
133 int r;
134
135 if (use_full_bus && *use_full_bus) {
136 r = bus_connect_transport(arg_transport, arg_host, user, bus);
137 if (IN_SET(r, 0, -EHOSTDOWN))
138 return r;
139
140 *use_full_bus = false;
141 }
142
143 return bus_connect_transport_systemd(arg_transport, arg_host, user, bus);
144 }
145
146 static int bus_get_uint64_property(sd_bus *bus, const char *path, const char *interface, const char *property, uint64_t *val) {
147 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
148 int r;
149
150 assert(bus);
151 assert(path);
152 assert(interface);
153 assert(property);
154 assert(val);
155
156 r = sd_bus_get_property_trivial(
157 bus,
158 "org.freedesktop.systemd1",
159 path,
160 interface,
161 property,
162 &error,
163 't', val);
164
165 if (r < 0) {
166 log_error("Failed to parse reply: %s", bus_error_message(&error, -r));
167 return r;
168 }
169
170 return 0;
171 }
172
173 static int bus_get_unit_property_strv(sd_bus *bus, const char *path, const char *property, char ***strv) {
174 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
175 int r;
176
177 assert(bus);
178 assert(path);
179 assert(property);
180 assert(strv);
181
182 r = sd_bus_get_property_strv(
183 bus,
184 "org.freedesktop.systemd1",
185 path,
186 "org.freedesktop.systemd1.Unit",
187 property,
188 &error,
189 strv);
190 if (r < 0) {
191 log_error("Failed to get unit property %s: %s", property, bus_error_message(&error, -r));
192 return r;
193 }
194
195 return 0;
196 }
197
198 static int compare_unit_time(const void *a, const void *b) {
199 return compare(((struct unit_times *)b)->time,
200 ((struct unit_times *)a)->time);
201 }
202
203 static int compare_unit_start(const void *a, const void *b) {
204 return compare(((struct unit_times *)a)->activating,
205 ((struct unit_times *)b)->activating);
206 }
207
208 static void unit_times_free(struct unit_times *t) {
209 struct unit_times *p;
210
211 for (p = t; p->has_data; p++)
212 free(p->name);
213 free(t);
214 }
215
216 DEFINE_TRIVIAL_CLEANUP_FUNC(struct unit_times *, unit_times_free);
217
218 static void subtract_timestamp(usec_t *a, usec_t b) {
219 assert(a);
220
221 if (*a > 0) {
222 assert(*a >= b);
223 *a -= b;
224 }
225 }
226
227 static int acquire_boot_times(sd_bus *bus, struct boot_times **bt) {
228 static const struct bus_properties_map property_map[] = {
229 { "FirmwareTimestampMonotonic", "t", NULL, offsetof(struct boot_times, firmware_time) },
230 { "LoaderTimestampMonotonic", "t", NULL, offsetof(struct boot_times, loader_time) },
231 { "KernelTimestamp", "t", NULL, offsetof(struct boot_times, kernel_time) },
232 { "InitRDTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_time) },
233 { "UserspaceTimestampMonotonic", "t", NULL, offsetof(struct boot_times, userspace_time) },
234 { "FinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, finish_time) },
235 { "SecurityStartTimestampMonotonic", "t", NULL, offsetof(struct boot_times, security_start_time) },
236 { "SecurityFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, security_finish_time) },
237 { "GeneratorsStartTimestampMonotonic", "t", NULL, offsetof(struct boot_times, generators_start_time) },
238 { "GeneratorsFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, generators_finish_time) },
239 { "UnitsLoadStartTimestampMonotonic", "t", NULL, offsetof(struct boot_times, unitsload_start_time) },
240 { "UnitsLoadFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, unitsload_finish_time) },
241 { "InitRDSecurityStartTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_security_start_time) },
242 { "InitRDSecurityFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_security_finish_time) },
243 { "InitRDGeneratorsStartTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_generators_start_time) },
244 { "InitRDGeneratorsFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_generators_finish_time) },
245 { "InitRDUnitsLoadStartTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_unitsload_start_time) },
246 { "InitRDUnitsLoadFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_unitsload_finish_time) },
247 {},
248 };
249 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
250 static struct boot_times times;
251 static bool cached = false;
252 int r;
253
254 if (cached)
255 goto finish;
256
257 assert_cc(sizeof(usec_t) == sizeof(uint64_t));
258
259 r = bus_map_all_properties(
260 bus,
261 "org.freedesktop.systemd1",
262 "/org/freedesktop/systemd1",
263 property_map,
264 BUS_MAP_STRDUP,
265 &error,
266 NULL,
267 &times);
268 if (r < 0)
269 return log_error_errno(r, "Failed to get timestamp properties: %s", bus_error_message(&error, r));
270
271 if (times.finish_time <= 0) {
272 log_error("Bootup is not yet finished (org.freedesktop.systemd1.Manager.FinishTimestampMonotonic=%"PRIu64").\n"
273 "Please try again later.\n"
274 "Hint: Use 'systemctl%s list-jobs' to see active jobs",
275 times.finish_time,
276 arg_scope == UNIT_FILE_SYSTEM ? "" : " --user");
277 return -EINPROGRESS;
278 }
279
280 if (arg_scope == UNIT_FILE_SYSTEM && times.security_start_time > 0) {
281 /* security_start_time is set when systemd is not running under container environment. */
282 if (times.initrd_time > 0)
283 times.kernel_done_time = times.initrd_time;
284 else
285 times.kernel_done_time = times.userspace_time;
286 } else {
287 /*
288 * User-instance-specific or container-system-specific timestamps processing
289 * (see comment to reverse_offset in struct boot_times).
290 */
291 times.reverse_offset = times.userspace_time;
292
293 times.firmware_time = times.loader_time = times.kernel_time = times.initrd_time = times.userspace_time =
294 times.security_start_time = times.security_finish_time = 0;
295
296 subtract_timestamp(&times.finish_time, times.reverse_offset);
297
298 subtract_timestamp(&times.generators_start_time, times.reverse_offset);
299 subtract_timestamp(&times.generators_finish_time, times.reverse_offset);
300
301 subtract_timestamp(&times.unitsload_start_time, times.reverse_offset);
302 subtract_timestamp(&times.unitsload_finish_time, times.reverse_offset);
303 }
304
305 cached = true;
306
307 finish:
308 *bt = &times;
309 return 0;
310 }
311
312 static void free_host_info(struct host_info *hi) {
313
314 if (!hi)
315 return;
316
317 free(hi->hostname);
318 free(hi->kernel_name);
319 free(hi->kernel_release);
320 free(hi->kernel_version);
321 free(hi->os_pretty_name);
322 free(hi->virtualization);
323 free(hi->architecture);
324 free(hi);
325 }
326
327 DEFINE_TRIVIAL_CLEANUP_FUNC(struct host_info*, free_host_info);
328
329 static int acquire_time_data(sd_bus *bus, struct unit_times **out) {
330 static const struct bus_properties_map property_map[] = {
331 { "InactiveExitTimestampMonotonic", "t", NULL, offsetof(struct unit_times, activating) },
332 { "ActiveEnterTimestampMonotonic", "t", NULL, offsetof(struct unit_times, activated) },
333 { "ActiveExitTimestampMonotonic", "t", NULL, offsetof(struct unit_times, deactivating) },
334 { "InactiveEnterTimestampMonotonic", "t", NULL, offsetof(struct unit_times, deactivated) },
335 {},
336 };
337 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
338 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
339 _cleanup_(unit_times_freep) struct unit_times *unit_times = NULL;
340 struct boot_times *boot_times = NULL;
341 size_t allocated = 0, c = 0;
342 UnitInfo u;
343 int r;
344
345 r = acquire_boot_times(bus, &boot_times);
346 if (r < 0)
347 return r;
348
349 r = sd_bus_call_method(
350 bus,
351 "org.freedesktop.systemd1",
352 "/org/freedesktop/systemd1",
353 "org.freedesktop.systemd1.Manager",
354 "ListUnits",
355 &error, &reply,
356 NULL);
357 if (r < 0) {
358 log_error("Failed to list units: %s", bus_error_message(&error, -r));
359 return r;
360 }
361
362 r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssssouso)");
363 if (r < 0)
364 return bus_log_parse_error(r);
365
366 while ((r = bus_parse_unit_info(reply, &u)) > 0) {
367 struct unit_times *t;
368
369 if (!GREEDY_REALLOC(unit_times, allocated, c+2))
370 return log_oom();
371
372 unit_times[c+1].has_data = false;
373 t = &unit_times[c];
374 t->name = NULL;
375
376 assert_cc(sizeof(usec_t) == sizeof(uint64_t));
377
378 r = bus_map_all_properties(
379 bus,
380 "org.freedesktop.systemd1",
381 u.unit_path,
382 property_map,
383 BUS_MAP_STRDUP,
384 &error,
385 NULL,
386 t);
387 if (r < 0)
388 return log_error_errno(r, "Failed to get timestamp properties of unit %s: %s", u.id, bus_error_message(&error, r));
389
390 subtract_timestamp(&t->activating, boot_times->reverse_offset);
391 subtract_timestamp(&t->activated, boot_times->reverse_offset);
392 subtract_timestamp(&t->deactivating, boot_times->reverse_offset);
393 subtract_timestamp(&t->deactivated, boot_times->reverse_offset);
394
395 if (t->activated >= t->activating)
396 t->time = t->activated - t->activating;
397 else if (t->deactivated >= t->activating)
398 t->time = t->deactivated - t->activating;
399 else
400 t->time = 0;
401
402 if (t->activating == 0)
403 continue;
404
405 t->name = strdup(u.id);
406 if (!t->name)
407 return log_oom();
408
409 t->has_data = true;
410 c++;
411 }
412 if (r < 0)
413 return bus_log_parse_error(r);
414
415 *out = TAKE_PTR(unit_times);
416 return c;
417 }
418
419 static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
420 static const struct bus_properties_map hostname_map[] = {
421 { "Hostname", "s", NULL, offsetof(struct host_info, hostname) },
422 { "KernelName", "s", NULL, offsetof(struct host_info, kernel_name) },
423 { "KernelRelease", "s", NULL, offsetof(struct host_info, kernel_release) },
424 { "KernelVersion", "s", NULL, offsetof(struct host_info, kernel_version) },
425 { "OperatingSystemPrettyName", "s", NULL, offsetof(struct host_info, os_pretty_name) },
426 {}
427 };
428
429 static const struct bus_properties_map manager_map[] = {
430 { "Virtualization", "s", NULL, offsetof(struct host_info, virtualization) },
431 { "Architecture", "s", NULL, offsetof(struct host_info, architecture) },
432 {}
433 };
434
435 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
436 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *system_bus = NULL;
437 _cleanup_(free_host_infop) struct host_info *host;
438 int r;
439
440 host = new0(struct host_info, 1);
441 if (!host)
442 return log_oom();
443
444 if (arg_scope != UNIT_FILE_SYSTEM) {
445 r = bus_connect_transport(arg_transport, arg_host, false, &system_bus);
446 if (r < 0) {
447 log_debug_errno(r, "Failed to connect to system bus, ignoring: %m");
448 goto manager;
449 }
450 }
451
452 r = bus_map_all_properties(system_bus ?: bus,
453 "org.freedesktop.hostname1",
454 "/org/freedesktop/hostname1",
455 hostname_map,
456 BUS_MAP_STRDUP,
457 &error,
458 NULL,
459 host);
460 if (r < 0) {
461 log_debug_errno(r, "Failed to get host information from systemd-hostnamed, ignoring: %s", bus_error_message(&error, r));
462 sd_bus_error_free(&error);
463 }
464
465 manager:
466 r = bus_map_all_properties(bus,
467 "org.freedesktop.systemd1",
468 "/org/freedesktop/systemd1",
469 manager_map,
470 BUS_MAP_STRDUP,
471 &error,
472 NULL,
473 host);
474 if (r < 0)
475 return log_error_errno(r, "Failed to get host information from systemd: %s", bus_error_message(&error, r));
476
477 *hi = TAKE_PTR(host);
478
479 return 0;
480 }
481
482 static int pretty_boot_time(sd_bus *bus, char **_buf) {
483 char ts[FORMAT_TIMESPAN_MAX];
484 struct boot_times *t;
485 static char buf[4096];
486 size_t size;
487 char *ptr;
488 int r;
489 usec_t activated_time = USEC_INFINITY;
490 _cleanup_free_ char* path = NULL, *unit_id = NULL;
491 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
492
493 r = acquire_boot_times(bus, &t);
494 if (r < 0)
495 return r;
496
497 path = unit_dbus_path_from_name(SPECIAL_DEFAULT_TARGET);
498 if (!path)
499 return log_oom();
500
501 r = sd_bus_get_property_string(
502 bus,
503 "org.freedesktop.systemd1",
504 path,
505 "org.freedesktop.systemd1.Unit",
506 "Id",
507 &error,
508 &unit_id);
509 if (r < 0) {
510 log_error_errno(r, "default.target doesn't seem to exist: %s", bus_error_message(&error, r));
511 unit_id = NULL;
512 }
513
514 r = bus_get_uint64_property(bus, path,
515 "org.freedesktop.systemd1.Unit",
516 "ActiveEnterTimestampMonotonic",
517 &activated_time);
518 if (r < 0) {
519 log_info_errno(r, "Could not get time to reach default.target. Continuing...");
520 activated_time = USEC_INFINITY;
521 }
522
523 ptr = buf;
524 size = sizeof(buf);
525
526 size = strpcpyf(&ptr, size, "Startup finished in ");
527 if (t->firmware_time > 0)
528 size = strpcpyf(&ptr, size, "%s (firmware) + ", format_timespan(ts, sizeof(ts), t->firmware_time - t->loader_time, USEC_PER_MSEC));
529 if (t->loader_time > 0)
530 size = strpcpyf(&ptr, size, "%s (loader) + ", format_timespan(ts, sizeof(ts), t->loader_time, USEC_PER_MSEC));
531 if (t->kernel_time > 0)
532 size = strpcpyf(&ptr, size, "%s (kernel) + ", format_timespan(ts, sizeof(ts), t->kernel_done_time, USEC_PER_MSEC));
533 if (t->initrd_time > 0)
534 size = strpcpyf(&ptr, size, "%s (initrd) + ", format_timespan(ts, sizeof(ts), t->userspace_time - t->initrd_time, USEC_PER_MSEC));
535
536 size = strpcpyf(&ptr, size, "%s (userspace) ", format_timespan(ts, sizeof(ts), t->finish_time - t->userspace_time, USEC_PER_MSEC));
537 if (t->kernel_time > 0)
538 strpcpyf(&ptr, size, "= %s ", format_timespan(ts, sizeof(ts), t->firmware_time + t->finish_time, USEC_PER_MSEC));
539
540 if (unit_id && activated_time > 0 && activated_time != USEC_INFINITY) {
541 if (t->userspace_time > 0)
542 size = strpcpyf(&ptr, size, "\n%s reached after %s in userspace", unit_id, format_timespan(ts, sizeof(ts), activated_time - t->userspace_time, USEC_PER_MSEC));
543 else
544 size = strpcpyf(&ptr, size, "\n%s reached after %s in userspace", unit_id, format_timespan(ts, sizeof(ts), activated_time - t->reverse_offset, USEC_PER_MSEC));
545 } else if (unit_id && activated_time == 0)
546 size = strpcpyf(&ptr, size, "\n%s was never reached", unit_id);
547 else if (unit_id && activated_time == USEC_INFINITY)
548 size = strpcpyf(&ptr, size, "\nCould not get time to reach %s.", unit_id);
549 else if (!unit_id)
550 size = strpcpyf(&ptr, size, "\ncould not find default.target");
551
552 ptr = strdup(buf);
553 if (!ptr)
554 return log_oom();
555
556 *_buf = ptr;
557 return 0;
558 }
559
560 static void svg_graph_box(double height, double begin, double end) {
561 long long i;
562
563 /* outside box, fill */
564 svg("<rect class=\"box\" x=\"0\" y=\"0\" width=\"%.03f\" height=\"%.03f\" />\n",
565 SCALE_X * (end - begin), SCALE_Y * height);
566
567 for (i = ((long long) (begin / 100000)) * 100000; i <= end; i+=100000) {
568 /* lines for each second */
569 if (i % 5000000 == 0)
570 svg(" <line class=\"sec5\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n"
571 " <text class=\"sec\" x=\"%.03f\" y=\"%.03f\" >%.01fs</text>\n",
572 SCALE_X * i, SCALE_X * i, SCALE_Y * height, SCALE_X * i, -5.0, 0.000001 * i);
573 else if (i % 1000000 == 0)
574 svg(" <line class=\"sec1\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n"
575 " <text class=\"sec\" x=\"%.03f\" y=\"%.03f\" >%.01fs</text>\n",
576 SCALE_X * i, SCALE_X * i, SCALE_Y * height, SCALE_X * i, -5.0, 0.000001 * i);
577 else
578 svg(" <line class=\"sec01\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n",
579 SCALE_X * i, SCALE_X * i, SCALE_Y * height);
580 }
581 }
582
583 static int plot_unit_times(struct unit_times *u, double width, int y) {
584 char ts[FORMAT_TIMESPAN_MAX];
585 bool b;
586
587 if (!u->name)
588 return 0;
589
590 svg_bar("activating", u->activating, u->activated, y);
591 svg_bar("active", u->activated, u->deactivating, y);
592 svg_bar("deactivating", u->deactivating, u->deactivated, y);
593
594 /* place the text on the left if we have passed the half of the svg width */
595 b = u->activating * SCALE_X < width / 2;
596 if (u->time)
597 svg_text(b, u->activating, y, "%s (%s)",
598 u->name, format_timespan(ts, sizeof(ts), u->time, USEC_PER_MSEC));
599 else
600 svg_text(b, u->activating, y, "%s", u->name);
601
602 return 1;
603 }
604
605 static int analyze_plot(int argc, char *argv[], void *userdata) {
606 _cleanup_(free_host_infop) struct host_info *host = NULL;
607 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
608 _cleanup_(unit_times_freep) struct unit_times *times = NULL;
609 _cleanup_free_ char *pretty_times = NULL;
610 bool use_full_bus = arg_scope == UNIT_FILE_SYSTEM;
611 struct boot_times *boot;
612 struct unit_times *u;
613 int n, m = 1, y = 0, r;
614 double width;
615
616 r = acquire_bus(&bus, &use_full_bus);
617 if (r < 0)
618 return log_error_errno(r, "Failed to create bus connection: %m");
619
620 n = acquire_boot_times(bus, &boot);
621 if (n < 0)
622 return n;
623
624 n = pretty_boot_time(bus, &pretty_times);
625 if (n < 0)
626 return n;
627
628 if (use_full_bus || arg_scope != UNIT_FILE_SYSTEM) {
629 n = acquire_host_info(bus, &host);
630 if (n < 0)
631 return n;
632 }
633
634 n = acquire_time_data(bus, &times);
635 if (n <= 0)
636 return n;
637
638 qsort(times, n, sizeof(struct unit_times), compare_unit_start);
639
640 width = SCALE_X * (boot->firmware_time + boot->finish_time);
641 if (width < 800.0)
642 width = 800.0;
643
644 if (boot->firmware_time > boot->loader_time)
645 m++;
646 if (boot->loader_time > 0) {
647 m++;
648 if (width < 1000.0)
649 width = 1000.0;
650 }
651 if (boot->initrd_time > 0)
652 m++;
653 if (boot->kernel_time > 0)
654 m++;
655
656 for (u = times; u->has_data; u++) {
657 double text_start, text_width;
658
659 if (u->activating > boot->finish_time) {
660 u->name = mfree(u->name);
661 continue;
662 }
663
664 /* If the text cannot fit on the left side then
665 * increase the svg width so it fits on the right.
666 * TODO: calculate the text width more accurately */
667 text_width = 8.0 * strlen(u->name);
668 text_start = (boot->firmware_time + u->activating) * SCALE_X;
669 if (text_width > text_start && text_width + text_start > width)
670 width = text_width + text_start;
671
672 if (u->deactivated > u->activating &&
673 u->deactivated <= boot->finish_time &&
674 u->activated == 0 && u->deactivating == 0)
675 u->activated = u->deactivating = u->deactivated;
676 if (u->activated < u->activating || u->activated > boot->finish_time)
677 u->activated = boot->finish_time;
678 if (u->deactivating < u->activated || u->deactivating > boot->finish_time)
679 u->deactivating = boot->finish_time;
680 if (u->deactivated < u->deactivating || u->deactivated > boot->finish_time)
681 u->deactivated = boot->finish_time;
682 m++;
683 }
684
685 svg("<?xml version=\"1.0\" standalone=\"no\"?>\n"
686 "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "
687 "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
688
689 svg("<svg width=\"%.0fpx\" height=\"%.0fpx\" version=\"1.1\" "
690 "xmlns=\"http://www.w3.org/2000/svg\">\n\n",
691 80.0 + width, 150.0 + (m * SCALE_Y) +
692 5 * SCALE_Y /* legend */);
693
694 /* write some basic info as a comment, including some help */
695 svg("<!-- This file is a systemd-analyze SVG file. It is best rendered in a -->\n"
696 "<!-- browser such as Chrome, Chromium or Firefox. Other applications -->\n"
697 "<!-- that render these files properly but much slower are ImageMagick, -->\n"
698 "<!-- gimp, inkscape, etc. To display the files on your system, just -->\n"
699 "<!-- point your browser to this file. -->\n\n"
700 "<!-- This plot was generated by systemd-analyze version %-16.16s -->\n\n", PACKAGE_VERSION);
701
702 /* style sheet */
703 svg("<defs>\n <style type=\"text/css\">\n <![CDATA[\n"
704 " rect { stroke-width: 1; stroke-opacity: 0; }\n"
705 " rect.background { fill: rgb(255,255,255); }\n"
706 " rect.activating { fill: rgb(255,0,0); fill-opacity: 0.7; }\n"
707 " rect.active { fill: rgb(200,150,150); fill-opacity: 0.7; }\n"
708 " rect.deactivating { fill: rgb(150,100,100); fill-opacity: 0.7; }\n"
709 " rect.kernel { fill: rgb(150,150,150); fill-opacity: 0.7; }\n"
710 " rect.initrd { fill: rgb(150,150,150); fill-opacity: 0.7; }\n"
711 " rect.firmware { fill: rgb(150,150,150); fill-opacity: 0.7; }\n"
712 " rect.loader { fill: rgb(150,150,150); fill-opacity: 0.7; }\n"
713 " rect.userspace { fill: rgb(150,150,150); fill-opacity: 0.7; }\n"
714 " rect.security { fill: rgb(144,238,144); fill-opacity: 0.7; }\n"
715 " rect.generators { fill: rgb(102,204,255); fill-opacity: 0.7; }\n"
716 " rect.unitsload { fill: rgb( 82,184,255); fill-opacity: 0.7; }\n"
717 " rect.box { fill: rgb(240,240,240); stroke: rgb(192,192,192); }\n"
718 " line { stroke: rgb(64,64,64); stroke-width: 1; }\n"
719 "// line.sec1 { }\n"
720 " line.sec5 { stroke-width: 2; }\n"
721 " line.sec01 { stroke: rgb(224,224,224); stroke-width: 1; }\n"
722 " text { font-family: Verdana, Helvetica; font-size: 14px; }\n"
723 " text.left { font-family: Verdana, Helvetica; font-size: 14px; text-anchor: start; }\n"
724 " text.right { font-family: Verdana, Helvetica; font-size: 14px; text-anchor: end; }\n"
725 " text.sec { font-size: 10px; }\n"
726 " ]]>\n </style>\n</defs>\n\n");
727
728 svg("<rect class=\"background\" width=\"100%%\" height=\"100%%\" />\n");
729 svg("<text x=\"20\" y=\"50\">%s</text>", pretty_times);
730 if (host)
731 svg("<text x=\"20\" y=\"30\">%s %s (%s %s %s) %s %s</text>",
732 isempty(host->os_pretty_name) ? "Linux" : host->os_pretty_name,
733 strempty(host->hostname),
734 strempty(host->kernel_name),
735 strempty(host->kernel_release),
736 strempty(host->kernel_version),
737 strempty(host->architecture),
738 strempty(host->virtualization));
739
740 svg("<g transform=\"translate(%.3f,100)\">\n", 20.0 + (SCALE_X * boot->firmware_time));
741 svg_graph_box(m, -(double) boot->firmware_time, boot->finish_time);
742
743 if (boot->firmware_time > 0) {
744 svg_bar("firmware", -(double) boot->firmware_time, -(double) boot->loader_time, y);
745 svg_text(true, -(double) boot->firmware_time, y, "firmware");
746 y++;
747 }
748 if (boot->loader_time > 0) {
749 svg_bar("loader", -(double) boot->loader_time, 0, y);
750 svg_text(true, -(double) boot->loader_time, y, "loader");
751 y++;
752 }
753 if (boot->kernel_time > 0) {
754 svg_bar("kernel", 0, boot->kernel_done_time, y);
755 svg_text(true, 0, y, "kernel");
756 y++;
757 }
758 if (boot->initrd_time > 0) {
759 svg_bar("initrd", boot->initrd_time, boot->userspace_time, y);
760 if (boot->initrd_security_start_time < boot->initrd_security_finish_time)
761 svg_bar("security", boot->initrd_security_start_time, boot->initrd_security_finish_time, y);
762 if (boot->initrd_generators_start_time < boot->initrd_generators_finish_time)
763 svg_bar("generators", boot->initrd_generators_start_time, boot->initrd_generators_finish_time, y);
764 if (boot->initrd_unitsload_start_time < boot->initrd_unitsload_finish_time)
765 svg_bar("unitsload", boot->initrd_unitsload_start_time, boot->initrd_unitsload_finish_time, y);
766 svg_text(true, boot->initrd_time, y, "initrd");
767 y++;
768 }
769
770 for (u = times; u->has_data; u++) {
771 if (u->activating >= boot->userspace_time)
772 break;
773
774 y += plot_unit_times(u, width, y);
775 }
776
777 svg_bar("active", boot->userspace_time, boot->finish_time, y);
778 if (boot->security_start_time > 0)
779 svg_bar("security", boot->security_start_time, boot->security_finish_time, y);
780 svg_bar("generators", boot->generators_start_time, boot->generators_finish_time, y);
781 svg_bar("unitsload", boot->unitsload_start_time, boot->unitsload_finish_time, y);
782 svg_text(true, boot->userspace_time, y, "systemd");
783 y++;
784
785 for (; u->has_data; u++)
786 y += plot_unit_times(u, width, y);
787
788 svg("</g>\n");
789
790 /* Legend */
791 svg("<g transform=\"translate(20,100)\">\n");
792 y++;
793 svg_bar("activating", 0, 300000, y);
794 svg_text(true, 400000, y, "Activating");
795 y++;
796 svg_bar("active", 0, 300000, y);
797 svg_text(true, 400000, y, "Active");
798 y++;
799 svg_bar("deactivating", 0, 300000, y);
800 svg_text(true, 400000, y, "Deactivating");
801 y++;
802 if (boot->security_start_time > 0) {
803 svg_bar("security", 0, 300000, y);
804 svg_text(true, 400000, y, "Setting up security module");
805 y++;
806 }
807 svg_bar("generators", 0, 300000, y);
808 svg_text(true, 400000, y, "Generators");
809 y++;
810 svg_bar("unitsload", 0, 300000, y);
811 svg_text(true, 400000, y, "Loading unit files");
812 y++;
813
814 svg("</g>\n\n");
815
816 svg("</svg>\n");
817
818 return 0;
819 }
820
821 static int list_dependencies_print(const char *name, unsigned int level, unsigned int branches,
822 bool last, struct unit_times *times, struct boot_times *boot) {
823 unsigned int i;
824 char ts[FORMAT_TIMESPAN_MAX], ts2[FORMAT_TIMESPAN_MAX];
825
826 for (i = level; i != 0; i--)
827 printf("%s", special_glyph(branches & (1 << (i-1)) ? TREE_VERTICAL : TREE_SPACE));
828
829 printf("%s", special_glyph(last ? TREE_RIGHT : TREE_BRANCH));
830
831 if (times) {
832 if (times->time > 0)
833 printf("%s%s @%s +%s%s", ansi_highlight_red(), name,
834 format_timespan(ts, sizeof(ts), times->activating - boot->userspace_time, USEC_PER_MSEC),
835 format_timespan(ts2, sizeof(ts2), times->time, USEC_PER_MSEC), ansi_normal());
836 else if (times->activated > boot->userspace_time)
837 printf("%s @%s", name, format_timespan(ts, sizeof(ts), times->activated - boot->userspace_time, USEC_PER_MSEC));
838 else
839 printf("%s", name);
840 } else
841 printf("%s", name);
842 printf("\n");
843
844 return 0;
845 }
846
847 static int list_dependencies_get_dependencies(sd_bus *bus, const char *name, char ***deps) {
848 _cleanup_free_ char *path = NULL;
849
850 assert(bus);
851 assert(name);
852 assert(deps);
853
854 path = unit_dbus_path_from_name(name);
855 if (!path)
856 return -ENOMEM;
857
858 return bus_get_unit_property_strv(bus, path, "After", deps);
859 }
860
861 static Hashmap *unit_times_hashmap;
862
863 static int list_dependencies_compare(const void *_a, const void *_b) {
864 const char **a = (const char**) _a, **b = (const char**) _b;
865 usec_t usa = 0, usb = 0;
866 struct unit_times *times;
867
868 times = hashmap_get(unit_times_hashmap, *a);
869 if (times)
870 usa = times->activated;
871 times = hashmap_get(unit_times_hashmap, *b);
872 if (times)
873 usb = times->activated;
874
875 return usb - usa;
876 }
877
878 static bool times_in_range(const struct unit_times *times, const struct boot_times *boot) {
879 return times &&
880 times->activated > 0 && times->activated <= boot->finish_time;
881 }
882
883 static int list_dependencies_one(sd_bus *bus, const char *name, unsigned int level, char ***units,
884 unsigned int branches) {
885 _cleanup_strv_free_ char **deps = NULL;
886 char **c;
887 int r = 0;
888 usec_t service_longest = 0;
889 int to_print = 0;
890 struct unit_times *times;
891 struct boot_times *boot;
892
893 if (strv_extend(units, name))
894 return log_oom();
895
896 r = list_dependencies_get_dependencies(bus, name, &deps);
897 if (r < 0)
898 return r;
899
900 qsort_safe(deps, strv_length(deps), sizeof (char*), list_dependencies_compare);
901
902 r = acquire_boot_times(bus, &boot);
903 if (r < 0)
904 return r;
905
906 STRV_FOREACH(c, deps) {
907 times = hashmap_get(unit_times_hashmap, *c);
908 if (times_in_range(times, boot) &&
909 times->activated >= service_longest)
910 service_longest = times->activated;
911 }
912
913 if (service_longest == 0)
914 return r;
915
916 STRV_FOREACH(c, deps) {
917 times = hashmap_get(unit_times_hashmap, *c);
918 if (times_in_range(times, boot) &&
919 service_longest - times->activated <= arg_fuzz)
920 to_print++;
921 }
922
923 if (!to_print)
924 return r;
925
926 STRV_FOREACH(c, deps) {
927 times = hashmap_get(unit_times_hashmap, *c);
928 if (!times_in_range(times, boot) ||
929 service_longest - times->activated > arg_fuzz)
930 continue;
931
932 to_print--;
933
934 r = list_dependencies_print(*c, level, branches, to_print == 0, times, boot);
935 if (r < 0)
936 return r;
937
938 if (strv_contains(*units, *c)) {
939 r = list_dependencies_print("...", level + 1, (branches << 1) | (to_print ? 1 : 0),
940 true, NULL, boot);
941 if (r < 0)
942 return r;
943 continue;
944 }
945
946 r = list_dependencies_one(bus, *c, level + 1, units,
947 (branches << 1) | (to_print ? 1 : 0));
948 if (r < 0)
949 return r;
950
951 if (to_print == 0)
952 break;
953 }
954 return 0;
955 }
956
957 static int list_dependencies(sd_bus *bus, const char *name) {
958 _cleanup_strv_free_ char **units = NULL;
959 char ts[FORMAT_TIMESPAN_MAX];
960 struct unit_times *times;
961 int r;
962 const char *id;
963 _cleanup_free_ char *path = NULL;
964 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
965 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
966 struct boot_times *boot;
967
968 assert(bus);
969
970 path = unit_dbus_path_from_name(name);
971 if (!path)
972 return -ENOMEM;
973
974 r = sd_bus_get_property(
975 bus,
976 "org.freedesktop.systemd1",
977 path,
978 "org.freedesktop.systemd1.Unit",
979 "Id",
980 &error,
981 &reply,
982 "s");
983 if (r < 0) {
984 log_error("Failed to get ID: %s", bus_error_message(&error, -r));
985 return r;
986 }
987
988 r = sd_bus_message_read(reply, "s", &id);
989 if (r < 0)
990 return bus_log_parse_error(r);
991
992 times = hashmap_get(unit_times_hashmap, id);
993
994 r = acquire_boot_times(bus, &boot);
995 if (r < 0)
996 return r;
997
998 if (times) {
999 if (times->time)
1000 printf("%s%s +%s%s\n", ansi_highlight_red(), id,
1001 format_timespan(ts, sizeof(ts), times->time, USEC_PER_MSEC), ansi_normal());
1002 else if (times->activated > boot->userspace_time)
1003 printf("%s @%s\n", id, format_timespan(ts, sizeof(ts), times->activated - boot->userspace_time, USEC_PER_MSEC));
1004 else
1005 printf("%s\n", id);
1006 }
1007
1008 return list_dependencies_one(bus, name, 0, &units, 0);
1009 }
1010
1011 static int analyze_critical_chain(int argc, char *argv[], void *userdata) {
1012 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
1013 _cleanup_(unit_times_freep) struct unit_times *times = NULL;
1014 struct unit_times *u;
1015 Hashmap *h;
1016 int n, r;
1017
1018 r = acquire_bus(&bus, NULL);
1019 if (r < 0)
1020 return log_error_errno(r, "Failed to create bus connection: %m");
1021
1022 n = acquire_time_data(bus, &times);
1023 if (n <= 0)
1024 return n;
1025
1026 h = hashmap_new(&string_hash_ops);
1027 if (!h)
1028 return log_oom();
1029
1030 for (u = times; u->has_data; u++) {
1031 r = hashmap_put(h, u->name, u);
1032 if (r < 0)
1033 return log_error_errno(r, "Failed to add entry to hashmap: %m");
1034 }
1035 unit_times_hashmap = h;
1036
1037 (void) pager_open(arg_no_pager, false);
1038
1039 puts("The time after the unit is active or started is printed after the \"@\" character.\n"
1040 "The time the unit takes to start is printed after the \"+\" character.\n");
1041
1042 if (argc > 1) {
1043 char **name;
1044 STRV_FOREACH(name, strv_skip(argv, 1))
1045 list_dependencies(bus, *name);
1046 } else
1047 list_dependencies(bus, SPECIAL_DEFAULT_TARGET);
1048
1049 h = hashmap_free(h);
1050 return 0;
1051 }
1052
1053 static int analyze_blame(int argc, char *argv[], void *userdata) {
1054 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
1055 _cleanup_(unit_times_freep) struct unit_times *times = NULL;
1056 struct unit_times *u;
1057 int n, r;
1058
1059 r = acquire_bus(&bus, NULL);
1060 if (r < 0)
1061 return log_error_errno(r, "Failed to create bus connection: %m");
1062
1063 n = acquire_time_data(bus, &times);
1064 if (n <= 0)
1065 return n;
1066
1067 qsort(times, n, sizeof(struct unit_times), compare_unit_time);
1068
1069 (void) pager_open(arg_no_pager, false);
1070
1071 for (u = times; u->has_data; u++) {
1072 char ts[FORMAT_TIMESPAN_MAX];
1073
1074 if (u->time > 0)
1075 printf("%16s %s\n", format_timespan(ts, sizeof(ts), u->time, USEC_PER_MSEC), u->name);
1076 }
1077
1078 return 0;
1079 }
1080
1081 static int analyze_time(int argc, char *argv[], void *userdata) {
1082 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
1083 _cleanup_free_ char *buf = NULL;
1084 int r;
1085
1086 r = acquire_bus(&bus, NULL);
1087 if (r < 0)
1088 return log_error_errno(r, "Failed to create bus connection: %m");
1089
1090 r = pretty_boot_time(bus, &buf);
1091 if (r < 0)
1092 return r;
1093
1094 puts(buf);
1095 return 0;
1096 }
1097
1098 static int graph_one_property(sd_bus *bus, const UnitInfo *u, const char* prop, const char *color, char* patterns[], char* from_patterns[], char* to_patterns[]) {
1099 _cleanup_strv_free_ char **units = NULL;
1100 char **unit;
1101 int r;
1102 bool match_patterns;
1103
1104 assert(u);
1105 assert(prop);
1106 assert(color);
1107
1108 match_patterns = strv_fnmatch(patterns, u->id, 0);
1109
1110 if (!strv_isempty(from_patterns) &&
1111 !match_patterns &&
1112 !strv_fnmatch(from_patterns, u->id, 0))
1113 return 0;
1114
1115 r = bus_get_unit_property_strv(bus, u->unit_path, prop, &units);
1116 if (r < 0)
1117 return r;
1118
1119 STRV_FOREACH(unit, units) {
1120 bool match_patterns2;
1121
1122 match_patterns2 = strv_fnmatch(patterns, *unit, 0);
1123
1124 if (!strv_isempty(to_patterns) &&
1125 !match_patterns2 &&
1126 !strv_fnmatch(to_patterns, *unit, 0))
1127 continue;
1128
1129 if (!strv_isempty(patterns) && !match_patterns && !match_patterns2)
1130 continue;
1131
1132 printf("\t\"%s\"->\"%s\" [color=\"%s\"];\n", u->id, *unit, color);
1133 }
1134
1135 return 0;
1136 }
1137
1138 static int graph_one(sd_bus *bus, const UnitInfo *u, char *patterns[], char *from_patterns[], char *to_patterns[]) {
1139 int r;
1140
1141 assert(bus);
1142 assert(u);
1143
1144 if (IN_SET(arg_dot, DEP_ORDER, DEP_ALL)) {
1145 r = graph_one_property(bus, u, "After", "green", patterns, from_patterns, to_patterns);
1146 if (r < 0)
1147 return r;
1148 }
1149
1150 if (IN_SET(arg_dot, DEP_REQUIRE, DEP_ALL)) {
1151 r = graph_one_property(bus, u, "Requires", "black", patterns, from_patterns, to_patterns);
1152 if (r < 0)
1153 return r;
1154 r = graph_one_property(bus, u, "Requisite", "darkblue", patterns, from_patterns, to_patterns);
1155 if (r < 0)
1156 return r;
1157 r = graph_one_property(bus, u, "Wants", "grey66", patterns, from_patterns, to_patterns);
1158 if (r < 0)
1159 return r;
1160 r = graph_one_property(bus, u, "Conflicts", "red", patterns, from_patterns, to_patterns);
1161 if (r < 0)
1162 return r;
1163 }
1164
1165 return 0;
1166 }
1167
1168 static int expand_patterns(sd_bus *bus, char **patterns, char ***ret) {
1169 _cleanup_strv_free_ char **expanded_patterns = NULL;
1170 char **pattern;
1171 int r;
1172
1173 STRV_FOREACH(pattern, patterns) {
1174 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1175 _cleanup_free_ char *unit = NULL, *unit_id = NULL;
1176
1177 if (strv_extend(&expanded_patterns, *pattern) < 0)
1178 return log_oom();
1179
1180 if (string_is_glob(*pattern))
1181 continue;
1182
1183 unit = unit_dbus_path_from_name(*pattern);
1184 if (!unit)
1185 return log_oom();
1186
1187 r = sd_bus_get_property_string(
1188 bus,
1189 "org.freedesktop.systemd1",
1190 unit,
1191 "org.freedesktop.systemd1.Unit",
1192 "Id",
1193 &error,
1194 &unit_id);
1195 if (r < 0)
1196 return log_error_errno(r, "Failed to get ID: %s", bus_error_message(&error, r));
1197
1198 if (!streq(*pattern, unit_id)) {
1199 if (strv_extend(&expanded_patterns, unit_id) < 0)
1200 return log_oom();
1201 }
1202 }
1203
1204 *ret = expanded_patterns;
1205 expanded_patterns = NULL; /* do not free */
1206
1207 return 0;
1208 }
1209
1210 static int dot(int argc, char *argv[], void *userdata) {
1211 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
1212 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1213 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
1214 _cleanup_strv_free_ char **expanded_patterns = NULL;
1215 _cleanup_strv_free_ char **expanded_from_patterns = NULL;
1216 _cleanup_strv_free_ char **expanded_to_patterns = NULL;
1217 int r;
1218 UnitInfo u;
1219
1220 r = acquire_bus(&bus, NULL);
1221 if (r < 0)
1222 return log_error_errno(r, "Failed to create bus connection: %m");
1223
1224 r = expand_patterns(bus, strv_skip(argv, 1), &expanded_patterns);
1225 if (r < 0)
1226 return r;
1227
1228 r = expand_patterns(bus, arg_dot_from_patterns, &expanded_from_patterns);
1229 if (r < 0)
1230 return r;
1231
1232 r = expand_patterns(bus, arg_dot_to_patterns, &expanded_to_patterns);
1233 if (r < 0)
1234 return r;
1235
1236 r = sd_bus_call_method(
1237 bus,
1238 "org.freedesktop.systemd1",
1239 "/org/freedesktop/systemd1",
1240 "org.freedesktop.systemd1.Manager",
1241 "ListUnits",
1242 &error,
1243 &reply,
1244 "");
1245 if (r < 0) {
1246 log_error("Failed to list units: %s", bus_error_message(&error, -r));
1247 return r;
1248 }
1249
1250 r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssssouso)");
1251 if (r < 0)
1252 return bus_log_parse_error(r);
1253
1254 printf("digraph systemd {\n");
1255
1256 while ((r = bus_parse_unit_info(reply, &u)) > 0) {
1257
1258 r = graph_one(bus, &u, expanded_patterns, expanded_from_patterns, expanded_to_patterns);
1259 if (r < 0)
1260 return r;
1261 }
1262 if (r < 0)
1263 return bus_log_parse_error(r);
1264
1265 printf("}\n");
1266
1267 log_info(" Color legend: black = Requires\n"
1268 " dark blue = Requisite\n"
1269 " dark grey = Wants\n"
1270 " red = Conflicts\n"
1271 " green = After\n");
1272
1273 if (on_tty())
1274 log_notice("-- You probably want to process this output with graphviz' dot tool.\n"
1275 "-- Try a shell pipeline like 'systemd-analyze dot | dot -Tsvg > systemd.svg'!\n");
1276
1277 return 0;
1278 }
1279
1280 static int dump_fallback(sd_bus *bus) {
1281 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1282 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
1283 const char *text = NULL;
1284 int r;
1285
1286 assert(bus);
1287
1288 r = sd_bus_call_method(
1289 bus,
1290 "org.freedesktop.systemd1",
1291 "/org/freedesktop/systemd1",
1292 "org.freedesktop.systemd1.Manager",
1293 "Dump",
1294 &error,
1295 &reply,
1296 NULL);
1297 if (r < 0)
1298 return log_error_errno(r, "Failed to issue method call Dump: %s", bus_error_message(&error, r));
1299
1300 r = sd_bus_message_read(reply, "s", &text);
1301 if (r < 0)
1302 return bus_log_parse_error(r);
1303
1304 fputs(text, stdout);
1305 return 0;
1306 }
1307
1308 static int dump(int argc, char *argv[], void *userdata) {
1309 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1310 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
1311 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
1312 int fd = -1;
1313 int r;
1314
1315 r = acquire_bus(&bus, NULL);
1316 if (r < 0)
1317 return log_error_errno(r, "Failed to create bus connection: %m");
1318
1319 (void) pager_open(arg_no_pager, false);
1320
1321 if (!sd_bus_can_send(bus, SD_BUS_TYPE_UNIX_FD))
1322 return dump_fallback(bus);
1323
1324 r = sd_bus_call_method(
1325 bus,
1326 "org.freedesktop.systemd1",
1327 "/org/freedesktop/systemd1",
1328 "org.freedesktop.systemd1.Manager",
1329 "DumpByFileDescriptor",
1330 &error,
1331 &reply,
1332 NULL);
1333 if (r < 0) {
1334 /* fall back to Dump if DumpByFileDescriptor is not supported */
1335 if (!IN_SET(r, -EACCES, -EBADR))
1336 return log_error_errno(r, "Failed to issue method call DumpByFileDescriptor: %s", bus_error_message(&error, r));
1337
1338 return dump_fallback(bus);
1339 }
1340
1341 r = sd_bus_message_read(reply, "h", &fd);
1342 if (r < 0)
1343 return bus_log_parse_error(r);
1344
1345 fflush(stdout);
1346 return copy_bytes(fd, STDOUT_FILENO, (uint64_t) -1, 0);
1347 }
1348
1349 static int cat_config(int argc, char *argv[], void *userdata) {
1350 char **arg;
1351 int r;
1352
1353 (void) pager_open(arg_no_pager, false);
1354
1355 STRV_FOREACH(arg, argv + 1) {
1356 const char *t = NULL;
1357
1358 if (arg != argv + 1)
1359 print_separator();
1360
1361 if (path_is_absolute(*arg)) {
1362 const char *dir;
1363
1364 NULSTR_FOREACH(dir, CONF_PATHS_NULSTR("")) {
1365 t = path_startswith(*arg, dir);
1366 if (t)
1367 break;
1368 }
1369
1370 if (!t) {
1371 log_error("Path %s does not start with any known prefix.", *arg);
1372 return -EINVAL;
1373 }
1374 } else
1375 t = *arg;
1376
1377 r = conf_files_cat(arg_root, t);
1378 if (r < 0)
1379 return r;
1380 }
1381
1382 return 0;
1383 }
1384
1385 static int set_log_level(int argc, char *argv[], void *userdata) {
1386 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1387 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
1388 int r;
1389
1390 assert(argc == 2);
1391 assert(argv);
1392
1393 r = acquire_bus(&bus, NULL);
1394 if (r < 0)
1395 return log_error_errno(r, "Failed to create bus connection: %m");
1396
1397 r = sd_bus_set_property(
1398 bus,
1399 "org.freedesktop.systemd1",
1400 "/org/freedesktop/systemd1",
1401 "org.freedesktop.systemd1.Manager",
1402 "LogLevel",
1403 &error,
1404 "s",
1405 argv[1]);
1406 if (r < 0)
1407 return log_error_errno(r, "Failed to issue method call: %s", bus_error_message(&error, r));
1408
1409 return 0;
1410 }
1411
1412 static int get_log_level(int argc, char *argv[], void *userdata) {
1413 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1414 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
1415 _cleanup_free_ char *level = NULL;
1416 int r;
1417
1418 r = acquire_bus(&bus, NULL);
1419 if (r < 0)
1420 return log_error_errno(r, "Failed to create bus connection: %m");
1421
1422 r = sd_bus_get_property_string(
1423 bus,
1424 "org.freedesktop.systemd1",
1425 "/org/freedesktop/systemd1",
1426 "org.freedesktop.systemd1.Manager",
1427 "LogLevel",
1428 &error,
1429 &level);
1430 if (r < 0)
1431 return log_error_errno(r, "Failed to get log level: %s", bus_error_message(&error, r));
1432
1433 puts(level);
1434 return 0;
1435 }
1436
1437 static int get_or_set_log_level(int argc, char *argv[], void *userdata) {
1438 return (argc == 1) ? get_log_level(argc, argv, userdata) : set_log_level(argc, argv, userdata);
1439 }
1440
1441 static int set_log_target(int argc, char *argv[], void *userdata) {
1442 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1443 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
1444 int r;
1445
1446 assert(argc == 2);
1447 assert(argv);
1448
1449 r = acquire_bus(&bus, NULL);
1450 if (r < 0)
1451 return log_error_errno(r, "Failed to create bus connection: %m");
1452
1453 r = sd_bus_set_property(
1454 bus,
1455 "org.freedesktop.systemd1",
1456 "/org/freedesktop/systemd1",
1457 "org.freedesktop.systemd1.Manager",
1458 "LogTarget",
1459 &error,
1460 "s",
1461 argv[1]);
1462 if (r < 0)
1463 return log_error_errno(r, "Failed to issue method call: %s", bus_error_message(&error, r));
1464
1465 return 0;
1466 }
1467
1468 static int get_log_target(int argc, char *argv[], void *userdata) {
1469 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1470 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
1471 _cleanup_free_ char *target = NULL;
1472 int r;
1473
1474 r = acquire_bus(&bus, NULL);
1475 if (r < 0)
1476 return log_error_errno(r, "Failed to create bus connection: %m");
1477
1478 r = sd_bus_get_property_string(
1479 bus,
1480 "org.freedesktop.systemd1",
1481 "/org/freedesktop/systemd1",
1482 "org.freedesktop.systemd1.Manager",
1483 "LogTarget",
1484 &error,
1485 &target);
1486 if (r < 0)
1487 return log_error_errno(r, "Failed to get log target: %s", bus_error_message(&error, r));
1488
1489 puts(target);
1490 return 0;
1491 }
1492
1493 static int get_or_set_log_target(int argc, char *argv[], void *userdata) {
1494 return (argc == 1) ? get_log_target(argc, argv, userdata) : set_log_target(argc, argv, userdata);
1495 }
1496
1497 static int dump_unit_paths(int argc, char *argv[], void *userdata) {
1498 _cleanup_(lookup_paths_free) LookupPaths paths = {};
1499 int r;
1500 char **p;
1501
1502 r = lookup_paths_init(&paths, arg_scope, 0, NULL);
1503 if (r < 0)
1504 return log_error_errno(r, "lookup_paths_init() failed: %m");
1505
1506 STRV_FOREACH(p, paths.search_path)
1507 puts(*p);
1508
1509 return 0;
1510 }
1511
1512 #if HAVE_SECCOMP
1513 static void dump_syscall_filter(const SyscallFilterSet *set) {
1514 const char *syscall;
1515
1516 printf("%s\n", set->name);
1517 printf(" # %s\n", set->help);
1518 NULSTR_FOREACH(syscall, set->value)
1519 printf(" %s\n", syscall);
1520 }
1521
1522 static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
1523 bool first = true;
1524
1525 (void) pager_open(arg_no_pager, false);
1526
1527 if (strv_isempty(strv_skip(argv, 1))) {
1528 int i;
1529
1530 for (i = 0; i < _SYSCALL_FILTER_SET_MAX; i++) {
1531 if (!first)
1532 puts("");
1533 dump_syscall_filter(syscall_filter_sets + i);
1534 first = false;
1535 }
1536 } else {
1537 char **name;
1538
1539 STRV_FOREACH(name, strv_skip(argv, 1)) {
1540 const SyscallFilterSet *set;
1541
1542 if (!first)
1543 puts("");
1544
1545 set = syscall_filter_set_find(*name);
1546 if (!set) {
1547 /* make sure the error appears below normal output */
1548 fflush(stdout);
1549
1550 log_error("Filter set \"%s\" not found.", *name);
1551 return -ENOENT;
1552 }
1553
1554 dump_syscall_filter(set);
1555 first = false;
1556 }
1557 }
1558
1559 return 0;
1560 }
1561
1562 #else
1563 static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
1564 log_error("Not compiled with syscall filters, sorry.");
1565 return -EOPNOTSUPP;
1566 }
1567 #endif
1568
1569 static int test_calendar(int argc, char *argv[], void *userdata) {
1570 int ret = 0, r;
1571 char **p;
1572 usec_t n;
1573
1574 n = now(CLOCK_REALTIME);
1575
1576 STRV_FOREACH(p, strv_skip(argv, 1)) {
1577 _cleanup_(calendar_spec_freep) CalendarSpec *spec = NULL;
1578 _cleanup_free_ char *t = NULL;
1579 usec_t next;
1580
1581 r = calendar_spec_from_string(*p, &spec);
1582 if (r < 0) {
1583 ret = log_error_errno(r, "Failed to parse calendar specification '%s': %m", *p);
1584 continue;
1585 }
1586
1587 r = calendar_spec_normalize(spec);
1588 if (r < 0) {
1589 ret = log_error_errno(r, "Failed to normalize calendar specification '%s': %m", *p);
1590 continue;
1591 }
1592
1593 r = calendar_spec_to_string(spec, &t);
1594 if (r < 0) {
1595 ret = log_error_errno(r, "Failed to format calendar specification '%s': %m", *p);
1596 continue;
1597 }
1598
1599 if (!streq(t, *p))
1600 printf(" Original form: %s\n", *p);
1601
1602 printf("Normalized form: %s\n", t);
1603
1604 r = calendar_spec_next_usec(spec, n, &next);
1605 if (r == -ENOENT)
1606 printf(" Next elapse: never\n");
1607 else if (r < 0) {
1608 ret = log_error_errno(r, "Failed to determine next elapse for '%s': %m", *p);
1609 continue;
1610 } else {
1611 char buffer[CONST_MAX(FORMAT_TIMESTAMP_MAX, FORMAT_TIMESTAMP_RELATIVE_MAX)];
1612
1613 printf(" Next elapse: %s\n", format_timestamp(buffer, sizeof(buffer), next));
1614
1615 if (!in_utc_timezone())
1616 printf(" (in UTC): %s\n", format_timestamp_utc(buffer, sizeof(buffer), next));
1617
1618 printf(" From now: %s\n", format_timestamp_relative(buffer, sizeof(buffer), next));
1619 }
1620
1621 if (*(p+1))
1622 putchar('\n');
1623 }
1624
1625 return ret;
1626 }
1627
1628 static int service_watchdogs(int argc, char *argv[], void *userdata) {
1629 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1630 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
1631 int b, r;
1632
1633 assert(IN_SET(argc, 1, 2));
1634 assert(argv);
1635
1636 r = acquire_bus(&bus, NULL);
1637 if (r < 0)
1638 return log_error_errno(r, "Failed to create bus connection: %m");
1639
1640 /* get ServiceWatchdogs */
1641 if (argc == 1) {
1642 r = sd_bus_get_property_trivial(
1643 bus,
1644 "org.freedesktop.systemd1",
1645 "/org/freedesktop/systemd1",
1646 "org.freedesktop.systemd1.Manager",
1647 "ServiceWatchdogs",
1648 &error,
1649 'b',
1650 &b);
1651 if (r < 0)
1652 return log_error_errno(r, "Failed to get service-watchdog state: %s", bus_error_message(&error, r));
1653
1654 printf("%s\n", yes_no(!!b));
1655
1656 return 0;
1657 }
1658
1659 /* set ServiceWatchdogs */
1660 b = parse_boolean(argv[1]);
1661 if (b < 0) {
1662 log_error("Failed to parse service-watchdogs argument.");
1663 return -EINVAL;
1664 }
1665
1666 r = sd_bus_set_property(
1667 bus,
1668 "org.freedesktop.systemd1",
1669 "/org/freedesktop/systemd1",
1670 "org.freedesktop.systemd1.Manager",
1671 "ServiceWatchdogs",
1672 &error,
1673 "b",
1674 b);
1675 if (r < 0)
1676 return log_error_errno(r, "Failed to set service-watchdog state: %s", bus_error_message(&error, r));
1677
1678 return 0;
1679 }
1680
1681 static int do_verify(int argc, char *argv[], void *userdata) {
1682 return verify_units(strv_skip(argv, 1), arg_scope, arg_man, arg_generators);
1683 }
1684
1685 static int help(int argc, char *argv[], void *userdata) {
1686
1687 (void) pager_open(arg_no_pager, false);
1688
1689 printf("%s [OPTIONS...] {COMMAND} ...\n\n"
1690 "Profile systemd, show unit dependencies, check unit files.\n\n"
1691 " -h --help Show this help\n"
1692 " --version Show package version\n"
1693 " --no-pager Do not pipe output into a pager\n"
1694 " --system Operate on system systemd instance\n"
1695 " --user Operate on user systemd instance\n"
1696 " --global Operate on global user configuration\n"
1697 " -H --host=[USER@]HOST Operate on remote host\n"
1698 " -M --machine=CONTAINER Operate on local container\n"
1699 " --order Show only order in the graph\n"
1700 " --require Show only requirement in the graph\n"
1701 " --from-pattern=GLOB Show only origins in the graph\n"
1702 " --to-pattern=GLOB Show only destinations in the graph\n"
1703 " --fuzz=SECONDS Also print also services which finished SECONDS\n"
1704 " earlier than the latest in the branch\n"
1705 " --man[=BOOL] Do [not] check for existence of man pages\n\n"
1706 " --generators[=BOOL] Do [not] run unit generators (requires privileges)\n\n"
1707 "Commands:\n"
1708 " time Print time spent in the kernel\n"
1709 " blame Print list of running units ordered by time to init\n"
1710 " critical-chain [UNIT...] Print a tree of the time critical chain of units\n"
1711 " plot Output SVG graphic showing service initialization\n"
1712 " dot [UNIT...] Output dependency graph in man:dot(1) format\n"
1713 " log-level [LEVEL] Get/set logging threshold for manager\n"
1714 " log-target [TARGET] Get/set logging target for manager\n"
1715 " dump Output state serialization of service manager\n"
1716 " cat-config Show configuration file and drop-ins\n"
1717 " unit-paths List load directories for units\n"
1718 " syscall-filter [NAME...] Print list of syscalls in seccomp filter\n"
1719 " verify FILE... Check unit files for correctness\n"
1720 " calendar SPEC... Validate repetitive calendar time events\n"
1721 " service-watchdogs [BOOL] Get/set service watchdog state\n"
1722 , program_invocation_short_name);
1723
1724 /* When updating this list, including descriptions, apply
1725 * changes to shell-completion/bash/systemd-analyze and
1726 * shell-completion/zsh/_systemd-analyze too. */
1727
1728 return 0;
1729 }
1730
1731 static int parse_argv(int argc, char *argv[]) {
1732 enum {
1733 ARG_VERSION = 0x100,
1734 ARG_ORDER,
1735 ARG_REQUIRE,
1736 ARG_ROOT,
1737 ARG_SYSTEM,
1738 ARG_USER,
1739 ARG_GLOBAL,
1740 ARG_DOT_FROM_PATTERN,
1741 ARG_DOT_TO_PATTERN,
1742 ARG_FUZZ,
1743 ARG_NO_PAGER,
1744 ARG_MAN,
1745 ARG_GENERATORS,
1746 };
1747
1748 static const struct option options[] = {
1749 { "help", no_argument, NULL, 'h' },
1750 { "version", no_argument, NULL, ARG_VERSION },
1751 { "order", no_argument, NULL, ARG_ORDER },
1752 { "require", no_argument, NULL, ARG_REQUIRE },
1753 { "root", required_argument, NULL, ARG_ROOT },
1754 { "system", no_argument, NULL, ARG_SYSTEM },
1755 { "user", no_argument, NULL, ARG_USER },
1756 { "global", no_argument, NULL, ARG_GLOBAL },
1757 { "from-pattern", required_argument, NULL, ARG_DOT_FROM_PATTERN },
1758 { "to-pattern", required_argument, NULL, ARG_DOT_TO_PATTERN },
1759 { "fuzz", required_argument, NULL, ARG_FUZZ },
1760 { "no-pager", no_argument, NULL, ARG_NO_PAGER },
1761 { "man", optional_argument, NULL, ARG_MAN },
1762 { "generators", optional_argument, NULL, ARG_GENERATORS },
1763 { "host", required_argument, NULL, 'H' },
1764 { "machine", required_argument, NULL, 'M' },
1765 {}
1766 };
1767
1768 int r, c;
1769
1770 assert(argc >= 0);
1771 assert(argv);
1772
1773 while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0)
1774 switch (c) {
1775
1776 case 'h':
1777 return help(0, NULL, NULL);
1778
1779 case ARG_VERSION:
1780 return version();
1781
1782 case ARG_ROOT:
1783 arg_root = optarg;
1784 break;
1785
1786 case ARG_SYSTEM:
1787 arg_scope = UNIT_FILE_SYSTEM;
1788 break;
1789
1790 case ARG_USER:
1791 arg_scope = UNIT_FILE_USER;
1792 break;
1793
1794 case ARG_GLOBAL:
1795 arg_scope = UNIT_FILE_GLOBAL;
1796 break;
1797
1798 case ARG_ORDER:
1799 arg_dot = DEP_ORDER;
1800 break;
1801
1802 case ARG_REQUIRE:
1803 arg_dot = DEP_REQUIRE;
1804 break;
1805
1806 case ARG_DOT_FROM_PATTERN:
1807 if (strv_extend(&arg_dot_from_patterns, optarg) < 0)
1808 return log_oom();
1809
1810 break;
1811
1812 case ARG_DOT_TO_PATTERN:
1813 if (strv_extend(&arg_dot_to_patterns, optarg) < 0)
1814 return log_oom();
1815
1816 break;
1817
1818 case ARG_FUZZ:
1819 r = parse_sec(optarg, &arg_fuzz);
1820 if (r < 0)
1821 return r;
1822 break;
1823
1824 case ARG_NO_PAGER:
1825 arg_no_pager = true;
1826 break;
1827
1828 case 'H':
1829 arg_transport = BUS_TRANSPORT_REMOTE;
1830 arg_host = optarg;
1831 break;
1832
1833 case 'M':
1834 arg_transport = BUS_TRANSPORT_MACHINE;
1835 arg_host = optarg;
1836 break;
1837
1838 case ARG_MAN:
1839 if (optarg) {
1840 r = parse_boolean(optarg);
1841 if (r < 0) {
1842 log_error("Failed to parse --man= argument.");
1843 return -EINVAL;
1844 }
1845
1846 arg_man = r;
1847 } else
1848 arg_man = true;
1849
1850 break;
1851
1852 case ARG_GENERATORS:
1853 if (optarg) {
1854 r = parse_boolean(optarg);
1855 if (r < 0) {
1856 log_error("Failed to parse --generators= argument.");
1857 return -EINVAL;
1858 }
1859
1860 arg_generators = r;
1861 } else
1862 arg_generators = true;
1863
1864 break;
1865
1866 case '?':
1867 return -EINVAL;
1868
1869 default:
1870 assert_not_reached("Unhandled option code.");
1871 }
1872
1873 if (arg_scope == UNIT_FILE_GLOBAL &&
1874 !STR_IN_SET(argv[optind] ?: "time", "dot", "unit-paths", "verify")) {
1875 log_error("Option --global only makes sense with verbs dot, unit-paths, verify.");
1876 return -EINVAL;
1877 }
1878
1879 if (arg_root && !streq_ptr(argv[optind], "cat-config")) {
1880 log_error("Option --root is only supported for cat-config right now.");
1881 return -EINVAL;
1882 }
1883
1884 return 1; /* work to do */
1885 }
1886
1887 int main(int argc, char *argv[]) {
1888
1889 static const Verb verbs[] = {
1890 { "help", VERB_ANY, VERB_ANY, 0, help },
1891 { "time", VERB_ANY, 1, VERB_DEFAULT, analyze_time },
1892 { "blame", VERB_ANY, 1, 0, analyze_blame },
1893 { "critical-chain", VERB_ANY, VERB_ANY, 0, analyze_critical_chain },
1894 { "plot", VERB_ANY, 1, 0, analyze_plot },
1895 { "dot", VERB_ANY, VERB_ANY, 0, dot },
1896 { "log-level", VERB_ANY, 2, 0, get_or_set_log_level },
1897 { "log-target", VERB_ANY, 2, 0, get_or_set_log_target },
1898 /* The following four verbs are deprecated aliases */
1899 { "set-log-level", 2, 2, 0, set_log_level },
1900 { "get-log-level", VERB_ANY, 1, 0, get_log_level },
1901 { "set-log-target", 2, 2, 0, set_log_target },
1902 { "get-log-target", VERB_ANY, 1, 0, get_log_target },
1903 { "dump", VERB_ANY, 1, 0, dump },
1904 { "cat-config", 2, VERB_ANY, 0, cat_config },
1905 { "unit-paths", 1, 1, 0, dump_unit_paths },
1906 { "syscall-filter", VERB_ANY, VERB_ANY, 0, dump_syscall_filters },
1907 { "verify", 2, VERB_ANY, 0, do_verify },
1908 { "calendar", 2, VERB_ANY, 0, test_calendar },
1909 { "service-watchdogs", VERB_ANY, 2, 0, service_watchdogs },
1910 {}
1911 };
1912
1913 int r;
1914
1915 setlocale(LC_ALL, "");
1916 setlocale(LC_NUMERIC, "C"); /* we want to format/parse floats in C style */
1917
1918 log_parse_environment();
1919 log_open();
1920
1921 r = parse_argv(argc, argv);
1922 if (r <= 0)
1923 goto finish;
1924
1925 r = dispatch_verb(argc, argv, verbs, NULL);
1926
1927 finish:
1928 pager_close();
1929
1930 strv_free(arg_dot_from_patterns);
1931 strv_free(arg_dot_to_patterns);
1932
1933 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
1934 }