示例#1
0
int
gf_umount_lazy (char *xlname, char *path, int rmdir_flag)
{
        int                   ret               = -1;
        runner_t              runner            = {0,};

        runinit (&runner);
#ifdef GF_LINUX_HOST_OS
        runner_add_args (&runner, _PATH_UMOUNT, "-l", path, NULL);
#else
        if (rmdir_flag)
                runner_add_args (&runner, SBIN_DIR "/umountd",
                                 "-r", path, NULL);
        else
                runner_add_args (&runner, SBIN_DIR "/umountd",
                                 path, NULL);
#endif
        ret = runner_run (&runner);
        if (ret) {
                gf_msg (xlname, GF_LOG_ERROR, errno, LG_MSG_UNMOUNT_FAILED,
                        "Lazy unmount of %s", path);
        }

#ifdef GF_LINUX_HOST_OS
        if (!ret && rmdir_flag) {
                ret = rmdir (path);
                if (ret)
                        gf_msg (xlname, GF_LOG_WARNING, errno,
                                LG_MSG_DIR_OP_FAILED, "rmdir %s", path);
        }
#endif

        return ret;
}
示例#2
0
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;
}
示例#3
0
static int
sc_service_action (struct service_command *sc, char *command)
{
        runner_t      runner = {0,};

        runinit (&runner);
        runner_add_args (&runner, sc->binary, sc->service, command, NULL);
        return runner_run (&runner);
}
示例#4
0
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;
}
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;

}
示例#6
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;
}