From 1098aaa51d2e3dca9e6c48ee1e9cb43bc87936f4 Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Fri, 2 Sep 2011 19:03:33 +0200 Subject: 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 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- xlators/features/marker/utils/Makefile.am | 6 +- xlators/features/marker/utils/gsyncd.in | 55 ----------- xlators/features/marker/utils/src/Makefile.am | 20 ++++ xlators/features/marker/utils/src/gsyncd.c | 131 ++++++++++++++++++++++++++ 4 files changed, 152 insertions(+), 60 deletions(-) delete mode 100755 xlators/features/marker/utils/gsyncd.in create mode 100644 xlators/features/marker/utils/src/Makefile.am create mode 100644 xlators/features/marker/utils/src/gsyncd.c (limited to 'xlators/features/marker') 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. + 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 + . +*/ + + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#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; +} -- cgit