[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new module write-any-file
From: |
Bruno Haible |
Subject: |
Re: new module write-any-file |
Date: |
Fri, 30 Mar 2007 01:40:10 +0200 |
User-agent: |
KMail/1.5.4 |
Paul Eggert wrote:
> > And if priv_allocset succeeds, it will not cache the result,
> > but instead redo the same system calls next time. Is this intentional?
>
> I don't follow this point; it looks to me like it caches.
When priv_allocset is callable, the function looks like this:
bool
can_write_any_file (void)
{
static bool initialized;
static bool can;
if (! initialized)
{
priv_set_t *pset = priv_allocset ();
if (pset)
{
can =
(getppriv (PRIV_EFFECTIVE, pset) == 0
&& priv_ismember (pset, PRIV_FILE_DAC_WRITE));
priv_freeset (pset);
}
else
initialized = true;
}
return can;
}
So if priv_allocset () succeeds, the 'initialized' variable stays false all
the time, and every invocation calls priv_allocset, getppriv, priv_ismember,
and priv_freeset again.
> Perhaps it's the "else #else" which confused you? (It certainly confuses
> me...)
If it confuses even you, then it's late time to make this code more
readable! To follow Jim's habit of "no #ifs inside a function", you can for
example put the core of this function into a 'static inline' function
called 'can_write_any_file_uncached'.
Bruno