Code Monkey home page Code Monkey logo

Comments (5)

benschumacher avatar benschumacher commented on July 29, 2024

Eric-

The previous issue #23 indicates that leaving the file open causes problems in some scenarios. I think closing the FD is an appropriate solution, but it seems like this could be a race condition and is possible related to being run multithreaded -- the code not being particularly robust for this sort of behavior. (NSCD, for example, is threaded.)

If you changed the magic() function to this definition, I believe it would solve this issue, if indeed it is the issue (you might need to #include <pthread.h>, too):

#include <pthread.h>
/*
 * magic - Returns the next magic number.
 */
u_int32_t
magic()
{
    static pthread_once_t magic_control = PTHREAD_ONCE_INIT;

    pthread_once(&magic_control, &magic_init);

    return (u_int32_t)random();
}

(I haven't tried running this code yet, but I have confirmed it does compile.)

I can also create a pull request for it when I get a chance. With this change, the 'magic_initialised' variable isn't used any longer, so it could be removed, as well.

Hope this helps,
Ben

from pam_tacplus.

daveolson53 avatar daveolson53 commented on July 29, 2024

benschumacher [email protected] wrote:

The previous issue #23 indicates that leaving the file open causes problems in
some scenarios. I think closing the FD is an appropriate solution, but it seems
like this could be a race condition and is possible related to being run
multithreaded -- the code not being particularly robust for this sort of
behavior. (NSCD, for example, is threaded.)

If you changed the magic() function to this definition, I believe it would
solve this issue, if indeed it is the issue (you might need to #include
<pthread.h>, too):

I think that's not a good idea. Big chunks of the code aren't thread
safe, so there isn't a reason to patch this one tiny thing.

I'd suggest saving that until the code is made thread safe, and do all the work
together.

Dave Olson
[email protected]

from pam_tacplus.

ehoffman2 avatar ehoffman2 commented on July 29, 2024

I don't think it's multi-thread related. In my scenario, I have only one thread running the code. The problem really is because when the function is called the first time, the file is opened (rfd is initialized) and is then closed (thus, the referenced FD is obsolete) before return to caller. The second time magic() is called (within the same tread), the file descriptor is now invalid (and not re-initialized). Data is read from whatever file is referenced by the obsolete descriptor.

Regards,
Eric

from pam_tacplus.

daveolson53 avatar daveolson53 commented on July 29, 2024

ehoffman2 [email protected] wrote:

I don't think it's multi-thread related. In my scenario, I have only one thread
running the code. The problem really is because when the function is called the
first time, the file is opened (rfd is initialized) and is then closed (thus,
the referenced FD is obsolete) before return to caller. The second time magic()
is called (within the same tread), the file descriptor is now invalid (and not
re-initialized). Data is read from whatever file is referenced by the obsolete
descriptor.

That sounds like the problem that was addressed by an earlier change.
Maybe I'm confused, though.

I any case, I stand by my recommendation that we not try to apply
the thread patch.

Dave Olson
[email protected]

from pam_tacplus.

kravietz avatar kravietz commented on July 29, 2024

The whole magic.c is now replaced by OpenSSL.

from pam_tacplus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.