#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <linux/limits.h>
#include <libgen.h>
void getJsonConfigPath(char *path, int pathLen)
{
char dir[PATH_MAX] = {0};
int n = readlink("/proc/self/exe", dir, PATH_MAX);
char *dname = dirname(dir);
if (strlen(dname) < pathLen) {
strcpy(path, dname);
int pathLen = strlen(path);
if (path[pathLen-1] == '/') {
strcat(path, "config.json");
} else {
strcat(path, "/config.json");
}
} else {
printf("dname too long: %d\n", strlen(dname));
}
}
int main() {
char path[PATH_MAX] = {0};
getJsonConfigPath(path, sizeof(path));
printf("path: %s\n", path);
return 0;
}
You can use the function getJsonConfigPath in you apache module,this function can return the config path you can use.