Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting path to executing application



I don't think Sailor's description of the reasoning is quite accurate.

The reasoning behind there being no quick way to get a path to a) your executable and b) open file descriptors is that there MAY NOT BE A PATH anymore to those things. It is perfectly reasonable to open a file and unlink it from the namespace. Whether that file was opened() with open(), or exec(), it doesn't matter. Older Un*x OSes actually tried to keep a file from being modified/unlinked while it was busy (mostly executables - like in SysV 3.x). But that was mostly because of limitations in the VM systems, not so you could always find a path to them. If fact, you could always change a component directory's permissions. Or you may also mount a new volume over top of one of the components leading up to the executable/file in question. So, while the file exists, there is no "from root (/) path" that will get you to the file.

It's also true that, in addition to the possibility of having no valid paths to the file anymore, there could be several valid paths to the same file. It's also true that no one path, under this situation, would be useful to all users of the file.

If you can't guarantee the accuracy/usefulness of the information returned, why have an API that returns it? That's how the reasoning went.

But yes, bundles do make some of these assumptions seem "annoying."
--Jim

On Friday, July 25, 2003, at 3:40 PM, tobias ford... wrote:

That's what I thought.

On Friday, July 25, 2003, at 12:28PM, Sailor Quasar wrote:
The full path of the running process, using only POSIX APIs, not using argv[0], and not peeking into kernel mem (which is what lsof and ps do)? That falls under the same missing-functionality heading as the inability to determine the file path/name from an open file descriptor...

The theory was that you shouldn't need to determine your own current path, since you could run another copy of yourself using a fork()/main()/_exit() construct and the working directory ought to be determined by the enclosing shell (or GUI layer). Also, that you shouldn't need to know the filename from an open descriptor since you needed that information to create it to begin with.

Both of those chains of reasoning break miserably on OS X, of course. The theory of application packages requires you to be able to track your own location, and of course you need to determine filenames from open file handles because they can be passed to you from all sorts of places. One also notes that OS X provides both of these functionalities using CF/NSBundle and the modern Carbon File Manager.

-- Sailor Quasar, just another player in The World
"Come with me in the twilight of the summer night for awhile"
Email: email@hidden


-------------------
Tobias Ford...
email@hidden email@hidden
-------------------
Senior Software Engineer @ WolfPack Studios
www.wolfpackstudios.com www.shadowbane.com
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: getting path to executing application (From: "tobias ford..." <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.