Example #1
0
File: luit.c Project: aosm/X11
static int
convert(int ifd, int ofd)
{
    int rc, i;
    unsigned char buf[BUFFER_SIZE];

    rc = droppriv();
    if(rc < 0) {
        perror("Couldn't drop priviledges");
        exit(1);
    }

    while(1) {
        i = read(ifd, buf, BUFFER_SIZE);
        if(i <= 0) {
            if(i < 0) {
                perror("Read error");
                exit(1);
            }
            break;
        }
        copyOut(outputState, ofd, buf, i);
    }
    return 0;
}
Example #2
0
File: luit.c Project: aosm/X11
static int
condom(int argc, char **argv)
{
    int pty;
    int pid;
    char *line;
    char *path;
    char **child_argv;
    int rc;

    rc = parseArgs(argc, argv, child_argv0,
                   &path, &child_argv);
    if(rc < 0)
        FatalError("Couldn't parse arguments\n");

    rc = allocatePty(&pty, &line);
    if(rc < 0) {
        perror("Couldn't allocate pty");
        exit(1);
    }

    rc = droppriv();
    if(rc < 0) {
        perror("Couldn't drop priviledges");
        exit(1);
    }

    pid = fork();
    if(pid < 0) {
        perror("Couldn't fork");
        exit(1);
    }

    if(pid == 0) {
        close(pty);
        child(line, path, child_argv);
    } else {
        free(child_argv);
        free(path);
        free(line);
        parent(pid, pty);
    }

    return 0;
}
Example #3
0
int
probes_init(struct glougloud *ggd) {
	_ggd = ggd;
	_probes = xcalloc(1, sizeof(struct glougloud_probes));
	_probes->pid = fork();
	if (_probes->pid > 0)
		return 0;
	setprocname("probes");
	droppriv(GLOUGLOUD_USER_PROBES, 1, NULL);

	_probes->evb = event_base_new();

	if (_modules_load() < 0)
	    goto err;

	_probes->rc = redis_connect(_probes->evb, cb_connect, cb_disconnect);
	if (_probes->rc->err)
		return -1;

	_probes->server = gg_server_start(_probes->evb,
		&ggd->probes.serv_ip, ggd->probes.serv_port,
		prb_handle_conn, prb_handle_packet, NULL);
	if (!_probes->server) {
		log_warn("probes: gg_server_start failed");
		return -1;
	}

	event_base_dispatch(_probes->evb);

	gg_server_stop(_probes->server);

	return 0;

err:
    probes_shutdown();
    return -1;
}