aboutsummaryrefslogtreecommitdiffstats
path: root/apps/sympathy.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/sympathy.c')
-rw-r--r--apps/sympathy.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/apps/sympathy.c b/apps/sympathy.c
index ef120ec..94cd801 100644
--- a/apps/sympathy.c
+++ b/apps/sympathy.c
@@ -11,6 +11,9 @@ static char rcsid[] =
/*
* $Log$
+ * Revision 1.41 2008/03/10 11:49:32 james
+ * *** empty log message ***
+ *
* Revision 1.40 2008/03/07 14:16:44 james
* *** empty log message ***
*
@@ -462,8 +465,8 @@ main (int argc, char *argv[])
ANSI *ansi = NULL;
- int csnok_pipe[2] = { 0 };
- int csnok = 0;
+ int cs_pipe[2] = { 0 };
+ int cs = 0;
int oflags[128];
char *oargs[128];
@@ -568,10 +571,8 @@ main (int argc, char *argv[])
/* to find out the pid of the server, we use a pipe */
if (oflags['s'] && oflags['c']) {
- if (!oflags['k']) {
- csnok++;
- pipe (csnok_pipe);
- }
+ cs++;
+ pipe (cs_pipe);
switch (pid = fork ()) {
case 0: /* child becomes the server */
@@ -580,8 +581,7 @@ main (int argc, char *argv[])
oflags['N'] = 0;
oflags['I'] = 0;
- if (csnok)
- close (csnok_pipe[0]);
+ close (cs_pipe[0]);
break;
case -1:
fatal_moan ("fork failed");
@@ -604,16 +604,18 @@ main (int argc, char *argv[])
/* if there was no k argument we need to find the */
/* pid of the server process so that we can work out */
/* what the socket is called. The server tells us on */
- /* a pipe */
+ /* a pipe. We do this even if k is specified to avoid */
+ /* a race, the server writes to the pipe when the socket */
+ /* is opened */
- if (csnok) {
- close (csnok_pipe[1]);
+ close (cs_pipe[1]);
- if (read (csnok_pipe[0], &pid, sizeof (pid)) != sizeof (pid))
- fatal_moan ("Failed to receive pid of server process");
+ if (read (cs_pipe[0], &pid, sizeof (pid)) != sizeof (pid))
+ fatal_moan ("Failed to receive pid of server process");
- close (csnok_pipe[0]);
+ close (cs_pipe[0]);
+ if (!oflags['k']) {
oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid);
oflags['k']++;
}
@@ -680,11 +682,12 @@ main (int argc, char *argv[])
server_socket = socket_listen (oargs['k']);
/* Tell our parent's parent what our pid is */
- if (csnok) {
+ /* and that we've opened the server socket */
+ if (cs) {
pid = getpid ();
- write (csnok_pipe[1], &pid, sizeof (pid));
- close (csnok_pipe[1]);
+ write (cs_pipe[1], &pid, sizeof (pid));
+ close (cs_pipe[1]);
}
if (!server_socket)
@@ -792,7 +795,6 @@ main (int argc, char *argv[])
fatal_moan ("-I requires an arugment");
send_to_server (client_socket, oargs['I']);
} else {
-
if (client_socket)
ipc_msg_send_initialize (client_socket);
@@ -807,13 +809,20 @@ main (int argc, char *argv[])
ansi =
ansi_new_from_terminal (terminal_open (0, 1), oflags['u'] ? 0 : 1);
ansi->reset (ansi, NULL);
- if (ansi->set_title)
+
+ }
+
+ if (ansi->set_title) {
+ if (oflags['c'] && oargs['k']) {
ansi->set_title (ansi, oargs['k']);
+ } else if ((ctx->t) && (ctx->t->name)) {
+ ansi->set_title (ansi, ctx->t->name);
+ }
}
+
}
}
-
ctx->v = vt102_new (&size);
ctx->h = history_new (history);