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.129.124]) by passt.top (Postfix) with ESMTP id 8035E5A005E for ; Tue, 14 Feb 2023 04:42:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676346119; 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=rTj07HVcuTK6xYF3eKBC6w6GG7WySNGXPB6TOCgEDfY=; b=TZufo9lvShCiNWFhNwFGy/88QKorV0S7x36toSI1xqU5QeeMtz8IkgP0rWptHmQ7FgDDML p+e6RMNILHGQlzprJJzSInQ9ZfrX84Y9cbx5kvMNmAXqMxg+s7vmu/4BZ3zL0N2CBXvAqV S7GkbqRaU41OeIPWDxr3m5PeIlL3+vQ= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-581-ooCtYzyWNNO7nP-1XDR6cA-1; Mon, 13 Feb 2023 22:41:58 -0500 X-MC-Unique: ooCtYzyWNNO7nP-1XDR6cA-1 Received: by mail-qk1-f200.google.com with SMTP id bp30-20020a05620a459e00b00738e1fe2470so8775817qkb.23 for ; Mon, 13 Feb 2023 19:41:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization: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=rTj07HVcuTK6xYF3eKBC6w6GG7WySNGXPB6TOCgEDfY=; b=Dbgk4aWOC2d6PjCmTuV2HrB1+aWi0Wgzdwu+nU+lqFKJX0yiGydaUx2EeRVXmWNkzb r1VO/+gzgWed+mfxN3HoGIe1VnVPcxXZvbU0ib2AT5CPbIWWYc02364sxL4jiFQa4Bmn 8sWFDA52oUDmTOfJqz+THMkwlppI2xw27i3rnqE15+CJbBI9Rf5pbzoyQ6giY54600Zs /DRXa4pYiNMzYh9PTPpd8mYADEBJTwmhZc/XFYMVQsHaK4fVaxlcdg/p/ywolGk78BvF WtsxV+DoRLkSjvQcDEWYdxw+GO0inRxGol4T+/xy4IXHya6vX1zOgGgQb6ToxIutfQDe WuGA== X-Gm-Message-State: AO0yUKUZbJguk4L1lHpFeq8z671m3dHVOAbjc4eB1HKetYkrYd0r47PV S9dVTyOBqYtwJiiTJ5HkD0dprR0JeL9jaYBXWqAIlSjIhBuLQf2yq/wy2+m9dFtXDFR4EbsqMVN CvUg0NMelLpXx/053kdc9pNOrqbnfn7a477CQeDC8wS2PZW+04JQO6cgjPAYHe3RNFw== X-Received: by 2002:a05:6214:1c48:b0:56e:a4a6:acd9 with SMTP id if8-20020a0562141c4800b0056ea4a6acd9mr2422571qvb.43.1676346117582; Mon, 13 Feb 2023 19:41:57 -0800 (PST) X-Google-Smtp-Source: AK7set/DYLUirZk71lZ4pXp4BVjaKxVpyGlZ0xk5efLq3VVLA+6fW7RWQceiteQ36GEV9zUkQwYUAw== X-Received: by 2002:a05:6214:1c48:b0:56e:a4a6:acd9 with SMTP id if8-20020a0562141c4800b0056ea4a6acd9mr2422548qvb.43.1676346117177; Mon, 13 Feb 2023 19:41:57 -0800 (PST) Received: from ?IPV6:2600:8805:3a00:3:3b4f:6d3c:92c4:a5c7? ([2600:8805:3a00:3:3b4f:6d3c:92c4:a5c7]) by smtp.gmail.com with ESMTPSA id r77-20020a374450000000b0073b425f6e33sm3468672qka.100.2023.02.13.19.41.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Feb 2023 19:41:56 -0800 (PST) Message-ID: Date: Mon, 13 Feb 2023 22:41:56 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH v2 1/9] log to stderr until process is daemonized, even if a logfile is set To: passt-dev@passt.top References: <20230208174838.1680517-1-laine@redhat.com> <20230208174838.1680517-2-laine@redhat.com> <20230209184528.2473f854@elisabeth> From: Laine Stump Organization: Red Hat In-Reply-To: <20230209184528.2473f854@elisabeth> 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: CIAQM22TWGJX5QJSY3IP33M6A627R2US X-Message-ID-Hash: CIAQM22TWGJX5QJSY3IP33M6A627R2US X-MailFrom: laine@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: Stefano Brivio 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 2/9/23 12:45 PM, Stefano Brivio wrote: > 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. Well, the fact that I didn't understand this was what was being done with the log mask kind of indicates this abuse will be misunderstood in the long run :-P But the abuse is already there, so it's not like I'm really making it any (much?) worse. It's just increasing the window when the logmask is set to LOG_EMERG, while modifying the log macro to not care if log_file is opened or not. I'll try that and see how it works out. > > 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. If I'm understanding you, that's kind of what I was doing, it's just that there are two modes - false == "logging before being daemonized" and true == "logging after being daemonized". > > By the way, the man page should be updated as well. > Good point.