From unknown Sat Aug 09 22:37:12 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#63058 <63058@debbugs.gnu.org> To: bug#63058 <63058@debbugs.gnu.org> Subject: Status: 28.2; Emacs is terminated by Windows when logging off even if modified buffers are open Reply-To: bug#63058 <63058@debbugs.gnu.org> Date: Sun, 10 Aug 2025 05:37:12 +0000 retitle 63058 28.2; Emacs is terminated by Windows when logging off even if= modified buffers are open reassign 63058 emacs submitter 63058 Harald Sanftmann severity 63058 normal tag 63058 notabug thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Apr 24 16:26:07 2023 Received: (at submit) by debbugs.gnu.org; 24 Apr 2023 20:26:07 +0000 Received: from localhost ([127.0.0.1]:50426 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pr2lA-00007V-39 for submit@debbugs.gnu.org; Mon, 24 Apr 2023 16:26:07 -0400 Received: from lists.gnu.org ([209.51.188.17]:33670) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pqyRC-0006jA-9T for submit@debbugs.gnu.org; Mon, 24 Apr 2023 11:49:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pqyR7-00079J-FU for bug-gnu-emacs@gnu.org; Mon, 24 Apr 2023 11:49:06 -0400 Received: from mout.web.de ([212.227.17.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pqyR5-0004Bk-D4 for bug-gnu-emacs@gnu.org; Mon, 24 Apr 2023 11:49:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1682351340; i=haraldsa@web.de; bh=K+m6W6J9V0b4A63TMgsOvnXi1UPdkmBDN7xvNEW9LRc=; h=X-UI-Sender-Class:Date:To:From:Subject; b=mE+CBcpByVhHByCK4B2jJRS+E8Y3qi7cuDDn0imA1ePuTqq5xEf4Zt1B4RiVe4Z50 fnGcHILa6h9gu6ad78zh61tg+9ClyYveJIV1O3+pJ1ZBvlKxvDNfIkwSa5Fq0VwRT4 aOUAuwACxCeCTlkbt73gTL6ro3RqGgT4b+KvqHdhwQ8pm75fRv0WX8WmAqq9uT1hxr utZGKgLupEyQ851XQmXaHR9zdYuGjDL6abw2bSaB3YXAvFrVp/6PMEInOE+q4Zkyee 6iQs/BZNV0Bcl/eGoFiaqEuYKh/x0waB5gQZRh4WsYMNLMT9eHdLtJq99FbkdxNixD NwnzAfxIK9ULQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.0.146] ([95.91.251.77]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1N9LEU-1qKa4G0x4G-015DaI for ; Mon, 24 Apr 2023 17:49:00 +0200 Message-ID: Date: Mon, 24 Apr 2023 17:48:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Content-Language: de-DE To: bug-gnu-emacs@gnu.org From: Harald Sanftmann Subject: 28.2; Emacs is terminated by Windows when logging off even if modified buffers are open Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:+JZ2QDh+C3qf6v0YBUGQczRhlelcwQ/e0/CPn3l0IA+45hIHYH3 ELHV+ZP/z3yX3EVZnQlv5GfPCuxSVv8bespHVW4vhJf8TH8b/GubtleSXJye5bD8IW5etFO g9zBAjJCO9okLp3vR+Rc970vJu+ABSyPcnOAYqPCzVWM0NyfhCXNFYGVpHxB+Nk5KlQq5ZJ ZZWuD4huaFf4jbpz5bHHA== X-Spam-Flag: NO UI-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elope-from=haraldsa@web.de; helo=mout.web.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 24 Apr 2023 16:26:03 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) Hi everybody, From time to time it happens that I have not closed Emacs before logging out. Windows just terminates the process even if modified buffers are open. I searched for a solution and learned how Windows is telling applications to prepare for the user logging off / Windows is shutting down: https://www.howtogeek.com/396277/what-exactly-happens-when-you-shut-down-o= r-sign-out-of-windows/ WM_QUERYENDSESSION and WM_ENDSESSION are the sent signals, if the application does not respond it will be terminated after 5 seconds. Then I found some code which could be the Emacs implementation: https://github.com/emacs-mirror/emacs/blob/master/src/w32fns.c switch (msg) { case WM_ERASEBKGND: ... case WM_ENDSESSION: my_post_msg (&wmsg, hwnd, msg, wParam, lParam); /* Allow time for Emacs to attempt an orderly shutdown. If we return, the process will be terminated immediately. FIXME: 1000 seconds is too long to sleep if the shutdown attempt fails (see bug#25875). But if it fails, we want to find out about it, so let's leave 1000 for now. */ sleep (1000); FALLTHROUGH; Seems like Emacs does not respond but sleeps for 1000 s. This will probably not cut it. Would be great to have a proper handling. Thanks & Reards, Harald In GNU Emacs 28.2 (build 2, x86_64-w64-mingw32) of 2022-09-13 built on AVALON Windowing system distributor 'Microsoft Corp.', version 10.0.22621 System Description: Microsoft Windows 10 Pro (v10.0.2009.22621.1555) Configured using: 'configure --with-modules --without-dbus --with-native-compilation --without-compress-install CFLAGS=3D-O2' Configured features: ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND THREADS TIFF TOOLKIT_SCROLL_BARS XPM ZLIB (NATIVE_COMP present but libgccjit not available) Important settings: value of $LANG: DEU locale-coding-system: cp1252 Major mode: Org From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 25 02:20:49 2023 Received: (at 63058) by debbugs.gnu.org; 25 Apr 2023 06:20:49 +0000 Received: from localhost ([127.0.0.1]:51054 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prC2j-0000UL-AV for submit@debbugs.gnu.org; Tue, 25 Apr 2023 02:20:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56576) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prC2h-0000U7-86 for 63058@debbugs.gnu.org; Tue, 25 Apr 2023 02:20:47 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prC2b-0000fb-3Z; Tue, 25 Apr 2023 02:20:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=htfG8/NpzoSueK4TbOLrAwwKm+XH5r7noFDKtG330WM=; b=scQs1/F/UkdT 5YvmhaZ1GmW5J2AVZEW07ZL5BkNIjR2ErywuesUit9RdfGp1yQimCOHl0WQyBkJfu42HOk5a3gDah 30djUk1FcJuBC+jozt0vnGsYuq739FPDKYaiR8LEFIzoodCE85BUJNj6jSi2QY7kqfgcNZWhDh0uJ 5F6b9V3PDi84YjlKr7W1TvOipkUeTQPQLZhuNIfJGwfhLbFNFigb5sm93PgdWsEblbscFoCsoa/bv Tp7AzfrcN0LRHYm/IPS/TZIDCut9o9+OZjqkyDNzRYDxZAj9xU9hxc4vgUwt872Q+qAbvgJKpfeLj b5gcDlPoCyzVuty61X2AjQ==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prC2a-0002nY-Cy; Tue, 25 Apr 2023 02:20:40 -0400 Date: Tue, 25 Apr 2023 09:21:05 +0300 Message-Id: <83sfcowkha.fsf@gnu.org> From: Eli Zaretskii To: Harald Sanftmann In-Reply-To: (message from Harald Sanftmann on Mon, 24 Apr 2023 17:48:59 +0200) Subject: Re: bug#63058: 28.2; Emacs is terminated by Windows when logging off even if modified buffers are open References: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 63058 Cc: 63058@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Mon, 24 Apr 2023 17:48:59 +0200 > From: Harald Sanftmann > > From time to time it happens that I have not closed Emacs before > logging out. Windows just terminates the process even if modified > buffers are open. That's the expected behavior in that case. Emacs should auto-save when the OS tells Emacs it is shutting down, so you have auto-save files to restore the session later, when the system is restarted. > I searched for a solution and learned how Windows is telling > applications to prepare for the user logging off / Windows is shutting > down: > https://www.howtogeek.com/396277/what-exactly-happens-when-you-shut-down-or-sign-out-of-windows/ > > WM_QUERYENDSESSION and WM_ENDSESSION are the sent signals, if the > application does not respond it will be terminated after 5 seconds. > > Then I found some code which could be the Emacs implementation: > > > https://github.com/emacs-mirror/emacs/blob/master/src/w32fns.c > > switch (msg) > { > case WM_ERASEBKGND: > ... > case WM_ENDSESSION: > my_post_msg (&wmsg, hwnd, msg, wParam, lParam); > /* Allow time for Emacs to attempt an orderly shutdown. If we > return, the process will be terminated immediately. FIXME: > 1000 seconds is too long to sleep if the shutdown attempt > fails (see bug#25875). But if it fails, we want to find out > about it, so let's leave 1000 for now. */ > sleep (1000); > FALLTHROUGH; > > Seems like Emacs does not respond but sleeps for 1000 s. This will > probably not cut it. This is not what happens; you saw only the first part of how Emacs on Windows handles this situation, in the input thread. What actually happens is that before the input thread starts sleeping above, it posts the WM_ENDSESSION message, via the my_post_msg call, to the main thread, where we have this: case WM_ENDSESSION: inev.kind = END_SESSION_EVENT; break; So this event gets inserted into the Emacs input event queue, and when it is processed, we do: case END_SESSION_EVENT: /* Make an event (end-session). */ return list1 (Qend_session); The above produces a Lisp event 'end-session', for which we have a default binding: initial_define_lispy_key (Vspecial_event_map, "end-session", "kill-emacs"); IOW, this event by default calls the command kill-emacs. And that command auto-saves any modified buffers that visit files, then shuts down Emacs. > Would be great to have a proper handling. What is a proper handling in this case? delay the shutdown indefinitely? that'd be even less proper, IMO. See also bug#23483 (which led to the existing implementation) and specifically these messages there: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23483#37 https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23483#40 https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23483#43 https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23483#46 You could, if you like, bind the end-session event to a different command, perhaps that will suit your usage better. But be very careful when you do this, because invoking commands that require user interaction will not work in this case: the Emacs' input thread, which handles all kinds of inputs, is sleeping, so the user cannot interact with Emacs. From debbugs-submit-bounces@debbugs.gnu.org Fri May 05 01:58:43 2023 Received: (at 63058) by debbugs.gnu.org; 5 May 2023 05:58:43 +0000 Received: from localhost ([127.0.0.1]:52937 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1puoSo-0004HS-SV for submit@debbugs.gnu.org; Fri, 05 May 2023 01:58:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39940) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1puoSn-0004HB-Ke; Fri, 05 May 2023 01:58:41 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puoSi-0001gy-AM; Fri, 05 May 2023 01:58:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=KdTR7IYaTHgWgSZafVIOURYeSN+i/+lloyKyQPd0wVw=; b=mzJ5gC/b98xb zC5JaPWSleO/pMTJAZeArNmRWDvhtqLxFZ8q8qcZZ9hfdC+eRLQ4SwHX/F3ZZgjZbThSXgF8Y7aVz FuggBqRjZ0WMXcjk1RmCnlTP1Rwe8jJIkuBHngHaB8qqtVQl6Z96P9rwoDu7vnqtpGfFdVVYukWEg qznoi3e2aNBBVDfG2NywL4WsyiiWYAEVUMq76lIk7o/rEcaBsGG406vHYx52fki/M/68sifangOtn Lr/8IgxtdazSsJrHO2HFzu25qN1OVJNmAwVljlWy6R/3qkEBfZ8+ZXY2GyRq/Xau7MjBXSXEMHOlA iZRLRQtiol8xHjzduSqk/Q==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puoSS-0005F4-DW; Fri, 05 May 2023 01:58:24 -0400 Date: Fri, 05 May 2023 08:59:13 +0300 Message-Id: <83a5yjjp3i.fsf@gnu.org> From: Eli Zaretskii To: haraldsa@web.de In-Reply-To: <83sfcowkha.fsf@gnu.org> (message from Eli Zaretskii on Tue, 25 Apr 2023 09:21:05 +0300) Subject: Re: bug#63058: 28.2; Emacs is terminated by Windows when logging off even if modified buffers are open References: <83sfcowkha.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 63058 Cc: 63058@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) tags 63058 notabug close 63058 thanks > Cc: 63058@debbugs.gnu.org > Date: Tue, 25 Apr 2023 09:21:05 +0300 > From: Eli Zaretskii > > This is not what happens; you saw only the first part of how Emacs on > Windows handles this situation, in the input thread. What actually > happens is that before the input thread starts sleeping above, it > posts the WM_ENDSESSION message, via the my_post_msg call, to the main > thread, where we have this: > > case WM_ENDSESSION: > inev.kind = END_SESSION_EVENT; > break; > > So this event gets inserted into the Emacs input event queue, and when > it is processed, we do: > > case END_SESSION_EVENT: > /* Make an event (end-session). */ > return list1 (Qend_session); > > The above produces a Lisp event 'end-session', for which we have a > default binding: > > initial_define_lispy_key (Vspecial_event_map, "end-session", > "kill-emacs"); > > IOW, this event by default calls the command kill-emacs. And that > command auto-saves any modified buffers that visit files, then shuts > down Emacs. > > > Would be great to have a proper handling. > > What is a proper handling in this case? delay the shutdown > indefinitely? that'd be even less proper, IMO. > > See also bug#23483 (which led to the existing implementation) and > specifically these messages there: > > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23483#37 > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23483#40 > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23483#43 > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23483#46 > > You could, if you like, bind the end-session event to a different > command, perhaps that will suit your usage better. But be very > careful when you do this, because invoking commands that require user > interaction will not work in this case: the Emacs' input thread, which > handles all kinds of inputs, is sleeping, so the user cannot interact > with Emacs. No further comments, so I'm now closing this issue, as I see no bug here: Emacs is behaving as intended. From unknown Sat Aug 09 22:37:12 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 02 Jun 2023 11:24:07 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator