#!/usr/bin/perl
# Create a new session.
use Fcntl;
#use Mooix::Thing;
run sub {
	my $this=shift;
	$this->super(@_) || $this->croak("super failed");
	%_=@_;
	
	if ($_{realtty}) {
		symlink($_{realtty}, "realtty") or
			$this->croak("symlink realtty");
	}

	if ($_{term}) {
		$this->term($_{term});
	}
	
	if ($_{unixuser}) {
		$this->unixuser($_{unixuser});
	}

	umask(0); # ignore umask
	
	unless ($this->defines('.pending')) {
		# This is opened by prompt, and must always exist. It
		# should be kept safe from prying eyes. And it needs
		# to be writable by the write and prompt methods, no
		# matter what the rest of the uidstack is.
		sysopen(TOUCH, ".pending", O_WRONLY | O_CREAT, 0660) ||
			$this->croak("touch .pending");
	}
	
	unless ($this->defines('.history')) {
		# The history list likewise.
		sysopen(TOUCH, "history", O_WRONLY | O_CREAT, 0660) ||
			$this->croak("touch history");
	}
	
	unless ($this->defines('.pagefile')) {
		# The .pagefile likewise.
		sysopen(TOUCH, ".pagefile", O_WRONLY | O_CREAT, 0660) ||
			$this->croak("touch .pagefile");
	}

	return $this;
}
