export.c revision 25300b5a1fcf54674a69d0f4ab08925be00b0227
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2015 Lennart Poettering
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 <http://www.gnu.org/licenses/>.
***/
#include <getopt.h>
#include "sd-event.h"
#include "event-util.h"
#include "signal-util.h"
#include "hostname-util.h"
#include "verbs.h"
#include "build.h"
#include "machine-image.h"
#include "import-util.h"
#include "export-tar.h"
#include "export-raw.h"
static void determine_compression_from_filename(const char *p) {
if (arg_compress != IMPORT_COMPRESS_UNKNOWN)
return;
if (!p) {
return;
}
if (endswith(p, ".xz"))
else if (endswith(p, ".gz"))
else if (endswith(p, ".bz2"))
else
}
static int interrupt_signal_handler(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
log_notice("Transfer aborted.");
return 0;
}
if (error == 0)
log_info("Operation completed successfully.");
}
int r, fd;
if (r < 0)
if (r == 0) {
return -ENOENT;
}
} else
if (argc >= 3)
if (path) {
if (open_fd < 0)
log_info("Exporting '%s', saving to '%s' with compression '%s'.", local, path, import_compress_type_to_string(arg_compress));
} else {
fd = STDOUT_FILENO;
log_info("Exporting '%s', saving to '%s' with compression '%s'.", local, strna(pretty), import_compress_type_to_string(arg_compress));
}
r = sd_event_default(&event);
if (r < 0)
return log_error_errno(r, "Failed to allocate event loop: %m");
if (r < 0)
return log_error_errno(r, "Failed to allocate exporter: %m");
if (r < 0)
return log_error_errno(r, "Failed to export image: %m");
r = sd_event_loop(event);
if (r < 0)
return log_error_errno(r, "Failed to run event loop: %m");
log_info("Exiting.");
return -r;
}
if (error == 0)
log_info("Operation completed successfully.");
}
int r, fd;
if (r < 0)
if (r == 0) {
return -ENOENT;
}
} else
if (argc >= 3)
if (path) {
if (open_fd < 0)
log_info("Exporting '%s', saving to '%s' with compression '%s'.", local, path, import_compress_type_to_string(arg_compress));
} else {
fd = STDOUT_FILENO;
log_info("Exporting '%s', saving to '%s' with compression '%s'.", local, strna(pretty), import_compress_type_to_string(arg_compress));
}
r = sd_event_default(&event);
if (r < 0)
return log_error_errno(r, "Failed to allocate event loop: %m");
if (r < 0)
return log_error_errno(r, "Failed to allocate exporter: %m");
if (r < 0)
return log_error_errno(r, "Failed to export image: %m");
r = sd_event_loop(event);
if (r < 0)
return log_error_errno(r, "Failed to run event loop: %m");
log_info("Exiting.");
return -r;
}
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
"Export container or virtual machine images.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --format=FORMAT Select format\n\n"
"Commands:\n"
" tar NAME [FILE] Export a TAR image\n"
" raw NAME [FILE] Export a RAW image\n",
return 0;
}
enum {
ARG_VERSION = 0x100,
};
{}
};
int c;
switch (c) {
case 'h':
case ARG_VERSION:
return 0;
case ARG_FORMAT:
else {
return -EINVAL;
}
break;
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
}
return 1;
}
{}
};
}
int r;
log_open();
if (r <= 0)
goto finish;
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}