Skip to content

Commit

Permalink
Merge pull request #4554 from elliefm/v39/cass-fakeldapd-as-daemon
Browse files Browse the repository at this point in the history
cassandane: run fakeldapd as a DAEMON rather than a START
  • Loading branch information
elliefm authored Aug 2, 2023
2 parents ec3eefd + 17069b2 commit 5619bbd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
7 changes: 5 additions & 2 deletions cassandane/Cassandane/Cyrus/Info.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ sub run_cyr_info
close RESULTS;

if ($args[0] eq 'proc') {
# if we see our fakesaslauthd, no we didn't
@res = grep { $_ !~ m/\bfakesaslauthd\b/ } @res;
# if we see any of our fake daemons, no we didn't
my @fakedaemons = qw(fakesaslauthd fakeldapd);
my $pattern = q{\b(?:} . join(q{|}, @fakedaemons) . q{)\b};
my $re = qr{$pattern};
@res = grep { $_ !~ m/$re/ } @res;
}

return @res;
Expand Down
33 changes: 23 additions & 10 deletions cassandane/Cassandane/Cyrus/LDAP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,30 @@ sub set_up
);

# arrange for the fakeldapd to be started
# XXX make this run as a DAEMON rather than a START
$self->{instance}->add_start(
name => 'fakeldapd',
argv => [
realpath('utils/fakeldapd'),
'-p', $self->{ldapport},
'-l', realpath('data/directory.ldif'),
],
);
$self->_start_instances();
my ($maj, $min) = Cassandane::Instance->get_version($self->{installation});
if ($maj < 3 || ($maj == 3 && $min < 4)) {
$self->{instance}->add_start(
name => 'fakeldapd',
argv => [
realpath('utils/fakeldapd'),
'-p', $self->{ldapport},
'-l', realpath('data/directory.ldif'),
],
);
}
elsif (not exists $self->{daemons}->{fakeldapd}) {
$self->{instance}->add_daemon(
name => 'fakeldapd',
argv => [
realpath('utils/fakeldapd'),
'-p', $self->{ldapport},
'-l', realpath('data/directory.ldif'),
],
wait => 'y',
);
}

$self->_start_instances();
$self->{instance}->create_user("otheruser");
}

Expand Down
19 changes: 18 additions & 1 deletion cassandane/utils/fakeldapd
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,21 @@ package main;

use Data::Dumper;
use Getopt::Std;
use IO::Handle;
use IO::Select;
use IO::Socket;
use Net::LDAP::LDIF;
use Net::LDAP::Util qw(canonical_dn);

# support running as a DAEMON with wait=y:
# * if fd 3 is already open, then we will need to write to it later to
# indicate we're ready.
# * we must grab this early, before the number gets used for something
# else, otherwise we won't be able to differentiate between the fd 3
# we care about or some other thing
# * if fd 3 was not already open, $status_fd will be undef
my $status_fd = IO::Handle->new_from_fd(3, 'w');

my %opts;
my %data;

Expand All @@ -151,7 +161,7 @@ while (not $ldif->eof()) {
}
die "ldif file contained no entries" if not scalar keys %data;

# ok, we're good. background ourselves
# ok, we're good. background ourselves if necessary
if (not $opts{d} and not $ENV{CYRUS_ISDAEMON}) {
my $pid = fork;
die "unable to fork: $!" if not defined $pid;
Expand All @@ -168,6 +178,13 @@ my $shutdown = 0;

$SIG{HUP} = sub { $shutdown++; };

# okay, now we're ready to accept requests. inform our parent,
# if they were waiting to be informed
if ($ENV{CYRUS_ISDAEMON} && $status_fd) {
print $status_fd "ok\r\n";
undef $status_fd;
}

while (my @ready = $select->can_read()) {
foreach my $fh (@ready) {
if ($fh == $listen) {
Expand Down

0 comments on commit 5619bbd

Please sign in to comment.