Various fixes to use more C++11 features

As we already use C++11 lambdas, we should also use foreach and std::string.
Well, the old code has an artificial limit of 512 chars. Granted, it's probably "big enough for everybody" (especially in the current incarnation, as there is no code path that calls `restart_service()` with a longer string than would fit), but given that the required size could be calculated upfront (`strlen()` of name + the size of the prefix/suffix + `\0` terminator) or even just using `asprintf()`, there's no need for having that limitation and then checking for the error condition (buffer is too small).