summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/common-utils.c48
-rw-r--r--libglusterfs/src/common-utils.h4
2 files changed, 52 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 4af1b4454..cb51dd175 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -3063,3 +3063,51 @@ gf_get_hard_limit (char *limit, char **hard_limit)
return 0;
}
+
+int
+gf_skip_header_section (int fd, int header_len)
+{
+ int ret = -1;
+
+ ret = lseek (fd, header_len, SEEK_SET);
+ if (ret == (off_t) -1) {
+ gf_log ("", GF_LOG_ERROR, "Failed to skip header "
+ "section");
+ } else {
+ ret = 0;
+ }
+
+ return ret;
+}
+
+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 acf2202d5..b50d3ac38 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -615,4 +615,8 @@ char **backtrace_symbols(void *const *, size_t);
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);
+int
+gf_skip_header_section (int fd, int header_len);
#endif /* _COMMON_UTILS_H */