This patch makes us defensive about good results from CheckPackage.c.  I 
have tested this extensively and it works properly.

Index: do.c
===================================================================
--- do.c        (revision 426)
+++ do.c        (working copy)
@@ -2794,6 +2794,16 @@

     match = PackageCheck(ptr->name, ptr->pkgmgr, ptr->ver, ptr->cmp);

+   /* Check for a problem executing the command */
+   Verbose("PackageCheck return = %d\n", match);
+   if ( (match != 1) && (match != 0) )
+      {
+      snprintf(OUTPUT,CF_BUFSIZE,"Error: Package manager query failed, 
skipping %s\n", ptr->name);
+      CfLog(cferror,OUTPUT,"packages");
+      ptr->done = 'y';
+      continue;
+      }
+
     /* Process any queued actions (install/remove). */
     if ((pending_pkgs != NULL) && ((ptr->action != prev_action) || 
(ptr->pkgmgr != prev_pkgmgr)))
        {

Index: package.c
===================================================================
--- package.c   (revision 426)
+++ package.c   (working copy)
@@ -1574,7 +1574,7 @@

    if ((pp = cfpopen (VBUFF, "r")) == NULL)
      {
-    Verbose ("Could not execute pkg_info.\n");
+    CfLog(cferror,"FATAL: Could not execute pkg_info.\n","packages");
      return 0;
      }

@@ -1585,16 +1585,24 @@
      snprintf(OUTPUT,CF_BUFSIZE,"Package install: %s\n",line);
      }

-  if (cfpclose (pp) == 0)
-    {
-    Verbose ("The package and version requested are installed in the 
package database.\n",package);
-    match=1;
-    }
-  else
-    {
-    Verbose ("The package and version requested do not exist in the 
package database.\n",package);
-    match=0;
-    }
+   switch( cfpclose( pp ) )
+      {
+      case 0:
+         Verbose ("FreeBSDPackageCheck(): %s %s %s is installed on this 
system.\n", pkgname, CMPSENSETEXT[cmp],(version[0] ? version : "ANY") );
+         match=1;
+         break;
+
+      case 1:
+         Verbose ("FreeBSDPackageCheck(): %s %s %s is not installed on 
this system.\n", pkgname, CMPSENSETEXT[cmp],(version[0] ? version : 
"ANY") );
+         match=0;
+         break;
+
+      default:
+         Verbose ("FreeBSDPackageCheck(): error running package query\n" );
+         match=-1;
+         break;
+      }
+
    return match;
  }

@@ -1647,15 +1655,24 @@
           }
        }

-   if (cfpclose (pp) == 0)
+   switch( cfpclose( pp ) )
        {
-      match = 1;
+      case 0:
+         Verbose ("FreeBSDPackageList(): %s %s %s is installed on this 
system.\n", pkgname, CMPSENSETEXT[cmp],(version[0] ? version : "ANY") );
+         match=1;
+         break;
+
+      case 1:
+         Verbose ("FreeBSDPackageList(): %s %s %s is not installed on 
this system.\n", pkgname, CMPSENSETEXT[cmp],(version[0] ? version : 
"ANY") );
+         match=0;
+         break;
+
+      default:
+         Verbose ("FreeBSDPackageList(): error running package query\n" );
+         match=-1;
+         break;
        }
-   else
-      {
-      Verbose ("The package and version requested do not exist in the 
package database.\n",package);
-      match = 0;
-      }
+
     return match;
  }
-- 
Jo Rhett
senior geek
Silicon Valley Colocation
_______________________________________________
Bug-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/bug-cfengine

Reply via email to