home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / 3b1 / 4377 < prev    next >
Encoding:
Text File  |  1993-01-24  |  5.6 KB  |  178 lines

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!nntp-server.caltech.edu!andy
  2. From: andy@cs.caltech.edu (Andy Fyfe)
  3. Newsgroups: comp.sys.3b1
  4. Subject: Re: Taylor uucp 1.4 gamma on 3B1 with TCP (long)
  5. Date: 23 Jan 1993 22:29:17 GMT
  6. Organization: California Institute of Technology
  7. Lines: 166
  8. Message-ID: <1jsgrtINNgeg@gap.caltech.edu>
  9. References: <1993Jan20.045619.1333@d-and-d.com> <1993Jan21.123039.8504@ohare.Chicago.COM> <1993Jan23.050509.7515@d-and-d.com>
  10. NNTP-Posting-Host: kodiak.cs.caltech.edu
  11.  
  12. The following two excerpts turn out to be stangely related (even though
  13. they're from the same thread!).
  14.  
  15. >In article <1993Jan19.054921.1557@ohare.Chicago.COM> kls@ohare.Chicago.COM (Karl Swartz) writes:
  16. >If it links, the route must exist.  Unfortunately, the gcc
  17. >version I have (1.40) returns 0 even if the link fails.  The includes
  18. >are also not specified.  So, the very first step is to change configure.
  19.  
  20. In article <1993Jan23.050509.7515@d-and-d.com> dnichols@d-and-d.com (DoN. Nichols) writes:
  21. >In article <1993Jan21.123039.8504@ohare.Chicago.COM> kls@ohare.Chicago.COM (Karl Swartz) writes:
  22. >>And then there's <sys/wait.h> -- the Wollongong version is essentially
  23. >>a no-op, so if you get that turkey you'll be missing all the stuff in
  24. >>the standard version.
  25. >
  26. >    You're right - perhaps that should be changed to include
  27. ><sys/wait.h>.
  28.  
  29. The problem Karl (and at least one other person I recently talked to)
  30. had with configure, caused by gcc erroneouly returning an exit status
  31. of 0, is probably the result of using shld, which calls /bin/ld to do
  32. the actual linking.  Shld uses wait() to wait for ld, and to get its
  33. return status, which it then returns to gcc.  And it manipulates the
  34. returned status from wait using the union defined in <sys/wait.h>, part
  35. of which looks like
  36.     struct {
  37.     unsigned short    w_Termsig:7;    /* termination signal */
  38.     unsigned short    w_Coredump:1;    /* core dump indicator */
  39.     unsigned short    w_Retcode:8;    /* exit code if w_termsig==0 */
  40.     } w_T;
  41. Which would be perfect if only the 3b1 were a little-endian machine!
  42.  
  43. To work on the 3b1, the struct needs to be reversed, and padding
  44. added to skip the high 16 bits, namely
  45.     struct {
  46.     unsigned short    w_padding:16;    /* ignore the high order 16 bits */
  47.     unsigned short    w_Retcode:8;    /* exit code if w_termsig==0 */
  48.     unsigned short    w_Coredump:1;    /* core dump indicator */
  49.     unsigned short    w_Termsig:7;    /* termination signal */
  50.     } w_T;
  51.  
  52. Code that doesn't use <sys/wait.h> may very well be better off!
  53.  
  54. I've changed shld to skip the "union wait" business altogether, and
  55. updated the copy on ftp.cs.caltech.edu:pub/3b1/gcc-1.42/shld.shar.Z
  56. (This only applies to gcc 1.x, which is why shld is in with gcc 1.42.
  57. (shld can be used with other version of gcc 1.x.)  Gcc 2.x uses a
  58. patched version of the collect program.)  I'm including the patch here,
  59. as well as a short test program if you want to check out your copy of
  60. <sys/wait.h>.
  61.  
  62. Andy Fyfe                    andy@cs.caltech.edu
  63.  
  64. #!/bin/sh
  65. # This is a shell archive (shar 3.46)
  66. # made 01/23/1993 22:20 UTC by andy@kodiak
  67. # Source directory /tmp_mnt/ufs/vortex/andy
  68. #
  69. # existing files will NOT be overwritten unless -c is specified
  70. #
  71. # This shar contains:
  72. # length  mode       name
  73. # ------ ---------- ------------------------------------------
  74. #    997 -rw-r--r-- shld.diff
  75. #    567 -rw-r--r-- test.c
  76. #
  77. # ============= shld.diff ==============
  78. if test -f 'shld.diff' -a X"$1" != X"-c"; then
  79.     echo 'x - skipping shld.diff (File already exists)'
  80. else
  81. echo 'x - extracting shld.diff (Text)'
  82. sed 's/^X//' << 'SHAR_EOF' > 'shld.diff' &&
  83. diff -c2 old/ld.c new/ld.c
  84. *** old/ld.c    Wed Jan 20 15:49:22 1993
  85. --- new/ld.c    Wed Jan 20 15:49:26 1993
  86. ***************
  87. *** 10,14 ****
  88. X  #include <signal.h>
  89. X  #include <sys/types.h>
  90. - #include <sys/wait.h>
  91. X  #include <sys/stat.h>
  92. X  
  93. --- 10,13 ----
  94. ***************
  95. *** 153,157 ****
  96. X  #endif
  97. X      int pid;
  98. !     union wait status;
  99. X  
  100. X  #ifdef DEBUG
  101. --- 152,156 ----
  102. X  #endif
  103. X      int pid;
  104. !     int status;
  105. X  
  106. X  #ifdef DEBUG
  107. ***************
  108. *** 177,186 ****
  109. X      while (pid != wait(&status))
  110. X          ;
  111. !     if (status.w_termsig == 0)
  112. !         return status.w_retcode;
  113. X      else {
  114. X          fprintf(stderr, "%s: caught signal %d%s\n",
  115. !         cmd_name, status.w_termsig,
  116. !         (status.w_coredump ? " (core dumped)" : ""));
  117. X          return 1;
  118. X      }
  119. --- 176,185 ----
  120. X      while (pid != wait(&status))
  121. X          ;
  122. !     if ((status & 0x7f) == 0)
  123. !         return status >> 8;
  124. X      else {
  125. X          fprintf(stderr, "%s: caught signal %d%s\n",
  126. !         cmd_name, status & 0x7f,
  127. !         (status & 0x80 ? " (core dumped)" : ""));
  128. X          return 1;
  129. X      }
  130. SHAR_EOF
  131. chmod 0644 shld.diff ||
  132. echo 'restore of shld.diff failed'
  133. Wc_c="`wc -c < 'shld.diff'`"
  134. test 997 -eq "$Wc_c" ||
  135.     echo 'shld.diff: original size 997, current size' "$Wc_c"
  136. fi
  137. # ============= test.c ==============
  138. if test -f 'test.c' -a X"$1" != X"-c"; then
  139.     echo 'x - skipping test.c (File already exists)'
  140. else
  141. echo 'x - extracting test.c (Text)'
  142. sed 's/^X//' << 'SHAR_EOF' > 'test.c' &&
  143. #include <sys/wait.h>
  144. main(argc, argv)
  145. int argc;
  146. char *argv[];
  147. {
  148. X    int pid;
  149. X    union wait status;
  150. X
  151. X    pid = fork();
  152. X    if (pid == -1) {
  153. X    printf("fork failed\n");
  154. X    exit(1);
  155. X    }
  156. X    if (pid == 0) { /* child */
  157. X    pid = atoi(argv[1]);
  158. X    if (pid >= 0) exit(pid);
  159. X    kill(getpid(), -pid);
  160. X    }
  161. X    wait(&status);
  162. X    printf("status is %d\n", status.w_status);
  163. X    if (status.w_termsig == 0)
  164. X    printf("child exits %d\n", status.w_retcode);
  165. X    else
  166. X    printf("child caught signal %d%s\n", status.w_termsig,
  167. X        (status.w_coredump ? " (core dumped)" : ""));
  168. X    exit(0);
  169. }
  170. SHAR_EOF
  171. chmod 0644 test.c ||
  172. echo 'restore of test.c failed'
  173. Wc_c="`wc -c < 'test.c'`"
  174. test 567 -eq "$Wc_c" ||
  175.     echo 'test.c: original size 567, current size' "$Wc_c"
  176. fi
  177. exit 0
  178.