Changeset 409


Ignore:
Timestamp:
Aug 27, 2012, 9:08:06 PM (12 years ago)
Author:
katerina
Message:

Improved fix for ticket #311 (thread safety of --enable-ptrace).

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/sh_unix.h

    r408 r409  
    375375#endif
    376376void sh_set_save_tv();
     377void sh_set_untraced(int val);
     378int  sh_get_untraced();
    377379#endif
    378380
     
    394396int sh_derr(void)
    395397{
    396   sh_not_traced = 0;
     398  sh_set_untraced(0);
    397399
    398400#ifdef HAVE_GETTIMEOFDAY
     
    404406  raise(SIGTRAP);
    405407 
    406   if (sh_not_traced == 0)
     408  if (sh_get_untraced() == 0)
    407409    _exit(5);
    408410
    409   sh_not_traced = 0;
     411  sh_set_untraced(0);
    410412  return (0);
    411413}
  • trunk/src/sh_unix.c

    r408 r409  
    53985398 */
    53995399#if defined(SCREW_IT_UP)
    5400 volatile int sh_not_traced = 0;
    5401 
     5400struct screw_it_up {
     5401  int not_traced;
    54025402#ifdef HAVE_GETTIMEOFDAY
     5403  struct timeval save_tv;
     5404#endif
     5405};
    54035406
    54045407#if defined(HAVE_PTHREAD)
     
    54125415}
    54135416
    5414 static inline struct timeval * sh_get_save_tv()
     5417static inline struct screw_it_up * sh_get_screw_it_up()
    54155418{
    54165419  void * ptr;
    5417   struct timeval * save_tv;
     5420  struct screw_it_up * screw;
    54185421
    54195422  (void) pthread_once(&gSaveTv_key_once, make_gSaveTv_key);
     
    54215424  if ((ptr = pthread_getspecific(gSaveTv_key)) == NULL)
    54225425    {
    5423       ptr = malloc(sizeof(struct timeval));
     5426      ptr = malloc(sizeof(struct screw_it_up));
    54245427      if (ptr)
    54255428        {
    5426           save_tv  = (struct timeval*) ptr;
     5429          screw = (struct screw_it_up *) ptr;
    54275430          (void) pthread_setspecific(gSaveTv_key, ptr);
    54285431        }
     
    54345437  else
    54355438    {
    5436       save_tv  = (struct timeval*) ptr;
    5437     }
    5438   return save_tv;
    5439 }
    5440 
     5439      screw = (struct screw_it_up *) ptr;
     5440    }
     5441  return screw;
     5442}
     5443
     5444#ifdef HAVE_GETTIMEOFDAY
    54415445void sh_set_save_tv()
    54425446{
    5443   struct timeval * save_tv = sh_get_save_tv();
     5447  struct screw_it_up * screw = sh_get_screw_it_up();
     5448  struct timeval * save_tv = &(screw->save_tv);
    54445449  if (save_tv)
    54455450    gettimeofday(save_tv, NULL);
    54465451  return;
    54475452}
     5453struct timeval * sh_get_save_tv()
     5454{
     5455  struct screw_it_up * screw = sh_get_screw_it_up();
     5456  struct timeval * save_tv = &(screw->save_tv);
     5457  return save_tv;
     5458}
     5459/* #ifdef HAVE_GETTIMEOFDAY */
     5460#endif
     5461
     5462void sh_set_untraced(int val)
     5463{
     5464  struct screw_it_up * screw = sh_get_screw_it_up();
     5465
     5466  screw->not_traced = val;
     5467  return;
     5468}
     5469int sh_get_untraced()
     5470{
     5471  struct screw_it_up * screw = sh_get_screw_it_up();
     5472
     5473  return screw->not_traced;
     5474}
    54485475
    54495476/* !defined(HAVE_PTHREAD) */
    54505477#else
    54515478
     5479#ifdef HAVE_GETTIMEOFDAY
    54525480static struct timeval * sSaveTv = NULL;
    5453 
    54545481static inline struct timeval * sh_get_save_tv()
    54555482{
     
    54605487  gettimeofday(sSaveTv, NULL);
    54615488}
    5462 #endif
    5463 
    54645489/* #ifdef HAVE_GETTIMEOFDAY */
    54655490#endif
     5491
     5492volatile int sh_not_traced = 0;
     5493void sh_set_untraced(int val)
     5494{
     5495  sh_not_traced = val;
     5496  return;
     5497}
     5498int sh_get_untraced()
     5499{
     5500  return sh_not_traced;
     5501}
     5502
     5503#endif
     5504
    54665505
    54675506void sh_sigtrap_handler (int signum)
     
    54795518    raise(SIGKILL);
    54805519#endif
    5481   sh_not_traced += signum;
     5520  sh_set_untraced(signum);
    54825521  return;
    54835522}
Note: See TracChangeset for help on using the changeset viewer.