Use strtok_r for thread-safety

Signed-off-by: Sebastian Ramacher <sramacher@debian.org>
Make default_device thread-local

Signed-off-by: Sebastian Ramacher <sramacher@debian.org>
Name the define THREAD_LOCAL and define it in every case

Signed-off-by: Sebastian Ramacher <sramacher@debian.org>