emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

server stuff


From: Dave Love
Subject: server stuff
Date: 10 Jan 2003 11:02:39 +0000
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

I'm puzzled why server processes have now been added to Emacs, since
they were rejected originally.  However...

I suggest changes to server.el along these lines, mainly so users can
use Custom to set it up.  Also, I don't think /tmp should be hardwired
but if that's changed, emacsclient.c will need changing in sync, which
I haven't done.

Note the comment about security.  I haven't tried to check whether
it's safe, but it doesn't look so, and it's not what gnuserv does.
That needs to be taken more seriously now the server can actually
execute Lisp.

2003-01-08  Dave Love  <address@hidden>

        * server.el (server-window): Customize.
        (server-mode): New.
        (server-temp-file-regexp, server-socket-name): Use
        temporary-file-directory.
        (server-unload-hook): Call server-start.

*** server.el.~1.86.~   Sat Nov  2 18:48:41 2002
--- server.el   Wed Jan  8 18:37:58 2003
***************
*** 1,6 ****
  ;;; server.el --- Lisp code for GNU Emacs running as server process
  
! ;; Copyright (C) 1986, 87, 92, 94, 95, 96, 97, 98, 99, 2000, 2001
  ;;     Free Software Foundation, Inc.
  
  ;; Author: William Sommerfeld <address@hidden>
--- 1,6 ----
  ;;; server.el --- Lisp code for GNU Emacs running as server process
  
! ;; Copyright (C) 1986, 87, 92, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002
  ;;     Free Software Foundation, Inc.
  
  ;; Author: William Sommerfeld <address@hidden>
***************
*** 44,53 ****
  ;; Note that any number of clients may dispatch files to emacs to be edited.
  
  ;; When you finish editing a Server buffer, again call server-edit
! ;; to mark that buffer as done for the client and switch to the next 
! ;; Server buffer.  When all the buffers for a client have been edited 
  ;; and exited with server-edit, the client "editor" will return
! ;; to the program that invoked it.  
  
  ;; Your editing commands and Emacs's display output go to and from
  ;; the terminal in the usual way.  Thus, server operation is possible
--- 44,53 ----
  ;; Note that any number of clients may dispatch files to emacs to be edited.
  
  ;; When you finish editing a Server buffer, again call server-edit
! ;; to mark that buffer as done for the client and switch to the next
! ;; Server buffer.  When all the buffers for a client have been edited
  ;; and exited with server-edit, the client "editor" will return
! ;; to the program that invoked it.
  
  ;; Your editing commands and Emacs's display output go to and from
  ;; the terminal in the usual way.  Thus, server operation is possible
***************
*** 69,76 ****
  ;; brought into the foreground for editing.  When done editing, Emacs is
  ;; suspended again, and the client program is brought into the foreground.
  
! ;; The buffer local variable "server-buffer-clients" lists 
! ;; the clients who are waiting for this buffer to be edited.  
  ;; The global variable "server-clients" lists all the waiting clients,
  ;; and which files are yet to be edited for each.
  
--- 69,76 ----
  ;; brought into the foreground for editing.  When done editing, Emacs is
  ;; suspended again, and the client program is brought into the foreground.
  
! ;; The buffer local variable "server-buffer-clients" lists
! ;; the clients who are waiting for this buffer to be edited.
  ;; The global variable "server-clients" lists all the waiting clients,
  ;; and which files are yet to be edited for each.
  
***************
*** 97,104 ****
    :group 'server
    :type 'hook)
  
! (defvar server-process nil 
!   "The current server process")
  
  (defvar server-previous-strings nil)
  
--- 97,104 ----
    :group 'server
    :type 'hook)
  
! (defvar server-process nil
!   "The current server process.")
  
  (defvar server-previous-strings nil)
  
***************
*** 114,137 ****
  ;; Changing major modes should not erase this local.
  (put 'server-buffer-clients 'permanent-local t)
  
