Could this perhaps just test if LD_PRELOAD contains "libumockdev-preload"? That sounds a bit cheaper.

Also/alternatively, this should have a static boolean to cache the result, as it will be called quite often.