This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[incremental] Patch: FYI: add --kill-server
- From: Tom Tromey <tromey at redhat dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 31 Aug 2007 08:44:09 -0600
- Subject: [incremental] Patch: FYI: add --kill-server
- Reply-to: Tom Tromey <tromey at redhat dot com>
I'm checking this in on the incremental-compiler branch.
This adds 'gcc --kill-server', to stop the running server.
Tom
ChangeLog:
2007-08-31 Tom Tromey <tromey@redhat.com>
* server.h (client_kill_server): Declare.
* gcc.c (kill_server): New global.
(option_map): Added --kill-server.
(process_command): Handle -kill-server.
(main): Likewise.
* server.c (request_and_response): Changed return type. Handle
'K' request.
(server_main_loop): Use request_and_response return value.
(send_command_and_wait): New function.
(client_wait): Use it.
(client_kill_server): New function.
Index: gcc.c
===================================================================
--- gcc.c (revision 127930)
+++ gcc.c (working copy)
@@ -200,6 +200,10 @@
static int server;
+/* Flag indicating that we should kill a running server process. */
+
+static int kill_server;
+
/* Flag indicating that we should attempt to connect to a server
process. */
@@ -1129,6 +1133,7 @@
{"--include-with-prefix", "-iwithprefix", "a"},
{"--include-with-prefix-before", "-iwithprefixbefore", "a"},
{"--include-with-prefix-after", "-iwithprefix", "a"},
+ {"--kill-server", "-kill-server", 0},
{"--language", "-x", "a"},
{"--library-directory", "-L", "a"},
{"--machine", "-m", "aj"},
@@ -3821,6 +3826,11 @@
server = 1;
n_switches++;
}
+ else if (strcmp (argv[i], "-kill-server") == 0)
+ {
+ kill_server = 1;
+ n_switches++;
+ }
else if (strcmp (argv[i], "-###") == 0)
{
/* This is similar to -v except that there is no execution
@@ -4194,6 +4204,8 @@
;
else if (strcmp (argv[i], "-server") == 0)
;
+ else if (strcmp (argv[i], "-kill-server") == 0)
+ ;
else if (strcmp (argv[i], "-###") == 0)
;
else if (argv[i][0] == '-' && argv[i][1] != 0)
@@ -6532,6 +6544,13 @@
return 0;
}
+ if (kill_server)
+ {
+ /* FIXME: allow more than cc1... */
+ client_kill_server (find_a_file (&exec_prefixes, "cc1", X_OK, 0));
+ return 0;
+ }
+
if (verbose_flag)
{
int n;
Index: server.c
===================================================================
--- server.c (revision 127930)
+++ server.c (working copy)
@@ -207,7 +207,7 @@
/* Helper function for server_main_loop. Read a request from the file
descriptor REQFD and take action. */
-static void
+static bool
request_and_response (int reqfd)
{
char **argvs[2];
@@ -259,7 +259,9 @@
}
else if (cmd == 'K')
{
- /* Kill server. FIXME. */
+ /* Kill server. In the single-threaded server, it is ok to
+ simply tell the main loop to exit. */
+ return false;
}
else
{
@@ -267,6 +269,7 @@
break;
}
}
+ return true;
}
/* Main loop of the server. Creates a server socket and listens to
@@ -279,6 +282,7 @@
{
int sockfd = open_socket (progname);
char reply = 't';
+ bool result = true;
if (sockfd < 0)
{
@@ -295,7 +299,7 @@
listen (sockfd, 5);
- while (true)
+ while (result)
{
int reqfd = accept (sockfd, NULL, 0);
if (reqfd < 0)
@@ -303,7 +307,7 @@
error ("error while accepting: %s", xstrerror (errno));
break;
}
- request_and_response (reqfd);
+ result = request_and_response (reqfd);
close (reqfd);
}
@@ -379,16 +383,13 @@
return result;
}
-/* Called by the client after submitting all its jobs. This waits for
- the server to complete the tasks. It reads from the server
- connection and prints errors to stderr. Both 'client_connect' and
- 'client_send_command' must have been successfully called before
- calling this. */
-void
-client_wait (void)
+/* Helper for client_wait and client_kill_server. Send a
+ single-letter command to the server and pipe the server's output to
+ our stderr. */
+static void
+send_command_and_wait (char cmd)
{
gcc_assert (connection_fd >= 0);
- char cmd = 'D';
if (write (connection_fd, &cmd, 1) != 1)
return;
@@ -404,3 +405,27 @@
fwrite (buffer, 1, len, stderr);
}
}
+
+/* Called by the client after submitting all its jobs. This waits for
+ the server to complete the tasks. It reads from the server
+ connection and prints errors to stderr. Both 'client_connect' and
+ 'client_send_command' must have been successfully called before
+ calling this. */
+void
+client_wait (void)
+{
+ send_command_and_wait ('D');
+}
+
+/* Request that the server exit. PROGNAME is the path name of the
+ server executable. */
+void
+client_kill_server (const char *progname)
+{
+ if (!client_connect (progname))
+ {
+ error ("couldn't connect to server: %s", xstrerror (errno));
+ return;
+ }
+ send_command_and_wait ('K');
+}
Index: server.h
===================================================================
--- server.h (revision 127930)
+++ server.h (working copy)
@@ -28,6 +28,7 @@
extern bool client_connect (const char *);
extern bool client_send_command (const char **);
extern void client_wait (void);
+extern void client_kill_server (const char *);
/* The main loop calls this when a command is read. */
extern void server_callback (int, char **, char **);