~mser/pkg.mser.at

18ff5314e078260a6fbed34375c25c7ed73a9627 — cryzed 2 years ago 3556c33
Improve code
2 files changed, 7 insertions(+), 8 deletions(-)

M packages/unshare-net/PKGBUILD
M packages/unshare-net/unshare-net
M packages/unshare-net/PKGBUILD => packages/unshare-net/PKGBUILD +2 -2
@@ 1,6 1,6 @@
# Maintainer: Michael Serajnik <m at mser dot at>
pkgname=unshare-net
pkgver=6
pkgver=7
pkgrel=1
pkgdesc="Selectively whitelist traffic to specified IPs and domains for target applications"
arch=("any")


@@ 8,7 8,7 @@ url="https://git.sr.ht/~mser/pkg.mser.at/tree/master/item/packages/unshare-net"
license=("AGPL3")
depends=("python")
source=("unshare-net")
sha512sums=('67c5bcc864abde583f843a77ea977bad3bcdd16099021754536c2c8de361c7a799175a556c187bd6505617235d8484513bf859ac27e028cd3aff78bb85348e0d')
sha512sums=('73d04dcf086a35a0c583d30e6fd1022e4b904af00f62b2efee7467cb6fb5752e7789cd1bf9f08b2ddb8e1228e2976ab575a0abce4a41e7d38528c6e1213c65ce')

package() {
  install -D --mode 755 "${srcdir}/unshare-net" --target-directory "${pkgdir}/usr/bin"

M packages/unshare-net/unshare-net => packages/unshare-net/unshare-net +5 -6
@@ 184,18 184,17 @@ def run(arguments: argparse.Namespace, command: list[str]) -> ExitCode:
    process = subprocess.Popen(su_command)
    cgroup_add_process(identifier, process.pid, cgroup_mount_path)

    def handle_signal(signal_: signal.Signals, *args: T.Any) -> None:
        process.send_signal(signal_)

    # From `$ man su`:
    #   Upon receiving either SIGINT, SIGQUIT or SIGTERM, su terminates its child and afterwards terminates itself with
    #   the received signal. The child is terminated by SIGTERM, after unsuccessful attempt and 2 seconds of delay the
    #   child is killed by SIGKILL.
    # That means, we only have to forward received signals to the target process and wait for its termination.
    def forward_signal(signal_: signal.Signals, *args: T.Any) -> None:
        process.send_signal(signal_)

    signal.signal(signal.SIGINT, handle_signal)
    signal.signal(signal.SIGQUIT, handle_signal)
    signal.signal(signal.SIGTERM, handle_signal)
    signal.signal(signal.SIGINT, forward_signal)
    signal.signal(signal.SIGQUIT, forward_signal)
    signal.signal(signal.SIGTERM, forward_signal)

    process.wait()