[padb] r325 committed - Factor out all code dealing with /proc/$pid/exe into one...

padb at googlecode.com padb at googlecode.com
Thu Nov 5 22:46:31 GMT 2009


Revision: 325
Author: apittman
Date: Thu Nov  5 14:46:03 2009
Log: Factor out all code dealing with /proc/$pid/exe into one
function and modify that to do the right thing on solaris.
This fixes several problems to do with finding the executable name.

http://code.google.com/p/padb/source/detail?r=325

Modified:
  /trunk/src/padb

=======================================
--- /trunk/src/padb	Thu Nov  5 14:28:07 2009
+++ /trunk/src/padb	Thu Nov  5 14:46:03 2009
@@ -2771,15 +2771,15 @@

      foreach my $pid ( get_process_list($user) ) {

-        if ($running_on_solaris) {
-            my $slink = readlink "/proc/$pid/path/a.out";
-            if ( defined $slink ) {
-                if ( defined $mpirun{ basename($slink) } ) {
-                    push @jobs, $pid;
-                }
-            }
-            next;
-        }
+        # Works for both solaris and Linux
+        my $link = proc_link($pid);
+        if ( defined $link ) {
+            if ( defined $mpirun{ basename($link) } ) {
+                push @jobs, $pid;
+            }
+        }
+
+        next if ($running_on_solaris);

          # This test does work on solaris but as it reports a full path
          # rather than just the basename it'll never pass.  It also
@@ -2789,13 +2789,6 @@
              push @jobs, $pid;
              next;
          }
-
-        # Linux only.
-        my $link = readlink "/proc/$pid/exe";
-        next unless defined $link;
-        if ( defined $mpirun{ basename($link) } ) {
-            push @jobs, $pid;
-        }
      }
      return @jobs;
  }
@@ -5825,7 +5818,7 @@
      } elsif ( $cmd eq 'rank' ) {
          $res = $vp;
      } elsif ( $cmd eq 'image' ) {
-        my $image = readlink "/proc/$gdb->{tracepid}/exe";
+        my $image = proc_link( $gdb->{tracepid} );
          if ( defined $image ) {
              $res = $image;
          }
@@ -5894,7 +5887,7 @@
                      $global{$str_name} = $str_value;

                      if ( $str_name eq 'ihqm' ) {
-                        my $image = readlink "/proc/$gdb->{tracepid}/exe";
+                        my $image = proc_link( $gdb->{tracepid} );
                          $str_value =~ s{%s}{$image};
                      }

@@ -8085,13 +8078,24 @@
      $handle->{target_response} = undef;
      return;
  }
+
+sub proc_link {
+    my $pid = shift;
+    my $path;
+    if ($running_on_solaris) {
+        $path = "/proc/$pid/path/a.out";
+    } else {
+        $path = "/proc/$pid/exe";
+    }
+    return readlink $path;
+}

  # Convert from a pid to a command name and do it in a safe manner to avoid
  # warnings.  suid programs tend to have the exe link which is un-readable
  # so if that yields nothing then load the name from the status file.
  sub pid_to_name {
      my $pid = shift;
-    my $exe = readlink "/proc/$pid/exe";
+    my $exe = proc_link($pid);
      if ( defined $exe ) {
          return basename($exe);
      } else {




More information about the padb-devel mailing list