Пример #1
0
R_API R2Pipe *r2p_open(const char *cmd) {
	R2Pipe *r2p = R_NEW0 (R2Pipe);
	if (!r2p) return NULL;
	r2p->magic = R2P_MAGIC;
	if (!cmd) {
		r2p->child = -1;
		return r2p_open_spawn (r2p, cmd);
	}
#if __WINDOWS__ && !defined(__CYGWIN__)
	w32_createPipe (r2p, cmd);
	r2p->child = (int)(r2p->pipe);
#else
	pipe (r2p->input);
	pipe (r2p->output);
#if LIBC_HAVE_FORK
	r2p->child = fork ();
#else
	r2p->child = -1;
#endif
	if (r2p->child == -1) {
		r2p_close (r2p);
		return NULL;
	}
	env ("R2PIPE_IN", r2p->input[0]);
	env ("R2PIPE_OUT", r2p->output[1]);

	if (r2p->child) {
		char ch;
		eprintf ("[+] r2pipe child is %d\n", r2p->child);
#if 0
		if (read (r2p->output[0], &ch, 1) != 1) {
			eprintf ("Failed to read 1 byte\n");
			r2p_close (r2p);
			return NULL;
		}
		if (ch == 0x00) {
			eprintf ("[+] r2pipe-io link stablished\n");
		}
#endif
	} else {
		int rc = 0;
		if (cmd && *cmd) {
			close (0);
			close (1);
			dup2 (r2p->input[0], 0);
			dup2 (r2p->output[1], 1);
			rc = r_sandbox_system (cmd, 0);
		}
		r2p_close (r2p);
		exit (rc);
		return NULL;
	}
#endif
	return r2p;
}
Пример #2
0
R_API R2Pipe *r2p_open(const char *cmd) {
    R2Pipe *r2p = R_NEW0 (R2Pipe);
    r2p->magic = R2P_MAGIC;
    if (!cmd) {
        r2p->child = -1;
        return r2p_open_spawn (r2p, cmd);
    }
#if __WINDOWS__ && !defined(__CYGWIN__)
    w32_createPipe (r2p, cmd);
    r2p->child = (int)(r2p->pipe);
#else
    pipe (r2p->input);
    pipe (r2p->output);
    r2p->child = fork ();
    if (r2p->child == -1) {
        r2p_close (r2p);
        return NULL;
    }
    env ("R2PIPE_IN", r2p->input[0]);
    env ("R2PIPE_OUT", r2p->output[1]);

    if (r2p->child) {
        eprintf ("Child is %d\n", r2p->child);
        char ch;
        read (r2p->output[0], &ch, 1);
    } else {
        int rc = 0;
        if (cmd && *cmd) {
            close (0);
            close (1);
            dup2 (r2p->input[0], 0);
            dup2 (r2p->output[1], 1);
            rc = r_sandbox_system (cmd, 0);
        }
        r2p_close (r2p);
        exit (rc);
        return NULL;
    }
#endif
    return r2p;
}