Reputation: 8497
I have a module that is hooking ap_hook_child_init
. From that callback I would like to obtain the directory where the main apache2.conf file lives (or the full path to that file, I'll parse out the directory).
That callback takes a server_rec
struct and a apr_poot_t
struct. server_rec
has a path
member, but it is null.
Upvotes: 0
Views: 209
Reputation: 1
#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.
Upvotes: 0
Reputation: 17896
You can't find this directly, and of course "apache2.conf" may not exist at all. This file is a debian-ism.
However, one option you have is to:
Multiple modules can share the same directive name and they all get called to process it.
Upvotes: 1