X-Git-Url: https://git.distorted.org.uk/~mdw/sw-tools/blobdiff_plain/3315e8b31a4707ef2c5491d0c9a9c9a09816bcb2..95e672af19ea22b86981b5e0f4eefb5efed98484:/src/sw_rsh.c diff --git a/src/sw_rsh.c b/src/sw_rsh.c index 3c910df..91aa82b 100644 --- a/src/sw_rsh.c +++ b/src/sw_rsh.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: sw_rsh.c,v 1.1 1999/06/02 16:53:34 mdw Exp $ + * $Id: sw_rsh.c,v 1.5 1999/06/24 16:02:22 mdw Exp $ * * Run remote commands * @@ -29,8 +29,22 @@ /*----- Revision history --------------------------------------------------* * * $Log: sw_rsh.c,v $ - * Revision 1.1 1999/06/02 16:53:34 mdw - * Initial revision + * Revision 1.5 1999/06/24 16:02:22 mdw + * Fix signal handling some more. + * + * 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. * */ @@ -59,6 +73,7 @@ #endif #include +#include #include #include #include @@ -74,8 +89,6 @@ /*----- Data structures ---------------------------------------------------*/ -typedef unsigned char octet; - #define PKHEADSZ 3 typedef struct pkhead { @@ -125,8 +138,7 @@ int pksend(sw_remote *r, int type, const void *p, size_t sz) /* --- Set up the packet header --- */ chunk = (sz > PKMAX ? PKMAX : sz); - h.len[0] = chunk & 0xff; - h.len[1] = (chunk >> 8) & 0xff; + STORE16(h.len, chunk); /* --- Write the packet header --- */ @@ -221,7 +233,7 @@ int pkrecv(sw_remote *r) /* --- Sort out what's going on --- */ - sz = h.len[0] | (h.len[1] << 8); + sz = LOAD16(h.len); r->sz = sz; if (!sz) return (h.type); @@ -626,6 +638,7 @@ done: static void sigchld(int sig) { + int e = errno; #ifdef DEBUG_SIGCHLD int status; while (waitpid(-1, &status, WNOHANG) > 0) { @@ -642,6 +655,7 @@ static void sigchld(int sig) while (waitpid(-1, 0, WNOHANG) > 0) ; #endif + errno = e; } /* --- @swrsh@ --- * @@ -674,7 +688,10 @@ int swrsh(sw_remote *r, const char *host, const char *cmd, char *argv[]) if (!handler) { struct sigaction sa; sa.sa_handler = sigchld; - sa.sa_flags = 0; + sa.sa_flags = SA_NOCLDSTOP; +#ifdef SA_RESTART + sa.sa_flags |= SA_RESTART; +#endif sigemptyset(&sa.sa_mask); sigaction(SIGCHLD, &sa, 0); handler = 1; @@ -702,6 +719,9 @@ 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]; remote(r, cmd, argv, environ);