IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27611


Ignore:
Timestamp:
Apr 5, 2010, 3:47:36 PM (16 years ago)
Author:
eugene
Message:

pendatic checking fscan, system, and mkstemp return values

Location:
trunk/Ohana/src
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/elixir/src/RemoteOps.c

    r10336 r27611  
    2020  }
    2121  sprintf (line, "kill -USR1 %d\n", pid);
    22   write (wsock, line, strlen (line));
     22  if (write (wsock, line, strlen (line)) != strlen(line)) {
     23    fprintf (stderr, "error sending signal\n");
     24    exit (1);
     25  }
    2326
    2427  for (i = 0; i < 100; i++) {
     
    4952  }
    5053  sprintf (line, "kill -TERM %d\n", pid);
    51   write (wsock, line, strlen (line));
     54  if (write (wsock, line, strlen (line)) != strlen(line)) {
     55    fprintf (stderr, "error sending signal\n");
     56    exit (1);
     57  }
    5258
    5359  for (i = 0; i < 100; i++) {
     
    7581
    7682  sprintf (response, "%s.XXXXXX", msgfile);
    77   mkstemp (response);
     83  if (mkstemp (response) == -1) {
     84    fprintf (stderr, "can't make temp file\n");
     85    exit (1);
     86  }
    7887  sprintf (message, "STATUS %s", response);
    7988  if (VERBOSE) fprintf (stderr, "sending message: %s\n", message);
     
    8695  }
    8796  sprintf (line, "kill -USR2 %d\n", pid);
    88   write (wsock, line, strlen (line));
     97  if (write (wsock, line, strlen (line)) != strlen(line)) {
     98    fprintf (stderr, "error sending signal\n");
     99    exit (1);
     100  }
    89101
    90102  /* wait (2 sec) for file to exist, then try to read it */
     
    146158  /* send TERM signal */
    147159  sprintf (line, "kill -TERM %d\n", pid);
    148   write (wsock, line, strlen (line));
     160  if (write (wsock, line, strlen (line)) != strlen(line)) {
     161    fprintf (stderr, "error sending signal\n");
     162    exit (1);
     163  }
    149164
    150165  /* wait for cleanup to finish */
     
    159174  /* kill meanly */
    160175  sprintf (line, "kill -KILL %d", pid);
    161   write (wsock, line, strlen (line));
     176  if (write (wsock, line, strlen (line)) != strlen(line)) {
     177    fprintf (stderr, "error sending signal\n");
     178    exit (1);
     179  }
     180
    162181  unlink (pidfile);
    163182
     
    165184 success:
    166185  sprintf (line, "exit\n");
    167   write (wsock, line, strlen(line));
     186  if (write (wsock, line, strlen (line)) != strlen(line)) {
     187    fprintf (stderr, "error sending signal\n");
     188    exit (1);
     189  }
    168190  close (wsock);
    169191  close (rsock);
     
    174196int LoadPID (char *file, pid_t *pid, char *username, char *machine) {
    175197
     198  int t1, t2, t3;
    176199  FILE *f;
    177200
     
    181204  }
    182205
    183   fscanf (f, "%*s %d", pid);
    184   fscanf (f, "%*s %s", username);
    185   fscanf (f, "%*s %s", machine);
     206  t1 = fscanf (f, "%*s %d", pid);
     207  t2 = fscanf (f, "%*s %s", username);
     208  t3 = fscanf (f, "%*s %s", machine);
     209  if ((t1 != 1) || (t2 != 2) || (t3 != 1)) {
     210    fprintf (stderr, "error reading pid info\n");
     211  }
    186212  fclose (f);
    187213
  • trunk/Ohana/src/gastro/src/gcenter.c

    r5386 r27611  
    7979    fprintf (stderr, "plotting %d points\n", Nvect);
    8080    fprintf (stderr, "type return to continue");
    81     fscanf (stdin, "%c", &c);
     81    if (fscanf (stdin, "%c", &c) != 1) {
     82      fprintf (stderr, "\n");
     83    }
    8284    Nvect = 0;
    8385  }
     
    166168      fprintf (stderr, "plotting %d points\n", Nvect);
    167169      fprintf (stderr, "type return to continue");
    168       fscanf (stdin, "%c", &c);
     170      if (fscanf (stdin, "%c", &c) != 1) {
     171        fprintf (stderr, "\n");
     172      }
    169173      Nvect = 0;
    170174    }
  • trunk/Ohana/src/gastro/src/getusno.c

    r27435 r27611  
    5858      fprintf (stderr, "can't open file %s, is cdrom %d in drive?\n", filename, disk);
    5959      fprintf (stderr, "press return when ready to continue: ");
    60       fscanf (stdin, "%c", &c);
     60      if (fscanf (stdin, "%c", &c) != 1) fprintf (stderr, "\n");
    6161      fprintf (stderr, "trying again...\n");
    6262      f = fopen (filename, "r");
  • trunk/Ohana/src/gastro/src/gfit.c

    r27435 r27611  
    242242      fprintf (stderr, "plotting %d points\n", Nvect);
    243243      fprintf (stderr, "type return to continue");
    244       fscanf (stdin, "%c", &c);
     244      if (fscanf (stdin, "%c", &c) != 1) fprintf (stderr, "\n");
    245245      Nvect = 0;
    246246    }
  • trunk/Ohana/src/gastro2/src/plots.c

    r21153 r27611  
    6161  DonePlotting (&gv, 2);
    6262  fprintf (stderr, "type return to continue");
    63   fscanf (stdin, "%c", &c);
     63  if (fscanf (stdin, "%c", &c) != 1) fprintf (stderr, "\n");
    6464  free (xv);
    6565  free (yv);
     
    117117  DonePlotting (&graphdata, Xg[version]);
    118118  fprintf (stderr, "type return to continue");
    119   fscanf (stdin, "%c", &c);
     119  if (fscanf (stdin, "%c", &c) != 1) fprintf (stderr, "\n");
    120120}
    121121
     
    161161  DonePlotting (&graphdata, 0);
    162162  fprintf (stderr, "type return to continue");
    163   fscanf (stdin, "%c", &c);
     163  if (fscanf (stdin, "%c", &c) != 1) fprintf (stderr, "\n");
    164164}
    165165
     
    245245  DonePlotting (&gf, 1);
    246246  fprintf (stderr, "type return to continue");
    247   fscanf (stdin, "%c", &c);
     247  if (fscanf (stdin, "%c", &c) != 1) fprintf (stderr, "\n");
    248248}
    249249
     
    261261  PlotVector (n, y, 1, 1);
    262262  fprintf (stderr, "type return to continue");
    263   fscanf (stdin, "%c", &c);
     263  if (fscanf (stdin, "%c", &c) != 1) fprintf (stderr, "\n");
    264264
    265265
     
    336336  DonePlotting (&graphdata, 0);
    337337  fprintf (stderr, "type return to continue");
    338   fscanf (stdin, "%c", &c);
     338  if (fscanf (stdin, "%c", &c) != 1) fprintf (stderr, "\n");
    339339
    340340}
  • trunk/Ohana/src/imregister/imreg/ConfigPID.c

    r2803 r27611  
    6565int LoadPID (char *file, pid_t *pid, char *username, char *machine) {
    6666
     67  int t1, t2, t3;
    6768  FILE *f;
    6869
     
    7273  }
    7374
    74   fscanf (f, "%*s %d", pid);
    75   fscanf (f, "%*s %s", username);
    76   fscanf (f, "%*s %s", machine);
     75  t1 = fscanf (f, "%*s %d", pid);
     76  t2 = fscanf (f, "%*s %s", username);
     77  t3 = fscanf (f, "%*s %s", machine);
     78  if ((t1 != 1) || (t2 != 2) || (t3 != 1)) {
     79    fprintf (stderr, "error reading pid info\n");
     80  }
    7781  fclose (f);
    7882
  • trunk/Ohana/src/imregister/imreg/SetSignals.c

    r16139 r27611  
    104104  }
    105105  sprintf (line, "kill -TERM %d\n", pid);
    106   write (wsock, line, strlen (line));
     106  if (write (wsock, line, strlen (line)) != strlen(line)) {
     107    fprintf (stderr, "error sending signal\n");
     108    exit (1);
     109  }
    107110
    108111  for (i = 0; i < 300; i++) {
  • trunk/Ohana/src/imregister/imreg/imregclient.c

    r7080 r27611  
    2222      exit (1);
    2323    }
    24     fscanf (f, "%f %f", &image[0].sky, &image[0].bias);
     24    if (fscanf (f, "%f %f", &image[0].sky, &image[0].bias) != 2) {
     25      fprintf (stderr, "error reading stats\n");
     26    }
    2527    fclose (f);
    2628    image[0].fwhm = get_fwhm (datfile);
  • trunk/Ohana/src/imregister/imreg/rconnect.c

    r12332 r27611  
    8787     without setting onintr */
    8888  sprintf (buffer, "onintr\n");
    89   write (*wsock, buffer, strlen(buffer));
     89  if (write (*wsock, buffer, strlen (buffer)) != strlen(buffer)) {
     90    fprintf (stderr, "error sending signal\n");
     91    close (*wsock);
     92    close (*rsock);
     93    return (FALSE);
     94  }
     95
    9096  if ((status == -1) && (errno == EPIPE)) {
    9197    fprintf (stderr, "socket closed unexpectedly\n");
  • trunk/Ohana/src/imregister/src/imstatreg.c

    r27435 r27611  
    7070
    7171    /* delete, unlock existing database */
    72     truncate (TempDB, 0);
     72    if (truncate (TempDB, 0)) {
     73      fprintf (stderr, "error truncating temp db\n");
     74      exit (1);
     75    }
    7376    gfits_db_close (&temp_db);
    7477    fprintf (stderr, "temporary database closed\n");
  • trunk/Ohana/src/nightd/src/GetStatus.c

    r2494 r27611  
    3333
    3434  sprintf (line, "rsh %s kill -USR1 %d", machine, pid);
    35   system (line);
     35  if (system (line) == -1) {
     36    fprintf (stderr, "failed to send signal\n");
     37  }
    3638  exit (0);
    3739
     
    5052
    5153  sprintf (line, "rsh %s kill -TERM %d", machine, pid);
    52   system (line);
     54  if (system (line) == -1) {
     55    fprintf (stderr, "failed to send signal\n");
     56  }
    5357  exit (0);
    5458
  • trunk/Ohana/src/nightd/src/misc.c

    r14590 r27611  
    1111int SetPID (pid_t *Xpid, char *Xuser, char *Xmachine) {
    1212 
     13  int t1, t2, t3;
    1314  pid_t pid;
    1415  char *username, machine[256];
     
    4344  }
    4445
    45   fscanf (f, "%*s %d", Xpid);
    46   fscanf (f, "%*s %s", Xuser);
    47   fscanf (f, "%*s %s", Xmachine);
     46  t1 = fscanf (f, "%*s %d", Xpid);
     47  t2 = fscanf (f, "%*s %s", Xuser);
     48  t3 = fscanf (f, "%*s %s", Xmachine);
     49  if ((t1 != 1) || (t2 != 2) || (t3 != 1)) {
     50    fprintf (stderr, "error reading pid info\n");
     51  }
    4852  fclose (f);
    4953  return (FALSE);
     
    125129
    126130  eof = 0x04;
    127   write (wfd[1], &eof, 1);
     131  if (write (wfd[1], &eof, 1) != 1) fprintf (stderr, "!\n");
    128132  close (wfd[1]);
    129133 
  • trunk/Ohana/src/opihi/cmd.astro/flux.c

    r7917 r27611  
    2929  ymax = 0;
    3030  for (i = 0; i < 4; i++) {
    31     fscanf (f, "%lf %lf", &x[i], &y[i]);
     31    if (fscanf (f, "%lf %lf", &x[i], &y[i]) != 2) {
     32      fprintf (stderr, "error reading coordinates from %s\n", argv[2]);
     33      fclose (f);
     34      return (FALSE);
     35    }
    3236    xmin = MAX (0, MIN (xmin, x[i] - 1));
    3337    ymin = MAX (0, MIN (ymin, y[i] - 1));
  • trunk/Ohana/src/opihi/cmd.basic/help.c

    r11084 r27611  
    1515  if (argc == 1) {
    1616    sprintf (buff, "ls %s", helpdir);
    17     system (buff);
     17    if (system (buff) == -1) {
     18      fprintf (stderr, "help directory unavailable\n");
     19      return (FALSE);
     20    }
    1821    return (TRUE);
    1922  }
  • trunk/Ohana/src/opihi/cmd.basic/list_help.c

    r7917 r27611  
    1818    fclose (f);
    1919    sprintf (line, "more %s", filename);
    20     system (line);
     20    if (system (line) == -1) {
     21      fprintf (stderr, "help list unavailable\n");
     22    }
    2123  }
    2224  unlink (filename);
  • trunk/Ohana/src/opihi/cmd.data/queuedrop.c

    r8427 r27611  
    44 
    55  int N;
    6   char *Key;
    7   char *line;
    8   char *Value;
    9   Queue *queue;
     6  char *Key = NULL;
     7  char *line = NULL;
     8  Queue *queue = NULL;
     9  char *Value = NULL;
    1010
    1111  Key = NULL;
  • trunk/Ohana/src/opihi/dvo/elixir.c

    r27435 r27611  
    4646
    4747  sprintf (msgfile, "%s/EMsg.XXXXXX", fifodir);
    48   mkstemp (msgfile);
     48  if (mkstemp (msgfile) == -1) {
     49    gprint (GP_ERR, "can't create fifo\n");
     50    return (FALSE);
     51  }
    4952  sprintf (message, "%s %s", cmd, msgfile);
    5053  unlink (msgfile);
  • trunk/Ohana/src/opihi/lib.shell/interrupt.c

    r14284 r27611  
    2727  while (1) {
    2828    gprint (GP_ERR, "operation halted, continue? (y/n) ");
    29     fscanf (stdin, "%s", string);
     29    if (fscanf (stdin, "%s", string) != 1) fprintf (stderr, "what?\n");
    3030   
    3131    if ((string[0] == 'y') || (string[0] == 'Y')) {
  • trunk/Ohana/src/relphot/src/plotstuff.c

    r20191 r27611  
    149149  if (PLOTDELAY > 500000) {
    150150    fprintf (stdout, "press return\n");
    151     fscanf (stdin, "%*c");
     151    if (fscanf (stdin, "%*c") != 1) fprintf (stderr, "\n");
    152152  } else {
    153153    usleep (PLOTDELAY);
Note: See TracChangeset for help on using the changeset viewer.