X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fimport%2Fimport-dkr.c;h=24ba766b1383c34f4ae940092abd8e49791115a8;hb=2c140ded48fc31e3c80a92a1f755a2b1ab6e1a30;hp=1a6cd4eaffc29d2767ee88618f84531ee3cf6a79;hpb=f4c135bf2f0abcf79c89efbeae51f03bacba5f2f;p=elogind.git diff --git a/src/import/import-dkr.c b/src/import/import-dkr.c index 1a6cd4eaf..24ba766b1 100644 --- a/src/import/import-dkr.c +++ b/src/import/import-dkr.c @@ -28,10 +28,11 @@ #include "btrfs-util.h" #include "utf8.h" #include "mkdir.h" +#include "import-util.h" #include "curl-util.h" #include "aufs-util.h" -#include "import-util.h" #include "import-job.h" +#include "import-common.h" #include "import-dkr.h" struct DkrImport { @@ -400,7 +401,6 @@ static int dkr_import_make_local_copy(DkrImport *i) { } static int dkr_import_job_on_open_disk(ImportJob *j) { - _cleanup_close_pair_ int pipefd[2] = { -1, -1 }; const char *base; DkrImport *i; int r; @@ -431,58 +431,9 @@ static int dkr_import_job_on_open_disk(ImportJob *j) { if (r < 0) return log_error_errno(r, "Failed to make btrfs subvolume %s: %m", i->temp_path); - if (pipe2(pipefd, O_CLOEXEC) < 0) - return log_error_errno(errno, "Failed to create pipe for tar: %m"); - - i->tar_pid = fork(); - if (i->tar_pid < 0) - return log_error_errno(errno, "Failed to fork off tar: %m"); - if (i->tar_pid == 0) { - int null_fd; - - /* Child */ - - reset_all_signal_handlers(); - reset_signal_mask(); - assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0); - - pipefd[1] = safe_close(pipefd[1]); - - if (dup2(pipefd[0], STDIN_FILENO) != STDIN_FILENO) { - log_error_errno(errno, "Failed to dup2() fd: %m"); - _exit(EXIT_FAILURE); - } - - if (pipefd[0] != STDIN_FILENO) - pipefd[0] = safe_close(pipefd[0]); - - null_fd = open("/dev/null", O_WRONLY|O_NOCTTY); - if (null_fd < 0) { - log_error_errno(errno, "Failed to open /dev/null: %m"); - _exit(EXIT_FAILURE); - } - - if (dup2(null_fd, STDOUT_FILENO) != STDOUT_FILENO) { - log_error_errno(errno, "Failed to dup2() fd: %m"); - _exit(EXIT_FAILURE); - } - - if (null_fd != STDOUT_FILENO) - null_fd = safe_close(null_fd); - - fd_cloexec(STDIN_FILENO, false); - fd_cloexec(STDOUT_FILENO, false); - fd_cloexec(STDERR_FILENO, false); - - execlp("tar", "tar", "--numeric-owner", "-C", i->temp_path, "-px", NULL); - log_error_errno(errno, "Failed to execute tar: %m"); - _exit(EXIT_FAILURE); - } - - pipefd[0] = safe_close(pipefd[0]); - - j->disk_fd = pipefd[1]; - pipefd[1] = -1; + j->disk_fd = import_fork_tar(i->temp_path, &i->tar_pid); + if (j->disk_fd < 0) + return j->disk_fd; return 0; } @@ -854,34 +805,3 @@ int dkr_import_pull(DkrImport *i, const char *name, const char *tag, const char return import_job_begin(i->images_job); } - -bool dkr_name_is_valid(const char *name) { - const char *slash, *p; - - if (isempty(name)) - return false; - - slash = strchr(name, '/'); - if (!slash) - return false; - - if (!filename_is_valid(slash + 1)) - return false; - - p = strndupa(name, slash - name); - if (!filename_is_valid(p)) - return false; - - return true; -} - -bool dkr_id_is_valid(const char *id) { - - if (!filename_is_valid(id)) - return false; - - if (!in_charset(id, "0123456789abcdef")) - return false; - - return true; -}