| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "alloc-util.h" |
| 4 |
#include "analyze.h" |
| 5 |
#include "analyze-verify-util.h" |
| 6 |
#include "analyze-verify.h" |
| 7 |
#include "copy.h" |
| 8 |
#include "extract-word.h" |
| 9 |
#include "log.h" |
| 10 |
#include "path-util.h" |
| 11 |
#include "rm-rf.h" |
| 12 |
#include "runtime-scope.h" |
| 13 |
#include "strv.h" |
| 14 |
#include "tmpfile-util.h" |
| 15 |
|
| 16 |
static int process_aliases(char *argv[], char *tempdir, char ***ret) { |
| 17 |
_cleanup_strv_free_ char **filenames = NULL; |
| 18 |
int r; |
| 19 |
|
| 20 |
assert(argv); |
| 21 |
assert(tempdir); |
| 22 |
assert(ret); |
| 23 |
|
| 24 |
STRV_FOREACH(filename, strv_skip(argv, 1)) { |
| 25 |
_cleanup_free_ char *src = NULL, *dst = NULL, *base = NULL; |
| 26 |
const char *parse_arg; |
| 27 |
|
| 28 |
parse_arg = *filename; |
| 29 |
r = extract_first_word(&parse_arg, &src, ":", EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_RETAIN_ESCAPE); |
| 30 |
if (r < 0) |
| 31 |
return r; |
| 32 |
|
| 33 |
if (!parse_arg) { |
| 34 |
r = strv_consume(&filenames, TAKE_PTR(src)); |
| 35 |
if (r < 0) |
| 36 |
return r; |
| 37 |
|
| 38 |
continue; |
| 39 |
} |
| 40 |
|
| 41 |
r = path_extract_filename(parse_arg, &base); |
| 42 |
if (r < 0) |
| 43 |
return r; |
| 44 |
|
| 45 |
dst = path_join(tempdir, base); |
| 46 |
if (!dst) |
| 47 |
return -ENOMEM; |
| 48 |
|
| 49 |
r = copy_file(src, dst, 0, 0644, COPY_REFLINK); |
| 50 |
if (r < 0) |
| 51 |
return r; |
| 52 |
|
| 53 |
r = strv_consume(&filenames, TAKE_PTR(dst)); |
| 54 |
if (r < 0) |
| 55 |
return r; |
| 56 |
} |
| 57 |
|
| 58 |
*ret = TAKE_PTR(filenames); |
| 59 |
return 0; |
| 60 |
} |
| 61 |
|
| 62 |
int verb_verify(int argc, char *argv[], uintptr_t _data, void *userdata) { |
| 63 |
_cleanup_strv_free_ char **filenames = NULL; |
| 64 |
_cleanup_(rm_rf_physical_and_freep) char *tempdir = NULL; |
| 65 |
int r; |
| 66 |
|
| 67 |
r = mkdtemp_malloc("/tmp/systemd-analyze-XXXXXX", &tempdir); |
| 68 |
if (r < 0) |
| 69 |
return log_error_errno(r, "Failed to setup working directory: %m"); |
| 70 |
|
| 71 |
r = process_aliases(argv, tempdir, &filenames); |
| 72 |
if (r < 0) |
| 73 |
return log_error_errno(r, "Couldn't process aliases: %m"); |
| 74 |
|
| 75 |
return verify_units(filenames, arg_runtime_scope, arg_man, arg_generators, arg_recursive_errors, arg_root); |
| 76 |
} |