summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2011-09-02 19:03:33 +0200
committerVijay Bellur <vijay@gluster.com>2011-09-22 05:22:59 -0700
commit1098aaa51d2e3dca9e6c48ee1e9cb43bc87936f4 (patch)
treeb6bb93729d685ede7a7cec1b09cb901d5885d693 /xlators
parent3672c989f369c5b57aff8d0d01fc221804ada6eb (diff)
geo-rep: rewrite gsyncd wrapper in C
This rewrite does not change functionality; it's purpose is to prepare followup modifications which will let all slave side helper programs being dispatched to through gsyncd. The string processing that's required for that task would be too much cumbersome in shell. Change-Id: Ia7858aba5efeb5dcff16a918ea1c02253f0e49ab BUG: 2825 Reviewed-on: http://review.gluster.com/459 Reviewed-by: Amar Tumballi <amar@gluster.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'xlators')
-rw-r--r--xlators/features/marker/utils/Makefile.am6
-rwxr-xr-xxlators/features/marker/utils/gsyncd.in55
-rw-r--r--xlators/features/marker/utils/src/Makefile.am20
-rw-r--r--xlators/features/marker/utils/src/gsyncd.c131
4 files changed, 152 insertions, 60 deletions
diff --git a/xlators/features/marker/utils/Makefile.am b/xlators/features/marker/utils/Makefile.am
index 84e926c00..556951d9f 100644
--- a/xlators/features/marker/utils/Makefile.am
+++ b/xlators/features/marker/utils/Makefile.am
@@ -1,7 +1,3 @@
-SUBDIRS = syncdaemon
-
-gsyncddir = $(libexecdir)/glusterfs
-
-gsyncd_SCRIPTS = gsyncd
+SUBDIRS = syncdaemon src
CLEANFILES =
diff --git a/xlators/features/marker/utils/gsyncd.in b/xlators/features/marker/utils/gsyncd.in
deleted file mode 100755
index b517b341f..000000000
--- a/xlators/features/marker/utils/gsyncd.in
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/bin/sh
-
-prefix="@prefix@"
-exec_prefix="@exec_prefix@"
-libexecdir=`eval echo "@libexecdir@"`
-sbindir=`eval echo "@sbindir@"`
-
-gluster="$sbindir"/gluster
-
-# glusterd service autodetection
-
-config_wanted=1
-if [ "$_GLUSTERD_CALLED_" = 1 ]; then
- # OK, we know glusterd called us, no need to look for further config
- config_wanted=0
- # ... altough this conclusion should not inherit to our children
- unset _GLUSTERD_CALLED_
-else
- # look for a -c option -- if present, we are already configured.
-
- for a in "$@"; do
- # -c found, see if it has an argument
- if [ "$one_more_arg" = 1 ]; then
- if echo "$a" | grep -qv ^-; then
- config_wanted=0
- break
- fi
- one_more_arg=0
- fi
-
- if [ "$a" = -c ] || [ "$a" = --config-file ]; then
- one_more_arg=1
- continue
- fi
-
- if echo $a | grep -qE '^(-c.|--config-file=)'; then
- config_wanted=0;
- break
- fi
- done
-
-fi
-
-if [ $config_wanted = 1 ]; then
- wd="`${gluster} --log-file=/dev/stderr system:: getwd`"
- if [ $? -eq 0 ]; then
- config_file="$wd/geo-replication/gsyncd.conf"
- fi
-fi
-
-if [ -z "$config_file" ]; then
- exec @PYTHON@ "$libexecdir"/glusterfs/python/syncdaemon/gsyncd.py "$@"
-else
- exec @PYTHON@ "$libexecdir"/glusterfs/python/syncdaemon/gsyncd.py -c "$config_file" "$@"
-fi
diff --git a/xlators/features/marker/utils/src/Makefile.am b/xlators/features/marker/utils/src/Makefile.am
new file mode 100644
index 000000000..74e2b3ef5
--- /dev/null
+++ b/xlators/features/marker/utils/src/Makefile.am
@@ -0,0 +1,20 @@
+gsyncddir = $(libexecdir)/glusterfs
+
+gsyncd_PROGRAMS = gsyncd
+
+gsyncd_SOURCES = gsyncd.c
+
+gsyncd_LDADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
+
+gsyncd_LDFLAGS = $(GF_LDFLAGS) $(GF_GLUSTERFS_LDFLAGS)
+
+AM_CFLAGS = -fPIC -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D$(GF_HOST_OS)\
+ -I$(top_srcdir)/libglusterfs/src\
+ -DGSYNCD_PREFIX=\"$(libexecdir)/glusterfs\"\
+ -DSBIN_DIR=\"$(sbindir)\" -DPYTHON=\"$(PYTHON)\"
+
+
+CLEANFILES =
+
+$(top_builddir)/libglusterfs/src/libglusterfs.la:
+ $(MAKE) -C $(top_builddir)/libglusterfs/src/ all
diff --git a/xlators/features/marker/utils/src/gsyncd.c b/xlators/features/marker/utils/src/gsyncd.c
new file mode 100644
index 000000000..ec1d3a65a
--- /dev/null
+++ b/xlators/features/marker/utils/src/gsyncd.c
@@ -0,0 +1,131 @@
+/*
+ Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "common-utils.h"
+#include "run.h"
+
+#define _GLUSTERD_CALLED_ "_GLUSTERD_CALLED_"
+#define GSYNCD_CONF "geo-replication/gsyncd.conf"
+
+static int
+config_wanted (int argc, char **argv)
+{
+ char *evas = NULL;
+ char *oa = NULL;
+ int i = 0;
+ int one_more_arg = 0;
+
+ evas = getenv (_GLUSTERD_CALLED_);
+ if (evas && strcmp (evas, "1") == 0) {
+ /* OK, we know glusterd called us, no need to look for further config
+ * ... altough this conclusion should not inherit to our children
+ */
+ unsetenv (_GLUSTERD_CALLED_);
+ return 0;
+ }
+
+ for (i = 1; i < argc; i++) {
+ /* -c found, see if it has an argument */
+ if (one_more_arg) {
+ if (argv[i][0] != '-')
+ return 0;
+ one_more_arg = 0;
+ }
+
+ if ((strcmp (argv[i], "-c") && strcmp (argv[i], "--config-file")) == 0) {
+ one_more_arg = 1;
+ continue;
+ }
+
+ oa = strtail (argv[i], "-c");
+ if (oa && !*oa)
+ oa = NULL;
+ if (!oa)
+ oa = strtail (argv[i], "--config-file=");
+ if (oa)
+ return 0;
+ }
+
+ return 1;
+}
+
+int
+main(int argc, char **argv)
+{
+ char config_file[PATH_MAX] = {0,};
+ size_t gluster_workdir_len = 0;
+ runner_t runner = {0,};
+ int i = 0;
+ int j = 0;
+ char *nargv[argc + 4];
+
+ if (config_wanted (argc, argv)) {
+ runinit (&runner);
+ runner_add_args (&runner, SBIN_DIR"/gluster",
+ "--log-file=/dev/stderr", "system::", "getwd",
+ NULL);
+ runner_redir (&runner, STDOUT_FILENO, RUN_PIPE);
+ if (runner_start (&runner) == 0 &&
+ fgets (config_file, PATH_MAX,
+ runner_chio (&runner, STDOUT_FILENO)) != NULL &&
+ config_file[strlen (config_file) - 1] == '\n' &&
+ runner_end (&runner) == 0)
+ gluster_workdir_len = strlen (config_file) - 1;
+
+ if (gluster_workdir_len) {
+ if (gluster_workdir_len + 1 + strlen (GSYNCD_CONF) + 1 >
+ PATH_MAX)
+ goto error;
+ config_file[gluster_workdir_len] = '/';
+ strcat (config_file, GSYNCD_CONF);
+ } else
+ config_file[0] = '\0';
+ }
+
+ j = 0;
+ nargv[j++] = PYTHON;
+ nargv[j++] = GSYNCD_PREFIX"/python/syncdaemon/gsyncd.py";
+ if (config_file[0]) {
+ nargv[j++] = "-c";
+ nargv[j++] = config_file;
+ }
+ for (i = 1; i < argc; i++)
+ nargv[j++] = argv[i];
+ nargv[j++] = NULL;
+
+ execvp (PYTHON, nargv);
+
+ fprintf (stderr, "exec of "PYTHON" failed\n");
+ return 127;
+
+ error:
+ fprintf (stderr, "gsyncd initializaion failed\n");
+ return 1;
+}