X-Git-Url: https://git.distorted.org.uk/~mdw/sw-tools/blobdiff_plain/6312480608563d7d10da23e51cba9f433f7b7a01..65eb98997977ba66bf96aff5e0cc8494ea03cdce:/src/sw_rsh.c diff --git a/src/sw_rsh.c b/src/sw_rsh.c index 0406798..785da7d 100644 --- a/src/sw_rsh.c +++ b/src/sw_rsh.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: sw_rsh.c,v 1.4 1999/06/24 15:51:17 mdw Exp $ + * $Id$ * * Run remote commands * @@ -26,25 +26,6 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: sw_rsh.c,v $ - * Revision 1.4 1999/06/24 15:51:17 mdw - * Fix signal handlers so they don't corrupt `errno'. - * - * Revision 1.3 1999/06/18 18:58:54 mdw - * Signal handling fixes. - * - * Revision 1.2 1999/06/02 17:03:29 mdw - * Fix use of `octet' now that mLib includes `bits.h' (as of version 1.3.5 - * release). Also use the mLib load and store macros rather than doing it - * by hand. - * - * Revision 1.1.1.1 1999/06/02 16:53:34 mdw - * Initial import. - * - */ - /*----- Header files ------------------------------------------------------*/ #include "config.h" @@ -88,11 +69,6 @@ #define PKHEADSZ 3 -typedef struct pkhead { - octet len[2]; - octet type; -} pkhead; - /*----- Static variables --------------------------------------------------*/ static int handler = 0; @@ -110,13 +86,13 @@ static rcmd *rcmds = RCMD_LINK; * Returns: Zero if it worked, nonzero otherwise. * * Use: Sends a data packet. If the type is `data', then `sz' may be - * arbitrarily large and is divided into small eenough chunks. + * arbitrarily large and is divided into small enough chunks. * Otherwise it's an error to send a packet that's too big. */ int pksend(sw_remote *r, int type, const void *p, size_t sz) { - pkhead h; + octet h[PKHEADSZ]; const char *q = p; size_t chunk; @@ -129,13 +105,13 @@ int pksend(sw_remote *r, int type, const void *p, size_t sz) /* --- Main output loop --- */ - h.type = type; + h[2] = type; do { /* --- Set up the packet header --- */ chunk = (sz > PKMAX ? PKMAX : sz); - STORE16(h.len, chunk); + STORE16(h, chunk); /* --- Write the packet header --- */ @@ -181,7 +157,7 @@ int pksend(sw_remote *r, int type, const void *p, size_t sz) int pkrecv(sw_remote *r) { - pkhead h; + octet h[PKHEADSZ]; size_t sz; char *p; ssize_t n; @@ -219,7 +195,7 @@ int pkrecv(sw_remote *r) * characters. */ - if (h.type >= PKTYPE_BOGUS) { + if (h[2] >= PKTYPE_BOGUS) { memcpy(r->buf, &h, PKHEADSZ); n = read(r->fdin, r->buf + PKHEADSZ, sizeof(r->buf) - PKHEADSZ); if (n < 0) @@ -230,10 +206,10 @@ int pkrecv(sw_remote *r) /* --- Sort out what's going on --- */ - sz = LOAD16(h.len); + sz = LOAD16(h); r->sz = sz; if (!sz) - return (h.type); + return (h[2]); if (sz > PKMAX) { errno = E2BIG; return (-1); @@ -254,7 +230,7 @@ int pkrecv(sw_remote *r) } } - return (h.type); + return (h[2]); } /*----- Error reporting and exit statuses --------------------------------*/ @@ -337,7 +313,7 @@ void swwait(sw_remote *r, int status) void swvprintf(sw_remote *r, const char *format, va_list ap) { dstr d = DSTR_INIT; - dstr_vputf(&d, format, ap); + dstr_vputf(&d, format, &ap); pksend(r, PKTYPE_DATA, d.buf, d.len); dstr_destroy(&d); } @@ -380,7 +356,7 @@ void swdie(sw_remote *r, int status, const char *format, ...) va_start(ap, format); dstr_putf(&d, "%s [remote]: ", QUIS); - dstr_vputf(&d, format, ap); + dstr_vputf(&d, format, &ap); dstr_putc(&d, '\n'); dstr_putz(&d); va_end(ap); @@ -716,10 +692,11 @@ int swrsh(sw_remote *r, const char *host, const char *cmd, char *argv[]) /* --- Child end of a local job --- */ + signal(SIGINT, SIG_DFL); + signal(SIGQUIT, SIG_DFL); + if (!host) { r->fdin = r->fdout = sk[1]; - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); remote(r, cmd, argv, environ); }