RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
  Module: rpm                              Date:   05-Sep-2014 21:36:30
  Branch: rpm-5_4                          Handle: 2014090519362900

  Modified files:           (Branch: rpm-5_4)
    rpm/rpmio               rpmsx.c

  Log:
    - rpmsx: use a single global object pointer (with sneaky state
    changes).

  Summary:
    Revision    Changes     Path
    2.4.4.3     +67 -54     rpm/rpmio/rpmsx.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmsx.c
  ============================================================================
  $ cvs diff -u -r2.4.4.2 -r2.4.4.3 rpmsx.c
  --- rpm/rpmio/rpmsx.c 4 Sep 2014 13:50:22 -0000       2.4.4.2
  +++ rpm/rpmio/rpmsx.c 5 Sep 2014 19:36:29 -0000       2.4.4.3
  @@ -60,8 +60,7 @@
   /*@unchecked@*/
   int _rpmsx_debug = 0;
   
  -/*@unchecked@*/ /*@relnull@*/
  -rpmsx _rpmsxI = NULL;
  +#define      SPEW(_list)     if (_rpmsx_debug) fprintf _list
   
   static void rpmsxFini(void * _sx)
        /*@globals fileSystem @*/
  @@ -70,8 +69,10 @@
       rpmsx sx = (rpmsx) _sx;
   
   #if defined(WITH_SELINUX)
  -    if (sx->fn)
  +    if (sx->fn) {
  +SPEW((stderr, "<-- matchpathcon_fini()\n"));
        matchpathcon_fini();
  +    }
   #endif
       sx->flags = 0;
       sx->fn = _free(sx->fn);
  @@ -94,45 +95,68 @@
       return (rpmsx) rpmioGetPool(pool, sizeof(*sx));
   }
   
  -rpmsx rpmsxNew(const char * fn, unsigned int flags)
  +/*@unchecked@*/ /*@relnull@*/
  +rpmsx _rpmsxI = NULL;
  +
  +static rpmsx rpmsxI(void)
  +     /*@globals _rpmsxI @*/
  +     /*@modifies _rpmsxI @*/
   {
  -    rpmsx sx = rpmsxGetPool(_rpmsxPool);
  +    if (_rpmsxI == NULL) {
  +     rpmsx sx = rpmsxGetPool(_rpmsxPool);
  +     sx->fn = NULL;
  +     sx->flags = 0;
  +     _rpmsxI = rpmsxLink(sx);
  +    }
  +    return _rpmsxI;
  +}
   
  -    sx->fn = NULL;
  -    sx->flags = flags;
  +rpmsx rpmsxNew(const char * _fn, unsigned int flags)
  +{
  +    const char * fn = rpmGetPath(_fn, NULL);
  +    rpmsx sx = rpmsxI();
   
  +    /* Use default file context path if arg is not an absolute path. */
  +    if (!(fn && fn[0] == '/'))
  +     fn = _free(fn);
   #if defined(WITH_SELINUX)
  -    if (fn == NULL)
  -     fn = selinux_file_context_path();
  +    if (fn == NULL) {
  +     fn = xstrdup(selinux_file_context_path());
  +SPEW((stderr, "--- selinux_file_context_path: %s\n", fn));
  +    }
  +#endif
   
  -    if (sx->flags)
  +    /* Already initialized? */
  +    if (sx->fn) {
  +     /* If already opened, add a new reference and return. */
  +     if (!strcmp(sx->fn, fn))        /* XXX chroot by stat(fn) inode */
  +         goto exit;
  +     /* Otherwise do an implicit matchpathcon_fini(). */
  +     rpmsxFini(sx);
  +    }
  +
  +    sx->fn = fn;
  +    sx->flags = flags;
  +
  +#if defined(WITH_SELINUX)
  +    if (sx->flags) {
        set_matchpathcon_flags(sx->flags);
  +SPEW((stderr, "--- set_matchpathcon_flags(0x%x)\n", sx->flags));
  +    }
  +
  +    /* If matchpathcon_init fails, turn off SELinux functionality. */
       {        int rc;
  -     sx->fn = rpmGetPath(fn, NULL);
  -     if (sx->fn && sx->fn[0] == '/')
  -         rc = matchpathcon_init(sx->fn);
  -     else
  -         rc = -1;
  -     /* If matchpathcon_init fails, turn off SELinux functionality. */
  -     if (rc < 0)
  -         sx->fn = _free(sx->fn);
  +SPEW((stderr, "--> matchpathcon_init(%s)\n", sx->fn));
  +     rc = matchpathcon_init(sx->fn);
  +     if (rc < 0) {
  +         rpmsxFini(sx);
  +         sx = NULL;          /* XXX transaction.c logic needs this. */
  +     }
       }
   #endif
  -    return rpmsxLink(sx);
  -}
  -
  -/*@unchecked@*/ /*@null@*/
  -static const char * _rpmsxI_fn;
  -/*@unchecked@*/
  -static int _rpmsxI_flags;
   
  -static rpmsx rpmsxI(void)
  -     /*@globals _rpmsxI @*/
  -     /*@modifies _rpmsxI @*/
  -{
  -    if (_rpmsxI == NULL)
  -     _rpmsxI = rpmsxNew(_rpmsxI_fn, _rpmsxI_flags);
  -    return _rpmsxI;
  +exit:
  +    return rpmsxLink(sx);
   }
   
   int rpmsxEnabled(/*@null@*/ rpmsx sx)
  @@ -143,8 +167,7 @@
   
       if (!oneshot) {
        rc = is_selinux_enabled();
  -if (_rpmsx_debug)
  -fprintf(stderr, "<-- %s(%p) rc %d\n", __FUNCTION__, sx, rc);
  +SPEW((stderr, "<-- %s(%p) rc %d\n", __FUNCTION__, sx, rc));
        oneshot++;
       }
   #endif
  @@ -178,8 +201,7 @@
   
       if (sx == NULL) sx = rpmsxI();
   
  -if (_rpmsx_debug)
  -fprintf(stderr, "--> %s(%p,%s) sxfn %s\n", __FUNCTION__, sx, fn, sx->fn);
  +SPEW((stderr, "--> %s(%p,%s) sxfn %s\n", __FUNCTION__, sx, fn, sx->fn));
   
   #if defined(WITH_SELINUX)
       if (sx->fn && fn) {
  @@ -192,8 +214,7 @@
       }
   #endif
   
  -if (_rpmsx_debug)
  -fprintf(stderr, "<-- %s(%p,%s) scon %s\n", __FUNCTION__, sx, fn, scon);
  +SPEW((stderr, "<-- %s(%p,%s) scon %s\n", __FUNCTION__, sx, fn, scon));
       return scon;
   }
   
  @@ -204,8 +225,7 @@
   
       if (sx == NULL) sx = rpmsxI();
   
  -if (_rpmsx_debug)
  -fprintf(stderr, "--> %s(%p,%s,0%o,%s) sxfn %s\n", __FUNCTION__, sx, fn, 
mode, scon, sx->fn);
  +SPEW((stderr, "--> %s(%p,%s,0%o,%s) sxfn %s\n", __FUNCTION__, sx, fn, mode, 
scon, sx->fn));
   
   #if defined(WITH_SELINUX)
       if (sx->fn) {
  @@ -219,8 +239,7 @@
       }
   #endif
   
  -if (_rpmsx_debug)
  -fprintf(stderr, "<-- %s(%p,%s,0%o,%s) rc %d\n", __FUNCTION__, sx, fn, mode, 
scon, rc);
  +SPEW((stderr, "<-- %s(%p,%s,0%o,%s) rc %d\n", __FUNCTION__, sx, fn, mode, 
scon, rc));
       return rc;
   }
   
  @@ -230,8 +249,7 @@
   
       if (sx == NULL) sx = rpmsxI();
   
  -if (_rpmsx_debug)
  -fprintf(stderr, "--> %s(%p,%s) sxfn %s\n", __FUNCTION__, sx, fn, sx->fn);
  +SPEW((stderr, "--> %s(%p,%s) sxfn %s\n", __FUNCTION__, sx, fn, sx->fn));
   
   #if defined(WITH_SELINUX)
       if (sx->fn && fn) {
  @@ -244,8 +262,7 @@
       }
   #endif
   
  -if (_rpmsx_debug)
  -fprintf(stderr, "<-- %s(%p,%s) scon %s\n", __FUNCTION__, sx, fn, scon);
  +SPEW((stderr, "<-- %s(%p,%s) scon %s\n", __FUNCTION__, sx, fn, scon));
       return scon;
   }
   
  @@ -256,8 +273,7 @@
   
       if (sx == NULL) sx = rpmsxI();
   
  -if (_rpmsx_debug)
  -fprintf(stderr, "--> %s(%p,%s,0%o,%s) sxfn %s\n", __FUNCTION__, sx, fn, 
mode, scon, sx->fn);
  +SPEW((stderr, "--> %s(%p,%s,0%o,%s) sxfn %s\n", __FUNCTION__, sx, fn, mode, 
scon, sx->fn));
   
   #if defined(WITH_SELINUX)
       if (sx->fn) {
  @@ -271,8 +287,7 @@
       }
   #endif
   
  -if (_rpmsx_debug)
  -fprintf(stderr, "<-- %s(%p,%s,0%o,%s) rc %d\n", __FUNCTION__, sx, fn, mode, 
scon, rc);
  +SPEW((stderr, "<-- %s(%p,%s,0%o,%s) rc %d\n", __FUNCTION__, sx, fn, mode, 
scon, rc));
       return rc;
   }
   
  @@ -282,14 +297,12 @@
   
       if (sx == NULL) sx = rpmsxI();
   
  -if (_rpmsx_debug)
  -fprintf(stderr, "--> %s(%p,%d,%p)\n", __FUNCTION__, sx, verified, argv);
  +SPEW((stderr, "--> %s(%p,%d,%p)\n", __FUNCTION__, sx, verified, argv));
   
   #if defined(WITH_SELINUX)
       rc = rpm_execcon(verified, argv[0], (char *const *)argv, environ);
   #endif
   
  -if (_rpmsx_debug)
  -fprintf(stderr, "<-- %s(%p,%d,%p) rc %d\n", __FUNCTION__, sx, verified, 
argv, rc);
  +SPEW((stderr, "<-- %s(%p,%d,%p) rc %d\n", __FUNCTION__, sx, verified, argv, 
rc));
       return rc;
   }
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to