enzo1982 / smooth

The smooth Class Library
http://www.smooth-project.org/
Artistic License 2.0
28 stars 11 forks source link

GetApplicationDirectory() code is not up-to-date with modern FreeBSD #5

Closed danfe closed 3 years ago

danfe commented 3 years ago

Currently, GetApplicationDirectory() works by calling procstat -b <pid> and getting the third field of the line matching the <pid>. The problem is that modern FreeBSD versions return four fields:

% procstat -b $$
  PID COMM                OSREL PATH
42096 tcsh              1300132 /bin/tcsh

So print $3 should really be print $4. Another thing is that filtering the PID line could be avoided if procstat is called with -h (suppress header) switch.

Ideally, however, is not to spawn and chain any processes and read their output with popen(), but ask the system with sysctl() call for the KERN_PROC_PATHNAME as described here.

enzo1982 commented 3 years ago

Thank you for bringing this up!

This is fixed in 7e21ca30 by changing to the KERN_PROC_PATHNAME sysctl. Also improved finding the binary path on macOS in the same commit.

danfe commented 3 years ago

Fixed in version 0.9.8, closing.