Refactor, share env helper fns with initctl

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2021-03-11 15:10:10 +01:00
1 parent bdf5f8fc90
commit 6b688c4211
2 files changed
+33 -33

No files matched your search

+31
View File
@@ -352,6 +352,37 @@ static inline char *svc_jobid(svc_t *svc, char *buf, size_t len)
return buf;
}
/*
* non-zero env, no checking if file exists or not
*/
static inline char *svc_getenv(svc_t *svc)
{
int v = 0;
if (!svc->env[0])
return NULL;
if (svc->env[0] == '-')
v = 1;
return &svc->env[v];
}
/*
* Check if svc has env, if env file exists returns true
* if it doesn't exist, but has '-', also true. if svc
* doesn't have env, also true.
*/
static inline int svc_checkenv(svc_t *svc)
{
char *env = svc_getenv(svc);
if (!env)
return 1;
return fexist(env);
}
#endif /* FINIT_SVC_H_ */
/**