kern_return_t OsqueryStop(kmod_info_t *ki, void *d) { dbg_printf("Kernel module stopping!\n"); // Only stop if there are no connected daemons. lck_mtx_lock(osquery.mtx); if (osquery.open_count > 0) { lck_mtx_unlock(osquery.mtx); return KERN_FAILURE; } // Stop sharing the queue and remove queue locks. // This will potentially block as heuristics are applied to make sure the // queue is no longer is use. if (osquery_cqueue_teardown(&osquery.cqueue)) { lck_mtx_unlock(osquery.mtx); return KERN_FAILURE; } // Remove the device node. devfs_remove(osquery.devfs); osquery.devfs = NULL; // Tear down the device node data. if (cdevsw_remove(osquery.major_number, &osquery_cdevsw) < 0) { panic("osquery kext: Cannot remove osquery from cdevsw"); } // Deallocate the IOCTL and kernel API locks. lck_mtx_unlock(osquery.mtx); teardown_locks(); return KERN_SUCCESS; }
kern_return_t OsqueryStop(kmod_info_t *ki, void *d) { dbg_printf("Kernel module stoping!\n"); lck_mtx_lock(osquery.mtx); if (osquery.open_count > 0) { lck_mtx_unlock(osquery.mtx); return KERN_FAILURE; } if (osquery_cqueue_teardown(&osquery.cqueue)) { lck_mtx_unlock(osquery.mtx); return KERN_FAILURE; } devfs_remove(osquery.devfs); osquery.devfs = NULL; if (cdevsw_remove(osquery.major_number, &osquery_cdevsw) < 0) { panic("osquery kext: Cannot remove osquery from cdevsw"); } lck_mtx_unlock(osquery.mtx); teardown_locks(); return KERN_SUCCESS; }