/* Client process that communicates with GNU Emacs acting as server.
-Copyright (C) 1986-1987, 1994, 1999-2014 Free Software Foundation, Inc.
+Copyright (C) 1986-1987, 1994, 1999-2015 Free Software Foundation, Inc.
This file is part of GNU Emacs.
# define CLOSE_SOCKET close
# define INITIALIZE()
-# ifndef WCONTINUED
-# define WCONTINUED 8
-# endif
-
#define egetenv(VAR) getenv(VAR)
#endif /* !WINDOWSNT */
#include <signal.h>
#include <errno.h>
-
-\f
-char *getenv (const char *);
-
#ifndef VERSION
#define VERSION "unspecified"
#endif
{
char *path = xmalloc (strlen (home) + strlen (config_file)
+ EXTRA_SPACE);
- strcpy (path, home);
- strcat (path, "/.emacs.d/server/");
- strcat (path, config_file);
+ char *z = stpcpy (path, home);
+ z = stpcpy (z, "/.emacs.d/server/");
+ strcpy (z, config_file);
config = fopen (path, "rb");
free (path);
}
{
char *path = xmalloc (strlen (home) + strlen (config_file)
+ EXTRA_SPACE);
- strcpy (path, home);
- strcat (path, "/.emacs.d/server/");
- strcat (path, config_file);
+ char *z = stpcpy (path, home);
+ z = stpcpy (z, "/.emacs.d/server/");
+ strcpy (z, config_file);
config = fopen (path, "rb");
free (path);
}
handle_sigcont (int signalnum)
{
int old_errno = errno;
+ pid_t pgrp = getpgrp ();
+ pid_t tcpgrp = tcgetpgrp (1);
- if (tcgetpgrp (1) == getpgrp ())
+ if (tcpgrp == pgrp)
{
- /* We are in the foreground. */
+ /* We are in the foreground. */
send_to_emacs (emacs_socket, "-resume \n");
}
- else
+ else if (0 <= tcpgrp && tty)
{
- /* We are in the background; cancel the continue. */
- raise (SIGSTOP);
+ /* We are in the background; cancel the continue. */
+ kill (-pgrp, SIGTTIN);
}
signal (signalnum, handle_sigcont);
{
/* socket_name is a file name component. */
long uid = geteuid ();
- ptrdiff_t tmpdirlen;
use_tmpdir = 1;
tmpdir = egetenv ("TMPDIR");
if (!tmpdir)
#endif
tmpdir = "/tmp";
}
- tmpdirlen = strlen (tmpdir);
socket_name_storage =
- xmalloc (tmpdirlen + strlen (server_name) + EXTRA_SPACE);
- strcpy (socket_name_storage, tmpdir);
- sprintf (socket_name_storage + tmpdirlen, "/emacs%ld/", uid);
- strcat (socket_name_storage + tmpdirlen, server_name);
+ xmalloc (strlen (tmpdir) + strlen (server_name) + EXTRA_SPACE);
+ char *z = stpcpy (socket_name_storage, tmpdir);
+ z += sprintf (z, "/emacs%ld/", uid);
+ strcpy (z, server_name);
local_socket_name = socket_name_storage;
}
{
/* We're running under su, apparently. */
long uid = pw->pw_uid;
- ptrdiff_t tmpdirlen = strlen (tmpdir);
char *user_socket_name
- = xmalloc (tmpdirlen + strlen (server_name) + EXTRA_SPACE);
- strcpy (user_socket_name, tmpdir);
- sprintf (user_socket_name + tmpdirlen, "/emacs%ld/", uid);
- strcat (user_socket_name + tmpdirlen, server_name);
+ = xmalloc (strlen (tmpdir) + strlen (server_name)
+ + EXTRA_SPACE);
+ char *z = stpcpy (user_socket_name, tmpdir);
+ z += sprintf (z, "/emacs%ld/", uid);
+ strcpy (z, server_name);
if (strlen (user_socket_name) < sizeof (server.sun_path))
strcpy (server.sun_path, user_socket_name);
const char *deq = "--daemon=";
char *daemon_arg = xmalloc (strlen (deq)
+ strlen (socket_name) + 1);
- strcpy (daemon_arg, deq);
- strcat (daemon_arg, socket_name);
+ strcpy (stpcpy (daemon_arg, deq), socket_name);
d_argv[1] = daemon_arg;
}
execvp ("emacs", d_argv);
exit (EXIT_FAILURE);
}
+#ifndef WINDOWSNT
+ if (tty)
+ {
+ pid_t pgrp = getpgrp ();
+ pid_t tcpgrp = tcgetpgrp (1);
+ if (0 <= tcpgrp && tcpgrp != pgrp)
+ kill (-pgrp, SIGTTIN);
+ }
+#endif /* !WINDOWSNT */
+
/* If alternate_editor is the empty string, start the emacs daemon
in case of failure to connect. */
start_daemon_if_needed = (alternate_editor