GNUSERV(1)

πŸ’– GNUSERV(1) β€” the gnuserv / gnuclient manual, but make it make sense πŸ’–

okay bestie, sit down, hydrate, because this is the manual for the whole gnuserv situation β€” the server and its little client besties for Emacs and XEmacs. it's giving "old-school Unix networking but make it lisp." let's get into it πŸ’…


✨ NAME ✨

gnuserv, gnuclient β€” server and clients for Emacs and XEmacs 🫢


✨ SYNOPSIS ✨

gnuclient [-display display] [-q] [-v] [-l library] [-batch] [-f
function] [-eval form] [-h hostname] [-p port] [-r remote-pathname]
[[+line] file] ...
gnudoit [-q] form
gnuserv
gnuattach Removed as of gnuserv 3.x

✨ DESCRIPTION ✨

so gnuclient is the vibe-checker that lets you, a whole entire human, ask an already-running Emacs or XEmacs process to please go edit the files or directories you named, and/or evaluate some lisp forms. depending on your environment it can be an X frame or a TTY frame. one classic glow-up use case: you're on a dialup connection to a machine where an Emacs or XEmacs process is already living its best life, and you just want to slide into its DMs. πŸ’Œ

gnudoit is a shell script frontend to gnuclient -batch -eval form. and listen. its use is deprecated. like, we don't do that anymore. try to get used to calling gnuclient directly, bestie. i promise it's fine. πŸ™ˆ

gnuserv is the actual server program, the main character, the one that Emacs or XEmacs sets running so it can handle all the incoming and outgoing requests. you don't usually summon it yourself β€” it gets started from Emacs or XEmacs by loading the gnuserv package and evaluating the Lisp form (gnuserv-start). she starts herself, she's independent like that. ✨

gnuattach no longer exists. gone. deceased. not invited to the function. πŸ’€


✨ OPTIONS ✨

gnuclient supports as much of the command line options of Emacs as makes sense in this context β€” like, the sensible subset β€” and then it adds a few of its own because she's extra. πŸ’…

heads up: options with long names can also be specified using a double hyphen instead of a single one. flexible queen.
  • -display display, --display display β€” if this is given, or the DISPLAY environment variable is set, then gnuclient tells Emacs to edit files in a frame on the specified X device. πŸ’»
  • -q β€” tells gnuclient to dip out as soon as the connection has been made with the XEmacs process. normally gnuclient is patient and waits until all the files on the command line have been finished with (their buffers killed) by the XEmacs process, and all the forms have been evaluated. -q = no waiting around, bye ✌️
  • -v β€” when this is specified, gnuclient requests that the specified files be viewed instead of edited. look but don't touch energy πŸ‘€
  • -l library β€” tell Emacs to load the specified library. πŸ“š
  • -batch β€” tell Emacs not to open any frames. just load libraries and evaluate lisp code. if no files to execute, functions to call, or forms to eval are given using the -l, -f, or -eval options, then the forms to eval are read from STDIN. headless mode, no window, all business πŸ«₯
  • -f function β€” make Emacs execute the lisp function. πŸƒ
  • -eval form β€” make Emacs execute the lisp form. 🧠
  • -h hostname β€” used only with Internet-domain sockets. this one specifies the host machine that should be running gnuserv. if it's not specified, then the value of the environment variable GNU_HOST is used if it's set. if no hostname is specified and GNU_HOST is not set, an internet connection will not be attempted. N.B.: gnuserv does NOT allow internet connections unless XAUTH authentication is used, or the GNU_SECURE variable has been specified and points at a file listing all trusted hosts. (see SECURITY below.) 🚨
    • note that an internet address may be specified instead of a hostname, which can speed up connections to the server by quite a bit β€” especially if the client machine is running YP. ⚑
    • note also that a hostname of unix can be used to specify that the connection to the server should use a Unix-domain socket (if supported) rather than an Internet-domain socket. 🐧
  • -p port β€” used only with Internet-domain sockets. this specifies the service port used to communicate between server and clients. if it's not specified, then the value of the environment variable GNU_PORT is used, if set; otherwise a service called gnuserv is looked up in the services database. and finally, if no other value can be found for the port, a default port is used, which is usually 21490 + uid. πŸ”’
