CFEngine: canonify your own strings

Want to quickly canonify a string for testing ? A shell one-liner has been given by the CFEngine folks :

Example with the mac address 00:1a:d1:48:ff:d0

$ echo -n "00:1a:d1:48:ff:d0"| perl -p -e 's/\W/_/g'
00_1a_d1_48_ff_d0loic@iron[0]: ~

The mac address is correctly canonified to 00_1a_d1_48_ff_d0, but my shell prompt is appended. For extra clarity a newline can be added with the -l flag:

$ echo -n "00:1a:d1:48:ff:d0"| perl -ple 's/\W/_/g'
00_1a_d1_48_ff_d0

Neil H. Watson has also transformed this one-liner to an independent script

Read more...

Grep and special files

Sometimes, you may wondering why a simple grep -R /my/path suddenly stalls, without any blatant reason nor disk activity.

First thing to do (after having nervously restarted the command of course ;-)) : check the process state with ps:

$ ps -uwp 2821
USER   PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
loic  2821  0.1  0.0  13368  3148 pts/2    S+   18:22   0:00 grep -R cfe.png /srv/

The STAT column is interesting here, because it gives the process status (man ps)

Read more...

CFEngine: how many classes can be defined?

  • 2014-01-19 update: A memory leak has been corrected in the development version
  • 2013-12-22 update: Added a graph on results with classes defined inside classes: promise type
  • 2013-12-16 update: Quick reaction from the CFEngine developers: a bug has been opened to investigate the Git memory consumption

This article is based on the same principle as my latest post CFEngine: maximum strings length : using CFEngine under extreme situations to reveal where some limits are, or getting confident on CFEngine’s scalability.

Read more...

Valgrind Massif output analysis tools

Massif is an awesome Valgrind tool when it comes to profile heap usage of a program. Basically, it analyses during the process’s life how many heap memory has been allocated, and the functions responsible of the allocations.

Read more...

CFEngine: maximum strings length

Update 2013-12-04: If you would like to participate, there is a dedicated bug report and a thread on the mailing-list

As far as I know, the maximum length of strings variables is not outlined in the official documentation.

You will hit internal limitations through warnings and errors during cf-agent execution, some examples:

Buffer exceeded 8192 bytes (...)
Expansion overflow constructing string. Increase CF_EXPANDSIZE macro. Tried to add (...)
error: Fatal CFEngine error: Can't expand varstring

Because I prefer to know beforehand such limits, I have tried to empirically quantify them, by reading files of different sizes using 2 methods:

Read more...

CFEngine: Issue when reading /proc or /sys files with readfile()

Introduction

A first glance, reading files located in /proc or /sys directories on GNU/Linux systems is not very different from reading plain files.

But you may encounter surprises while doing so through CFEngine and its readfile() function. I will try to explain why, the current state with stable CFEngine versions, and a workaround.

TL;DR Workaround

Using CFEngine’s readfile()

Because of the “everything is a file” approach of all Unix derivatives, /proc or /sys files allow an usual I/O interface. In CFEngine, the readfile() function lets you reading an external file into a variable:

Read more...