From nobody Thu Sep 28 15:52:45 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RxJ0F3pCVz4tyTQ; Thu, 28 Sep 2023 15:52:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RxJ0F23q0z4LVQ; Thu, 28 Sep 2023 15:52:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695916365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=s5nPGGzR1okCfIpeJvPGZzV3+QEmdhW9QFkeDwuWYIY=; b=Gjyg/djthN8pd2i2J6h4R9P++Dn7J1VQkh0HVWvpMtjIbY/ZWBHA9V/wPRV2sxGs2Pu4fV vCWdUnf7OvWEsN9nch/Ypkv9dVajNlfFaDgzZv0PhLORLs97TiVQytGZo0a+d0E3LpOD/M bRXZkyodnVIhcNnZqjPAXHD2DoRjwkWg1ilwtGEfGC3HZQDxjkaJL29mfq9mmlWt/mSwE5 6cHSHeLa3/6pMiyGtCLhUl8BC0xUUkruZ8WERVYDVLhiQfyMK4Xf0rm+TKMzCUA8AjKE90 2RmNp/vU5P1bS8i/QTh3PICnKuPboqCg+CCq+qdhAbOU+iaDyOLIgZBItZ30Qw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695916365; a=rsa-sha256; cv=none; b=kYZXxxXKji23+kTa8z2WHLLdP1W7io+n2qDnO0pdtPIv7yLR98BIhAIht2WmUSbOPNe/7l VU1jI1mOTMxZfj7d9Llv0D41+npdGjyr20zkWHAnoZJCnv/K7dLiT2MLVfPQPJkfI9P39g YMioiIfPB/A38Wd5c2W1s1L+HrWyp7jRx0wQVggyhMbpwzdJ/SL6I8DTiLpYDksGa9TgiI rxJIfkBKyoDeoLlwUG5YrnVa3D1eZPJ7UGd981dbZ+pDAPMzKhYhrxdm9ZRdC//ZPHqC+O zIjetzzM0iFoM4n25+jQk4EiUeUXKUUAQntGGBP6MmdOQELujdWml4WLh25M0A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695916365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=s5nPGGzR1okCfIpeJvPGZzV3+QEmdhW9QFkeDwuWYIY=; b=b5anzByTL/ETjHTzLUoihZV5AtfCvbgnKcR+N/ezjDd1cdQmjP89T94dpLIBHXslvr8EB6 9qRIhgInw2ycRsEeewe18cVaQvV4gGEWtNxNv/xW4+ONlvoSizlffJjrtqraOHJGNZW7v9 TXST/azzd79QBmTq18uw8aGNCFXsUu7SwFyoI37CEWzZnhHYxyF27LiFYX5HbsVdyrUr6f elEgxFNE8M4n4WnIycbREdxzvb3zvbdcwTaJwG93jISGC7IP3xynM9tHaYQ0GCvyA04RWi wGgPzXndrm3JKj6RdYgLEfhguoiaAZCp1UHdf7gRDznJ9DI6w36N+m/LsVynlQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RxJ0F19mNzCTm; Thu, 28 Sep 2023 15:52:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 38SFqjif022448; Thu, 28 Sep 2023 15:52:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38SFqjBL022445; Thu, 28 Sep 2023 15:52:45 GMT (envelope-from git) Date: Thu, 28 Sep 2023 15:52:45 GMT Message-Id: <202309281552.38SFqjBL022445@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: c3175a6e1c5a - main - syslogd: Do not open console descriptor List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c3175a6e1c5a4b6337368ea140e3a3837b327ef2 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c3175a6e1c5a4b6337368ea140e3a3837b327ef2 commit c3175a6e1c5a4b6337368ea140e3a3837b327ef2 Author: Jake Freeland AuthorDate: 2023-09-01 02:51:12 +0000 Commit: Mark Johnston CommitDate: 2023-09-28 15:51:54 +0000 syslogd: Do not open console descriptor Setup consfile filed for logging while Initialized is false, but do not bother opening the console. Close console/tty descriptors after parsing, as well. The ttymsg() function will re-open these descriptors for us. Also, remove references to the ctty global variable since it will always be _PATH_CONSOLE. Reviewed by: markj MFC after: 3 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41380 --- usr.sbin/syslogd/syslogd.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 5ccea8ce424b..9f4c21cab026 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -154,7 +154,6 @@ static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94"; static const char *ConfFile = _PATH_LOGCONF; static const char *PidFile = _PATH_LOGPID; -static const char ctty[] = _PATH_CONSOLE; static const char include_str[] = "include"; static const char include_ext[] = ".conf"; @@ -800,6 +799,12 @@ main(int argc, char *argv[]) if (Sflag == 0) addsock(_PATH_LOG_PRIV, NULL, S_IRUSR | S_IWUSR); + consfile.f_type = F_CONSOLE; + consfile.f_file = -1; + (void)strlcpy(consfile.fu_fname, _PATH_CONSOLE + sizeof(_PATH_DEV) - 1, + sizeof(consfile.fu_fname)); + (void)strlcpy(bootfile, getbootfile(), sizeof(bootfile)); + if ((!Foreground) && (!Debug)) { ppid = waitdaemon(30); if (ppid < 0) { @@ -810,11 +815,6 @@ main(int argc, char *argv[]) } else if (Debug) setlinebuf(stdout); - consfile.f_type = F_CONSOLE; - (void)strlcpy(consfile.fu_fname, ctty + sizeof(_PATH_DEV) - 1, - sizeof(consfile.fu_fname)); - (void)strlcpy(bootfile, getbootfile(), sizeof(bootfile)); - kq = kqueue(); if (kq == -1) { warn("failed to initialize kqueue"); @@ -1651,20 +1651,9 @@ logmsg(int pri, const struct logtime *timestamp, const char *hostname, /* log the message to the particular outputs */ if (!Initialized) { - f = &consfile; - /* - * Open in non-blocking mode to avoid hangs during open - * and close(waiting for the port to drain). - */ - f->f_file = open(ctty, O_WRONLY | O_NONBLOCK, 0); - - if (f->f_file >= 0) { - f->f_lasttime = *timestamp; - fprintlog_first(f, hostname, app_name, procid, msgid, - structured_data, msg, flags); - close(f->f_file); - f->f_file = -1; - } + consfile.f_lasttime = *timestamp; + fprintlog_first(&consfile, hostname, app_name, procid, + msgid, structured_data, msg, flags); return; } @@ -3049,12 +3038,15 @@ parse_action(const char *p, struct filed *f) if (syncfile) f->f_flags |= FFLAG_SYNC; if (isatty(f->f_file)) { - if (strcmp(p, ctty) == 0) + if (strcmp(p, _PATH_CONSOLE) == 0) f->f_type = F_CONSOLE; else f->f_type = F_TTY; (void)strlcpy(f->fu_fname, p + sizeof(_PATH_DEV) - 1, sizeof(f->fu_fname)); + /* This will be reopened by ttymsg(). */ + close(f->f_file); + f->f_file = -1; } else { (void)strlcpy(f->fu_fname, p, sizeof(f->fu_fname)); f->f_type = F_FILE;