home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / aix / 13788 < prev    next >
Encoding:
Text File  |  1993-01-28  |  6.7 KB  |  241 lines

  1. Newsgroups: comp.unix.aix
  2. Path: sparky!uunet!munnari.oz.au!spool.mu.edu!yale.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sunic!news.lth.se!pollux.lu.se!balder.tf1.lu.se!gs
  3. From: gs@balder.tf1.lu.se (Goran Svensson)
  4. Subject: Re: * IDLE OUT ON RS/6000 *
  5. Message-ID: <1993Jan27.150954.10492@pollux.lu.se>
  6. Summary: PSOIX and SIGHUP and so on
  7. Keywords: PSOXI, SIGHUP, Idonotunderstand
  8. Sender: goran@btj.se
  9. Nntp-Posting-Host: balder.tf1.lu.se
  10. Organization: none
  11. References: <C14Dzu.owr@austin.ibm.com> <117@DSM530.UUCP> <C18nK1.1MDK@austin.ibm.com>
  12. Date: Wed, 27 Jan 1993 15:09:54 GMT
  13. Lines: 226
  14.  
  15. Sorry folks, I really would love to take this one of stage, but since
  16. I am not allowed to mail to IBM I have to reply here. This is directed
  17. to Rich Coe and John Haugh @austin.ibm.com who were kind enought to answer 
  18. my previous question (or anyone else who may know)
  19.  
  20.  
  21.    ----- Transcript of session follows -----
  22. 550 Mailing across IBM boundary not authorized
  23.  
  24. ---
  25.  
  26.  
  27. Thanks to both of you for taking the time to answer me, this is a problem that
  28. has been bugging me for a while.
  29.  
  30. I am not totaly familiar with the concept of foreground and background 
  31. processes, but here is what I do:
  32.  
  33. I have a telnet based terminal server, from which I log in to my AIX.
  34. While there I start a program (any program), and then my terminal is 
  35. switched of (that is, the telnet session dies. The same behaviour has been
  36. observed between 2 AIX machines when I ^T and quits telnet). The ksh dies
  37. but the program is not notified. The read terminates with 0, so that part
  38. works fine, but as Rich says, there are many programs out there who does
  39. not expect this behaviour. No signal is processed, and the program is allowed
  40. to proceed. A 'simple' program in included below, just to show what I am doing.
  41.  
  42. John (or Rich), I expect the program to be a part of the foreground process
  43. group and should receive a SIGHUP. I had a case with IBM during the autumn
  44. and it was terminated when Andre Mbus at IBM gave me this answer:
  45.  
  46. ...
  47. This is what happening: on the telnet client side when the terminal is
  48. turned off the shell send a SIGHUP to telnet as  a result telnet get
  49. killed during that process telnet close the connection and send a FIN
  50. to telnetd which in turn close the pty and any process which 
  51. try to read or write 
  52. to that tty get and EOF. So there is no SIGHUP send to telnetd 
  53. and telnetd does not send a SIGHUP signal to foreground
  54. processes. The
  55. application should not be looking for SIGHUP but to check if the tty is
  56. still opened.
  57. ... ( I copied the answer letter by letter to keep the original phrasing and
  58. spelling)
  59.  
  60. Is it really so? If I do not misread your answers, I tend to say no.
  61. John, you state that if the program was started by the session leader,
  62. I should receive a SIGHUP. Well, I don't. And I did have a case with IBM.
  63.  
  64. I do not know what is right and what is wrong, but if you are right, then 
  65. Andre is wrong (or, most plausible, I am totally wrong).
  66.  
  67. Regards,
  68. Goran Svensson
  69. BTJ System AB
  70. Sweden
  71. goran@btj.se
  72. --- Program follows ---
  73.  
  74. #include        <signal.h>
  75. #include        <stdio.h>
  76. #include        <setjmp.h>
  77. #include    <errno.h>
  78.  
  79. static        jmp_buf    jmp_intr;
  80.  
  81. /*
  82. --------------------------------------------------------------------------------
  83. */
  84. #include    <sys/time.h>
  85. #include    <sys/types.h>
  86.  
  87. char *adate()
  88. {
  89.     int    status, len;
  90.    char  *sccs_id="@(#) adate() 1.0 930120 Return pointer to time of day";
  91.  
  92.     struct timestruc_t    current_time;
  93.     char                        *today;
  94.     time_t                    ct;
  95.  
  96.     status = gettimer( TIMEOFDAY, ¤t_time );
  97.  
  98.     ct = current_time.tv_sec;
  99.  
  100.     today = ctime( &ct );
  101.  
  102. /* Remove trailing \n */
  103.    len = strlen(today);
  104.    today[len-1] = '\0';
  105.  
  106.     return( today );
  107.  
  108. }
  109. /*
  110. --------------------------------------------------------------------------------
  111. */
  112.  
  113. static void report_alarm( char *message )
  114. {
  115.    char     *date;
  116.    FILE     *logfile;
  117.  
  118.    date = adate();
  119.  
  120.    printf( "%s\n", message );
  121.     printf( "Interrupted at %s\n ", date );
  122.  
  123.    logfile = fopen("/tmp/traps.log", "a");
  124.    if ( logfile != (FILE *)0 ) {
  125.       fprintf( logfile, "%s. Interrupted at %s\n", message, date );
  126.       fclose(logfile);
  127.    }
  128.    else
  129.       fprintf( stderr, "Could not open logfile /tmp/traps.log\n");
  130.  
  131.    exit(1);
  132. /*
  133.     longjmp( jmp_intr, 1 );
  134. */
  135. }
  136.  
  137. static void alarm_dfl()    /* hangup, generated when terminal disconnects */
  138. {
  139.    report_alarm( "alarm_dfl: A default signal 0 has been found" );
  140. }
  141.  
  142. static void alarm_hup()    /* hangup, generated when terminal disconnects */
  143. {
  144.    report_alarm( "alarm_hup: Someone just hanged up" );
  145. }
  146.  
  147. static void alarm_int()    /* interrupt, generated from terminal special char */
  148. {
  149.    report_alarm( "alarm_int: I was interrupted" );
  150. }
  151.  
  152. static void alarm_quit()     /* (*) quit, generated from terminal special char */
  153. {
  154.    report_alarm( "alarm_quit: I has been told to quit" );
  155. }
  156.  
  157. static void alarm_ill()     /* (*) illegal instruction (not reset when caught)*/
  158. {
  159.    report_alarm( "alarm_ill: I do not believe this, an illegal instruction" );
  160. }
  161.  
  162. static void alarm_segv()     /* (*) segmentation violation */
  163. {
  164.    report_alarm( "alarm_segv: Oops, I just VIOLATED someones toes" );
  165. }
  166.  
  167. static void alarm_sys()      /* (*) bad argument to system call */
  168. {
  169.    report_alarm( "alarm_sys: A system call does not like my parameters" );
  170. }
  171.  
  172. static void alarm_pipe()      /* write on a pipe with no one to read it */
  173. {
  174.    report_alarm( "alarm_pipe: A pipe is a TWO way communication, remember ?" );
  175. }
  176.  
  177. static void alarm_alrm()        /* alarm clock timeout */
  178. {
  179.    report_alarm( "alarm_alrm: The timer alarm is belling" );
  180. }
  181.  
  182. static void alarm_term()    /* software termination signal */
  183. {
  184.    report_alarm( "alarm_term: Why should I terminate" );
  185. }
  186.  
  187. static void alarm_cld()        /* (+) sent to parent on child stop or exit */
  188. {
  189.    report_alarm( "alarm_cld: Ohh, my child is dying" );
  190. }
  191.  
  192. static void alarm_pwr()    /* (+) power-fail restart */
  193. {
  194.    report_alarm( "alarm_pwr: Who pulled the power cord ???" );
  195. }
  196.  
  197. void catch_alarms()
  198. {
  199.     char    ident[] = "@(#) alarm.c 921014 catch_alarms(): Catch alarms and traps";
  200.  
  201.     signal( SIG_DFL, alarm_dfl );
  202.     signal( SIGHUP, alarm_hup );
  203.     signal( SIGINT, alarm_int );
  204.     signal( SIGQUIT, alarm_quit );
  205.     signal( SIGILL, alarm_ill );
  206.     signal( SIGSEGV, alarm_segv );
  207.     signal( SIGSYS, alarm_sys );
  208.     signal( SIGPIPE, alarm_pipe );
  209.     signal( SIGALRM, alarm_alrm );
  210.     signal( SIGTERM, alarm_term );
  211.     signal( SIGCHLD, alarm_cld );
  212.     signal( SIGPWR, alarm_pwr );
  213.  
  214.  
  215. }
  216.  
  217. main()
  218. {
  219.     char    ioarr[20], dummy[128];
  220.    char  ident[] = "@(#) alarm.c 921014 Test various alarms and traps";
  221.    int   status;
  222.  
  223.    catch_alarms();
  224.  
  225.    alarm( 60 );
  226.    errno = 0;
  227.     status = scanf( "%s", ioarr );
  228.    if ( status != 1 ) {
  229.       if (errno) {
  230.          sprintf( dummy, "scanf status=%d, errno=%d, errmsg=%s", status, errno, strerror(errno) );
  231.       }
  232.       else {
  233.          sprintf( dummy, "scanf status=%d", status );
  234.       }
  235.       report_alarm( dummy );
  236.    }
  237.     printf( "Input: %s<-\n", ioarr );
  238.  
  239. }
  240.  
  241.