mirror of
https://github.com/systemd/systemd.git
synced 2024-11-02 19:21:53 +03:00
nspawn: be more careful when initializing the hostname from the directory name
This commit is contained in:
parent
eaeb18dba9
commit
3a74cea5e4
@ -101,8 +101,9 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
free(arg_directory);
|
free(arg_directory);
|
||||||
if (!(arg_directory = strdup(optarg))) {
|
arg_directory = canonicalize_file_name(optarg);
|
||||||
log_error("Failed to duplicate root directory.");
|
if (!arg_directory) {
|
||||||
|
log_error("Failed to canonicalize root directory.");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,6 +475,28 @@ finish:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int setup_hostname(void) {
|
||||||
|
char *hn;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
|
hn = file_name_from_path(arg_directory);
|
||||||
|
if (hn) {
|
||||||
|
hn = strdup(hn);
|
||||||
|
if (!hn)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
hostname_cleanup(hn);
|
||||||
|
|
||||||
|
if (!isempty(hn))
|
||||||
|
if (sethostname(hn, strlen(hn)) < 0)
|
||||||
|
r = -errno;
|
||||||
|
|
||||||
|
free(hn);
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
static int drop_capabilities(void) {
|
static int drop_capabilities(void) {
|
||||||
static const unsigned long retain[] = {
|
static const unsigned long retain[] = {
|
||||||
CAP_CHOWN,
|
CAP_CHOWN,
|
||||||
@ -872,7 +895,6 @@ int main(int argc, char *argv[]) {
|
|||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
/* child */
|
/* child */
|
||||||
|
|
||||||
const char *hn;
|
|
||||||
const char *home = NULL;
|
const char *home = NULL;
|
||||||
uid_t uid = (uid_t) -1;
|
uid_t uid = (uid_t) -1;
|
||||||
gid_t gid = (gid_t) -1;
|
gid_t gid = (gid_t) -1;
|
||||||
@ -1000,8 +1022,7 @@ int main(int argc, char *argv[]) {
|
|||||||
goto child_fail;
|
goto child_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((hn = file_name_from_path(arg_directory)))
|
setup_hostname();
|
||||||
sethostname(hn, strlen(hn));
|
|
||||||
|
|
||||||
if (argc > optind)
|
if (argc > optind)
|
||||||
execvpe(argv[optind], argv + optind, (char**) envp);
|
execvpe(argv[optind], argv + optind, (char**) envp);
|
||||||
|
Loading…
Reference in New Issue
Block a user