Re: [AD] No more END_OF_MAIN on *nix!

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Evert Glebbeek wrote:

well, with the attached patch at least, which is an update of my previous patch that adds procfs support to get_executable_name.

This patch gets rid of the magic_main mangling in UNIX, using procfs if available to grab a copy of the running program. If procfs is not available, it tries to shell out and get the name of the executable from the pid by querying the ps command. This is not as good as using procfs, but in my tests not less reliable than depending on argv[0]. It depends on the ps command being available (not a big demand IMO) and delivering its output in the same format across platforms (this may be more of a concern).

Comments?

Nice idea. Do you know if the -o switch is standard across different versions of `ps'? I can check Solaris tomorrow.

+   /* Try using the output of the ps command to at least find the name of */
+   /* the file if not the full path */
+   uszprintf (linkname, sizeof(linkname), "ps -o \"%%a\" -p %d", pid);
+   do_uconvert (linkname, U_CURRENT, filename, U_ASCII, size);
There's no need to use uzsprintf to produce the command line and then convert to ASCII. I guess you don't want to depend on snprintf, but sprintf is fine in this case.

Also, if the ps output is not an absolute path it should search the PATH, like with argv[0].

Peter




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/