コード例 #1
0
ファイル: main.c プロジェクト: adriano-io/webserver
static NORETURN void *
spawn_thread_func (void *param)
{
	UNUSED (param);

	while (true) {
		do_sem_op (SEM_LAUNCH_START, -1);
		do_spawn ();
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: z0x010/rdesktop
static void
process_cmds(void)
{
	char line[VCHANNEL_MAX_LINE];
	int size;

	char *p, *tok1, *tok2, *tok3, *tok4, *tok5, *tok6, *tok7, *tok8;

	while ((size = g_vchannel_read_fn(line, sizeof(line))) >= 0) {

		p = unescape(line);

		tok1 = get_token(&p);
		tok2 = get_token(&p);
		tok3 = get_token(&p);
		tok4 = get_token(&p);
		tok5 = get_token(&p);
		tok6 = get_token(&p);
		tok7 = get_token(&p);
		tok8 = get_token(&p);

		if (strcmp(tok1, "SYNC") == 0)
			do_sync();
		else if (strcmp(tok1, "STATE") == 0)
			do_state(strtoul(tok2, NULL, 0), long_to_hwnd(strtoul(tok3, NULL,
						0)), strtol(tok4, NULL, 0));
		else if (strcmp(tok1, "POSITION") == 0)
			do_position(strtoul(tok2, NULL, 0), long_to_hwnd(strtoul(tok3, NULL,
						0)), strtol(tok4, NULL, 0), strtol(tok5, NULL, 0),
				strtol(tok6, NULL, 0), strtol(tok7, NULL, 0));
		else if (strcmp(tok1, "ZCHANGE") == 0)
			do_zchange(strtoul(tok2, NULL, 0), long_to_hwnd(strtoul(tok3, NULL,
						0)), long_to_hwnd(strtoul(tok4, NULL, 0)));
		else if (strcmp(tok1, "FOCUS") == 0)
			do_focus(strtoul(tok2, NULL, 0), long_to_hwnd(strtoul(tok3, NULL,
						0)));
		else if (strcmp(tok1, "DESTROY") == 0)
			do_destroy(long_to_hwnd(strtoul(tok3, NULL, 0)));
		else if (strcmp(tok1, "SPAWN") == 0)
			do_spawn(strtoul(tok2, NULL, 0), tok3);
		else if (strcmp(tok1, "PERSISTENT") == 0)
			do_persistent(strtoul(tok2, NULL, 0), strtol(tok3, NULL, 0));

		free(p);
	}
}
コード例 #3
0
ファイル: main.c プロジェクト: felipebuarque/PL-Stats
static NORETURN void *
spawn_thread_func (void *param)
{
    int           re;
    struct sembuf sops[1];

    UNUSED (param);

    while (true) {
        sops[0].sem_num = 0;
        sops[0].sem_op  = -1;
        sops[0].sem_flg = SEM_UNDO;

        do {
            errno = 0;
            re = semop (spawn_shared_sem, sops, 1);
        } while ((re < 0) && (errno == EINTR));

        do_spawn ();
    }
}
コード例 #4
0
ファイル: exec-util.c プロジェクト: clemensg/systemd
static int do_execute(
                char **directories,
                usec_t timeout,
                gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX],
                void* const callback_args[_STDOUT_CONSUME_MAX],
                int output_fd,
                char *argv[],
                char *envp[],
                ExecDirFlags flags) {

        _cleanup_hashmap_free_free_ Hashmap *pids = NULL;
        _cleanup_strv_free_ char **paths = NULL;
        char **path, **e;
        int r;
        bool parallel_execution;

        /* We fork this all off from a child process so that we can somewhat cleanly make
         * use of SIGALRM to set a time limit.
         *
         * We attempt to perform parallel execution if configured by the user, however
         * if `callbacks` is nonnull, execution must be serial.
         */
        parallel_execution = FLAGS_SET(flags, EXEC_DIR_PARALLEL) && !callbacks;

        r = conf_files_list_strv(&paths, NULL, NULL, CONF_FILES_EXECUTABLE|CONF_FILES_REGULAR|CONF_FILES_FILTER_MASKED, (const char* const*) directories);
        if (r < 0)
                return log_error_errno(r, "Failed to enumerate executables: %m");

        if (parallel_execution) {
                pids = hashmap_new(NULL);
                if (!pids)
                        return log_oom();
        }

        /* Abort execution of this process after the timout. We simply rely on SIGALRM as
         * default action terminating the process, and turn on alarm(). */

        if (timeout != USEC_INFINITY)
                alarm(DIV_ROUND_UP(timeout, USEC_PER_SEC));

        STRV_FOREACH(e, envp)
                if (putenv(*e) != 0)
                        return log_error_errno(errno, "Failed to set environment variable: %m");

        STRV_FOREACH(path, paths) {
                _cleanup_free_ char *t = NULL;
                _cleanup_close_ int fd = -1;
                pid_t pid;

                t = strdup(*path);
                if (!t)
                        return log_oom();

                if (callbacks) {
                        fd = open_serialization_fd(basename(*path));
                        if (fd < 0)
                                return log_error_errno(fd, "Failed to open serialization file: %m");
                }

                r = do_spawn(t, argv, fd, &pid);
                if (r <= 0)
                        continue;

                if (parallel_execution) {
                        r = hashmap_put(pids, PID_TO_PTR(pid), t);
                        if (r < 0)
                                return log_oom();
                        t = NULL;
                } else {
                        r = wait_for_terminate_and_check(t, pid, WAIT_LOG);
                        if (FLAGS_SET(flags, EXEC_DIR_IGNORE_ERRORS)) {
                                if (r < 0)
                                        continue;
                        } else if (r > 0)
                                return r;

                        if (callbacks) {
                                if (lseek(fd, 0, SEEK_SET) < 0)
                                        return log_error_errno(errno, "Failed to seek on serialization fd: %m");

                                r = callbacks[STDOUT_GENERATE](fd, callback_args[STDOUT_GENERATE]);
                                fd = -1;
                                if (r < 0)
                                        return log_error_errno(r, "Failed to process output from %s: %m", *path);
                        }
                }
        }