~mser/pkg.mser.at

669ef65a94d593b16aa00885a553cd9664a54710 — cryzed 2 years ago 3a46287
unshare-net: Smarter logging
2 files changed, 8 insertions(+), 6 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=12
pkgver=13
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' 'python-appdirs')
source=('unshare-net')
sha512sums=('69b1af86905ada0a17f3a9fd0ab03d7fa75f9415b56ecaa3a144f2741b0533216d7bd08c8b9428e94f59eff3d718186f212f7c4a8702eb33d90a6e8715fddb17')
sha512sums=('ee17c6ba318c2264e1616c7b232cf40fb931af27e8b63aa142b237d0045009f163b461de9368ae8a918f07bcababf3c4da3ddb75cab070844700ff070fc1765a')

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

M packages/unshare-net/unshare-net => packages/unshare-net/unshare-net +6 -4
@@ 145,12 145,12 @@ def get_argument_parser() -> argparse.ArgumentParser:
def get_log_path() -> pathlib.Path:
    path = pathlib.Path(appdirs.user_log_dir(APPLICATION_NAME))
    path.mkdir(parents=True, exist_ok=True)
    return path / (APPLICATION_NAME + ".log")
    return path / f"{APPLICATION_NAME}.log"


def rotate_log(source: str, destination: str) -> None:
    source_path = pathlib.Path(source)
    with source_path.open("rb") as source_file, gzip.open(destination + ".gz", "wb") as destination_file:
    with source_path.open("rb") as source_file, gzip.open(f"{destination}.gz", "wb") as destination_file:
        destination_file.writelines(source_file)

    source_path.unlink()


@@ 171,7 171,7 @@ def run(arguments: argparse.Namespace, command: list[str]) -> ExitCode:
    if cgroup_mount_paths:
        cgroup_mount_path = cgroup_mount_paths[0]
    else:
        cgroup_mount_path = pathlib.Path(tempfile.mkdtemp(prefix=APPLICATION_NAME + "-"))
        cgroup_mount_path = pathlib.Path(tempfile.mkdtemp(prefix=f"{APPLICATION_NAME}-"))
        logger.debug("created %r", str(cgroup_mount_path))
        # These are the mount options used by Arch Linux (systemd), so I assume they are fine
        mount("--types", "cgroup2", identifier, str(cgroup_mount_path), "--options", "defaults,nosuid,nodev,noexec")


@@ 269,7 269,9 @@ def main() -> None:

    logging.basicConfig(format=LOGGING_FORMAT)
    logger.setLevel(arguments.logging_level)
    handler = logging.handlers.TimedRotatingFileHandler(get_log_path(), when="midnight")
    handler = logging.handlers.TimedRotatingFileHandler(
        get_log_path(), when="midnight", interval=30, backupCount=12, delay=True
    )
    handler.rotator = rotate_log
    handler.setFormatter(logging.Formatter(LOGGING_FORMAT))
    logger.addHandler(handler)