diff mbox

[OpenWrt-Devel,procd,8/9] ujail: split name (-n) and hostname (-h) options

Message ID 1448924967-63976-9-git-send-email-champetier.etienne@gmail.com
State Accepted
Headers show

Commit Message

Etienne Champetier Nov. 30, 2015, 11:09 p.m. UTC
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
---
 jail/jail.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/jail/jail.c b/jail/jail.c
index 97ddaab..541363a 100644
--- a/jail/jail.c
+++ b/jail/jail.c
@@ -35,10 +35,11 @@ 
 #include <libubox/uloop.h>
 
 #define STACK_SIZE	(1024 * 1024)
-#define OPT_ARGS	"S:C:n:r:w:d:psuloc"
+#define OPT_ARGS	"S:C:n:h:r:w:d:psuloc"
 
 static struct {
 	char *name;
+	char *hostname;
 	char **jail_argv;
 	char *seccomp;
 	char *capabilities;
@@ -216,6 +217,7 @@  static void usage(void)
 	fprintf(stderr, "  -c\t\tset PR_SET_NO_NEW_PRIVS\n");
 	fprintf(stderr, "  -n <name>\tthe name of the jail\n");
 	fprintf(stderr, "namespace jail options:\n");
+	fprintf(stderr, "  -h <hostname>\tchange the hostname of the jail\n");
 	fprintf(stderr, "  -r <file>\treadonly files that should be staged\n");
 	fprintf(stderr, "  -w <file>\twriteable files that should be staged\n");
 	fprintf(stderr, "  -p\t\tjail has /proc\n");
@@ -255,8 +257,8 @@  static int exec_jail(void)
 
 static int spawn_jail(void *_notused)
 {
-	if (opts.name && sethostname(opts.name, strlen(opts.name))) {
-		ERROR("failed to sethostname: %s\n", strerror(errno));
+	if (opts.hostname && sethostname(opts.hostname, strlen(opts.hostname))) {
+		ERROR("sethostname(%s) failed: %s\n", opts.hostname, strerror(errno));
 	}
 
 	if (build_jail_fs()) {
@@ -334,6 +336,9 @@  int main(int argc, char **argv)
 		case 'n':
 			opts.name = optarg;
 			break;
+		case 'h':
+			opts.hostname = optarg;
+			break;
 		case 'r':
 			opts.namespace = 1;
 			add_path_and_deps(optarg, 1, 0, 0);