import-tar.c revision 8c9cfc28448bf671807e7d96b580221edebd71da
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering This file is part of systemd.
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering Copyright 2015 Lennart Poettering
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering systemd is free software; you can redistribute it and/or modify it
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering under the terms of the GNU Lesser General Public License as published by
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering (at your option) any later version.
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering systemd is distributed in the hope that it will be useful, but
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering Lesser General Public License for more details.
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering You should have received a copy of the GNU Lesser General Public License
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
f23e83b156da8966e43e303dced5439503450d21Zbigniew Jędrzejewski-SzmekTarImport* tar_import_unref(TarImport *i) {
f23e83b156da8966e43e303dced5439503450d21Zbigniew Jędrzejewski-Szmek sd_event_source_unref(i->input_event_source);
f23e83b156da8966e43e303dced5439503450d21Zbigniew Jędrzejewski-Szmek (void) kill_and_sigcont(i->tar_pid, SIGKILL);
f23e83b156da8966e43e303dced5439503450d21Zbigniew Jędrzejewski-Szmek (void) wait_for_terminate(i->tar_pid, NULL);
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering (void) rm_rf(i->temp_path, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
f23e83b156da8966e43e303dced5439503450d21Zbigniew Jędrzejewski-Szmek import_compress_free(&i->compress);
2c86ba5a51b29e41bdfde6771d93cc5317b253cfZbigniew Jędrzejewski-Szmek _cleanup_(tar_import_unrefp) TarImport *i = NULL;
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering RATELIMIT_INIT(i->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering i->image_root = strdup(image_root ?: "/var/lib/machines");
dc83f27a7cf03757dec11a69ec18504ad4ea8f89Lennart Poettering i->grow_machine_directory = path_startswith(i->image_root, "/var/lib/machines");
*ret = i;
i = NULL;
unsigned percent;
assert(i);
assert(i);
if (i->tar_pid > 0) {
i->tar_pid = 0;
if (i->read_only) {
if (i->force_local)
assert(i);
if (!i->final_path)
return log_oom();
return log_oom();
if (r == -ENOTTY) {
if (i->tar_fd < 0)
return i->tar_fd;
i->written_since_last_grow = 0;
ssize_t l;
assert(i);
goto finish;
r = -EIO;
goto finish;
r = tar_import_finish(i);
goto finish;
i->buffer_size += l;
goto finish;
r = tar_import_fork_tar(i);
goto finish;
goto finish;
i->buffer_size = 0;
if (i->on_finished)
return tar_import_process(i);
return tar_import_process(i);
assert(i);
return -EINVAL;
if (i->input_fd >= 0)
return -EBUSY;
return -errno;
if (r == -EPERM) {