public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: Laurent Vivier <lvivier@redhat.com>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH] log, passt: Keep printing to stderr when passt is running in foreground
Date: Tue,  6 Aug 2024 14:13:21 +0200	[thread overview]
Message-ID: <20240806121321.3144260-1-sbrivio@redhat.com> (raw)

There are two cases where we want to stop printing to stderr: if it's
closed, and if pasta spawned a shell (and --debug wasn't given).

But if passt is running in foreground, we currently stop to report any
message, even error messages, once we're ready, as reported by
Laurent, because we set the log_runtime flag, which we use to indicate
we're ready, regardless of whether we're running in foreground or not.

Turn that flag (back) to log_stderr, and set it only when we really
want to stop printing to stderr.

Reported-by: Laurent Vivier <lvivier@redhat.com>
Fixes: afd9cdc9bb48 ("log, passt: Always print to stderr before initialisation is complete")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 log.c   |  6 +++---
 log.h   |  2 +-
 passt.c | 12 +++++++-----
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/log.c b/log.c
index eb3a780..4ecc2ad 100644
--- a/log.c
+++ b/log.c
@@ -44,7 +44,7 @@ struct timespec	log_start;		/* Start timestamp */
 
 int		log_trace;		/* --trace mode enabled */
 bool		log_conf_parsed;	/* Logging options already parsed */
-bool		log_runtime;		/* Daemonised, or ready in foreground */
+bool		log_stderr = true;	/* Not daemonised, no shell spawned */
 
 /**
  * logtime_fmt_and_arg() - Build format and arguments to print relative log time
@@ -257,7 +257,7 @@ void vlogmsg(bool newline, int pri, const char *format, va_list ap)
 	}
 
 	if (debug_print || !log_conf_parsed ||
-	    (!log_runtime && (log_mask & LOG_MASK(LOG_PRI(pri))))) {
+	    (log_stderr && (log_mask & LOG_MASK(LOG_PRI(pri))))) {
 		(void)vfprintf(stderr, format, ap);
 		if (newline && format[strlen(format)] != '\n')
 			fprintf(stderr, "\n");
@@ -364,7 +364,7 @@ void passt_vsyslog(bool newline, int pri, const char *format, va_list ap)
 	if (newline && format[strlen(format)] != '\n')
 		n += snprintf(buf + n, BUFSIZ - n, "\n");
 
-	if (log_sock >= 0 && send(log_sock, buf, n, 0) != n && !log_runtime)
+	if (log_sock >= 0 && send(log_sock, buf, n, 0) != n && log_stderr)
 		fprintf(stderr, "Failed to send %i bytes to syslog\n", n);
 }
 
diff --git a/log.h b/log.h
index 5cb16d6..ba17f79 100644
--- a/log.h
+++ b/log.h
@@ -43,7 +43,7 @@ void logmsg_perror(int pri, const char *format, ...)
 
 extern int log_trace;
 extern bool log_conf_parsed;
-extern bool log_runtime;
+extern bool log_stderr;
 extern struct timespec log_start;
 
 void trace_init(int enable);
diff --git a/passt.c b/passt.c
index 6401730..ea5bece 100644
--- a/passt.c
+++ b/passt.c
@@ -290,15 +290,17 @@ int main(int argc, char **argv)
 	if (isolate_prefork(&c))
 		die("Failed to sandbox process, exiting");
 
-	if (!c.foreground)
+	if (!c.foreground) {
 		__daemon(c.pidfile_fd, devnull_fd);
-	else
+		log_stderr = false;
+	} else {
 		pidfile_write(c.pidfile_fd, getpid());
+	}
 
-	log_runtime = true;
-
-	if (pasta_child_pid)
+	if (pasta_child_pid) {
 		kill(pasta_child_pid, SIGUSR1);
+		log_stderr = false;
+	}
 
 	isolate_postfork(&c);
 
-- 
@@ -290,15 +290,17 @@ int main(int argc, char **argv)
 	if (isolate_prefork(&c))
 		die("Failed to sandbox process, exiting");
 
-	if (!c.foreground)
+	if (!c.foreground) {
 		__daemon(c.pidfile_fd, devnull_fd);
-	else
+		log_stderr = false;
+	} else {
 		pidfile_write(c.pidfile_fd, getpid());
+	}
 
-	log_runtime = true;
-
-	if (pasta_child_pid)
+	if (pasta_child_pid) {
 		kill(pasta_child_pid, SIGUSR1);
+		log_stderr = false;
+	}
 
 	isolate_postfork(&c);
 
-- 
2.43.0


                 reply	other threads:[~2024-08-06 12:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240806121321.3144260-1-sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=lvivier@redhat.com \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).