From nobody Thu Sep 28 15:52:43 2023 X-Original-To: dev-commits-src-all@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 4RxJ0D2yCTz4tyWp; Thu, 28 Sep 2023 15:52:44 +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 4RxJ0D1228z4LLg; Thu, 28 Sep 2023 15:52:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695916364; 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=U2p2MZepxBQtEecnqY9gGt836faRkL429Nas+a1aCiQ=; b=Qps3tFOUVq6qNfmaNAm+nJmfgGw5S8qvgsyG2GOEOf4aPoffipAI0u+F5lZ5wFtEJwgbQm 8BZBe+G/shT2iao8IDbnWoLmSwGhtyX+6InhPIe4J0yKU+BN+Y8kvtXP7OIEOL/ur1A6AL ksAEmoOm9SE1OAueQVPYh9c2wiivV0ErnK1aIyZGQfG4te3JxSm6GvT9NKOsPwlWCP9bqO mJfP542ZsOAbvG1SlLViJtQhTagSC7mdG6VmsiB+AEOvS8urWJqrHvO3+bQGdyTxlan22l 3qcvadZjDdBvDDifEnGGInWjDR6MHSPR40p0iGCkyN+hX/6LfdSUwc6aUBQ3/Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695916364; a=rsa-sha256; cv=none; b=OeklR43J+h2+jp5aPHa0gL0+ocLdXu0s+jnocz3ksWPS3GSXa0nLRgLeZnvfs2O7boegU+ vz9jIdp6iUjSO3PwVORI+Qr3XJwN8pP7Inv310VhuFN9u5Fb5HQL2VXC6INyRkR8yeiYf4 Hll1A37pW3O3RzL9rk2sBWFinfdvBCYb48ek/guRqo1CwenDwyBA7CjKxMK6RDZlsjJ3ry XQzsf5zy05hAHtiNgNa3c0oYVrfkBLx5yIpc0OmgG9tLfW2T7bnPGi3OB3kERgWQHAHx9H bvs4LrjZMHxZGv75poAeglt5SatS8Ao3t96fLbEzN+xi5QwUkhh092BHVKQWSw== 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=1695916364; 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=U2p2MZepxBQtEecnqY9gGt836faRkL429Nas+a1aCiQ=; b=LYflaOM5gbIKb8fS/pyPt4pVEteZkJLcSU1rHAo6giIPtgb6UbdM3re6/mf5sfzKvsPqZJ RplcZyJurvoRXgkpJ6jAdAboYd3ukgipEWDREUNZgTkzA6QVW128NuUCmy6C0SNODTlZVa RBVLTpBuK9ugM1Ugw3RuMQ2QJZK0jnekwejcEgUyVwEFlKSI6FiEYjCylLclTLcI8LOJSA 2CcXmDShDMfWzAyHJ3YiUzryq2y1yu3NzHdUg9WyQYG5JZ7MQ6scxEi3omSpHpuBH6hKNQ ozRCE55xGqlfKaChJ7HhuAjYXjVOf8rS8JPladWsz0gTxRF0ybtek5MGd/p51w== 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 4RxJ0D06gCzDJ8; Thu, 28 Sep 2023 15:52:44 +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 38SFqh7r022399; Thu, 28 Sep 2023 15:52:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38SFqhZF022396; Thu, 28 Sep 2023 15:52:43 GMT (envelope-from git) Date: Thu, 28 Sep 2023 15:52:43 GMT Message-Id: <202309281552.38SFqhZF022396@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: 5b44c24f8524 - main - syslogd: unlink() -> unlinkat() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 5b44c24f8524558b4e4c4c24dc465e9f4eed5ae9 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=5b44c24f8524558b4e4c4c24dc465e9f4eed5ae9 commit 5b44c24f8524558b4e4c4c24dc465e9f4eed5ae9 Author: Jake Freeland AuthorDate: 2023-09-01 02:51:06 +0000 Commit: Mark Johnston CommitDate: 2023-09-28 15:51:53 +0000 syslogd: unlink() -> unlinkat() Save basename and dirname for use in unlinkat() when removing UNIX sockets from fs. Reviewed by: markj, emaste MFC after: 3 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41379 --- usr.sbin/syslogd/syslogd.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index d317afa73844..5ccea8ce424b 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -130,6 +130,7 @@ static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94"; #include #include #include +#include #include #include #include @@ -198,7 +199,8 @@ struct socklist { #define sl_salen sl_ai.ai_addrlen #define sl_family sl_ai.ai_family int sl_socket; - const char *sl_name; + char *sl_name; + int sl_dirfd; int (*sl_recv)(struct socklist *); STAILQ_ENTRY(socklist) next; }; @@ -2341,8 +2343,12 @@ die(int signo) logerror(buf); } STAILQ_FOREACH(sl, &shead, next) { - if (sl->sl_sa != NULL && sl->sl_family == AF_LOCAL) - unlink(sl->sl_name); + if (sl->sl_sa != NULL && sl->sl_family == AF_LOCAL) { + if (unlinkat(sl->sl_dirfd, sl->sl_name, 0) == -1) { + dprintf("Failed to unlink %s: %s", sl->sl_name, + strerror(errno)); + } + } } pidfile_remove(pfh); @@ -3782,7 +3788,16 @@ socksetup(struct addrinfo *ai, const char *name, mode_t mode) if (sl == NULL) err(1, "malloc failed"); sl->sl_socket = s; - sl->sl_name = name; + if (ai->ai_family == AF_LOCAL) { + char *name2 = strdup(name); + if (name2 == NULL) + err(1, "strdup failed"); + sl->sl_name = strdup(basename(name2)); + sl->sl_dirfd = open(dirname(name2), O_DIRECTORY); + if (sl->sl_name == NULL || sl->sl_dirfd == -1) + err(1, "failed to save dir info for %s", name); + free(name2); + } sl->sl_recv = sl_recv; (void)memcpy(&sl->sl_ai, ai, sizeof(*ai)); if (ai->ai_addrlen > 0) {