import.c revision 7eeeb28e45ae4d436bdccad1d519cfcb81c0762d
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2014 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic bool arg_force = false;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic void on_finished(DckImport *import, int error, void *userdata) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_info("Operation completed successfully.");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_info_errno(error, "Operation failed: %m");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int pull_dck(int argc, char *argv[], void *userdata) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _cleanup_(dck_import_unrefp) DckImport *import = NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _cleanup_event_unref_ sd_event *event = NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_error("Remote name '%s' is not valid.", name);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_error("Tag name '%s' is not valid.", tag);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *p;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_error("Local image name '%s' is not valid.", local);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering p = strappenda("/var/lib/container/", local);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_info("Image '%s' already exists.", local);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return log_error_errno(errno, "Can't check if image '%s' already exists: %m", local);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_info("Pulling '%s' with tag '%s', saving as '%s'.", name, tag, local);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_info("Pulling '%s' with tag '%s'.", name, tag);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return log_error_errno(r, "Failed to allocate event loop: %m");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert_se(sigprocmask_many(SIG_BLOCK, SIGTERM, SIGINT, -1) == 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering sd_event_add_signal(event, NULL, SIGINT, NULL, NULL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = dck_import_new(&import, event, on_finished, event);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return log_error_errno(r, "Failed to allocate importer: %m");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = dck_import_pull(import, name, tag, local, arg_force);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return log_error_errno(r, "Failed to pull image: %m");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return log_error_errno(r, "Failed to run event loop: %m");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int help(int argc, char *argv[], void *userdata) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering printf("%s [OPTIONS...] {COMMAND} ...\n\n"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering "Import container or virtual machine image.\n\n"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " -h --help Show this help\n"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " --version Show package version\n"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " --force Force creation of image\n\n"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering " pull-dck REMOTE [NAME] Download an image\n",
b9d394ea565fd742bcdd34e8dd61ae07c58a9565Lennart Poetteringstatic int parse_argv(int argc, char *argv[]) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "version", no_argument, NULL, ARG_VERSION },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "force", no_argument, NULL, ARG_FORCE },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int import_main(int argc, char *argv[]) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return dispatch_verb(argc, argv, verbs, NULL);