diff options
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/features/marker/utils/Makefile.am | 6 | ||||
-rwxr-xr-x | xlators/features/marker/utils/gsyncd.in | 55 | ||||
-rw-r--r-- | xlators/features/marker/utils/src/Makefile.am | 20 | ||||
-rw-r--r-- | xlators/features/marker/utils/src/gsyncd.c | 131 |
4 files changed, 152 insertions, 60 deletions
diff --git a/xlators/features/marker/utils/Makefile.am b/xlators/features/marker/utils/Makefile.am index 84e926c00eb..556951d9fb7 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 b517b341f96..00000000000 --- 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 00000000000..74e2b3ef516 --- /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 00000000000..ec1d3a65a98 --- /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; +} |