Skip to content

semget fails when there a semaphore with semid 0 #72

@martinkoehler

Description

@martinkoehler

I ran in the same bug as Siarhei Kuchynski:
The following code in line 64 of Log::Log4perl::Util::Semaphore should fix this:
64 defined($self->{id} = semget( $self->{ikey}, 1, 0 ))

He observes:
"When a semaphore with specified key (0x6f6e616e) and semid = 0 already
exists, semget fails for this semaphore:

bash-4.0# ipcs -s

Verberge zitierten Text
------ Semaphore Arrays --------

key semid owner perms nsems

0x6f6e616e 0 root 777 1

with the following error message

semget(1869504878) failed: at
/usr/share/perl5/vendor_perl//Log/Log4perl/Util/Semaphore.pm line 64.

This is caused by line 64 of Log::Log4perl::Util::Semaphore.pm

63 print "Semaphore '$self->{key}' already exists\n" if INTERNAL_DEBUG;

64 $self->{id} = semget( $self->{ikey}, 1, 0 )

65 or die "semget($self->{ikey}) failed: $!";

semget returns ID 0 for the key 1869504878 and dies, though 0 should be
considered to be valid ID
According to http://perldoc.perl.org/functions/semget.html:
semget KEY,NSEMS,FLAGS
Calls the System V IPC function semget(2). Returns the semaphore id, or the
undefined value on error.
It seems that init method should call die only if semget returns undefined
value, not zero.
"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions