Changeset 240 for trunk/src


Ignore:
Timestamp:
Aug 6, 2009, 12:35:50 AM (15 years ago)
Author:
katerina
Message:

Fix bugs in mailer code (ticket #160, #161).

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_mail.c

    r238 r240  
    15841584  length = res_query (hostname, C_IN, T_MX,
    15851585                      (unsigned char *) reply, 4095);
     1586
    15861587  if (length < 1)
    15871588    {
     
    16491650        }
    16501651    }
     1652
    16511653  count         = ntohs (header->ancount);
    16521654  if (count < 1)
     
    16881690      /* HEADER NAME
    16891691       */
    1690       ret = dn_expand ((unsigned char *) &reply, eom, comp_dn,
     1692      ret = dn_expand ((unsigned char *) reply, eom, comp_dn,
    16911693                       (char *) expanded, 1023);
    16921694      comp_dn += ret;
     
    17111713        }
    17121714
     1715
    17131716      /* CLASS (re-use 'type' var)
    17141717       */
     
    17231726        }
    17241727
     1728
    17251729      /* TTL
    17261730       */
     
    17581762        }
    17591763
    1760       ret = dn_expand ((unsigned char *) &reply, eom, comp_dn,
     1764      ret = dn_expand ((unsigned char *) reply, eom, comp_dn,
    17611765                       (char *) expanded, 1023);
    17621766      comp_dn += ret;
  • trunk/src/sh_nmail.c

    r232 r240  
    4444
    4545SH_MUTEX_INIT(mutex_listall, PTHREAD_MUTEX_INITIALIZER);
     46SH_MUTEX_INIT(mutex_flush_l, PTHREAD_MUTEX_INITIALIZER);
    4647
    4748/* Pointer to last address */
     
    376377}
    377378
     379/* Is not called from same(recursively) or different thread
     380 */
    378381static
    379382int sh_nmail_flag_recipients (int level, const char * message,
     
    391394}
    392395
     396/* Can be called from same thread with mutex_listall held via sh_nmail_flush()
     397 */
    393398static
    394399int sh_nmail_test_recipients (int level, const char * message,
     
    399404  if (message)
    400405    {
    401       SH_MUTEX_LOCK_UNSAFE(mutex_listall);
    402       retval = sh_nmail_compute_recipients (level, message, alias, 0);
    403       SH_MUTEX_UNLOCK_UNSAFE(mutex_listall);
     406      if (0 == SH_MUTEX_TRYLOCK_UNSAFE(mutex_flush_l))
     407        {
     408          SH_MUTEX_LOCK_UNSAFE(mutex_listall);
     409          retval = sh_nmail_compute_recipients (level, message, alias, 0);
     410          SH_MUTEX_UNLOCK_UNSAFE(mutex_listall);
     411          SH_MUTEX_UNLOCK_UNSAFE(mutex_flush_l);
     412        }
    404413    }
    405414  return retval;
     
    426435}
    427436
     437static int nmail_count = 0;
     438
    428439/*
    429440 * First mark list of recipients, then call sh_mail_msg().
     
    433444{
    434445  volatile int retval = 0;
    435   static int count = 0;
    436446
    437447  /* Need to:
     
    445455  if (0 == SH_MUTEX_TRYLOCK_UNSAFE(nmail_lock))
    446456    {
    447       ++count;
    448       if (count != 1)
    449         {
    450           --count;
     457      ++nmail_count;
     458      if (nmail_count != 1)
     459        {
     460          --nmail_count;
    451461          SH_MUTEX_UNLOCK_UNSAFE(nmail_lock);
    452462          goto cleanup;
     
    468478        }
    469479      SH_MUTEX_LOCK_UNSAFE(nmail_lock);
    470       --count;
     480      --nmail_count;
    471481      SH_MUTEX_UNLOCK_UNSAFE(nmail_lock);
    472482    }
     
    477487}
    478488
     489static int sh_nmail_flush_int (void);
     490
     491int sh_nmail_flush ()
     492{
     493  int                retval = 0;
     494
     495  if (0 == SH_MUTEX_TRYLOCK_UNSAFE(nmail_lock))
     496    {
     497      ++nmail_count;
     498      if (nmail_count != 1)
     499        {
     500          --nmail_count;
     501          SH_MUTEX_UNLOCK_UNSAFE(nmail_lock);
     502          return retval;
     503        }
     504      SH_MUTEX_UNLOCK_UNSAFE(nmail_lock);
     505
     506      retval = sh_nmail_flush_int ();
     507
     508      SH_MUTEX_LOCK_UNSAFE(nmail_lock);
     509      --nmail_count;
     510      SH_MUTEX_UNLOCK_UNSAFE(nmail_lock);
     511    }
     512  return retval;
     513}
     514
     515/* warning: variable ‘list’ might be clobbered by ‘longjmp’ or ‘vfork’*/
     516static struct alias ** list_dummy;
     517
    479518/*
    480519 * Loop over all recipients in stack.
     
    483522 */
    484523
    485 int sh_nmail_flush ()
     524static int sh_nmail_flush_int ()
    486525{
    487526  int                retval = 0;
     
    491530  struct alias     * dlist;
    492531
     532  /* warning: variable ‘list’ might be clobbered by ‘longjmp’ or ‘vfork’*/
     533  list_dummy = &list;
     534
    493535  SH_MUTEX_LOCK(mutex_listall);
    494536
     
    529571      list = compiled_recipient_list;
    530572     
     573      SH_MUTEX_LOCK(mutex_flush_l);
    531574      (void) sh_mail_msg(sh_string_str(msg));
     575      SH_MUTEX_UNLOCK(mutex_flush_l);
     576
    532577      sh_string_destroy(&msg);
    533578     
     
    591636    if (smsg)
    592637      {
     638        SH_MUTEX_LOCK(mutex_flush_l);
    593639        (void) sh_mail_msg(sh_string_str(smsg));
     640        SH_MUTEX_UNLOCK(mutex_flush_l);
    594641        sh_string_destroy(&smsg);
    595642      }
     
    656703    if (smsg)
    657704      {
     705        SH_MUTEX_LOCK(mutex_flush_l);
    658706        (void) sh_mail_msg(sh_string_str(smsg));
     707        SH_MUTEX_UNLOCK(mutex_flush_l);
    659708        sh_string_destroy(&smsg);
    660709      }
Note: See TracChangeset for help on using the changeset viewer.