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 520225A026F for ; Wed, 13 Mar 2024 11:24:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710325441; 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=keAHJmm20WaroB4wX1XNY0Z+ilYe2lumlEU/NCpT/q8=; b=YIyUnzWejnae0jDbprG7IbCiA6YSxjFqErTCoOZxWb1sKOECvffTEwJ5VQIrpqP6BjoYhc EgIg3CVTNX4voUVShlKVQcUAAAdSet8z1tYkVT4xJWb+KEg9jW5x5Vr1UGCkTZTeNQtKw1 R2+uhpntdXKEQxCuErf5jQeP4niiCbk= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-362-X4tUix5kNR-_iwXMTpJKWw-1; Wed, 13 Mar 2024 06:23:59 -0400 X-MC-Unique: X4tUix5kNR-_iwXMTpJKWw-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-412e99244dbso22898095e9.2 for ; Wed, 13 Mar 2024 03:23:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710325439; x=1710930239; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=keAHJmm20WaroB4wX1XNY0Z+ilYe2lumlEU/NCpT/q8=; b=FYu0e+NI9PyMQxV27JXF1fDufIK6Sg0T9D8py/6BhSgKEDIk1FC3l7xlLLOZHPNSIm 0juOmOfK4tCfavC2aKDc+H96+/TdNZS5EkFZdHFRP8cLRhOHKBx4wiE8PY+Ae4qKODN0 rvwMLFOLedhTfJUtwfxjcgCTArzccGwp1GO4AHLQSSkMaChlibUxlpuROcSAmRRF/HuH jo1RK0vvL1ImnH2/6yNdfu+JhGAHqerrrLyzPWcPrpIUVQ74bSGfY6zljenGP/tfvZ5V jzez5/tXvExkRrW1IEu1q9otlp075OMkSf3dNHT9bxXpz5ygmdIb8GJGjRg0Z5g5+s6J Sm8g== X-Forwarded-Encrypted: i=1; AJvYcCWkuT98G93rsREQyCpFoNxYkw7suhsNf21KZkE23Nj5z9lCyiPJ/L6AUpqdBWTZvq/AgmWw52ZalnjnZxgg2tiTTrZy X-Gm-Message-State: AOJu0Ywj8aRifhJVZquIcTMP4JXtrj/64Ef/gwZS6ZfLzz1L7XZ+aXjz a4s8JKRrQuwwRQMs3IiWr/dpsn7fluoCPzf8ZlXf61s7LGm/JmiWcCkeWTurvFknhLiwEFa+fzj Cf+5hp35m+NcMTYY7oWmd1omJM56XsFSe1IHFFGmXHFQHGfcPCw== X-Received: by 2002:a05:600c:1e2a:b0:413:ec6b:8539 with SMTP id ay42-20020a05600c1e2a00b00413ec6b8539mr405062wmb.4.1710325438764; Wed, 13 Mar 2024 03:23:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9pPrZiOQJ/flLDBEXMFPRMZ3Sz3W37c1Li+hMZPDr5KzasWV0frNH4b/kukXg2oXEeJmncQ== X-Received: by 2002:a05:600c:1e2a:b0:413:ec6b:8539 with SMTP id ay42-20020a05600c1e2a00b00413ec6b8539mr405049wmb.4.1710325438395; Wed, 13 Mar 2024 03:23:58 -0700 (PDT) Received: from [192.168.188.25] ([80.243.52.135]) by smtp.gmail.com with ESMTPSA id o15-20020a05600c4fcf00b004132ae838absm1845033wmq.43.2024.03.13.03.23.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Mar 2024 03:23:58 -0700 (PDT) Message-ID: <4ea9d22c-fed4-410b-84f9-340f95c63c9b@redhat.com> Date: Wed, 13 Mar 2024 11:23:56 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] passt, log: Call __openlog() earlier, log to stderr until we detach To: Stefano Brivio , passt-dev@passt.top References: <20240312223448.649997-1-sbrivio@redhat.com> From: Paul Holzinger In-Reply-To: <20240312223448.649997-1-sbrivio@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: ZUP7ZYVNPXZHRBM4ILQEP7474CV4UQVC X-Message-ID-Hash: ZUP7ZYVNPXZHRBM4ILQEP7474CV4UQVC X-MailFrom: pholzing@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: 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: 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 > --- > 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. > + __openlog(log_name, 0, LOG_DAEMON); > + > if (!c.foreground) > __daemon(pidfile_fd, devnull_fd); > else