#!/usr/sww/bin/taintperl
$ENV{'PATH'}='/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/local/postgres/bin';
$ENV{'SHELL'}='/bin/sh';
$ENV{'IFS'}='';
$ENV{'USER'}='postgres';
open(PS, "ps auxwwg |")
	|| die("$0: could not locate ps!?");
@ps = <PS>;
close(PS);
@pm=grep(/_postmaster -d$/, @ps);
$pms=$#pm + 1;
print "I think there are $pms postmaster(s) already running.\n";
if ($pms < 1) {
	chdir("/usr/local/postgres/bin");
	print "I am running ipcclean as UID $>...\n";
	system("ipcclean");
	print "I am starting the postmaster as UID $>...\n";
	$ret = system("postmaster") / 256;
	print "\n";
	if (!$ret) {
		print "I think the postmaster started ok.\n";
		print "Due to perl script strangeness, the real UID may not\n";
		print "appear to be set correctly, and the postmaster may\n";
		print "appear to be running as you.  Don't worry about it.\n";
	} else {
		print "Sorry, the postmaster wouldn't start.\n";
		exit(1)
	}
}
exit(0);
