1 ?MAKE:usekernprocpathname: cat rm_try Compile run Setvar
3 ?S:usekernprocpathname:
4 ?S: This variable, indicates that we can use sysctl with
5 ?S: KERN_PROC_PATHNAME to get a full path for the executable, and hence
6 ?S: convert $^X to an absolute path.
8 ?C:USE_KERN_PROC_PATHNAME:
9 ?C: This symbol, if defined, indicates that we can use sysctl with
10 ?C: KERN_PROC_PATHNAME to get a full path for the executable, and hence
11 ?C: convert $^X to an absolute path.
13 ?H:#$usekernprocpathname USE_KERN_PROC_PATHNAME /**/
15 ?LINT:set usekernprocpathname
17 : Determine if we can use sysctl with KERN_PROC_PATHNAME to find executing program
19 echo "Determining whether we can use sysctl with KERN_PROC_PATHNAME to find executing program..." >&4
21 /* Intentionally a long probe as I'd like to sanity check that the exact
22 approach is going to work, as thinking it will work, but only having it
23 part working at runtime is worse than not having it. */
25 #include <sys/types.h>
26 #include <sys/sysctl.h>
27 #include <sys/param.h>
34 main(int argc, char **argv) {
36 char *argv_leaf = strrchr(argv[0], '/');
43 mib[2] = KERN_PROC_PATHNAME;
47 fprintf(stderr, "Can't locate / in '%s'\n", argv[0]);
51 if (sysctl(mib, 4, NULL, &size, NULL, 0)) {
56 if (size < strlen(argv_leaf) + 1) {
57 fprintf(stderr, "size %lu is too short for a path\n",
58 (unsigned long) size);
62 if (size > MAXPATHLEN * MAXPATHLEN) {
63 fprintf(stderr, "size %lu is too long for a path\n",
64 (unsigned long) size);
68 buffer = malloc(size);
74 if (sysctl(mib, 4, buffer, &size, NULL, 0)) {
79 if (strlen(buffer) + 1 != size) {
80 fprintf(stderr, "size != strlen(buffer) + 1 (%lu != %lu)\n",
81 (unsigned long)size, (unsigned long)strlen(buffer) + 1);
87 fprintf(stderr, "Not an absolute path: '%s'\n", buffer);
91 if (strstr(buffer, "/./")) {
92 fprintf(stderr, "Contains /./: '%s'\n", buffer);
96 if (strstr(buffer, "/../")) {
97 fprintf(stderr, "Contains /../: '%s'\n", buffer);
101 buffer_leaf = strrchr(buffer, '/');
102 if (strcmp(buffer_leaf, argv_leaf) != 0) {
103 fprintf(stderr, "Leafnames differ: '%s' vs '%s'\n", argv[0], buffer);
115 if eval $compile_ok; then
117 echo "You can use sysctl with KERN_PROC_PATHNAME to find the executing program." >&4
120 echo "Nope, sysctl with KERN_PROC_PATHNAME doesn't work here." >&4
124 echo "I'm unable to compile the test program." >&4
125 echo "I'll assume no sysctl with KERN_PROC_PATHNAME here." >&4
129 set usekernprocpathname