note that since gnuserv doesn't allow command-line options, the port for it will have to be specified via one of the alternative methods. she doesn't take orders from the command line, sorry. πŸ™…
  • -r pathname β€” used only with Internet-domain sockets. the pathname argument may be needed to inform Emacs how to reach the root directory of a remote machine. gnuclient prepends this string to each path argument given. for example, if you were trying to edit a file on a client machine called otter, whose root directory was accessible from the server machine via the path /net/otter, then this argument should be set to /net/otter. if this option is omitted, then the value is taken from the environment variable GNU_NODE, if set, or the empty string otherwise. πŸ—ΊοΈ
  • [+n] file β€” this is the path of the file to be edited. if the file is a directory, then the directory browsers dired or monkey are usually invoked instead. the cursor is put at line number n if specified. πŸ“

✨ SETUP ✨

gnuserv is packaged standardly with recent versions of XEmacs. so you should be able to start the server simply by evaluating the XEmacs Lisp form (gnuserv-start), or equivalently by typing M-x gnuserv-start. that's it. that's the setup. iconic, minimal, no notes. ✨


✨ CONFIGURATION ✨

the behavior of this whole suite of programs is mostly controlled on the lisp side in Emacs, and its behavior can be customized to a large extent. type M-x customize-group RET gnuserv RET for easy access. more documentation can be found in the file gnuserv.el. πŸ“–


✨ EXAMPLE ✨

