New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get_exename() for OpenBSD. #17
get_exename() for OpenBSD. #17
Conversation
Issue `get_exename()` gets the pathname of the current process. In femtolisp, this is used to set the top-level `*install-dir*` which in turn is used as the location of the system image, `flisp.boot`. There is only a trivial implementation of `get_exename()` for OpenBSD that simply returns `NULL`. A minor consequence is that the unit test will fail for the default build (make) because the system image cannot be found. Fix This commit provides an implementation of `get_exename()` for OpenBSD, so that the system image can be found. Unlike, say, Linux or FreeBSD, OpenBSD doesn't have a system call to get the path of the current (or any, for that matter) process. The present code contains some logic that was put together to emulate the behavior of the Linux and FreeBSD variants of `get_exename()` as best as possible. It works as described by the following. (1) Call `sysctl(3)` (with `CTL_KERN` -> `KERN_PROC_ARGS` -> `KERN_PROC_ARGV`) to get the "`argv[0]`" of the current process. If the program (flisp) was called in "`basename` form" (i.e. as "flisp"), then go to (2). Otherwise, return the value from `sysctl(3)` which will be an absolute or relative pathname, e.g. "/usr/local/bin/flisp" or "../flisp". The code for (1) was adapted from old OpenBSD-specific `tmux` code that has since been abandoned by the author only because he deemed it "too expensive". For that code, see http://sourceforge.net/p/tmux/tmux-code/ci/8c259f562be24570a19fd94b223034ae8c6e4277/tree/osdep-openbsd.c (2) Since we now only have "flisp", we need to find out where it is located on the system. We assume that a program like the shell had to crawl `PATH` to find "flisp"; hence we do the same. The code for (2) was adapted from the `which` utility in OpenBSD. See http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/usr.bin/which/which.c?rev=1.20&content-type=text/plain Finally, any error condition returns `NULL`, which is the same behavior of the other `get_exename()` variants.
I thought of another thing. The whole idea for this commit is to make the behavior of
This works for finding Whether this should be the case (i.e. What do you think? Am I over-thinking this? Thanks! |
Thanks, this is much appreciated! I think install-dir should be an absolute path; it should still be possible to use it to find flisp's files if the current directory changes at run time. |
Oh, yes, you are right. So, I should put in more logic to resolve the relative pathnames to absolute. Now, comes my lack of github etiquette/protocol: should I add another commit (the new change) on top of this one, or ditch this commit and resubmit a new commit/issue, being the combination of what I have now plus the new stuff coming (as if I'd known all along what I was doing :)? I suppose, in the end, it's not a big deal, but I thought I'd ask. Thanks, Jeff! |
Typically I'd force push to the same branch (then github will update the PR automatically), and squash commits if there are lots of them. With just 2 commits I'd say squashing is optional. |
OK, Jeff, you should see the second commit now. I added a call to Sorry for the delay finishing this. Again, thanks for your help. |
Here are some tests (some of which may be overkill, but hey, Overkill's my middle name). I start the whole thing with a clone from scratch. (I omit some output for brevity's sake.)
|
Issue
get_exename()
gets the pathname of the current process. In femtolisp, this is used to set the top-level*install-dir*
which in turn is used as the location of the system image,flisp.boot
.There is only a trivial implementation of
get_exename()
for OpenBSD that simply returnsNULL
. A minor consequence is that the unit test will fail for the default build (make) because the system image cannot be found.Fix
This commit provides an implementation of
get_exename()
for OpenBSD, so that the system image can be found.Unlike, say, Linux or FreeBSD, OpenBSD doesn't have a system call to get the path of the current (or any, for that matter) process. The present code contains some logic that was put together to emulate the behavior of the Linux and FreeBSD variants of
get_exename()
as best as possible. It works as described by the following.(1) Call
sysctl(3)
(withCTL_KERN
->KERN_PROC_ARGS
->KERN_PROC_ARGV
) to get the "argv[0]
" of the current process. If the program (flisp) was called in "basename
form" (i.e. as "flisp"), then go to (2). Otherwise, return the value fromsysctl(3)
which will be an absolute or relative pathname, e.g. "/usr/local/bin/flisp" or "../flisp".The code for (1) was adapted from old OpenBSD-specific
tmux
code that has since been abandoned by the author only because he deemed it "too expensive". For that code, seehttp://sourceforge.net/p/tmux/tmux-code/ci/8c259f562be24570a19fd94b223034ae8c6e4277/tree/osdep-openbsd.c
(2) Since we now only have "flisp", we need to find out where it is located on the system. We assume that a program like the shell had to crawl
PATH
to find "flisp"; hence we do the same.The code for (2) was adapted from the
which
utility in OpenBSD. Seehttp://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/usr.bin/which/which.c?rev=1.20&content-type=text/plain
Finally, any error condition returns
NULL
, which is the same behavior of the otherget_exename()
variants.