diff options
author | Shehjar Tikoo <shehjart@gluster.com> | 2009-05-24 23:05:26 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-06-02 23:15:03 -0700 |
commit | a29ec1f1484902400f08b24ed777ea984923ffea (patch) | |
tree | 810a9222fbebfdf1e3aa231a08319d1207363659 /booster | |
parent | f888b3f5be4be893323b644dba0668ae3d40228e (diff) |
booster: Clean-up handling of log/fstab env variables
Handle two cases when deciding log/fstab file:
1. It turns out that that strdup or strlen doesnt actually
check for NULL before trying to do its thing with the string
so it seg-faults on seeing a NULL char pointer.
2. getenv can return an empty string if the
env var was exported as:
$ export GLUSTEFS_BOOSTER_LOG=
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'booster')
-rw-r--r-- | booster/src/booster.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/booster/src/booster.c b/booster/src/booster.c index b51cc25cae3..cb35be519d3 100644 --- a/booster/src/booster.c +++ b/booster/src/booster.c @@ -376,6 +376,7 @@ mbp_open (int fd, dev_t file_devno) FILE *specfp = NULL; int32_t file_size = -1; int ret = -1; + char *logfile = NULL; glusterfs_handle_t handle = NULL; glusterfs_init_params_t ctx = { @@ -409,8 +410,13 @@ mbp_open (int fd, dev_t file_devno) goto out; fseek (specfp, 0L, SEEK_SET); - ctx.logfile = strdup (getenv (BOOSTER_LOG_ENV_VAR)); - if (!ctx.logfile) + logfile = getenv (BOOSTER_LOG_ENV_VAR); + if (logfile) { + if (strlen (logfile) > 0) + ctx.logfile = strdup (logfile); + else + ctx.logfile = strdup (BOOSTER_DEFAULT_LOG); + } else ctx.logfile = strdup (BOOSTER_DEFAULT_LOG); ctx.specfp = specfp; @@ -1178,10 +1184,13 @@ booster_init (void) * socket calls will fall-back to the real API. */ booster_conf_path = getenv (BOOSTER_CONF_ENV_VAR); - if (booster_conf_path == NULL) + if (booster_conf_path != NULL) { + if (strlen (booster_conf_path) > 0) + ret = booster_configure (booster_conf_path); + else + ret = booster_configure (DEFAULT_BOOSTER_CONF); + } else ret = booster_configure (DEFAULT_BOOSTER_CONF); - else - ret = booster_configure (booster_conf_path); if (ret == 0) gf_log ("booster", GF_LOG_DEBUG, "booster is inited"); |