コード例 #1
0
ファイル: gsyncd.c プロジェクト: redbeedave/glusterfs
static int
invoke_gsyncd (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 (restricted) {
                /* in restricted mode we forcibly use the system-wide config */
                runinit (&runner);
                runner_add_args (&runner, SBIN_DIR"/gluster",
                                 "--log-file=-", "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
                        goto error;

                if (setenv ("_GSYNCD_RESTRICTED_", "1", 1) == -1)
                        goto error;
        }

        if (chdir ("/") == -1)
                goto error;

        j = 0;
        nargv[j++] = PYTHON;
        nargv[j++] = GSYNCD_PREFIX"/python/syncdaemon/"GSYNCD_PY;
        for (i = 1; i < argc; i++)
                nargv[j++] = argv[i];
        if (config_file[0]) {
                nargv[j++] = "-c";
                nargv[j++] = config_file;
        }
        nargv[j++] = NULL;

        execvp (PYTHON, nargv);

        fprintf (stderr, "exec of "PYTHON" failed\n");
        return 127;

 error:
        fprintf (stderr, "gsyncd initializaion failed\n");
        return 1;
}
コード例 #2
0
ファイル: run.c プロジェクト: pavantc/glusterd_scalability
int
main ()
{
        runner_t runner;
        char buf[80];
        char *wdbuf;;
        int ret;
        long pathmax = pathconf ("/", _PC_PATH_MAX);

        wdbuf = malloc (pathmax);
        assert (wdbuf);
        getcwd (wdbuf, pathmax);

        TBANNER ("basic functionality");
        runcmd ("echo", "a", "b", NULL);

        TBANNER ("argv extension");
        runcmd ("echo", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
                "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
                "31", "32", "33", "34", "35", "36", "37", "38", "39", "40",
                "41", "42", "43", "44", "45", "46", "47", "48", "49", "50",
                "51", "52", "53", "54", "55", "56", "57", "58", "59", "60",
                "61", "62", "63", "64", "65", "66", "67", "68", "69", "70",
                "71", "72", "73", "74", "75", "76", "77", "78", "79", "80",
                "81", "82", "83", "84", "85", "86", "87", "88", "89", "90",
                "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", NULL);

        TBANNER ("add_args, argprintf, log, and popen-style functionality");
        runinit (&runner);
        runner_add_args (&runner, "echo", "pid:", NULL);
        runner_argprintf (&runner, "%d\n", getpid());
        runner_add_arg (&runner, "wd:");
        runner_add_arg (&runner, wdbuf);
        runner_redir (&runner, 1, RUN_PIPE);
        runner_start (&runner);
        runner_log (&runner, "(x)", LOG_DEBUG, "starting program");
        while (fgets (buf, sizeof(buf), runner_chio (&runner, 1)))
                printf ("got: %s", buf);
        runner_end (&runner);

        TBANNER ("execve error reporting");
        ret = runcmd ("bafflavvitty", NULL);
        printf ("%d %d [%s]\n", ret, errno, strerror (errno));

        return 0;
}
コード例 #3
0
static int
cli_check_gsync_present ()
{
        char                buff[PATH_MAX] = {0, };
        runner_t            runner = {0,};
        char                *ptr = NULL;
        int                 ret = 0;

        ret = setenv ("_GLUSTERD_CALLED_", "1", 1);
        if (-1 == ret) {
                gf_log ("", GF_LOG_WARNING, "setenv syscall failed, hence could"
                        "not assert if geo-replication is installed");
                goto out;
        }

        runinit (&runner);
        runner_add_args (&runner, GSYNCD_PREFIX"/gsyncd", "--version", NULL);
        runner_redir (&runner, STDOUT_FILENO, RUN_PIPE);
        ret = runner_start (&runner);
        if (ret == -1) {
                gf_log ("", GF_LOG_INFO, "geo-replication not installed");
                goto out;
        }

        ptr = fgets(buff, sizeof(buff), runner_chio (&runner, STDOUT_FILENO));
        if (ptr) {
                if (!strstr (buff, "gsyncd")) {
                        ret  = -1;
                        goto out;
                }
        } else {
                ret = -1;
                goto out;
        }

        ret = runner_end (&runner);

        if (ret)
                gf_log ("", GF_LOG_ERROR, "geo-replication not installed");

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
        return ret ? -1 : 0;

}
コード例 #4
0
ファイル: run.c プロジェクト: AsherBond/glusterfs
int
main (int argc, char **argv)
{
        runner_t runner;
        char buf[80];
        char *wdbuf;;
        int ret;
        int fd;
        long pathmax = pathconf ("/", _PC_PATH_MAX);
        struct timeval tv = {0,};
        struct timeval *tvp = NULL;

        wdbuf = malloc (pathmax);
        assert (wdbuf);
        getcwd (wdbuf, pathmax);

        TBANNER ("basic functionality");
        runcmd ("echo", "a", "b", NULL);

        TBANNER ("argv extension");
        runcmd ("echo", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
                "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
                "31", "32", "33", "34", "35", "36", "37", "38", "39", "40",
                "41", "42", "43", "44", "45", "46", "47", "48", "49", "50",
                "51", "52", "53", "54", "55", "56", "57", "58", "59", "60",
                "61", "62", "63", "64", "65", "66", "67", "68", "69", "70",
                "71", "72", "73", "74", "75", "76", "77", "78", "79", "80",
                "81", "82", "83", "84", "85", "86", "87", "88", "89", "90",
                "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", NULL);

        TBANNER ("add_args, argprintf, log, and popen-style functionality");
        runinit (&runner);
        runner_add_args (&runner, "echo", "pid:", NULL);
        runner_argprintf (&runner, "%d\n", getpid());
        runner_add_arg (&runner, "wd:");
        runner_add_arg (&runner, wdbuf);
        runner_redir (&runner, 1, RUN_PIPE);
        runner_start (&runner);
        runner_log (&runner, "(x)", LOG_DEBUG, "starting program");
        while (fgets (buf, sizeof(buf), runner_chio (&runner, 1)))
                printf ("got: %s", buf);
        runner_end (&runner);

        TBANNER ("execve error reporting");
        ret = runcmd ("bafflavvitty", NULL);
        printf ("%d %d [%s]\n", ret, errno, strerror (errno));

        TBANNER ("output redirection");
        fd = mkstemp ("/tmp/foof");
        assert (fd != -1);
        runinit (&runner);
        runner_add_args (&runner, "echo", "foo", NULL);
        runner_redir (&runner, 1, fd);
        ret = runner_run (&runner);
        printf ("%d", ret);
        if (ret != 0)
                printf (" %d [%s]", errno, strerror (errno));
        putchar ('\n');

        if (argc > 1) {
                tv.tv_sec = strtoul (argv[1], NULL, 10);
                if (tv.tv_sec > 0)
                        tvp = &tv;
                select (0, 0, 0, 0, tvp);
        }

        return 0;
}