0

I've built an uninstaller that call helper executable with elevated permissions to remove my driver's launchd-plist, so that it won't come up again on the next boot cycle.

In order reflect the new stage of /Library/LaunchDaemons, I invalidate the kextcache using the following command touch /Library/Extensions/ showed in this question.

However, when I do so from the helper executable right after the plist file was removed, it wouldn't succeed, and my driver still go up after reboot. When I do it manually by typing the command touch /Library/Extensions right after the uninstaller helper finish, it does the trick.

here's how my code looks like in the first option (invalidate from the helper exec).

        remove(OSX_LAUNCHD_PLIST_PATH);
        pid_t pid = -1;
        char const * args[] = {"touch", "/Library/Extensions", NULL};
        posix_spawn(&pid, "/usr/bin/touch", NULL, NULL, (char **)args, NULL);
        waitpid(pid, &status, WNOHANG|WUNTRACED);

perhaps you could tell me why do I get different behaviour in each of the options.

UPDATE:

it seems like the cache invalidation requires to repeat this command more than once. This code worked to me, but i don't have a clue why ...

        for (int x=0 ; x < 2; x++ ) {
            char const * args[] = {"touch", "/Library/Extensions", NULL};
            posix_spawn(&pid, "/usr/bin/touch", NULL, NULL, (char **)args, NULL);
            waitpid(pid, &status, WNOHANG|WUNTRACED);
            char const * args2[] = {"touch", "/System/Library/Extensions", NULL};
            posix_spawn(&pid, "/usr/bin/touch", NULL, NULL, (char **)args2, NULL);
            waitpid(pid, &status, WNOHANG|WUNTRACED);
        }
Community
  • 1
  • 1
Zohar81
  • 4,554
  • 5
  • 29
  • 82
  • There can be a timing issue with the kext cache invalidation. If you touch /LE or /SLE while the kext cache is being rebuilt, it won't be rebuilt again. So for example if you have 2 kexts in /LE, and you delete one, this will trigger a rebuild, and if you then delete another kext after that one has already been included in the cache, but the cache is still being rebuilt, it won't be rebuilt again on completion. – pmdj Sep 07 '16 at 13:56
  • thanks for replying, Is there a way to ensure kextcache invalidation before the next boot cycle, beside trying to invalidate many times and hope that one will be caught... – Zohar81 Sep 07 '16 at 14:25
  • furthermore, is there a way to check what is the cache status. It would be great if i can detect when the cache wasn't properly invalidated. – Zohar81 Sep 07 '16 at 14:41

0 Answers0