Rexec

  • Fixed bug in gpdb_add_project.pl
  • Met about MultiSite Hardening Daemon (MSHD)

Rexec

The gpdb_add_project.pl script utilizes rsh to log into remote sites to execute and otherwise gather data from other sites (Actually it uses rsh locally too but that's another blog entry!). It does this with code like this:

unless ($site_registry_handle->open("rsh $siteHash{$siteName} -n cat $syncReg |"))  {
   print ("Can not open rsh $siteHash{$siteName} -n cat $syncReg |.\n");
   exit;
}

The problem is that the above code will not work. What is returned from the open call here is whether or not the rsh command worked - not whether or not the cat command worked! Indeed open of a pipe returns little - it's the close of the pipe that's going to return the status of the rsh! The status of the cat in this case is never returned. And in this case it was failing. There is no real reliable method for getting the status of the cat command except perhaps to process the remote session using expect or Perl/Expect.

Since we expect the cat to work and to return lines and because there is a specific format for the first line, I implemented the following:

sub GetDSRegFile {
  my $file	= shift;
  my $server	= shift;

  my @lines;

  if ($server) {
    @lines = `rsh $server -n cat $file`;

    return undef if $?;
  } else {
    @lines = `cat $file`;
  } # if

  if ($lines [0] and $lines [0] !~ /\#\# SYNC_VERSION 1\.0/) {
    return undef;
  } else {
    return @lines;
  } # if
} # GetDSRegFile

This solves the problem for this particular case. However this script uses this invalid technique for many other "remote calls" and has potential for error.