source: npl/commonservers/daemontools/supervise.patch @ c5c522c

gcc484ntopperl-5.22
Last change on this file since c5c522c was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 2.7 KB
  • supervise.c

    old new  
    1515#include "iopause.h"
    1616#include "taia.h"
    1717#include "deepsleep.h"
     18//syn3 protection mechanism (C)zah Drent
     19#include "timesaver.h"
    1820
     21//DatuX hack ivm time checker  getal bevat seconden
     22#define MaxRefreshTime 3600
    1923#define FATAL "supervise: fatal: "
    2024#define WARNING "supervise: warning: "
    2125
     
    111115
    112116void doit(void)
    113117{
     118
    114119  iopause_fd x[2];
    115120  struct taia deadline;
    116121  struct taia stamp;
    117122  int wstat;
    118123  int r;
    119124  char ch;
    120 
     125  int bytes;
    121126  announce();
    122 
    123127  for (;;) {
    124128    if (flagexit && !pid) return;
    125 
    126129    sig_unblock(sig_child);
    127 
    128130    x[0].fd = selfpipe[0];
    129131    x[0].events = IOPAUSE_READ;
    130132    x[1].fd = fdcontrol;
    131133    x[1].events = IOPAUSE_READ;
    132134    taia_now(&stamp);
    133     taia_uint(&deadline,3600);
     135    taia_uint(&deadline,MaxRefreshTime);
    134136    taia_add(&deadline,&stamp,&deadline);
     137   
     138    if (!(TimeCheck(0,NULL)) )
     139    {
     140         //syn3 mag niet meer gebruikt worden, bovenstaand word genegeerd.
     141          //verder gooien de service down als dat nog niet zo is
     142          if (pid)
     143          {
     144                //dit stuk is een copy/paste van het bovenstaande 'd' commando :-D
     145                flagwant = 1;
     146                flagwantup = 0;
     147                if (pid) { kill(pid,SIGTERM); kill(pid,SIGCONT); flagpaused = 0; }
     148                announce();
     149          }
     150    }
     151   
     152    //wacht totdat er nieuwe input is, OF op een timeout
    135153    iopause(x,2,&deadline,&stamp);
    136 
    137154    sig_block(sig_child);
    138 
    139     while (read(selfpipe[0],&ch,1) == 1)
    140       ;
    141 
     155    //kijk of de 'selfpipe' (wtf) data heeft
     156    while (read(selfpipe[0],&ch,1) == 1) ;
    142157    for (;;) {
    143158      r = wait_nohang(&wstat);
    144159      if (!r) break;
     
    152167        break;
    153168      }
    154169    }
    155 
    156     if (read(fdcontrol,&ch,1) == 1)
     170    //lees ALTIJD de control pipe (ivm opstoppingen)
     171    bytes=read(fdcontrol,&ch,1);
     172   
     173  //mag syn3 gebruik worden (x mag altijd, ivm registratie)?
     174  if (TimeCheck(0,NULL) || ch=='x')
     175  {
     176    //ja, dus handel alles af zoals normaal:
     177    if (bytes == 1 )
    157178      switch(ch) {
    158179        case 'd':
    159180          flagwant = 1;
     
    202223          announce();
    203224          break;
    204225      }
     226    }
     227    else
     228    {
     229          //syn3 mag niet meer gebruikt worden, bovenstaand word genegeerd.
     230          //verder gooien de service down als dat nog niet zo is
     231          if (pid)
     232          {
     233                //dit stuk is een copy/paste van het bovenstaande 'd' commando :-D
     234                flagwant = 1;
     235                flagwantup = 0;
     236                if (pid) { kill(pid,SIGTERM); kill(pid,SIGCONT); flagpaused = 0; }
     237                announce();
     238          }
     239    }
    205240  }
    206241}
    207242
     
    257292  if (fdok == -1)
    258293    strerr_die4sys(111,FATAL,"unable to read ",dir,"/supervise/ok: ");
    259294  coe(fdok);
    260 
    261295  if (!flagwant || flagwantup) trystart();
    262 
    263296  doit();
    264297  announce();
    265298  _exit(0);
Note: See TracBrowser for help on using the repository browser.