Julius Plenz – Blog

Rapzeugs

Was so liegen geblieben ist:

Bei mir läuft die Königsmische auf Repeat.

posted 2012-01-22 tagged hiphop

vlock and suspend to ram

I've had weird race conditions when using vlock together with s2ram. It appears suspend to ram wants to switch VTs, while vlock hooks into the switch requests and explicitly disables them. So some of the time, the machine would not suspend, while at other times, vlock wouldn't be able to acquire the VT.

To solve this, I wrote a simple vlock plugin, which simply clears the lock mechanism, writes mem to /sys/power/state and later reinstates the locking mechanism. This plugin is called after all and new. Thus, the screen will be locked properly before suspending.

Here's my suspend.c:

#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

/* Include this header file to make sure the types of the dependencies
 * and hooks are correct. */
#include "vlock_plugin.h"
#include "../src/console_switch.h"

const char *succeeds[] = { "all", "new", NULL };
const char *depends[] =  { "all", "new", NULL };

bool vlock_start(void __attribute__ ((__unused__)) **ctx_ptr)
{
    int fd;

    unlock_console_switch();

    if((fd = open("/sys/power/state", O_WRONLY)) != -1) {
        if(write(fd, "mem", 3) == -1)
            perror("suspend: write");
        close(fd);
    }

    lock_console_switch();

    return true;
}

Simply paste it to the vlock modules folder, make suspend.so and copy it to /usr/lib/vlock/modules. I now invoke it like this:

env VLOCK_PLUGINS="all new suspend" vlock

posted 2012-01-20 tagged linux and c

Xorg, really?!

Are you fucking kidding me? You reintroduce broken behaviour that possibly has devastating security consequences and and make it the default?! Yeah I agree the "usual" X server locking approach is not the best way to do it – but to knowingly smash the security of people's computers on a grand scale... that's priceless.

(My locking solution is env USER=feh vlock -a -n, again.)

Update: Why it happened

posted 2012-01-20 tagged linux and rant

zsh: complete words from tmux pane

