From be42afab1c325fae5c3c270876a3447220adcca5 Mon Sep 17 00:00:00 2001 From: james <> Date: Fri, 7 Mar 2008 13:16:02 +0000 Subject: *** empty log message *** --- apps/clients.c | 165 +++++++----- apps/clients.h | 10 +- apps/mainloop.c | 408 ++++++++++++++---------------- apps/mainloop.h | 9 +- apps/sympathy.c | 749 +++++++++++++++++++++++++------------------------------ apps/usage.c | 7 +- src/Makefile.am | 5 +- src/ansi.c | 9 +- src/cmd.c | 5 +- src/history.c | 7 +- src/html.c | 5 +- src/ipc.c | 59 ++--- src/ipc.h | 36 ++- src/keydis.c | 7 +- src/lockfile.c | 15 +- src/log.c | 7 +- src/prototypes.h | 320 ++++++++++++------------ src/ptty.c | 5 +- src/raw.c | 5 +- src/ring.c | 7 +- src/rotate.c | 7 +- src/serial.c | 5 +- src/slide.c | 12 +- src/symsocket.c | 21 +- src/terminal.c | 5 +- src/tty.c | 5 +- src/utf8.c | 5 +- src/util.c | 29 +++ src/vt102.c | 5 +- 29 files changed, 978 insertions(+), 956 deletions(-) diff --git a/apps/clients.c b/apps/clients.c index 621c21c..0dcd863 100644 --- a/apps/clients.c +++ b/apps/clients.c @@ -1,4 +1,4 @@ -/* +/* * clients.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.19 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.18 2008/03/03 18:16:16 james * *** empty log message *** * @@ -74,6 +77,61 @@ static char rcsid[] = "$Id$"; #include #include "clients.h" + +void client_initialize(Client *c,Context *ctx) +{ + send_history (ctx->h, c); + send_vt102 (ctx->v, c); + c->initialized=1; +} + +void +client_execute_message (Client *client,IPC_Msg * m, Context * c) +{ + switch (m->hdr.type) { + case IPC_MSG_TYPE_NOOP: + break; + case IPC_MSG_TYPE_DEBUG: + log_f (c->l, "", m->debug.msg); + break; + case IPC_MSG_TYPE_KEY: + vt102_send (c, m->key.key); + break; + case IPC_MSG_TYPE_SETBAUD: + tty_set_baud (c->t, m->setbaud.baud); + tty_parse_reset (c); + log_f (c->l, "", m->setbaud.baud); + break; + case IPC_MSG_TYPE_SENDBREAK: + log_f (c->l, ""); + tty_send_break (c->t); + break; + case IPC_MSG_TYPE_SETFLOW: + log_f (c->l, "", m->setflow.flow ? "on" : "off"); + tty_set_flow (c->t, m->setflow.flow); + break; + case IPC_MSG_TYPE_SETANSI: + vt102_set_ansi (c->v, m->setansi.ansi); + break; + case IPC_MSG_TYPE_HANGUP: + log_f (c->l, ""); + tty_hangup (c->t); + break; + case IPC_MSG_TYPE_SETSIZE: + vt102_resize (c, m->setsize.winsize); + break; + case IPC_MSG_TYPE_RESET: + vt102_reset (c); + break; + case IPC_MSG_TYPE_INITIALIZE: + client_initialize(client,c); + break; + default: + log_f (c->l, "", m->hdr.type); + } +} + + void client_free (Client * c) { @@ -91,8 +149,9 @@ clients_new_client (Clients * cs, Socket * s, Context * ctx) { Client *c; - c = (Client *) malloc (sizeof (Client)); + c = (Client *) xmalloc (sizeof (Client)); + c->initialized=0; c->dead = 0; c->s = s; c->next = cs->head; @@ -117,27 +176,23 @@ clients_reap (Clients * cs) Client **p, *c; - for (p = &cs->head; *p;) - { - Client *c = *p; - - if (c->dead) - { - *p = c->next; - client_free (c); - cs->n--; - } - else - { - p = &(c->next); - } + for (p = &cs->head; *p;) { + Client *c = *p; + + if (c->dead) { + *p = c->next; + client_free (c); + cs->n--; + } else { + p = &(c->next); } + } } Clients * clients_new (void) { - Clients *ret = (Clients *) malloc (sizeof (Clients)); + Clients *ret = (Clients *) xmalloc (sizeof (Clients)); ret->n = 0; ret->head = NULL; @@ -150,10 +205,9 @@ clients_pre_select (Clients * cs, fd_set * rfds, fd_set * wfds) { Client *c; - for (c = cs->head; c; c = c->next) - { - socket_pre_select (c->s, rfds, wfds); - } + for (c = cs->head; c; c = c->next) { + socket_pre_select (c->s, rfds, wfds); + } } void @@ -163,21 +217,19 @@ clients_post_select (Clients * cs, Context * ctx, fd_set * rfds, Client *c; int deaded = 0; - for (c = cs->head; c; c = c->next) - { - if (socket_post_select (c->s, rfds, wfds)) - { - c->dead++; - deaded++; - } - - if (c->s->msg) - { - socket_execute_msg (c->s, ctx); - } + for (c = cs->head; c; c = c->next) { + if (socket_post_select (c->s, rfds, wfds)) { + c->dead++; + deaded++; + } + if (c->s->msg) { + client_execute_message (c,c->s->msg,ctx); + socket_consume_msg (c->s); } + } + if (deaded) clients_reap (cs); } @@ -188,10 +240,9 @@ clients_shutdown (Clients * cs) { Client *c; - for (c = cs->head; c; c = c->next) - { - c->dead++; - } + for (c = cs->head; c; c = c->next) { + c->dead++; + } clients_reap (cs); @@ -225,12 +276,11 @@ send_status (Clients * cs, char *msg) strncpy (m->status, msg, IPC_MAX_BUF); m->status[IPC_MAX_BUF - 1] = 0; - for (c = cs->head; c; c = c->next) - { - if (!c->dead) - if (ipc_msg_send (c->s, (IPC_Msg *) m)) - c->dead++; - } + for (c = cs->head; c; c = c->next) { + if (!c->dead && c->initialized) + if (ipc_msg_send (c->s, (IPC_Msg *) m)) + c->dead++; + } return len; } @@ -254,12 +304,11 @@ send_output (Clients * cs, void *buf, int len) m->len = len; memcpy (m->term, buf, len); - for (c = cs->head; c; c = c->next) - { - if (!c->dead) - if (ipc_msg_send (c->s, (IPC_Msg *) m)) - c->dead++; - } + for (c = cs->head; c; c = c->next) { + if (!c->dead && c->initialized) + if (ipc_msg_send (c->s, (IPC_Msg *) m)) + c->dead++; + } return len; @@ -273,18 +322,16 @@ send_history (History * h, Client * c) HISTORY_INC (h, rptr); HISTORY_INC (h, rptr); - while (rptr != h->wptr) - { - History_ent *l = &h->lines[rptr]; - if (l->valid) - { + while (rptr != h->wptr) { + History_ent *l = &h->lines[rptr]; + if (l->valid) { - if (ipc_msg_send_history (c->s, l)) - c->dead++; + if (ipc_msg_send_history (c->s, l)) + c->dead++; - } - HISTORY_INC (h, rptr); } + HISTORY_INC (h, rptr); + } } void diff --git a/apps/clients.h b/apps/clients.h index 3396f5c..8a1625e 100644 --- a/apps/clients.h +++ b/apps/clients.h @@ -1,4 +1,4 @@ -/* +/* * clients.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.8 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.7 2008/03/03 06:04:42 james * *** empty log message *** * @@ -41,6 +44,7 @@ typedef struct Client_struct { struct Client_struct *next; + int initialized; Socket *s; int dead; } Client; diff --git a/apps/mainloop.c b/apps/mainloop.c index a3697f3..6eec7be 100644 --- a/apps/mainloop.c +++ b/apps/mainloop.c @@ -1,4 +1,4 @@ -/* +/* * mainloop.c: * * Copyright (c) 2008 James McKenzie , @@ -9,8 +9,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.27 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.26 2008/03/06 21:34:09 james * *** empty log message *** * @@ -172,11 +175,10 @@ get_status (TTY * t, Clients * cs) cd = (tty_status.lines & TIOCM_CD) ? 1 : 0; - if (cd != last_cd_state) - { - gettimeofday (&last_cd_edge, NULL); - last_cd_state = cd; - } + if (cd != last_cd_state) { + gettimeofday (&last_cd_edge, NULL); + last_cd_state = cd; + } gettimeofday (&now, NULL); timersub (&now, &last_cd_edge, &dif); @@ -189,45 +191,44 @@ static char * line_to_name (int l) { - switch (l) - { + switch (l) { #ifdef TIOCM_LE - case TIOCM_LE: - return "LE"; + case TIOCM_LE: + return "LE"; #endif #ifdef TIOCM_DTR - case TIOCM_DTR: - return "DTR"; + case TIOCM_DTR: + return "DTR"; #endif #ifdef TIOCM_RTS - case TIOCM_RTS: - return "RTS"; + case TIOCM_RTS: + return "RTS"; #endif #ifdef TIOCM_ST - case TIOCM_ST: - return "ST"; + case TIOCM_ST: + return "ST"; #endif #ifdef TIOCM_SR - case TIOCM_SR: - return "SR"; + case TIOCM_SR: + return "SR"; #endif #ifdef TIOCM_CTS - case TIOCM_CTS: - return "CTS"; + case TIOCM_CTS: + return "CTS"; #endif #ifdef TIOCM_CD - case TIOCM_CD: - return "CD"; + case TIOCM_CD: + return "CD"; #endif #ifdef TIOCM_RI - case TIOCM_RI: - return "RI"; + case TIOCM_RI: + return "RI"; #endif #ifdef TIOCM_DSR - case TIOCM_DSR: - return "DSR"; + case TIOCM_DSR: + return "DSR"; #endif - } + } return "??"; } @@ -249,20 +250,18 @@ log_line_changes (Context * ctx, int old, int new) while (*n) *(ptr++) = *(n++); - while (dif >= c) - { + while (dif >= c) { - if (dif & c) - { - *(ptr++) = ' '; - *(ptr++) = (new & c) ? '+' : '-'; - n = line_to_name (c); - while (*n) - *(ptr++) = *(n++); - } - - c <<= 1; + if (dif & c) { + *(ptr++) = ' '; + *(ptr++) = (new & c) ? '+' : '-'; + n = line_to_name (c); + while (*n) + *(ptr++) = *(n++); } + + c <<= 1; + } *(ptr++) = '>'; *ptr = 0; @@ -323,54 +322,45 @@ check_status (Context * c, Clients * cs) ptr = do_line (ptr, status.lines, TIOCM_RI); ptr = do_line (ptr, status.lines, TIOCM_CD); - if (status.blocked) - { - t = ", Locked"; - while (*t) - *(ptr++) = *(t++); - } - - if (status.crtscts) - { - t = ", Flow"; - while (*t) - *(ptr++) = *(t++); - } + if (status.blocked) { + t = ", Locked"; + while (*t) + *(ptr++) = *(t++); + } + + if (status.crtscts) { + t = ", Flow"; + while (*t) + *(ptr++) = *(t++); + } #if 0 - if (status.lines & TIOCM_CD) - { - ptr += - sprintf (ptr, ", On %d.%d", status.cd_edge_sec / 60, - status.cd_edge_sec % 60); - } - else - { - ptr += - sprintf (ptr, ", Off %d.%d", status.cd_edge_sec / 60, - status.cd_edge_sec % 60); - } + if (status.lines & TIOCM_CD) { + ptr += + sprintf (ptr, ", On %d.%d", status.cd_edge_sec / 60, + status.cd_edge_sec % 60); + } else { + ptr += + sprintf (ptr, ", Off %d.%d", status.cd_edge_sec / 60, + status.cd_edge_sec % 60); + } #endif ptr += sprintf (ptr, ", %d client%s", status.nclients, (status.nclients == 1) ? "" : "s"); - if (c->tp->biterrs) - { + if (c->tp->biterrs) { - ptr += - sprintf (ptr, ", %d err%s", c->tp->biterrs, - (c->tp->biterrs == 1) ? "" : "s"); + ptr += + sprintf (ptr, ", %d err%s", c->tp->biterrs, + (c->tp->biterrs == 1) ? "" : "s"); - if (c->tp->guessed_baud == -1) - { - ptr += sprintf (ptr, " try higher"); - } - else if (c->tp->guessed_baud > 0) - { - ptr += sprintf (ptr, " try %db", c->tp->guessed_baud); - } + if (c->tp->guessed_baud == -1) { + ptr += sprintf (ptr, " try higher"); + } else if (c->tp->guessed_baud > 0) { + ptr += sprintf (ptr, " try %db", c->tp->guessed_baud); } + } *ptr = 0; @@ -390,38 +380,37 @@ static int msg_from_server (ANSI * a, IPC_Msg * m, Context * c) { int err = 0; - switch (m->hdr.type) - { - - case IPC_MSG_TYPE_NOOP: - break; - case IPC_MSG_TYPE_DEBUG: -// fprintf (stderr,"%p [%d] %s\n", m, m->hdr.size , m->debug.msg ); - break; - case IPC_MSG_TYPE_HISTORY: - history_add (c->h, m->history.history.line); - break; - case IPC_MSG_TYPE_VT102: - if (sizeof (VT102) != m->vt102.len) - abort (); - - *(c->v) = m->vt102.vt102; - - if (a->one_shot) - { - a->one_shot (a, &c->v->crt); - err++; /*Simulate a fatal write error enclosing tty */ - } - break; - case IPC_MSG_TYPE_TERM: - err += tty_parse (c, m->term.term, m->term.len); - break; - case IPC_MSG_TYPE_STATUS: - cmd_new_status (c->d, c, m->status.status); - break; - default: - fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type); + switch (m->hdr.type) { + + case IPC_MSG_TYPE_NOOP: + break; + case IPC_MSG_TYPE_DEBUG: + // fprintf (stderr,"%p [%d] %s\n", m, m->hdr.size , m->debug.msg ); + break; + case IPC_MSG_TYPE_HISTORY: + history_add (c->h, m->history.history.line); + break; + case IPC_MSG_TYPE_VT102: + if (sizeof (VT102) != m->vt102.len) + crash_out("sizeof(VT102) differs in client and server"); + + *(c->v) = m->vt102.vt102; + + if (a->one_shot) { + a->one_shot (a, &c->v->crt); + err++; /* Simulate a fatal write error enclosing tty + */ } + break; + case IPC_MSG_TYPE_TERM: + err += tty_parse (c, m->term.term, m->term.len); + break; + case IPC_MSG_TYPE_STATUS: + cmd_new_status (c->d, c, m->status.status); + break; + default: + fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type); + } return err; } @@ -437,151 +426,130 @@ mainloop (Context * c, ANSI * ansi, Socket * server_socket, c->u = utf8_new (); /* are we being fed by a tty or a socket */ - if (client_socket) - { - if (server_socket) - abort (); - c->k = keydis_ipc_new (client_socket); - } - else - { - if (!c->t) - abort (); - c->k = keydis_vt102_new (); - } + if (client_socket) { + if (server_socket) + crash_out("mainloop cannot both be a server and a client"); + c->k = keydis_ipc_new (client_socket); + } else { + if (!c->t) + crash_out("mainloop must have either a client_socket or a terminal"); + c->k = keydis_vt102_new (); + } /* do we have an upstream terminal to talk to */ /* if so start a command parser */ - if (ansi) - { - c->d = cmd_new (); - } - else - { - c->d = NULL; - } + if (ansi) { + c->d = cmd_new (); + } else { + c->d = NULL; + } vt102_reset (c); - if (server_socket) - { - if (client_socket) - abort (); - clients = clients_new (); - } - else - { - clients = NULL; - } + if (server_socket) { + if (client_socket) + crash_out("mainloop cannot both be a server and a client"); + clients = clients_new (); + } else { + clients = NULL; + } - for (;;) - { - struct timeval tv = { 0, 250000 }; + for (;;) { + struct timeval tv = { 0, 250000 }; - if ((c->d) && (c->d->disconnect)) - break; + if ((c->d) && (c->d->disconnect)) + break; - /*update the status lines, locally or remotely */ - if (c->t) - check_status (c, clients); + /* update the status lines, locally or remotely */ + if (c->t) + check_status (c, clients); - FD_ZERO (&rfds); - FD_ZERO (&wfds); + FD_ZERO (&rfds); + FD_ZERO (&wfds); - if (c->t) - tty_pre_select (c->t, &rfds, &wfds); + if (c->t) + tty_pre_select (c->t, &rfds, &wfds); - if (server_socket) - { - FD_SET (server_socket->fd, &rfds); - clients_pre_select (clients, &rfds, &wfds); - } + if (server_socket) { + FD_SET (server_socket->fd, &rfds); + clients_pre_select (clients, &rfds, &wfds); + } - if (client_socket) - socket_pre_select (client_socket, &rfds, &wfds); + if (client_socket) + socket_pre_select (client_socket, &rfds, &wfds); - if (ansi && ansi->terminal) - tty_pre_select (ansi->terminal, &rfds, &wfds); + if (ansi && ansi->terminal) + tty_pre_select (ansi->terminal, &rfds, &wfds); - select (FD_SETSIZE, &rfds, &wfds, NULL, &tv); + select (FD_SETSIZE, &rfds, &wfds, NULL, &tv); - /*any message from clients, or new connexions */ - if (server_socket) + /* any message from clients, or new connexions */ + if (server_socket) { + Socket *new_client_socket; + if (FD_ISSET (server_socket->fd, &rfds) + && ((new_client_socket = socket_accept (server_socket)))) { { - Socket *new_client_socket; - if (FD_ISSET (server_socket->fd, &rfds) - && ((new_client_socket = socket_accept (server_socket)))) - { - { - Client *new_client; - /*New client connexion */ - new_client = - clients_new_client (clients, new_client_socket, c); - - send_history (c->h, new_client); - send_vt102 (c->v, new_client); - - } - } - - clients_post_select (clients, c, &rfds, &wfds); + Client *new_client; + /* New client connexion */ + new_client = clients_new_client (clients, new_client_socket, c); + + } + } - /*any data from the port */ - if (c->t && FD_ISSET (c->t->rfd, &rfds)) - { - char buf[IPC_MAX_BUF]; - int red; + clients_post_select (clients, c, &rfds, &wfds); + } - red = c->t->recv (c->t, buf, sizeof (buf)); + /* any data from the port */ + if (c->t && FD_ISSET (c->t->rfd, &rfds)) { + char buf[IPC_MAX_BUF]; + int red; - if (red < 0) - break; + red = c->t->recv (c->t, buf, sizeof (buf)); - if (red) - { - if (clients) - send_output (clients, buf, red); - if (tty_parse (c, buf, red)) - break; - } - } + if (red < 0) + break; + if (red) { + if (clients) + send_output (clients, buf, red); + if (tty_parse (c, buf, red)) + break; + } + } - /*any data from the server */ - if (client_socket) - { - int err = 0; - if (socket_post_select (client_socket, &rfds, &wfds)) - break; + /* any data from the server */ + if (client_socket) { + int err = 0; - while (client_socket->msg && !err) - { - err += msg_from_server (ansi, client_socket->msg, c); - socket_consume_msg (client_socket); - } + if (socket_post_select (client_socket, &rfds, &wfds)) + break; - if (err) - break; - } + while (client_socket->msg && !err) { + err += msg_from_server (ansi, client_socket->msg, c); + socket_consume_msg (client_socket); + } + if (err) + break; + } - /*update our local screen */ - if (ansi) - { - if (ansi->dispatch) - if (ansi->dispatch (ansi, c)) - break; - if (ansi->update) - if (ansi->update (ansi, c)) - break; - } + /* update our local screen */ + if (ansi) { + if (ansi->dispatch) + if (ansi->dispatch (ansi, c)) + break; + + if (ansi->update) + if (ansi->update (ansi, c)) + break; } + } if (clients) clients_shutdown (clients); diff --git a/apps/mainloop.h b/apps/mainloop.h index 2c7f2b9..d94d02a 100644 --- a/apps/mainloop.h +++ b/apps/mainloop.h @@ -1,4 +1,4 @@ -/* +/* * mainloop.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.10 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.9 2008/03/06 16:49:39 james * *** empty log message *** * diff --git a/apps/sympathy.c b/apps/sympathy.c index 357f1df..bb141b1 100644 --- a/apps/sympathy.c +++ b/apps/sympathy.c @@ -1,4 +1,4 @@ -/* +/* * sympathy.c: * * Copyright (c) 2008 James McKenzie , @@ -9,8 +9,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.37 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.36 2008/03/06 21:34:09 james * *** empty log message *** * @@ -182,7 +185,7 @@ sigchld (int dummy) wait3 (&status, WNOHANG, NULL); } -/*Dispell zombies, from for example log compression*/ +/* Dispell zombies, from for example log compression */ void garlic (void) { @@ -204,26 +207,25 @@ teedious_snprintf (char *fmt, va_list ap) if (!buf) fatal_moan ("malloc failed"); - while (1) - { + while (1) { - va_copy (aq, ap); - n = vsnprintf (buf, size, fmt, aq); - va_end (aq); + va_copy (aq, ap); + n = vsnprintf (buf, size, fmt, aq); + va_end (aq); - if (n > -1 && n < (size)) - return buf; + if (n > -1 && n < (size)) + return buf; - if (n > -1) /* glibc 2.1 */ - size = n + 1; - else /* glibc 2.0 */ - size *= 2; /* twice the old size */ + if (n > -1) /* glibc 2.1 */ + size = n + 1; + else /* glibc 2.0 */ + size *= 2; /* twice the old size */ - buf = realloc (buf, size); + buf = realloc (buf, size); - if (!buf) - fatal_moan ("malloc failed"); - } + if (!buf) + fatal_moan ("malloc failed"); + } } @@ -236,7 +238,7 @@ gloo_paths (char *dir, char *leaf) dir = ""; if (!leaf) leaf = ""; - ret = ptr = malloc (strlen (dir) + strlen (leaf) + 2); + ret = ptr = xmalloc (strlen (dir) + strlen (leaf) + 2); while (*dir) *(ptr++) = *(dir++); @@ -249,7 +251,7 @@ gloo_paths (char *dir, char *leaf) } -/*make the path in fmt from home (hence the name) */ +/* make the path in fmt from home (hence the name) */ char * mome (char *fmt, ...) { @@ -261,16 +263,13 @@ mome (char *fmt, ...) if (!home) return NULL; - if (fmt) - { - va_start (ap, fmt); - leaf = teedious_snprintf (fmt, ap); - va_end (ap); - } - else - { - leaf = NULL; - } + if (fmt) { + va_start (ap, fmt); + leaf = teedious_snprintf (fmt, ap); + va_end (ap); + } else { + leaf = NULL; + } ret = gloo_paths (home, leaf); if (leaf) @@ -289,56 +288,45 @@ find_socket (char **retpath, char *fmt, ...) va_list ap; - if (fmt) - { - va_start (ap, fmt); - leaf = teedious_snprintf (fmt, ap); - va_end (ap); - } - else - { - leaf = NULL; - } - + if (fmt) { + va_start (ap, fmt); + leaf = teedious_snprintf (fmt, ap); + va_end (ap); + } else { + leaf = NULL; + } - for (ptr = socket_dirs; *ptr; ptr++) - { - if (**ptr == '~') - { - h = mome (*ptr + 1); - } - else - { - h = *ptr; - } - if (!h) - continue; + for (ptr = socket_dirs; *ptr; ptr++) { + if (**ptr == '~') { + h = mome (*ptr + 1); + } else { + h = *ptr; + } + if (!h) + continue; - path = gloo_paths (h, leaf); - if (**ptr == '~') - free (h); - ret = socket_connect (path); + path = gloo_paths (h, leaf); + if (**ptr == '~') + free (h); + ret = socket_connect (path); - if (ret) - { - if (retpath) - { - *retpath = path; - } - else - { - free (path); - } - free (leaf); - return ret; - } - free (path); + if (ret) { + if (retpath) { + *retpath = path; + } else { + free (path); + } + free (leaf); + return ret; } + free (path); + + } free (leaf); return NULL; @@ -366,38 +354,30 @@ list_sockets_in_dir (char *sockdir) rewinddir (dir); - while ((ent = readdir (dir))) - { - sn = gloo_paths (sockdir, ent->d_name); - if (stat (sn, &buf) || (!S_ISSOCK (buf.st_mode))) - { - free (sn); - continue; - } - - s = socket_connect (sn); - - if (s) - { - printf ("\t%s (Active)\n", sn); - socket_free (s); - } - else - { - if (strncmp (ent->d_name, hostname, hostname_len)) - { - printf ("\t%s (Unknown - not this host)\n", sn); - } - else - { - printf ("\t%s (Dead, wiped)\n", sn); - unlink (sn); - } - } - + while ((ent = readdir (dir))) { + sn = gloo_paths (sockdir, ent->d_name); + if (stat (sn, &buf) || (!S_ISSOCK (buf.st_mode))) { free (sn); + continue; } + s = socket_connect (sn); + + if (s) { + printf ("\t%s (Active)\n", sn); + socket_free (s); + } else { + if (strncmp (ent->d_name, hostname, hostname_len)) { + printf ("\t%s (Unknown - not this host)\n", sn); + } else { + printf ("\t%s (Dead, wiped)\n", sn); + unlink (sn); + } + } + + free (sn); + } + closedir (dir); return 0; @@ -409,26 +389,22 @@ list_sockets (void) char **ptr, *h; - for (ptr = socket_dirs; *ptr; ptr++) - { - if (**ptr == '~') - { - h = mome (*ptr + 1); - } - else - { - h = *ptr; - } + for (ptr = socket_dirs; *ptr; ptr++) { + if (**ptr == '~') { + h = mome (*ptr + 1); + } else { + h = *ptr; + } - if (!h) - continue; + if (!h) + continue; - list_sockets_in_dir (h); + list_sockets_in_dir (h); - if (**ptr == '~') - free (h); + if (**ptr == '~') + free (h); - } + } return 0; } @@ -439,11 +415,10 @@ get_hostname (void) { struct utsname name; - if (uname (&name)) - { - strcpy (hostname, "unknown."); - return; - } + if (uname (&name)) { + strcpy (hostname, "unknown."); + return; + } strcpy (hostname, name.nodename); @@ -479,35 +454,28 @@ main (int argc, char *argv[]) memset (oflags, 0, sizeof (oflags)); memset (oargs, 0, sizeof (oargs)); - while ((c = getopt (argc, argv, "I:NRP:vw:utscr:lKHd:pb:fL:Fk:n:")) != EOF) - { - switch (c) - { - case ':': - case 'h': - case '?': - usage (); - default: - if ((c > 64) && (c < 91)) - { - oflags[c]++; - oargs[c] = optarg; - } - else if ((c > 96) && (c < 123)) - { - oflags[c]++; - oargs[c] = optarg; - } - else - { - fprintf (stderr, "unknown option %c\n", c); - usage (); - } - } - + while ((c = getopt (argc, argv, "I:NRP:vw:utscr:lKHd:pb:fL:Fk:n:")) != EOF) { + switch (c) { + case ':': + case 'h': + case '?': + usage (); + default: + if ((c > 64) && (c < 91)) { + oflags[c]++; + oargs[c] = optarg; + } else if ((c > 96) && (c < 123)) { + oflags[c]++; + oargs[c] = optarg; + } else { + fprintf (stderr, "unknown option %c\n", c); + usage (); + } } - /*Compatability for screen's ls */ + } + + /* Compatability for screen's ls */ if (oflags['l']) oflags['s'] = 0; @@ -520,25 +488,23 @@ main (int argc, char *argv[]) sum += oflags['l']; sum += oflags['v']; - if (!sum) - { - /*If no mode is specified behave like screen */ - oflags['s']++; - oflags['c']++; - sum++; - } + if (!sum) { + /* If no mode is specified behave like screen */ + oflags['s']++; + oflags['c']++; + sum++; + } if (sum != 1) fatal_moan ("specifiy exactly one of ( -c and or -s ), -t, -r, -l and -v"); } - if (oflags['v']) - { - fprintf (stderr, "Version: %s\n", libsympathy_version ()); - fprintf (stderr, "Version: %s\n", rcsid); - return 0; - } + if (oflags['v']) { + fprintf (stderr, "Version: %s\n", libsympathy_version ()); + fprintf (stderr, "Version: %s\n", rcsid); + return 0; + } if (oflags['l']) return list_sockets (); @@ -548,17 +514,16 @@ main (int argc, char *argv[]) fatal_moan ("-k is incompatible with -r"); - if (oflags['n']) - { - history = safe_atoi (oargs['n']); - if (history < 0) - fatal_moan ("cannot parse -n %s as an integer", oargs['n']); + if (oflags['n']) { + history = safe_atoi (oargs['n']); + if (history < 0) + fatal_moan ("cannot parse -n %s as an integer", oargs['n']); - if (!history) - fatal_moan ("agrument to -n must be greater than zero"); - } + if (!history) + fatal_moan ("agrument to -n must be greater than zero"); + } - /*Fold -r implies -c */ + /* Fold -r implies -c */ if (oflags['r']) oflags['c']++; @@ -572,68 +537,64 @@ main (int argc, char *argv[]) if (oflags['H'] && oflags['N']) fatal_moan ("-H is incompatible with -N"); - /*implement server and client: this process forks. The parent */ - /*becomes the client and the child forks again to become the */ - /*server. If there's no -k argument the client (parent) needs */ - /*to find out the pid of the server, we use a pipe */ - - if (oflags['s'] && oflags['c']) - { - if (!oflags['k']) - { - csnok++; - pipe (csnok_pipe); - } - - switch (pid = fork ()) - { - case 0: /*child becomes the server */ - oflags['c'] = 0; - oflags['H'] = 0; - oflags['N'] = 0; - oflags['I'] = 0; - - if (csnok) - close (csnok_pipe[0]); - break; - case -1: - fatal_moan ("fork failed"); - default: /*parent becomes client */ - oflags['s'] = 0; - oflags['K'] = 0; - oflags['d'] = 0; - oflags['p'] = 0; - oflags['b'] = 0; - oflags['f'] = 0; - oflags['L'] = 0; - oflags['R'] = 0; - oflags['P'] = 0; - oflags['n'] = 0; - oflags['w'] = 0; - - /*Collect the child */ - waitpid (pid, NULL, 0); - - /*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 */ - - if (csnok) - { - close (csnok_pipe[1]); - - if (read (csnok_pipe[0], &pid, sizeof (pid)) != sizeof (pid)) - fatal_moan ("Failed to receive pid of server process"); - - close (csnok_pipe[0]); - - oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid); - oflags['k']++; - } - } + /* implement server and client: this process forks. The parent */ + /* becomes the client and the child forks again to become the */ + /* server. If there's no -k argument the client (parent) needs */ + /* to find out the pid of the server, we use a pipe */ + + if (oflags['s'] && oflags['c']) { + if (!oflags['k']) { + csnok++; + pipe (csnok_pipe); } + switch (pid = fork ()) { + case 0: /* child becomes the server */ + oflags['c'] = 0; + oflags['H'] = 0; + oflags['N'] = 0; + oflags['I'] = 0; + + if (csnok) + close (csnok_pipe[0]); + break; + case -1: + fatal_moan ("fork failed"); + default: /* parent becomes client */ + oflags['s'] = 0; + oflags['K'] = 0; + oflags['d'] = 0; + oflags['p'] = 0; + oflags['b'] = 0; + oflags['f'] = 0; + oflags['L'] = 0; + oflags['R'] = 0; + oflags['P'] = 0; + oflags['n'] = 0; + oflags['w'] = 0; + + /* Collect the child */ + waitpid (pid, NULL, 0); + + /* 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 */ + + if (csnok) { + close (csnok_pipe[1]); + + if (read (csnok_pipe[0], &pid, sizeof (pid)) != sizeof (pid)) + fatal_moan ("Failed to receive pid of server process"); + + close (csnok_pipe[0]); + + oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid); + oflags['k']++; + } + } + } + if (oflags['c'] && !oflags['k'] && !oflags['r']) fatal_moan ("-c requires a socket to be specified with -s or -k or -r"); @@ -646,223 +607,193 @@ main (int argc, char *argv[]) fatal_moan ("-c or -r are incompatible with -p, -d, -K, -b, -f, -R, -P or -L"); - if (oflags['t'] || oflags['s']) - { - if (!oflags['p'] && !oflags['d']) - oflags['p']++; + if (oflags['t'] || oflags['s']) { + if (!oflags['p'] && !oflags['d']) + oflags['p']++; + } + + if (oflags['w']) { + char buf[128], *ptr; + strcpy (buf, oargs['w']); + ptr = index (buf, 'x'); + if (ptr) { + *ptr = 0; + ptr++; + size.y = safe_atoi (ptr); } + size.x = safe_atoi (buf); - if (oflags['w']) - { - char buf[128], *ptr; - strcpy (buf, oargs['w']); - ptr = index (buf, 'x'); - if (ptr) - { - *ptr = 0; - ptr++; - size.y = safe_atoi (ptr); - } - size.x = safe_atoi (buf); - - if ((size.x > VT102_MAX_COLS) || (size.x < 1)) - fatal_moan ("-w requires a width between 1 and %d\n", VT102_MAX_COLS); - - if ((size.y > VT102_MAX_ROWS) || (size.y < 1)) - fatal_moan ("-w requires a height between 1 and %d\n", - VT102_MAX_ROWS); + if ((size.x > VT102_MAX_COLS) || (size.x < 1)) + fatal_moan ("-w requires a width between 1 and %d\n", VT102_MAX_COLS); - } + if ((size.y > VT102_MAX_ROWS) || (size.y < 1)) + fatal_moan ("-w requires a height between 1 and %d\n", VT102_MAX_ROWS); - if (oflags['s'] && !oflags['F']) - { - /*nochdir incase socket is relative path, unlink then will fail */ - daemon (1, 0); + } - } + if (oflags['s'] && !oflags['F']) { + /* nochdir incase socket is relative path, unlink then will fail */ + daemon (1, 0); + + } - if (oflags['s']) - { - char *path; - path = mome ("/.sympathy"); - mkdir (path, 0700); - free (path); + if (oflags['s']) { + char *path; + path = mome ("/.sympathy"); + mkdir (path, 0700); + free (path); - if (!oflags['k']) - { - pid = getpid (); + if (!oflags['k']) { + pid = getpid (); - oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid); - oflags['k']++; - } + oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid); + oflags['k']++; + } - server_socket = socket_listen (oargs['k']); + server_socket = socket_listen (oargs['k']); - /*Tell our parent's parent what our pid is */ - if (csnok) - { - pid = getpid (); + /* Tell our parent's parent what our pid is */ + if (csnok) { + pid = getpid (); + + write (csnok_pipe[1], &pid, sizeof (pid)); + close (csnok_pipe[1]); + } - write (csnok_pipe[1], &pid, sizeof (pid)); - close (csnok_pipe[1]); - } + if (!server_socket) + fatal_moan ("failed to create socket %s for listening", oargs['k']); - if (!server_socket) - fatal_moan ("failed to create socket %s for listening", oargs['k']); + } + if (oflags['s'] || oflags['t']) { + if (oflags['P']) { + FILE *fp; + pid_file = oargs['P']; + fp = fopen (pid_file, "w"); + if (fp) { + fprintf (fp, "%d", getpid ()); + fclose (fp); + } } - if (oflags['s'] || oflags['t']) - { - if (oflags['P']) - { - FILE *fp; - pid_file = oargs['P']; - fp = fopen (pid_file, "w"); - if (fp) - { - fprintf (fp, "%d", getpid ()); - fclose (fp); - } - } - - if (oflags['L']) - { - ctx->l = file_log_new (oargs['L'], oflags['R']); - if (!ctx->l) - fatal_moan ("unable to access log file %s", oargs['L']); - } - - if (oflags['p']) - { - ctx->t = ptty_open (NULL, NULL, &size); - if (!ctx->t) - fatal_moan ("unable to open a ptty"); - } - else - { - /*HACK-- check that console=device does not occur in */ - /*/proc/cmdline */ - if (!oargs['d']) - fatal_moan ("no argument to -d"); - - { - char kernel_cmdline[4096] = { 0 }; - char search_string[1024] = "console="; - char *ptr = oargs['d']; - int fd; - - if (!strncmp ("/dev/", ptr, 5)) - ptr += 5; - - strcat (search_string, ptr); - - fd = open ("/proc/cmdline", O_RDONLY); - read (fd, kernel_cmdline, sizeof (kernel_cmdline)); - close (fd); - - kernel_cmdline[sizeof (kernel_cmdline) - 1] = 0; - - if (strstr (kernel_cmdline, search_string)) - fatal_moan ("/proc/cmdline contains %s", search_string); - } - - ctx->t = - serial_open (oargs['d'], - oflags['K'] ? SERIAL_LOCK_ACTIVE : - SERIAL_LOCK_PASSIVE); - if (!ctx->t) - fatal_moan ("unable to open serial port %s", oargs['d']); - } - - if (oflags['b']) - { - int baud = safe_atoi (oargs['b']); - - if (baud < 0) - fatal_moan ("Unable to parse baudrate %s", oargs['b']); - - tty_set_baud (ctx->t, baud); - - } - - tty_set_flow (ctx->t, oflags['f'] ? 1 : 0); + if (oflags['L']) { + ctx->l = file_log_new (oargs['L'], oflags['R']); + if (!ctx->l) + fatal_moan ("unable to access log file %s", oargs['L']); } + if (oflags['p']) { + ctx->t = ptty_open (NULL, NULL, &size); + if (!ctx->t) + fatal_moan ("unable to open a ptty"); + } else { + /* HACK-- check that console=device does not occur in */ + /* /proc/cmdline */ + if (!oargs['d']) + fatal_moan ("no argument to -d"); - if (oflags['r']) - { - char *id = oargs['r']; + { + char kernel_cmdline[4096] = { 0 }; + char search_string[1024] = "console="; + char *ptr = oargs['d']; + int fd; + + if (!strncmp ("/dev/", ptr, 5)) + ptr += 5; - if (!id) - fatal_moan ("-r requires an argument"); + strcat (search_string, ptr); - if (safe_atoi (id) > 0) - { - client_socket = - find_socket (&oargs['k'], "%s%d", hostname, safe_atoi (id)); - } - else - { - client_socket = find_socket (&oargs['k'], "%s", id); - } + fd = open ("/proc/cmdline", O_RDONLY); + read (fd, kernel_cmdline, sizeof (kernel_cmdline)); + close (fd); - if (!client_socket) - fatal_moan ("failed to find socket %s", oargs['r']); + kernel_cmdline[sizeof (kernel_cmdline) - 1] = 0; + + if (strstr (kernel_cmdline, search_string)) + fatal_moan ("/proc/cmdline contains %s", search_string); + } + + ctx->t = + serial_open (oargs['d'], + oflags['K'] ? SERIAL_LOCK_ACTIVE : SERIAL_LOCK_PASSIVE); + if (!ctx->t) + fatal_moan ("unable to open serial port %s", oargs['d']); + } + + if (oflags['b']) { + int baud = safe_atoi (oargs['b']); + + if (baud < 0) + fatal_moan ("Unable to parse baudrate %s", oargs['b']); + + tty_set_baud (ctx->t, baud); } - else if (oflags['c']) - { - client_socket = socket_connect (oargs['k']); - if (!client_socket) - fatal_moan ("failed to connect to socket %s", oargs['k']); + tty_set_flow (ctx->t, oflags['f'] ? 1 : 0); + } + + + if (oflags['r']) { + char *id = oargs['r']; + if (!id) + fatal_moan ("-r requires an argument"); + + if (safe_atoi (id) > 0) { + client_socket = + find_socket (&oargs['k'], "%s%d", hostname, safe_atoi (id)); + } else { + client_socket = find_socket (&oargs['k'], "%s", id); } + if (!client_socket) + fatal_moan ("failed to find socket %s", oargs['r']); + + } else if (oflags['c']) { + client_socket = socket_connect (oargs['k']); + + if (!client_socket) + fatal_moan ("failed to connect to socket %s", oargs['k']); + + } - if (oflags['c'] || oflags['t']) - { - if (oflags['N']) - { - ctx->r = rx_new_raw (0, 1); - ansi = ansi_new_raw (0, 1); - } - else if (oflags['H']) - { - ansi = ansi_new_html (stdout); - } - else - { - terminal_register_handlers (); - ansi = - ansi_new_from_terminal (terminal_open (0, 1), - oflags['u'] ? 0 : 1); - ansi->reset (ansi, NULL); - if (ansi->set_title) - ansi->set_title (ansi, oargs['k']); - } - if (oflags['I']) - { - //FIXME ... - } + if (oflags['I']) { + // FIXME ... + + } else { + if (client_socket) + ipc_msg_send_initialize(client_socket); + + if (oflags['c'] || oflags['t']) { + if (oflags['N']) { + ctx->r = rx_new_raw (0, 1); + ansi = ansi_new_raw (0, 1); + } else if (oflags['H']) { + ansi = ansi_new_html (stdout); + } else { + terminal_register_handlers (); + ansi = + ansi_new_from_terminal (terminal_open (0, 1), oflags['u'] ? 0 : 1); + ansi->reset (ansi, NULL); + if (ansi->set_title) + ansi->set_title (ansi, oargs['k']); } + } ctx->v = vt102_new (&size); ctx->h = history_new (history); mainloop (ctx, ansi, server_socket, client_socket); + } -// mainloop (tty, server_socket, client_socket, ansi, log, history, &size); - - if (ansi) - { - ansi->close (ansi); - terminal_atexit (); - } + if (ansi) { + ansi->close (ansi); + terminal_atexit (); + } if (ctx->t) ctx->t->close (ctx->t); diff --git a/apps/usage.c b/apps/usage.c index abad505..cbf3a09 100644 --- a/apps/usage.c +++ b/apps/usage.c @@ -1,4 +1,4 @@ -/* +/* * usage.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.22 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.21 2008/03/06 21:34:09 james * *** empty log message *** * diff --git a/src/Makefile.am b/src/Makefile.am index 6cdefe7..4e4daa7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,9 @@ # $Id$ # # $Log$ +# Revision 1.24 2008/03/07 13:16:02 james +# *** empty log message *** +# # Revision 1.23 2008/03/06 16:49:05 james # *** empty log message *** # @@ -133,7 +136,7 @@ VCHK=${shell cat ${VFS} | @MD5SUM@ | @AWK@ '{print $$1 }' } VNUM=${shell @GREP@ ${VCHK} ${VFD}/version-md5sums | @AWK@ '{ print $$2 }' } VDEF=${shell echo `cat ${VFD}/version-major`.`cat ${VFD}/version-minor`.`cat ${VFD}/version-micro` } -protos: +protos: sympathy.h echo > prototypes.h ${CPROTO} -e -v ${INCLUDES} ${SRCS} > prototypes.tmp mv -f prototypes.tmp prototypes.h diff --git a/src/ansi.c b/src/ansi.c index a70a51d..593b367 100644 --- a/src/ansi.c +++ b/src/ansi.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.50 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.49 2008/03/07 12:37:04 james * *** empty log message *** * @@ -515,9 +518,7 @@ ansi_resize_check (ANSI * a, CRT_Pos * size) if (size) a->crt.size = *size; - // FIXME: -- echos back crap? - // a->terminal->xmit (a->terminal, "\033[c", 3); - + // a->terminal->xmit (a->terminal, "\033c", 3); // maybe - issue 132 column command if we're 132? ansi_cls (a); @@ -947,7 +948,7 @@ ansi_new_from_terminal (TTY * t, int utf8) { ANSI *ret; - ret = malloc (sizeof (ANSI)); + ret = xmalloc (sizeof (ANSI)); memset (ret, 0, sizeof (ANSI)); ret->terminal = t; diff --git a/src/cmd.c b/src/cmd.c index 3f98331..c898973 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.13 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.12 2008/03/07 12:37:04 james * *** empty log message *** * @@ -178,7 +181,7 @@ cmd_new (void) { Cmd *ret; - ret = (Cmd *) malloc (sizeof (Cmd)); + ret = (Cmd *) xmalloc (sizeof (Cmd)); ret->disconnect = 0; ret->active = 0; diff --git a/src/history.c b/src/history.c index 6ba2719..d80a1b6 100644 --- a/src/history.c +++ b/src/history.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.7 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.6 2008/03/07 12:37:04 james * *** empty log message *** * @@ -37,8 +40,8 @@ history_new (int n) { History *ret; - ret = (History *) malloc (sizeof (History)); - ret->lines = malloc (n * sizeof (History_ent)); + ret = (History *) xmalloc (sizeof (History)); + ret->lines = xmalloc (n * sizeof (History_ent)); memset (ret->lines, 0, n * sizeof (History_ent)); ret->wptr = 0; diff --git a/src/html.c b/src/html.c index dc5e3f8..53af2fe 100644 --- a/src/html.c +++ b/src/html.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.15 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.14 2008/03/07 12:37:04 james * *** empty log message *** * @@ -205,7 +208,7 @@ ansi_new_html (FILE * f) { ANSI *ret; - ret = malloc (sizeof (ANSI)); + ret = xmalloc (sizeof (ANSI)); memset (ret, 0, sizeof (ANSI)); ret->file = f; diff --git a/src/ipc.c b/src/ipc.c index a45d5e6..328580b 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.10 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.9 2008/03/07 12:37:04 james * *** empty log message *** * @@ -51,7 +54,7 @@ ipc_check_for_message_in_slide (Slide * s) if (SLIDE_BYTES (s) < m->hdr.size) return NULL; if (m->hdr.size < sizeof (IPC_Msg_hdr)) - abort (); + crash_out ("ipc_check_for_message_in_slide test failed"); return m; } @@ -61,7 +64,7 @@ ipc_consume_message_in_slide (Slide * s) { IPC_Msg *m = ipc_check_for_message_in_slide (s); if (!m) - abort (); + crash_out ("ipc_consume_message_in_slide test failed"); slide_consume (s, m->hdr.size); } @@ -94,6 +97,16 @@ ipc_msg_send_debug (Socket * s, char *msg) return ipc_msg_send (s, (IPC_Msg *) m); } +int +ipc_msg_send_initialize (Socket * s) +{ + IPC_Msg_initialize m; + + m.size = sizeof (m); + m.type = IPC_MSG_TYPE_INITIALIZE; + return ipc_msg_send (s, (IPC_Msg *) & m); +} + int ipc_msg_send_history (Socket * s, History_ent * l) { @@ -253,45 +266,3 @@ ipc_msg_send_reset (Socket * s) return ipc_msg_send (s, (IPC_Msg *) & m); } -void -ipc_execute_message (IPC_Msg * m, Context * c) -{ - switch (m->hdr.type) { - case IPC_MSG_TYPE_NOOP: - break; - case IPC_MSG_TYPE_DEBUG: - log_f (c->l, "", m->debug.msg); - break; - case IPC_MSG_TYPE_KEY: - vt102_send (c, m->key.key); - break; - case IPC_MSG_TYPE_SETBAUD: - tty_set_baud (c->t, m->setbaud.baud); - tty_parse_reset (c); - log_f (c->l, "", m->setbaud.baud); - break; - case IPC_MSG_TYPE_SENDBREAK: - log_f (c->l, ""); - tty_send_break (c->t); - break; - case IPC_MSG_TYPE_SETFLOW: - log_f (c->l, "", m->setflow.flow ? "on" : "off"); - tty_set_flow (c->t, m->setflow.flow); - break; - case IPC_MSG_TYPE_SETANSI: - vt102_set_ansi (c->v, m->setansi.ansi); - break; - case IPC_MSG_TYPE_HANGUP: - log_f (c->l, ""); - tty_hangup (c->t); - break; - case IPC_MSG_TYPE_SETSIZE: - vt102_resize (c, m->setsize.winsize); - break; - case IPC_MSG_TYPE_RESET: - vt102_reset (c); - break; - default: - log_f (c->l, "", m->hdr.type); - } -} diff --git a/src/ipc.h b/src/ipc.h index 46766a5..d36dcfd 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.10 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.9 2008/03/07 12:37:04 james * *** empty log message *** * @@ -48,18 +51,19 @@ #define IPC_MSG_TYPE_NOOP 0 #define IPC_MSG_TYPE_DEBUG 1 -#define IPC_MSG_TYPE_VT102 2 -#define IPC_MSG_TYPE_HISTORY 3 -#define IPC_MSG_TYPE_KEY 4 -#define IPC_MSG_TYPE_TERM 5 -#define IPC_MSG_TYPE_STATUS 6 -#define IPC_MSG_TYPE_SETBAUD 7 -#define IPC_MSG_TYPE_SENDBREAK 8 -#define IPC_MSG_TYPE_SETFLOW 9 -#define IPC_MSG_TYPE_SETANSI 10 -#define IPC_MSG_TYPE_HANGUP 11 -#define IPC_MSG_TYPE_SETSIZE 12 -#define IPC_MSG_TYPE_RESET 13 +#define IPC_MSG_TYPE_INITIALIZE 2 +#define IPC_MSG_TYPE_VT102 3 +#define IPC_MSG_TYPE_HISTORY 4 +#define IPC_MSG_TYPE_KEY 5 +#define IPC_MSG_TYPE_TERM 6 +#define IPC_MSG_TYPE_STATUS 7 +#define IPC_MSG_TYPE_SETBAUD 8 +#define IPC_MSG_TYPE_SENDBREAK 9 +#define IPC_MSG_TYPE_SETFLOW 10 +#define IPC_MSG_TYPE_SETANSI 11 +#define IPC_MSG_TYPE_HANGUP 12 +#define IPC_MSG_TYPE_SETSIZE 13 +#define IPC_MSG_TYPE_RESET 14 typedef struct { @@ -83,6 +87,13 @@ typedef struct char msg[0]; } IPC_Msg_debug; +typedef struct +{ + int32_t size; + int32_t type; + char msg[0]; +} IPC_Msg_initialize; + typedef struct { int32_t size; @@ -181,6 +192,7 @@ typedef union IPC_Msg_hdr hdr; IPC_Msg_noop noop; IPC_Msg_debug debug; + IPC_Msg_initialize initialize; IPC_Msg_history history; IPC_Msg_VT102 vt102; IPC_Msg_key key; diff --git a/src/keydis.c b/src/keydis.c index 8d88d46..75c6d98 100644 --- a/src/keydis.c +++ b/src/keydis.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.15 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.14 2008/03/07 12:37:04 james * *** empty log message *** * @@ -261,7 +264,7 @@ keydis_vt102_reset (KeyDis * _t, Context * c) KeyDis * keydis_vt102_new (void) { - KeyDis_VT102 *t = malloc (sizeof (KeyDis_VT102)); + KeyDis_VT102 *t = xmalloc (sizeof (KeyDis_VT102)); t->key = keydis_vt102_key; t->close = keydis_close; t->set_baud = keydis_vt102_set_baud; @@ -278,7 +281,7 @@ keydis_vt102_new (void) KeyDis * keydis_ipc_new (Socket * s) { - KeyDis_IPC *t = malloc (sizeof (KeyDis_IPC)); + KeyDis_IPC *t = xmalloc (sizeof (KeyDis_IPC)); t->key = keydis_ipc_key; t->close = keydis_close; t->set_baud = keydis_ipc_set_baud; diff --git a/src/lockfile.c b/src/lockfile.c index 31343cc..72e7960 100644 --- a/src/lockfile.c +++ b/src/lockfile.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.14 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.13 2008/03/07 12:37:04 james * *** empty log message *** * @@ -74,10 +77,12 @@ static char rcsid[] = #include "lockfile.h" +extern void *xmalloc(size_t); + Filelist * filelist_new (void) { - Filelist *fl = (Filelist *) malloc (sizeof (Filelist)); + Filelist *fl = (Filelist *) xmalloc (sizeof (Filelist)); fl->head = NULL; @@ -115,7 +120,7 @@ filelist_add (Filelist * fl, char *fn) if (!strcmp (fle->name, fn)) return; - fle = malloc (sizeof (Filelist_ent)); + fle = xmalloc (sizeof (Filelist_ent)); strcpy (fle->name, fn); @@ -342,6 +347,7 @@ lockfile_make_list (char *device) ret = filelist_new (); + if (ret) { lockfile_add_name_from_dev (ret, dev_stat.st_rdev); lockfile_add_name_from_path (ret, device); @@ -349,6 +355,7 @@ lockfile_make_list (char *device) lockfile_check_dir_for_dev (ret, "/dev/", dev_stat.st_rdev); lockfile_check_dir_for_dev (ret, "/dev/usb/", dev_stat.st_rdev); lockfile_check_dir_for_dev (ret, "/dev/tts/", dev_stat.st_rdev); + } return ret; } @@ -420,6 +427,7 @@ lockfile_lock (Filelist * fl) ret = filelist_new (); + if (ret) { lockfile_remove_stale (fl); for (fle = fl->head; fle; fle = fle->next) { @@ -430,6 +438,7 @@ lockfile_lock (Filelist * fl) } filelist_add (ret, fle->name); } + } return ret; } @@ -505,7 +514,7 @@ serial_lock_new (char *dev, int mode) if (!fl) return NULL; - l = (Serial_lock *) malloc (sizeof (Serial_lock)); + l = (Serial_lock *) xmalloc (sizeof (Serial_lock)); l->mode = mode; l->locks_to_check = fl; diff --git a/src/log.c b/src/log.c index 2f41951..c117779 100644 --- a/src/log.c +++ b/src/log.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.11 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.10 2008/03/07 12:37:04 james * *** empty log message *** * @@ -119,7 +122,7 @@ file_log_new (char *fn, int rotate) dc = 0; } - l = malloc (sizeof (File_Log)); + l = xmalloc (sizeof (File_Log)); l->log = flog_log; l->close = flog_close; @@ -168,7 +171,7 @@ log_f (Log * log, char *fmt, ...) else /* glibc 2.0 */ size *= 2; /* twice the old size */ - buf = realloc (buf, size); + buf = xrealloc (buf, size); if (!buf) return; diff --git a/src/prototypes.h b/src/prototypes.h index dd7cdfe..6fd6a7a 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -1,181 +1,183 @@ /* ansi.c */ -extern ANSI *ansi_new_from_terminal (TTY * t, int utf8); +extern ANSI *ansi_new_from_terminal(TTY *t, int utf8); /* crt.c */ -extern void crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color); -extern void crt_cls (CRT * c); -extern void crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color); -extern void crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea, - int color); -extern void crt_reset (CRT * c); -extern void crt_insert (CRT * c, CRT_CA ca); +extern void crt_erase(CRT *c, CRT_Pos s, CRT_Pos e, int ea, int color); +extern void crt_cls(CRT *c); +extern void crt_scroll_up(CRT *c, CRT_Pos s, CRT_Pos e, int ea, int color); +extern void crt_scroll_down(CRT *c, CRT_Pos s, CRT_Pos e, int ea, int color); +extern void crt_reset(CRT *c); +extern void crt_insert(CRT *c, CRT_CA ca); /* html.c */ -extern ANSI *ansi_new_html (FILE * f); +extern ANSI *ansi_new_html(FILE *f); /* libsympathy.c */ /* render.c */ /* version.c */ -extern char *libsympathy_version (void); +extern char *libsympathy_version(void); /* vt102.c */ extern int vt102_cmd_length[128]; extern int vt102_cmd_termination[128]; -extern void vt102_crt_update (Context * c); -extern void vt102_do_resize (Context * c); -extern void vt102_log_line (Context * c, int line); -extern void vt102_history (Context * c, CRT_Pos t, CRT_Pos b); -extern void vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br); -extern void vt102_cursor_normalize (VT102 * v); -extern void vt102_cursor_carriage_return (VT102 * v); -extern void vt102_cursor_advance_line (Context * c); -extern void vt102_cursor_retreat_line (Context * c); -extern void vt102_do_pending_wrap (Context * c); -extern void vt102_cursor_advance (Context * c); -extern void vt102_cursor_retreat (VT102 * v); -extern void vt102_reset_tabs (VT102 * v); -extern void vt102_cursor_advance_tab (VT102 * v); -extern void vt102_cursor_retreat_tab (VT102 * v); -extern int vt102_cursor_home (VT102 * v); -extern int vt102_cursor_absolute (VT102 * v, int x, int y); -extern int vt102_cursor_relative (VT102 * v, int x, int y); -extern void vt102_delete_from_line (VT102 * v, CRT_Pos p); -extern void vt102_insert_into_line (VT102 * v, CRT_Pos p); -extern void vt102_change_mode (Context * c, int private, char *ns, int set); -extern void vt102_parse_mode_string (Context * c, char *buf, int len); -extern void vt102_change_attr (VT102 * v, char *na); -extern void vt102_parse_attr_string (VT102 * v, char *buf, int len); -extern void vt102_save_state (VT102 * v); -extern void vt102_restore_state (VT102 * v); -extern void vt102_regular_char (Context * c, VT102 * v, uint32_t ch); -extern int vt102_send_id (Context * c, char *buf); -extern void vt102_scs (Context * c, int g, int s); -extern void vt102_status_line (VT102 * v, char *str); -extern void vt102_parser_reset (VT102_parser * p); -extern void vt102_reset_state (Context * c); -extern int vt102_rx_hook (Context * c, int ch); -extern int vt102_parse_char (Context * c, int ch); -extern void vt102_send (Context * c, uint8_t key); -extern void vt102_reset (Context * c); -extern VT102 *vt102_new (CRT_Pos * size); -extern void vt102_set_ansi (VT102 * v, int ansi); -extern void vt102_resize (Context * c, CRT_Pos size); -extern void vt102_free (VT102 * v); +extern void vt102_crt_update(Context *c); +extern void vt102_do_resize(Context *c); +extern void vt102_log_line(Context *c, int line); +extern void vt102_history(Context *c, CRT_Pos t, CRT_Pos b); +extern void vt102_clip_cursor(VT102 *v, CRT_Pos tl, CRT_Pos br); +extern void vt102_cursor_normalize(VT102 *v); +extern void vt102_cursor_carriage_return(VT102 *v); +extern void vt102_cursor_advance_line(Context *c); +extern void vt102_cursor_retreat_line(Context *c); +extern void vt102_do_pending_wrap(Context *c); +extern void vt102_cursor_advance(Context *c); +extern void vt102_cursor_retreat(VT102 *v); +extern void vt102_reset_tabs(VT102 *v); +extern void vt102_cursor_advance_tab(VT102 *v); +extern void vt102_cursor_retreat_tab(VT102 *v); +extern int vt102_cursor_home(VT102 *v); +extern int vt102_cursor_absolute(VT102 *v, int x, int y); +extern int vt102_cursor_relative(VT102 *v, int x, int y); +extern void vt102_delete_from_line(VT102 *v, CRT_Pos p); +extern void vt102_insert_into_line(VT102 *v, CRT_Pos p); +extern void vt102_change_mode(Context *c, int private, char *ns, int set); +extern void vt102_parse_mode_string(Context *c, char *buf, int len); +extern void vt102_change_attr(VT102 *v, char *na); +extern void vt102_parse_attr_string(VT102 *v, char *buf, int len); +extern void vt102_save_state(VT102 *v); +extern void vt102_restore_state(VT102 *v); +extern void vt102_regular_char(Context *c, VT102 *v, uint32_t ch); +extern int vt102_send_id(Context *c, char *buf); +extern void vt102_scs(Context *c, int g, int s); +extern void vt102_status_line(VT102 *v, char *str); +extern void vt102_parser_reset(VT102_parser *p); +extern void vt102_reset_state(Context *c); +extern int vt102_rx_hook(Context *c, int ch); +extern int vt102_parse_char(Context *c, int ch); +extern void vt102_send(Context *c, uint8_t key); +extern void vt102_reset(Context *c); +extern VT102 *vt102_new(CRT_Pos *size); +extern void vt102_set_ansi(VT102 *v, int ansi); +extern void vt102_resize(Context *c, CRT_Pos size); +extern void vt102_free(VT102 *v); /* tty.c */ -extern void tty_pre_select (TTY * t, fd_set * rfds, fd_set * wfds); -extern int tty_get_status (TTY * t, TTY_Status * s); -extern int tty_get_baud (TTY * t); -extern void tty_set_baud (TTY * t, int rate); -extern void tty_send_break (TTY * t); -extern void tty_set_flow (TTY * t, int flow); -extern void tty_hangup (TTY * t); -extern void tty_length (TTY * t, int l); -extern void tty_winch (TTY * t, CRT_Pos size); -extern void tty_parse_reset (Context * c); -extern void tty_analyse (Context * c); -extern TTY_Parser *tty_parser_new (void); -extern int tty_parse (Context * c, uint8_t * buf, int len); +extern void tty_pre_select(TTY *t, fd_set *rfds, fd_set *wfds); +extern int tty_get_status(TTY *t, TTY_Status *s); +extern int tty_get_baud(TTY *t); +extern void tty_set_baud(TTY *t, int rate); +extern void tty_send_break(TTY *t); +extern void tty_set_flow(TTY *t, int flow); +extern void tty_hangup(TTY *t); +extern void tty_length(TTY *t, int l); +extern void tty_winch(TTY *t, CRT_Pos size); +extern void tty_parse_reset(Context *c); +extern void tty_analyse(Context *c); +extern TTY_Parser *tty_parser_new(void); +extern int tty_parse(Context *c, uint8_t *buf, int len); /* keydis.c */ -extern KeyDis *keydis_vt102_new (void); -extern KeyDis *keydis_ipc_new (Socket * s); +extern KeyDis *keydis_vt102_new(void); +extern KeyDis *keydis_ipc_new(Socket *s); /* history.c */ -extern History *history_new (int n); -extern void history_free (History * h); -extern void history_add (History * h, CRT_CA * c); +extern History *history_new(int n); +extern void history_free(History *h); +extern void history_add(History *h, CRT_CA *c); /* ring.c */ -extern int ring_read (Ring * r, void *b, int n); -extern int ring_write (Ring * r, void *b, int n); -extern int ring_space (Ring * r); -extern int ring_bytes (Ring * r); -extern Ring *ring_new (int n); +extern int ring_read(Ring *r, void *b, int n); +extern int ring_write(Ring *r, void *b, int n); +extern int ring_space(Ring *r); +extern int ring_bytes(Ring *r); +extern Ring *ring_new(int n); /* ptty.c */ -extern TTY *ptty_open (char *path, char *argv[], CRT_Pos * size); +extern TTY *ptty_open(char *path, char *argv[], CRT_Pos *size); /* terminal.c */ extern int terminal_winches; -extern void terminal_atexit (void); -extern void terminal_getsize (TTY * _t); -extern void terminal_dispatch (void); -extern void terminal_register_handlers (void); -extern TTY *terminal_open (int rfd, int wfd); +extern void terminal_atexit(void); +extern void terminal_getsize(TTY *_t); +extern void terminal_dispatch(void); +extern void terminal_register_handlers(void); +extern TTY *terminal_open(int rfd, int wfd); /* util.c */ -extern int wrap_read (int fd, void *buf, int len); -extern int wrap_write (int fd, void *buf, int len); -extern void set_nonblocking (int fd); -extern void set_blocking (int fd); -extern void default_termios (struct termios *termios); -extern void client_termios (struct termios *termios); -extern int fput_cp (FILE * f, uint32_t ch); +extern int wrap_read(int fd, void *buf, int len); +extern int wrap_write(int fd, void *buf, int len); +extern void set_nonblocking(int fd); +extern void set_blocking(int fd); +extern void default_termios(struct termios *termios); +extern void client_termios(struct termios *termios); +extern int fput_cp(FILE *f, uint32_t ch); +extern void crash_out(char *why); +extern void *xmalloc(size_t s); +extern void *xrealloc(void *p, size_t s); +extern char *xstrdup(const char *s); /* log.c */ -extern Log *file_log_new (char *fn, int rotate); -extern void log_f (Log * log, char *fmt, ...); +extern Log *file_log_new(char *fn, int rotate); +extern void log_f(Log *log, char *fmt, ...); /* ipc.c */ -extern IPC_Msg *ipc_check_for_message_in_slide (Slide * s); -extern void ipc_consume_message_in_slide (Slide * s); -extern int ipc_msg_send (Socket * s, IPC_Msg * m); -extern int ipc_msg_send_debug (Socket * s, char *msg); -extern int ipc_msg_send_history (Socket * s, History_ent * l); -extern int ipc_msg_send_vt102 (Socket * s, VT102 * v); -extern int ipc_msg_send_key (Socket * s, int key); -extern int ipc_msg_send_term (Socket * s, void *buf, int len); -extern int ipc_msg_send_status (Socket * s, char *buf); -extern int ipc_msg_send_setbaud (Socket * s, int baud); -extern int ipc_msg_send_sendbreak (Socket * s); -extern int ipc_msg_send_setflow (Socket * s, int flow); -extern int ipc_msg_send_setansi (Socket * s, int ansi); -extern int ipc_msg_send_hangup (Socket * s); -extern int ipc_msg_send_setsize (Socket * s, CRT_Pos size); -extern int ipc_msg_send_reset (Socket * s); -extern void ipc_execute_message (IPC_Msg * m, Context * c); +extern IPC_Msg *ipc_check_for_message_in_slide(Slide *s); +extern void ipc_consume_message_in_slide(Slide *s); +extern int ipc_msg_send(Socket *s, IPC_Msg *m); +extern int ipc_msg_send_debug(Socket *s, char *msg); +extern int ipc_msg_send_initialize(Socket *s); +extern int ipc_msg_send_history(Socket *s, History_ent *l); +extern int ipc_msg_send_vt102(Socket *s, VT102 *v); +extern int ipc_msg_send_key(Socket *s, int key); +extern int ipc_msg_send_term(Socket *s, void *buf, int len); +extern int ipc_msg_send_status(Socket *s, char *buf); +extern int ipc_msg_send_setbaud(Socket *s, int baud); +extern int ipc_msg_send_sendbreak(Socket *s); +extern int ipc_msg_send_setflow(Socket *s, int flow); +extern int ipc_msg_send_setansi(Socket *s, int ansi); +extern int ipc_msg_send_hangup(Socket *s); +extern int ipc_msg_send_setsize(Socket *s, CRT_Pos size); +extern int ipc_msg_send_reset(Socket *s); /* slide.c */ -extern void slide_free (Slide * s); -extern void slide_consume (Slide * s, int n); -extern void slide_added (Slide * s, int n); -extern Slide *slide_new (int n); -extern void slide_expand (Slide * s, int n); +extern void slide_free(Slide *s); +extern void slide_consume(Slide *s, int n); +extern void slide_added(Slide *s, int n); +extern Slide *slide_new(int n); +extern void slide_expand(Slide *s, int n); /* symsocket.c */ -extern int wrap_recv (int fd, void *buf, int len); -extern int wrap_send (int fd, void *buf, int len); -extern void socket_free (Socket * s); -extern void socket_free_parent (Socket * s); -extern Socket *socket_listen (char *path); -extern Socket *socket_accept (Socket * l); -extern Socket *socket_connect (char *path); -extern void socket_consume_msg (Socket * s); -extern void socket_pre_select (Socket * s, fd_set * rfds, fd_set * wfds); -extern int socket_post_select (Socket * s, fd_set * rfds, fd_set * wfds); -extern int socket_write (Socket * s, void *buf, int len); -extern void socket_execute_msg (Socket * s, Context * ctx); +extern int wrap_recv(int fd, void *buf, int len); +extern int wrap_send(int fd, void *buf, int len); +extern void socket_free(Socket *s); +extern void socket_free_parent(Socket *s); +extern Socket *socket_listen(char *path); +extern Socket *socket_accept(Socket *l); +extern Socket *socket_connect(char *path); +extern void socket_consume_msg(Socket *s); +extern void socket_pre_select(Socket *s, fd_set *rfds, fd_set *wfds); +extern int socket_post_select(Socket *s, fd_set *rfds, fd_set *wfds); +extern int socket_write(Socket *s, void *buf, int len); /* serial.c */ -extern TTY *serial_open (char *path, int lock_mode); +extern TTY *serial_open(char *path, int lock_mode); /* cmd.c */ -extern int cmd_parse (Cmd * c, Context * ctx, ANSI * a, char *buf); -extern void cmd_show_status (Cmd * c, Context * ctx); -extern int cmd_key (Cmd * c, Context * ctx, ANSI * a, int key); -extern int cmd_deactivate (Cmd * c, Context * ctx); -extern int cmd_activate (Cmd * c, Context * ctx); -extern void cmd_new_status (Cmd * c, Context * ctx, char *msg); -extern Cmd *cmd_new (void); +extern int cmd_parse(Cmd *c, Context *ctx, ANSI *a, char *buf); +extern void cmd_show_status(Cmd *c, Context *ctx); +extern int cmd_key(Cmd *c, Context *ctx, ANSI *a, int key); +extern int cmd_deactivate(Cmd *c, Context *ctx); +extern int cmd_activate(Cmd *c, Context *ctx); +extern void cmd_new_status(Cmd *c, Context *ctx, char *msg); +extern Cmd *cmd_new(void); /* lockfile.c */ -extern Filelist *filelist_new (void); -extern void filelist_remove (Filelist * fl, Filelist_ent * fle); -extern void filelist_add (Filelist * fl, char *fn); -extern void filelist_free (Filelist * fl); -extern void filelist_print (Filelist * fl, FILE * f); -extern int lockfile_make (char *name); -extern void lockfile_add_places (Filelist * fl, char *leaf); -extern void lockfile_regularize_and_add (Filelist * fl, char *leaf); -extern void lockfile_add_name_from_path (Filelist * fl, char *file); -extern void lockfile_add_name_from_dev (Filelist * fl, dev_t dev); -extern void lockfile_check_dir_for_dev (Filelist * fl, char *dir, dev_t dev); -extern Filelist *lockfile_make_list (char *device); -extern void lockfile_remove_stale (Filelist * fl); -extern Filelist *lockfile_lock (Filelist * fl); -extern void lockfile_unlock (Filelist * fl); -extern int serial_lock_check (Serial_lock * l); -extern void serial_lock_free (Serial_lock * l); -extern Serial_lock *serial_lock_new (char *dev, int mode); +extern Filelist *filelist_new(void); +extern void filelist_remove(Filelist *fl, Filelist_ent *fle); +extern void filelist_add(Filelist *fl, char *fn); +extern void filelist_free(Filelist *fl); +extern void filelist_print(Filelist *fl, FILE *f); +extern int lockfile_make(char *name); +extern void lockfile_add_places(Filelist *fl, char *leaf); +extern void lockfile_regularize_and_add(Filelist *fl, char *leaf); +extern void lockfile_add_name_from_path(Filelist *fl, char *file); +extern void lockfile_add_name_from_dev(Filelist *fl, dev_t dev); +extern void lockfile_check_dir_for_dev(Filelist *fl, char *dir, dev_t dev); +extern Filelist *lockfile_make_list(char *device); +extern void lockfile_remove_stale(Filelist *fl); +extern Filelist *lockfile_lock(Filelist *fl); +extern void lockfile_unlock(Filelist *fl); +extern int serial_lock_check(Serial_lock *l); +extern void serial_lock_free(Serial_lock *l); +extern Serial_lock *serial_lock_new(char *dev, int mode); /* utf8.c */ -extern int utf8_flush (Context * c); -extern int utf8_parse (Context * c, uint32_t ch); -extern UTF8 *utf8_new (void); -extern int utf8_encode (char *ptr, int ch); -extern int utf8_emit (TTY * t, int ch); +extern int utf8_flush(Context *c); +extern int utf8_parse(Context *c, uint32_t ch); +extern UTF8 *utf8_new(void); +extern int utf8_encode(char *ptr, int ch); +extern int utf8_emit(TTY *t, int ch); /* vt102_charset.c */ extern uint32_t vt102_charset_c0[128]; extern uint32_t vt102_charset_us[128]; @@ -184,10 +186,10 @@ extern uint32_t vt102_charset_vt52[128]; extern uint32_t vt102_charset_gl[128]; extern uint32_t *charset_from_csid[]; /* rotate.c */ -extern void rotate_gzip (char *file); -extern void rotate (char *file); -extern int rotate_check (char *file); +extern void rotate_gzip(char *file); +extern void rotate(char *file); +extern int rotate_check(char *file); /* raw.c */ -extern RX *rx_new_raw (int rfd, int wfd); -extern TTY *terminal_new_raw (int rfd, int wfd); -extern ANSI *ansi_new_raw (int rfd, int wfd); +extern RX *rx_new_raw(int rfd, int wfd); +extern TTY *terminal_new_raw(int rfd, int wfd); +extern ANSI *ansi_new_raw(int rfd, int wfd); diff --git a/src/ptty.c b/src/ptty.c index 5f4651d..393eab6 100644 --- a/src/ptty.c +++ b/src/ptty.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.20 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.19 2008/03/07 12:37:04 james * *** empty log message *** * @@ -203,7 +206,7 @@ ptty_open (char *path, char *argv[], CRT_Pos * size) } #endif - t = (PTTY *) malloc (sizeof (PTTY)); + t = (PTTY *) xmalloc (sizeof (PTTY)); strncpy (t->name, name, sizeof (t->name)); t->name[sizeof (t->name) - 1] = 0; diff --git a/src/raw.c b/src/raw.c index e5a58dc..15c12f8 100644 --- a/src/raw.c +++ b/src/raw.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.7 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.6 2008/03/07 12:37:04 james * *** empty log message *** * @@ -67,7 +70,7 @@ rx_new_raw (int rfd, int wfd) { RX_Raw *ret; - ret = malloc (sizeof (RX_Raw)); + ret = xmalloc (sizeof (RX_Raw)); memset (ret, 0, sizeof (RX_Raw)); ret->rx = rx_raw_rx; diff --git a/src/ring.c b/src/ring.c index 44b2bb9..920e1ca 100644 --- a/src/ring.c +++ b/src/ring.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.8 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.7 2008/03/07 12:37:04 james * *** empty log message *** * @@ -95,8 +98,8 @@ ring_bytes (Ring * r) Ring * ring_new (int n) { - Ring *ret = (Ring *) malloc (sizeof (Ring)); - ret->ring = (uint8_t *) malloc (n); + Ring *ret = (Ring *) xmalloc (sizeof (Ring)); + ret->ring = (uint8_t *) xmalloc (n); ret->size = n; ret->wptr = ret->rptr = 0; diff --git a/src/rotate.c b/src/rotate.c index ad1752e..fae79f4 100644 --- a/src/rotate.c +++ b/src/rotate.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.10 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.9 2008/03/07 12:37:04 james * *** empty log message *** * @@ -71,8 +74,8 @@ rotate (char *file) return; i = strlen (file) + 32; - buf1 = malloc (i); - buf2 = malloc (i); + buf1 = xmalloc (i); + buf2 = xmalloc (i); for (i = NUM_FILES_TO_KEEP; i > 0; --i) { sprintf (buf1, "%s.%d", file, i - 1); diff --git a/src/serial.c b/src/serial.c index bc3558a..1592f9e 100644 --- a/src/serial.c +++ b/src/serial.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.16 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.15 2008/03/07 12:37:04 james * *** empty log message *** * @@ -202,7 +205,7 @@ serial_open (char *path, int lock_mode) return NULL; } - t = (Serial *) malloc (sizeof (Serial)); + t = (Serial *) xmalloc (sizeof (Serial)); t->lock = l; diff --git a/src/slide.c b/src/slide.c index 7561f60..a06daea 100644 --- a/src/slide.c +++ b/src/slide.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.7 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.6 2008/03/07 12:37:04 james * *** empty log message *** * @@ -54,7 +57,7 @@ slide_consume (Slide * s, int n) s->nbytes -= n; if (s->nbytes < 0) - abort (); + crash_out("slide_consume called with -ve number of bytes"); memmove (s->slide, s->slide + n, s->nbytes); @@ -74,9 +77,9 @@ slide_added (Slide * s, int n) Slide * slide_new (int n) { - Slide *ret = (Slide *) malloc (sizeof (Slide)); + Slide *ret = (Slide *) xmalloc (sizeof (Slide)); - ret->slide = (uint8_t *) malloc (n); + ret->slide = (uint8_t *) xmalloc (n); ret->size = n; ret->target_size = n; ret->nbytes = 0; @@ -96,7 +99,6 @@ slide_expand (Slide * s, int n) while (n > s->size) s->size <<= 1; - // FIXME -- might fail - s->slide = realloc (s->slide, s->size); + s->slide = xrealloc (s->slide, s->size); } diff --git a/src/symsocket.c b/src/symsocket.c index 15b58c5..0c1b42b 100644 --- a/src/symsocket.c +++ b/src/symsocket.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.12 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.11 2008/03/07 12:37:04 james * *** empty log message *** * @@ -137,7 +140,7 @@ socket_listen (char *path) return NULL; n = strlen (path) + sizeof (struct sockaddr_un); - sun = (struct sockaddr_un *) malloc (n); + sun = (struct sockaddr_un *) xmalloc (n); memset (sun, 0, n); sun->sun_family = AF_UNIX; @@ -158,7 +161,7 @@ socket_listen (char *path) set_nonblocking (fd); - ret = (Socket *) malloc (sizeof (Socket)); + ret = (Socket *) xmalloc (sizeof (Socket)); memset (ret, 0, sizeof (Socket)); ret->read_buf = NULL; ret->write_buf = NULL; @@ -186,7 +189,7 @@ socket_accept (Socket * l) return NULL; - ret = (Socket *) malloc (sizeof (Socket)); + ret = (Socket *) xmalloc (sizeof (Socket)); memset (ret, 0, sizeof (Socket)); set_nonblocking (fd); @@ -216,7 +219,7 @@ socket_connect (char *path) return NULL; n = strlen (path) + sizeof (struct sockaddr_un); - sun = (struct sockaddr_un *) malloc (n); + sun = (struct sockaddr_un *) xmalloc (n); memset (sun, 0, n); sun->sun_family = AF_UNIX; @@ -232,7 +235,7 @@ socket_connect (char *path) set_nonblocking (fd); - ret = (Socket *) malloc (sizeof (Socket)); + ret = (Socket *) xmalloc (sizeof (Socket)); memset (ret, 0, sizeof (Socket)); ret->fd = fd; @@ -339,11 +342,3 @@ socket_write (Socket * s, void *buf, int len) return len; } -void -socket_execute_msg (Socket * s, Context * ctx) -{ - if (!s->msg) - return; - ipc_execute_message (s->msg, ctx); - socket_consume_msg (s); -} diff --git a/src/terminal.c b/src/terminal.c index 3e2cc64..c6c581c 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.17 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.16 2008/03/07 12:42:08 james * *** empty log message *** * @@ -278,7 +281,7 @@ terminal_open (int rfd, int wfd) pid_t child; struct termios termios; - t = (TERMINAL *) malloc (sizeof (TERMINAL)); + t = (TERMINAL *) xmalloc (sizeof (TERMINAL)); strcpy (t->name, "terminal"); t->rfd = rfd; diff --git a/src/tty.c b/src/tty.c index 57962e7..df1ad8f 100644 --- a/src/tty.c +++ b/src/tty.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.25 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.24 2008/03/07 12:37:04 james * *** empty log message *** * @@ -510,7 +513,7 @@ tty_parser_new (void) { TTY_Parser *p; - p = (TTY_Parser *) malloc (sizeof (TTY_Parser)); + p = (TTY_Parser *) xmalloc (sizeof (TTY_Parser)); memset (p, 0, sizeof (TTY_Parser)); diff --git a/src/utf8.c b/src/utf8.c index baa03cb..f909666 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.15 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.14 2008/03/07 12:37:04 james * *** empty log message *** * @@ -157,7 +160,7 @@ utf8_new (void) { UTF8 *ret; - ret = (UTF8 *) malloc (sizeof (UTF8)); + ret = (UTF8 *) xmalloc (sizeof (UTF8)); ret->in_utf8 = 0; diff --git a/src/util.c b/src/util.c index 877a86e..bd4bffe 100644 --- a/src/util.c +++ b/src/util.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.10 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.9 2008/03/07 12:37:04 james * *** empty log message *** * @@ -166,3 +169,29 @@ fput_cp (FILE * f, uint32_t ch) return fwrite (buf, i, 1, f); } + +void crash_out(char *why) +{ +terminal_atexit(); +fprintf(stderr,"sympathy is aborting: %s\n",why ? why:""); +exit(1); +} + +void *xmalloc(size_t s) +{ +void *ret=malloc(s); +if (!ret) crash_out("malloc failed"); +return ret; +} +void *xrealloc(void *p,size_t s) +{ +p=realloc(p,s); +if (!p) crash_out("realloc failed"); +return p; +} +char *xstrdup(const char *s) +{ +char *ret=strdup(s); +if (!ret) crash_out("strdup failed"); +return ret; +} diff --git a/src/vt102.c b/src/vt102.c index ca0096e..14a8327 100644 --- a/src/vt102.c +++ b/src/vt102.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.66 2008/03/07 13:16:02 james + * *** empty log message *** + * * Revision 1.65 2008/03/07 12:42:08 james * *** empty log message *** * @@ -2055,7 +2058,7 @@ vt102_new (CRT_Pos * size) { VT102 *v; - v = (VT102 *) malloc (sizeof (VT102)); + v = (VT102 *) xmalloc (sizeof (VT102)); v->xn_glitch = 1; -- cgit v1.2.3