-/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
- This file is part of systemd.
-
- Copyright 2015 Lennart Poettering
-***/
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <getopt.h>
+#include <locale.h>
#include "sd-event.h"
#include "sd-id128.h"
#include "alloc-util.h"
+#include "discover-image.h"
#include "export-raw.h"
#include "export-tar.h"
#include "fd-util.h"
#include "fs-util.h"
#include "hostname-util.h"
#include "import-util.h"
-#include "machine-image.h"
+#include "main-func.h"
#include "signal-util.h"
#include "string-util.h"
#include "verbs.h"
_cleanup_close_ int open_fd = -1;
int r, fd;
- if (machine_name_is_valid(argv[1])) {
- r = image_find(IMAGE_MACHINE, argv[1], &image);
+ if (hostname_is_valid(argv[1], 0)) {
+ r = image_find(IMAGE_MACHINE, argv[1], NULL, &image);
if (r == -ENOENT)
return log_error_errno(r, "Machine image %s not found.", argv[1]);
if (r < 0)
if (argc >= 3)
path = argv[2];
- if (isempty(path) || streq(path, "-"))
- path = NULL;
+ path = empty_or_dash_to_null(path);
determine_compression_from_filename(path);
fd = STDOUT_FILENO;
- (void) readlink_malloc("/proc/self/fd/1", &pretty);
+ (void) fd_get_path(fd, &pretty);
log_info("Exporting '%s', saving to '%s' with compression '%s'.", local, strna(pretty), import_compress_type_to_string(arg_compress));
}
_cleanup_close_ int open_fd = -1;
int r, fd;
- if (machine_name_is_valid(argv[1])) {
- r = image_find(IMAGE_MACHINE, argv[1], &image);
+ if (hostname_is_valid(argv[1], 0)) {
+ r = image_find(IMAGE_MACHINE, argv[1], NULL, &image);
if (r == -ENOENT)
return log_error_errno(r, "Machine image %s not found.", argv[1]);
if (r < 0)
if (argc >= 3)
path = argv[2];
- if (isempty(path) || streq(path, "-"))
- path = NULL;
+ path = empty_or_dash_to_null(path);
determine_compression_from_filename(path);
fd = STDOUT_FILENO;
- (void) readlink_malloc("/proc/self/fd/1", &pretty);
+ (void) fd_get_path(fd, &pretty);
log_info("Exporting '%s', saving to '%s' with compression '%s'.", local, strna(pretty), import_compress_type_to_string(arg_compress));
}
arg_compress = IMPORT_COMPRESS_GZIP;
else if (streq(optarg, "bzip2"))
arg_compress = IMPORT_COMPRESS_BZIP2;
- else {
- log_error("Unknown format: %s", optarg);
- return -EINVAL;
- }
+ else
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown format: %s", optarg);
break;
case '?':
return -EINVAL;
default:
- assert_not_reached("Unhandled option");
+ assert_not_reached();
}
return 1;
}
static int export_main(int argc, char *argv[]) {
-
static const Verb verbs[] = {
{ "help", VERB_ANY, VERB_ANY, 0, help },
{ "tar", 2, 3, 0, export_tar },
return dispatch_verb(argc, argv, verbs, NULL);
}
-int main(int argc, char *argv[]) {
+static int run(int argc, char *argv[]) {
int r;
setlocale(LC_ALL, "");
r = parse_argv(argc, argv);
if (r <= 0)
- goto finish;
+ return r;
- (void) ignore_signals(SIGPIPE, -1);
+ (void) ignore_signals(SIGPIPE);
- r = export_main(argc, argv);
-
-finish:
- return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+ return export_main(argc, argv);
}
+
+DEFINE_MAIN_FUNCTION(run);