Changeset 174


Ignore:
Timestamp:
Aug 27, 2008, 5:40:28 PM (16 years ago)
Author:
katerina
Message:

Fix for tickets #112, #113 (dnmalloc deadlock on fork, hostname portability in test script).

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r173 r174  
    1313dnl start
    1414dnl
    15 AM_INIT_AUTOMAKE(samhain, 2.4.5a)
     15AM_INIT_AUTOMAKE(samhain, 2.4.6)
    1616AC_DEFINE([SAMHAIN], 1, [Application is samhain])
    1717AC_CANONICAL_HOST
  • trunk/docs/Changelog

    r173 r174  
    1 2.4.5a:
     12.4.6:
     2        * fix potential deadlock with dnmalloc upon fork()
     3        * fix non-portable use of 'hostname -f' in regression test suite
     4          (reported by Borut Podlipnik)
     5
     62.4.5a (18-08-2008):
    27        * fix compile problem in dnmalloc.c (remove prototypes for
    38          memset/memcpy), problem reported by Juergen Daubert
  • trunk/include/sh_unix.h

    r170 r174  
    209209/* close all files >= fd, except possibly one
    210210 */
    211 void sh_unix_closeall (int fd, int except);
     211void sh_unix_closeall (int fd, int except, int inchild);
    212212
    213213
  • trunk/include/slib.h

    r170 r174  
    401401   */
    402402  int sl_dropall(int fd, int except);
     403  int sl_dropall_dirty(int fd, int except); /* don't deallocate */
    403404
    404405  /* Check whether file is trustworthy.
  • trunk/src/dnmalloc.c

    r173 r174  
    15081508    pthread_mutex_unlock(&mALLOC_MUTEx);
    15091509}
    1510 void dnmalloc_fork_child(void) {
     1510void dnmalloc_fork_child(void) {
     1511  int rc;
    15111512#ifdef __GLIBC__
    15121513  if (dnmalloc_use_mutex)
    1513     pthread_mutex_init(&mALLOC_MUTEx, NULL);
     1514    {
     1515      pthread_mutex_unlock (&mALLOC_MUTEx);
     1516      pthread_mutex_destroy(&mALLOC_MUTEx);
     1517      rc = pthread_mutex_init(&mALLOC_MUTEx, NULL);
     1518    }
    15141519#else
    15151520  if (dnmalloc_use_mutex)
    1516     pthread_mutex_unlock(&mALLOC_MUTEx);
    1517 #endif
     1521    rc = pthread_mutex_unlock(&mALLOC_MUTEx);
     1522#endif
     1523  if (rc != 0)
     1524    {
     1525      fputs("fork_child failed", stderr);
     1526      _exit(EXIT_FAILURE);
     1527    }
    15181528}
    15191529static int dnmalloc_mutex_lock(pthread_mutex_t *mutex)
  • trunk/src/samhain.c

    r172 r174  
    12341234  /* --- Close all but first three file descriptors. ---
    12351235   */
    1236   sh_unix_closeall(3, -1); /* at program start */
     1236  sh_unix_closeall(3, -1, SL_FALSE); /* at program start */
    12371237
    12381238
  • trunk/src/sh_entropy.c

    r171 r174  
    581581      /* don't leak file descriptors
    582582       */
    583       sh_unix_closeall (3, -1); /* in child process */
     583      sh_unix_closeall (3, -1, SL_TRUE); /* in child process */
    584584
    585585      /* zero priv info
  • trunk/src/sh_extern.c

    r170 r174  
    294294           */
    295295#if !defined(PDGBFILE)
    296           sh_unix_closeall (3, task->com_fd); /* in child process */
     296          sh_unix_closeall (3, task->com_fd, SL_TRUE); /* in child process */
    297297#endif
    298298
  • trunk/src/sh_gpg.c

    r170 r174  
    487487      /* don't leak file descriptors
    488488       */
    489       sh_unix_closeall (3, -1); /* in child process */
     489      sh_unix_closeall (3, -1, SL_TRUE); /* in child process */
    490490
    491491      if (NULL == freopen(_("/dev/null"), "r+", stderr))
  • trunk/src/sh_unix.c

    r172 r174  
    12461246#endif
    12471247
    1248 void sh_unix_closeall (int fd, int except)
     1248void sh_unix_closeall (int fd, int except, int inchild)
    12491249{
    12501250  int fdx = fd;
     
    12811281    }
    12821282
    1283   sl_dropall (fdx, except);
     1283  if (!inchild)
     1284    sl_dropall (fdx, except);
     1285  else
     1286    sl_dropall_dirty (fdx, except);
    12841287
    12851288  SL_RET0(_("sh_unix_closeall"));
  • trunk/src/slib.c

    r170 r174  
    20932093            (void) free(ofiles[fd]->path);
    20942094          (void) free(ofiles[fd]);
     2095          ofiles[fd] = NULL;
     2096        }
     2097      ++fd;
     2098    }
     2099  return 0;
     2100}
     2101
     2102int sl_dropall_dirty(int fd, int except)
     2103{
     2104  while (fd < MAXFD)
     2105    {
     2106      if (ofiles[fd] != NULL && fd != except)
     2107        {
    20952108          ofiles[fd] = NULL;
    20962109        }
  • trunk/test/test.sh

    r172 r174  
    482482
    483483find_hostname () {
    484     tmp=`hostname -f 2>/dev/null`
    485     if [ $? -ne 0 ]; then
     484
     485    uname -a | grep Linux >/dev/null
     486    if [ $? -eq 0 ]; then
     487        tmp=`hostname -f 2>/dev/null`
     488        if [ $? -ne 0 ]; then
     489            tmp=`hostname 2>/dev/null`
     490        fi
     491    else
    486492        tmp=`hostname 2>/dev/null`
    487493    fi
Note: See TracChangeset for help on using the changeset viewer.