From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-16.pe-b.jellyfish.systems (out-16.pe-b.jellyfish.systems [198.54.127.93]) by passt.top (Postfix) with ESMTPS id C1B8B5A004C for ; Fri, 24 May 2024 14:45:19 +0200 (CEST) Received: from output-router-5c9bf9d745-bgrqh (new-01.privateemail.com [198.54.118.220]) by pe-b.jellyfish.systems (Postfix) with ESMTPA id 4Vm4Wd70ZmzDqHM; Fri, 24 May 2024 12:45:17 +0000 (UTC) Received: from MTA-06.privateemail.com (unknown [10.50.14.16]) (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 E498418000CF; Fri, 24 May 2024 08:45:17 -0400 (EDT) Received: from mta-06.privateemail.com (localhost [127.0.0.1]) by mta-06.privateemail.com (Postfix) with ESMTP id B720D1800044; Fri, 24 May 2024 08:45:17 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=danishpraka.sh; s=default; t=1716554717; bh=qV5Q2Ey9THNpeVbe6NqrjZJc6hRAH/RjUYTJPa4RYho=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=X0nid2sDBc5cv0aB+nwrjGZgx0k0mF47RYnlWM1tULplu0DJC45ISzh0r0hnptDkU cnF7KbgXxJGEMuXVTsP9vBxa/YA82gigAJCuCJyXCH0MDPatlpD/A3ugX9xXxVnuSH wtfczY7jiS1+QVg8e1bWml0KQqsL40TzBEpCxETBdJIa8OJsLIt6ISBfDIB8tPkpje ZLnBXZDz/0FGyLyabRR3R/8vSsp50IIIzy14pePuEegP3XG+U1pE11gOibjZm8KJeE /Uj5p+XOxZvnWfZ77jiCiL0akKdpRtDa8bbKWiIg3a2mTk6R6X9AJAA0OshY1Yotdz DVJjDrZwu+UVQ== Received: from [192.168.1.28] (unknown [122.171.22.79]) by mta-06.privateemail.com (Postfix) with ESMTPA; Fri, 24 May 2024 08:45:15 -0400 (EDT) Message-ID: <314fcd0e-14cd-1f96-9d9f-e0380159b9dd@danishpraka.sh> Date: Fri, 24 May 2024 18:15:14 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH] pasta.c: modify hostname when detaching new namespace Content-Language: en-US To: Stefano Brivio References: <20240520083650.12032-1-contact@danishpraka.sh> <20240521193400.4f1b15c5@elisabeth> <20240523162347.44e6faf3@elisabeth> From: Danish Prakash In-Reply-To: <20240523162347.44e6faf3@elisabeth> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP Message-ID-Hash: NQKLQOMTK2UPT6E6AGKS5TNNG7A5UOGL X-Message-ID-Hash: NQKLQOMTK2UPT6E6AGKS5TNNG7A5UOGL X-MailFrom: contact@danishpraka.sh 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: On 5/23/24 19:53, Stefano Brivio wrote: > Danish, it would be easier if you answered inline. If Gmail is making > it hard, perhaps switch to an email client (I use claws-mail)? Anyway, > it's not a big issue for the moment: Yeah, something went wrong with that last one, sorry about that. I switched to a new email and didn't properly set it up. Hopefully it'll be better now. > On Thu, 23 May 2024 19:22:16 +0530 > Danish Prakash wrote: > >> Thanks for the review and the links. >> >>> + if (!gethostname(hostname + sizeof(HOSTNAME_PREFIX) - 1, HOST_NAME_MAX + 1 - sizeof(HOSTNAME_PREFIX))) { >>> + if (sethostname(hostname, strlen(hostname))) >>> + debug("Unable to set pasta-prefixed hostname"); >>> } >> >> The above snippet, although it looks correct, > > Wait, I didn't suggest if (!gethostname(...)), I suggested > gethostname(...). The ! there is yours. :) I misread your point earlier i guess. My intent here is to change the hostname (sethostname) if gethostname succeeds. >> doesn't work in cases where the hostname is long enough (~>58 chars). >> It works fine for shorter hostnames. > > In any case, it depends on how you define "doesn't work". What should > we do if the original hostname is long enough that we can't prefix > "pasta-" while fitting in 63 characters? > > Append it anyway and truncate the original hostname (what my line did), > or leave it like it is (what your snippet does, I guess)? It's a matter > of taste I'd say. I'm not sure I follow this part here, in your "line", are you getting and setting the hostname in two different conditionals? Because both would be doing the same thing ie. truncating the hostname but given how gethostname is implemented, the call would fail if len(hostname) > len passed to gethostname... > ...no, I don't think you're missing out on any edge case, you simply > missed that part of the man page. Note that we need to play nicely with > other C libraries too (especially musl), so error or not, we should do > the right/same thing. > > Perhaps most robust approach: > > if (!gethostname(hostname + sizeof(HOSTNAME_PREFIX) - 1, > HOST_NAME_MAX + 1 - sizeof(HOSTNAME_PREFIX)) || > errno == ENAMETOOLONG) { > > so that if it's glibc, and it truncates, we'll just go ahead with our > truncated name, but not if there's any other error. ...But this seems to do the job because gethostname returns the truncated hostname *along* with ENAMETOOLONG in the edge case where hostname is longer than the provided len, so as long as we're handling and are okay with that error, we get the desired result. I'll send along the updated patch shortly. -- danishpraka.sh