Jo Rhett wrote:
> This patch makes us defensive about good results from CheckPackage.c. I
> have tested this extensively and it works properly.
The following patch is the same except the CfLog invocations. I
misunderstood the use of the third argument. This is better.
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,"");
+ ptr->done = 'y';
+ continue;
+ }
+
/* Process any queued actions (install/remove). */
if ((pending_pkgs != NULL) && ((ptr->action != prev_action) ||
(ptr->pkgmgr != prev_pkgmgr)))
{
@@ -2865,7 +2875,7 @@
InstallPackage(pkgmgr, pending_pkgs);
break;
default:
- snprintf(OUTPUT,CF_BUFSIZE,"Internal error! Tried to process
package with an unknown action: %d. This should never happen!\n", action);
+ snprintf(OUTPUT,CF_BUFSIZE,"Internal error! Tried to process
package with an unknown action: %d. This should never happen!\n", action);
CfLog(cferror,OUTPUT,"");
break;
}
Index: package.c
===================================================================
--- package.c (revision 426)
+++ package.c (working copy)
@@ -173,7 +173,7 @@
if (!GetMacroValue(CONTEXTID,"RPMInstallCommand"))
{
- CfLog(cferror,"RPMInstallCommand NOT Set. Package
Installation Not Possible!\n","packages");
+ CfLog(cferror,"RPMInstallCommand NOT Set. Package
Installation Not Possible!\n","");
return 0;
}
strncpy(rawinstcmd,
GetMacroValue(CONTEXTID,"RPMInstallCommand"),CF_BUFSIZE);
@@ -184,7 +184,7 @@
if (!GetMacroValue(CONTEXTID,"DPKGInstallCommand"))
{
- CfLog(cferror,"DPKGInstallCommand NOT Set. Package
Installation Not Possible!\n","packages");
+ CfLog(cferror,"DPKGInstallCommand NOT Set. Package
Installation Not Possible!\n","");
return 0;
}
strncpy(rawinstcmd,
GetMacroValue(CONTEXTID,"DPKGInstallCommand"),CF_BUFSIZE);
@@ -195,7 +195,7 @@
if (!GetMacroValue(CONTEXTID,"SUNInstallCommand"))
{
- CfLog(cferror,"SUNInstallCommand NOT Set. Package
Installation Not Possible!\n","packages");
+ CfLog(cferror,"SUNInstallCommand NOT Set. Package
Installation Not Possible!\n","");
return 0;
}
strncpy(rawinstcmd,
GetMacroValue(CONTEXTID,"SUNInstallCommand"),CF_BUFSIZE);
@@ -205,7 +205,7 @@
case pkgmgr_aix:
if (!GetMacroValue(CONTEXTID,"AIXInstallCommand"))
{
- CfLog(cferror,"AIXInstallCommand NOT Set. Package
Installation Not Possible!\n","packages");
+ CfLog(cferror,"AIXInstallCommand NOT Set. Package
Installation Not Possible!\n","");
return 0;
}
strncpy(rawinstcmd,
GetMacroValue(CONTEXTID,"AIXInstallCommand"),CF_BUFSIZE);
@@ -217,7 +217,7 @@
if (!GetMacroValue(CONTEXTID,"PortageInstallCommand"))
{
- CfLog(cferror,"PortageInstallCommand NOT Set. Package
Installation Not Possible!\n","packages");
+ CfLog(cferror,"PortageInstallCommand NOT Set. Package
Installation Not Possible!\n","");
return 0;
}
strncpy(rawinstcmd,
GetMacroValue(CONTEXTID,"PortageInstallCommand"),CF_BUFSIZE);
@@ -228,7 +228,7 @@
if (!GetMacroValue(CONTEXTID,"FreeBSDInstallCommand"))
{
- CfLog(cferror,"FreeBSDInstallCommand NOT Set. Package
Installation Not Possible!\n","packages");
+ CfLog(cferror,"FreeBSDInstallCommand NOT Set. Package
Installation Not Possible!\n","");
return 0;
}
strncpy(rawinstcmd,
GetMacroValue(CONTEXTID,"FreeBSDInstallCommand"),CF_BUFSIZE);
@@ -237,7 +237,7 @@
/* Default */
default:
snprintf(OUTPUT,CF_BUFSIZE,"Unknown package manager %d\n",pkgmgr);
- CfLog(cferror,OUTPUT,"packages");
+ CfLog(cferror,OUTPUT,"");
break;
}
@@ -254,7 +254,7 @@
{
if ((pp = cfpopen(instcmd, "r")) == NULL)
{
- CfLog(cfinform,"Could not execute package install
command.\n\n","packages");
+ CfLog(cfinform,"Could not execute package install
command.\n\n","popen");
/* Return that the package is still not installed */
return 0;
}
@@ -263,24 +263,24 @@
{
ReadLine(line,CF_BUFSIZE-1,pp);
snprintf(OUTPUT,CF_BUFSIZE,"Package install: %s\n",line);
- CfLog(cfinform,OUTPUT,"packages");
+ CfLog(cfinform,OUTPUT,"");
}
if (cfpclose(pp) != 0)
{
- CfLog(cfinform,"Package install command was not
successful.\n\n","packages");
+ CfLog(cfinform,"Package install command was not
successful.\n\n","popen");
result = 0;
}
else
{
- CfLog(cfinform,"Successfully installed
package(s).\n","packages");
+ CfLog(cfinform,"Successfully installed package(s).\n","");
result = 1;
}
}
}
else
{
- CfLog(cferror,"Unable to evaluate package manager
command.\n","packages");
+ CfLog(cferror,"Unable to evaluate package manager command.\n","");
result = 0;
}
@@ -304,7 +304,7 @@
}
else
{
- CfLog(cfinform,"Package cannot be upgraded because the old
version was not removed.\n\n","packages");
+ CfLog(cfinform,"Package cannot be upgraded because the old
version was not removed.\n\n","");
result = 0;
}
DeleteItemList(removelist);
@@ -321,7 +321,7 @@
if (pkglist == NULL)
{
- CfLog(cferror,"RemovePackage: no packages to remove.\n","packages");
+ CfLog(cferror,"RemovePackage: no packages to remove.\n","");
return 0;
}
@@ -342,7 +342,7 @@
/* Default */
default:
- CfLog(cferror,"RemovePackage: Package removal not yet
implemented for this package manager.\n","packages");
+ CfLog(cferror,"RemovePackage: Package removal not yet
implemented for this package manager.\n","p");
break;
}
@@ -358,7 +358,7 @@
{
if ((pp = cfpopen(delcmd, "r")) == NULL)
{
- CfLog(cferror,"RemovePackage: Could not execute package
removal command.\n","packages");
+ CfLog(cferror,"RemovePackage: Could not execute package
removal command.\n","popen");
/* Return that the package is still not removed */
return 0;
}
@@ -367,24 +367,24 @@
{
ReadLine(line,CF_BUFSIZE-1,pp);
snprintf(OUTPUT,CF_BUFSIZE,"Package removal: %s\n",line);
- CfLog(cfinform,OUTPUT,"packages");
+ CfLog(cfinform,OUTPUT,"");
}
if (cfpclose(pp) != 0)
{
- CfLog(cfinform,"Package removal command was not
successful.\n","packages");
+ CfLog(cfinform,"Package removal command was not
successful.\n","");
result = 0;
}
else
{
- CfLog(cfinform,"Successfully removed
package(s).\n","packages");
+ CfLog(cfinform,"Successfully removed package(s).\n","");
result = 1;
}
}
}
else
{
- CfLog(cferror,"Unable to evaluate package manager
command.\n","packages");
+ CfLog(cferror,"Unable to evaluate package manager command.\n","");
result = 0;
}
return result;
@@ -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","popen");
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