summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-04-22 14:48:21 +0200
committerLennart Poettering <lennart@poettering.net>2012-04-22 14:48:21 +0200
commit144f0fc0c8a5e2f6b72179e2b5fb992474da24ad (patch)
treee4fc1365bf85387bcfed6fecb1417485772213e7 /src
parent5cd6eef69b926175b889799d80bd9deb33a904d1 (diff)
nspawn: add --uuid= switch to allow setting the machine id for the container
Diffstat (limited to 'src')
-rw-r--r--src/nspawn/nspawn.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 7050c05ec2..bf3a84471d 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -55,6 +55,7 @@
static char *arg_directory = NULL;
static char *arg_user = NULL;
static char **arg_controllers = NULL;
+static char *arg_uuid = NULL;
static bool arg_private_network = false;
static bool arg_boot = false;
@@ -67,6 +68,7 @@ static int help(void) {
" -b --boot Boot up full system (i.e. invoke init)\n"
" -u --user=USER Run the command under specified user or uid\n"
" -C --controllers=LIST Put the container in specified comma-separated cgroup hierarchies\n"
+ " --uuid=UUID Set a specific machine UUID for the container\n"
" --private-network Disable network in container\n",
program_invocation_short_name);
@@ -76,7 +78,8 @@ static int help(void) {
static int parse_argv(int argc, char *argv[]) {
enum {
- ARG_PRIVATE_NETWORK = 0x100
+ ARG_PRIVATE_NETWORK = 0x100,
+ ARG_UUID
};
static const struct option options[] = {
@@ -86,6 +89,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "controllers", required_argument, NULL, 'C' },
{ "private-network", no_argument, NULL, ARG_PRIVATE_NETWORK },
{ "boot", no_argument, NULL, 'b' },
+ { "uuid", required_argument, NULL, ARG_UUID },
{ NULL, 0, NULL, 0 }
};
@@ -140,6 +144,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_boot = true;
break;
+ case ARG_UUID:
+ arg_uuid = optarg;
+ break;
+
case '?':
return -EINVAL;
@@ -912,6 +920,7 @@ int main(int argc, char *argv[]) {
NULL, /* HOME */
NULL, /* USER */
NULL, /* LOGNAME */
+ NULL, /* container_uuid */
NULL
};
@@ -1022,13 +1031,20 @@ int main(int argc, char *argv[]) {
}
}
- if ((asprintf((char**)(envp + 3), "HOME=%s", home? home: "/root") < 0) ||
- (asprintf((char**)(envp + 4), "USER=%s", arg_user? arg_user : "root") < 0) ||
- (asprintf((char**)(envp + 5), "LOGNAME=%s", arg_user? arg_user : "root") < 0)) {
+ if ((asprintf((char**)(envp + 3), "HOME=%s", home ? home: "/root") < 0) ||
+ (asprintf((char**)(envp + 4), "USER=%s", arg_user ? arg_user : "root") < 0) ||
+ (asprintf((char**)(envp + 5), "LOGNAME=%s", arg_user ? arg_user : "root") < 0)) {
log_error("Out of memory");
goto child_fail;
}
+ if (arg_uuid) {
+ if (asprintf((char**)(envp + 6), "container_uuid=%s", arg_uuid) < 0) {
+ log_error("Out of memory");
+ goto child_fail;
+ }
+ }
+
setup_hostname();
if (arg_boot) {