예제 #1
0
파일: rcS.c 프로젝트: asac/procd
static void q_initd_run(struct runqueue *q, struct runqueue_task *t)
{
	struct initd *s = container_of(t, struct initd, proc.task);
	int pipefd[2];
	pid_t pid;

	DEBUG(2, "start %s %s \n", s->file, s->param);
	if (pipe(pipefd) == -1) {
		ERROR("Failed to create pipe\n");
		return;
	}

	pid = fork();
	if (pid < 0)
		return;

	if (pid) {
		close(pipefd[1]);
		s->fd.stream.string_data = true,
		s->fd.stream.notify_read = pipe_cb,
		runqueue_process_add(q, &s->proc, pid);
		ustream_fd_init(&s->fd, pipefd[0]);
		return;
	}
	close(pipefd[0]);
	dup2(pipefd[1], STDOUT_FILENO);
	dup2(pipefd[1], STDERR_FILENO);

	execlp(s->file, s->file, s->param, NULL);
	exit(1);
}
예제 #2
0
static void logread_fd_cb(struct ubus_request *req, int fd)
{
	static struct ustream_fd test_fd;

	test_fd.stream.notify_read = logread_fd_data_cb;
	ustream_fd_init(&test_fd, fd);
}
예제 #3
0
파일: syslog.c 프로젝트: fingon/procd
static int klog_open(void)
{
	int fd;

	DEBUG(1, "Opening %s\n", KLOG_DEFAULT_PROC);
	fd = open(KLOG_DEFAULT_PROC, O_RDONLY | O_NONBLOCK);
	if (fd < 0) {
		ERROR("Failed to open %s\n", KLOG_DEFAULT_PROC);
		return -1;
	}
	fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
	ustream_fd_init(&klog, fd);
	return 0;
}
예제 #4
0
파일: syslog.c 프로젝트: fingon/procd
static int syslog_open(void)
{
	int fd;

	DEBUG(1, "Opening %s\n", log_dev);
	unlink(log_dev);
	fd = usock(USOCK_UNIX | USOCK_UDP |  USOCK_SERVER | USOCK_NONBLOCK, log_dev, NULL);
	if (fd < 0) {
		ERROR("Failed to open %s\n", log_dev);
		return -1;
	}
	chmod(log_dev, 0666);
	ustream_fd_init(&slog, fd);
	return 0;
}
예제 #5
0
파일: tcp.c 프로젝트: lperkov/libsysrepo
static void connect_cb(struct uloop_fd *f, unsigned int events) 
{ 
	if (ufd.eof || ufd.error) { 
		_debug("connection to sysrepo failed"); 
		uloop_timeout_set(&reconnect_timer, 1000);
		return; 
	} 

	___debug("connection with sysrepo established"); 
	uloop_fd_delete(&ufd); 

	usfd.stream.string_data = true;
	usfd.stream.notify_read = read_cb;
	usfd.stream.notify_state = state_cb;
	usfd.stream.notify_write = write_cb;
	ustream_fd_init(&usfd, ufd.fd);

    usfd.stream.write_error = 0;

	u_tcp_printf("%07d\n%s\n", strlen(CUSTOM_XML_HELO) + 1, CUSTOM_XML_HELO);
	u_tcp_printf("%07d\n%s\n", strlen(CUSTOM_XML_SET_DATASTORE) + 1, CUSTOM_XML_SET_DATASTORE);
}
예제 #6
0
파일: main.c 프로젝트: lynxis/netifd
int
netifd_start_process(const char **argv, char **env, struct netifd_process *proc)
{
	int pfds[2];
	int pid;

	netifd_kill_process(proc);

	if (pipe(pfds) < 0)
		return -1;

	if ((pid = fork()) < 0)
		goto error;

	if (!pid) {
		int i;

		if (env) {
			while (*env) {
				putenv(*env);
				env++;
			}
		}
		if (proc->dir_fd >= 0)
			if (fchdir(proc->dir_fd)) {}

		close(pfds[0]);

		for (i = 0; i <= 2; i++) {
			if (pfds[1] == i)
				continue;

			dup2(pfds[1], i);
		}

		if (pfds[1] > 2)
			close(pfds[1]);

		execvp(argv[0], (char **) argv);
		exit(127);
	}

	if (pid < 0)
		goto error;

	close(pfds[1]);
	proc->uloop.cb = netifd_process_cb;
	proc->uloop.pid = pid;
	uloop_process_add(&proc->uloop);
	list_add_tail(&proc->list, &process_list);

	system_fd_set_cloexec(pfds[0]);
	proc->log.stream.string_data = true;
	proc->log.stream.notify_read = netifd_process_log_read_cb;
	ustream_fd_init(&proc->log, pfds[0]);

	return 0;

error:
	close(pfds[0]);
	close(pfds[1]);
	return -1;
}