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 E5EFE5A005E for ; Thu, 9 Feb 2023 18:45:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675964732; 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=z9rg/ohb1+InpC1N5n+F2olHMo6SDRWILku9iqq7nD4=; b=eduQ/v+z48SYV4uXb2r969X0p/YgguKxNLWldJ56B6CdvtwU9tUZp+0+vYMsxrzzXTOxa/ Mb4jKpyCCVQcjCIn5Qc3IMEwf7fhQbqUcppakNy/RNlVmCXRDAaS8WH/1m0dyNFTad7yML b+h2LC4BAXRtRqDxt1o0gobl3QPMZ38= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-646-8pWIyHcaMx6gO1SY0dUkHw-1; Thu, 09 Feb 2023 12:45:31 -0500 X-MC-Unique: 8pWIyHcaMx6gO1SY0dUkHw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E9AA85A588; Thu, 9 Feb 2023 17:45:31 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-4.brq.redhat.com [10.40.208.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 362B940398A0; Thu, 9 Feb 2023 17:45:31 +0000 (UTC) Date: Thu, 9 Feb 2023 18:45:28 +0100 From: Stefano Brivio To: Laine Stump Subject: Re: [PATCH v2 1/9] log to stderr until process is daemonized, even if a logfile is set Message-ID: <20230209184528.2473f854@elisabeth> In-Reply-To: <20230208174838.1680517-2-laine@redhat.com> References: <20230208174838.1680517-1-laine@redhat.com> <20230208174838.1680517-2-laine@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: YJYBVLIN6MRAJOO7NXJGVUA7KT3YH5EB X-Message-ID-Hash: YJYBVLIN6MRAJOO7NXJGVUA7KT3YH5EB 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, laine@laine.org X-Mailman-Version: 3.3.3 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, 8 Feb 2023 12:48:30 -0500 Laine Stump wrote: > Signed-off-by: Laine Stump > --- > log.c | 14 +++++++++++++- > log.h | 1 + > passt.c | 6 ++++-- > 3 files changed, 18 insertions(+), 3 deletions(-) > > diff --git a/log.c b/log.c > index 468c730..0ab0adf 100644 > --- a/log.c > +++ b/log.c > @@ -34,6 +34,7 @@ static int log_sock = -1; /* Optional socket to system logger */ > static char log_ident[BUFSIZ]; /* Identifier string for openlog() */ > static int log_mask; /* Current log priority mask */ > static int log_opt; /* Options for openlog() */ > +static int log_daemon_mode = false; /* true once process is daemonized */ > > static int log_file = -1; /* Optional log file descriptor */ > static size_t log_size; /* Maximum log file size in bytes */ > @@ -67,7 +68,8 @@ void name(const char *format, ...) { \ > } \ > \ > if ((setlogmask(0) & LOG_MASK(LOG_DEBUG) || \ > - setlogmask(0) == LOG_MASK(LOG_EMERG)) && log_file == -1) { \ > + setlogmask(0) == LOG_MASK(LOG_EMERG)) \ > + && (log_file == -1 || !log_daemon_mode)) { \ This is getting a bit complicated. At the moment, LOG_EMERG is abused with the meaning "we don't know where/what to log yet", because we didn't process logging options yet. Would it be an option to extend this abuse a bit further, and use LOG_EMERG to indicate that passt didn't daemonise yet, instead? You would just need to move the __setlogmask() calls in main(), and change the comment about the first one. I haven't tested this, and we should be a bit careful with this (check what happens with and without running passt from an interactive terminal, with and without a log file, etc.). A possibly cleaner approach could be to decouple this from the log mask, and have an enum instead, to represent logging "states" or "modes" -- but I'm not sure we're really going to save much complexity with it. By the way, the man page should be updated as well. -- Stefano