Forum: Cfengine Help
Subject: Cfengine 3.0.5 segmentation fault with a bundle
Author: Seva Gluschenko
Link to topic: https://cfengine.com/forum/read.php?3,17578,17578#msg-17578

Hello folks,

tryin' to enforce certain package version for CentOS, I wrote a method to 
achieve that, but unfortunately it produces segmentation fault. I was ready to 
file a bug report, but I've found it useful to request an advice first. 
Perhaps, somebody could explain me what's wrong with this example?


body common control
{
 bundlesequence => { "test" };
}

########################################################
bundle agent test
{
 reports:
    centos::
        "Hello World";
}

bundle agent force_package(pkg, ver, arch)
{
 vars:
    centos::
        "installed"     string  => execresult("/bin/rpm -q $(pkg)", "noshell");

 classes:
        "exists" not    => strcmp("$(installed)", "package $(pkg) is not 
installed");

    exists::
        "ok" expression => strcmp("$(installed)", "$(ver)-$(arch)");

 files:
    !ok::
        "$(g.pkg_localpath)"
                copy_from       => my_scp("$(g.pkg_path)"),
                file_select     => by_name("$(pkg)-$(ver)"),
                classes         => if_repaired(canonify("$(pkg)_received")),
                comment => "Download $(pkg) when needed";

 packages:
    !ok.centos::
        "$(pkg)"
                package_method  => yum,
                package_policy  => "delete",
                comment         => "Remove wrong version ($(installed)) of 
$(pkg) (need $(ver))";

 commands:
    centos::
        "/bin/rpm -i $(pkg)-$(ver).$(arch).rpm"
                ifvarclass      => canonify("$(pkg)_received"),
                comment         => "Install the package received";

 reports:
    !ok::
        "$(pkg): forced version: $(ver) (was: $(installed))"
                ifvarclass      => canonify("$(pkg)_received");
}

############################################

body classes if_repaired(x)
{
        promise_repaired => { "$(x)" };
}

########################################################


body file_select by_name(x)
{
        leaf_name       => { "$(x).*" };
        file_result     => "leaf_name";
}

body copy_from my_scp(from)
{
        source  => "$(from)";
        compare => "digest";
        #trustkey => "true";

!policy_host::
        servers => { "$(g.policy_server)" };
}

########################################################

body package_method yum
{
package_changes => "bulk";
package_list_command => "/usr/bin/yum list installed";

# Remember to escape special characters like |

package_list_name_regex    => "([^.]+).*";
package_list_version_regex => "[^\s]\s+([^\s]+).*";
package_list_arch_regex    => "[^.]+\.([^\s]+).*";

package_installed_regex => ".*installed.*";
package_name_convention => "$(name)";

package_add_command => "/usr/bin/yum -y install";
package_delete_command => "/bin/rpm -e";
package_verify_command => "/bin/rpm -V";
package_update_command => "/usr/bin/yum -y update";
}


The most insane thing about this is that it segfaults even not being called, at 
the verification stage. The debug output was as follows:

Found scope reference body
GetVariable(body,x): using scope 'body' for variable 'x'
return final variable type=string, value={
$(pkg)-$(ver)}
  Aggregate result |$(pkg)-$(ver).*|, scanning at "" (current delta .*)
Returning complete scalar expansion ($(x).* => $(pkg)-$(ver).*)

Appending scalar to rval-list [$(pkg)-$(ver).*]
CopyRvalItem(s)
   Appending a list to rhs
Doing arg-mapped sublval = file_result (promises.c)
ExpandPrivateRval(scope=body,type=s)

ExpandPrivateScalar(body,leaf_name)
  Aggregate result |leaf_name|, scanning at "" (current delta leaf_name)
Returning complete scalar expansion (leaf_name => leaf_name)

   Appending Constraint: file_result => leaf_name
Deleting scope body
Object body exists
 ----> Delete variable association x
DeleteRvalItem(s)$(pkg)-$(ver)
   Appending Constraint: classes => true
Handling body-lval "classes"
Adding scope data body
MapBodyArgs(begin)
StringDataType((<9E>T   <9D>T       ^A)
StringDataType(x)
Segmentation fault


_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to