X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FLEI.pm;h=f6bc920d4cae9cecf849eb648683703b881eb93e;hb=a4fa97d8ecd32927f0f3d6580c474059b59dabd2;hp=ef3f90fce9883952ce82986947e64946df0a0260;hpb=d44073df16b9ae461ec445bea45a3c48451ae1e4;p=public-inbox.git diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index ef3f90fc..f6bc920d 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -84,6 +84,7 @@ our %CMD = ( # sorted in order of importance/use: 'q' => [ 'SEARCH_TERMS...', 'search for messages matching terms', qw( save-as=s output|mfolder|o=s format|f=s dedupe|d=s thread|t augment|a sort|s=s reverse|r offset=i remote local! external! pretty mua-cmd=s + verbose|v since|after=s until|before=s), opt_dash('limit|n=i', '[0-9]+') ], 'show' => [ 'MID|OID', 'show a given object (Message-ID or object ID)', @@ -278,6 +279,16 @@ sub fail ($$;$) { undef; } +sub child_error { # passes non-fatal curl exit codes to user + my ($self, $child_error) = @_; # child_error is $? + if (my $sock = $self->{sock}) { # send to lei(1) client + send($sock, "child_error $child_error", MSG_EOR); + } else { # oneshot + $self->{child_error} = $child_error; + } + undef; +} + sub atfork_prepare_wq { my ($self, $wq) = @_; my $tcafc = $wq->{-ipc_atfork_child_close} //= [ $listener // () ]; @@ -959,19 +970,21 @@ sub lazy_start { exit($exit_code // 0); } -# for users w/o Socket::Msghdr +# for users w/o Socket::Msghdr installed or Inline::C enabled sub oneshot { my ($main_pkg) = @_; my $exit = $main_pkg->can('exit'); # caller may override exit() local $quit = $exit if $exit; local %PATH2CFG; umask(077) // die("umask(077): $!"); - dispatch((bless { + my $self = bless { 0 => *STDIN{GLOB}, 1 => *STDOUT{GLOB}, 2 => *STDERR{GLOB}, env => \%ENV - }, __PACKAGE__), @ARGV); + }, __PACKAGE__; + dispatch($self, @ARGV); + x_it($self, $self->{child_error}) if $self->{child_error}; } # ensures stdout hits the FS before sock disconnects so a client