diff options
author | Vijay Bellur <vbellur@redhat.com> | 2013-08-12 00:31:41 -0700 |
---|---|---|
committer | Gerrit Code Review <review@dev.gluster.org> | 2013-08-12 00:31:41 -0700 |
commit | e46e51c2a9367d4f4a0b96419a21751e54b58f58 (patch) | |
tree | 54b13d3c8a74eefb48baa7ad505c726f1e09af70 /libglusterfs | |
parent | 291cd61a04689104a6bba562b285d7f74645e0ad (diff) | |
parent | 355ee5fa3905a38092804e19c9447578fef50919 (diff) |
Merge "common-utils: Move glusterd_is_service_running() to common-utils" into quotaquota
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/common-utils.c | 32 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 2 |
2 files changed, 34 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index bec3249f..061162f7 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -2908,3 +2908,35 @@ gf_get_hard_limit (char *limit, char **hard_limit) return 0; } + +gf_boolean_t +gf_is_service_running (char *pidfile, int *pid) +{ + FILE *file = NULL; + gf_boolean_t running = _gf_false; + int ret = 0; + int fno = 0; + + file = fopen (pidfile, "r+"); + if (!file) + goto out; + + fno = fileno (file); + ret = lockf (fno, F_TEST, 0); + if (ret == -1) + running = _gf_true; + if (!pid) + goto out; + + ret = fscanf (file, "%d", pid); + if (ret <= 0) { + gf_log ("", GF_LOG_ERROR, "Unable to read pidfile: %s, %s", + pidfile, strerror (errno)); + *pid = -1; + } + +out: + if (file) + fclose (file); + return running; +} diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index f8db8e30..209e5025 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -595,4 +595,6 @@ void md5_wrapper(const unsigned char *data, size_t len, char *md5); int gf_get_soft_limit (char *limit, char **soft_limit); int gf_get_hard_limit (char *limit, char **hard_limit); +gf_boolean_t +gf_is_service_running (char *pidfile, int *pid); #endif /* _COMMON_UTILS_H */ |