import-common.c revision ce30c8dcb41dfe9264f79f30c7f51c0e74576638
/*-*- 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 <unistd.h>
#include "util.h"
#include "btrfs-util.h"
#include "capability.h"
#include "signal-util.h"
#include "import-common.h"
int import_make_read_only_fd(int fd) {
int r;
/* First, let's make this a read-only subvolume if it refers
* to a subvolume */
r = btrfs_subvol_set_read_only_fd(fd, true);
/* This doesn't refer to a subvolume, or the file
* system isn't even btrfs. In that, case fall back to
* chmod()ing */
if (r < 0)
/* Drop "w" flag */
return 0;
} else if (r < 0)
return log_error_errno(r, "Failed to make subvolume read-only: %m");
return 0;
}
int import_make_read_only(const char *path) {
if (fd < 0)
return import_make_read_only_fd(fd);
}
int r;
if (pid < 0)
if (pid == 0) {
int null_fd;
(1ULL << CAP_CHOWN) |
(1ULL << CAP_FOWNER) |
(1ULL << CAP_FSETID) |
(1ULL << CAP_MKNOD) |
(1ULL << CAP_SETFCAP) |
(1ULL << CAP_DAC_OVERRIDE);
/* Child */
(void) reset_all_signal_handlers();
(void) reset_signal_mask();
}
if (pipefd[0] != STDIN_FILENO)
if (null_fd < 0) {
}
}
if (null_fd != STDOUT_FILENO)
fd_cloexec(STDIN_FILENO, false);
fd_cloexec(STDOUT_FILENO, false);
fd_cloexec(STDERR_FILENO, false);
if (unshare(CLONE_NEWNET) < 0)
r = capability_bounding_set_drop(~retain, true);
if (r < 0)
log_error_errno(r, "Failed to drop capabilities, ignoring: %m");
}
r = pipefd[1];
return r;
}
int r;
if (pid < 0)
if (pid == 0) {
int null_fd;
/* Child */
(void) reset_all_signal_handlers();
(void) reset_signal_mask();
}
if (null_fd < 0) {
}
}
if (null_fd != STDIN_FILENO)
fd_cloexec(STDIN_FILENO, false);
fd_cloexec(STDOUT_FILENO, false);
fd_cloexec(STDERR_FILENO, false);
if (unshare(CLONE_NEWNET) < 0)
r = capability_bounding_set_drop(~retain, true);
if (r < 0)
log_error_errno(r, "Failed to drop capabilities, ignoring: %m");
}
r = pipefd[0];
pipefd[0] = -1;
return r;
}