[Saga-devel] saga SVN commit 3329: /trunk/adaptors/ssh/ssh_job/

amerzky at cct.lsu.edu amerzky at cct.lsu.edu
Sun Jan 18 00:57:48 CST 2009


User: amerzky
Date: 2009/01/18 12:57 AM

Modified:
 /trunk/adaptors/ssh/ssh_job/
  ssh_job.cpp, ssh_job_service.cpp

Log:
 add some sanity checks and fallbacks for missing attributes
 A

File Changes:

Directory: /trunk/adaptors/ssh/ssh_job/
=======================================

File [modified]: ssh_job.cpp
Delta lines: +35 -2
===================================================================
--- trunk/adaptors/ssh/ssh_job/ssh_job.cpp	2009-01-17 21:59:56 UTC (rev 3328)
+++ trunk/adaptors/ssh/ssh_job/ssh_job.cpp	2009-01-18 06:57:38 UTC (rev 3329)
@@ -5,6 +5,9 @@
 //  (See accompanying file LICENSE or copy at 
 //   http://www.boost.org/LICENSE_1_0.txt)
 
+// system includes
+#include <pwd.h>
+
 // saga includes
 #include <saga/saga.hpp>
 #include <saga/saga/adaptors/task.hpp>
@@ -78,15 +81,45 @@
     ctx_ = contexts[0];
 
     // sanity check
-    if ( ctx_.get_attribute ("Type") != "ssh" )
+    if ( ! ctx_.attribute_exists ("Type") ||
+           ctx_.get_attribute    ("Type") != "ssh" )
     {
       SAGA_ADAPTOR_THROW_NO_CONTEXT ("no ssh context found for session",
                                      saga::NoSuccess);
     }
 
+    // FIXME: check if attribs exist
+    if ( ! ctx_.attribute_exists ("UserKey") )
+    {
+      // _need_ key to be useful
+      SAGA_ADAPTOR_THROW_NO_CONTEXT ("ssh context has no userkey",
+                                     saga::NoSuccess);
+    }
+
     key_  = ctx_.get_attribute ("UserKey");
-    user_ = ctx_.get_attribute ("UserID");
 
+
+    if ( ctx_.attribute_exists ("UserKey") )
+    {
+      user_ = ctx_.get_attribute ("UserID");
+    } 
+    else
+    {
+      struct passwd * p = ::getpwuid (::getuid ());
+      if ( p == NULL )
+      {
+        user_ = "root";
+      }
+      user_ = p->pw_name;
+    }
+
+
+    // the URL may actually have a userid fixed
+    if ( "" != rm_.get_userinfo () )
+    {
+      user_ = rm_.get_userinfo ();
+    }
+
     SAGA_LOG_DEBUG (rm_.get_string ().c_str ());
 
 

File [modified]: ssh_job_service.cpp
Delta lines: +27 -2
===================================================================
--- trunk/adaptors/ssh/ssh_job/ssh_job_service.cpp	2009-01-17 21:59:56 UTC (rev 3328)
+++ trunk/adaptors/ssh/ssh_job/ssh_job_service.cpp	2009-01-18 06:57:38 UTC (rev 3329)
@@ -5,6 +5,9 @@
 //  (See accompanying file LICENSE or copy at 
 //   http://www.boost.org/LICENSE_1_0.txt)
 
+// system includes
+#include <pwd.h>
+
 // stl includes
 #include <vector>
 
@@ -75,7 +78,8 @@
     {
       // dump_context (contexts[i]);
       
-      if ( contexts[i].get_attribute ("Type") == "ssh" )
+      if ( contexts[i].attribute_exists ("Type") &&
+           contexts[i].get_attribute ("Type") == "ssh" )
       {
         SAGA_LOG_ALWAYS ("Using this context");
         ssh_contexts.push_back (contexts[i]);
@@ -115,9 +119,30 @@
 
 
       // FIXME: check if attribs exist
+      if ( ! ctx_.attribute_exists ("UserKey") )
+      {
+        // _need_ key to be useful
+        break;
+      }
+
       key_  = ctx_.get_attribute ("UserKey");
-      user_ = ctx_.get_attribute ("UserID");
 
+
+      if ( ctx_.attribute_exists ("UserKey") )
+      {
+        user_ = ctx_.get_attribute ("UserID");
+      } 
+      else
+      {
+        struct passwd * p = ::getpwuid (::getuid ());
+        if ( p == NULL )
+        {
+          user_ = "root";
+        }
+        user_ = p->pw_name;
+      }
+
+
       // the URL may actually have a userid fixed
       if ( "" != rm_.get_userinfo () )
       {



More information about the saga-devel mailing list