Changeset 379bcaf4955fc4c5eacc375218033eb41602a152

Show
Ignore:
Timestamp:
10/03/10 21:45:16 (4 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1286142316 +0000
git-parent:

[634b4a3bb6507360b2be47824769d3a9740f533b]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1286142316 +0000
Message:

rework stratcon's startup sequence to look like noit's, refs #319

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/stratcond.c

    r634b4a3 r379bcaf  
    178178 
    179179static int child_main() { 
    180   char lockfile[PATH_MAX]; 
    181180  char conf_str[1024]; 
    182   char user[32], group[32]; 
    183   char *trace_dir = NULL; 
    184  
    185   /* First initialize logging, so we can log errors */ 
    186   noit_log_init(); 
    187   noit_log_stream_add_stream(noit_debug, noit_stderr); 
    188   noit_log_stream_add_stream(noit_error, noit_stderr); 
    189  
    190   /* Next load the configs */ 
    191   noit_conf_init(APPNAME); 
     181 
     182  /* Next (re)load the configs */ 
    192183  if(noit_conf_load(config_file) == -1) { 
    193184    fprintf(stderr, "Cannot load config: '%s'\n", config_file); 
     
    195186  } 
    196187 
    197   /* Acquire the lock so that we can throw an error if it doesn't work. 
    198    * If we've started -D, we'll have the lock. 
    199    * If not we will daemon and must reacquire the lock. 
    200    */ 
    201   lockfile[0] = '\0'; 
    202   if(noit_conf_get_stringbuf(NULL, "/" APPNAME "/@lockfile", 
    203                              lockfile, sizeof(lockfile))) { 
    204     if(noit_lockfile_acquire(lockfile) < 0) { 
    205       noitL(noit_stderr, "Failed to acquire lock: %s\n", lockfile); 
    206       exit(-1); 
    207     } 
    208   } 
    209  
    210   /* Reinitialize the logging system now that we have a config */ 
    211   snprintf(user, sizeof(user), "%d", getuid()); 
    212   snprintf(group, sizeof(group), "%d", getgid()); 
    213   if(noit_security_usergroup(droptouser, droptogroup, noit_true)) { 
    214     noitL(noit_stderr, "Failed to drop privileges, exiting.\n"); 
    215     exit(2); 
    216   } 
    217   noit_conf_log_init(APPNAME); 
    218   cli_log_switches(); 
    219   if(noit_security_usergroup(user, group, noit_true)) { 
    220     noitL(noit_stderr, "Failed to regain privileges, exiting.\n"); 
    221     exit(2); 
    222   } 
    223   if(debug) 
    224     noit_debug->enabled = 1; 
    225  
    226   if(!glider) noit_conf_get_string(NULL, "/" APPNAME "/watchdog/@glider", &glider); 
    227   noit_watchdog_glider(glider); 
    228   noit_conf_get_string(NULL, "/" APPNAME "/watchdog/@tracedir", &trace_dir); 
    229   if(trace_dir) noit_watchdog_glider_trace_dir(trace_dir); 
     188  noit_log_reopen_all(); 
    230189 
    231190  /* Lastly, run through all other system inits */ 
     
    298257 
    299258int main(int argc, char **argv) { 
    300   int fd; 
     259  int fd, lockfd = -1; 
     260  char lockfile[PATH_MAX]; 
     261  char user[32], group[32]; 
     262  char *trace_dir = NULL; 
    301263  parse_clargs(argc, argv); 
     264 
     265  noit_log_init(); 
     266  noit_log_stream_add_stream(noit_debug, noit_stderr); 
     267  noit_log_stream_add_stream(noit_error, noit_stderr); 
     268 
     269  /* Next load the configs */ 
     270  noit_conf_init(APPNAME); 
     271  if(noit_conf_load(config_file) == -1) { 
     272    fprintf(stderr, "Cannot load config: '%s'\n", config_file); 
     273    exit(-1); 
     274  } 
     275 
     276  /* Reinitialize the logging system now that we have a config */ 
     277  snprintf(user, sizeof(user), "%d", getuid()); 
     278  snprintf(group, sizeof(group), "%d", getgid()); 
     279  if(noit_security_usergroup(droptouser, droptogroup, noit_true)) { 
     280    noitL(noit_stderr, "Failed to drop privileges, exiting.\n"); 
     281    exit(-1); 
     282  } 
     283  noit_conf_log_init(APPNAME); 
     284  cli_log_switches(); 
     285  if(noit_security_usergroup(user, group, noit_true)) { 
     286    noitL(noit_stderr, "Failed to regain privileges, exiting.\n"); 
     287    exit(-1); 
     288  } 
     289  if(debug) 
     290    noit_debug->enabled = 1; 
     291 
     292  if(!glider) noit_conf_get_string(NULL, "/" APPNAME "/watchdog/@glider", &glider); 
     293  noit_watchdog_glider(glider); 
     294  noit_conf_get_string(NULL, "/" APPNAME "/watchdog/@tracedir", &trace_dir); 
     295  if(trace_dir) noit_watchdog_glider_trace_dir(trace_dir); 
    302296 
    303297  if(chdir("/") != 0) { 
     
    308302  noit_watchdog_prefork_init(); 
    309303 
     304  /* Acquire the lock so that we can throw an error if it doesn't work. 
     305   * If we've started -D, we'll have the lock. 
     306   * If not we will daemon and must reacquire the lock. 
     307   */ 
     308  lockfd = -1; 
     309  lockfile[0] = '\0'; 
     310  if(noit_conf_get_stringbuf(NULL, "/" APPNAME "/@lockfile", 
     311                             lockfile, sizeof(lockfile))) { 
     312    if((lockfd = noit_lockfile_acquire(lockfile)) < 0) { 
     313      noitL(noit_stderr, "Failed to acquire lock: %s\n", lockfile); 
     314      exit(-1); 
     315    } 
     316  } 
     317 
    310318  if(foreground) exit(child_main()); 
     319 
     320  /* This isn't inherited across forks... */ 
     321  if(lockfd >= 0) noit_lockfile_release(lockfd); 
    311322 
    312323  fd = open("/dev/null", O_RDWR); 
     
    318329  if(fork()) exit(0); 
    319330 
     331  /* Reacquire the lock */ 
     332  if(*lockfile) { 
     333    if(noit_lockfile_acquire(lockfile) < 0) { 
     334      noitL(noit_stderr, "Failed to acquire lock: %s\n", lockfile); 
     335      exit(-1); 
     336    } 
     337  } 
     338 
    320339  return noit_watchdog_start_child("stratcond", child_main, 0); 
    321340} 
  • src/utils/noit_watchdog.c

    r634b4a3 r379bcaf  
    5656void noit_watchdog_glider(const char *path) { 
    5757  glider_path = path; 
     58  if(glider_path) 
     59    noitL(noit_error, "Setting watchdog glider to '%s'\n", glider_path); 
    5860} 
    5961void noit_watchdog_glider_trace_dir(const char *path) { 
     
    128130      /* trace handlers */ 
    129131      noit_monitored_child_pid = getpid(); 
    130       if(glider_path) signal(SIGSEGV, glideme); 
     132      if(glider_path) { 
     133        noitL(noit_error, "catching faults with glider\n"); 
     134        signal(SIGSEGV, glideme); 
     135      } 
    131136      /* run the program */ 
    132137      exit(func());