From 8997ca78b192e0da8bacfbd9b2d109be79106e07 Mon Sep 17 00:00:00 2001 From: Sasha Romijn Date: Tue, 14 Jan 2025 15:24:44 +0100 Subject: [PATCH] Fix incorrect error when logfile exists and is writeable in non-writeable dir Ref #937, ref #941, ref #666 --- irrd/daemon/main.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/irrd/daemon/main.py b/irrd/daemon/main.py index a4a07613..9e436c4e 100755 --- a/irrd/daemon/main.py +++ b/irrd/daemon/main.py @@ -99,12 +99,15 @@ def main(): os.setegid(gid) os.seteuid(uid) if staged_logfile_path: - staged_logfile_dir = Path(staged_logfile_path).parent - if not os.access(staged_logfile_dir, os.W_OK, effective_ids=True): - logging.critical( - f"Unable to start: logfile {staged_logfile_path} not writable by UID {uid} / GID {gid}" - ) - return + # First check if a writable file already exists, if not, + # if we have permission to create the file. + if not os.access(staged_logfile_path, os.W_OK, effective_ids=True): + staged_logfile_dir = Path(staged_logfile_path).parent + if not os.access(staged_logfile_dir, os.W_OK, effective_ids=True): + logging.critical( + f"Unable to start: logfile {staged_logfile_path} not writable by UID {uid} / GID {gid}" + ) + return with daemon.DaemonContext(**daemon_kwargs): config_init(args.config_file_path)