X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Fimport%2Fimport.c;h=f34244acff2e71f81879cecf1f457204d7a49bb0;hb=9a43fc6a2ad9e88719c4496fbeebf18cfb65cbb2;hp=454e64e3cb3c2f3af78b97f939fc5fac5a9395f0;hpb=c3de717e5121167fd9e744e0712dbd09d79233bc;p=thirdparty%2Fsystemd.git
diff --git a/src/import/import.c b/src/import/import.c
index 454e64e3cb3..f34244acff2 100644
--- a/src/import/import.c
+++ b/src/import/import.c
@@ -1,22 +1,4 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
- This file is part of systemd.
-
- Copyright 2015 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see .
-***/
#include
@@ -31,6 +13,7 @@
#include "import-tar.h"
#include "import-util.h"
#include "machine-image.h"
+#include "main-func.h"
#include "signal-util.h"
#include "string-util.h"
#include "verbs.h"
@@ -88,10 +71,11 @@ static int import_tar(int argc, char *argv[], void *userdata) {
}
if (!arg_force) {
- r = image_find(local, NULL);
- if (r < 0)
- return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
- else if (r > 0) {
+ r = image_find(IMAGE_MACHINE, local, NULL);
+ if (r < 0) {
+ if (r != -ENOENT)
+ return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
+ } else {
log_error("Image '%s' already exists.", local);
return -EEXIST;
}
@@ -112,7 +96,7 @@ static int import_tar(int argc, char *argv[], void *userdata) {
fd = STDIN_FILENO;
- (void) readlink_malloc("/proc/self/fd/0", &pretty);
+ (void) fd_get_path(fd, &pretty);
log_info("Importing '%s', saving as '%s'.", strna(pretty), local);
}
@@ -183,10 +167,11 @@ static int import_raw(int argc, char *argv[], void *userdata) {
}
if (!arg_force) {
- r = image_find(local, NULL);
- if (r < 0)
- return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
- else if (r > 0) {
+ r = image_find(IMAGE_MACHINE, local, NULL);
+ if (r < 0) {
+ if (r != -ENOENT)
+ return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
+ } else {
log_error("Image '%s' already exists.", local);
return -EEXIST;
}
@@ -207,8 +192,8 @@ static int import_raw(int argc, char *argv[], void *userdata) {
fd = STDIN_FILENO;
- (void) readlink_malloc("/proc/self/fd/0", &pretty);
- log_info("Importing '%s', saving as '%s'.", pretty, local);
+ (void) fd_get_path(fd, &pretty);
+ log_info("Importing '%s', saving as '%s'.", strempty(pretty), local);
}
r = sd_event_default(&event);
@@ -308,7 +293,6 @@ static int parse_argv(int argc, char *argv[]) {
}
static int import_main(int argc, char *argv[]) {
-
static const Verb verbs[] = {
{ "help", VERB_ANY, VERB_ANY, 0, help },
{ "tar", 2, 3, 0, import_tar },
@@ -319,7 +303,7 @@ static int import_main(int argc, char *argv[]) {
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, "");
@@ -328,12 +312,11 @@ int main(int argc, char *argv[]) {
r = parse_argv(argc, argv);
if (r <= 0)
- goto finish;
+ return 0;
(void) ignore_signals(SIGPIPE, -1);
- r = import_main(argc, argv);
-
-finish:
- return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+ return import_main(argc, argv);
}
+
+DEFINE_MAIN_FUNCTION(run);