Fix typo in comment.
[sw-tools] / src / sw_rsh.c
index 4f2be0d..8720551 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: sw_rsh.c,v 1.3 1999/06/18 18:58:54 mdw Exp $
+ * $Id: sw_rsh.c,v 1.7 1999/09/24 13:16:22 mdw Exp $
  *
  * Run remote commands
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: sw_rsh.c,v $
+ * Revision 1.7  1999/09/24 13:16:22  mdw
+ * Fix typo in comment.
+ *
+ * Revision 1.6  1999/09/24 13:15:57  mdw
+ * Remove unnecessary assumptions about structure layouts.  (The `pkhead'
+ * structure is no more.)
+ *
+ * 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.
  *
 
 #define PKHEADSZ 3
 
-typedef struct pkhead {
-  octet len[2];
-  octet type;
-} pkhead;
-
 /*----- Static variables --------------------------------------------------*/
 
 static int handler = 0;
@@ -107,13 +115,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;
 
@@ -126,13 +134,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 --- */
 
@@ -178,7 +186,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;
@@ -216,7 +224,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)
@@ -227,10 +235,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);
@@ -251,7 +259,7 @@ int pkrecv(sw_remote *r)
     }
   }
 
-  return (h.type);
+  return (h[2]);
 }
 
 /*----- Error reporting and exit statuses --------------------------------*/
@@ -632,6 +640,7 @@ done:
 
 static void sigchld(int sig)
 {
+  int e = errno;
 #ifdef DEBUG_SIGCHLD
   int status;
   while (waitpid(-1, &status, WNOHANG) > 0) {
@@ -648,6 +657,7 @@ static void sigchld(int sig)
   while (waitpid(-1, 0, WNOHANG) > 0)
     ;
 #endif
+  errno = e;
 }
 
 /* --- @swrsh@ --- *
@@ -711,10 +721,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);
     }