From: Mark Wooding Date: Sun, 24 Apr 2016 22:30:30 +0000 (+0100) Subject: with-authinfo-kludge: Actually write pidfiles like the manual says. X-Git-Tag: 0.1.0~4 X-Git-Url: https://git.distorted.org.uk/~mdw/with-authinfo-kludge/commitdiff_plain/399b694fd9dd04d09fd94ad459854d6f36ff4299 with-authinfo-kludge: Actually write pidfiles like the manual says. --- diff --git a/with-authinfo-kludge b/with-authinfo-kludge index 112668e..47660a4 100755 --- a/with-authinfo-kludge +++ b/with-authinfo-kludge @@ -21,10 +21,6 @@ ### along with this program; if not, write to the Free Software Foundation, ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -## things to do -## -## pidfiles - my $VERSION = "0.1.0~unfinished"; use strict; @@ -167,6 +163,16 @@ sub lockedp ($) { return $l->l_type != F_UNLCK; } +sub write_to_file ($$) { + my ($file, $contents) = @_; + my $new = "$file.new"; + open my $fh, ">", $new or sysfail "couldn't open `$new' for writing: $!"; + print $fh $contents; + $fh->flush && !$fh->error && close $fh + or sysfail "failed to write to `$new': $!"; + rename $new, $file or sysfail "failed to rename `$new' to `$file': $!"; +} + my $INKIDP = 0; sub myfork () { my $kid = fork; @@ -693,6 +699,7 @@ EOF $s->{"_ssh_stdin"} = $win; $s->{"_ssh_stdout"} = $rout; $KIDMAP{$kid} = [$s, "SSH tunnel"]; + write_to_file "$SESSDIR/ssh-$server.pid", "$kid\n"; } } @@ -782,6 +789,7 @@ sub run_client (@) { exec @args or sysfail "failed to exec `$prog': $!"; } $CLIENTKID = $kid; + write_to_file "$SESSDIR/client.pid", "$kid\n"; } sub accept_loop () {