/* Client process that communicates with GNU Emacs acting as server.
-Copyright (C) 1986-1987, 1994, 1999-2013 Free Software Foundation, Inc.
+Copyright (C) 1986-1987, 1994, 1999-2014 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#define EXIT_FAILURE 1
#endif
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
/* Additional space when allocating buffers for filenames, etc. */
#define EXTRA_SPACE 100
/* Display a normal or error message.
On Windows, use a message box if compiled as a Windows app. */
-static void message (int, const char *, ...) ATTRIBUTE_FORMAT_PRINTF (2, 3);
+static void message (bool, const char *, ...) ATTRIBUTE_FORMAT_PRINTF (2, 3);
static void
-message (int is_error, const char *format, ...)
+message (bool is_error, const char *format, ...)
{
va_list args;
break;
case 'V':
- message (FALSE, "emacsclient %s\n", VERSION);
+ message (false, "emacsclient %s\n", VERSION);
exit (EXIT_SUCCESS);
break;
break;
default:
- message (TRUE, "Try `%s --help' for more information\n", progname);
+ message (true, "Try `%s --help' for more information\n", progname);
exit (EXIT_FAILURE);
break;
}
if (alternate_editor && alternate_editor[0] == '\0')
{
- message (TRUE, "--alternate-editor argument or ALTERNATE_EDITOR variable cannot be\n\
+ message (true, "--alternate-editor argument or ALTERNATE_EDITOR variable cannot be\n\
an empty string");
exit (EXIT_FAILURE);
}
message aligns properly both in a tty and in a Windows message box.
Please try to preserve them; otherwise the output is very hard to read
when using emacsclientw. */
- message (FALSE,
+ message (false,
"Usage: %s [OPTIONS] FILE...\n%s%s%s", progname, "\
Tell the Emacs server to visit the specified files.\n\
Every FILE can be either just a FILENAME or [+LINE[:COLUMN]] FILENAME.\n\
int i = optind - 1;
execvp (alternate_editor, main_argv + i);
- message (TRUE, "%s: error executing alternate editor \"%s\"\n",
+ message (true, "%s: error executing alternate editor \"%s\"\n",
progname, alternate_editor);
}
exit (EXIT_FAILURE);
{
main_argv = argv;
progname = argv[0];
- message (TRUE, "%s: Sorry, the Emacs server is supported only\n"
+ message (true, "%s: Sorry, the Emacs server is supported only\n"
"on systems with Berkeley sockets.\n",
argv[0]);
fail ();
| FORMAT_MESSAGE_ARGUMENT_ARRAY,
NULL, WSAGetLastError (), 0, (LPTSTR)&msg, 0, NULL);
- message (TRUE, "%s: %s: %s\n", progname, function_name, msg);
+ message (true, "%s: %s: %s\n", progname, function_name, msg);
LocalFree (msg);
#else
- message (TRUE, "%s: %s: %s\n", progname, function_name, strerror (errno));
+ message (true, "%s: %s: %s\n", progname, function_name, strerror (errno));
#endif
}
int sent = send (s, send_buffer, sblen, 0);
if (sent < 0)
{
- message (TRUE, "%s: failed to send %d bytes to socket: %s\n",
+ message (true, "%s: failed to send %d bytes to socket: %s\n",
progname, sblen, strerror (errno));
fail ();
}
file_name_absolute_p (const char *filename)
{
/* Sanity check, it shouldn't happen. */
- if (! filename) return FALSE;
+ if (! filename) return false;
/* /xxx is always an absolute path. */
- if (filename[0] == '/') return TRUE;
+ if (filename[0] == '/') return true;
/* Empty filenames (which shouldn't happen) are relative. */
- if (filename[0] == '\0') return FALSE;
+ if (filename[0] == '\0') return false;
#ifdef WINDOWSNT
/* X:\xxx is always absolute. */
if (isalpha ((unsigned char) filename[0])
&& filename[1] == ':' && (filename[2] == '\\' || filename[2] == '/'))
- return TRUE;
+ return true;
/* Both \xxx and \\xxx\yyy are absolute. */
- if (filename[0] == '\\') return TRUE;
+ if (filename[0] == '\\') return true;
#endif
- return FALSE;
+ return false;
}
#ifdef WINDOWSNT
if (WSAStartup (MAKEWORD (2, 0), &wsaData))
{
- message (TRUE, "%s: error initializing WinSock2\n", progname);
+ message (true, "%s: error initializing WinSock2\n", progname);
exit (EXIT_FAILURE);
}
}
if (! config)
- return FALSE;
+ return false;
if (fgets (dotted, sizeof dotted, config)
&& (port = strchr (dotted, ':')))
*port++ = '\0';
else
{
- message (TRUE, "%s: invalid configuration info\n", progname);
+ message (true, "%s: invalid configuration info\n", progname);
exit (EXIT_FAILURE);
}
if (! fread (authentication, AUTH_KEY_LENGTH, 1, config))
{
- message (TRUE, "%s: cannot read authentication info\n", progname);
+ message (true, "%s: cannot read authentication info\n", progname);
exit (EXIT_FAILURE);
}
fclose (config);
- return TRUE;
+ return true;
}
static HSOCKET
return INVALID_SOCKET;
if (server.sin_addr.s_addr != inet_addr ("127.0.0.1") && !quiet)
- message (FALSE, "%s: connected to remote socket at %s\n",
+ message (false, "%s: connected to remote socket at %s\n",
progname, inet_ntoa (server.sin_addr));
/* Open up an AF_INET socket. */
return 0;
else
{
- message (TRUE, "%s: could not get terminal name\n", progname);
+ message (true, "%s: could not get terminal name\n", progname);
fail ();
}
}
return 0;
else
{
- message (TRUE, "%s: please set the TERM variable to your terminal type\n",
+ message (true, "%s: please set the TERM variable to your terminal type\n",
progname);
fail ();
}
else
{
/* This causes nasty, MULTI_KBOARD-related input lockouts. */
- message (TRUE, "%s: opening a frame in an Emacs term buffer"
+ message (true, "%s: opening a frame in an Emacs term buffer"
" is not supported\n", progname);
fail ();
}
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);
/* Open up an AF_UNIX socket in this person's home directory. */
if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
{
- message (TRUE, "%s: socket: %s\n", progname, strerror (errno));
+ message (true, "%s: socket: %s\n", progname, strerror (errno));
return INVALID_SOCKET;
}
strcpy (server.sun_path, local_socket_name);
else
{
- message (TRUE, "%s: socket-name %s too long\n",
+ message (true, "%s: socket-name %s too long\n",
progname, local_socket_name);
fail ();
}
strcpy (server.sun_path, user_socket_name);
else
{
- message (TRUE, "%s: socket-name %s too long\n",
+ message (true, "%s: socket-name %s too long\n",
progname, user_socket_name);
exit (EXIT_FAILURE);
}
we are root. */
if (0 != geteuid ())
{
- message (TRUE, "%s: Invalid socket owner\n", progname);
+ message (true, "%s: Invalid socket owner\n", progname);
return INVALID_SOCKET;
}
break;
case 2:
/* `stat' failed */
if (saved_errno == ENOENT)
- message (TRUE,
+ message (true,
"%s: can't find socket; have you started the server?\n\
To start the server in Emacs, type \"M-x server-start\".\n",
progname);
else
- message (TRUE, "%s: can't stat %s: %s\n",
+ message (true, "%s: can't stat %s: %s\n",
progname, server.sun_path, strerror (saved_errno));
return INVALID_SOCKET;
}
if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2)
< 0)
{
- message (TRUE, "%s: connect: %s\n", progname, strerror (errno));
+ message (true, "%s: connect: %s\n", progname, strerror (errno));
return INVALID_SOCKET;
}
s = set_local_socket (socket_name);
if ((s != INVALID_SOCKET) || no_exit_if_error)
return s;
- message (TRUE, "%s: error accessing socket \"%s\"\n",
+ message (true, "%s: error accessing socket \"%s\"\n",
progname, socket_name);
exit (EXIT_FAILURE);
}
if ((s != INVALID_SOCKET) || no_exit_if_error)
return s;
- message (TRUE, "%s: error accessing server file \"%s\"\n",
+ message (true, "%s: error accessing server file \"%s\"\n",
progname, local_server_file);
exit (EXIT_FAILURE);
}
return s;
/* No implicit or explicit socket, and no alternate editor. */
- message (TRUE, "%s: No socket or alternate editor. Please use:\n\n"
+ message (true, "%s: No socket or alternate editor. Please use:\n\n"
#ifndef NO_SOCKETS_IN_FILE_SYSTEM
"\t--socket-name\n"
#endif
if ((w == -1) || !WIFEXITED (status) || WEXITSTATUS (status))
{
- message (TRUE, "Error: Could not start the Emacs daemon\n");
+ message (true, "Error: Could not start the Emacs daemon\n");
exit (EXIT_FAILURE);
}
/* Try connecting, the daemon should have started by now. */
- message (TRUE, "Emacs daemon should have started, trying to connect again\n");
+ message (true, "Emacs daemon should have started, trying to connect again\n");
if ((emacs_socket = set_socket (1)) == INVALID_SOCKET)
{
- message (TRUE, "Error: Cannot connect even after starting the Emacs daemon\n");
+ message (true, "Error: Cannot connect even after starting the Emacs daemon\n");
exit (EXIT_FAILURE);
}
}
d_argv[1] = daemon_arg;
}
execvp ("emacs", d_argv);
- message (TRUE, "%s: error starting emacs daemon\n", progname);
+ message (true, "%s: error starting emacs daemon\n", progname);
}
#endif /* WINDOWSNT */
}
if ((argc - optind < 1) && !eval && current_frame)
{
- message (TRUE, "%s: file name or argument required\n"
+ message (true, "%s: file name or argument required\n"
"Try `%s --help' for more information\n",
progname, progname);
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
cwd = get_current_dir_name ();
if (cwd == 0)
{
- message (TRUE, "%s: %s\n", progname,
+ message (true, "%s: %s\n", progname,
"Cannot get current working directory");
fail ();
}