summaryrefslogtreecommitdiff
path: root/web/src/pubcookie/debug.cgi
blob: dd9983805c5c5295f28f43e320468f5b70cea7dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
$| = 1;
$wp_uidmapper_bin = "/usr/local/libexec/alpine/bin/wp_uidmapper";
$wp_uidmapper_socket = "/tmp/wp_uidmapper";

print "Content-type: text/plain\n\n";
print "klist:\n";
system("/usr/local/bin/klist");
print "\n";

#if($ENV{'QUERY_STRING'} eq 'stop') {
#    foreach $line (ps("axww")) {
#	($line =~ m/^(\d+).*wp_uidmapper/) && kill(15,$1);
#    }
#    sleep(1);
#    if(-e $wp_uidmapper_socket) {
#	print "Could not kill wp_uidmapper\n";
#	exit(1);
#    }
#    print "wp_uidmapper stopped\n";
#    exit 0;
#}

if (! -e $wp_uidmapper_socket) {
    print "Yikes! need to spawn new wp_uidmapper process\n";
    if(!fork()) {
	close(STDIN);
	close(STDOUT);
	close(STDERR);
	setpgrp(0,0);
	exec("$wp_uidmapper_bin 60000-64999");
    }
    sleep 1;
}

@ps = ps("auxww");
print "wp_uidmapper:\n";
foreach $line (@ps) { ($line =~ m/wp_uidmapper/) && print $line; }

print "\nEnvironment:\n";
foreach $key (sort { $a cmp $b } keys(%ENV)) {
    print "$key: $ENV{$key}\n";
}

print "\nAlpine user processes:\n";
foreach $line (@ps) { ($line =~ m/^\#/) && print $line; }
exit 0;

sub ps {
    my ($args) = @_;
    my (@a);
    open(PS,"ps $args|") || return;
    @a = <PS>;
    close(PS);
    return @a;
}