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 A60265A0307 for ; Wed, 05 Jun 2024 00:41:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717540880; 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=84uWhr0iMxoLf5dIH1tPjPaW0TVBEkWZuVRNmUSbvPg=; b=URDlzAlhXioXYe+xelheh8VhSOoI52AkYTDU1oS48d/Vf0TgzRvfoYwkRbxM23FiLzC5xu Wvqh0hpXe3jvAY/UkIQTqrDkboYfoLMH1rolGbsGbqN/RUbeTvJOHGHLD5Or0wf5XPJ8zf uEMoimF/fl0aZYtR9/OoXQvCu0OLq5k= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-100-yGhx50djNPepYY9s7EpTkQ-1; Tue, 04 Jun 2024 18:41:19 -0400 X-MC-Unique: yGhx50djNPepYY9s7EpTkQ-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6ae4a6f537eso57508586d6.3 for ; Tue, 04 Jun 2024 15:41:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717540878; x=1718145678; 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=84uWhr0iMxoLf5dIH1tPjPaW0TVBEkWZuVRNmUSbvPg=; b=LB1Hm4G8hk3ifddJcBj/4MTCRaWg20K4Q0s7YJibDs3p4Of5uAbF2QNibq8p99sUqC Xe53P9WMYzGAgrfPkA1TWGijr5Q9UGQvtNETC61gENAARtalp6yYVKPthlxKuBKyRffh 6YQfOWmrAKEeqX8GFivwOvP9P6Sz9D5yCR/s3lGFGkxMUaRQjHvu1Ji6RNgq/6QKWiL1 kzruDP1UxNHZB8dqAZrJZ47DRSXY1iLnCDpClmOKnBsZI7nwUV1xPWHP1T9zB7/e6WrG pKqvVNXWy+/kqWTlMXwJ+jIglWFTvGeyG3iDUTWWzV23xavLKsmP+R+x2DFYfj7cQxLm V8GQ== X-Gm-Message-State: AOJu0Yy0aHxvmzHaz6xIa45uuyyVbMfVOqB5rOB8+I1iyMZpqEJEU4EQ Nn0DJB+2jAc28mljv4pK2DetHS6g93NcwkzFvccaEn2aeLmAto5tFNss3GqFg7c43kkCGcaz9dt 7uIxpYIatPJUES57PaWzeO4Fmfuj2fDe8o+KDXQRaGXJeHxjFAg== X-Received: by 2002:a05:6214:469f:b0:6ad:754a:e501 with SMTP id 6a1803df08f44-6b02bf28416mr8724906d6.23.1717540878060; Tue, 04 Jun 2024 15:41:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJcDhB0zhwtj6yd26kNgnQNGazLoeeIaMFpgY8Lcr9dn0dH8wwf4HLG/hTvssEKQ0eS9M1Rg== X-Received: by 2002:a05:6214:469f:b0:6ad:754a:e501 with SMTP id 6a1803df08f44-6b02bf28416mr8724616d6.23.1717540877566; Tue, 04 Jun 2024 15:41:17 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ae4b4065e9sm43248306d6.83.2024.06.04.15.41.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2024 15:41:16 -0700 (PDT) Date: Wed, 5 Jun 2024 00:40:41 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 2/3] conf: Don't print usage via the logging subsystem Message-ID: <20240605004041.5c408bc8@elisabeth> In-Reply-To: <20240529090405.965748-3-david@gibson.dropbear.id.au> References: <20240529090405.965748-1-david@gibson.dropbear.id.au> <20240529090405.965748-3-david@gibson.dropbear.id.au> 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: 5DT6P4N7HGMNAPG5RMNAWYEKBMTY2UI3 X-Message-ID-Hash: 5DT6P4N7HGMNAPG5RMNAWYEKBMTY2UI3 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, erik.sjolund@gmail.com 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 Wed, 29 May 2024 19:04:04 +1000 David Gibson wrote: > The message from usage() when given invalid options, or the -h / --help > option is currently printed by many calls to the info() function, also > used for runtime logging of informational messages. > > That isn't useful: the usage message should always go to the terminal > (stdout or stderr), never syslog or a logfile. It should never be > filtered by priority. Really the only thing using the common logging > functions does is give more opportunities for something to go wrong. > > Replace all the info() calls with direct fprintf() calls. This does mean > manually adding "\n" to each message. A little messy, but worth it for the > simplicity in other dimensions. Yes, definitely less messy than the existing implementation, I just wonder: > Link: https://bugs.passt.top/show_bug.cgi?id=90 > > Signed-off-by: David Gibson > --- > conf.c | 318 ++++++++++++++++++++++++++++----------------------------- > 1 file changed, 159 insertions(+), 159 deletions(-) > > diff --git a/conf.c b/conf.c > index f2a92574..31f5b197 100644 > --- a/conf.c > +++ b/conf.c > @@ -706,193 +706,194 @@ static unsigned int conf_ip6(unsigned int ifi, > /** > * usage() - Print usage, exit with given status code > * @name: Executable name > + * @f: Stream to print usage info to > * @status: Status code for exit() > */ > -static void usage(const char *name, int status) > +static void usage(const char *name, FILE *f, int status) > { > if (strstr(name, "pasta")) { > - info("Usage: %s [OPTION]... [COMMAND] [ARGS]...", name); > - info(" %s [OPTION]... PID", name); > - info(" %s [OPTION]... --netns [PATH|NAME]", name); > - info(""); > - info("Without PID or --netns, run the given command or a"); > - info("default shell in a new network and user namespace, and"); > - info("connect it via pasta."); > + fprintf(f, "Usage: %s [OPTION]... [COMMAND] [ARGS]...\n", name); > + fprintf(f, " %s [OPTION]... PID\n", name); > + fprintf(f, " %s [OPTION]... --netns [PATH|NAME]\n", name); > + fprintf(f, "\n"); > + fprintf(f, "Without PID or --netns, run the given command or a\n"); > + fprintf(f, "default shell in a new network and user namespace, and\n"); > + fprintf(f, "connect it via pasta.\n"); I haven't checked how it looks like in the end, but in most of this function, we use fprintf() without arguments after the format, and we need explicit newlines anyway, so, what if we concatenate the whole output, say: fprintf(f, "Without PID or --netns, run the given command or a\n" "default shell in a new network and user namespace, and\n" "connect it via pasta.\n" ); ? I used separate info() calls (or whatever they were) in the past just because of the convenient newlines. -- Stefano