From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 791C61F9FC for ; Thu, 14 Oct 2021 04:32:55 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/3] lei add-external --mirror: respect client umask Date: Thu, 14 Oct 2021 04:32:54 +0000 Message-Id: <20211014043255.19545-3-e@80x24.org> In-Reply-To: <20211014043255.19545-1-e@80x24.org> References: <20211014043255.19545-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: While lei is intended for non-public mail and runs umask(077) by default, externals are one area which can safely defer to the user's umask. Instead of sending it unconditionally with every command, only have lei-daemon request it when necessary. --- lib/PublicInbox/LEI.pm | 11 +++++++++++ lib/PublicInbox/LeiMirror.pm | 2 ++ script/lei | 2 ++ 3 files changed, 15 insertions(+) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index bd8a6bef632b..635cd0c5508a 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -1518,4 +1518,15 @@ sub cfg_dump ($$) { undef; } +sub request_umask { + my ($lei) = @_; + my $s = $lei->{sock} // return; + send($s, 'umask', MSG_EOR) // die "send: $!"; + vec(my $rvec = '', fileno($s), 1) = 1; + select($rvec, undef, undef, 2) or die 'timeout waiting for umask'; + recv($s, my $v, 5, 0) // die "recv: $!"; + (my $u, $lei->{client_umask}) = unpack('AV', $v); + $u eq 'u' or warn "E: recv $v has no umask"; +} + 1; diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm index 1369c00c57fd..fb73d8631670 100644 --- a/lib/PublicInbox/LeiMirror.pm +++ b/lib/PublicInbox/LeiMirror.pm @@ -424,6 +424,7 @@ sub start_clone_url { sub do_mirror { # via wq_io_do my ($self) = @_; my $lei = $self->{lei}; + umask($lei->{client_umask}) if defined $lei->{client_umask}; eval { my $iv = $lei->{opt}->{'inbox-version'}; if (defined $iv) { @@ -448,6 +449,7 @@ sub start { require PublicInbox::Inbox; require PublicInbox::Admin; require PublicInbox::InboxWritable; + $lei->request_umask; my ($op_c, $ops) = $lei->workers_start($self, 1); $lei->{wq1} = $self; $self->wq_io_do('do_mirror', []); diff --git a/script/lei b/script/lei index bc43779821e7..8f6e8aacb86b 100755 --- a/script/lei +++ b/script/lei @@ -122,6 +122,8 @@ while (1) { $exec_cmd->(\@fds, split(/\0/, $1)); } elsif ($buf eq '-WINCH') { kill($buf, @parent); # for MUA + } elsif ($buf eq 'umask') { + send($sock, 'u'.pack('V', umask), MSG_EOR) or die "send: $!" } elsif ($buf =~ /\Ax_it ([0-9]+)\z/) { $x_it_code ||= $1 + 0; last;