Julian Andres Klode: hardlink 0.2 RC1 released
Filed under: General
* In case of you ve noticed, this blog has new URL: http://0x1f1f.wordpress.com, reading from Planet Debian doesn t harm your feed reader (if any readers left
The 13th Debian Conference is just around the corner. DebConf12 will be held in Managua, Nicaragua, July 8-14, 2012, and we need your help!
Why should I care?
DebConf is the annual conference for Debian contributors and interested users. Previous Debian Conferences have featured speakers and attendees from around the world (DebConf11 had attendees from 46 different countries).
DebConf helps share the knowledge and experiences of individual developers with the entire community. It also helps promote enthusiasm for specialized areas of development and encourages discussions about Debian s future.
The benefits that DebConf brings to the Debian project as a whole, and the larger Free Software community, will improve Debian and by extension will help improve GNU/Linux for everyone, whether they use Debian (or a Debian derivative), or any other distribution.
How can I help?
DebConf is a lot to organize and pay for. We invite you to help that this is going to be a successfull event.
More than two years ago I wrote arbtt, a tool that silently records what programs you are using and allows you to do statistics on that data later, based on rules that you define afterwards, hence the name automatic rule based time tracker. I wasn t doing much with it recently (the last release has been half a year ago), but it nevertheless was running on my machine and by now has tracked a total time span of 248 days in 350000 records.
Yesterday, I had a use for it again: measuring the time spent creating a certain document with LaTeX. So I added a rule to my categorize.cfg and ran arbtt-stats. I knew that it was not very fast, and that my data set has grown considerably since I last used it. And indeed, it took more than 6 minutes to process the data and spit out the result.
Since I m currently working on the GHC 7.4.1 transition in Debian anyways, I decided to check what happens if I compile the code with that version of the Haskell compiler, instead of the previous version 7.0.4. And behold: The whole process took merely 17.3 seconds to complete! At first I did not believe it, but the result was identical, both binaries were built with the same option, i.e. no profiling enabled or anything like that. Wouldn t you also like to have such speed ups for free, just by waiting for someone else to improve their work?
I tried to find out the reason for the speed up and created profiling output from both the old and the new binary. The old binary spends 83% of the time in Categorize.checkRegex, which basically just call Text.Regex.PCRE.Light.match. Since the version of pcre-light is the same in both binaries, I conclude that the Foreign Function Interface that GHC provides to interact with C libraries (libpcre in this case) is much faster now, although I do not find any mention in the release notes. And even if I do not count the 83% time spent in checkRegex, the code from the new compiler is still 2.7 times faster. Thanks, GHC devs, great work!
Flattr this post
Some sponsors are evil and pedanticOr on the command-line:
$ lintian -EvIL +pedantic ...It works for Lintian 2.5.5 (and newer), which handles pedantic like other severities. If you need help understanding the tags, you can add an extra i (-i) to evil . That being said, remember that experimental (-E) and pedantic (-L +pedantic) tags are what they are for a reason. Also quite a few people will probably find verbose (-v) too noisy. However, leaving any of them out would have ruined the mnemonic.
display-info = yes # or no display-experimental = yes # or no pedantic = yes # or no verbose = yes # or no
phpMyAdmin is quite popular software (to give some numbers let's mention 10000 downloads daily on SourceForge.net or 122685 reports in Debian's popcon) and as such is quite attractive target for various scripted attacks. If you run phpMyAdmin installation somewhere you should really make sure it is enough secured, so that these script kiddies don't get through.
In past month I've looked at what kind of attacks are these guys trying and in all cases these are pretty old vulnerabilities, some of them fixed years ago. So the first thing you should do is to update. It is always good to run latest stable version, but in case you can not for whatever reason, try at least taking the most important fixes and using them.
In ideal world your distribution would do this job for you, but in case it did not, you can for example take patches from Debian, which is pretty good at taking our patches (surprisingly it is not much related to my involvement there). To check which patches they have applied you can use excellent patch-tracker tool, which exposes patches from all released packages.
To give you overview of which issues are mostly being attempted to exploit by script kiddies right now, here is the list:
setup directory from phpMyAdmin, you will probably not use it after initial setuplibraries directory from browser, as it is not needed, supplied .htaccess file does thiscookie is probably the best choice for shared hostingFiled under: Debian English Phpmyadmin Suse 0 comments Flattr this!
perf Linux tool. I heard that oprofile
was deprecated and that there is a new tool, and I noted down to try
it sometime.
Updated: more languages, fixed typos, more details, some
graphs. Apologies if this shows twice in your feed.
The problem with perf stats is that I hate bloat, or even perceived
bloat. Even when it doesn't affect me in any way, the concept of
wasted cycles makes me really sad.
You probably can guess where this is going I said, well, let's see
what perf says about a simple "null" program. Surely doing nothing
should be just a small number of instructions, right?
Note: I think that perf also records kernel-side code, because the
lowest I could get was about ~50K instructions for starting a null
program in assembler that doesn't use libc and just executes the
syscall asm instruction. However, these ~50K instructions are noise
the moment you start to use more high-level languages. Yes, this is
expected, but the I was still shocked. And there's lots of delta
between languages I'd expected to behave somewhat identical.
Again, this is not important in the real world. At all. They are just
numbers, and probably the noise (due to short runtime) has lots of
influence on the resulting numbers. And I might have screwed up the
measurements somehow.
Test setup
Each program was the equivalent of 'exit 0' in the appropriate form
for the language. During the measurements, the machine was as much as
possible idle (single-user mode, measurements run at real-time
priority, etc.). For compiled languages, -O2 was used. For scripts,
a simple #!/path/to/interpreter (without options, except in the case
of Python, see below) was used. Each program/script was run 500 times
(perf's -r 500) and I've checked that the variations were small
( 0.80% on the metrics I used).
You can find all the programs I've used at
http://git.k1024.org/perf-null.git/, the current tests are for the
tag version perf-null-0.1.
The raw data for the below tables/graphs is at
log-4.
Results
Compiled languages
| Language | Cycles | Instructions |
|---|---|---|
| asm | 63K | 51K |
| c-dietlibc | 74K | 57K |
| c-libc-static | 177K | 107K |
| c-libc-shared | 506K | 300K |
| c++-static | 178K | 107K |
| c++-dynamic | 1,750K | 1,675K |
| haskell-single | 2,229K | 1,338K |
| haskell-threaded | 2,629K | 1,522K |
| ocaml-bytecode | 3,271K | 2,741K |
| ocaml-native | 1,042K | 666K |
more instructions. I would guess that the initialisation of the
standard C++ library is complex?
Haskell, which has a GC and quite a complex runtime, executes slightly
less instructions than C++, but uses more cycles. Not bad, given the
capabilities of the runtime. The two versions of the Haskell program
are with the single-threaded runtime and with the multi-threaded one;
not much difference. A fully statically-linked Haskell binary (not
recommended usually) goes below 1M instructions, but not by much.
OCaml is a very nice surprise. The bytecode runtime is a bit slow to
startup, but the (native) compiled version is quite fast to start:
only 2 number of instructions and cycles compared to C, for an
advanced language. And twice as fast as Haskell . Nice!
Shells
| Language | Cycles | Instructions |
|---|---|---|
| dash | 766K | 469K |
| bash | 1,680K | 1,044K |
| mksh | 1,258K | 942K |
| mksh-static | 504K | 322K |
/bin/sh
from bash to dash makes sense.
I wasn't aware of mksh, so thanks for the comments. It is, in the
static variant, more efficient that dash, by about 1.5 . However, the
dynamically linked version doesn't look too great (dash is also
dynamically linked; I would guess a statically-linked dash "beats"
mksh-static).
Text processing
I've added perl here (even though it's a 'full' language) just for
comparison; it's also in the next section.
| Language | Cycles | Instructions |
|---|---|---|
| mawk | 849K | 514K |
| gawk | 1,363K | 980K |
| perl | 2,946K | 2,213K |
Priority: required is
that it's faster than gawk, but I wouldn't have guessed it's almost
twice as fast.
Interpreted languages
Here is where the fun starts
| Language | Cycles | Instructions |
|---|---|---|
| lua 5.1 | 1,947K | 1,485K |
| lua 5.2 | 1,724K | 1,335K |
| lua jit | 1,209K | 803K |
| perl | 2,946K | 2,213K |
| tcl 8.4 | 5,011K | 4,552K |
| tcl 8.5 | 6,888K | 6,022K |
| tcl 8.6 | 8,196K | 7,236K |
| ruby 1.8 | 7,013K | 6,128K |
| ruby 1.9.3 | 35,870K | 35,022K |
| python 2.6 -S | 11,752K | 10,247K |
| python 2.7 -S | 11,438K | 10,198K |
| python 3.2 -S | 29,003K | 27,409K |
| pypy -S | 21,106K | 10,036K |
| python 2.6 | 25,143K | 21,989K |
| python 2.7 | 47,325K | 50,217K |
| python 2.7 -O | 47,341K | 50,185K |
| python 3.2 | 113,567K | 124,133K |
| python 3.2 -O | 113,424K | 124,133K |
| pypy | 90,779K | 68,455K |
perf stat python -c
'pass' you get some unbelievable numbers, like 50M instructions to
do, well, nothing. Yes, it has a GC, yes, it does import modules at
runtime, but still On closer investigation, the site module and the
imports it does do eat a lot of time. Running a simpler python -S
brings it back to a more reasonable 10M instructions, which is in-line
with the other interpreted languages.
However, even with the -S taken into account, Python also slows down
across versions: a tiny improvement from 2.6 to 2.7, but (like Ruby) a
3 slowdown from 2.7 to 3.2. Trying the optimised version (-O)
doesn't help at all. Trying pypy, which was based on Python 2.7, makes
it around 2 slower to startup (both with and without -S).
So in the interpreted languages, it seems only Lua is trying to
improve, the rest of the languages are piling up bloat with every
version. Note: I should have tried multiple perl versions too.
Java
Java is in its own category; you guess why , right?
GCJ was version 4.6, whereas by java below I mean OpenJDK Runtime
Environment (IcedTea6 1.11) (6b24-1.11-4).
| Language | Cycles | Instructions |
|---|---|---|
| null-gcj | 97,156K | 74,576K |
| java -jamvm | 85,535K | 80,102K |
| java -server | 147,174K | 136,803K |
| java -zero | 132,967K | 124,977K |
| java -cacao | 229,799K | 205,312K |
binfmt_misc
indeed, but that doesn't allow different Java classes to use different
Java VMs, so I don't count this), as opposed to every single other
thing I tested here. Someone didn't grow on Unix?
Comparative analysis
Since there are almost 4 orders of magnitude difference between all
the things tested here, a graph of cycles or instructions is not
really useful. However, cycles/instruction, branches percentage and
branches miss-predicted percentage can be. Hence first the
cycles/instructions:
Pypy is jumping out of the graph here, with the top value of over 2
cycles/instruction. Lua JIT is also bigger than Lua non-JIT, so maybe
there's something to this (mostly joking, two data points don't make a
series). On the other hand, Python wins as best cycles/instruction
(0.91). Lots of ILP, to get below 1?
Java gets, irrespective of VM, consistently near 1.0-1.1. C++ gets
very different numbers between static linking (1.666) and dynamic
linking (1.045), whereas C has basically identical numbers. mksh also
has a difference between dynamic and static linking. Hmm
Ruby, TCL and Python have consistent values across versions.
And that's about what I can see from that graph. Next up, percentage
of branches out of total instructions and percentage of branches
missed:
Note that the two lines shouldn't really be on the same graph; for the
branch %, the 100% is the total instructions count, but for the branch
miss %, the 100% is the total branch count. Anyway.
There are two low-value outliers:
Description: module to automate definition of a DBIx::Class::Schema DBIx::Class::Schema::Loader is an extension to DBIx::Class that automates the definition of a DBIx::Class::Schema by scanning table schemas and setting up columns and primary keys appropriately. It supports MySQL, PostgreSQL, SQLite and DB2. . Bare table definitions are fairly straightforward, but relationship creation is somewhat heuristic, especially with respect to choosing relationship types and names, as well as join types. The relationships generated by this module will probably never be as well-defined as hand-generated ones.I want to add This package is awesome but I don t want to be bothered by leading dots and white spaces. First, I go in the package directory, then check the syntax with
cme:
$ cme check dpkgThen create a loop directory, where the dpkg content will be mapped to a fuse directory:
$ mkdir loop $ cme fusefs dpkg -fuse-dir loop/ Mounting config on loop/ in background. Use command 'fusermount -u loop/' to unmount $ cat loop/control/binary/libdbix-class-schema-loader-perl/Description DBIx::Class::Schema::Loader is an extension to DBIx::Class that automates the definition of a DBIx::Class::Schema by scanning table schemas and setting up columns and primary keys appropriately. It supports MySQL, PostgreSQL, SQLite and DB2. Bare table definitions are fairly straightforward, but relationship creation is somewhat heuristic, especially with respect to choosing relationship types and names, as well as join types. The relationships generated by this module will probably never be as well-defined as hand-generated ones.Then edit
loop/control/binary/libdbix-class-schema-loader-perl/Description with your favorite editor.
For the sake of this blog, I will use echo to edit this file:
$ echo -e "\nThis module is awesome" >> loop/control/binary/libdbix-class-schema-loader-perl/DescriptionNow umount the loop (note that the actual debian/control is not changed before this step):
fusermount -u loopNow the result:
$ cat debian/control [...] Description: module to automate definition of a DBIx::Class::Schema DBIx::Class::Schema::Loader is an extension to DBIx::Class that automates the definition of a DBIx::Class::Schema by scanning table schemas and setting up columns and primary keys appropriately. It supports MySQL, PostgreSQL, SQLite and DB2. . Bare table definitions are fairly straightforward, but relationship creation is somewhat heuristic, especially with respect to choosing relationship types and names, as well as join types. The relationships generated by this module will probably never be as well-defined as hand-generated ones. . This module is awesomeHere s another example to fill the license text for a license while respecting DEP-5 syntax, (done after the cme command):
# creating this dir will create a new DEP-5
# standalone license section with name CC-BY-30
mkdir loop/copyright/License/CC-BY-30
# fill the text part of the license
wget http://creativecommons.org/licenses/by/3.0/legalcode -O - \
html2text -style pretty > loop/copyright/License/CC-BY-30/text
$ fusermount -u loop
$ cat debian/copyright
[...]
License: CC-BY-30
.
.
.
Creative_Commons
.
.
Creative Commons Legal Code
.
.
Attribution 3.0 Unported
[...]
And that s it. (note that cme command is new and is available only from version 2.004 of Config::Model)
Of course, there s more than a awy to do it: you can also run cme edit dpkg and add or edit license text in the GUI (or in an editor launched by the GUI). cme will take care of the syntax details.
All the best
The bug webinterface of the
Ultimate Debian Database
currently knows about the following release critical bugs:
| In Total: | 1340 |
|---|---|
| Affecting Wheezy: | 777 |
| Wheezy only: | 122 |
| Remaining to be fixed in Wheezy: | 655 |
| Pending in Wheezy: | 41 |
|---|---|
| Patched in Wheezy: | 86 |
| Duplicates in Wheezy: | 45 |
| Can be fixed in a security Update: | 21 |
| Contrib or non-free in Wheezy: | 16 |
| Claimed in Wheezy: | 0 |
| Delayed in Wheezy: | 6 |
| Otherwise fixed in Wheezy: | 49 |
Wheezyreleased. However, with the view of the Release Managers, 687 need to be dealt with for the release to happen. Please see
Interpreting the release critical bug statisticsfor an explanation of the different numbers.
The bug webinterface of the
Ultimate Debian Database
currently knows about the following release critical bugs:
| In Total: | 1340 |
|---|---|
| Affecting Wheezy: | 777 |
| Wheezy only: | 122 |
| Remaining to be fixed in Wheezy: | 655 |
| Pending in Wheezy: | 41 |
|---|---|
| Patched in Wheezy: | 86 |
| Duplicates in Wheezy: | 45 |
| Can be fixed in a security Update: | 21 |
| Contrib or non-free in Wheezy: | 16 |
| Claimed in Wheezy: | 0 |
| Delayed in Wheezy: | 6 |
| Otherwise fixed in Wheezy: | 49 |
Wheezyreleased. However, with the view of the Release Managers, 687 need to be dealt with for the release to happen. Please see
Interpreting the release critical bug statisticsfor an explanation of the different numbers.
SNMP stands for Simple Network Management Protocol. It allows
a manager to query information from an agent. A popular use of
SNMP is to retrieve network interface counters to plot a bandwidth
graph. While the S in SNMP stands for simple, SNMP can be quite
difficult to deal with. However, it is still the de facto standard
for retrieving metrics in an heterogeneous
environment. Net-SNMP is a suite of SNMP applications
including an agent. Out of the box, this agent exports a lot of
information but if something is missing, there are several ways to
extend it. Which ones?
tl;dr: in my opinion, extending Net-SNMP should be done with
either of those methods:
extend directive;pass_persist directive;.1.3.6.1.2.1.31.1.1.1.1.2 is the
OID of the name of the second network card.
Usually, SNMP is operated over UDP, port 161. For the purpose of this
article, we consider a manager can issue three kinds of requests:
IF-MIB::ifName.2. Those MIB modules are described using a subset of
ASN.1 defined in RFC 2578.
A MIB module allows to group several variables into a conceptual
table. For example, IF-MIB::ifDescr, IF-MIB::ifType,
IF-MIB::ifSpeed are columns of IF-MIB::ifTable. Each row is
associated to an index. In the case of IF-MIB::ifTable, it is the
interface index. Net-SNMP includes snmptable allowing one to display
such a table in a natural manner1:
$ snmptable localhost IF-MIB::ifTable SNMP table: IF-MIB::ifTable ifIndex ifDescr ifType ifMtu ifSpeed 1 lo softwareLoopback 16436 10000000 2 eth0 ethernetCsmacd 1500 100000000 3 eth1 ethernetCsmacd 1500 10000000 4 br0 ethernetCsmacd 1500 0
snmpget to get a specific
variable, snmpwalk to discover available variables (with GETNEXT
operation) from an OID and snmptranslate to translate between object
names and OID.
$ snmpget localhost IF-MIB::ifDescr.2 IF-MIB::ifDescr.2 = STRING: eth0 $ snmpwalk localhost IF-MIB::ifDescr IF-MIB::ifDescr.1 = STRING: lo IF-MIB::ifDescr.2 = STRING: eth0 IF-MIB::ifDescr.3 = STRING: eth1 IF-MIB::ifDescr.4 = STRING: br0 $ snmpwalk -On public localhost .1.3.6.1.2.1.2.2.1.2 .1.3.6.1.2.1.2.2.1.2.1 = STRING: lo .1.3.6.1.2.1.2.2.1.2.2 = STRING: eth0 .1.3.6.1.2.1.2.2.1.2.3 = STRING: eth1 .1.3.6.1.2.1.2.2.1.2.4 = STRING: br0 $ snmptranslate -On IF-MIB::ifDescr.3 .1.3.6.1.2.1.2.2.1.2.3
ethtool -S allows us to access various statistics from a network
card, like the number of octets received and transmitted or the number
of collisions. While some of those statistics are defined in
IF-MIB, in RMON-MIB and in
EtherLike-MIB, some of them are not available and very
specific. Therefore, we would like to export those statistics,
unmodified, through SNMP.
To the best of my knowledge, no MIB module exists for such an
usage. The first task is to write one. It can be called
ETHTOOL-MIB. It only contains one table indexed by the
interface index and the name of the statistic. Here is the expected output:
$ snmpwalk localhost ETHTOOL-MIB::ethtoolStat.2 ethtoolStat.2.'align_errors' = Counter64: 0 ethtoolStat.2.'broadcast' = Counter64: 25 ethtoolStat.2.'multicast' = Counter64: 345 ethtoolStat.2.'rx_errors' = Counter64: 0 ethtoolStat.2.'rx_missed' = Counter64: 0 ethtoolStat.2.'rx_packets' = Counter64: 262011 ethtoolStat.2.'tx_aborted' = Counter64: 0 ethtoolStat.2.'tx_errors' = Counter64: 0 ethtoolStat.2.'tx_multi_collisions' = Counter64: 0 ethtoolStat.2.'tx_packets' = Counter64: 296170 ethtoolStat.2.'tx_single_collisions' = Counter64: 0 ethtoolStat.2.'tx_underrun' = Counter64: 0 ethtoolStat.2.'unicast' = Counter64: 261641
extend directive allows the agent to execute an arbitrary
command and to provide its output and status through
NET-SNMP-EXTEND-MIB module. If we want to export the statistics for
eth0, we could add something like this in snmpd.conf, using a
custom script to format the output of ethtool -S in
a way that is more suitable for our use:
# Export eth0 statistics extend eth0-names /full/path/to/ethtool-stats eth0 names extend eth0-values /full/path/to/ethtool-stats eth0 values
NET-SNMP-EXTEND-MIB:: nsExtendOutput2Table:
$ snmpwalk localhost NET-SNMP-EXTEND-MIB::nsExtendOutput2Table nsExtendOutLine."eth0-names".1 = STRING: tx_packets nsExtendOutLine."eth0-names".2 = STRING: rx_packets nsExtendOutLine."eth0-names".3 = STRING: tx_errors nsExtendOutLine."eth0-names".4 = STRING: rx_errors nsExtendOutLine."eth0-names".5 = STRING: rx_missed nsExtendOutLine."eth0-names".6 = STRING: align_errors nsExtendOutLine."eth0-names".7 = STRING: tx_single_collisions nsExtendOutLine."eth0-names".8 = STRING: tx_multi_collisions nsExtendOutLine."eth0-values".1 = STRING: 246309 nsExtendOutLine."eth0-values".2 = STRING: 223941 nsExtendOutLine."eth0-values".3 = STRING: 0 nsExtendOutLine."eth0-values".4 = STRING: 0 nsExtendOutLine."eth0-values".5 = STRING: 0 nsExtendOutLine."eth0-values".6 = STRING: 0 nsExtendOutLine."eth0-values".7 = STRING: 0 nsExtendOutLine."eth0-values".8 = STRING: 0
eth2, we
could issue the following command:
$ snmpset -m +NET-SNMP-EXTEND-MIB localhost \ > 'nsExtendStatus."eth2-names"' = createAndGo \ > 'nsExtendCommand."eth2-names"' = /full/path/to/ethtool-stats \ > 'nsExtendArgs."eth2-names"' = 'eth2 names' \ > 'nsExtendStatus."eth2-values"' = createAndGo \ > 'nsExtendCommand."eth2-values"' = /full/path/to/ethtool-stats \ > 'nsExtendArgs."eth2-values"' = 'eth2 values' nsExtendStatus."eth2-names" = INTEGER: createAndGo(4) nsExtendCommand."eth2-names" = STRING: /full/path/to/ethtool-stats nsExtendArgs."eth2-names" = STRING: eth2 names nsExtendStatus."eth2-values" = INTEGER: createAndGo(4) nsExtendCommand."eth2-values" = STRING: /full/path/to/ethtool-stats nsExtendArgs."eth2-values" = STRING: eth2 values $ snmpgetnext -m +NET-SNMP-EXTEND-MIB localhost \ > 'nsExtendOutLine."eth2-names"' nsExtendOutLine."eth2-names".1 = STRING: tx_packets
extend does not allow to implement an arbitrary MIB module. If
the cache is not disabled, extend is a good solution for various
simple needs, like providing the content of a one-line file or the
output of some Nagios plugin. However, exporting anything tabular,
like interface statistics, is not a good fit.
pass_persist directive. Such a script will
receive requests on its standard input with a very simple
line-oriented protocol described in the
manual page of snmpd.conf. Here is an example of interaction:
PING PONG get .1.3.6.1.4.1.39178.100.1.1.1.2.2.109.117.108.116.105.99.97.115.116 .1.3.6.1.4.1.39178.100.1.1.1.2.2.109.117.108.116.105.99.97.115.116 counter64 223941 getnext .1.3.6.1.4.1.39178.100.1.1.1.2.2 .1.3.6.1.4.1.39178.100.1.1.1.2.2.97.108.105.103.110.95.101.114 counter64 0
use SNMP::Extension::PassPersist; my $extsnmp = SNMP::Extension::PassPersist->new( backend_collect => \&update_tree ); $extsnmp->run; sub update_tree my @interfaces = </sys/class/net/*>; foreach my $interface (@interfaces) $interface =~ s/^.*\///; open(ETHTOOL, "ethtool -S $interface 2>/dev/null ") or next; while (<ETHTOOL>) /^\s+(\w+): (\d+)$/ or next; my $name = $1; my $value = int($2); my $oid = oid_compute($interface, $name); $extsnmp->add_oid_entry($oid, "counter", $value); close(ETHTOOL);
pass_persist allows you to implement an arbitrary MIB module with
honest performances. Here are some important things to know about this directive:
snmpd to
become a master agent, you just need to add master agentx in
snmpd.conf. Here are some of the benefits of an AgentX sub-agent over
pass_persist:
NetSNMP::agent, to write a sub-agent
using AgentX protocol. This module is not as convenient as the module
for pass_persist described above since it does not provide a
convenient layer to put required information into some
datastore. Basically, it mimics the available C API. Here are a few
examples of its use:
pass_persist version. My Perl skills
are a bit rusty and the code has many rough edges.ctypes. It provides a more
high-level view. I did not write an example for this one but you can
look at the example provided by the author.
mib2c, a tool that will
help you convert a MIB module into C code: after a few questions, you
will get a skeleton C code you will have to complete with the logic to
retrieve real objects. A generated file also provides directions on
what to do (with some magic command to have a step-by-step cookbook).
I was able to implement ETHTOOL-MIB by just running it through
mib2c, choosing the table container helper with cache and adding
some code in ethtoolStatTable_data_access.c. You can look at the
result on Github. Here is a stripped-down
version2 of what has been modified:
/* Socket for ioctl */ skfd = socket(AF_INET, SOCK_DGRAM, 0); /* Iterate through all interfaces */ getifaddrs(&ifap); for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) /* Grab statistics name and values */ strcpy(ifr.ifr_name, ifa->ifa_name); drvinfo.cmd = ETHTOOL_GDRVINFO; ifr.ifr_data = (caddr_t) &drvinfo; ioctl(skfd, SIOCETHTOOL, &ifr); n_stats = drvinfo.n_stats; strings->cmd = ETHTOOL_GSTRINGS; strings->string_set = ETH_SS_STATS; strings->len = n_stats; ifr.ifr_data = (caddr_t) strings; ioctl(skfd, SIOCETHTOOL, &ifr); stats->cmd = ETHTOOL_GSTATS; stats->n_stats = n_stats; ifr.ifr_data = (caddr_t) stats; ioctl(skfd, SIOCETHTOOL, &ifr); ifIndex = if_nametoindex(ifa->ifa_name); /* Iterate through statistics */ for (i = 0; i < n_stats; i++) /* Declare the appropriate index */ strncpy(ethtoolStatName, (char *)&strings->data[i * ETH_GSTRING_LEN], ETH_GSTRING_LEN); ethtoolStatName[sizeof(ethtoolStatName) - 1] = '\0'; ethtoolStatName_len = strlen(ethtoolStatName); /* Append this new variable to the container. */ rowreq_ctx = ethtoolStatTable_allocate_rowreq_ctx(); ethtoolStatTable_indexes_set(rowreq_ctx, ifIndex, ethtoolStatName, ethtoolStatName_len); rowreq_ctx->data.ethtoolStat.high = stats->data[i] >> 32; rowreq_ctx->data.ethtoolStat.low = (uint32_t)stats->data[i]; CONTAINER_INSERT(container, rowreq_ctx);
mib2c built a ethtoolStatTable_indexes_set() for this
purpose. OpenHPI project provides an
extensive documentation to write a sub-agent this way.
Now, on the downside, to implement a single table, I have 14
generated files whose code style is usually unfit to integrate
into an existing project : some people, me included, do not like
automatically generated code, all the more when it is so verbose. The
solution would be to use the new API without mib2c; unfortunately,
while the documentation exists, all provided examples
rely exclusively on mib2c tool. Unless you are able to grasp the new
API without it, I would restrict its use to two cases:
mib2c, there is no
coding style problem.static oid ethtool_oid[] = 1, 3, 6, 1, 4, 1, 39178, 100, 1 ; static struct variable3 ethtool_vars[] = 1, ASN_COUNTER64, RONLY, ethtool_stat, 3, 1, 1, 2 ; int main() netsnmp_enable_subagent(); snmp_disable_log(); snmp_enable_stderrlog(); init_agent("ethtoolAgent"); REGISTER_MIB("ethtoolStatTable", ethtool_vars, variable3, ethtool_oid); init_snmp("ethtoolAgent"); while (1) agent_check_and_process(1);
REGISTER_MIB() macro is used to register the provided root OID
(ethtool_oid) to the master agent. It also registers handlers
associated to various sub-OID through the ethtool_vars[] array. Each
member of this array features the following fields:
magic is an integer allowing one to discriminate OID handled by
the same handler. For a table, this allows to handle several
columns with the same handler since they share a common index.type is the type of the variable that will be returned.acl tells if the object is read-only (RONLY) or read-write
(RWRITE).findVar is the handler associated to the object. Its task will be
to find the appropriate object and return its value.ethtool_stat() handler function is the following:
static u_char* ethtool_stat(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method);
NULL if no appropriate object was found. The value can be statically
stored since it will be copied. Here is the description of the arguments:
struct variable *vp is the structure the handle was associated
with, except that vp->name is now a full OID, not a relative
one. You can access vp->magic to determine which column or which
scalar to handle if this handler is common to several objects.oid *name and size_t *length describe the OID requested. If you
want to return another OID (for a GETNEXT request for example), you
can modify them. name points to an OID array large enough to fit
any OID you want to return.int exact tells if the requested OID should be exactly matched
(case of GET or SET) or not (GETNEXT).size_t *var_len is used to tell the size of the returned object.WriteMethod **write_method is only used if the variable is
modifiable. When a SET request is received, the API will call the
handler with exact set to 1 and expects to get a pointer to the
function that will handle the write operation3.exec and sh are deprecated. Use extend instead.pass is a bit simpler than pass_persist. The command is run
once for each request. Such a command can easily be turned into a
pass_persist script. Moreover, Net-SNMP will not answer any
request while a pass command is running.proxy redirects requests to another SNMP agent. Unless you have
some code that can only act as a complete SNMP agent, it is better
to use AgentX instead. For programs using Net-SNMP API, turning an
agent into an AgentX sub-agent is just one line of code. Since a
sub-agent involves less code than a complete agent, it is more
efficient and more reliable.smux has been superseeded by AgentX.perl and dlmod allow one to load and execute external code
inside the running agent. Unless you have important performance
requirements, it is better to use a sub-agent instead: if some bug
happens, only the sub-agent will be affected, not the master
agent. A sub-agent sticks more closely to the Unix philosophy:
write programs that do one thing and do it well . However,
Net-SNMP FAQ says:
Implementing the module in C within the main agent (directly or via
dlmod) is probably the most efficient and reliable, closely followed
by embedded perl (or python) extensions. These have the advantage
of minimal overheads between the code implementing the MIB module,
and the agent framework, and no inter-process communication issues.
snmp* are usually required to
specify a version and a community (for SNMPv1 and
SNMPv2c) or a user (for SNMPv3). In all examples, I do
not specify anything. I assume that ~/.snmp/snmp.conf
contains the appropriate bits. Moreover, some outputs are
truncated.
A year ago, during FOSDEM 2011, I walked up to the NamurLUG folks who'd been doing video
coverage of FOSDEM for years, and suggested that this year, maybe they
should consider using dvswitch for video
coverage. While they seemed agreeable to this idea, they simply had not
had the time to look at it in detail, and were therefore not using it.
Since I've used dvswitch in the past, both as part of the DebConf video team and for my own
concert recordings, I reasoned this a problem that could be solved by
joining the video team.
However, when it came to be time to start preparing for FOSDEM 2012,
we found that many of the NamurLUG people were not going to have as much
time to prepare for video coverage as they had during past years, and
therefore responsibility of FOSDEM video coverage fell entirely to
me. This was fairly unexpected, though not too daunting.
For those of you who don't know dvswitch very well: a typical
dvswitch installation for coverage of a talk requires:



