From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 018E35A004E for ; Wed, 26 Jun 2024 00:28:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719354511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6sZJsRoAZVnJQswxREhcOutg/RCSpilehPzhdKZV7bg=; b=StFicYQTVJ04j7yOX1EQhncLWI4+UazQauAMn6XxMgZQ4TEGq9fLUN60NxdcNjZiR4IEZf MUctcPwyuhZTuVht8WF6Y427zQjCginqYMtcL8yj2FvZXRmmpCh2QM4Qq0o9VDA0jWOWI5 Xp9aThbA4PiiPIGwqYXGh4NZmuPYYwU= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-Eecx1agRP7mg2vHnOG8slQ-1; Tue, 25 Jun 2024 18:28:30 -0400 X-MC-Unique: Eecx1agRP7mg2vHnOG8slQ-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6b077178ca4so103124986d6.0 for ; Tue, 25 Jun 2024 15:28:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719354509; x=1719959309; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=6sZJsRoAZVnJQswxREhcOutg/RCSpilehPzhdKZV7bg=; b=v4tgBhzYsLC2379mtK7elv+Fpp3LzJRRPg+dnxvUJ+Rk1w0p6CymoejZ8JdacwZHzi uZSSmTvrqIk7OW3NX5yJtI+ZzzDxvyQ2y5WjYWnpsQn/YgCx5jhrI8MGv6jHfIR0afYK 4Xq/1bjRP/QsDYepZLanx2RXonPyiaTDUm6TRlmSeqicnXQuGWGJiloNREaqWhNnRujV 5deVAMq+2MujbYpQCs2rozULR6r+81CEI8zuxyk0/CyhUdHBDMFVYoItaBj3I+MPuCpy /5P0XIDdkgK1b3QCg/9Gy4Czf0t916XulYEZjNDUgi0kJDNypfWsZKnHjGPb+DwKjjEC vXLA== X-Gm-Message-State: AOJu0YzUn5Po1RRg9ZV+kdI5LhprnftGXxEhLXMD1MX45LOhSCrPc2N9 +Mvpykw1DpZeIvIzfJjkDEE9IhRIzKlZ48kk1g8oWKqgKyN1oG4VS1cjHnO/X7laeIwPFxH0Asx r7VzwltqO7vNrsjyCXzqiqf9/50+eGhAkRcmtGwmdHloB7F+g4VnSXoiaiXPi X-Received: by 2002:ad4:4f47:0:b0:6b4:f888:ebb3 with SMTP id 6a1803df08f44-6b5409bc674mr71617416d6.14.1719354508587; Tue, 25 Jun 2024 15:28:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHs0496aD5cPMZ9dWLGIQdZeDIQINcZgGSYyUzhc1IbgAqKs3Ixk35YASvico6+v0K/QNUFw== X-Received: by 2002:ad4:4f47:0:b0:6b4:f888:ebb3 with SMTP id 6a1803df08f44-6b5409bc674mr71617326d6.14.1719354508127; Tue, 25 Jun 2024 15:28:28 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b520e75cd3sm46710036d6.146.2024.06.25.15.28.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Jun 2024 15:28:27 -0700 (PDT) Date: Wed, 26 Jun 2024 00:27:52 +0200 From: Stefano Brivio To: Danish Prakash Subject: Re: [PATCH] pasta.c: modify hostname when detaching new namespace Message-ID: <20240626002752.42cbd065@elisabeth> In-Reply-To: <20240524193918.151fd2fc@elisabeth> References: <20240520083650.12032-1-contact@danishpraka.sh> <20240524124903.2004-1-contact@danishpraka.sh> <20240524193918.151fd2fc@elisabeth> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 3XJP5IV3FNW32OPVXW2ZH2YAWWNJX54S X-Message-ID-Hash: 3XJP5IV3FNW32OPVXW2ZH2YAWWNJX54S X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Hi Danish, On Fri, 24 May 2024 19:39:18 +0200 Stefano Brivio wrote: > On Fri, 24 May 2024 18:18:53 +0530 > Danish Prakash wrote: > > > 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 | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/pasta.c b/pasta.c > > index 31e1e00..90afd74 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; > > > > @@ -178,6 +180,7 @@ struct pasta_spawn_cmd_arg { > > */ > > 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; > > > > @@ -188,6 +191,12 @@ 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)) || > > Following the Linux kernel coding style also means we try to stick into > 80 columns where possible: > > https://www.kernel.org/doc/html/latest/process/coding-style.html#breaking-long-lines-and-strings > > ...so there was a reason why I proposed this line like I did, with the > line splits. These subtleties, I can also fix them up on merge. > > > + errno == ENAMETOOLONG ) { > > Excess whitespace between ENAMETOOLONG and ). Same here, I would fix > this up on merge. > > > + if (sethostname(hostname, strlen(hostname))) > > So, I mentioned before that you don't really need to set a NULL > terminating byte for sethostname() itself, because it takes a length. > > But strlen() needs it. If gethostname() truncated the hostname, > according to POSIX, it's unspecified whether we'll have a NULL byte at > the end of 'hostname', and strlen() would read out-of-bounds, past the > end of 'hostname'. > > That's not an issue with glibc, but if POSIX says it's not guaranteed, > we shouldn't take anything for granted. > > I would suggest that you simply add a NULL byte at HOST_NAME_MAX, > unconditionally, that should cover the normal case as well as the > ENAMETOOLONG case. I haven't tested this by the way. > > > + warn("Unable to set pasta-prefixed hostname"); > > + } > > + > > /* Wait for the parent to be ready: see main() */ > > sigemptyset(&set); > > sigaddset(&set, SIGUSR1); > I didn't get any follow up on this patch. Did you actually mean to abandon it? If you prefer, I can also pick it up from there. -- Stefano