home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / pmcron03.zip / cron_det.c < prev    next >
C/C++ Source or Header  |  1996-05-09  |  11KB  |  202 lines

  1. /* Copyright (c) 1995 Florian Große-Coosmann, RCS section at the eof         */
  2. /* This is the non PM frontend. This program type is still in testing.       */
  3. /* See the PM frontend for more information. It should be preferred for OS/2.*/
  4. /* Most important mistake: It can't "start" a program (no DOS, VIO sessions  */
  5. /* etc)                                                                      */
  6. /* Many interesting functions belonging to this frontend are placed in the   */
  7. /* module cronmain.c, since they are shared with the cron_pm.c module.       */
  8. #define INCL_NOCOMMON
  9. #define INCL_DOSSEMAPHORES
  10.  
  11. #include <os2.h>
  12.  
  13. #include <io.h>
  14. #include <stdarg.h>
  15. #include <signal.h>
  16. #include "server.h"
  17.  
  18. /*****************************************************************************/
  19. /*  function name : DetachedNewProgramStatus                                 */
  20. /*                                                                           */
  21. /*  arguments     : ID of the resource string which should be display as     */
  22. /*                  the new program status                                   */
  23. /*                                                                           */
  24. /*  description   : displays the new program status (normal, at startup,     */
  25. /*                  etc.) on the program status line.                        */
  26. /*                                                                           */
  27. /*  note          : not used in the non PM version                           */
  28. /*****************************************************************************/
  29. void DetachedNewProgramStatus(ULONG NewStatus)
  30. {
  31. }
  32.  
  33. /*****************************************************************************/
  34. /*  function name : DetachedNewStartTime                                     */
  35. /*                                                                           */
  36. /*  arguments     : time of the job that will be started next.               */
  37. /*                                                                           */
  38. /*  description   : displays the time of the next starting job on the        */
  39. /*                  related display line. The time may be (time_t) -1. In    */
  40. /*                  this case there are either no periodically running       */
  41. /*                  jobs or no job time is in the computing distance (24-    */
  42. /*                  48 hours)                                                */
  43. /*                                                                           */
  44. /*  note          : not used in the non PM version                           */
  45. /*****************************************************************************/
  46. void DetachedNewStartTime(time_t time)
  47. {
  48. }
  49.  
  50. /*****************************************************************************/
  51. /*  function name : DetachedNewOutputFile                                    */
  52. /*                                                                           */
  53. /*  description   : displays the current output file on the related          */
  54. /*                  display line.                                            */
  55. /*                                                                           */
  56. /*  note          : not used in the non PM version                           */
  57. /*****************************************************************************/
  58. void DetachedNewOutputFile(void)
  59. {
  60. }
  61.  
  62. /*****************************************************************************/
  63. /*  function name : DetachedJobsModified                                     */
  64. /*                                                                           */
  65. /*  description   : Send the notebook dialog "Crontabs" a WM_USER. This      */
  66. /*                  will advise it to refresh since the list of jobs has     */
  67. /*                  been changed.                                            */
  68. /*                                                                           */
  69. /*  note          : not used in the non PM version                           */
  70. /*****************************************************************************/
  71. void DetachedJobsModified(void)
  72. {
  73. }
  74.  
  75. /*****************************************************************************/
  76. /*  function name : DetachedStopPM                                           */
  77. /*                                                                           */
  78. /*  description   : Send the PM window a WM_CLOSE. The program should        */
  79. /*                  terminate. The window has already received a WM_CLOSE    */
  80. /*                  and will die now since StopPM is called from the         */
  81. /*                  daemon thread.                                           */
  82. /*                                                                           */
  83. /*  note          : not used in the non PM version                           */
  84. /*****************************************************************************/
  85. void DetachedStopPM(void)
  86. {
  87. }
  88.  
  89. /*****************************************************************************/
  90. /*  function name : XMessage                                                 */
  91. /*                                                                           */
  92. /*  arguments     : see printf                                               */
  93. /*                                                                           */
  94. /*  description   : like Message buts append \n to the message.              */
  95. /*****************************************************************************/
  96. static void XMessage(const char *fmt,...)
  97. {
  98.    va_list marker;
  99.    if ((ProgramFlags & PRG_OUTPUT_IS_NUL) || (out == NULL))
  100.       return;
  101.    BlockOutput();
  102.    fputs(GetTimeString(),out);
  103.    va_start(marker,fmt);
  104.    vfprintf(out,fmt,marker);
  105.    va_end(marker);
  106.    putc('\n',out);
  107.    fflush(out);
  108.    UnBlockOutput();
  109. }
  110.  
  111. /*****************************************************************************/
  112. /*  function name : DetachedError                                            */
  113. /*                                                                           */
  114. /*  arguments     : string describing an error, owner of the error window    */
  115. /*                                                                           */
  116. /*  description   : prints the error string into the output file. The HWND   */
  117. /*                  parameter is for the PM version only.                    */
  118. /*****************************************************************************/
  119. void DetachedError(const char *s,HWND dummy)
  120. {
  121.    XMessage(s);
  122.    Dprintf((char *) s);
  123. }
  124.  
  125. /*****************************************************************************/
  126. /*  function name : DetachedFatalError                                       */
  127. /*                                                                           */
  128. /*  arguments     : see Error.                                               */
  129. /*                                                                           */
  130. /*  description   : see Error but terminates the program.                    */
  131. /*****************************************************************************/
  132. void DetachedFatalError(const char *s,HWND dummy)
  133. {
  134.    Error(s,dummy);
  135.    exit(-1);
  136. }
  137.  
  138. /*****************************************************************************/
  139. /*  function name : DetachedStop                                             */
  140. /*                                                                           */
  141. /*  arguments     : signal number generated by the runtime system            */
  142. /*                                                                           */
  143. /*  description   : This is a signal routine. This routine will shut down    */
  144. /*                  the program gracefully if the user or the system sends   */
  145. /*                  a signal (SIG_TERM, ^C or ^Break)                        */
  146. /*                  On the first call the programm will be stoped normally   */
  147. /*                  (with atexit execution in the cron thread). On the       */
  148. /*                  second call the program dies with exit since we can      */
  149. /*                  assume that the user has detected an error in the        */
  150. /*                  atexit exeution and wants an emergency stop.             */
  151. /*                  We must be very careful. If the signal is SIG_TERM       */
  152. /*                  the runtime system will stop the program on              */
  153. /*                  return. This isn't acceptable. Therefore we need the     */
  154. /*                  use of longjmp.                                          */
  155. /*                                                                           */
  156. /*  note          : don't call directly                                      */
  157. /*****************************************************************************/
  158. void DetachedStop(int code)
  159. {
  160.    static int first = 1;
  161.    if (first) {                         /* first call?                       */
  162.       first = 0;
  163.       GlobalStop++;                     /* show other threads this circum-   */
  164.                                         /* stance                            */
  165.       if (CronSem != (HEV) 0)           /* cron thread alive? awake it!      */
  166.          DosPostEventSem(CronSem);      /* let atexit execution run          */
  167.       if (pipehandle != -1)             /* Pipe open? close it, maybe it has */
  168.          close(pipehandle);             /* blocked the joblist               */
  169.       pipehandle = -1;
  170.       signal(code,SIG_ACK);
  171.       if (SetJumpEnabled)               /* can we use longjmp?               */
  172.          longjmp(PrgEnd,1);
  173.       else
  174.          exit(0);
  175.    }
  176.                                         /* else called twice                 */
  177.    signal(code,SIG_IGN);
  178.    if ((ProgramFlags & PRG_OUTPUT_IS_NUL) || (out == NULL))
  179.       exit(0);
  180.    fputs(GetTimeString(),out);
  181.    fputs(Get(IDS_DieOnSigSig),out);
  182.    putc('\n',out);
  183.    fflush(out);
  184.    exit(0);
  185. }
  186.  
  187. /* RCS depending informations
  188.  *
  189.  * $Name: Version121 $
  190.  *
  191.  * $Log: cron_det.c $
  192.  * Revision 1.2  1995/02/20 12:53:23  Florian
  193.  * All dialogs are placed into a notebook.
  194.  * Some bugs fixed.
  195.  *
  196.  * Revision 1.1  1995/02/03 10:42:23  Florian
  197.  * Initial revision
  198.  *
  199.  *
  200.  */
  201. static char rcsid[] = "@(#)$Id: cron_det.c 1.2 1995/02/20 12:53:23 Florian Rel $";
  202.