This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit 54d51a3cba0c5896fdbaac328ba833a31ef61f95
Author: Nir Soffer <nsoffer(a)redhat.com>
Date: Thu Jan 11 04:46:17 2018 +0200
Add environment variables helpers
These helpers make it easy to get an environment variable falling back
to default value if the environment variable is not set. This will be
used for using a special sanlock run directory and disabling privileged
operations when running sanlock in the tests.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
src/Makefile | 9 ++++++---
src/env.c | 34 ++++++++++++++++++++++++++++++++++
src/env.h | 15 +++++++++++++++
3 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/src/Makefile b/src/Makefile
index 69fcd13..3ca25c9 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -37,7 +37,8 @@ CMD_SOURCE = \
monotime.c \
cmd.c \
client_cmd.c \
- sanlock_sock.c
+ sanlock_sock.c \
+ env.c
LIB_ENTIRE_SOURCE = \
client.c \
@@ -51,11 +52,13 @@ LIB_ENTIRE_SOURCE = \
task.c \
timeouts.c \
direct_lib.c \
- monotime.c
+ monotime.c \
+ env.c
LIB_CLIENT_SOURCE = \
client.c \
- sanlock_sock.c
+ sanlock_sock.c \
+ env.c
LIBPC_ENTIRE_SOURCE = libsanlock.pc.in
LIBPC_CLIENT_SOURCE = libsanlock_client.pc.in
diff --git a/src/env.c b/src/env.c
new file mode 100644
index 0000000..e1d2f3a
--- /dev/null
+++ b/src/env.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2018 Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v2 or (at your option) any later version.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "env.h"
+
+const char *env_get(const char *key, const char *defval)
+{
+ const char *val;
+
+ val = getenv(key);
+ if (val == NULL)
+ return defval;
+
+ return val;
+}
+
+int env_get_bool(const char *key, int defval)
+{
+ const char *val;
+
+ val = getenv(key);
+ if (val == NULL)
+ return defval;
+
+ return strcmp(val, "1") ? 0 : 1;
+}
diff --git a/src/env.h b/src/env.h
new file mode 100644
index 0000000..ca3a3ff
--- /dev/null
+++ b/src/env.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright 2018 Red Hat, Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v2 or (at your option) any later version.
+ */
+
+#ifndef __ENV_H__
+#define __ENV_H__
+
+const char *env_get(const char *key, const char *defval);
+int env_get_bool(const char *key, int defval);
+
+#endif
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.