Branch: Tag:

1998-07-13

1998-07-13 20:13:38 by David Hedbor <david@hedbor.org>

Fixed ABS. Before it wouldn't start after reboot or when the variable was
changed, so basically it was never engaged.

Rev: server/base_server/roxen.pike:1.219

1: - constant cvs_version = "$Id: roxen.pike,v 1.218 1998/07/12 00:22:44 neotron Exp $"; + constant cvs_version = "$Id: roxen.pike,v 1.219 1998/07/13 20:13:38 neotron Exp $";      // ABS and suicide systems contributed freely by Francesco Chemolli   
80:   object euid_egid_lock = Thread.Mutex();   #endif /* THREADS */    -  - //these mixed's are used by the ABS and suicide options, - //to determine whether a call_out is active. - static mixed abs_call_out=0, suicide_call_out=0; -  +    int privs_level;   int die_die_die;   
1164:       return 0;   } -  - void restart_if_stuck () { -  abs_call_out=0; -  if (!QUERY(ABS_engage)) + static int abs_started; + void restart_if_stuck (int force) { +  remove_call_out(restart_if_stuck); +  if (!(QUERY(abs_engage) || force))    return; -  abs_call_out=call_out (restart_if_stuck,10); +  if(!abs_started) { +  abs_started = 1; +  werror("Anti-Block System Enabled.\n"); +  } +  call_out (restart_if_stuck,10);    signal(signum("SIGALRM"),lambda( int n ) { -  perror ((ctime(time())-"\n")+ -  "**** ABS engaged! Restarting. ***\n"); +  werror ("**** %s: ABS engaged! Restarting. \n", +  (ctime(time())-"\n"));    fork_or_quit();    }); -  alarm (60*QUERY(ABS_timeout)+10); +  alarm (60*QUERY(abs_timeout)+10);   }      void post_create () { -  if (QUERY(ABS_engage)) -  abs_call_out=call_out (restart_if_stuck,10); +  if (QUERY(abs_engage)) +  call_out (restart_if_stuck,10);    if (QUERY(suicide_engage)) -  suicide_call_out=call_out (restart,60*60*24*QUERY(suicide_timeout)); +  call_out (restart,60*60*24*QUERY(suicide_timeout));   }      void create()
1852:    TYPE_TEXT|VAR_MORE, "A short string describing this server");   #endif /* ENABLE_NEIGHBOURHOOD */    -  setvars(retrieve("Variables", 0)); -  -  if(QUERY(_v) < CONFIGURATION_FILE_LEVEL) -  { -  update_global_vars(retrieve("Variables", 0)->_v?QUERY(_v):0); -  QUERY(_v) = CONFIGURATION_FILE_LEVEL; -  store("Variables", variables, 0, 0); -  set("_v", CONFIGURATION_FILE_LEVEL); -  } -  -  for(p = 1; p < argc; p++) -  { -  string c, v; -  if(sscanf(argv[p],"%s=%s", c, v) == 2) -  if(variables[c]) -  variables[c][VAR_VALUE]=compat_decode_value(v); -  else -  perror("Unknown variable: "+c+"\n"); -  } -  docurl=QUERY(docurl2); -  -  globvar("ABS_engage", 0, "Anti-Block-System: Enable", TYPE_FLAG|VAR_MORE, +  globvar("abs_engage", 0, "Anti-Block-System: Enable", TYPE_FLAG|VAR_MORE,    "If set, it will enable the anti-block-system. "    "This will restart the server after a configurable number of minutes if it "    "locks up. If you are running in a single threaded environment heavy calculations "
1881:    "cause the server to reboot, since only one thread is blocked. In general there is "    "no harm in having this option enabled. ");    -  globvar("ABS_timeout", 5, "Anti-Block-System: Timeout", TYPE_INT_LIST, +  globvar("abs_timeout", 5, "Anti-Block-System: Timeout", TYPE_INT_LIST,    "If the server is unable to accept connection for this many "    "minutes, it will be restarted. You need to find a balance: "    "if set too low, the server will be restarted even if it's doing "    "legal things (like generating many images), if set too high you will "    "have long downtimes.",    ({1,2,3,4,5,10,15}), -  lambda() {return !QUERY(ABS_engage);} +  lambda() {return !QUERY(abs_engage);}    );       globvar ("suicide_engage",
1909:    ({1,2,3,4,5,6,7,14,30}),    lambda(){return !QUERY(suicide_engage);}    ); +  +  setvars(retrieve("Variables", 0)); +  +  if(QUERY(_v) < CONFIGURATION_FILE_LEVEL) +  { +  update_global_vars(retrieve("Variables", 0)->_v?QUERY(_v):0); +  QUERY(_v) = CONFIGURATION_FILE_LEVEL; +  store("Variables", variables, 0, 0); +  set("_v", CONFIGURATION_FILE_LEVEL);    }    -  +  for(p = 1; p < argc; p++) +  { +  string c, v; +  if(sscanf(argv[p],"%s=%s", c, v) == 2) +  if(variables[c]) +  variables[c][VAR_VALUE]=compat_decode_value(v); +  else +  perror("Unknown variable: "+c+"\n"); +  } +  docurl=QUERY(docurl2);    -  + }    -  +  +    // To avoid stack error :-) This is really a bug in Pike, that is   // probably fixed by now, but since I needed a catch() as well, I   // never did come around to removing the hack.
2520:   }      // Called from the configuration interface. - string check_variable(string name, string value) + string check_variable(string name, mixed value)   {    switch(name)    {
2546:    return "The URL should follow this format: protocol://computer[:port]/";    break;    -  case "ABS_engage": -  if (value) { -  if (!abs_call_out) -  restart_if_stuck(); -  } else { -  if (abs_call_out) { -  remove_call_out(abs_call_out); -  abs_call_out=0; -  } -  } +  case "abs_engage": +  if (value) +  restart_if_stuck(1); +  else +  remove_call_out(restart_if_stuck);    break;       case "suicide_engage": -  if (value) { -  if (!suicide_call_out) -  suicide_call_out=call_out(restart,60*60*24*QUERY(suicide_timeout)); -  } else { -  if (suicide_call_out) { -  remove_call_out(suicide_call_out); -  suicide_call_out=0; -  } -  } +  if (value) +  call_out(restart,60*60*24*QUERY(suicide_timeout)); +  else +  remove_call_out(restart);    break;    }   }