! (defvar server-window nil
!   "*The window to use for selecting Emacs server buffers.
  If nil, use the selected window.
- If it is a frame, use the frame's selected window.
  If it is a function, it should take one argument (a buffer) and
! display and select it.  A common value is `pop-to-buffer'.")
  
! (defcustom server-temp-file-regexp "^/tmp/Re\\|/draft$"
!   "*Regexp which should match filenames of temporary files
! which are deleted and reused after each edit
! by the programs that invoke the Emacs server."
    :group 'server
    :type 'regexp)
  
  (defcustom server-kill-new-buffers t
    "*Whether to kill buffers when done with them.
  If non-nil, kill a buffer unless it already existed before editing
! it with Emacs server. If nil, kill only buffers as specified by
  `server-temp-file-regexp'.
  Please note that only buffers are killed that still have a client,
  i.e. buffers visited which \"emacsclient --no-wait\" are never killed in
--- 114,150 ----
  ;; Changing major modes should not erase this local.
  (put 'server-buffer-clients 'permanent-local t)
  
! (defcustom server-window nil
!   "*Specification of the window to use for selecting Emacs server buffers.
  If nil, use the selected window.
  If it is a function, it should take one argument (a buffer) and
! display and select it.  A common value is `pop-to-buffer'.
! If it is a window, use that.
! If it is a frame, use the frame's selected window.
  
! It is not meaningful to set this to a specific frame or window with Custom.
! Only programs can do so."
!   :group 'server
!   :version "21.4"
!   :type '(choice (const :tag "Use selected window"
!                       :match (lambda (widget value)
!                                (not (functionp value)))
!                       nil)
!                (function-item :tag "Use pop-to-buffer" pop-to-buffer)
!                (function :tag "Other function")))
! 
! (defcustom server-temp-file-regexp (concat "^" temporary-file-directory
!                                          "/Re\\|/draft$")
!   "*Regexp matching names of temporary files.
! These are deleted and reused after each edit by the programs that
! invoke the Emacs server."
    :group 'server
    :type 'regexp)
  
  (defcustom server-kill-new-buffers t
    "*Whether to kill buffers when done with them.
  If non-nil, kill a buffer unless it already existed before editing
! it with Emacs server.  If nil, kill only buffers as specified by
  `server-temp-file-regexp'.
  Please note that only buffers are killed that still have a client,
  i.e. buffers visited which \"emacsclient --no-wait\" are never killed in
***************
*** 149,161 ****
  are done with it in the server.")
  (make-variable-buffer-local 'server-existing-buffer)
  
  (defvar server-socket-name
!   (format "/tmp/esrv%d-%s" (user-uid)
          (substring (system-name) 0 (string-match "\\." (system-name)))))
  
- ;; If a *server* buffer exists,
- ;; write STRING to it for logging purposes.
  (defun server-log (string &optional client)
    (if (get-buffer "*server*")
        (with-current-buffer "*server*"
        (goto-char (point-max))
--- 162,176 ----
  are done with it in the server.")
  (make-variable-buffer-local 'server-existing-buffer)
  
+ ;; Fixme: This doesn't look secure.  If it really is, it deserves a
+ ;; comment, but I'd expect it to be created in a protected subdir as
+ ;; normal.  -- fx
  (defvar server-socket-name
!   (format "/%s/esrv%d-%s" temporary-file-directory (user-uid)
          (substring (system-name) 0 (string-match "\\." (system-name)))))
  
  (defun server-log (string &optional client)
+   "If a *server* buffer exists, write STRING to it for logging purposes."
    (if (get-buffer "*server*")
        (with-current-buffer "*server*"
        (goto-char (point-max))
***************
*** 249,258 ****
                   ;; to file-name-coding-system.
                   :coding 'raw-text)))
        (set-default-file-modes umask)))))
  
- ;Process a request from the server to edit some files.
- ;Format of STRING is "PATH PATH PATH... \n"
  (defun server-process-filter (proc string)
    (server-log string proc)
    (let ((ps (assq proc server-previous-strings)))
      (when (cdr ps)
--- 264,286 ----
                   ;; to file-name-coding-system.
                   :coding 'raw-text)))
        (set-default-file-modes umask)))))
+ 
+ ;;;###autoload
+ (define-minor-mode server-mode
+   "Toggle Server mode.
+ With ARG, turn Server mode on if ARG is positive, off otherwise.
+ Server mode runs a process that accepts commands from the
+ `emacsclient' program.  See `server-start' and Info node `Emacs server'."
+   :global t
+   :group 'server
+   ;; Fixme: Should this check for an existing server socket and do
+   ;; nothing if there is one (for multiple Emacs sessions)?
+   (server-start (not server-mode)))
+ (custom-add-version 'server-mode "21.4")
  
  (defun server-process-filter (proc string)
+   "Process a request from the server to edit some files.
+ PROC is the server process.  Format of STRING is \"PATH PATH PATH... \n\"."
    (server-log string proc)
    (let ((ps (assq proc server-previous-strings)))
      (when (cdr ps)
***************
*** 520,526 ****
  prevent a backup for it.)  The variable `server-temp-file-regexp' controls
  which filenames are considered temporary.
  
! If invoked with a prefix argument, or if there is no server process running, 
  starts server process and that is all.  Invoked by \\[server-edit]."
    (interactive "P")
    (if (or arg
--- 548,554 ----
  prevent a backup for it.)  The variable `server-temp-file-regexp' controls
  which filenames are considered temporary.
  
! If invoked with a prefix argument, or if there is no server process running,
  starts server process and that is all.  Invoked by \\[server-edit]."
    (interactive "P")
    (if (or arg
***************
*** 585,590 ****
--- 613,619 ----
  (global-set-key "\C-x#" 'server-edit)
  
  (defun server-unload-hook ()
+   (server-start t)
    (remove-hook 'kill-buffer-query-functions 
'server-kill-buffer-query-function)
    (remove-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function)
    (remove-hook 'kill-buffer-hook 'server-kill-buffer))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]