Today I wrote a rather cool Z-Shell completion function: It will present all words that are found in the current tmux pane in a zsh completion menu. That means you can actually complete words from the output of commands that you just executed. (In a way it's a little bit like the keeper function, without the overhead of remembering to call keeper in the first place.)

The code below defines two keybindings:

Here's the code:

_tmux_pane_words() {
  local expl
  local -a w
  if [[ -z "$TMUX_PANE" ]]; then
    _message "not running inside tmux!"
    return 1
  fi
  w=( ${(u)=$(tmux capture-pane \; show-buffer \; delete-buffer)} )
  _wanted values expl 'words from current tmux pane' compadd -a w
}

zle -C tmux-pane-words-prefix   complete-word _generic
zle -C tmux-pane-words-anywhere complete-word _generic
bindkey '^Xt' tmux-pane-words-prefix
bindkey '^X^X' tmux-pane-words-anywhere
zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' completer _tmux_pane_words
zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' ignore-line current
zstyle ':completion:tmux-pane-words-anywhere:*' matcher-list 'b:=* m:{A-Za-z}={a-zA-Z}'

How does it work? _tmux_pane_words will just capture the current pane's contents (capture-pane), print out the buffer that contains it (show-buffer) and then delete it again (delete-buffer). – The rest of the magic happens via Zsh's excellent completion mechanisms.

See it in action (after typing spm^X^X):

posted 2012-01-19 tagged zsh, tmux and linux

Wenn der kleine Hunger kommt...

... Rucolasalat mit Tomaten!

posted 2012-01-17 tagged life

trying pthreads

Today I played around with POSIX threads a little. In an assignment, we have to implement a very, very simple webserver that does asynchronous I/O. Since it should perform well, I thought I'd not only serialize I/O, but also parallelize it.

So there's a boss that just accepts new inbound connections and appends the fds to a queue:

clientfd = accept(sockfd, (struct sockaddr *) &client, &client_len);
if(clientfd == -1)
    error("accept");
new_request(clientfd);

The new_request function in turn appends it to a queue (of size TODOS = 64), and emits a cond_new signal for possibly waiting workers:

pthread_mutex_lock(&mutex);
while((todo_end + 1) % TODOS == todo_begin) {
    fprintf(stderr, "[master] Queue is completely filled; waiting\n");
    pthread_cond_wait(&cond_ready, &mutex);
}
fprintf(stderr, "[master] adding socket %d at position %d (begin=%d)\n",
    clientfd, todo_end, todo_begin);
todo[todo_end] = clientfd;
todo_end = (todo_end + 1) % TODOS;
pthread_cond_signal(&cond_new);
pthread_mutex_unlock(&mutex);

The workers (there being 8) will just emit a cond_ready, possibly wait until a cond_new is signalled, and then extract the first client fd from the queue. After that, a simple function involving some reads and writes will handle the communication on that fd.

pthread_mutex_lock(&mutex);
pthread_cond_signal(&cond_ready);
while(todo_end == todo_begin)
    pthread_cond_wait(&cond_new, &mutex);
clientfd = todo[todo_begin];
todo_begin = (todo_begin + 1) % TODOS;
pthread_mutex_unlock(&mutex);

// handle communication on clientfd

(Full source is here: webserver.c.)

Now this works pretty well and is fairly easy. I'm not very experienced with threads, though, and run into problems when I do massive parallel requests.

If I run ab, the Apache Benchmark tool with 10,000 requests, 1,000 concurrent, on the webserver it'll go up to 9000-something requests and then lock up.

$ ab -n 10000 -c 1000 http://localhost:8080/index.html
...
Completed 8000 requests
Completed 9000 requests
apr_poll: The timeout specified has expired (70007)
Total of 9808 requests completed

The webserver is blocked; its last line of output reads like this:

[master] Queue is completely filled; waiting

If I attach strace while in this blocking state, I get this:

$ strace -fp `pidof ./webserver`
Process 21090 attached with 9 threads - interrupt to quit
[pid 21099] recvfrom(32,  <unfinished ...>
[pid 21098] recvfrom(23,  <unfinished ...>
[pid 21097] recvfrom(31,  <unfinished ...>
[pid 21095] recvfrom(35,  <unfinished ...>
[pid 21094] recvfrom(34,  <unfinished ...>
[pid 21093] recvfrom(33,  <unfinished ...>
[pid 21092] recvfrom(26,  <unfinished ...>
[pid 21091] recvfrom(24,  <unfinished ...>
[pid 21090] futex(0x6024e4, FUTEX_WAIT_PRIVATE, 55883, NULL

So the children seem to be starving on unfinished recv calls, while the master thread waits for any children to work away the queue. (With a queue size of 1024 and 200 workers I couldn't reproduce the situation.)

How can one counteract this? Specify a timeout? Spawn workers on demand? Set the listen() backlog argument to a low value? – or is it all Apache Benchmark's fault? *confused*

posted 2012-01-17 tagged linux and c

"Wofür Deutschland Krieg führen darf. Und muss."

Ich habe unter der Woche Bernd Ulrichs Streitschrift Wofür Deutschland Krieg führen darf. Und muss. vom Oktober 2011 gelesen. Das Buch war für mich unter mehreren Aspekten interessant. Einerseits beleuchtet es die Hintergründe der Kriege, die ich damals als Kind noch nicht mitbekommen habe – den Namen UÇK kannte ich zwar aus den Nachrichten, wusste aber damit nichts zu verbinden – und bietet so eine gute Perspektive auf die jüngere Deutsche Geschichte, gerade auch in Hinblick auf die Auswirkungen der Wiedervereinigung auf die geopolitische Sicherheitslage Europas und der Welt, sowie das politische Selbstbewusstsein Deutschlands. Andererseits meldet sich hier aus der Generation meiner Eltern ein Kriegsdienstverweigerer und ehemaliger Mitarbeiter des Fraktionsvorstandes der Grünen im Deutschen Bundestag zu Wort, der mittlerweile stellvertretender Chefredaktuer und Leiter des Politik-Ressorts der Zeit ist.

Das ganze ist flüssig zu lesen, aber natürlich kontrovers – und das soll es ja auch sein. Zunächst muss gesagt werden, dass das Buch eine Reihe interessanter Einsichten enthält, die auch sehr treffend ausformuliert sind. Über die Tatsache, dass sich in der deutschen Bevölkerung nur sehr schwierig eine stabile Mehrheit für einen Einsatz der Bundeswehr finden lässt, bemerkt er ganz richtig (S. 53):

Hinzu kommt ein ganz profaner Umstand. In Deutschland finden unablässig irgendwelche Wahlen statt, weshalb eine kriegführende Bundesregierung einem andauernden Plebiszit ausgesetzt ist, das sie nur überstehen kann, solange andere als die militärischen Fragen wahlentscheidend sind.

Und weiter:

Die Regierung wird infolgedessen dazu tendieren, die Fragen von Krieg und Frieden möglichst nicht zu thematisieren, ja, ihre Thematisierung aktiv zu verhindern.

Eine weitere interessante Beobachtung stellt Ulrich über die "spezielle Verbindung" zwischen Deutschland und Israel an (S. 73):

In der wachsenden Distanz zu Israel und in die zunehmende Skepsis gegen Militäreinsätze hinein bringt nun die Merkel-Doktrin Deutschland näher an einen Militäreinsatz für Israel. Hier liegt eine enorme latente Spannung.

Schaut man auf das Inhaltsverzeichnis, so kann man das Buch in einige wesentliche Thesen zusammenfassen:

  1. Aufweichung der Bündnistreue: Emanzipation von der Bündnispflicht, hin zu Von-Fall-zu-Fall-Entscheidungen.
  2. Die Kriege im Irak und in Afghanistan waren falsch; die auf dem Balkan und in Libyen richtig.
  3. Künftige Militäreinsätze im Ausland sollten "Polizeicharakter" haben, Völkerrecht ist teilweise überholt.

Meine Generation, also die zur Zeit des Niedergangs der DDR oder nach dem Mauerfall Geborenen, sind in meinen Augen sehr pazifistisch eingestellt, und das ist gut so. Rundheraus würde ich sagen: Krieg ist immer falsch.

Leider stimmt das nicht. Ja, wenn man an all die Kriege denkt, die Amerika so geführt hat im Südosten Asiens, oder wie die Kriege in Afghanistan und dem Irak laufen: das ist abgrundtief falsch. – Andererseits muss man sich immer wieder den Ruandischen Genozid vor Augen halten, und die damalige Passivität der UN. Dadurch, dass westliche Mächte nicht eingegriffen haben, obwohl sie ziemlich gut wussten, dass ein riesiger Völkermord passierte, das ist unverantwortlich. – Wenn man sagt "Krieg ist in keinem Fall tragbar", dann öffnet man dem Kulturrelativismus Tür und Tor. Profan ausgedrückt, sagt man: "Lass die Anderen doch mit sich selbst klarkommen. Wenn sie sich abschlachten, dann ist das nicht mein Problem, und nicht einmal notwendigerweise falsch." – eine solche Einstellung ist sehr, sehr gefährlich. Von daher ist für den Pazifisten die Fragestellung, ob es überhaupt legitime Kriege gibt, eine sehr viel schwierigere, als sie auf den ersten Blick scheint.

Im Nachhinein kann man möglicherweise sagen, dass der Einsatz der Bundeswehr als Teil des NATO-Bündnisses in Libyen gerechtfertigt gewesen wäre. Der Einsatz ist mittlerweile beendet, und der Aufbau des Landes kann beginnen. Wenn ein Präsident die Luftwaffe gegen das eigene Volk einsetzt, dann sollte es schwer sein, wegzuschauen. – Natürlich muss man sich überlegen, wer denn die Machtposition Gaddafis über Jahrzehnte gefestigt hat. Aber man kann und darf die Frage nach militärischer Intervention nicht mit einer antiimperialistischen Floskel à la "hätten wir nicht X gemacht ... wäre nicht Y passiert" abtun. Dort sterben Leute.

Ich tue mich auch schwer in der Frage, zumal ich von einer anderen Prämisse ausgehe, was die Situation zugegebenermaßen leichter macht: Ich empfinde nichts für das Staatenkonstrukt Deutschland. Deutsche Kultur, insbesondere die deutsche Sprache und Literatur, sowie klassische Musik bedeutet mir etwas – das geht aber über Staatengrenzen hinaus. Der Großteil von Deutschland – das heißt, alles außerhalb von Hamburg und Berlin – bedeutet mir nichts, ganz einfach nichts. Ich habe da schließlich nie gelebt. Aber ohne die Grundlage von konstruierten Staaten, die gemeinsam agieren, entfällt natürlich die Notwendigkeit zur Verantwortung gegenüber anderen Staaten – es bleibt die Verantwortung von Menschen gegenüber anderen Menschen, und dort sind die Menschenrechte ein ziemlich allgemein akzeptierter Konsens.

Zusammenfassend lässt sich sagen, dass das Buch einige spannende Einsichten, auch in das Wirken von Presse und Politik, bereit hält. Und es ist beeindruckend zu sehen, wie ein ehemaliger überzeugter pazifistischer Aktivist heute Kriege zu legitimieren versucht.

posted 2012-01-08 tagged politik and bookdump

mutt sidebar patch improvements

It is generally accepted as an almost universal truth that mutt sucks, but is the MUA that sucks less than all others. While people use either Vim or Emacs and fight about it, I hardly see any people fight about whether mutt is good or bad. There is, to my knowledge, no alternative worth mentioning.

Mutt dates back well into the mid-nineties. As you might imagine, with lots of contributors over the course of almost two decades, the code quality is rather messy.

When development had stalled for quite a while in the mid-2000's, a fork was attempted. While mutt-ng was quite popular for a while, most changes were incorporated back into mainline mutt at some point. (Ironically, the latest article in the mutt-ng development blog is from October 2006 and is titled "mutt-ng isn't dead!"). The development of main mutt gained some momentum again, triggered in large parts by the contributions of late Rocco Rutte.

I remember two big features that the original mutt authors just wouldn't integrate into mainline: The headercache patch and the sidebar patch. About the former I can't say anything, but lately I've been fixing the Sidebar patch in various places. (We use mutt at work and rely heavily on e-mail communication, so we'd like a bug-free user agent, naturally.)

When all the mutt forking went about five years ago, I didn't know much about it. Retrospectively, I see the people did a hell of a job. Long before mutt-ng was forked, Sven told me he and Mika met in Graz for several weeks to sift and sort through the availbale patches, intending to do a "super patch".

Mutt's code quality is arguably rather messy.

On top of that, the Sidebar patch tries to make it even worse. Imagine this: mutt draws a mail from position (line=x,char=0) to the end of the line. Now the sidebar patch will introduce a left "margin", such that the sidebar can be drawn there. Thus, all code parts where a line is started from the leftmost character has to be rewritten to check if the sidebar is active and possibly start drawing at (line=x,char=20).

The sidebar code quality is a fringe case of bad code. Really, it sucks. However, there's no real way to "do it right", since original mutt never planned for a sidebar.

Who maintains the sidebar patch? – Not sure. There's a version at thomer.com, but he says:

July 20, 2006 I quit. Sadly, there seems to be no desire to absorb the sidebar patch into the main source tree.

The most up-to-date version is found at Lunar Linux. Last update is from mid-2009.

Debian offers a mutt-patched package that includes the sidebar patch, albeit in a different version than usually found 'round the net. In short, this patch is a mess, too.

But since I made all the fixes, I decided to contact the package's maintainer, Antonio Radici. He promptly responded and said he'd happily fix all the issues, so I started by opening two bug reports. Nothing has happened since.

The patches run quite stable for my colleagues, so I think it's best to release them. Maybe someone else can use them. Please note that I have absolutely no interest in taking over any Sidebar patch maintainance. ;-)

For some of the patches I provide annotations. They all feature quite descriptive commit messages, and apply cleanly on top of the Debian mutt repository's master branch.

The first four patches are not by me, they are just the corresponding patches from the debian/patches/ directory applied to have a starting point.

The first few patches fix rather trivial bugs.

Now come the performance critical patches. They are the real reason I was assigned the task to repair the sidebar:

This patch fixes a huge speed penalty. Previously, the sidebar would count the mails (and thus read through the whole mbox) every time that mtime > atime! This is just an incredible oversight by the developer and must have burned hundreds of millions of CPU cycles.

This introduces a member `sb_last_checked' to the BUFFY struct. It
will be set by `mh_buffy_update', `buffy_maildir_update' and
`buffy_mbox_update' when they count all the mails.

Mboxes only: `buffy_mbox_update' will not be run unless the
condition "sb_last_checked > mtime of the file" holds. This solves
a huge performance penalty you obtain with big mailboxes. The
`mx_open_mailbox' call with the M_PEEK flag will *reset* mtime and
atime to the values from before. Thus, you cannot rely on "mtime >
atime" to check whether or not to count new mail.

Also, don't count mail if the sidebar is not active:

Then, I removed a lot of cruft and simply stupid design. Just consider one of the functions I removed:

-static int quick_log10(int n)
-{
-        char string[32];
-        sprintf(string, "%d", n);
-        return strlen(string);
-}

That is just insane.

Now, customizing the sidebar format is simple, straight-forward and mutt-like:

sidebar_format

    Format string for the sidebar. The sequences `%N', `%F' and
    `%S' will be replaced by the number of new or flagged messages
    or the total size of the mailbox. `%B' will be replaced with
    the name of the mailbox. The `%!' sequence will be expanded to
    `!' if there is one flagged message; to `!!' if there are two
    flagged messages; and to `n!' for n flagged messages, n>2.

While investigating mutt's performance, one thing struck me: To decode a mail (eg. from Base64), mutt will create a temporary file and print the contents into it, later reading them back. This also happens for evaluating filters that determine coloring. For example,

color   index  black green  '~b Julius'

will highlight mail containg my name in the body in bright green (this is tremendously useful). However, for displaying a message in the index, it will be decoded to a temporary file and later read back. This is just insane, and clearly a sign that the mutt authors wouldn't bother with dynamic memory allocation.

By chance I found a glib-only function fmemopen(), "fmemopen, open_memstream, open_wmemstream - open memory as stream".

From the commit message:

When searching the header or body for strings and the
`thorough_search' option is set, a temp file was created, parsed,
and then unlinked again. This is now done in memory using glibc's
open_memstream() and fmemopen() if they are available.

This makes mutt respond much more rapidly.

Finally, there are some patches that fix various other issues, see commit message for details.

There you go. I appreciate any comments or further improvements.

Update 1: The original author contacted me. He told me he's written most of the code in a single sitting late at night. ;-)

Update 2: The 16th patch will make mutt crash when you compile it with -D_FORTIFY_SOURCE=2. There's a fix: 0020-use-PATH_MAX-instead-of-_POSIX_PATH_MAX-when-realpat.patch (thanks, Jakob!)

posted 2012-01-08 tagged mutt, linux and c

Bookdump

Ich habe erstaunlich wenig gelesen die letzten paar Monate. Außerdem habe ich zwei Bücher nicht zu Ende gelesen, was sonst gar nicht meine Art ist.

Die unfertigen Bücher: David Foster Wallace: The Pale King, war mir viel zu unklar und querbeet. Man muss sich vorstellen, dass jemand das Thema "Boredom" am Beispiel einer merkwürdigen Ansammlung von Steuereintreibern im Illinois der '70er Jahre veranschaulichen will. Und das Buch ist, nicht zuletzt aufgrund seiner Sprache, unglaublich schwer lesbar. Typisch DFW, nur nicht mitreißend. (Konstant lustig ist nur die Situationen, in die "David Wallace" aufgrund der Namensverwechslung gerät.) – Dann habe ich mir auf einer Zugfahrt große Teile von Michail Bulgakow: Der Meister und Margarita gegönnt. Aber über der Hälfte, und als sie Besen reitend noch immer Unsinn reden, habe ich das Buch wieder weg gelegt. Ich habe von dem Autor mehr erwartet, nachdem mir mehrere Leute von ihm vorgeschwärmt hatten.

Einen weiteren Roman habe ich von Bret Easton Ellis gelesen: Less than Zero. Der war wesentlich besser als "The Rules of Attraction": Einfach mehr, und bessere Dekadenz. – Auch von Irvin D. Yalom habe ich ein zweites Buch gelesen, nachdem mir "Und Nietzsche weinte" sehr, sehr gut gefallen hatte. (Der Film ist keinesfalls zu empfehlen.) Die Schopenhauer-Kur ist nicht historisch, dafür mit allerlei historischen Notizen gespickt. Ein schöner Roman.

Peter Seibel: Coders at Work ist ein schönes Buch: In 20 Interviews stellen sich Programmiergrößen wie Jamie Zawinsky und auch Donald Knuth einem ganzen Katalog von Fragen: Debuggen via Single-Stepping, oder doch lieber Quick'n'dirty-Print-Statements? Editor oder IDE? Was war der härteste Bug, den sie je behoben haben? – Alles in allem der wunderbare Beweis dafür, dass diese Leute auch nur Menschen sind, außerdem gibt es Gelegenheit, über das eigene Codeschreiben zu reflektieren, und eventuell gewisse Fallstricke bei der Projektplanung bei Anderen wie bei sich selbst aufzudecken.

(Ich habe dieses Buch als Anlass genommen, mir The Art of Computer Programming, Band 1, zu kaufen. Ob sie dieses Buch gelesen haben wurden nämlich auch fast alle gefragt. Durch den "harten, mathematischen Teil" bin ich schon gut durchgekommen, aber mit dem MIX-Teil habe ich erst ein bisschen begonnen.)

David Foster Wallace: Everything and More ist grandios. Es ist der erste Nicht-Roman, den ich von DFW gelesen habe. Im wesentlichen geht es um die Eigenschaften der reellen Zahlen, die einen Mathematikstudenten im ersten Semester in Analysis I tage-, wenn nicht sogar wochenlang beschäftigen: Wie kann es sein, dass es unendlich viele rationale Zahlen sind, sie aber 0% der reellen Zahlen ausmachen? Wie kann es verschiedene "Größen" von Unendlichkeit geben? – Das ganze bettet DFW liebevoll in einen historischen Kontext und mathematisch nicht ganz präzise, aber doch wunderbar verständliche, selbst erfundene Notation ein. Schon der Untertitel deutet einiges an Sprachwitz an: A Compact History of Infinity. Für Mathematikinteressierte definitiv zu empfehlen!

posted 2012-01-05 tagged bookdump

tmux session names

Usually, I name my tmux sessions according to what project I'm working on. To attach a specific session, I use a custom tm function, with the appropriate completion:

# 2011-10-19: tmux shortcut for creating/attaching named sessions
  tm() {
    [[ -z "$1" ]] && { echo "usage: tm <session>" >&2; return 1; }
    tmux has -t $1 && tmux attach -t $1 || tmux new -s $1
  }

# 2011-10-19
# stolen from completion function _tmux
  function __tmux-sessions() {
      local expl
      local -a sessions
      sessions=( ${${(f)"$(command tmux list-sessions)"}/:[ $'\t']##/:} )
      _describe -t sessions 'sessions' sessions "$@"
  }
  compdef __tmux-sessions tm

It looks like this:

A colleague use this, but with a modification. If [[ -z "$1" ]], he'll simply do a tmux attach, which will attach the last recently used session.

posted 2012-01-03 tagged tmux

Kindergeld ab jetzt einkommensunabhängig

Seit dem 1. Januar wird das Kindergeld unabhängig vom Einkommen des Kindes gewährt. Damit fällt die bisherige Grenze von 8.004 Euro pro Jahr weg.

Ich habe ja keine Ahnung von Jura und den Techniken von Juristen. Aber es sieht mir so aus, als ob da sehr, sehr wenig automatisiert wurde bisher. Als naiver, und (im positiven Sinne) fauler, technisch versierter Mensch, stelle ich mir das so vor:

Aber: denkste! Nach zehn Minuten Recherche bin ich in etwa so weit: Das "Steuervereinfachungsgesetz 2011" wurde am 19. Juni 2011 beschlossen, und im BGBl. I S. 2131 (Nr. 55) im Artikel 12 bekannt gegeben. (Das Original im PDF gibt es hier von bgbl.de.) Das liest sich so:

2. § 2 wird wie folgt geändert:

a) In Absatz 2 werden die Sätze 2 bis 10 durch die folgenden Sätze ersetzt:

„Nach Abschluss einer erstmaligen Berufsausbildung und eines Erststudiums wird ein Kind in den Fällen des Satzes 1 Nummer 2 nur berücksichtigt, wenn das Kind keiner Erwerbstätigkeit nachgeht. Eine Erwerbstätigkeit mit bis zu 20 Stunden regelmäßiger wöchentlicher Arbeitszeit, ein Ausbildungsdienstverhältnis oder ein geringfügiges Beschäftigungsverhältnis im Sinne der §§ 8 und 8a des Vierten Buches Sozialgesetzbuch sind unschädlich."

Ahh, gut, denke ich mir – und was stand denn ehemals in § 2, Abs. 2, Satz 2–10 BKGG? Jetzt steht da nämlich natürlich nur die neue Fassung!

Immerhin kann buzer.de schonmal alle Gesetze, die ein anderes Gesetz ändern, auflisten, also eine Art Versionshistorie: Änderungen am BKGG.

Leider kann man aber nicht einfach die vorherige Version via der Wayback Machine aufrufen, denn die robots.txt von bauzer.de liest sich u.a. so:

User-agent: ia_archiver
Disallow: /

Großartig. Justlaw.de haben genau den gleichen Eintrag. Dejure.de ist nur zweimal in 2006 archiviert worden, das hilft auch nicht wirklich.

Wie komme ich nun an ein Text-Diff? Unter recht-in.de gibt es prinzipiell die Möglichkeit, eine alte Version abzurufen, nur leider wurden aufgrund der Beendigung der Kooperation mit der Rechtsdatenbank

[w]ie bereits angekündigt ... alle Urteile, Gesetze und Kommentare von recht-in.de entfernt. Wir bedanken uns für das entgegengebrachte Vertrauen.

Dang!

Durch Zufall stoße ich auf lexetius.com, und da gibt es genau das, was ich brauche, zum Beispiel hier die Gegenüberstellung der alten und neuen Version des PfandBG – leider nur ist das BKGG nicht aufgeführt. Der Mensch, der das gemacht hat, wurde anscheinend auch für einen Preis auf dem EDV-Gerichtstag 2009 nominiert. Wonach ich also suche, ist ein Gesetz in "historisch-synoptischer Edition". Sowas gibt es für das BGB auch als PDF, von dem Autor von lexetius.com.

Und endlich, schließlich, nach über vierzig Minuten Recherche und mit dem neuen Stichwort "synoptisch" bzw. "Synopse" lande ich via Google(!), weil ich das Nutzerinterface zunächst nicht kapiert hatte, wieder bei buzer.de. Dort sieht die Gesetzesänderung so aus (Link hinter dem Bild geht zur Seite):

Wow. Diese Seite muss ich mir wirklich merken!

Was habe ich gelernt? – Auch wenn ich es niemals vorhatte, merke ich doch, wie richtig es war, nicht Jura zu studieren. Und ich muss mir dieses Jahr keine Sorgen um eventuelle Kindergeldrückzahlungen machen.

posted 2012-01-03 tagged life and recht

Happy New Year!

I started this blog exactly one year ago. Over the course of this year, I wrote 105 articles. That is not really much, and I want to write more – just about the stuff that's on my mind. So stay tuned. ;-)

Usage statistics for
blog.plenz.com

A Happy New Year to all my readers!

posted 2011-12-31 tagged life and blog

28C3, Tag 3 und 4

Ich war ehrlich gesagt die letzten beiden Tage nicht im bcc, sondern habe nur von zu Hause Streams geschaut. Den letzten Congress über war ich komplett beschäftigt, hatte immer was zu tun, bin zu nichts gekommen – und dieses Jahr sind so gut wie alle Leute, die ich sonst immer dort getroffen habe, nicht da gewesen. Die Atmosphäre ware gefühlt nicht so nett wie noch die vergangenen Jahre.

Die Bitcoin-Analyse war nett und aufschlussreich. Aber auch hier gab es direkt Contra im Publikum und vor allem im IRC – ich weiß da nie so recht, was man glauben soll. Interessant, dass sie den Fakt gebracht haben, dass Rick Falkvinge seine Altersvorsorge in BTC angelegt hat.

Der "Cellular protocol stacks for Internet"-Talk war sicherlich aufschlussreich, wenn man durch die ganzen Akronyme durchgestiegen ist. Ich habe nichts verstanden.

"The Hack will not be televised?" war eine nette Kollektion von Filmen, von denen ich einige auch noch nicht gesehen hatte. Der Fnord-Jahresrückblick war ganz nett.

Ich habe mir extra den Wecker gestellt, um nach nur fünf Stunden Schlaf für den Talk um 13:30 aufzustehen, "bup: Git for backups". Leider gab es keine Demo, und nur wenige Informationen, die über das Lesen der Doku hinausgingen.

posted 2011-12-30 tagged ccc

Old DVDs and mplayer

I was just watching an old DVD of mine (from 2003), but was annoyed that the video had "hardcoded" black bars at the top and the bottom and was in interlaced format. A fast motion looks like this:

In motion, no deinterlacing, boders

But mplayer can do everything! You just need to know how. Here it is: Use the cropdetect video filter, skip to the actual video and let it run for a while (it will detect the black areas that don't change). Then copy the output:

$ mplayer -vf cropdetect dvd://
...
[CROP] Crop area: X: 5..717  Y: 57..421  (-vf crop=704:352:10:64).

Now, play the movie in 4:3 aspect racio, and force cropping at the numbers you just found out. Additionally, use the yadif deinterlacer:

$ mplayer -aspect 4:3 -vf yadif,crop=704:352:10:64 dvd://

Now the same scene (with heavy motion) looks much nicer:

In motion, deinterlacing, boders cropped

posted 2011-12-29 tagged mplayer

28C3, Tag 2

Heute nicht so viele Talks geschaut. "Reverse-engineering a Qualcomm baseband" war irgendwie verdammt cool – einen GDB an den Debug-Port eines USB-3G-Adapters anschließen und allerlei Disassembly-Magie betreiebn – aber leider (sprachlich) schwer zu verstehen.

Der Nachfolgende Talk, "Post Memory Corruption Memory Analysis", hatte unglaubliches Potenzial. Den Menschen hätte man mal zwei Stunden lange reden lassen sollen. Leider konnte er nur einen kleinen Teil seiner 90 Folien zeigen, und war glaube ich von der ziemlich unwissenden Audienz ein wenig geschockt. Ist nunmal nicht die Blackhat.

Ich habe mich das erste Mal mit PIE außerhalb von -fPIC auseinandergesetzt, was ja im ersten Moment nicht schlecht klingt. Sein Exploit habe ich nicht so 100% verstanden. Die Technik aber ist super-elegant: Einfach den Prozess einhundert Mal wegforken, überprüfen, wo die Adressen anlaufen, und daraus eine höchstwahrscheinliche Stelle finden. Simpel, aber scheint gut zu funktionieren.

posted 2011-12-29 tagged ccc

Abschreiben

Erst dachte ich, dass ich einfach bloß vergessen hätte, dass ich heute schon die taz gelesen hatte. Der komplette Artikel inklusive diverser Formulierungn kam mir bekannt vor. Aber dann habe ich nochmal nachgeschaut, und der Artikel "Liebesaffäre" mit Diktatoren (taz) und "Liebesaffäre zwischen westlichen Technologie-Unternehmen und Diktatoren" (Zeit online) ist in vielen Teilen fast im Wortlaut gleich. Einzelne Sätze sind korrigiert bzw. hinzugefügt.

Ehrlich? Liefert die DPA so gut vorstrukturierte Artikel, dass man da nur noch einen Absatz reinfüllen muss, und das als "eigenes" verkaufen kann?

posted 2011-12-28 tagged media and ccc

28C3, Tag 1

Die Rechnung "Lange schlafen und Keynote mit Laptop im Bett gucken" ging nichtso ganz auf: Das Netz im bcc war flaky und deshalb kamen die FEM-Streams nicht aus dem Gebäude heraus. Dafür in Ruhe geduscht. Der nachfolgende Talk von Anne Roths war interessant – ich hatte die wesentlichen Aspekte der Dresden-Affäre gar nicht so wirklich mitbekommen.

Der Vortrag über die Sicherheit von Eisenbahnnlagen war interessant und unheimlich zugleich. Bei auf physikalischem Kontakt oder simplen Induktionen basierenden Notbremssystemen haben Saboteure auf offener Strecke ja wirklich ein leichtes Spiel. (Sidefact: Dass Sitzplatzreservierungen in den ICEs immer noch per Diskette eingespielt werden lässt auch ein bisschen erahnen, wie "modern" die Technik der Bahn bisweilen ist.)

Die Talks hatte ich von zu Hause mit den mittlerweile funktionierenden Streams geguckt. Dann wollte ich schnell ins bcc los, um einen Platz in Saal 1 zu finden. Hat leider nicht geklappt.

Daraufhin saß ich für den zweiten Part der Talks auf Ebene A mit Kabelnetz und habe weiter Streams geschaut. Den Staatstrojaner-Talk habe ich nur teilweise gehört, den Großteil der Details hatte ich aber auch schon in der Entstehung verfolgt, von daher nicht viel neues.

Travis' Talk über PIP-Exploits war hingegen äußerst interessant. Schaut euch den am besten selbst an (z.B. beim FEM-On-Demand-Stream). Die wesentliche Idee, die man im Hinterkopf behalten sollte: Man kann prinzipiell, und wenn man genügend Bandbreite hat, Radio-Frames ohne Radio-Equipment verschicken – also IP-Pakete schicken, die mit gewisser Wahrscheinlichkeit als andere Pakete aufgefasst werden, wenn Sie über Wireless-Equipment an den Empfänger geschickt werden. Das ganze ist standards-compliant und ist ein (OSI-)Level-1-Exploit. Beeindruckend.

In der Pause habe ich mir einen Sitzplatz organisiert in Saal 1. Der anschließende Talk, The coming war on general computation, war nicht neu, aber rhetorisch sehr gut (ohne Slides). Ich habe allerdings nur mit halbem Ohr zugehört. Zum Glück gibt es solche Leute, die sich mit lernresistenten Politikern und Lobbyisten herumschlagen.

Bei Karsten Nohls Talk konnte man schon im Voraus davon ausgehen, dass etwas beeindruckendes präsentiert werden würde. Das war dann auch so. Wie bei den beiden vorherigen Talks gilt wieder: Dringend anschauen, und sich im Klaren darüber sein, dass GSM im wesentlichen kaputt ist. Oh, und: In Zukunft die Handyrechnung mal genauer untersuchen, wenn sie erstaunlich hoch ist. ;-)

Danach kam Dan Kaminskys "Black Ops of TCP/IP 2011". Dan hat häufig interessante Ideen aber hat irgendwie weder primärquellen oder veröffentlicht Resultate so, dass sie auffindbar oder nachvollziehbar wären. (Eine Ausnahme, die mir einfällt, ist das DNS-Tunneling-Tool OzymanDNS.) Der Talk ging zunächst um BitCoins, an denen er eineige mehr oder weniger interessante und geeky-lustige Feststellungen machte. Schließlich kam er dann doch noch auf TCP/IP zu sprechen, um später auch noch etwas zu Net-neutrality/QoS zu erzählen. Interessante Anregungen – aber irgendwie nicht so wirklich aufschlussreich. Dazu kommt, dass er schnell redet und gleichzeitig andere Infos auf den überfüllten Slides stehen hat. Eins zur Zeit geht, beides nicht...

Die nachfolgende Pentanews Game Show war gefühlt schlechter und schlechter programmiert (vom Interface her) als letztes Mal.

Ich habe merkwürdige Probleme mit dem WLAN beim Congress. Ich führe das momentan darauf zurück, dass es mehrere APs mit der gleichen ESSID gibt, und natürlich ein beträchtliches Noise-Level herrscht. Das Problem tritt ortsunabhängig und sowohl auf 5Ghz und 2.4Ghz auf, und liest sich im Log wie folgt:

[86969.683316] wlan0: authenticate with b4:a4:e3:64:8d:cd (try 1)
[86969.684909] wlan0: authenticated
[86969.685164] wlan0: associate with b4:a4:e3:64:8d:cd (try 1)
[86969.688341] wlan0: RX AssocResp from b4:a4:e3:64:8d:cd (capab=0x1 status=0 aid=25)
[86969.688351] wlan0: associated
[86996.951510] wlan0: deauthenticating from b4:a4:e3:64:8d:cd by local choice (reason=2)

Man beachte die 27 Sekunden, die zwischen Association und Deassociation liegen. Manchmal ist auch reason=3. Ich habe diverse Optionen für das iwlagn-Modul ausprobiert, um das Problem zu lösen (u.a. 11n_disable=1 und swcrypto=1), allerdings ohne Erfolg. Wenn ich allerdings nicht via iwconfig arbeite, dann geht es: Ich habe das erste Mal wicd installiert und benutzt, und damit funktioniert das WLAN wunderbar. Keine Idee, warum.

posted 2011-12-28 tagged ccc

sed and jekyll tags

Did you know the -s switch to sed? I had the strange effect that operating on several files produced different results between when I called sed repeatedly in a for loop and passing all the files as arguments just once. – -s tells sed not to consider all files to be one big stream, but to separate them from each other.

Anyway, here's a script that searches all the posts now and gives me numbers on the tags I already used.

#!/bin/sh

sed -s -n '
    /---/,/---/ {
        /tags:/ {
            s/^tags: \[//;
            s/\]$//;
            s/, */\n/g;
            p
        }
    }' ~/blog/_posts/*.markdown | sort | uniq -c | sort -n

posted 2011-12-27 tagged sh and sed

28C3

28C3 propaganda sticker I'll be at the 28th Chaos Communication Congress the next few days. If you are there, too, write me an email or text me.

I haven't throughly looked at the Fahrplan yet. But there are some classics there already, for example Dan Kaminsky, the Fnord News Show or a new Neusprech talk by maha.

Some other talks seem promising: Deceiving Authorship Detection will unveil two tools for detecting and obfuscating authorship patterns; The future of cryptology: which 3 letters algorithm(s) could be our Titanic? also sounds cool.

I was surprised to see a talk about "bup". Usually, the Congress has a very un-techy focus. To outsiders this might sound strange, but it's mainly about ideas, not so much about technology of the status quo. Talk topics normally include "What if X happens?" (where X is in: internet lockdown, censorship, Aliens arrive, ...), "How can we hack X?" (X being: CCTVs, mobile devices, our government, ...), "How we hacked X" (where X might just be your occasional airport access control badges system).

Anyway, I hope I'll have some time to play around with stuff I had on my mind for some time now.

Preparation for tomorrow's Keynote: Evgeny Morozov's TED talk.


posted 2011-12-27 tagged life and ccc

Fotos

Mein Bruder interessiert sich seit einiger Zeit sehr für Fotografie und macht wirklich gute Bilder. Die folgenden Fotos von mir hat er über die Feiertage gemacht:

posted 2011-12-27 tagged life

git grep

Mit Axel und Frank kam ich auf Gits eigenes grep zu sprechen. Warum wird die Funktionalität da gedoppelt und neu programmiert?

Ein Auszug meiner Antwortmail an die beiden, für das Blog mit Links angereichert:

Im wesentlichen leistet git-grep das gleiche wie grep auf allen verwalteten Dateien. ABER es ist, und das war m.E. die Hauptmotivation dahinter, es überhaupt zu schreiben, viel schneller als reguläres grep. (Und reguläres grep zu schlagen ist ja bekanntermaßen schon schwer.)

Zum Beispiel, wenn man im Kernel-Tree greppt. (Alle Kommandos mehrfach ausgeführt, so dass der Cache voll ist.)

$ time grep foo -- **/*.c NO
grep foo -- **/*.c &>| /dev/null  17.67s user 0.22s system 99% cpu 17.928 total

$ time git grep foo -- **/*.c NO
git grep foo -- **/*.c &>| /dev/null  6.17s user 0.31s system 109% cpu 5.888 total

Viel beeindruckender wird es noch, wenn man für git-grep das Globbing-Muster erst gar nicht angibt.

$ time git grep foo NO
git grep foo &>| /dev/null  0.66s user 0.30s system 342% cpu 0.281 total

Oder alternativ ein Globbing-Muster angibt, das aber nicht erst von der Shell expandieren lässt:

$ time git grep foo -- '*.c' NO
git grep foo -- '*.c' &>| /dev/null  0.46s user 0.16s system 300% cpu 0.208 total

Also noch mal zusammengefasst: Wenn ich in allen C-Dateien nach "foo" greppe, bin ich mit der Git-Version auf meinem System 17.9/0.208 = 86.05 mal so schnell wie reguläres grep. Anders ausgedrückt: Das eine Kommando dauert, das andere ist fast "sofort da".

Wie das geht? Im wesentlichen ist das auf Multithreading zurückzuführen. (Sieht man ja auch an den CPU-Zahlen: grep bei ca. 100% = eine CPU, git-grep bei >300% = drei CPUs.)

Im Mutltithreading-Modus von git-grep gibt es den Haupt-Thread, der einfach alle Blobs einsammelt, die überprüft werden sollen, und die an acht Threads weitergibt, die dann entsprechend asynchron die Matches durchschauen können, aber trozdem alles in einer sinnvollen Reihenfolge ausgeben. (Details: builtin/grep.c)

posted 2011-12-22 tagged git and oneliners

X220's UMTS card

I've been toying around with the UMTS module in my X220 lately. I got a pre-paid SIM from blau.de, who offer 24h UMTS flatrates for 2,40 EUR. (This is probably my use case: Being somewhere without internet access for a day or two. This only happens so often, so I don't want a "real" flat.)

My UMTS card is manufactured by Sony Ericsson and connected via internal USB:

$ lsusb -v -s 004:003
    ...
    idVendor           0x0bdb Ericsson Business Mobile Networks BV
    idProduct          0x1911

The installation is easy: Just insert the SIM card behind the battery as shown here. Add yourself to the dialout group, log in again, and you're set.

You can first connect to your device using chat or picocom (which you can be terminated via C-a C-x). To ask if you can use the SIM without PIN, send the AT+CPIN? command:

$ picocom /dev/ttyACM0
...
AT+CPIN?
+CPIN: READY

If you're not ready to go, I would disable the PIN request using a regular phone. (I did.)

Dialling out is easy. I set up two profiles in the /etc/wvdial.conf that allow me to switch between "pay per megabyte" and "dayflat":

[Dialer blau]
Modem = /dev/ttyACM0
Init1 = AT+CGDCONT=1,"IP","internet.eplus.de"
Stupid mode = 1
phone= *99#
Username = blau
Password = blau

[Dialer tagesflat]
Modem = /dev/ttyACM0
Init1 = AT+CGDCONT=1,"IP","tagesflat.eplus.de"
Stupid mode = 1
phone= *99#
Username = blau
Password = blau

The rest happens automatically, once you invoke wvdial blau or wvdial tagesflat. (Note you have to execute these with root privileges because they want to modify pppd-related config files.) Most probably you want the follow-up command route add default dev ppp0 to route all traffic via the ppp0 interface.

In a test run I got a downstream speed of 190KB/s (city perimeter). Working over SSH is not painful at all.

I also played around with gammu a little bit.

$ gammu --identify
Device               : /dev/ttyACM0
Manufacturer         : Lenovo
Model                : unknown (F5521gw)
Firmware             : R2A07

The Wammu interface is nice, it can even receive SMS. But sending SMSes failed so far:

$ echo "Das ist ein Test" | gammu --debug textall --debug-file /tmp/gammu \
    sendsms TEXT +491785542342
...
1 "AT+CMGS=28"
2 "> 079194710716000011000C919471584532240000FF10C4F01C949ED341E5B41B442DCFE9^Z"
3 "+CMS ERROR: 500"

... which is somewhat of an "generic error". Maybe sending SMS is not supported at all. I'll look into that later.

Also, I'll have a look whether my Card supports GPS information retrieval. Thinkwiki claims a similar model does this. Interesting.

Update: Actually, I forgot one thing. I keep the following two entries in my /etc/wvdial.conf:

[Dialer on]
Modem = /dev/ttyACM0
Init1 = AT+CFUN=1

[Dialer off]
Modem = /dev/ttyACM0
Init1 = AT+CFUN=4

The actual sequence is now: wvdial on && wvdial blau. The AT+CFUN=1 will active the radio equipment, which is necessary. And, suddenly, also SMS delivery works! :-)

posted 2011-12-22 tagged x220, umts and linux

New X220

I got a brand new Thinkpad X220 on thursday. I'm not much into hardware, I think it should mainly work. I have a model with 4 GB of RAM, an i7 at 2.7 GHz, UMTS preinstalled, SSD instead of a HDD and an IPS panel. It's a really nifty thing.

Paying the extra money for the SSD is totally worth it. Everything happens instantaneous. The bootup process is down to five seconds. The IPS panel is really worth it, too. ThinkPads have long been criticized for their bad displays – with the new panel at full brightness, my regular screen looks really dim and grey...

The Debian netinstall works smoothly. I haven't come around to testing all the stuff like the DisplayPort connectors, Bluetooth, UMTS, USB 3.0. But the usual stuff works out of the box.

However, there are major problems with the power management of both the graphics card and the whole system, the latter one being a regression in the recent 3.0 and 3.1 kernel series regarding ASPM. Currently I'm using the 3.1.0-1-amd64 kernel with the pcie_aspm=force boot parameter. I cannot really see a difference in power consumtion when varying this parameter, though.

A major thing, however, is re-enabling the RC6 mode of the graphics chip. This alone saves more than 4W when the computer is in an idle state. My /etc/modprobe.d/i915-kms.conf looks like this now:

options i915 modeset=1
options i915 i915_enable_rc6=1
options i915 i915_enable_fbc=1
options i915 lvds_downclock=1

Suspend/resume works fine, no flickering effects. I use the following command to find out the current power consumption:

while sleep 1; do
    awk '{printf"%.2f\n",$1/-1000}' < /sys/devices/platform/smapi/BAT0/power_now;
done

This requires the tp_smapi kernel module to be loaded. With full brightness (0) and while writing this blog article, the consumption is at ~12W; with medium brightness (8) it's ~8.5W; at the lowest brightness (15) it's ~8W; With the display completely turned off, it's ~6.5W. There are people who claim they only have an ~5.4 power consumption. If you have any other hints on this or if you own an X220 yourself, I'd be interested in the details.

posted 2011-12-10 tagged x220 and linux