aboutsummaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-06-08 15:23:33 +0200
committerToni Uhlig <matzeton@googlemail.com>2021-06-08 15:23:33 +0200
commita41ddafa88de870aadad4acdf0193ac3a326c403 (patch)
treeb4400a61a9738620510aa57706e1349c20253727 /utils.c
parent30502ff0a0d12e8f1a39c3366d14a3f443051e65 (diff)
Git tag/commit version printing for nDPId/nDPIsrvd. Reduces confusion.
* disabled subshell spawn for run_tests.sh, common pitfall while using counters Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/utils.c b/utils.c
index 16b233ced..f6340105b 100644
--- a/utils.c
+++ b/utils.c
@@ -79,14 +79,14 @@ static int create_pidfile(char const * const pidfile)
return 0;
}
-int is_path_absolute(char const * const prefix,
- char const * const path)
+int is_path_absolute(char const * const prefix, char const * const path)
{
if (path[0] != '/')
{
syslog(LOG_DAEMON | LOG_ERR,
"%s path must be absolut i.e. starting with a `/', path given: `%s'",
- prefix, path);
+ prefix,
+ path);
return 1;
}
@@ -134,7 +134,8 @@ int daemonize_shutdown(char const * const pidfile)
return 0;
}
-int change_user_group(char const * const user, char const * const group,
+int change_user_group(char const * const user,
+ char const * const group,
char const * const pidfile,
char const * const uds_collector_path,
char const * const uds_distributor_path)
@@ -143,39 +144,62 @@ int change_user_group(char const * const user, char const * const group,
struct group * grp;
gid_t gid;
- if (getuid() != 0) {
+ if (getuid() != 0)
+ {
return 0;
}
- if (user == NULL) {
+ if (user == NULL)
+ {
return 1;
}
pwd = getpwnam(user);
- if (pwd == NULL) {
+ if (pwd == NULL)
+ {
return 1;
}
- if (group != NULL) {
+ if (group != NULL)
+ {
grp = getgrnam(group);
- if (grp == NULL) {
+ if (grp == NULL)
+ {
return 1;
}
gid = grp->gr_gid;
- } else {
+ }
+ else
+ {
gid = pwd->pw_gid;
}
- if (uds_collector_path != NULL) {
+ if (uds_collector_path != NULL)
+ {
chmod(uds_collector_path, S_IRUSR | S_IWUSR);
chown(uds_collector_path, pwd->pw_uid, gid);
}
- if (uds_distributor_path != NULL) {
+ if (uds_distributor_path != NULL)
+ {
chmod(uds_distributor_path, S_IRUSR | S_IWUSR | S_IRGRP);
chown(uds_distributor_path, pwd->pw_uid, gid);
}
- if (pidfile != NULL) {
+ if (pidfile != NULL)
+ {
chown(pidfile, pwd->pw_uid, gid);
}
return setregid(gid, gid) != 0 || setreuid(pwd->pw_uid, pwd->pw_uid);
}
+
+char const * get_nDPId_version()
+{
+ return "nDPId version "
+#ifdef GIT_VERSION
+ GIT_VERSION
+#else
+ "unknown"
+#endif
+ "\n"
+ "(C) 2020-2021 Toni Uhlig\n"
+ "Please report any BUGs to toni@impl.cc\n";
+}