gnuclient -q -f mh-smail
gnuclient -h cuckoo -r /ange@otter: /tmp/*
gnuclient ../src/listproc.c

more examples and sample wrapper scripts are provided in the etc/gnuserv directory of the Emacs installation. go look, there's lore in there. πŸŽ€


✨ SYSV IPC ✨

SysV IPC is used to communicate between gnuclient and gnuserv if the symbol SYSV_IPC is defined at the top of gnuserv.h. this is incompatible with both Unix-domain and Internet-domain socket communication as described below. ⚠️

a file called /tmp/gsrv??? is created as a key for the message queue, and if removed will cause the communication between server and client to fail until the server is restarted. so like. don't delete it. seriously. 😭


✨ UNIX-DOMAIN SOCKETS ✨

a Unix-domain socket is used to communicate between gnuclient and gnuserv if the symbol UNIX_DOMAIN_SOCKETS is defined at the top of gnuserv.h. a file called /tmp/gsrvdir????/gsrv is created for communication. πŸ”Œ

if the symbol USE_TMPDIR is set at the top of gnuserv.h, $TMPDIR, when set, is used instead of /tmp. if that file is deleted, or TMPDIR has different values for the server and the client, communication between server and client will fail. πŸ’€

only the user running gnuserv will be able to connect to the socket. exclusive. πŸ’…


✨ INTERNET-DOMAIN SOCKETS ✨

Internet-domain sockets are used to communicate between gnuclient and gnuserv if the symbol INTERNET_DOMAIN_SOCKETS is defined at the top of gnuserv.h. both Internet-domain and Unix-domain sockets can be used at the same time, no cap. 🌐

if a hostname is specified via -h or via the GNU_HOST environment variable, gnuclient establishes connections using an internet domain socket. if not, a local connection is attempted via either a unix-domain socket or SYSV IPC. ✨


✨ SECURITY ✨

using Internet-domain sockets, a more robust form of security is needed that wasn't necessary with either Unix-domain sockets or SysV IPC. currently, two authentication protocols are supported to provide this: MIT-MAGIC-COOKIE-1 (based on the X11 xauth(1) program) and a simple host-based access control mechanism, hereafter called GNUSERV-1. πŸ”

the GNUSERV-1 protocol is always available, whereas support for MIT-MAGIC-COOKIE-1 may or may not have been enabled (via a #define at the top of gnuserv.h) at compile-time. so it's a vibe-check-on-your-build situation. 🫠

gnuserv, using GNUSERV-1, performs a limited form of access control at the machine level. by default no internet-domain socket is opened. if the variable GNU_SECURE can be found in gnuserv's environment, and it names a readable filename, then this file is opened and assumed to be a list of hosts, one per line, from which the server will allow requests. connections from any other host will be rejected. 🚫

even the machine on which gnuserv is running is not permitted to make connections via the internet socket unless its hostname is explicitly specified in this file. 😀

note that a host may be either a numeric IP address or a hostname, and that any user on an approved host may connect to your gnuserv and execute arbitrary elisp (e.g., delete all your files). 😭 so like, be so for real about who's on that list. also: if this file contains a lot of hostnames then the server may take quite a time to start up. patience, bestie. 🐌

when the MIT-MAGIC-COOKIE-1 protocol is enabled, an internet socket is opened by default. gnuserv will accept a connection from any host, and will wait for a "magic cookie" (essentially, a password) to be presented by the client. if the client doesn't present the cookie, or if the cookie is wrong, the authentication of the client is considered to have failed. πŸͺ

at this point, gnuserv falls back to the GNUSERV-1 protocol; if the client is calling from a host listed in the GNU_SECURE file, the connection will be accepted, otherwise it will be rejected. so it's giving "plan B is also a vibe check." ✨

when the gnuserv server is started, it looks for a cookie defined for display 999 on the machine where it is running. if the cookie is found, it will be stored for use as the authentication cookie. πŸͺ✨

these cookies are defined in an authorization file (usually ~/.Xauthority) that is manipulated by the X11 xauth(1) program. for example, a machine "kali" which runs an emacs that invokes gnuserv should respond as follows (at the shell prompt) when set up correctly.

kali% xauth list
GS65.SP.CS.CMU.EDU:0  MIT-MAGIC-COOKIE-1  11223344
KALI.FTM.CS.CMU.EDU:999  MIT-MAGIC-COOKIE-1  1234

in the above case, the authorization file defines two cookies. the second one, defined for screen 999 on the server machine, is used for gnuserv authentication. πŸ‘‘

on the client machine's side, the authorization file must contain an identical line, specifying the server's cookie. in other words, on a machine "foobar" which wishes to connect to "kali," the xauth list output should contain the line:

KALI.FTM.CS.CMU.EDU:999  MIT-MAGIC-COOKIE-1  1234

to create the cookie, you can use a command like

xauth add `hostname`:999 MIT-MAGIC-COOKIE-1 `head -c512
/dev/urandom|md5sum`

for more information on authorization files, take a look at the xauth(1X11) man page, or invoke xauth interactively (without any arguments) and type "help" at the prompt. πŸ“–

remember that case in the name of the authorization protocol (i.e. MIT-MAGIC-COOKIE-1) is significant! mit-magic-cookie-1 is not it, bestie. πŸ’…

🌸 ENVIRONMENT 🌸

Bestie, there's exactly one env var here and she's doing the most:

  • DISPLAY β€” the default X device where your edit frame gets put. That's it. That's the whole list. She's simple but she matters. πŸ’…

πŸŽ€ FILES πŸŽ€

Here's where gnuserv keeps her little treasures on disk, and which flavor of socket you're running totally changes where she hides them:

  • /tmp/gsrv??? β€” the SYSV IPC girlies only 🫢 if you're on the SYSV IPC setup, this is your spot.
  • /tmp/gsrvdir???/gsrv β€” unix domain sockets only ✨ if you went the unix-domain-socket route, this is the one.
  • ~/.emacs β€” your Emacs customization file, aka the vibe-setter. If you wanna know more, go read emacs(1) and xemacs(1), they got you. πŸ“–

✨ SEE ALSO ✨

Go read these when you're done here, no cap:

  • dtemacs(1)
  • xauth(1X11)
  • Xsecurity(1X11)
  • gnuserv.el

πŸ’€ BUGS πŸ’€

Okay so there IS one known oopsie, and it's not me being dramatic, it's literally in the source:

NULs occurring in result strings don't get passed back to gnudoit properly.

So like, if your result string has a NUL in it, gnudoit is not getting the full picture. She's giving selective hearing. 😭 Not a you problem, a her problem. Just know it.


πŸ‘‘ AUTHOR. πŸ‘‘

This absolute legend right here:

Andy Norman (ange@hplb.hpl.hp.com) β€” and he built it heavily upon etc/emacsclient.c, etc/server.c and lisp/server.el from the GNU Emacs 18.52 distribution. Respect the lineage. 🧚

And then a whole squad of people came through with various modifications, so let's give them their flowers:

  • Bob Weiner (weiner@mot.com)
  • Darrell Kindred (dkindred@cmu.edu)
  • Arup Mukherjee (arup@cmu.edu)
  • Ben Wing (ben@xemacs.org)
  • Hrvoje Niksic (hniksic@xemacs.org)

That's the whole page, bestie, you made it to the end πŸπŸ’– This one came out of the 4th Berkeley Distribution, and the page is filed under GNUSERV(1) β€” so if you ever need to cite her, that's the flex. Now go set up your sockets and slay. πŸ¦‹βœ¨

πŸ“¦ where this page comes from