IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 18, 2010, 12:49:05 PM (16 years ago)
Author:
eugene
Message:

merging changes from trunk into branches/pap

Location:
branches/pap
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/Ohana

  • branches/pap/Ohana/src/opihi/pantasks/pantasks_server.c.in

    r23530 r28003  
    1313*/
    1414
     15void special_init (int *argc, char **argv);
     16
    1517/* program-dependent initialization */
    1618int main (int argc, char **argv) {
    1719 
    18   char log_stdout[128], log_stderr[128];
     20  char log_stdout[1024], log_stderr[1024];
    1921  pthread_t JobsAndTasksThread;
    2022  pthread_t clientsThread;
     
    2325  SockAddress Address;
    2426
    25   general_init (&argc, argv);
     27  strcpy (log_stdout, "stdout");
     28  strcpy (log_stderr, "stderr");
    2629
    27   // define server output log files
     30  special_init (&argc, argv);
     31
     32  //
     33  stdin = freopen ("/dev/zero", "r", stdin);
     34
     35  // this block redirects the actual stderr, stdout steams to the output files
    2836  if (VarConfig ("PANTASKS_SERVER_STDOUT", "%s", log_stdout) != NULL) {
     37    if (strcmp (log_stdout, "stdout")) {
     38      stdout = freopen (log_stdout, "a", stdout);
     39      if (!stdout) {
     40        fprintf (stderr, "failed to open %s for output\n", log_stdout);
     41        exit (1);
     42      }
     43    }
     44  }
     45  if (VarConfig ("PANTASKS_SERVER_STDERR", "%s", log_stderr) != NULL) {
     46    if (strcmp (log_stderr, "stderr")) {
     47      stderr = freopen (log_stderr, "a", stderr);
     48      if (!stderr) {
     49        fprintf (stdout, "failed to open %s for error output\n", log_stderr);
     50        exit (1);
     51      }
     52    }
     53  }
     54
     55  /* init for main (or only) thread */
     56  gprintInit ();
     57
     58  // this block changes the target of the gprint output streams
     59  if (strcmp (log_stdout, "stdout")) {
    2960      gprintSetFileThisThread (GP_LOG, log_stdout);
    3061  }
    31   if (VarConfig ("PANTASKS_SERVER_STDERR", "%s", log_stderr) != NULL) {
     62  if (strcmp (log_stderr, "stderr")) {
    3263      gprintSetFileThisThread (GP_ERR, log_stderr);
    3364  }
     
    4172  InitBasic ();
    4273  InitData ();
     74  InitAstro ();
    4375  InitPantasksServer ();
    4476
     
    105137void welcome () { }
    106138void program_init (int *argc, char **argv) {}
     139
     140// I need to do things in a different order here to have config / freopen / gprint sequenced correctly
     141void special_init (int *argc, char **argv) {
     142
     143  /* init srand for rnd numbers elsewhere */
     144  long A, B;
     145  A = time(NULL);
     146  for (B = 0; A == time(NULL); B++);
     147  srand48(B);
     148 
     149  /* set signals */
     150  signal (SIGINT, SIG_IGN);
     151
     152  init_error ();
     153
     154  /* load config data (.ptolemyrc) */
     155  if (!ConfigInit (argc, argv)) {
     156    fprintf (stderr, "can't find (.ptolemyrc,ptolemy.rc) config file. some functions will be unavailable\n");
     157  }
     158
     159  return;
     160}
Note: See TracChangeset for help on using the changeset viewer.