Skip to content

Commit

Permalink
Instance: run fakesaslauthd as a wait=y DAEMON
Browse files Browse the repository at this point in the history
not strictly related to this PR, but I've been wanting to do this
for ages, and now I can, and it shows that the previous commit works
  • Loading branch information
elliefm committed Jun 26, 2023
1 parent 10ff8d4 commit ea553b5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
5 changes: 5 additions & 0 deletions cassandane/Cassandane/Cyrus/Info.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ sub run_cyr_info
my @res = readline(RESULTS);
close RESULTS;

if ($args[0] eq 'proc') {
# if we see our fakesaslauthd, no we didn't
@res = grep { $_ !~ m/\bfakesaslauthd\b/ } @res;
}

return @res;
}

Expand Down
35 changes: 24 additions & 11 deletions cassandane/Cassandane/Instance.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1200,16 +1200,31 @@ sub start
}

# arrange for fakesaslauthd to be started by master
# XXX make this run as a DAEMON rather than a START
my $fakesaslauthd_socket = "$self->{basedir}/run/mux";
my $fakesaslauthd_isdaemon = 1;
if ($self->{authdaemon}) {
$self->add_start(
name => 'fakesaslauthd',
argv => [
abs_path('utils/fakesaslauthd'),
'-p', $fakesaslauthd_socket,
],
);
my ($maj, $min) = Cassandane::Instance->get_version(
$self->{installation});
if ($maj < 3 || ($maj == 3 && $min < 4)) {
$self->add_start(
name => 'fakesaslauthd',
argv => [
abs_path('utils/fakesaslauthd'),
'-p', $fakesaslauthd_socket,
],
);
$fakesaslauthd_isdaemon = 0;
}
elsif (not exists $self->{daemons}->{fakesaslauthd}) {
$self->add_daemon(
name => 'fakesaslauthd',
argv => [
abs_path('utils/fakesaslauthd'),
'-p', $fakesaslauthd_socket,
],
wait => 'y',
);
}
}

if (!$self->{re_use_dir} || ! -d $self->{basedir})
Expand Down Expand Up @@ -1243,9 +1258,7 @@ sub start

# give fakesaslauthd a moment (but not more than 2s) to set up its
# socket before anything starts trying to connect to services
# XXX if this were a DAEMON with wait=y, this would be unnecessary,
# XXX though those didn't exist until 3.4
if ($self->{authdaemon}) {
if ($self->{authdaemon} && !$fakesaslauthd_isdaemon) {
my $tries = 0;
while (not -S $fakesaslauthd_socket && $tries < 2_000_000) {
$tries += usleep(10_000); # 10ms as us
Expand Down
19 changes: 18 additions & 1 deletion cassandane/utils/fakesaslauthd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# for any user. Use me for testing!

use Getopt::Std;
use IO::Handle;
use IO::Socket::UNIX;
use Sys::Syslog qw(:standard :macros);

Expand All @@ -16,13 +17,22 @@ sub get_counted_string
return unpack("A$size", $data);
}

# 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;

getopts("C:dp:v", \%opts);

die "need a socket path" if not $opts{p};

openlog('fakesaslauthd', '', LOG_LOCAL6)
openlog('fakesaslauthd', 'pid', LOG_LOCAL6)
or die "Cannot openlog";

# ok, we're good. background ourselves
Expand All @@ -46,6 +56,13 @@ syslog LOG_INFO, "listening on $opts{p}";
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 $client = $sock->accept()) {
my $LoginName = get_counted_string($client);
my $Password = get_counted_string($client);
Expand Down

0 comments on commit ea553b5

Please sign in to comment.