From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Pierre Neidhardt Newsgroups: gmane.emacs.bugs Subject: bug#30421: 25.3; desktop.el: Steal lock when no living "emacs" process owns it Date: Sun, 18 Feb 2018 12:26:06 +0100 Message-ID: <87r2pilesx.fsf@gmail.com> References: <871shram2i.fsf@gmail.com> <83mv0f1q6t.fsf@gnu.org> <87r2prpl05.fsf@gmail.com> <87zi4fa4ft.fsf@users.sourceforge.net> <838tbz1o8k.fsf@gnu.org> <87mv0f5urq.fsf@gmail.com> <837erj1m46.fsf@gnu.org> <87k1vj5tju.fsf@gmail.com> <834lmn1k5h.fsf@gnu.org> <876073e5d9.fsf@gmail.com> <83wozjz79c.fsf@gnu.org> <87bmgv2vvk.fsf@gmail.com> <87o9kpn9pq.fsf@gmail.com> <83po55e4md.fsf@gnu.org> <87r2pkilsj.fsf@gmail.com> <83fu60cb82.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1519123052 21196 195.159.176.226 (20 Feb 2018 10:37:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 20 Feb 2018 10:37:32 +0000 (UTC) User-Agent: mu4e 1.0; emacs 26.0.91 Cc: 30421@debbugs.gnu.org, npostavs@users.sourceforge.net To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Feb 18 12:25:41 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1enN5r-00051K-9E for geb-bug-gnu-emacs@m.gmane.org; Sun, 18 Feb 2018 12:25:19 +0100 Original-Received: from localhost ([::1]:44706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1enN7q-0006C0-Dh for geb-bug-gnu-emacs@m.gmane.org; Sun, 18 Feb 2018 06:27:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50445) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1enN7Z-00066p-Gr for bug-gnu-emacs@gnu.org; Sun, 18 Feb 2018 06:27:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1enN7W-0006OO-DT for bug-gnu-emacs@gnu.org; Sun, 18 Feb 2018 06:27:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41059) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1enN7W-0006OG-9x for bug-gnu-emacs@gnu.org; Sun, 18 Feb 2018 06:27:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1enN7V-0005j1-U4 for bug-gnu-emacs@gnu.org; Sun, 18 Feb 2018 06:27:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Pierre Neidhardt Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 18 Feb 2018 11:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30421 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 30421-submit@debbugs.gnu.org id=B30421.151895318021948 (code B ref 30421); Sun, 18 Feb 2018 11:27:01 +0000 Original-Received: (at 30421) by debbugs.gnu.org; 18 Feb 2018 11:26:20 +0000 Original-Received: from localhost ([127.0.0.1]:48955 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1enN6p-0005hv-EH for submit@debbugs.gnu.org; Sun, 18 Feb 2018 06:26:19 -0500 Original-Received: from mail-wr0-f173.google.com ([209.85.128.173]:39614) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1enN6l-0005hg-Kk for 30421@debbugs.gnu.org; Sun, 18 Feb 2018 06:26:16 -0500 Original-Received: by mail-wr0-f173.google.com with SMTP id w77so6899456wrc.6 for <30421@debbugs.gnu.org>; Sun, 18 Feb 2018 03:26:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=jY9j8P3jTNRTHrdkcYpirDZM0eNYB1i57xzQIfCOLFM=; b=F0xWS3qhT3MXemj0Dn+wgJoNYSuUinSHM3mqN+y6MXQLaxw1mG8+fTzZOpQZ6Y9OvF ZzWdlHtoDLbD1XrtYISsG122JOXArIKCYYUtuHVoNfegeAUMXatJZURaammRypFUQMHL BM+qe//Yd4IAR8lXy3Q18yits7AiYubRMUgP3BmYB3uFbSnBzOLLa3MApmsVrMMi4OPD vZWGcXhKiGhQSdf0jblL48ufnJLp0i3BlNyQYJ2QYWaVai4hytmbBr4Hg9hjbZ4w+Fbn dLbBGbwnhSyUwirD8mej0D6uJkR5bQjfK7pyIKoU0Jv9AEOlTTuZfxX7+qzv2RIBsrAQ hbaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=jY9j8P3jTNRTHrdkcYpirDZM0eNYB1i57xzQIfCOLFM=; b=Z2NODR7IOn8gZd60nNVvH6sFC46skNacxIBjCqzMT6rN/XbhhK39DWAvzKw4d7f75P RP5uMy+oESrCs9lcTxWZfgxLoKN28OjkUZ7+j02Q7RwhAUlG80N8wPGun4dOOgTibSrQ rGswayF1JlF4eGcuwIOa/I2+fMUxZOc7tKrYge8Hn7xJg58OPgdYRDqJ0ltKKq8Zn+D9 QNZbMoTwQVrSNdLI3VcrRo6QEvqQO71ByNwqRcdUoAviNnz9D1XxYR1LykRWBa4mASm6 jjecNsbshXtFXhciDk/aRSkK6ZaD2u9NxoLcsRQ8gtGrrx8yX9TM2xb0+SR0dTuAv3LE Pv3w== X-Gm-Message-State: APf1xPD3muDb/bgIyCD9R6ddp4xGYYMffTwjTMH3NZfS5nKaySkBH+a4 9T1BGB20tgPhZ/Vx9+kvht/xZg== X-Google-Smtp-Source: AH8x227FF/rR2u9/Jfo3YHxLlVBG9sODDC0OvHVHc5IzkvVD3BEtD0dipKmJTL/mHrdyNw9Y8nNkLg== X-Received: by 10.223.199.207 with SMTP id y15mr11055074wrg.158.1518953169657; Sun, 18 Feb 2018 03:26:09 -0800 (PST) Original-Received: from mimimi (18.160.3.93.rev.sfr.net. [93.3.160.18]) by smtp.gmail.com with ESMTPSA id p1sm20396445wra.90.2018.02.18.03.26.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 18 Feb 2018 03:26:08 -0800 (PST) In-reply-to: <83fu60cb82.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:143484 --=-=-= Content-Type: text/plain Did not work. Recipe: - init.el: (require 'desktop) (defun desktop-read (&optional dirname) "Read and process the desktop file in directory DIRNAME. Look for a desktop file in DIRNAME, or if DIRNAME is omitted, look in directories listed in `desktop-path'. If a desktop file is found, it is processed and `desktop-after-read-hook' is run. If no desktop file is found, clear the desktop and run `desktop-no-desktop-file-hook'. This function is a no-op when Emacs is running in batch mode. It returns t if a desktop file was loaded, nil otherwise." (interactive) (unless noninteractive (setq desktop-dirname (file-name-as-directory (expand-file-name (or ;; If DIRNAME is specified, use it. (and (< 0 (length dirname)) dirname) ;; Otherwise search desktop file in desktop-path. (let ((dirs desktop-path)) (while (and dirs (not (file-exists-p (desktop-full-file-name (car dirs))))) (setq dirs (cdr dirs))) (and dirs (car dirs))) ;; If not found and `desktop-path' is non-nil, use its first element. (and desktop-path (car desktop-path)) ;; Default: .emacs.d. user-emacs-directory)))) (if (file-exists-p (desktop-full-file-name)) ;; Desktop file found, but is it already in use? (let ((desktop-first-buffer nil) (desktop-buffer-ok-count 0) (desktop-buffer-fail-count 0) (owner (desktop-owner)) ;; Avoid desktop saving during evaluation of desktop buffer. (desktop-save nil) (desktop-autosave-was-enabled)) (if (and owner (memq desktop-load-locked-desktop '(nil ask)) (or (null desktop-load-locked-desktop) ;; Without a visible frame, Emacs daemon cannot ;; prompt the user so we don't load. (and (daemonp) (= (length (visible-frame-list)) 1)) (not (y-or-n-p (format "Warning: desktop file appears to be in use by PID %s.\n\ Using it may cause conflicts. Use it anyway? " owner))))) (let ((default-directory desktop-dirname)) (setq desktop-dirname nil) (run-hooks 'desktop-not-loaded-hook) (unless desktop-dirname (message "Desktop file in use; not loaded."))) (desktop-lazy-abort) ;; Temporarily disable the autosave that will leave it ;; disabled when loading the desktop fails with errors, ;; thus not overwriting the desktop with broken contents. (setq desktop-autosave-was-enabled (memq 'desktop-auto-save-set-timer (default-toplevel-value 'window-configuration-change-hook))) (desktop-auto-save-disable) ;; Evaluate desktop buffer and remember when it was modified. (load (desktop-full-file-name) t t t) (setq desktop-file-modtime (nth 5 (file-attributes (desktop-full-file-name)))) ;; If it wasn't already, mark it as in-use, to bother other ;; desktop instances. (unless (eq (emacs-pid) owner) (condition-case nil (desktop-claim-lock) (file-error (message "Couldn't record use of desktop file") (sit-for 1)))) (unless (desktop-restoring-frameset-p) ;; `desktop-create-buffer' puts buffers at end of the buffer list. ;; We want buffers existing prior to evaluating the desktop (and ;; not reused) to be placed at the end of the buffer list, so we ;; move them here. (mapc 'bury-buffer (nreverse (cdr (memq desktop-first-buffer (nreverse (buffer-list)))))) (switch-to-buffer (car (buffer-list)))) (run-hooks 'desktop-delay-hook) (setq desktop-delay-hook nil) (desktop-restore-frameset) (run-hooks 'desktop-after-read-hook) (message "Desktop: %s%d buffer%s restored%s%s." (if desktop-saved-frameset (let ((fn (length (frameset-states desktop-saved-frameset)))) (format "%d frame%s, " fn (if (= fn 1) "" "s"))) "") desktop-buffer-ok-count (if (= 1 desktop-buffer-ok-count) "" "s") (if (< 0 desktop-buffer-fail-count) (format ", %d failed to restore" desktop-buffer-fail-count) "") (if desktop-buffer-args-list (format ", %d to restore lazily" (length desktop-buffer-args-list)) "")) (unless (desktop-restoring-frameset-p) ;; Bury the *Messages* buffer to not reshow it when burying ;; the buffer we switched to above. (when (buffer-live-p (get-buffer "*Messages*")) (bury-buffer "*Messages*")) ;; Clear all windows' previous and next buffers, these have ;; been corrupted by the `switch-to-buffer' calls in ;; `desktop-restore-file-buffer' (bug#11556). This is a ;; brute force fix and should be replaced by a more subtle ;; strategy eventually. (walk-window-tree (lambda (window) (set-window-prev-buffers window nil) (set-window-next-buffers window nil)))) (setq desktop-saved-frameset nil) (if desktop-autosave-was-enabled (desktop-auto-save-enable)) t)) ;; No desktop file found. (let ((default-directory desktop-dirname)) (run-hooks 'desktop-no-desktop-file-hook)) (message "No desktop file.") nil))) (when (daemonp) (defun ambrevar/desktop-init (frame) (when (frame-parameter frame 'client) (desktop-save-mode) (desktop-read) (remove-hook 'after-make-frame-functions 'ambrevar/desktop-init))) (add-hook 'after-make-frame-functions 'ambrevar/desktop-init)) - Leave a ~/.emacs.d/.emacs.desktop behind. - Kill all emacs instances. - `echo 0 > ~/.emacs.d/.emacs.desktop.lock` - Optional: Switch to a TTY. - Start `emacsclient -a '' -t` or `emacsclient -a '' -c` if not in a TTY. - Emacs gives a blank screen (with a blinking cursor in a TTY). Press `n`. - See the *Messages* buffer: the `n` was answering the desktop question. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAlqJYs4ACgkQm9z0l6S7 zH9eZwf+OOKlLj996ahuVod189YAYfGAW+YpnFwj/+0QupgxVgiY6CFEGLBUQ0Al IXxWgPmD23LZTZC3PGSS8tKzbVvn+u2M3Lb6xNZlvu+Jcl528ut7w3oYBUwDHGxb L/YVBWTlBDl81Cxt+S/akyOX7nmvSqU41VtDIjkDBAa5ywRsETbSw5wS/e9YuVA0 m6a3TFv++dpVMQcDik3HUFQeun6iNOvuOJk/Jt8d+gZqc7l2bf1b5/enea1Y3IBD uhpRrHU+gR9bU2aVmELF0aJiJzKagjWRIScgg8gu4qE2yDBoU1ow1oIGO5Z3LUH4 6RsfRQhicgHOvtDix+BLHLUvpBxa4Q== =3pE6 -----END PGP SIGNATURE----- --=-=-=--