Changeset 321 for trunk/src/sh_sub.c


Ignore:
Timestamp:
Mar 17, 2011, 10:07:44 PM (14 years ago)
Author:
katerina
Message:

Fix for ticket #240: The samhain_kmem kernel module should be loaded earlier

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_sub.c

    r316 r321  
    2020#include "config_xor.h"
    2121
     22/* 0->1 for debug */
     23#if 0
     24#define SH_SUB_DBG 1
     25#endif
     26
    2227#ifndef NULL
    2328#if !defined(__cplusplus)
     
    6267static ssize_t sh_sub_read(int fd, void *buf, size_t count);
    6368
    64 static void sh_kill_sub()
     69void sh_kill_sub()
    6570{
    6671  SH_MUTEX_LOCK(mutex_sub);
     72
    6773  if (sh_child_pid != -1)
    6874    {
    6975      int status;
     76#ifdef WCONTINUED
     77      int wflags = WNOHANG|WUNTRACED|WCONTINUED;
     78#else
     79      int wflags = WNOHANG|WUNTRACED;
     80#endif
    7081
    7182      close (parent2child[1]);
    7283      close (child2parent[0]);
    7384
    74       fprintf(stderr, "FIXME kill_sub %d\n", (int) sh_child_pid);
     85      /* fprintf(stderr, "FIXME kill_sub %d\n", (int) sh_child_pid); */
    7586
    7687      /* Let's be rude. */
     
    8091
    8192      if (sh_wait_ret == 0)
    82         sh_wait_ret = waitpid(          -1, &status, WNOHANG|WUNTRACED);
     93        sh_wait_ret = waitpid(          -1, &status, wflags);
    8394      else
    84         sh_wait_ret = waitpid(sh_child_pid, &status, WNOHANG|WUNTRACED);
     95        sh_wait_ret = waitpid(sh_child_pid, &status, wflags);
    8596
    8697      sh_child_pid = -1;
    8798    }
     99
    88100  SH_MUTEX_UNLOCK(mutex_sub);
    89101  return;
     
    93105{
    94106  pid_t res;
    95   int   retval = 0;
     107  volatile int   retval = 0;
    96108
    97109  SH_MUTEX_LOCK(mutex_sub);
     
    162174              ++fd;
    163175            }
     176
     177          /*
     178          for (i = 0; i < 3; ++i)
     179            {
     180              if ( fcntl(i, F_GETFL, 0) == (-1))
     181                (void) open(_("/dev/null"), O_RDWR, 0);
     182            }
     183          */
    164184
    165185          /* reset signal handling
     
    275295  do {
    276296
    277     // fprintf(stderr, "FIXME wait_com polling..\n");
     297    /* fprintf(stderr, "FIXME wait_com polling..\n"); */
    278298
    279299    do {
     
    307327            outbuf.errnum = errno;
    308328
    309             // fprintf(stderr, "FIXME wait_com writing..\n");
     329            /* fprintf(stderr, "FIXME wait_com writing..\n"); */
    310330
    311331            ret = sh_sub_write(child2parent[1], &outbuf, sizeof(outbuf));
    312332            if (ret < 0)
    313333              {
    314                 fprintf(stderr, "FIXME wait_com return 1\n");
     334                /* fprintf(stderr, "FIXME wait_com return 1\n"); */
    315335                return;
    316336              }
     
    318338        else /* sh_sub_read() < 0 */
    319339          {
    320             fprintf(stderr, "FIXME wait_com return 2\n");
     340            /* fprintf(stderr, "FIXME wait_com return 2\n"); */
    321341            return;
    322342          }
    323343      }
    324344   
    325     // fprintf(stderr, "FIXME wait_com next..\n");
     345    /* fprintf(stderr, "FIXME wait_com next..\n"); */
    326346
    327347  } while (1 == 1);
     
    362382}
    363383
     384#ifdef SH_SUB_DBG
     385#include <stdarg.h>
     386static void debug_it (const char *fmt, ...)
     387{
     388  char msg[256];
     389  va_list ap;
     390
     391  int fd = open("debug.it", O_CREAT|O_WRONLY|O_APPEND, 0666);
     392
     393  va_start(ap, fmt);
     394  vsnprintf(msg, sizeof(msg), fmt, ap);  /* flawfinder: ignore */
     395  va_end(ap);
     396
     397  write(fd, msg, strlen(msg));
     398  write(fd, "\n", 1);
     399  close(fd);
     400  return;
     401}
     402#endif
     403
    364404static int sh_sub_stat_int(const char *path, struct stat *buf, char command)
    365405{
     
    397437 start:
    398438
     439#ifdef SH_SUB_DBG
     440  debug_it("%d sh_child_pid %d\n", (int)getpid(), (int) sh_child_pid);
     441#endif
     442
    399443  if (sh_child_pid == -1)
    400444    sh_create_sub();
    401445
    402   // fprintf(stderr, "FIXME stat_sub %s\n", inbuf.path);
     446#ifdef SH_SUB_DBG
     447  debug_it("%d stat_sub %s (%d)\n", (int)getpid(), inbuf.path, (int) sh_child_pid);
     448#endif
    403449
    404450  SH_MUTEX_LOCK(mutex_sub_work);
     
    412458    }
    413459
    414   // fprintf(stderr, "FIXME stat_sub polling..\n");
     460#ifdef SH_SUB_DBG
     461  debug_it("%d stat_sub polling..\n", (int)getpid());
     462#endif
    415463
    416464  pfds.fd     = child2parent[0];
     
    428476    }
    429477
    430   // fprintf(stderr, "FIXME stat_sub reading..\n");
     478#ifdef SH_SUB_DBG
     479  debug_it("%d stat_sub reading..\n", (int)getpid());
     480#endif
    431481
    432482  retval = sh_sub_read (child2parent[0], &outbuf, sizeof(outbuf));
     
    444494  if      (sflag == 0)
    445495    {
    446       // fprintf(stderr, "FIXME stat_sub done..\n");
     496#ifdef SH_SUB_DBG
     497      debug_it("%d stat_sub done..\n", (int)getpid());
     498#endif
    447499      memcpy(buf, &(outbuf.sbuf), sizeof(struct stat));
    448500      errno = outbuf.errnum;
     
    451503  else if (sflag == 1)
    452504    {
     505#ifdef SH_SUB_DBG
     506      debug_it("%d stat_sub error..\n", (int)getpid());
     507#endif
    453508      /* could not read, thus subprocess may have gone */
     509      sflag = 0;
    454510      goto start;
    455511    }
Note: See TracChangeset for help on using the changeset viewer.