Re: [AD] [AL] get_executable_name in xsystem.c |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
George Foot wrote on Thu Apr 06, 2000 um 12:08:55AM:
> Patches are normally best sent to the `conductors' list, but I
Ok, Cc' to this list.
> I think your change should certainly go in the Linux system
No, I wouldn't do this in the linux driver either. Reason: I noticed
that upx-compressed programs are temporarily extracted to /tmp/whatever
and deleted short time after start - but the proc-symlink still points
to the deleted file. So looking in the path is the better idea.
> driver. The X one should maybe be altered to search the path
> specified in PATH, if argv[0] doesn't contain a slash.
Sure. Has anyone a ready function that can be used for searching in
path, that can be used for Allegro? Otherwise I will try this next week,
not enough free time at the moment.
> > static void _xwin_sysdrv_get_executable_name(char *output, int size)
> > {
> > struct stat *testfile; // evtl. used later
> > int statmes;
> > char exe[250]="/proc/", temp[16];
> > size_t exe_length;
> >
> > statmes=stat(__crt0_argv[0],testfile);
>
> At this stage, `testfile' is an uninitialised pointer, but
I used this "stat"-method in an other program to check existence of a
file and it worked.
> `stat' tries to fill in the data there. Take out the `*' in the
> declaration, and pass `&testfile' to `stat'.
Trying this I got sth. like the following:
./src/x/xsystem.c:231: storage size of `buf' isn't known
Strange thing, I will check this later.
> Maybe, if this goes in the X driver too, we should check we're
> in Linux earlier. I don't like this stat actually -- I could
As mentioned before, this method better should not be used.
> run a program by typing "foo", and the executable would be the
> one in my path, not the random file called `foo' in the current
> directory.
Right.
> completely, and trust the /proc entry instead. If the /proc
> entry doesn't exist (e.g. we're on a system without /proc
> support?!) then we could fall back to the generic way.
There are also some systems with /proc unreadable non-root users,
this method would also fail on such systems.
Summary: forget /proc, forget looking in the current directory (eg.
stat), use PATH
> > exe_length=readlink(exe, exe, 250); // read real filename from symlink
>
> Are you sure it's OK to do this? I'd rather send the output
> from `readlink' into a different buffer to its filename buffer.
It is ok, readlink first reads exe, do it's work and writes output to
exe. The old content is no longer needed.
> this way, but my manpage doesn't guarrantee that it works. :)
My does not either, but it works anyhow :) It may fail by other
implementations of readlink.
> > memcpy(output, exe, exe_length); // and write to output
>
> That's not OK; it looks (from the code below) that this function
> should return a Unicode string, so you need to use do_uconvert,
> as below.
Good, do_uconvert can shorten strings too.
> > And an other thing, probably important for Michael Bukin:
> > X11 is called "X Window System", NOT X-Windows, see X(1)
>
> It might be a bit late to change that now. :) I agree that the
Who knows...
Greetings,
Eduard.
--
=====================================================================
Eduard Bloch <eb@xxxxxxxxxx>; HP: http://eduard.bloch.com/edecosi
0xEDF008C5(gpg): E6EB 98E2 B885 8FF0 6C04 5C1D E106 481E EDF0 08C5
**
Don't drink as root!