#!/usr/bin/perl
#use Mooix::Thing;
#use Fcntl ':flock';
run sub {
	my $this=shift;
	%_=@_;
	my $prompt=$_{prompt};
	
	# Open and lock tty.
	open (TTY, "+<tty") || die "open tty: $!";
	# This is a mite iffy. This object uses flock locking. Perl's
	# "flock" locking may be fctnl locking on some platforms though.
	flock(TTY, LOCK_EX);

	# Turn off echoing.
	system('stty -echo >tty <tty 2>/dev/null');
	
	if ($this->safepassword) {
		print TTY "[Password request from system.]\n";
	}
	else {
		print TTY "[Password request from third party! Do not enter system password.]\n";
	}
	
	# Print prompt.
	select TTY;
	$|=1;
	select STDOUT;
	print TTY $prompt;
	
	# Get line.
	my $pw = <TTY>;
	chomp $pw;
	
	# Turn on echoing.
	system('stty sane >tty <tty 2>/dev/null');

	print TTY "\n";
	
	return $pw;
}
