aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDanish Prakash <contact@danishpraka.sh>2024-07-30 11:31:23 +0530
committerStefano Brivio <sbrivio@redhat.com>2024-07-30 17:27:43 +0200
commit0149d11cc5043d618cf4a6e6e8201d5718836dd2 (patch)
tree212d2d37cba093e07a18e70cbe1b3abe767a9a90
parent8fae3b73cb1451f766037583c02d86971502f5eb (diff)
downloadpasst-0149d11cc5043d618cf4a6e6e8201d5718836dd2.tar
passt-0149d11cc5043d618cf4a6e6e8201d5718836dd2.tar.gz
passt-0149d11cc5043d618cf4a6e6e8201d5718836dd2.tar.bz2
passt-0149d11cc5043d618cf4a6e6e8201d5718836dd2.tar.lz
passt-0149d11cc5043d618cf4a6e6e8201d5718836dd2.tar.xz
passt-0149d11cc5043d618cf4a6e6e8201d5718836dd2.tar.zst
passt-0149d11cc5043d618cf4a6e6e8201d5718836dd2.zip
pasta: modify hostname when detaching new namespace
When invoking pasta without any arguments, it's difficult to tell whether we are in the new namespace or not leaving users a bit confused. This change modifies the host namespace to add a prefix "pasta-" to make it a bit more obvious. Signed-off-by: Danish Prakash <contact@danishpraka.sh> [sbrivio: coding style fixes] Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--pasta.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/pasta.c b/pasta.c
index 084288c..572048d 100644
--- a/pasta.c
+++ b/pasta.c
@@ -50,6 +50,8 @@
#include "netlink.h"
#include "log.h"
+#define HOSTNAME_PREFIX "pasta-"
+
/* PID of child, in case we created a namespace */
int pasta_child_pid;
@@ -177,6 +179,7 @@ struct pasta_spawn_cmd_arg {
/* cppcheck-suppress [constParameterCallback, unmatchedSuppression] */
static int pasta_spawn_cmd(void *arg)
{
+ char hostname[HOST_NAME_MAX + 1] = HOSTNAME_PREFIX;
const struct pasta_spawn_cmd_arg *a;
sigset_t set;
@@ -187,6 +190,14 @@ static int pasta_spawn_cmd(void *arg)
if (write_file("/proc/sys/net/ipv4/ping_group_range", "0 0"))
warn("Cannot set ping_group_range, ICMP requests might fail");
+ if (!gethostname(hostname + sizeof(HOSTNAME_PREFIX) - 1,
+ HOST_NAME_MAX + 1 - sizeof(HOSTNAME_PREFIX)) ||
+ errno == ENAMETOOLONG) {
+ hostname[HOST_NAME_MAX] = '\0';
+ if (sethostname(hostname, strlen(hostname)))
+ warn("Unable to set pasta-prefixed hostname");
+ }
+
/* Wait for the parent to be ready: see main() */
sigemptyset(&set);
sigaddset(&set, SIGUSR1);