summaryrefslogtreecommitdiffstats
path: root/utils/utils.c
diff options
context:
space:
mode:
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-08-17 11:21:11 +0530
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-08-17 14:22:55 +0530
commitb535c44fdd2b71c50a8fcbcf1e1e1c2d1c0340e9 (patch)
tree208d639723c7a8bfc1b928ee7843155c69fe8a5e /utils/utils.c
parentd723907c8eaa25f107c7fadd79ca5f9bc6596edf (diff)
logger: support logdir choosing via Environment variable
Currently the default logdir is DATADIR /log/gluster-block/ This patch will provide a way to change this default logdir via Env variable $ export GB_LOGDIR=/var/log/gluster-block-new-path/ Note: make sure to restart the processes (cli & daemon) after you set GB_LOGDIR Change-Id: Id142e4a4dfe7b6ebc9cf8296b8ceb8bff37691b8 Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Diffstat (limited to 'utils/utils.c')
-rw-r--r--utils/utils.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/utils/utils.c b/utils/utils.c
index d66db8d..3c2b9ad 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -9,11 +9,14 @@
*/
+# include <dirent.h>
+# include <sys/stat.h>
+
# include "utils.h"
# include "config.h"
-size_t logLevel = GB_LOG_INFO;
+struct gbConf gbConf = {GB_LOG_INFO, GB_LOGDIR, '\0', '\0', '\0', '\0'};
const char *argp_program_version = "" \
PACKAGE_NAME" ("PACKAGE_VERSION")" \
@@ -172,6 +175,64 @@ out:
}
+static bool
+glusterBlockLogdirCreate(void)
+{
+ DIR* dir = opendir(gbConf.logDir);
+
+
+ if (dir) {
+ closedir(dir);
+ } else if (errno == ENOENT) {
+ if (mkdir(gbConf.logDir, 0755) == -1) {
+ fprintf(stderr, "mkdir(%s) failed (%s)", gbConf.logDir, strerror (errno));
+ return 0; /* False */
+ }
+ } else {
+ fprintf(stderr, "opendir(%s) failed (%s)", gbConf.logDir, strerror (errno));
+ return 0; /* False */
+ }
+
+ return 1;
+}
+
+
+int
+initLogging(void)
+{
+ char *logDir = NULL;
+
+
+ logDir = getenv("GB_LOGDIR");
+ if (!logDir) {
+ logDir = GB_LOGDIR;
+ }
+
+ if (strlen(logDir) > PATH_MAX - GB_MAX_LOGFILENAME) {
+ fprintf(stderr, "strlen of logDir Path > PATH_MAX: %s\n", logDir);
+ return EXIT_FAILURE;
+ }
+
+ /* set logfile paths */
+ snprintf(gbConf.logDir, PATH_MAX,
+ "%s", logDir);
+ snprintf(gbConf.daemonLogFile, PATH_MAX,
+ "%s/gluster-blockd.log", logDir);
+ snprintf(gbConf.cliLogFile, PATH_MAX,
+ "%s/gluster-block-cli.log", logDir);
+ snprintf(gbConf.gfapiLogFile, PATH_MAX,
+ "%s/gluster-block-gfapi.log", logDir);
+ snprintf(gbConf.configShellLogFile, PATH_MAX,
+ "%s/gluster-block-configshell.log", logDir);
+
+ if(!glusterBlockLogdirCreate()) {
+ return EXIT_FAILURE;
+ }
+
+ return 0;
+}
+
+
int
gbAlloc(void *ptrptr, size_t size,
const char *filename, const char *funcname, size_t linenr)