summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/common-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs/src/common-utils.c')
-rw-r--r--libglusterfs/src/common-utils.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 4af1b44..cb51dd1 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;
+}