Created
August 5, 2016 20:02
-
-
Save mneumann/a2f6b6a0a03935b561d6185872a4b222 to your computer and use it in GitHub Desktop.
current_exe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/sysctl.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
int main() { | |
{ | |
char buf[1024]; | |
int sz = readlink("/proc/curproc/file", &buf, 1024); | |
buf[sz] = 0; | |
printf("procfs: %s\n", buf); | |
} | |
int mib[4]; | |
mib[0] = CTL_KERN; | |
mib[1] = KERN_PROC; | |
mib[2] = KERN_PROC_PATHNAME; | |
mib[3] = -1; | |
size_t sz = 0; | |
int err = sysctl(mib, 4, NULL, &sz, NULL, 0); | |
char *s = malloc(sz); | |
err = sysctl(mib, 4, s, &sz, NULL, 0); | |
s[sz-1] = 0; | |
printf("sysctl: %s\n", s); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# uname -a | |
DragonFly babel.localnet 4.7-DEVELOPMENT DragonFly v4.7.0.94.g57eef-DEVELOPMENT #25: Wed Aug 3 20:20:48 CEST 2016 mneumann@babel.localnet:/usr/obj/usr/src/sys/X86_64_GENERIC x86_64 | |
# ./current_exe | |
procfs: /home/mneumann/current_exe | |
sysctl: /data2/pfs/@@-1:00001/mneumann/current_exe | |
## The problem is, that the path sysctl returns contains a ":", which is not allowed inside a regular path. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This commit fixes the issue. DragonFly >= 4.6.1 will not be affected: