IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4714


Ignore:
Timestamp:
Aug 5, 2005, 9:53:49 AM (21 years ago)
Author:
eugene
Message:

fixed some memory leaks, pushed extra init functions into lib inits

Location:
trunk/Ohana/src/opihi
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.basic/init.c

    r4689 r4714  
    7676  int i;
    7777
     78  InitCommands ();
     79  InitMacros ();
     80  InitBuffers ();
     81  InitVectors ();
     82  InitVariables ();
     83  InitLists ();
     84  InitOutfile ();
     85
    7886  for (i = 0; i < sizeof (cmds) / sizeof (Command); i++) {
    7987    AddCommand (&cmds[i]);
    8088  }
    81 
     89 
    8290}
  • trunk/Ohana/src/opihi/cmd.data/init.c

    r4703 r4714  
    215215  int i;
    216216
     217  InitGraph ();
     218  InitImage ();
     219  InitQueues ();
     220
    217221  for (i = 0; i < sizeof (cmds) / sizeof (Command); i++) {
    218222    AddCommand (&cmds[i]);
  • trunk/Ohana/src/opihi/dimm/dimm.c

    r4689 r4714  
    1212  auto_break = TRUE;
    1313
    14   Nlists = 0;
    15   ALLOCATE (lists, List, 1);
    16 
    17   /* init functions required by libraries */
    18   /* -libopihi */
    19   InitCommands ();
    20   InitMacros ();
    21   InitBuffers ();
    22   InitVectors ();
    23   InitVariables ();
    24 
    25   /* -libdisplay */
    26   InitGraph ();
    27   InitImage ();
    28 
    2914  /* load the commands used by this implementation */
    3015  InitBasic ();
    3116  InitData ();
    32   InitOutfile ();
    3317  InitAstro ();
    3418  InitDIMM ();
  • trunk/Ohana/src/opihi/dvo/dvo.c

    r4689 r4714  
    1212  auto_break = TRUE;
    1313
    14   Nlists = 0;
    15   ALLOCATE (lists, List, 1);
    16 
    17   /* init functions required by libraries */
    18   /* -libopihi */
    19   InitCommands ();
    20   InitMacros ();
    21   InitBuffers ();
    22   InitVectors ();
    23   InitVariables ();
    24 
    25   /* -libdisplay */
    26   InitGraph ();
    27   InitImage ();
    28 
    2914  /* load the commands used by this implementation */
    3015  InitBasic ();
    3116  InitData ();
    32   InitOutfile ();
    3317  InitAstro ();
    3418  InitDVO ();
  • trunk/Ohana/src/opihi/dvo2/dvo2.c

    r2598 r4714  
    77# define opihi_rcfile ".dvorc"
    88
    9 void InitBasic ();
    10 void InitData ();
    11 void InitAstro ();
    12 void InitDVO2 ();
    13 
    14 void welcome () {
    15   fprintf (stderr, "\n");
    16   fprintf (stderr, "Welcome to %s - %s\n\n", opihi_name, opihi_description);
    17 }
    18 
    199/* program-dependent initialization */
    2010void initialize (int argc, char **argv) {
    2111 
    22   FILE *f;
    23 
    2412  auto_break = TRUE;
    25 
    26   Nlists = 0;
    27   ALLOCATE (lists, List, 1);
    28 
    29   /* init functions required by libraries */
    30   /* -libopihi */
    31   InitCommands ();
    32   InitMacros ();
    33   InitBuffers ();
    34   InitVectors ();
    35   InitVariables ();
    36 
    37   /* -libdisplay */
    38   InitGraph ();
    39   InitImage ();
    4013
    4114  /* load the commands used by this implementation */
     
    4417  InitAstro ();
    4518  InitDVO2 ();
    46   InitOutfile ();
    4719
    4820  rl_readline_name = opihi_name;
     
    5224  set_str_variable ("PROMPT", opihi_prompt);
    5325  set_str_variable ("RCFILE", opihi_rcfile);
     26# ifdef HELPDIR_DEFAULT
     27  set_str_variable ("HELPDIR", MACRO_NAME(HELPDIR_DEFAULT));
     28# endif
    5429
    55   /* here we open the history file for append.  it this fails, we
    56      won't be able to write to it, warn the user.  otherwise, this
    57      creates the file readline will write to, if it did not exist */ 
    58 
    59   /* check history file */
    60   /* rewrite with fstat or stat */
    61   f = fopen (opihi_history, "a");
    62   if (f == NULL) /* no current history file here */
    63     fprintf (stderr, "can't save history.\n");
    64   else
    65     fclose (f);
    66  
    67   stifle_history (200);
    68   read_history (opihi_history);
     30  { /* check history file permission */
     31    FILE *f;
     32    f = fopen (opihi_history, "a");
     33    if (f == NULL) /* no current history file here */
     34      fprintf (stderr, "can't save history.\n");
     35    else
     36      fclose (f);
     37    stifle_history (200);
     38    read_history (opihi_history);
     39  }
    6940
    7041  signal (SIGINT, SIG_IGN);
     
    7243}
    7344
     45/* standard welcome message */
     46void welcome () {
     47  fprintf (stderr, "\n");
     48  fprintf (stderr, "Welcome to %s - %s\n\n", opihi_name, opihi_description);
     49}
     50
    7451/* add program-dependent exit functions here */
    7552void cleanup () {
    76   /* -libdisplay
     53  /* -libdisplay */
    7754  QuitImage ();
    78   QuitGraph (); */
     55  QuitGraph ();
    7956  return;
    8057}
  • trunk/Ohana/src/opihi/include/psched.h

    r4705 r4714  
    151151int CheckTasks ();
    152152int CheckSystem ();
     153int CheckController ();
    153154int CheckTimeRanges (TimeRange *ranges, int Nranges);
    154155int GetJobOutput (char *channel, int pid, IOBuffer *buffer, int Nbytes);
     
    156157int CheckControllerJobStatus (Job *job);
    157158int SubmitControllerJob (Job *job);
     159int DeleteControllerJob (Job *job);
     160Job *FindControllerJob (int JobID);
    158161int StartController ();
    159162int ControllerCommand (char *command, char *response, IOBuffer *buffer);
  • trunk/Ohana/src/opihi/include/shell.h

    r4704 r4714  
    5959int           is_loop                   PROTO((char *line));
    6060int           is_macro_create           PROTO((char *line));
     61void          InitLists                 PROTO(());
    6162
    6263void          InitCommands              PROTO(());
  • trunk/Ohana/src/opihi/lib.shell/ListOps.c

    r3922 r4714  
    11# include "opihi.h"
    22# include "macro.h"
     3
     4void InitLists () {
     5  Nlists = 0;
     6  ALLOCATE (lists, List, 1);
     7  return;
     8}
    39
    410/* return a new string consisting of the next line in the current list */
  • trunk/Ohana/src/opihi/mana/mana.c

    r4689 r4714  
    1212  auto_break = TRUE;
    1313
    14   Nlists = 0;
    15   ALLOCATE (lists, List, 1);
    16 
    17   /* init functions required by libraries */
    18   /* -libopihi */
    19   InitCommands ();
    20   InitMacros ();
    21   InitBuffers ();
    22   InitVectors ();
    23   InitVariables ();
    24 
    25   /* -libdisplay */
    26   InitGraph ();
    27   InitImage ();
    28 
    2914  /* load the commands used by this implementation */
    3015  InitBasic ();
    3116  InitData ();
    32   InitOutfile ();
    3317  InitAstro ();
    3418  InitMana ();
  • trunk/Ohana/src/opihi/pantasks/CheckController.c

    r4706 r4714  
    77  Job *job;
    88  IOBuffer buffer;
    9  
    109
    1110  /* get the list of completed jobs (exit / crash), update the job status */
    12 
    1311  if (!CheckControllerStatus()) return (TRUE);
    1412
     
    2119  }
    2220
     21  p = memstr (buffer.buffer, "USAGE: jobstack", buffer.Nbuffer);
     22  if (p != NULL) {
     23    FreeIOBuffer (&buffer);
     24    return (FALSE);
     25  }
     26
    2327  /** parse job list **/
    24   sscanf (buffer.buffer, "%*s %s", &Njobs);
     28  status = sscanf (buffer.buffer, "%*s %d", &Njobs);
     29  if (status != 1) {
     30    FreeIOBuffer (&buffer);
     31    return (FALSE);
     32  }
     33
    2534  p = buffer.buffer;
    26  
    2735  for (i = 0; i < Njobs; i++) {
    2836    q = strchr (p, '\n');
    2937    if (q == NULL) {
    3038      fprintf (stderr, "controller message error: incomplete job list\n");
    31       FreeIOBuffer (&buffer);
    3239      break;
    3340    }
    34     p = q++;
    35     sscanf (p, "%d", &JobID);
    36     job = FindJob (JobID);
     41    p = q + 1;
     42    status = sscanf (p, "%d", &JobID);
     43
     44    job = FindControllerJob (JobID);
    3745    if (job == NULL) {
    38       fprintf (stderr, "misplaced job? %d not in job list\n");
     46      fprintf (stderr, "misplaced job? %d not in EXIT job list\n", JobID);
    3947      continue;
    4048    }
     
    4250    CheckControllerJob (job);
    4351  }
    44     
     52 
    4553  /*** check CRASH jobs ***/
    46   InitIOBuffer (&buffer, 0x100);
     54  FlushIOBuffer (&buffer);
    4755  status = ControllerCommand ("jobstack crash", CONTROLLER_PROMPT, &buffer);
    4856  if (!status) {
     
    5058    return (FALSE);
    5159  }
     60  p = memstr (buffer.buffer, "USAGE: jobstack", buffer.Nbuffer);
     61  if (p != NULL) {
     62    FreeIOBuffer (&buffer);
     63    return (FALSE);
     64  }
    5265
    5366  /** parse job list **/
    54   sscanf (buffer.buffer, "%*s %s", &Njobs);
     67  status = sscanf (buffer.buffer, "%*s %d", &Njobs);
     68  if (status != 1) {
     69    FreeIOBuffer (&buffer);
     70    return (FALSE);
     71  }
     72
    5573  p = buffer.buffer;
    56  
    5774  for (i = 0; i < Njobs; i++) {
    5875    q = strchr (p, '\n');
    5976    if (q == NULL) {
    6077      fprintf (stderr, "controller message error: incomplete job list\n");
    61       FreeIOBuffer (&buffer);
    6278      break;
    6379    }
    64     p = q++;
    65     sscanf (p, "%d", &JobID);
    66     job = FindJob (JobID);
     80    p = q + 1;
     81   
     82    status = sscanf (p, "%d", &JobID);
     83    job = FindControllerJob (JobID);
    6784    if (job == NULL) {
    68       fprintf (stderr, "misplaced job? %d not in job list\n");
     85      fprintf (stderr, "misplaced job? %d not in CRASH job list\n", JobID);
    6986      continue;
    7087    }
     
    7289    CheckControllerJob (job);
    7390  }
     91  FreeIOBuffer (&buffer);
    7492  return (TRUE);
    7593}
  • trunk/Ohana/src/opihi/pantasks/CheckSystem.c

    r4706 r4714  
    88     eventually
    99  */
     10  struct timeval start, stop;
     11  double dtime;
     12 
     13  gettimeofday (&start, (void *) NULL);
     14  CheckTasks ();
     15  gettimeofday (&stop, (void *) NULL);
     16  dtime = DTIME (stop, start);
     17  if (VerboseMode()) fprintf (stderr, "check 1: %f seconds\n", dtime);
    1018
    11   CheckTasks ();
     19  gettimeofday (&start, (void *) NULL);
    1220  CheckJobs ();
     21  gettimeofday (&stop, (void *) NULL);
     22  dtime = DTIME (stop, start);
     23  if (VerboseMode()) fprintf (stderr, "check 2: %f seconds\n", dtime);
     24
     25  gettimeofday (&start, (void *) NULL);
    1326  CheckController ();
     27  gettimeofday (&stop, (void *) NULL);
     28  dtime = DTIME (stop, start);
     29  if (VerboseMode()) fprintf (stderr, "check 3: %f seconds\n", dtime);
     30
     31  gettimeofday (&start, (void *) NULL);
    1432  CheckControllerOutput ();
     33  gettimeofday (&stop, (void *) NULL);
     34  dtime = DTIME (stop, start);
     35  if (VerboseMode()) fprintf (stderr, "check 4: %f seconds\n", dtime);
     36
    1537  return (TRUE);
    1638}
  • trunk/Ohana/src/opihi/pantasks/ControllerOps.c

    r4706 r4714  
    186186  job[0].pid = atoi (string);
    187187  FreeIOBuffer (&buffer);
    188 
    189   InitIOBuffer (&job[0].stdout, 0x100);
    190   InitIOBuffer (&job[0].stderr, 0x100);
    191188  return (TRUE);
    192189}
     
    419416  InitIOBuffer (&buffer, 0x100);
    420417  status = ControllerCommand (cmd, CONTROLLER_PROMPT, &buffer);
     418  FreeIOBuffer (&buffer);
     419
    421420  ControllerStatus = FALSE;
    422421  result = waitpid (ControllerPID, &waitstatus, WNOHANG);
     
    429428  close (stdout_cntl);
    430429  close (stderr_cntl);
    431 
    432   return (TRUE);
    433 }
     430  FreeIOBuffer (&stdout_buffer);
     431  FreeIOBuffer (&stderr_buffer);
     432
     433  return (TRUE);
     434}
  • trunk/Ohana/src/opihi/pantasks/JobOps.c

    r4706 r4714  
    3939  for (i = 0; i < Njobs; i++) {
    4040    if (jobs[i][0].JobID == JobID) {
     41      return (jobs[i]);
     42    }
     43  }
     44  return (NULL);
     45
     46
     47/* return job with given controller Job ID */
     48Job *FindControllerJob (int JobID) {
     49
     50  int i;
     51
     52  /* return job with matching JobID */
     53  for (i = 0; i < Njobs; i++) {
     54    if (jobs[i][0].mode == JOB_LOCAL) continue;
     55    if (jobs[i][0].pid  == JobID) {
    4156      return (jobs[i]);
    4257    }
     
    96111     need to have matched entries to these quantites in the job structure */
    97112
     113  InitIOBuffer (&job[0].stdout, 0x100);
     114  InitIOBuffer (&job[0].stderr, 0x100);
     115
    98116  jobs[Njobs] = job;
    99117  Njobs ++;
     
    117135  }
    118136  free (job[0].argv);
     137
     138  FreeIOBuffer (&job[0].stdout);
     139  FreeIOBuffer (&job[0].stderr);
     140  free (job);
    119141  return;
    120142}
     
    161183  gettimeofday (&job[0].start, (void *) NULL);
    162184  job[0].last = job[0].start;
    163  
     185  job[0].state = JOB_PENDING;
    164186  return (TRUE);
    165187}
  • trunk/Ohana/src/opihi/pantasks/LocalJob.c

    r4697 r4714  
    144144  job[0].pid = pid;
    145145
    146   InitIOBuffer (&job[0].stdout, 0x100);
    147   InitIOBuffer (&job[0].stderr, 0x100);
    148146  return (TRUE);
    149147
  • trunk/Ohana/src/opihi/pantasks/controller_host.c

    r4706 r4714  
    2020  if (status) fwrite (buffer.buffer, 1, buffer.Nbuffer, stderr);
    2121  FreeIOBuffer (&buffer);
    22 
     22  return (TRUE);
    2323}
  • trunk/Ohana/src/opihi/pantasks/init.c

    r4705 r4714  
    5353  int i;
    5454
     55  InitTasks ();
     56  InitJobs ();
     57  InitJobIDs ();
     58
    5559  for (i = 0; i < sizeof (cmds) / sizeof (Command); i++) {
    5660    AddCommand (&cmds[i]);
  • trunk/Ohana/src/opihi/pantasks/psched.c

    r4705 r4714  
    1212  auto_break = TRUE;
    1313
    14   Nlists = 0;
    15   ALLOCATE (lists, List, 1);
    16 
    17   /* init functions required by libraries */
    18   /* -libopihi */
    19   InitCommands ();
    20   InitMacros ();
    21   InitBuffers ();
    22   InitVectors ();
    23   InitVariables ();
    24 
    25   /* -libdisplay */
    26   InitGraph ();
    27   InitImage ();
    28 
    2914  /* load the commands used by this implementation */
    3015  InitBasic ();
    3116  InitData ();
    32   InitOutfile ();
    3317  InitPsched ();
    34   InitTasks ();
    35   InitJobs ();
    36   InitJobIDs ();
    3718
    3819  rl_readline_name = opihi_name;
  • trunk/Ohana/src/opihi/pclient/pclient.c

    r4691 r4714  
    1212  auto_break = TRUE;
    1313
    14   Nlists = 0;
    15   ALLOCATE (lists, List, 1);
    16 
    17   /* init functions required by libraries */
    18   /* -libshell */
    19   InitCommands ();
    20   InitMacros ();
    21   InitBuffers ();
    22   InitVectors ();
    23   InitVariables ();
    24 
    25   /* -libdata */
    26   InitGraph ();
    27   InitImage ();
    28 
    2914  /* load the commands used by this implementation */
    3015  InitBasic ();
    31   InitOutfile ();
    3216  InitPclient ();
    3317  InitChild ();
  • trunk/Ohana/src/opihi/pcontrol/Makefile

    r4706 r4714  
    5454$(SDIR)/jobstack.$(ARCH).o \
    5555$(SDIR)/kill.$(ARCH).o \
     56$(SDIR)/pulse.$(ARCH).o \
    5657$(SDIR)/status.$(ARCH).o \
    5758$(SDIR)/stdout.$(ARCH).o \
  • trunk/Ohana/src/opihi/pcontrol/init.c

    r4706 r4714  
    77int jobstack    PROTO((int, char **));
    88int kill_pc     PROTO((int, char **));
     9int pulse       PROTO((int, char **));
    910int status      PROTO((int, char **));
    1011int stderr_pc   PROTO((int, char **));
     
    1920  {"jobstack",  jobstack,  "list jobs for a single stack"},
    2021  {"kill",      kill_pc,   "kill job"},
     22  {"pulse",     pulse,     "set system pulse"},
    2123  {"status",    status,    "get system status"},
    2224  {"stderr",    stderr_pc, "get stderr buffer for job"},
  • trunk/Ohana/src/opihi/pcontrol/jobstack.c

    r4706 r4714  
    66  Stack *stack;
    77  Job *job;
    8   Host *host;
    9   int JobID, HostID;
    108
    11   if (argc != 3) {
     9  if (argc != 2) {
    1210    fprintf (stdout, "USAGE: jobstack (jobstack)\n");
    1311    fprintf (stdout, "       (jobstack) : pending, busy, exit, crash, hung, done\n");
     
    2725    job = stack[0].object[i];
    2826    /* PrintID (stdout, job[0].JobID); */
    29     fprintf (stdout, "%d ", job[0].JobID);
     27    fprintf (stdout, "%lld ", job[0].JobID);
    3028    fprintf (stdout, "%s  %s\n", job[0].argv[0], job[0].hostname);
    3129  }
  • trunk/Ohana/src/opihi/pcontrol/pcontrol.c

    r4691 r4714  
    1212  auto_break = TRUE;
    1313
    14   Nlists = 0;
    15   ALLOCATE (lists, List, 1);
    16 
    17   /* init functions required by libraries */
    18   /* -libshell */
    19   InitCommands ();
    20   InitMacros ();
    21   InitBuffers ();
    22   InitVectors ();
    23   InitVariables ();
    24 
    25   /* -libdata */
    26   InitGraph ();
    27   InitImage ();
    28 
    2914  /* load the commands used by this implementation */
    3015  InitBasic ();
    31   InitOutfile ();
    3216  InitPcontrol ();
    3317
  • trunk/Ohana/src/opihi/scripts/psched.pro

    r4705 r4714  
    77task test
    88  command partest
    9   periods -poll 1.0
    10   periods -exec 2.0
     9  periods -poll 0.1
     10  periods -exec 0.1
    1111  periods -timeout 10.0
    12   nmax 15
     12  nmax 5
    1313  host anyhost
    1414
     
    1616  task.exit 0
    1717    # echo "task exit 0"
    18     queuesize stdout -var Nstdout
    19     for i 0 $Nstdout
    20       queuepop stdout -var line
    21       queuepush results "$line"
    22     end
     18    queuedelete stdout
     19    queuedelete stderr
     20    memory leaks
     21#   queuesize stdout -var Nstdout
     22#    for i 0 $Nstdout
     23#      queuepop stdout -var line
     24#      queuepush results "$line"
     25#    end
    2326  end
    2427
  • trunk/Ohana/src/opihi/scripts/sched.pro

    r4697 r4714  
    1 
    2 # controller host alala
    31
    42task test
     
    97  # trange 07:09 07:10
    108  # trange -exclude 07:09:30 07:09:45
    11   nmax 1
     9  nmax 5
    1210  host local
    1311  # host localhost
     
    2018  # stdout / stderr lines on named queues
    2119  task.exit 0
    22     echo "task exit 0"
    23     queuesize stdout
    24     queuesize stderr
     20#    echo "task exit 0"
     21#    queuesize stdout
     22#    queuesize stderr
     23    queuedelete stdout
     24    queuedelete stderr
     25    memory leaks
    2526  end
    2627
Note: See TracChangeset for help on using the changeset viewer.