summaryrefslogtreecommitdiff
path: root/lib-src/emacsclient.c
diff options
context:
space:
mode:
authorYuuki Harano <masm+github@masm11.me>2021-11-11 00:39:53 +0900
committerYuuki Harano <masm+github@masm11.me>2021-11-11 00:39:53 +0900
commit4dd1f56f29fc598a8339a345c2f8945250600602 (patch)
treeaf341efedffe027e533b1bcc0dbf270532e48285 /lib-src/emacsclient.c
parent4c49ec7f865bdad1629d2f125f71f4e506b258f2 (diff)
parent810fa21d26453f898de9747ece7205dfe6de9d08 (diff)
downloademacs-4dd1f56f29fc598a8339a345c2f8945250600602.tar.gz
Merge branch 'master' of git.savannah.gnu.org:/srv/git/emacs into feature/pgtk
Diffstat (limited to 'lib-src/emacsclient.c')
-rw-r--r--lib-src/emacsclient.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 8fa571fd4ef..1f3e72f81db 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -80,9 +80,6 @@ char *w32_getenv (const char *);
#include <sys/stat.h>
#include <unistd.h>
-#ifndef WINDOWSNT
-# include <acl.h>
-#endif
#include <filename.h>
#include <intprops.h>
#include <min-max.h>
@@ -94,10 +91,6 @@ char *w32_getenv (const char *);
# pragma GCC diagnostic ignored "-Wformat-truncation=2"
#endif
-#if !defined O_PATH && !defined WINDOWSNT
-# define O_PATH O_SEARCH
-#endif
-
/* Name used to invoke this program. */
static char const *progname;
@@ -123,6 +116,9 @@ static bool eval;
/* True means open a new frame. --create-frame etc. */
static bool create_frame;
+/* True means reuse a frame if it already exists. */
+static bool reuse_frame;
+
/* The display on which Emacs should work. --display. */
static char const *display;
@@ -172,6 +168,7 @@ static struct option const longopts[] =
{ "tty", no_argument, NULL, 't' },
{ "nw", no_argument, NULL, 't' },
{ "create-frame", no_argument, NULL, 'c' },
+ { "reuse-frame", no_argument, NULL, 'r' },
{ "alternate-editor", required_argument, NULL, 'a' },
{ "frame-parameters", required_argument, NULL, 'F' },
#ifdef SOCKETS_IN_FILE_SYSTEM
@@ -558,6 +555,11 @@ decode_options (int argc, char **argv)
create_frame = true;
break;
+ case 'r':
+ create_frame = true;
+ reuse_frame = true;
+ break;
+
case 'p':
parent_id = optarg;
create_frame = true;
@@ -659,6 +661,8 @@ The following OPTIONS are accepted:\n\
-nw, -t, --tty Open a new Emacs frame on the current terminal\n\
-c, --create-frame Create a new frame instead of trying to\n\
use the current Emacs frame\n\
+-r, --reuse-frame Create a new frame if none exists, otherwise\n\
+ use the current Emacs frame\n\
", "\
-F ALIST, --frame-parameters=ALIST\n\
Set the parameters of a new frame\n\
@@ -1140,6 +1144,12 @@ process_grouping (void)
#ifdef SOCKETS_IN_FILE_SYSTEM
+# include <acl.h>
+
+# ifndef O_PATH
+# define O_PATH O_SEARCH
+# endif
+
/* A local socket address. The union avoids the need to cast. */
union local_sockaddr
{
@@ -1406,10 +1416,8 @@ local_sockname (int s, char sockname[socknamesize], int tmpdirlen,
/* Put the full address name into the buffer, since the caller might
need it for diagnostics. But don't overrun the buffer. */
uintmax_t uidmax = uid;
- int emacsdirlen;
int suffixlen = snprintf (sockname + tmpdirlen, socknamesize - tmpdirlen,
- "/emacs%"PRIuMAX"%n/%s", uidmax, &emacsdirlen,
- server_name);
+ "/emacs%"PRIuMAX"/%s", uidmax, server_name);
if (! (0 <= suffixlen && suffixlen < socknamesize - tmpdirlen))
return ENAMETOOLONG;
@@ -1417,7 +1425,8 @@ local_sockname (int s, char sockname[socknamesize], int tmpdirlen,
this user's directory and does not let others write to it; this
fends off some symlink attacks. To avoid races, keep the parent
directory open while checking. */
- char *emacsdirend = sockname + tmpdirlen + emacsdirlen;
+ char *emacsdirend = sockname + tmpdirlen + suffixlen -
+ strlen(server_name) - 1;
*emacsdirend = '\0';
int dir = openat (AT_FDCWD, sockname,
O_PATH | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
@@ -1948,7 +1957,7 @@ main (int argc, char **argv)
if (nowait)
send_to_emacs (emacs_socket, "-nowait ");
- if (!create_frame)
+ if (!create_frame || reuse_frame)
send_to_emacs (emacs_socket, "-current-frame ");
if (display)