On Tue, 16 Jun 2009 12:47:29 -0400
Bob Doolittle <[email protected]> wrote:

> Attached is a script I wrote to highlight inconsistencies in the 
> operational state of the system in cases like this. Try running it as root.
> 
> If any Linux jocks want to take a crack at porting this to Linux that'd 
> be great. I've been unable to find anything on Linux similar to "pargs" 
> on OpenSolaris that can actually show me the current environment of a 
> running process (ps ewww only shows the environment that was inherited 
> by the process, not its current environment, and I haven't managed to 
> get what I want out of /proc yet either). We need to see the current 
> environment value of $DISPLAY to deduce which display an Xnewt process 
> is managing.

I, too, didn't find out how to access the current environment of a Linux 
process.
Both ps and /proc/pid/environ show the environment with which the process was 
started. 
So I decided to extract the DISPLAY value from the environment of the Xnewt 
process. 

Neither bash nor pdksh have associative arrays. (There is a ksh package for
Linux which provides ksh93. But all the SRSS-on-Linux recipes recommend 
installing pdksh. A relic of the times when SRSS itself had problems with 
ksh93.)
So I opted for a quick and dirty perl translation of Bob's code.

Use the attached script for whatever you like.

Miek

-- 
Meik Hellmund
Mathematisches Institut, Uni Leipzig
e-mail: [email protected]
http://www.math.uni-leipzig.de/~hellmund

#!/usr/bin/perl


die "Sorry, this is Linux only at the moment!\n" unless $^O == "linux";

# How many gdm master processes?

@gdmm = `pgrep -x -P 1  gdm`;


die "Problem: No gdm master process running!\n" unless @gdmm;
die "Problem: more than one gdm master running!\n" if scalar @gdmm > 1;

# Get all gdm child processes

chomp($gdmmpid = $gdmm[0]);
@gdms = `pgrep -x -P $gdmmpid gdm`;

# no children?
die "Problem: No display managed by gdm!\n" unless @gdms;


# some counter
$nxorg=0;
$nxnewt=0;
$ngdm= scalar @gdms;

# foreach gdm child: has it Xorg child? 
#                    no => has it Xnewt child? 
#                          yes => get DISPLAY from Xnewt env


#Note: gdm usually calls /usr/bin/X and this is a symlink to /usr/bin/Xorg   
#      The argument of pgrep must be the target of the symlink!

foreach $pid (@gdms) {
    chomp $pid;
    @xorgs = `pgrep -x -P $pid Xorg`;

    if(@xorgs) {
	$nxorg++;
    } else {

	@xnewts = `pgrep -x -P $pid Xnewt`;

	if(@xnewts) {
	    $nxnewt++;
	    chomp($xnewtpid= $xnewts[0]);
	    $xenv=`ps eww $xnewtpid`;
	    $xenv=~ s/.* DISPLAY=[^:]*:(\S*).*/$1/s;
	    $GDMPROCDPYS{$xenv} = $xnewtpid;
	}
    }
}

print "Number of gdm child processes running:  $ngdm\n";
print "Number of Xorg server child processes:  $nxorg\n";
print "Number of Xnewt server child processes: $nxnewt\n";

if($ngdm==$nxorg+$nxnewt) {
    print "This looks ok so far...\n";
} else {
    print "Problem: some gdm processes did not spawn an X server!\n";
}


# cut'n paste of Bob Dolittle's shell code. 
# 222 laziness points for calling awk and sed inside perl.

# Record all gdm-managed displays in Xservers file
foreach $dpy (`awk '
	/^:[0-9]* / { split(\$1, a, ":"); print a[2] }
	' /tmp/SUNWut/config/xconfig/Xservers`) {
    chomp $dpy;
    $XSERVERDPYS{$dpy}=1;
}

# Record all SRSS-managed displays for filtering purposes
foreach $dpy  (`awk '
	/^# :[0-9]* RESERVED/ { split(\$2, a, ":"); print a[2] }
	' /tmp/SUNWut/config/xconfig/Xservers`) {
    chomp $dpy;
    $XSERVERRESERVEDDPYS{$dpy}=1;
}


# Record all sessions, ignore SRSS-managed sessions (XXX what about YUV?)
foreach $dpy (`cd /var/opt/SUNWut/displays; ls`) {
    chomp $dpy;
    $DISPLAYDPYS{$dpy}=1 unless $XSERVERRESERVEDDPYS{$dpy}==1;
}


# Record displays in gdmdynamic configuration report (ignore console)
$dpystr=`gdmdynamic -l | sed 's/:\\([0-9]*\\)[^;]*[;]*/\\1 /g'`;
foreach $dpy (split(' ',$dpystr)) { 
    chomp $dpy;
    $GDMDYNDPYS{$dpy} = 1 unless $dpy == 0;
}

# Cross-correlate everything, by gdm-managed Xserver entries
for $dpy  (keys %XSERVERDPYS){
    if (not defined $GDMPROCDPYS{$dpy}) {
	print "No process for $dpy in Xservers\n";
    }
    if (not defined $DISPLAYDPYS{$dpy}) {
	print "No display file for $dpy in Xservers\n";
    }
    if (not defined $GDMDYNDPYS{$dpy}) { 
	print "No gdmdynamic config for $dpy in Xservers\n";
    }
#	if $VERBOSE; then
#		PID=
#		if $PRINTPIDS; then
#			PID=" ${GDMPROCDPYS[$dpy]}"
#		fi
#		print $dpy$PID
#	fi
    delete $GDMPROCDPYS{$dpy};
    delete $DISPLAYDPYS{$dpy};
    delete $GDMDYNDPYS{$dpy};
    delete $XSERVERDPYS{$dpy};
}

# Any leftovers not covered in Xservers file?

if(scalar values %GDMPROCDPYS > 0) {
    print "The following dpys have gdm procs but no entry in Xservers:\n";
    for $d (keys %GDMPROCDPYS) {
	print " $d\n";
    }
}

if(scalar values %DISPLAYDPYS > 0) {
    print "The following dpys have display files but no (unreserved) entry in Xservers:\n";
    for $d (keys %DISPLAYDPYS) {
	print " $d\n";
    }
}

if(scalar values %GDMDYNDPYS > 0) {
    print "The following dpys have gdmdynamic configs but no entry in Xservers:\n";
    for $d (keys %GDMDYNDPYS) {
	print " $d\n";
    }
}





_______________________________________________
SunRay-Users mailing list
[email protected]
http://www.filibeto.org/mailman/listinfo/sunray-users

Reply via email to