From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from imap.gmail.com [173.194.76.109] by localhost with POP3 (fetchmail-6.3.26) for (single-drop); Mon, 20 May 2024 10:45:27 +0200 (CEST) Received: by 2002:a05:6a10:9148:b0:55f:c3c0:ed08 with SMTP id n8csp251291pxb; Mon, 20 May 2024 01:45:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUEQQwkBmk+hAa3g+4/a67t7ZanCU24yqoRdBsakxIrjxOBstITguLYk+bKSLxJM22Qq1ZgOy8zlX8MSnXMeVSDJ0Muc8lYzRI= X-Google-Smtp-Source: AGHT+IEiIV7Wn2RXsGMo6Wimp5XSFwek5ckxUJUG4uIOr4FNb3H8mLSEhbfU1AnghGUElERujArL X-Received: by 2002:ac8:5a84:0:b0:43d:dfb5:a6a3 with SMTP id d75a77b69052e-43dfde872femr404107381cf.66.1716194706230; Mon, 20 May 2024 01:45:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716194706; cv=none; d=google.com; s=arc-20160816; b=ABFMwVMc+tIs6wRoowFr5t1QTnMs6K95+khcJb7UQaxeiDcL5KXgzNZ0NXBozTDafp 0EZBYEISz7b5gifXdPd2F07BAN9kv3H/VZALCGnegOsiudc62XkFrZMZXA3D3A+4+QYA 3tbcX4LAPbxSoVoobNMR9CzSsREiaRJ86e2CuUHHXrw9hS9fjZZxXWyAp4G4XinIVSi/ 0r71q9512DAkL8k0DB5HhTNgID7mNxc2jx4vaNd7QB1714KutAKMBy7xcmJ2my4p1omv qXLpxAfBowDQs5h44JWYIbP9R8siBfbY8cWTBEakNemP+LAysJtmpIkTI8x3YP6N6xC0 IDaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:delivered-to; bh=L9Moagr4zpN45uGybhH4VkaXHwntOVi8TUL7zJlWJ1M=; fh=5ZaY5UwiUlMCUey2m01C3vEgWcctnsWRJuzzPaH9wcA=; b=F7Fh3oHo4NctwthXbs3lFnKWpt3G4sXNjxxnSw9RzDVe/IBBi6YOGhY5qSSC8N4A6T eaJPLiEMp1Hx2lbbhNC7RHVbaqPOOVZuTqLDWxs7aKRO3/wef6eProp4JFT3wUvNBSmk ghQRt4rx4UVuwTuJs9gOhcxUQMhjX3oowpdTwMFUIiBWY+euVn1evabjQ+OxrK5k9GCU ZDY1Zvp+tJhhmlSwsGPshXUmF4tJU7RS7IavnVZJKbBH4q5Kw8048vLYcqnays7cSlOX CScE1f8xHOLN3raFuucfnaJZAMXj1msNGapXoOMYtEMsfgBrRyv2Qmc9GK43Tm7wmgix 15ew==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of contact@danishpraka.sh designates 198.54.127.72 as permitted sender) smtp.mailfrom=contact@danishpraka.sh Return-Path: Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com. [205.139.110.120]) by mx.google.com with ESMTPS id d75a77b69052e-43df8f159a7si239562431cf.239.2024.05.20.01.45.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 01:45:06 -0700 (PDT) Received-SPF: pass (google.com: domain of contact@danishpraka.sh designates 198.54.127.72 as permitted sender) client-ip=198.54.127.72; Authentication-Results: mx.google.com; spf=pass (google.com: domain of contact@danishpraka.sh designates 198.54.127.72 as permitted sender) smtp.mailfrom=contact@danishpraka.sh Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-158-WVbaoI5JO4qDqMlzMb4N8A-1; Mon, 20 May 2024 04:45:04 -0400 X-MC-Unique: WVbaoI5JO4qDqMlzMb4N8A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DA3EC3806710 for ; Mon, 20 May 2024 08:45:03 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D680E1C09482; Mon, 20 May 2024 08:45:03 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast08.extmail.prod.ext.rdu2.redhat.com [10.11.55.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9DCE31C09480 for ; Mon, 20 May 2024 08:45:03 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F9DC3813BC4 for ; Mon, 20 May 2024 08:45:03 +0000 (UTC) Received: from out-06.pe-b.jellyfish.systems (out-06.pe-b.jellyfish.systems [198.54.127.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-248-UGwxmlEnMY2kk4wVwE6Wvw-1; Mon, 20 May 2024 04:45:01 -0400 X-MC-Unique: UGwxmlEnMY2kk4wVwE6Wvw-1 Received: from output-router-5c9bf9d745-hksrc (new-01.privateemail.com [198.54.118.220]) by pe-b.jellyfish.systems (Postfix) with ESMTPA id 4VjWC75JnwzFprF; Mon, 20 May 2024 08:37:07 +0000 (UTC) Received: from MTA-15.privateemail.com (unknown [10.50.14.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by NEW-01.privateemail.com (Postfix) with ESMTPS id A4E4618000D2; Mon, 20 May 2024 04:37:07 -0400 (EDT) Received: from mta-15.privateemail.com (localhost [127.0.0.1]) by mta-15.privateemail.com (Postfix) with ESMTP id 77308180018E; Mon, 20 May 2024 04:37:07 -0400 (EDT) Received: from localhost.localdomain (unknown [122.171.21.206]) by mta-15.privateemail.com (Postfix) with ESMTPA; Mon, 20 May 2024 04:37:03 -0400 (EDT) From: Danish Prakash To: sbrivio@redhat.com, passt-dev@passt.top Cc: Danish Prakash Subject: [PATCH] pasta.c: modify hostname when detaching new namespace Date: Mon, 20 May 2024 14:05:58 +0530 Message-ID: <20240520083650.12032-1-contact@danishpraka.sh> MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition;Similar Internal Domain=false;Similar Monitored External Domain=false;Custom External Domain=false;Mimecast External Domain=false;Newly Observed Domain=false;Internal User Name=false;Custom Display Name List=false;Reply-to Address Mismatch=false;Targeted Threat Dictionary=false;Mimecast Threat Dictionary=false;Custom Threat Dictionary=false X-Mimecast-Spam-Signature: yes X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: danishpraka.sh Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="US-ASCII"; x-default=true List-Id: 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 --- pasta.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pasta.c b/pasta.c index 31e1e00..840a2b1 100644 --- a/pasta.c +++ b/pasta.c @@ -180,6 +180,8 @@ static int pasta_spawn_cmd(void *arg) { =09const struct pasta_spawn_cmd_arg *a; =09sigset_t set; +=09char hostname[HOST_NAME_MAX+1], pasta_hostname[HOST_NAME_MAX+1]; +=09char *hostname_prefix =3D "pasta-"; =20 =09/* We run in a detached PID and mount namespace: mount /proc over */ =09if (mount("", "/proc", "proc", 0, NULL)) @@ -188,6 +190,17 @@ static int pasta_spawn_cmd(void *arg) =09if (write_file("/proc/sys/net/ipv4/ping_group_range", "0 0")) =09=09warn("Cannot set ping_group_range, ICMP requests might fail"); =20 +=09if (gethostname(hostname, HOST_NAME_MAX+1) =3D=3D 0) { +=09=09if ((strlen(hostname) + strlen(hostname_prefix)) > HOST_NAME_MAX) { +=09=09=09hostname[strlen(hostname)-strlen(hostname_prefix)] =3D '\0'; +=09=09} +=09=09sprintf(pasta_hostname, "%s%s", hostname_prefix, hostname); + +=09=09if (sethostname(pasta_hostname, strlen(pasta_hostname)) !=3D 0) { +=09=09=09warn("Unable to set pasta-prefixed hostname"); +=09=09} +=09} + =09/* Wait for the parent to be ready: see main() */ =09sigemptyset(&set); =09sigaddset(&set, SIGUSR1); --=20 2.45.1