Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cassandane: run fakeldapd as a DAEMON rather than a START #4554

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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