Fedora does not resolve hosts after upgrading from Fedora 23 to 24

My system was not able to resolve any hosts anymore. Basically it did ignore the DNS resolver passed by DHCP (over wifi, but shouldn’t matter). Resolving indicating directly a DNS server like worked fine.

Looks like something broke with connman. Easy fix was to delete the symlink /etc/resolv.conf which pointed into the nirvana and restart the NetworkManager.

For the lazy (check first if resolv.conf is in fact a dangling symlink):
sudo rm /etc/resolv.conf
sudo servicectl restart NetworkManager
cat /etc/resolv.conf

Good readings

As usual the quality of content on the net varies a lot. So I’ll put a few links here of technical blogs I really enjoy and think they are of good quality.

C99: func() or func(void)?

While reviewing code I came across a change set which read like this:

- void super_duper_func () {
+ void super_duper_func (void) {

I was puzzled, what’s the difference anyway except from making it explicitly clear that there are no parameter expected? Well, I was wrong. The ISO 9899 standard (read: C99 standard) states under paragraph ‘ Function declarators (including prototypes)’ that

10 — The special case of an unnamed parameter of type void as the only item in the list specifies that the function has no parameters.
14 — An identifier list declares only the identifiers of the parameters of the function. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the
parameters is supplied.

Therefore we can conclude that even though your code may compile and work correctly, your code is not standard compliant and you may even leap a compile time error detection. Have a look a this snippet which compiled flawless with clang 3.4:


void func();

int main() {
    return 0;

void func() {
    printf("in func()n");

Though when you turn on all warnings in clang you will get a warning but this is easily overlooked and not very obvious:

$ clang -std=c99 -Weverything -o empty_param_list empty_param_list.c
empty_param_list.c:10:6: warning: no previous prototype for function 'func' [-Wmissing-prototypes]
void func() {
empty_param_list.c:3:6: note: this declaration is not a prototype; add 'void' to make it a prototype for a zero-parameter function
void func();
1 warning generated.

If you go through the code you will find a function prototype and you may think that if there was no previous prototype and the function is defined later than ‘main’ the compiler will fail anyway … In this case if you forgot the function prototype the compiler would throw an error (conflicting types for ‘func’) even if you passed no arguments.

To sum it up:

  • Create function prototypes/declarations (they go before the first function definition in your source)
  • If you don’t need any parameters explicitly write void in the parameter list (helps you with finding mistakes)
  • Turn on all warnings with either ‘-Wall’ (gcc) or ‘-Weverything’ (clang) and don’t ignore those warnings!

Where does ‘const’ go in C++

A word of warning at the beginning: This post is about C++, not about C and I will not explain the basics of pointer arithmetics! So whatever you read here may not necessarily apply to C. Nevertheless you may have a look Sugih’s page which features are in C.


While writing C++11 code I was faced with the task of passing variables to functions which will not alter these. Or pure getter methods. And after reading a post about C++ constness I was left with more questions than really understanding. A quick search revealed thorough FAQ about const usage in C++. Here I’d like to make a short round-up of it.

How to read const

First of all, read it from right-to-left. For instance int const* const p would be read as “p is a constant pointer to a constant int”.

A few examples

string const& s

Let’s say you read something like this:

void MyClass::func (std::string const& s);

So reading from right-to-left this would say “s is reference to a constant std::string”. This implies that func is not going to modify s. But keep in mind that you may have a dangling reference here, especially if you work with multi-threaded code. If this would be a pointer instead of a reference it is still possible the pointer to be NULL.

string* const s

void MyClass::func (std::string* const s);

Again, read from right-to-left: “s is a constant pointer to a string”. s may be modified (the object itself) but s may not point to a different object. As you may have already noticed it’s not that hard to read when you stick to the “read from right-to-left” rule.

string const* const s

void MyClass::func (std::string const* const s);

This would read “s is a constant pointer to a constant string” and therefore the function guarantees (respectively the compiler enforces it) that the content of s may not be changed nor may s point to a different object.

string const& const s

A signature as followed

void MyClass::func (std::string const& const s);

is non-sense in term of that references can never be re-assigned and therefore is redundant.

Similar consts

Obviously some signatures mean the same thing:

void MyClass::func (const std::string& s); // you may know this from C
void MyClass::func (std::string const& s);

void MyClass::func (const std::string* s);
void MyClass::func (std::string const* s); // equivalent
void MyClass::func (std::string* const s); // Pitfall: NOT equivalent

Now, it doesn’t matter which version you use but is more a decision you have to make. If previously written code opts for one variant you should for the sake of consistency use the same way. But if you want to use the handy right-to-left rule you may consider the first variant, which in my personal opinion is better for beginners.

Methods that do not change its object

When you write a pure getter method you may want to tell your compiler that the following code may not change the object itself.

std::string const& MyClass::func () const;

The last const indicates that this function may not alter its objects data.

Advanced constness

The mutable keyword

Let’s say that you want to count how many times your getter method was called but you want to declare your method to be const. How would you do that? Well, that’s how it would work:

#include <iostream>

class MyClass
    std::string s;
    mutable int count;
    std::string const& get_string() const;
    int get_count();

MyClass::MyClass () {
    s = "Hello World!";
    count = 0;

MyClass::~MyClass () {}

std::string const& MyClass::get_string() const {
    return s;

int MyClass::get_count() {
    return count;

int main () {
    MyClass o;
    for (int i = 0; i < 5; ++i)
        std::cout << "\"" << o.get_string() << "\"" << 
            " was accessed " << o.get_count() << " times." << std::endl;

    exit (0);

Which executed does this:

$ ./mutable 
"Hello World!" was accessed 1 times.
"Hello World!" was accessed 2 times.
"Hello World!" was accessed 3 times.
"Hello World!" was accessed 4 times.
"Hello World!" was accessed 5 times.

One more thing: MyClass** → MyClass const**

There is one more thing which is hard to understand and Marshall Cline does a better job at explaining it than I will ever be able to do: Why am I getting an error converting a Foo** → Foo const**?

Final words

A big thank you to Marshall Cline which is a master mind in explaining complex things! And also thank all these people who I bothered so much while writing code.

git send-email: Can’t locate Net/SMTP/SSL.pm

While trying to send a patch with git (installed over macports) over GMail I came across the following error on Mac OS X 10.8:

Can't locate Net/SMTP/SSL.pm in @INC (@INC contains: /usr/../Library/Perl/5.12/darwin-
thread-multi-2level /usr/share/git-core/perl /Library/Perl/5.12/darwin-thread-multi-2l
evel /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network
/Library/Perl/5.12 /Library/Perl/Updates/5.12.4 /System/Library/Perl/5.12/darwin-threa
d-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-threa
d-multi-2level /System/Library/Perl/Extras/5.12 .) at /usr/libexec/git-core/git-send-e
mail line 1124.

Which also seems to be the problem filed in the macports bugtracker.

The solution however is pretty easy — except if you don’t read like I did — and requires you just a few commands:

$ sudo port install p5.12-net-smtp-ssl
$ sudo mkdir -p /usr/share/git-core/perl/Net/SMTP
$ sudo ln /opt/local/lib/perl5/vendor_perl/5.12.4/Net/SMTP/SSL.pm \

And suddenly: It works!

(Mis-)Using void* to pass arbitrary arguments

I came across the situation where I need to call a function passing a callback function and possible arguments for the callback function:

zthread_fork (zctx_t *ctx, zthread_attached_fn *thread_fn, void *args);

(from czmq)

Later my thread_fn will be called and args passed to it. And now I had to pass more than one argument to it. After hours of trying getting my head around it (and using an array of pointer) with a lot of help I came to a working example:

#include <stdio.h>

struct params_t
    void (*func)(int*);
    int* i;

void bla (int *i)
    printf("%dn", *i);

void bar (void *args)
   struct params_t *argstruct = (struct params_t*) args;
   void (*func)(int *) = argstruct->func;
   int *num = argstruct->i;
int main ()
    // Function pointer of bla()
    int b = 100;
    // Put both variables into the struct
    struct params_t args;
    args.func = &bla;
    args.i = &b;
    return 0;

Bear in mind that this only works if you are in the process and thread, it may work with different threads but no one can guarantee the other thread still exists.

urxvt clickable links with ctrl-click

Today some friends and I messed around with urxvt and we wondered how we could make urxvt launch URLs with not only a simple mouse click, but with ctrl-click. Well, I had to dig around in the source code for this:

sub on_start {
   my ($self) = @_;

   $self->{launcher} = $self->my_resource ("launcher") || $self->x_resource("url-launcher") || "sensible-browser";

   $self->{urls} = [];
   $self->{showing} = 0;
   $self->{button}  = 2;
   $self->{state}   = 0;
   if($self->{argv}[0] || $self->my_resource ("button")) {
      my @mods = split '', $self->{argv}[0] || $self->my_resource ("button");
      for my $mod (@mods) {
         if($mod =~ /^d+$/) {
            $self->{button} = $mod;
         } elsif($mod eq "C") {
            $self->{state} |= urxvt::ControlMask;
         } elsif($mod eq "S") {
            $self->{state} |= urxvt::ShiftMask;
         } elsif($mod eq "M") {
            $self->{state} |= $self->ModMetaMask;
         } elsif($mod ne "-" && $mod ne " ") {
            warn("$mod is invalid in $self->{_name}<$self->{argv}[0]>n");

(from http://cvs.schmorp.de/rxvt-unicode/src/perl/matcher?revision=1.13&view=markup#l188)

Basically it would split the input from URxvt.matcher.button and set different settings. So to enable ctrl-click you have to pre- or postpend a capital C, S for shift and M for the meta-key. My config now looks like this:

! ~.Xresources
URxvt.perl-ext-common:  default,matcher
URxvt.url-launcher:     /opt/google/chrome/google-chrome
URxvt.matcher.button:   C1