Python: force c integer overflow behavior

Python language

Python-2.x offers 2 types of integers: plain integers and long integers.

While plain integers have a least a 32 bits precision, long integers have unlimited precision (Numeric types)

Plain integers are automatically promoted to long integers if an overflow happens:

Python 2.7.5 (default, May 12 2013, 12:00:47)
[GCC 4.8.0 20130502 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.maxint
9223372036854775807
>>> a = sys.maxint
>>> print type(a)
<type 'int'>
>>> a +=1
>>> print a
9223372036854775808
>>> print type(a)
<type 'long'>

C language

In C language, integers overflow behavior is different regarding the integer signedness. 2 situations arise: (Basics of Integer Overflow)

Read more...

CFEngine: A bunch of new slist facilities

Recently (still in master branch, and certainly in CFEngine-3.5), great new functions have been added to make powerful manipulations on slists. You will find below for each function its documentation (extracted from master branch) and a downloadable example:

filter

Extracts a sublist of elements matching arg1 as a regular expression (if arg3 is true) or as an exact string (if arg3 is false) from a list variable specified in arg2. In regular expression mode, the regex is anchored. If arg4 is true, the matches are inverted (you get elements that don’t match arg1). arg5 specifies a maximum number of elements to return.

Read more...

CFEngine: little insert_lines annoyance fixed

Sometimes, crontab entries are preferable over CFEngine internal scheduling when jobs have special scheduling requirements. I have one example where a job must absolutely be started every 2 minutes. (03:20, 03:22, 03:24 and so on)

By default cf-execd is started every 5 minutes, it is ok for 03:20 with Min00, but Min22 and Min24 hard classes will never be defined while cf-execd is running, and some job occurrences never started. Cf-execd can be launched every minute, but by reducing this interval you may have to deal with lock issues. (long splaytime ?)

Read more...

CFEngine: bash-completion settings

You can now get completion for cf-* commands if you are using Bash and bash-completion helper

Simply put contrib/cfengine-completion.bash into your bash_completion.d directory:

# wget  https://raw.github.com/cfengine/core/master/contrib/cfengine-completion.bash -O -|sudo tee /etc/bash_completion.d/cfengine

Restart your shell, and enjoy:

$ cf-promises --<tab><tab>
--bundlesequence        --diagnostic            --full-check            --negate                --verbose               
--debug                 --dry-run               --help                  --policy-output-format  --version               
--define                --file                  --inform                --reports               
$ ~/.cfagent/bin/cf-promises --bundl<tab>
$ ~/.cfagent/bin/cf-promises --bundlesequence
Read more...

CFEngine: getting mac addresses on BSD systems

It is now possible to retrieve mac addresses under BSD operating systems. (merged into master branch, not yet released)

As far as I know, at least FreeBSD, NetBSD and OpenBSD don’t implement the SIOCGIFHWADDR ioctl, so a getifaddrs() fallback was needed.

Before, only mac_unknown hard class was reported:

# cf-promises -v|hcgrep mac
mac_unknown

Now:

# cf-promises -v|hcgrep mac
mac_08_00_d5_84_88_00

Of course, sys.hardware_addresses and [sys.hardware_macinterface_name] variables are populated.

what is hcgrep?

Read more...