To add more simply
./configure -with-hook=ntp.conf
+Some system services expose the name of the service we are in,
+by default dhcpcd will pick SVCNAME from the environment.
+You can override this in CPPFLAGS+= -DSVCNAME="RC_SVCNAME".
+This is important because dhcpcd will scrub the environment aside from $PATH
+before running hooks.
+This variable could be used to facilitate service re-entry so this chain could
+happen in a custom OS hook:
+ dhcpcd service marked inactive && dhcpcd service starts
+ dependant services are not started because dhcpcd is inactive (not stopped)
+ dhcpcd hook tests $if_oneup && $if_ipwaited
+ if true, mark the dhcpcd service as started and then start dependencies
+ if false and the dhcpcd service was previously started, mark as inactive and
+ stop any dependant services.
+
Compatibility
-------------
#include "compat/posix_spawn.h"
#endif
+/* Allow the OS to define another script env var name */
+#ifndef SVCNAME
+#define SVCNAME "SVCNAME"
+#endif
+
#define DEFAULT_PATH "PATH=/usr/bin:/usr/sbin:/bin:/sbin"
static const char * const if_params[] = {
{
char *argv[2];
char **env = NULL, **ep;
- char *path, *bigenv;
+ char *svcname, *path, *bigenv;
size_t e, elen = 0;
pid_t pid;
int status = 0;
syslog(LOG_ERR, "%s: make_env: %m", ifp->name);
return -1;
}
- ep = realloc(env, sizeof(char *) * (elen + 2));
+ /* Resize for PATH and SVCNAME */
+ svcname = getenv(SVCNAME);
+ ep = realloc(env, sizeof(char *) * (elen + 2 + (svcname ? 1 : 0)));
if (ep == NULL) {
elen = 0;
goto out;
goto out;
}
}
+ ep = env;
+ if (svcname) {
+ e = strlen(SVCNAME) + strlen(svcname) + 2;
+ env[++elen] = malloc(e);
+ if (env[elen] == NULL) {
+ elen = 0;
+ goto out;
+ }
+ snprintf(env[elen], e, "%s=%s", SVCNAME, svcname);
+ }
env[++elen] = NULL;
pid = exec_script(ifp->ctx, argv, env);