commit: 95c1df28a7611a9fc7c24df4f1bb0984aa5775c2 Author: Sam James <sam <AT> gentoo <DOT> org> AuthorDate: Thu Nov 13 19:05:13 2025 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Thu Nov 13 19:05:13 2025 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=95c1df28
net-vpn/tor: fix startup w/ OpenRC + bridges Closes: https://bugs.gentoo.org/964340 Signed-off-by: Sam James <sam <AT> gentoo.org> .../tor/files/tor-0.4.8.20-openrc-startup.patch | 118 ++++++++++++ net-vpn/tor/tor-0.4.8.20-r1.ebuild | 202 +++++++++++++++++++++ 2 files changed, 320 insertions(+) diff --git a/net-vpn/tor/files/tor-0.4.8.20-openrc-startup.patch b/net-vpn/tor/files/tor-0.4.8.20-openrc-startup.patch new file mode 100644 index 000000000000..90172302f616 --- /dev/null +++ b/net-vpn/tor/files/tor-0.4.8.20-openrc-startup.patch @@ -0,0 +1,118 @@ +https://bugs.gentoo.org/964340 +https://gitlab.torproject.org/tpo/core/tor/-/issues/41164 +https://gitlab.torproject.org/tpo/core/tor/-/commit/ed28f2a1b3b1d40027a8b8d8b8a3a5d112ae3829 +https://gitlab.torproject.org/tpo/core/tor/-/commit/d2b5942e2820bd1d386e3c1e77a92363b05d28df + +From ed28f2a1b3b1d40027a8b8d8b8a3a5d112ae3829 Mon Sep 17 00:00:00 2001 +From: Jim Newsome <[email protected]> +Date: Mon, 2 Jun 2025 17:09:20 -0500 +Subject: [PATCH] Add tor_pipe_cloexec + +--- + src/lib/fdio/fdio.c | 28 ++++++++++++++++++++++++++++ + src/lib/fdio/fdio.h | 1 + + 2 files changed, 29 insertions(+) + +diff --git a/src/lib/fdio/fdio.c b/src/lib/fdio/fdio.c +index 7e27644067..f132e370d1 100644 +--- a/src/lib/fdio/fdio.c ++++ b/src/lib/fdio/fdio.c +@@ -14,6 +14,9 @@ + #ifdef HAVE_UNISTD_H + #include <unistd.h> + #endif ++#ifdef HAVE_FCNTL_H ++#include <fcntl.h> ++#endif + #ifdef _WIN32 + #include <windows.h> + #endif +@@ -118,3 +121,28 @@ write_all_to_fd_minimal(int fd, const char *buf, size_t count) + } + return 0; + } ++ ++#if defined(HAVE_PIPE2) && defined(O_CLOEXEC) ++int ++tor_pipe_cloexec(int pipefd[2]) ++{ ++ return pipe2(pipefd, O_CLOEXEC); ++} ++#elif defined(HAVE_PIPE) && defined(FD_CLOEXEC) ++int ++tor_pipe_cloexec(int pipefd[2]) ++{ ++ if (pipe(pipefd)) { ++ return -1; ++ } ++ if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC)) { ++ return -1; ++ } ++ if (fcntl(pipefd[1], F_SETFD, FD_CLOEXEC)) { ++ return -1; ++ } ++ return 0; ++} ++#else ++/* Intentionally leave symbol undefined. */ ++#endif +diff --git a/src/lib/fdio/fdio.h b/src/lib/fdio/fdio.h +index 7551dedb9e..4fd35fda43 100644 +--- a/src/lib/fdio/fdio.h ++++ b/src/lib/fdio/fdio.h +@@ -22,5 +22,6 @@ int tor_fd_setpos(int fd, off_t pos); + int tor_fd_seekend(int fd); + int tor_ftruncate(int fd); + int write_all_to_fd_minimal(int fd, const char *buf, size_t count); ++int tor_pipe_cloexec(int pipefd[2]); + + #endif /* !defined(TOR_FDIO_H) */ +-- +GitLab + +From d2b5942e2820bd1d386e3c1e77a92363b05d28df Mon Sep 17 00:00:00 2001 +From: Jim Newsome <[email protected]> +Date: Mon, 2 Jun 2025 17:10:45 -0500 +Subject: [PATCH] start_daemon: open pipe with cloexec + +Fixes #41013 +Fixes #41088 +--- + changes/bug41088 | 4 ++++ + src/lib/process/daemon.c | 3 ++- + 3 files changed, 7 insertions(+), 1 deletion(-) + create mode 100644 changes/bug41088 + +diff --git a/changes/bug41088 b/changes/bug41088 +new file mode 100644 +index 0000000000..7f9c178f97 +--- /dev/null ++++ b/changes/bug41088 +@@ -0,0 +1,4 @@ ++ o Minor bugfixes (bridges, pluggable transport): ++ - Fix a bug causing the initial tor process to hang intead of exiting with ++ RunAsDaemon, when pluggable transports are used. ++ Fixes bug 41088; bugfix on 0.4.9.1-alpha. +diff --git a/src/lib/process/daemon.c b/src/lib/process/daemon.c +index abd1d36576..1bfb162d85 100644 +--- a/src/lib/process/daemon.c ++++ b/src/lib/process/daemon.c +@@ -13,6 +13,7 @@ + + #ifndef _WIN32 + ++#include "lib/fdio/fdio.h" + #include "lib/fs/files.h" + #include "lib/log/log.h" + #include "lib/thread/threads.h" +@@ -63,7 +64,7 @@ start_daemon(void) + return 0; + start_daemon_called = 1; + +- if (pipe(daemon_filedes)) { ++ if (tor_pipe_cloexec(daemon_filedes)) { + /* LCOV_EXCL_START */ + log_err(LD_GENERAL,"pipe failed; exiting. Error was %s", strerror(errno)); + exit(1); // exit ok: during daemonize, pipe failed. +-- +GitLab diff --git a/net-vpn/tor/tor-0.4.8.20-r1.ebuild b/net-vpn/tor/tor-0.4.8.20-r1.ebuild new file mode 100644 index 000000000000..a49a1d241dcd --- /dev/null +++ b/net-vpn/tor/tor-0.4.8.20-r1.ebuild @@ -0,0 +1,202 @@ +# Copyright 1999-2025 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +PYTHON_COMPAT=( python3_{11..14} ) +VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/torproject.org.asc +inherit edo python-any-r1 readme.gentoo-r1 systemd verify-sig + +MY_PV="$(ver_rs 4 -)" +MY_PF="${PN}-${MY_PV}" +DESCRIPTION="Anonymizing overlay network for TCP" +HOMEPAGE="https://www.torproject.org/ https://gitlab.torproject.org/tpo/core/tor/" + +if [[ ${PV} == 9999 ]] ; then + EGIT_REPO_URI="https://gitlab.torproject.org/tpo/core/tor" + inherit autotools git-r3 +else + SRC_URI=" + https://www.torproject.org/dist/${MY_PF}.tar.gz + https://archive.torproject.org/tor-package-archive/${MY_PF}.tar.gz + verify-sig? ( + https://dist.torproject.org/${MY_PF}.tar.gz.sha256sum + https://dist.torproject.org/${MY_PF}.tar.gz.sha256sum.asc + ) + " + + S="${WORKDIR}/${MY_PF}" + + if [[ ${PV} != *_alpha* && ${PV} != *_beta* && ${PV} != *_rc* ]]; then + KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~mips ~ppc ~ppc64 ~riscv ~sparc ~x86 ~ppc-macos" + fi + + BDEPEND="verify-sig? ( >=sec-keys/openpgp-keys-tor-20250713 )" +fi + +# BSD in general, but for PoW, needs --enable-gpl (GPL-3 per --version) +# We also already had GPL-2 listed here for the init script, but obviously +# that's different from the actual binary. +LICENSE="BSD GPL-2 GPL-3" +SLOT="0" +IUSE="caps doc hardened lzma +man scrypt seccomp selinux +server systemd test zstd" +RESTRICT="!test? ( test )" + +RDEPEND=" + >=dev-libs/libevent-2.1.12-r1:=[ssl] + dev-libs/openssl:=[-bindist(-)] + virtual/zlib:= + caps? ( sys-libs/libcap ) + man? ( app-text/asciidoc ) + lzma? ( app-arch/xz-utils ) + scrypt? ( app-crypt/libscrypt ) + seccomp? ( >=sys-libs/libseccomp-2.4.1 ) + systemd? ( sys-apps/systemd:= ) + zstd? ( app-arch/zstd:= ) +" +DEPEND=" + ${RDEPEND} + test? ( + ${DEPEND} + ${PYTHON_DEPS} + ) +" +RDEPEND+=" + acct-user/tor + acct-group/tor + selinux? ( sec-policy/selinux-tor ) +" +BDEPEND+=" + acct-user/tor + acct-group/tor +" + +DOCS=() + +PATCHES=( + "${FILESDIR}"/${PN}-0.2.7.4-torrc.sample.patch + "${FILESDIR}"/${PN}-0.4.8.20-openrc-startup.patch +) + +QA_CONFIG_IMPL_DECL_SKIP=( + # test correctly fails because -lnacl fails if not available + # https://bugs.gentoo.org/900092 + crypto_scalarmult_curve25519 +) + +pkg_setup() { + use test && python-any-r1_pkg_setup +} + +src_unpack() { + if [[ ${PV} == 9999 ]] ; then + git-r3_src_unpack + else + if use verify-sig; then + cd "${DISTDIR}" || die + verify-sig_verify_detached ${MY_PF}.tar.gz.sha256sum{,.asc} + verify-sig_verify_unsigned_checksums \ + ${MY_PF}.tar.gz.sha256sum sha256 ${MY_PF}.tar.gz + cd "${WORKDIR}" || die + fi + + default + fi +} + +src_prepare() { + default + + # Running shellcheck automagically isn't useful for ebuild testing. + echo "exit 0" > scripts/maint/checkShellScripts.sh || die + + if [[ ${PV} == 9999 ]] ; then + eautoreconf + fi +} + +src_configure() { + use doc && DOCS+=( README.md ChangeLog ReleaseNotes doc/HACKING ) + + export ac_cv_lib_cap_cap_init=$(usex caps) + export tor_cv_PYTHON="${EPYTHON}" + # Already set by default in profiles for our toolchain + export tor_cv_cflags__fcf_protection_full=no + + local myeconfargs=( + --localstatedir="${EPREFIX}/var" + --disable-all-bugs-are-fatal + --enable-system-torrc + --disable-android + --disable-coverage + --disable-html-manual + --disable-libfuzzer + --enable-missing-doc-warnings + --disable-module-dirauth + --enable-pic + --disable-restart-debugging + + # Unless someone asks & has a compelling reason, just always + # build in GPL mode for pow, given we don't want yet another USE + # flag combination to have to test just for the sake of it. + # (PoW requires GPL.) + --enable-gpl + --enable-module-pow + + $(use_enable hardened gcc-hardening) + $(use_enable hardened linker-hardening) + $(use_enable man asciidoc) + $(use_enable man manpage) + $(use_enable lzma) + $(use_enable scrypt libscrypt) + $(use_enable seccomp) + $(use_enable server module-relay) + $(use_enable systemd) + $(use_enable test unittests) + $(use_enable zstd) + ) + + econf "${myeconfargs[@]}" +} + +src_test() { + local skip_tests=( + # Fails in sandbox + :sandbox/open_filename + :sandbox/openat_filename + ) + + if use arm ; then + skip_tests+=( + # bug #920905 + # https://gitlab.torproject.org/tpo/core/tor/-/issues/40912 + :sandbox/opendir_dirname + :sandbox/openat_filename + :sandbox/chmod_filename + :sandbox/chown_filename + :sandbox/rename_filename + ) + fi + + # The makefile runs these by parallel by chunking them with a script + # but that means we lose verbosity and can't skip individual tests easily + # either. + edo ./src/test/test --verbose "${skip_tests[@]}" +} + +src_install() { + default + readme.gentoo_create_doc + + newconfd "${FILESDIR}"/tor.confd tor + newinitd "${FILESDIR}"/tor.initd-r9 tor + systemd_dounit "${FILESDIR}"/tor.service + + keepdir /var/lib/tor + + fperms 750 /var/lib/tor + fowners tor:tor /var/lib/tor + + insinto /etc/tor/ + newins "${FILESDIR}"/torrc-r2 torrc +}
