diff options
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 */ |