Re: Unloading a KEXT with Client still connected
Re: Unloading a KEXT with Client still connected
- Subject: Re: Unloading a KEXT with Client still connected
- From: Allan Hoeltje <email@hidden>
- Date: Wed, 13 Jul 2005 15:47:37 -0700
Thank you all for responding:
> Can it be possible to rethink the issue and wonder if instead, you
> could not just prevent the kext from being unloaded when the client is
> connected?
> Your kext can, and probably should, refuse to unload if there are
> connections open.
> Can you better outline what type of KEXT this is? What IOKit family,
> etc. are you based on?
>
> The answer can depend on family / type of KEXT (but also listen to
> what other have already responded with).
OK, let me be more specific. My KEXT is an IP filter and I am sending
selected IP packets to my client. In the KEXT _start() function I add IPv4
and IPv6 filters and then do a ctl_register with a dynamic ID. My client
app opens the KEXT connection via:
sockNum = socket( PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL )
ioctl( sockNum, CTLIOCGINFO, &info ) // to get the ctl_id
connect( sockNum, (struct sockaddr *)&sockAddr, sizeof( struct sockaddr_ctl
))
When the client starts, the KEXT gets a call in its ctl_connect_func and I
save the kctlref and unit ID. When the client quits, the KEXT gets a call
in its ctl_disconnect_func and I clean up any connection state that I
maintain.
My concern here is that my KEXT has no way of anticipating when the user
(that's me) pulls the plug with kextunload while the connected app is still
running. At that point the _stop funtion in my KEXT is called and I remove
my IPv4 and IPv6 filters and then call ctl_deregister and deregister fails
with EBUSY.
So, are you all saying that in my _stop() there is a way to see if a client
is connected and if so merely return KERN_FAILURE to prevent the KEXT from
unloading? What api is this? There is no ctl_ call available in
kern_control.h to do this ...
Unless I call ctl_deregister first in my _stop() and return KERN_FAILURE
immediately if I get EBUSY - is that it?
> When shutting down or restarting, a non-IOKit kext will not be
> unloaded automatically, so you will not get a panic if your client is
> still connected.
This is good news for when my KEXT goes into the startup folder.
-Allan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden