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 7452D5A026F for ; Wed, 13 Mar 2024 11:41:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710326517; 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=JDH4cCVcN9797iFO27v2JAxQdlUgHFvaCN+eOrjYW/k=; b=FA71DpdhV03Ta8E6nQmplSDHlje+bORsrRwldBvw5TBz8q5xV1GwaPYSFMUQRJMbSoiI4n pL/qQHFdYqM4w0l/blYwz8GnRYBkw2LbDwR4aHteyPq+V7dMrITPi7ug9wDwtrpVhYG5GR alZ0kwbFXnVG5QwLSVojYIO8CQURRTs= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-440-U0bzYCcFNi-ZilMnEi04EA-1; Wed, 13 Mar 2024 06:41:55 -0400 X-MC-Unique: U0bzYCcFNi-ZilMnEi04EA-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2d45c84435eso15012941fa.0 for ; Wed, 13 Mar 2024 03:41:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710326514; x=1710931314; 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=JDH4cCVcN9797iFO27v2JAxQdlUgHFvaCN+eOrjYW/k=; b=VZ0f8WEwzw7oxVD362dY/by1JUQZKS5f+9dXCSbNpS1dkeO4lUs7xBERgHMysDRJZ9 jyxVTHbzTUCGmHIq4L5skauUPmX8nfp/khmuVmwYY1Q846Xz51saEZj4gZrQwYZazYzu BVxyt+nnjxGsBG4AsxNpljHWnE2tr7Bdki4ujUhxk95Yz3mVtsj14DnUghMuPPNmDSoJ uYMc1+Cio28O0XqIpIldAEL4D80LpwYxbmxQNC2GSEPbIqdkU0ssajAYSB5CoggKJDqg CmM2Cab2cal68gKvWrUoQxX54gHsMvHeVf3XZXz3Hpv6Kz8w1hN1Pb7roQ291x0kkPLR WRYg== X-Gm-Message-State: AOJu0YzArukHiAtvvcNiVHZQJn/nh+xKoOADDcjHVshsJf6vsHHMgH8n USaW5KxvhW2iaHdf4k2zEK8+bCLaOBLbDVIOZ9W/atS7zAD8nLxVIQrw1LmgfbIWaEtXK7KTOxu cvmdMMjbGyeqbLB69sPpWURuriVFH1LMD2IxGmMvHqZthTF0LTg== X-Received: by 2002:a2e:a692:0:b0:2d2:a3bc:b7d8 with SMTP id q18-20020a2ea692000000b002d2a3bcb7d8mr7233740lje.20.1710326514159; Wed, 13 Mar 2024 03:41:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSp49K+mHPmWS5LAvauWQOQ2bFw4ke1QHscESpTfo2UeGHPJWhd1aIJaP3AyTT5pauITVzTQ== X-Received: by 2002:a2e:a692:0:b0:2d2:a3bc:b7d8 with SMTP id q18-20020a2ea692000000b002d2a3bcb7d8mr7233725lje.20.1710326513474; Wed, 13 Mar 2024 03:41:53 -0700 (PDT) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id t21-20020a50d715000000b005682a0e915fsm5131899edi.76.2024.03.13.03.41.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2024 03:41:52 -0700 (PDT) Date: Wed, 13 Mar 2024 11:41:19 +0100 From: Stefano Brivio To: Paul Holzinger Subject: Re: [PATCH] passt, log: Call __openlog() earlier, log to stderr until we detach Message-ID: <20240313114119.7b2252da@elisabeth> In-Reply-To: <4ea9d22c-fed4-410b-84f9-340f95c63c9b@redhat.com> References: <20240312223448.649997-1-sbrivio@redhat.com> <4ea9d22c-fed4-410b-84f9-340f95c63c9b@redhat.com> 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: 5VX5QPHGXCH4RT4MDJKCDOYGSDJIEGAH X-Message-ID-Hash: 5VX5QPHGXCH4RT4MDJKCDOYGSDJIEGAH 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, David Gibson 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, 13 Mar 2024 11:23:56 +0100 Paul Holzinger wrote: > Thanks for the quick patch. > > On 12/03/2024 23:34, Stefano Brivio wrote: > > Paul reports that, with commit 15001b39ef1d ("conf: set the log level > > much earlier"), early messages aren't reported to standard error > > anymore. > > > > The reason is that, once the log mask is changed from LOG_EARLY, we > > don't force logging to stderr, and this mechanism was abused to have > > early errors on stderr. Now that we drop LOG_EARLY earlier on, this > > doesn't work anymore. > > > > Call __openlog() as soon as we know the mode we're running as, using > > LOG_PERROR. Then, once we detach, if we're not running from an > > interactive terminal and logging to standard error is not forced, > > drop LOG_PERROR from the options. > > > > While at it, make sure we don't print messages to standard error > > reporting that we couldn't log to the system logger, if we didn't > > open a connection yet. That's expected. > > > > Reported-by: Paul Holzinger > > Fixes: 15001b39ef1d ("conf: set the log level much earlier") > > Signed-off-by: Stefano Brivio > > Tested-by: Paul Holzinger And thanks for the quick test. > > --- > > log.c | 2 +- > > passt.c | 14 +++++++------- > > 2 files changed, 8 insertions(+), 8 deletions(-) > > > > diff --git a/log.c b/log.c > > index eafaca2..bdd31b4 100644 > > --- a/log.c > > +++ b/log.c > > @@ -174,7 +174,7 @@ void passt_vsyslog(int pri, const char *format, va_list ap) > > if (log_opt & LOG_PERROR) > > fprintf(stderr, "%s", buf + prefix_len); > > > > - if (send(log_sock, buf, n, 0) != n) > > + if (log_sock >= 0 && send(log_sock, buf, n, 0) != n) > > fprintf(stderr, "Failed to send %i bytes to syslog\n", n); > > } > > > > diff --git a/passt.c b/passt.c > > index f430648..e4cb11e 100644 > > --- a/passt.c > > +++ b/passt.c > > @@ -225,6 +225,8 @@ int main(int argc, char **argv) > > strncpy(argv0, argv[0], PATH_MAX - 1); > > name = basename(argv0); > > if (strstr(name, "pasta")) { > > + __openlog(log_name = "pasta", LOG_PERROR, LOG_DAEMON); > > + > > sa.sa_handler = pasta_child_handler; > > if (sigaction(SIGCHLD, &sa, NULL)) { > > die("Couldn't install signal handlers: %s", > > @@ -237,18 +239,16 @@ int main(int argc, char **argv) > > } > > > > c.mode = MODE_PASTA; > > - log_name = "pasta"; > > } else if (strstr(name, "passt")) { > > + __openlog(log_name = "passt", LOG_PERROR, LOG_DAEMON); > > + > > c.mode = MODE_PASST; > > - log_name = "passt"; > > } else { > > exit(EXIT_FAILURE); > > } > > > > madvise(pkt_buf, TAP_BUF_BYTES, MADV_HUGEPAGE); > > > > - __openlog(log_name, 0, LOG_DAEMON); > > - > > c.epollfd = epoll_create1(EPOLL_CLOEXEC); > > if (c.epollfd == -1) { > > perror("epoll_create1"); > > @@ -269,9 +269,6 @@ int main(int argc, char **argv) > > conf(&c, argc, argv); > > trace_init(c.trace); > > > > - if (c.force_stderr || isatty(fileno(stdout))) > > - __openlog(log_name, LOG_PERROR, LOG_DAEMON); > > - > > pasta_netns_quit_init(&c); > > > > tap_sock_init(&c); > > @@ -314,6 +311,9 @@ int main(int argc, char **argv) > > if (isolate_prefork(&c)) > > die("Failed to sandbox process, exiting"); > > > > + if (!c.force_stderr && !isatty(fileno(stdout))) > > I still have the feeling this should check the stderr fd instead of > stdout as it is logging to stderr. But I guess it shouldn't make a big > difference in real situations so not a big deal. Now that you mention this, I'm quite undecided: true, we're checking if we want to print to standard error, but what we want to check here is if we're running from an interactive terminal, for which testing if stdout is a terminal is quite idiomatic. On the other hand: $ cat isatty.c #include #include int main() { return isatty(fileno(stdout)); } $ gcc -o isatty isatty.c $ ./isatty >/dev/null; echo $? 0 $ ./isatty 2>/dev/null; echo $? 1 so we would (fail to) print to stderr if it's redirected to /dev/null, but not print to stderr if stdout is redirected. At this point I would have a slight preference toward changing it like you suggested. -- Stefano