On Mar 8, 2009, at 5:38 AM, Michael Ash wrote:

On Sat, Mar 7, 2009 at 8:30 PM, Ken Thomases <k...@codeweavers.com> wrote:
On Mar 7, 2009, at 5:26 PM, Olivier Palliere wrote:

I am working on an application that once started, sets up some temporary files and so. I didn't think of it at first, but I had the case where a friend force quitted the application, and I was left with the app not running, and still my temporary things hanging around. Ultimately, this is ok, as a reboot will clear /tmp, but ideally, I'd like to clear it up as
soon as possible.

Do your temp files really need to remain listed in the file system? You can
open/create them and then unlink them.  Your file descriptor (or
NSFileHandle) will remain valid and will be able to access and manipulate the file data, but the file won't be listed in the file system. When your process exits (cleanly or otherwise), the kernel will make sure all of your file descriptors are closed. In this case, because there are no more links to the file, the closing of the last file descriptor to it will cause it to
be deleted.

And if they *really* do need to have a directory entry, your best bet
is probably to spawn a little subprocess when you create the files
that just sits and waits for its parent to die. Once the parent
disappears for any reason, it can delete the files.

Thanks a lot for your insight (both of you)!

This is basically what I did, except that currently my subprocess is not daemon capable, as I initially wanted to get that code handled by launchd which states *very* clearly that you should not fork or so.

Now it seems the requirements are shifting and I might have, over time (but not before another release), to also add a *deny* rule in ipfw when my code is running. In that case, if the app dies, then I have a bigger problem than just files hanging around ;-) but I'll think about this when the time comes.

Many thanks again for the help,
Olivier./.




Mike
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/olivier%40sunprotectingfactory.com

This email sent to oliv...@sunprotectingfactory.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to