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 AA0E65A004C for ; Fri, 24 May 2024 19:39:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716572367; 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=KPiUSSs0+zSXPKE5UaRj4olUkt7tWXBTNEDax9LdglA=; b=GCAWtGyajJ7bTSKDNdN5C4iyt8s/OsTx+g6TKfDShyPmpW0g6x4VflRflY04kf/BovQgAK kMEcNaI/uSLSEEX5t8sW75KvIPeAe0bdoW/GAfyOMhckfWhp7ULWXnySQn7CO+F9Y/K+0p lvUhl+CC01zvvrwKhY24fAnfpGFX5mg= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-_eI9aoGCNpm0-Q7PefK2-A-1; Fri, 24 May 2024 13:39:26 -0400 X-MC-Unique: _eI9aoGCNpm0-Q7PefK2-A-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a626764169fso46211766b.2 for ; Fri, 24 May 2024 10:39:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716572364; x=1717177164; 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=KPiUSSs0+zSXPKE5UaRj4olUkt7tWXBTNEDax9LdglA=; b=bLAbIp6mziNZYX60i2EuP+ajV7drJ/1cTYlnxcYOzw25zki/vG4vHZmYPxRjPRW0Nu 07L66aRZOTT+aQ92ZbW38Bm1QGmkf/bf8l813f92jGsY4Hqlfqm9mosWi/iBwbbXlc53 3r3mOKr0yrvRqCTCFQOsJIYTlYKSJ8wfNTXElrPl4pJTu7Qxk225Di3gdC9/K1DU+pTZ iDJJtvym/SF8wrziO+hpcCar44HAyvC2PfBr0189slThBoRyNZ9/BrFqPWDVoL8PslIY XkFX2sGW1yW/Ez95lLUP7daPAEslOH4af5gWqo7easvKO9Y95EQqOU3f1Hwy64neF6Hv nluQ== X-Gm-Message-State: AOJu0Yw5EMra3cs5mQzg8ej2NWahiVN1+tDUj00GGqeO7RldoqS4wqoc 8h4iMCQYi2ZivYBATWiQiLU80q4b+i4MMvuapP5roAdNLb3esS+oehsokbyAKaoYTDnPM2HkAZQ E4BfBiz6muB2Sq1YwR6kk6OZ4pWApaOkfEaDiqpAfg3ZpQNK6kkkCQe2hcW8W X-Received: by 2002:a17:906:66c7:b0:a62:2eca:4f12 with SMTP id a640c23a62f3a-a6264f14815mr163653766b.59.1716572363485; Fri, 24 May 2024 10:39:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQLg4iRAqBjgL4/Did93rVbn1dYaxFrB8TVMf6pGXZhcwoihhlIvl0OZCznt3gv5rIWYrf6Q== X-Received: by 2002:a17:906:66c7:b0:a62:2eca:4f12 with SMTP id a640c23a62f3a-a6264f14815mr163652266b.59.1716572362758; Fri, 24 May 2024 10:39:22 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a626c9376dasm157907466b.54.2024.05.24.10.39.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2024 10:39:22 -0700 (PDT) Date: Fri, 24 May 2024 19:38:48 +0200 From: Stefano Brivio To: Danish Prakash Subject: Re: [PATCH] pasta.c: modify hostname when detaching new namespace Message-ID: <20240524193848.573fa67a@elisabeth> In-Reply-To: <314fcd0e-14cd-1f96-9d9f-e0380159b9dd@danishpraka.sh> References: <20240520083650.12032-1-contact@danishpraka.sh> <20240521193400.4f1b15c5@elisabeth> <20240523162347.44e6faf3@elisabeth> <314fcd0e-14cd-1f96-9d9f-e0380159b9dd@danishpraka.sh> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; 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: ZZV6SZ6AJVI6RBQKEG2G56Q7ANIPYO4N X-Message-ID-Hash: ZZV6SZ6AJVI6RBQKEG2G56Q7ANIPYO4N 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: On Fri, 24 May 2024 18:15:14 +0530 Danish Prakash wrote: > 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. Sure, I understand, I just suggested a particular version of the gethostname() call. I didn't comment on what's around it. > >> 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? Not really, I wasn't commenting on sethostname() at all, but in your snippet you quoted above, yes, and I think it's fine, because there might be other reasons why sethostname() fails. > 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. > -- Stefano