Exemplo n.º 1
0
static int wproc_is_alive(struct wproc_worker *wp)
{
	if (!wp || !wp->pid)
		return 0;
	if (kill(wp->pid, 0) == 0 && iobroker_is_registered(nagios_iobs, wp->sd))
		return 1;
	return 0;
}
Exemplo n.º 2
0
static int echo_service(int fd, int events, void *arg)
{
	char buf[1024];
	int len;

	len = read(fd, buf, sizeof(buf));
	if (len < 0) {
		perror("read");
		iobroker_close(iobs, fd);
		ok_int(iobroker_is_registered(iobs, fd), 0, "Closing must deregister");
		return 0;
	}
	/* zero read means we're disconnected */
	if (!len) {
		iobroker_close(iobs, fd);
		ok_int(iobroker_is_registered(iobs, fd), 0, "Closing must deregister");
		return 0;
	}

	if (write(fd, buf, len) < 0)
		t_fail("write returned failure: %s", strerror(errno));

	return 0;
}
Exemplo n.º 3
0
static int listen_handler(int fd, int events, void *arg)
{
	int sock;
	struct sockaddr_in sain;
	socklen_t addrlen;

	if (!arg || arg != iobs) {
		printf("Argument passing seems to fail spectacularly\n");
	}

	addrlen = sizeof(sain);
	//printf("listen_handler(%d, %d, %p) called\n", fd, events, arg);
	sock = accept(fd, (struct sockaddr *)&sain, &addrlen);
	if (sock < 0) {
		perror("accept");
		return -1;
	}

	if (write(sock, msg[0], strlen(msg[0])) < 0)
		t_fail("write returned failure: %s", strerror(errno));
	iobroker_register(iobs, sock, iobs, echo_service);
	ok_int(iobroker_is_registered(iobs, sock), 1, "is_registered must be true");
	return 0;
}