From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from re-prd-fep-047.btinternet.com (mailomta1-re.btinternet.com [213.120.69.94]) by sourceware.org (Postfix) with ESMTPS id E0E5F385E02C for ; Fri, 8 Mar 2024 18:35:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E0E5F385E02C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dronecode.org.uk Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dronecode.org.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E0E5F385E02C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=213.120.69.94 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709922934; cv=none; b=tiMXrwaI7Nb1QKAv2no6LhLZatlT1Iu8pX27BZqZrx+j7D1/unjwVOWsmsr7xRxDL7cuHBS3i3JuOQDjxpoBK3I3N8KD8M+SvuFJolGWawURVAKgK6ClL/2eejt/nExHlMUoRTNTVOzgHhODz/SAphheNx/Q3sHcrULjHRhMl60= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709922934; c=relaxed/simple; bh=FQLIC8mI+tr49/MtsWlUnaKg5txfiV/bzRyZlz2EGGc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=YSXkThgSa6axrKKrBIqrD8yH81CxLfITyAI38Kv6qwBnKEQbeiW0HEPshVDWAWnSRlbYuprsZ2Eua0S3ootq84Fj6upuAeM8xWL8XoBpH99vUTuVuevyHaysocCZ6jaJFUvyPPoHOizp3+tpXu/LKHPS3ZpOb5XmjSaCCTpFJDI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from re-prd-rgout-004.btmx-prd.synchronoss.net ([10.2.54.7]) by re-prd-fep-047.btinternet.com with ESMTP id <20240308183530.GMA28253.re-prd-fep-047.btinternet.com@re-prd-rgout-004.btmx-prd.synchronoss.net>; Fri, 8 Mar 2024 18:35:30 +0000 Authentication-Results: btinternet.com; none X-SNCR-Rigid: 6577B87C0AB065AE X-Originating-IP: [81.153.98.185] X-OWM-Source-IP: 81.153.98.185 X-OWM-Env-Sender: jon.turney@dronecode.org.uk X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvledrieehgdduudegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhonhcuvfhurhhnvgihuceojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheqnecuggftrfgrthhtvghrnhepleeitdejhfdtveekheeugeffgeevfedtjeejveefhfeiffefkedtvdetheehieejnecukfhppeekuddrudehfedrleekrddukeehnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehhvghloheplhhotggrlhhhohhsthdrlhhotggrlhguohhmrghinhdpihhnvghtpeekuddrudehfedrleekrddukeehpdhmrghilhhfrhhomhepjhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukhdpnhgspghrtghpthhtohepvddprhgtphhtthhopegthihgfihinhdqrghpphhssegthihgfihinhdrtghomhdprhgtphhtthhopehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkpdhrvghvkffrpehhohhsthekuddqudehfedqleekqddukeehrdhrrghnghgvkeduqdduheefrdgsthgtvghnthhrrghlphhluhhsrdgtohhmpdgruhhthhgpuhhsvghrpehjohhnthhurhhnvgihsegsthhinhhtvghrnhgvthdrtghomhdpghgvohfk rfepifeupdfovfetjfhoshhtpehrvgdqphhrugdqrhhgohhuthdqtddtge X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean Received: from localhost.localdomain (81.153.98.185) by re-prd-rgout-004.btmx-prd.synchronoss.net (authenticated as jonturney@btinternet.com) id 6577B87C0AB065AE; Fri, 8 Mar 2024 18:35:30 +0000 From: Jon Turney To: cygwin-apps@cygwin.com Cc: Jon Turney Subject: [PATCH setup 05/16] Don't call Antivirus::AtExit() directly from Logger::exit() Date: Fri, 8 Mar 2024 18:34:24 +0000 Message-ID: <20240308183440.4263-6-jon.turney@dronecode.org.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240308183440.4263-1-jon.turney@dronecode.org.uk> References: <20240308183440.4263-1-jon.turney@dronecode.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The call to Antivirus::AtExit() needs to be take place before we write the log, so we see in the log if it failed. But calling it directly from Logger::exit() is a horrible layering violation, which makes it impossible to use the logger in other executables... Add LogFile::atexit() method, which registers atexit handlers which are run by LogFile::exit() before the log is closed. The real solution here is probably not to exit via Logger::exit() all over the place. And also perhaps to switch logfile writing from "defered" to "immediate" once the root directory has been selected (which establishes where the logfile should be written). Also update a comment, out of date since 5fa64c3c. --- AntiVirus.cc | 4 ++-- LogFile.cc | 18 +++++++++++++----- LogFile.h | 8 ++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/AntiVirus.cc b/AntiVirus.cc index cc416cc..cb8e8ee 100644 --- a/AntiVirus.cc +++ b/AntiVirus.cc @@ -16,8 +16,7 @@ #include "AntiVirus.h" #include "getopt++/BoolOption.h" - -#include "LogSingleton.h" +#include "LogFile.h" #include "win32.h" #include @@ -77,6 +76,7 @@ bool AntiVirusPage::Create () { detect(); + Logger().atexit(AntiVirus::AtExit); return PropertyPage::Create (NULL, dialog_cmd, IDD_VIRUS); } diff --git a/LogFile.cc b/LogFile.cc index ab2e3ec..0022eff 100644 --- a/LogFile.cc +++ b/LogFile.cc @@ -28,7 +28,6 @@ #include #include #include -#include "AntiVirus.h" #include "filemanip.h" #include "String++.h" #include "getopt++/BoolOption.h" @@ -115,12 +114,21 @@ LogFile::getFileName (int level) const return ""; } +void +LogFile::atexit(void (*func)(void)) +{ + exit_fns.push_back(func); +} + void LogFile::exit (int exit_code, bool show_end_install_msg) { - AntiVirus::AtExit(); + /* Execute any functions we want to run at exit (we don't use stdlib atexit() + because we want to allow them to potentially write to the log) */ + for (auto i = exit_fns.rbegin(); i != exit_fns.rend(); ++i) + (*i)(); + static int been_here = 0; - /* Exitcode -1 is special... */ if (been_here) ::exit (exit_code); been_here = 1; @@ -132,8 +140,8 @@ LogFile::exit (int exit_code, bool show_end_install_msg) Log (LOG_PLAIN) << "note: " << wstring_to_string(buf) << endLog; } - /* ... in that it skips the boring log messages. Exit code -1 is used when - just printing the help output and when we're self-elevating. */ + /* Skip the log messages when just printing the help/version output, and when + we're self-elevating. */ if (show_end_install_msg) Log (LOG_TIMESTAMP) << "Ending cygwin install" << endLog; diff --git a/LogFile.h b/LogFile.h index ddbc2dc..8efa1b0 100644 --- a/LogFile.h +++ b/LogFile.h @@ -18,6 +18,7 @@ #include "LogSingleton.h" #include +#include // Logging class. Default logging level is PLAIN. class LogFile : public LogSingleton { @@ -36,18 +37,21 @@ public: * but doesn't call generic C++ destructors */ virtual void exit (int exit_code, bool show_end_install_msg = true) - __attribute__ ((noreturn)); + __attribute__ ((noreturn)); + virtual void atexit( void (*func)(void)); + virtual void flushAll (); virtual ~LogFile(); // get a specific verbosity stream. virtual std::ostream &operator() (enum log_level level); - + protected: LogFile(std::stringbuf *aStream); LogFile (LogFile const &); // no copy constructor LogFile &operator = (LogFile const&); // no assignment operator virtual void endEntry(); // the current in-progress entry is complete. static int exit_msg; + std::vector exit_fns; private: void log_save (int babble, const std::string& filename, bool append); }; -- 2.43.0