The bug webinterface of the
Ultimate Debian Database
currently knows about the following release critical bugs:
| In Total: | 1447 |
|---|---|
| Affecting Wheezy: | 865 |
| Wheezy only: | 170 |
| Remaining to be fixed in Wheezy: | 695 |
| Pending in Wheezy: | 46 |
|---|---|
| Patched in Wheezy: | 91 |
| Duplicates in Wheezy: | 42 |
| Can be fixed in a security Update: | 18 |
| Contrib or non-free in Wheezy: | 15 |
| Claimed in Wheezy: | 0 |
| Delayed in Wheezy: | 8 |
| Otherwise fixed in Wheezy: | 44 |
Wheezyreleased. However, with the view of the Release Managers, 767 need to be dealt with for the release to happen. Please see
Interpreting the release critical bug statisticsfor an explanation of the different numbers.
If you re not into packaging and if you asked how you could help Debian, someone probably suggested that you help to translate it.
It s true that translating Debian is essential if we want to make Debian available to everybody on the world. There are many persons who are stuck as soon as they get a message in English, so it s important to aim for 100% coverage in terms of localization.
Some vocabulary: localization vs internationalization
Internationalization (i18n) is the work that makes it possible to translate messages in a given application.
Localization (l10n) is the work of translating messages of said application. So as a translator, you ll be doing localization but some knowledge of internationalization is still useful because it will define how you re supposed to provide the translations. We ll come back to that later.
Join your localization team
Usually the translation work is shared among multiple translators within a localization team. Check out the Debian International page on www.debian.org to find out instructions for translators for each language.
Many teams have a debian-l10n-*@lists.debian.org mailing list used for coordination, feel free to ask questions on those lists when you start (but make sure that you have read the relevant documentation before).
Each team has its own workflow, so observe for a while to get used to what s happening before asking your first questions.
What is there to translate?
The translation of most of the software provided by Debian is not handled by Debian. The Debian translation teams only handle the translation of:
# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR Software in the Public Interest, Inc. # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR <email>, YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: dpkg 1.16.1\n" "Report-Msgid-Bugs-To: debian-dpkg@lists.debian.org\n" "POT-Creation-Date: 2011-09-23 03:37+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <email>\n" "Language-Team: LANGUAGE <ll>\n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" #: lib/dpkg/ar.c:66 #, c-format msgid "invalid character '%c' in archive '%.250s' member '%.16s' size" msgstr "" #: lib/dpkg/ar.c:81 lib/dpkg/ar.c:97 lib/dpkg/ar.c:108 lib/dpkg/ar.c:112 #: lib/dpkg/ar.c:134 utils/update-alternatives.c:1154 #, c-format msgid "unable to write file '%s'" msgstr "" [ ]The lines starting with #: are comments that indicate the source files where the (English) string is used. This can be useful if you want check the source to have more information about how the string is used. The lines starting with #, contain flags that can be important. If the fuzzy flag is set, the translated string is not used because it must be updated (or at least verified) since the original string evolved. The c-format flags indicates that the string must be a C format string, this has some implications in what s allowed in the string (in particular when it embeds conversion specifier for arguments submitted to printf-like functions). Another thing to note is that the translation of the empty string is used to store some meta-information about the translation itself. Contributing a translation as a PO file When you start a new translation, you copy that POT file to create a PO file for your own language (eg. fr.po for the French language). You replace some template values (identified with the upper case words in the POT file) and you replace all the empty strings on msgstr lines with the translation of the string that appears in the previous msgid line. The result could be something like this:
# translation of fr.po to French # Messages fran ais pour dpkg (Linux-GNU Debian). msgid "" msgstr "" "Project-Id-Version: fr\n" "Report-Msgid-Bugs-To: debian-dpkg@lists.debian.org\n" "POT-Creation-Date: 2011-09-23 03:37+0200\n" "PO-Revision-Date: 2012-01-16 07:57+0100\n" "Last-Translator: Christian Perrier <bubulle>\n" "Language-Team: French <debian-l10n-french>\n" "Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: Plural-Forms: nplurals=2; plural=n>1;\n" "X-Generator: Lokalize 1.2\n" #: lib/dpkg/ar.c:66 #, c-format msgid "invalid character '%c' in archive '%.250s' member '%.16s' size" msgstr "caract re invalide %1$c dans la taille du membre %3$.16s de l'archive %2$.250s " #: lib/dpkg/ar.c:81 lib/dpkg/ar.c:97 lib/dpkg/ar.c:108 lib/dpkg/ar.c:112 #: lib/dpkg/ar.c:134 utils/update-alternatives.c:1154 #, c-format msgid "unable to write file '%s'" msgstr "impossible d' crire le fichier %s " [ ]If there s already a PO file for your language, there might still work to do: there might be strings that have not yet been translated and there might be fuzzy strings which have to be updated strings which were already translated but where the original string has been modified. There are software that can assist you to edit PO files: poedit, virtaal, lokalize, gtranslator. There are also special extensions for vim (packaged in vim-scripts) and for Emacs. Submit the translation for inclusion Once you have a complete PO file, you should submit it for inclusion. Sometimes you will have been granted commit rights to the source code repository so that you can include your translation by yourself. In the other cases, you should submit your translation with a bug report tagged l10n and someone else will include your work in the next release. Depending on the team, the workflow might require a review before the submission. In that case, you usually have to send a call for review on the coordination mailing list. Go ahead! Hopefully those explanations will be enough to get you started. There are many other things to learn but it s good to learn while practicing For example, can you find out why the French translation above changed %c in %1$c ?
Do you want to read more tutorials like this one? Click here to subscribe to my free newsletter, you can opt to receive future articles by email.
No comment Liked this article? Click here. My blog is Flattr-enabled.
Next.