5 # dgit-repos-server DISTRO DISTRO-DIR AUTH-SPEC [<settings>] --ssh
6 # dgit-repos-server DISTRO DISTRO-DIR AUTH-SPEC [<settings>] --cron
8 # --repos=GIT-REPOS-DIR default DISTRO-DIR/repos/
9 # --suites=SUITES-FILE default DISTRO-DIR/suites
10 # --policy-hook=POLICY-HOOK default DISTRO-DIR/policy-hook
11 # --dgit-live=DGIT-LIVE-DIR default DISTRO-DIR/dgit-live
12 # (DISTRO-DIR is not used other than as default)
14 # .../dgit-repos-server --pre-receive-hook PACKAGE
16 # Invoked as the ssh restricted command
18 # Works like git-receive-pack
20 # SUITES is the name of a file which lists the permissible suites
21 # one per line (#-comments and blank lines ignored)
23 # AUTH-SPEC is a :-separated list of
24 # KEYRING.GPG,AUTH-SPEC
25 # where AUTH-SPEC is one of
30 $SIG{__WARN__} = sub { die $_[0]; };
32 # DGIT-REPOS-DIR contains:
33 # git tree (or other object) lock (in acquisition order, outer first)
35 # _tmp/PACKAGE_prospective ! } SAME.lock, held during receive-pack
37 # _tmp/PACKAGE_incoming$$ ! } SAME.lock, held during receive-pack
38 # _tmp/PACKAGE_incoming$$_fresh ! }
40 # PACKAGE.git } PACKAGE.git.lock
41 # PACKAGE_garbage } (also covers executions of
42 # PACKAGE_garbage-old } policy hook script for PACKAGE)
43 # PACKAGE_garbage-tmp }
44 # policy* } (for policy hook script, covered by
45 # } lock only when invoked for a package)
47 # leaf locks, held during brief operaton only:
52 # _template } SAME.lock
54 # locks marked ! may be held during client data transfer
56 # What we do on push is this:
57 # - extract the destination repo name
58 # - make a hardlink clone of the destination repo
59 # - provide the destination with a stunt pre-receive hook
60 # - run actual git-receive-pack with that new destination
61 # as a result of this the stunt pre-receive hook runs; it does this:
62 # + understand what refs we are allegedly updating and
63 # check some correspondences:
64 # * we are updating only refs/tags/debian/* and refs/dgit/*
65 # * and only one of each
66 # * and the tag does not already exist
68 # * recover the suite name from the destination refs/dgit/ ref
69 # + disassemble the signed tag into its various fields and signature
71 # * parsing the first line of the tag message to recover
72 # the package name, version and suite
73 # * checking that the package name corresponds to the dest repo name
74 # * checking that the suite name is as recovered above
75 # + verify the signature on the signed tag
76 # and if necessary check that the keyid and package are listed in dm.txt
77 # + check various correspondences:
78 # * the signed tag must refer to a commit
79 # * the signed tag commit must be the refs/dgit value
80 # * the name in the signed tag must correspond to its ref name
81 # * the tag name must be debian/<version> (massaged as needed)
82 # * the suite is one of those permitted
83 # * the signed tag has a suitable name
84 # * run the "push" policy hook
85 # * replay prevention for --deliberately-not-fast-forward
86 # * check the commit is a fast forward
87 # * handle a request from the policy hook for a fresh repo
88 # + push the signed tag and new dgit branch to the actual repo
90 # If the destination repo does not already exist, we need to make
91 # sure that we create it reasonably atomically, and also that
92 # we don't every have a destination repo containing no refs at all
93 # (because such a thing causes git-fetch-pack to barf). So then we
94 # do as above, except:
95 # - before starting, we take out our own lock for the destination repo
96 # - we create a prospective new destination repo by making a copy
98 # - we use the prospective new destination repo instead of the
99 # actual new destination repo (since the latter doesn't exist)
100 # - after git-receive-pack exits, we
101 # + check that the prospective repo contains a tag and head
102 # + rename the prospective destination repo into place
105 # - We are crash-only
106 # - Temporary working trees and their locks are cleaned up
107 # opportunistically by a program which tries to take each lock and
108 # if successful deletes both the tree and the lockfile
109 # - Prospective working trees and their locks are cleaned up by
110 # a program which tries to take each lock and if successful
111 # deletes any prospective working tree and the lock (but not
112 # of course any actual tree)
113 # - It is forbidden to _remove_ the lockfile without removing
114 # the corresponding temporary tree, as the lockfile is also
115 # a stampfile whose presence indicates that there may be
118 # Policy hook script is invoked like this:
119 # POLICY-HOOK-SCRIPT DISTRO DGIT-REPOS-DIR DGIT-LIVE-DIR ACTION...
121 # POLICY-HOOK-SCRIPT ... check-list [...]
122 # POLICY-HOOK-SCRIPT ... check-package PACKAGE [...]
123 # POLICY-HOOK-SCRIPT ... push PACKAGE \
124 # VERSION SUITE TAGNAME DELIBERATELIES [...]
125 # POLICY-HOOK-SCRIPT ... push-confirm PACKAGE \
126 # VERSION SUITE TAGNAME DELIBERATELIES FRESH-REPO|'' [...]
128 # Exit status is a bitmask. Bit weight constants are defined in Dgit.pm.
130 # suppress dgit-repos-server's fast-forward check ("push" only)
132 # blow away repo right away (ie, as if before push or fetch)
133 # ("check-package" and "push" only)
134 # any unexpected bits mean failure, and then known set bits are ignored
135 # if no unexpected bits set, operation continues (subject to meaning
136 # of any expected bits set). So, eg, exit 0 means "continue normally"
137 # and would be appropriate for an unknown action.
139 # cwd for push and push-confirm is a temporary repo where the
140 # to-be-pushed objects have been received; TAGNAME is the
143 # FRESH-REPO is '' iff the repo for this package already existed, or
144 # the pathname of the newly-created repo which will be renamed into
145 # place if everything goes well. (NB that this is generally not the
146 # same repo as the cwd, because the objects are first received into a
147 # temporary repo so they can be examined.)
149 # if push requested FRESHREPO, push-confirm happens in said fresh repo
150 # and FRESH-REPO is guaranteed not to be ''.
152 # policy hook for a particular package will be invoked only once at
153 # a time - (see comments about DGIT-REPOS-DIR, above)
155 # check-list and check-package are invoked via the --cron option.
156 # First, without any locking, check-list is called. It should produce
157 # a list of package names. Then check-package will be invoked for
158 # each named package, in each case after taking an appropriate lock.
160 # If policy hook wants to run dgit (or something else in the dgit
161 # package), it should use DGIT-LIVE-DIR/dgit (etc.)
165 use Fcntl qw(:flock);
166 use File::Path qw(rmtree);
168 use Debian::Dgit qw(:DEFAULT :policyflags);
170 open DEBUG, ">/dev/null" or die $!;
188 #----- utilities -----
191 print DEBUG "$debug @_\n";
194 sub realdestrepo () { "$dgitrepos/$package.git"; }
196 sub acquirelock ($$) {
197 my ($lock, $must) = @_;
199 printf DEBUG "$debug locking %s %d\n", $lock, $must;
202 $fh = new IO::File $lock, ">" or die "open $lock: $!";
203 my $ok = flock $fh, $must ? LOCK_EX : (LOCK_EX|LOCK_NB);
205 die "flock $lock: $!" if $must;
206 debug " locking $lock failed";
209 next unless stat_exists $lock;
210 my $want = (stat _)[1];
212 my $got = (stat _)[1];
213 last if $got == $want;
218 sub acquirermtree ($$) {
219 my ($tree, $must) = @_;
220 my $fh = acquirelock("$tree.lock", $must);
228 sub locksometree ($) {
230 acquirelock("$tree.lock", 1);
233 sub lockrealtree () {
234 locksometree(realdestrepo);
238 my $tmpdir = "$dgitrepos/_tmp";
239 return if mkdir $tmpdir;
240 return if $! == EEXIST;
244 sub recorderror ($) {
246 my $w = $ENV{'DGIT_DRS_WORK'}; # we are in stunthook
249 open ERR, ">", "$w/drs-error" or die $!;
250 print ERR $why, "\n" or die $!;
259 recorderror "reject: $why";
260 die "dgit-repos-server: reject: $why\n";
266 local $Data::Dumper::Indent = 0;
267 local $Data::Dumper::Terse = 1;
268 debug "|".Dumper(\@_);
276 die "@_ $? $!" if $r;
280 my ($policyallowbits, @polargs) = @_;
281 # => ($exitstatuspolicybitmap);
282 die if $policyallowbits & ~0x3e;
283 my @cmd = ($policyhook,$distro,$dgitrepos,$dgitlive,@polargs);
286 die "system: $!" if $r < 0;
287 die "hook (@cmd) failed ($?)" if $r & ~($policyallowbits << 8);
288 debug sprintf "hook (%s) => %#x", "@polargs", $r;
292 sub mkemptyrepo ($$) {
293 my ($dir,$sharedperm) = @_;
294 runcmd qw(git init --bare --quiet), "--shared=$sharedperm", $dir;
297 sub mkrepo_fromtemplate ($) {
299 my $template = "$dgitrepos/_template";
300 locksometree($template);
301 debug "copy template $template -> $dir";
302 my $r = system qw(cp -a --), $template, $dir;
303 !$r or die "create new repo $dir failed: $r $!";
306 sub movetogarbage () {
307 # realdestrepo must have been locked
308 my $garbagerepo = "$dgitrepos/${package}_garbage";
309 # We arrange to always keep at least one old tree, for anti-rewind
310 # purposes (and, I guess, recovery from mistakes). This is either
311 # $garbage or $garbage-old.
312 if (stat_exists "$garbagerepo") {
313 rmtree "$garbagerepo-tmp";
314 if (rename "$garbagerepo-old", "$garbagerepo-tmp") {
315 rmtree "$garbagerepo-tmp";
317 die "$garbagerepo $!" unless $!==ENOENT;
319 rename "$garbagerepo", "$garbagerepo-old" or die "$garbagerepo $!";
321 rename realdestrepo, $garbagerepo
323 or die "$garbagerepo $!";
326 #----- git-receive-pack -----
328 sub fixmissing__git_receive_pack () {
330 $destrepo = "$dgitrepos/_tmp/${package}_prospective";
331 acquirermtree($destrepo, 1);
332 mkrepo_fromtemplate($destrepo);
335 sub makeworkingclone () {
337 $workrepo = "$dgitrepos/_tmp/${package}_incoming$$";
338 acquirermtree($workrepo, 1);
339 my $lfh = lockrealtree();
340 runcmd qw(git clone -l -q --mirror), $destrepo, $workrepo;
342 rmtree "${workrepo}_fresh";
345 sub setupstunthook () {
346 my $prerecv = "$workrepo/hooks/pre-receive";
347 my $fh = new IO::File $prerecv, O_WRONLY|O_CREAT|O_TRUNC, 0777
348 or die "$prerecv: $!";
349 print $fh <<END or die "$prerecv: $!";
352 exec $0 --pre-receive-hook $package
354 close $fh or die "$prerecv: $!";
355 $ENV{'DGIT_DRS_WORK'}= $workrepo;
356 $ENV{'DGIT_DRS_DEST'}= $destrepo;
357 debug " stunt hook set up $prerecv";
360 sub dealwithfreshrepo () {
361 my $freshrepo = "${workrepo}_fresh";
362 return unless stat_exists $freshrepo;
363 $destrepo = $freshrepo;
366 sub maybeinstallprospective () {
367 return if $destrepo eq realdestrepo;
369 if (open REJ, "<", "$workrepo/drs-error") {
372 REJ->error and die $!;
376 $!==&ENOENT or die $!;
379 debug " show-ref ($destrepo) ...";
381 my $child = open SR, "-|";
382 defined $child or die $!;
384 chdir $destrepo or die $!;
385 exec qw(git show-ref);
388 my %got = qw(tag 0 head 0);
391 debug " show-refs| $_";
392 s/^\S*[1-9a-f]\S* (\S+)$/$1/ or die;
394 m{^refs/tags/} ? 'tag' :
395 m{^refs/dgit/} ? 'head' :
399 $!=0; $?=0; close SR or $?==256 or die "$? $!";
401 debug "installprospective ?";
402 die Dumper(\%got)." -- missing refs in new repo"
403 if grep { !$_ } values %got;
407 if ($destrepo eq "${workrepo}_fresh") {
411 debug "install $destrepo => ".realdestrepo;
412 rename $destrepo, realdestrepo or die $!;
413 remove "$destrepo.lock" or die $!;
416 sub main__git_receive_pack () {
419 runcmd qw(git receive-pack), $workrepo;
421 maybeinstallprospective();
424 #----- stunt post-receive hook -----
426 our ($tagname, $tagval, $suite, $oldcommit, $commit);
427 our ($version, %tagh);
430 debug " updates ...";
434 m/^(\S+) (\S+) (\S+)$/ or die "$_ ?";
435 my ($old, $sha1, $refname) = ($1, $2, $3);
436 if ($refname =~ m{^refs/tags/(?=debian/)}) {
437 reject "pushing multiple tags!" if defined $tagname;
440 reject "tag $tagname already exists -".
441 " not replacing previously-pushed version"
443 } elsif ($refname =~ m{^refs/dgit/}) {
444 reject "pushing multiple heads!" if defined $suite;
449 reject "pushing unexpected ref!";
452 STDIN->error and die $!;
454 reject "push is missing tag ref update" unless defined $tagname;
455 reject "push is missing head ref update" unless defined $suite;
456 debug " updates ok.";
460 debug " parsetag...";
461 open PT, ">dgit-tmp/plaintext" or die $!;
462 open DS, ">dgit-tmp/plaintext.asc" or die $!;
463 open T, "-|", qw(git cat-file tag), $tagval or die $!;
465 $!=0; $_=<T>; defined or die $!;
467 if (m/^(\S+) (.*)/) {
468 push @{ $tagh{$1} }, $2;
475 $!=0; $_=<T>; defined or die $!;
476 m/^($package_re) release (\S+) for \S+ \((\S+)\) \[dgit\]$/ or
477 reject "tag message not in expected format";
479 die unless $1 eq $package;
481 die "$3 != $suite " unless $3 eq $suite;
485 print PT $copyl or die $!;
486 $!=0; $_=<T>; defined or die "missing signature? $!";
488 if (m/^\[dgit ([^"].*)\]$/) { # [dgit "something"] is for future
491 if (s/^distro\=(\S+) //) {
492 die "$1 != $distro" unless $1 eq $distro;
493 } elsif (s/^(--deliberately-$package_re) //) {
494 push @deliberatelies, $1;
495 } elsif (s/^supersede:(\S+)=(\w+) //) {
496 die "supersede $1 twice" if defined $supersedes{$1};
497 $supersedes{$1} = $2;
498 } elsif (s/^[-+.=0-9a-z]\S* //) {
500 die "unknown dgit info in tag ($_)";
505 last if m/^-----BEGIN PGP/;
516 debug " parsetag ok.";
519 sub checksig_keyring ($) {
520 my ($keyringfile) = @_;
521 # returns primary-keyid if signed by a key in this keyring
523 # or dies on other errors
527 debug " checksig keyring $keyringfile...";
529 our @cmd = (qw(gpgv --status-fd=1 --keyring),
531 qw(dgit-tmp/plaintext.asc dgit-tmp/plaintext));
538 next unless s/^\[GNUPG:\] //;
540 debug " checksig| $_";
541 my @l = split / /, $_;
542 if ($l[0] eq 'NO_PUBKEY') {
544 } elsif ($l[0] eq 'VALIDSIG') {
546 $sigtype eq '00' or reject "signature is not of type 00!";
548 die unless defined $ok;
554 debug sprintf " checksig ok=%d", !!$ok;
559 sub dm_txt_check ($$) {
560 my ($keyid, $dmtxtfn) = @_;
561 debug " dm_txt_check $keyid $dmtxtfn";
562 open DT, '<', $dmtxtfn or die "$dmtxtfn $!";
564 m/^fingerprint:\s+$keyid$/oi
566 if (s/^allow:/ /i..0) {
569 or reject "key $keyid missing Allow section in permissions!";
574 or reject "package $package not allowed for key $keyid";
579 debug " dm_txt_check allow| $_";
580 foreach my $p (split /\s+/) {
581 if ($p eq $package) {
583 debug " dm_txt_check ok";
588 DT->error and die $!;
590 reject "key $keyid not in permissions list although in keyring!";
594 foreach my $kas (split /:/, $keyrings) {
595 debug "verifytag $kas...";
596 $kas =~ s/^([^,]+),// or die;
597 my $keyid = checksig_keyring $1;
598 if (defined $keyid) {
599 if ($kas =~ m/^a$/) {
600 debug "verifytag a ok";
602 } elsif ($kas =~ m/^m([^,]+)$/) {
603 dm_txt_check($keyid, $1);
604 debug "verifytag m ok";
611 reject "key not found in keyrings";
615 debug "checksuite ($suitesfile)";
616 open SUITES, "<", $suitesfile or die $!;
622 return if $_ eq $suite;
624 die $! if SUITES->error;
625 reject "unknown suite";
628 sub checktagnoreplay () {
629 # We check that the signed tag mentions the name and value of
630 # (a) in the case of FRESHREPO all tags in the repo;
631 # (b) in the case of just NOFFCHECK all tags referring to
632 # the current head for the suite (there must be at least one).
633 # This prevents a replay attack using an earlier signed tag.
634 return unless $policy & (FRESHREPO|NOFFCHECK);
636 my $garbagerepo = "$dgitrepos/${package}_garbage";
640 foreach my $garb ("$garbagerepo", "$garbagerepo-old") {
641 if (stat_exists $garb) {
642 $ENV{GIT_DIR} = $garb;
646 if (!defined $ENV{GIT_DIR}) {
647 # Nothing to overwrite so the FRESHREPO and NOFFCHECK were
648 # pointless. Oh well.
649 debug "checktagnoreplay - no garbage, ok";
654 if (!($policy & FRESHREPO)) {
655 my $branch = server_branch($suite);
657 `git for-each-ref --format='%(objectname)' '[r]efs/$branch'`;
658 defined or die "$branch $? $!";
659 $? and die "$branch $?";
661 # No such branch - NOFFCHECK was unnecessary. Oh well.
662 debug "checktagnoreplay - not FRESHREPO, new branch, ok";
665 m/^(\w+)\n$/ or die "$branch $_ ?";
667 debug "checktagnoreplay - not FRESHREPO,".
668 " checking for overwriting refs/$branch=$onlyreferring";
673 git_for_each_tag_referring($onlyreferring, sub {
674 my ($objid,$fullrefname,$tagname) = @_;
675 debug "checktagnoreplay - overwriting $fullrefname=$objid";
676 my $supers = $supersedes{$fullrefname};
677 if (!defined $supers) {
678 push @problems, "does not supersede $fullrefname";
679 } elsif ($supers ne $objid) {
681 "supersedes $fullrefname=$supers but previously $fullrefname=$objid";
688 reject "replay attack prevention check failed:".
689 " signed tag for $version: ".
690 join("; ", @problems).
693 debug "checktagnoreply - all ok"
698 my $vals = $tagh{$tag};
699 reject "missing header $tag in signed tag object" unless $vals;
700 reject "multiple headers $tag in signed tag object" unless @$vals == 1;
707 tagh1('type') eq 'commit' or reject "tag refers to wrong kind of object";
708 tagh1('object') eq $commit or reject "tag refers to wrong commit";
709 tagh1('tag') eq $tagname or reject "tag name in tag is wrong";
714 debug "translated version $v";
715 $tagname eq "debian/$v" or die;
719 my @policy_args = ($package,$version,$suite,$tagname,
720 join(",",@deliberatelies));
721 $policy = policyhook(NOFFCHECK|FRESHREPO, 'push', @policy_args);
726 # check that our ref is being fast-forwarded
727 debug "oldcommit $oldcommit";
728 if (!($policy & NOFFCHECK) && $oldcommit =~ m/[^0]/) {
729 $?=0; $!=0; my $mb = `git merge-base $commit $oldcommit`;
731 $mb eq $oldcommit or reject "not fast forward on dgit branch";
734 if ($policy & FRESHREPO) {
735 # This is troublesome. We have been asked by the policy hook
736 # to receive the push into a fresh repo. But of course we
737 # have actually already mostly received the push into the working
738 # repo. (This is unavoidable because the instruction to use a new
739 # repo comes ultimately from the signed tag for the dgit push,
740 # which has to have been received into some repo.)
742 # So what we do is generate a fresh working repo right now and
743 # push the head and tag into it. The presence of this fresh
744 # working repo is detected by the parent, which responds by
745 # making a fresh master repo from the template.
747 $destrepo = "${workrepo}_fresh"; # workrepo lock covers
748 mkrepo_fromtemplate $destrepo;
751 my $willinstall = ($destrepo eq realdestrepo ? '' : $destrepo);
752 policyhook(0, 'push-confirm', @policy_args, $willinstall);
756 my @cmd = (qw(git send-pack), $destrepo);
757 push @cmd, qw(--force) if $policy & NOFFCHECK;
758 push @cmd, "$commit:refs/dgit/$suite",
759 "$tagval:refs/tags/$tagname";
763 !$r or die "onward push to $destrepo failed: $r $!";
768 chdir $workrepo or die "chdir $workrepo: $!";
769 mkdir "dgit-tmp" or $!==EEXIST or die $!;
775 debug "stunthook done.";
778 #----- git-upload-pack -----
780 sub fixmissing__git_upload_pack () {
781 $destrepo = "$dgitrepos/_empty";
782 my $lfh = locksometree($destrepo);
783 return if stat_exists $destrepo;
784 rmtree "$destrepo.new";
785 mkemptyrepo "$destrepo.new", "0644";
786 rename "$destrepo.new", $destrepo or die $!;
787 unlink "$destrepo.lock" or die $!;
791 sub main__git_upload_pack () {
792 my $lfh = locksometree($destrepo);
793 chdir $destrepo or die "$destrepo: $!";
795 runcmd qw(git upload-pack), ".";
798 #----- arg parsing and main program -----
808 # keys are used for DGIT_DRS_XXX too
809 'repos' => \$dgitrepos,
810 'suites' => \$suitesfile,
811 'policy-hook' => \$policyhook,
812 'dgit-live' => \$dgitlive,
815 our @hookenvs = qw(distro suitesfile policyhook dgitlive keyrings dgitrepos);
817 # workrepo and destrepo handled ad-hoc
822 my $cmd = $ENV{'SSH_ORIGINAL_COMMAND'};
832 or reject "command string not understood";
838 my $mainfunc = $main::{"main__$funcn"};
840 reject "unknown method" unless $mainfunc;
842 my $lfh = lockrealtree();
844 $policy = policyhook(FRESHREPO,'check-package',$package);
845 if ($policy & FRESHREPO) {
851 if (stat_exists realdestrepo) {
852 $destrepo = realdestrepo;
854 debug " fixmissing $funcn";
855 my $fixfunc = $main::{"fixmissing__$funcn"};
859 debug " running main $funcn";
863 sub parseargsdispatch () {
866 delete $ENV{'GIT_DIR'}; # if not run via ssh, our parent git process
867 delete $ENV{'GIT_PREFIX'}; # sets these and they mess things up
869 if ($ENV{'DGIT_DRS_DEBUG'}) {
871 open DEBUG, ">&STDERR" or die $!;
874 if ($ARGV[0] eq '--pre-receive-hook') {
875 if ($debug) { $debug.="="; }
878 $package = shift @ARGV;
879 ${ $main::{$_} } = $ENV{"DGIT_DRS_\U$_"} foreach @hookenvs;
880 defined($workrepo = $ENV{'DGIT_DRS_WORK'}) or die;
881 defined($destrepo = $ENV{'DGIT_DRS_DEST'}) or die;
882 open STDOUT, ">&STDERR" or die $!;
887 recorderror "$@" or die;
893 $distro = $ENV{'DGIT_DRS_DISTRO'} = argval();
894 my $distrodir = argval();
895 $keyrings = $ENV{'DGIT_DRS_KEYRINGS'} = argval();
897 foreach my $dk (keys %indistrodir) {
898 ${ $indistrodir{$dk} } = "$distrodir/$dk";
901 while (@ARGV && $ARGV[0] =~ m/^--([-0-9a-z]+)=/ && $indistrodir{$1}) {
902 ${ $indistrodir{$1} } = $'; #';
906 $ENV{"DGIT_DRS_\U$_"} = ${ $main::{$_} } foreach @hookenvs;
910 my $mode = shift @ARGV;
911 die unless $mode =~ m/^--(\w+)$/;
912 my $fn = ${*::}{"mode_$1"};
918 while (my $fh = pop @lockfhs) { close $fh; }
923 if (!chdir "$dgitrepos/_tmp") {
924 $!==ENOENT or die $!;
927 foreach my $lf (<*.lock>) {
929 $tree =~ s/\.lock$//;
930 next unless acquirermtree($tree, 0);
931 remove $lf or warn $!;