Пример #1
0
static void process(void)
{
	xmlNode *cur_node;
	xmlNode *status;
	int rc;
	struct assembly *assembly;
	qb_map_iter_t *iter;
	static xmlNode *pe_root;

	qb_enter();

	/*
	 * Remove status descriptor
	 */
	pe_root = xmlDocGetRootElement(_pe);
	for (cur_node = pe_root->children; cur_node; cur_node = cur_node->next) {
		if (cur_node->type == XML_ELEMENT_NODE &&
			strcmp((char*)cur_node->name, "status") == 0) {

			xmlUnlinkNode(cur_node);
			xmlFreeNode(cur_node);
			break;
		}
	}

	status = xmlNewChild(pe_root, NULL, BAD_CAST "status", NULL);
	iter = qb_map_iter_create(assembly_map);
	while ((qb_map_iter_next(iter, (void **)&assembly)) != NULL) {
		insert_status(status, assembly);
	}
	qb_map_iter_free(iter);

	rc = pe_process_state(_pe, resource_execute_cb,
			      transition_completed_cb,
			      NULL, cape_debug);

	if (rc != 0) {
		schedule_processing();
	}

	qb_leave();
}
Пример #2
0
//void mrsend(char *p)
void mrsend(char *machine, char *test, char *color, char *message)
{
	struct display *mp;
	struct sockaddr_in my_addr;
	struct linger l_optval;
	unsigned long nonblock;

	char *p = NULL;
	int is;

	if (debug > 1) mrlog("mrsend(%s, %s, %s, %s)", machine, test, color, message);
#if 0
	n = sscanf(p, "status %199[^.].%99[^ ] %99s",
		   machine, test, color);
	if (n != 3) {
		mrlog("Bogus string in mrsend, process anyway");
		if (debug) mrlog("%s", p);
	}
#endif
	is = insert_status(machine, test, color);
	if (is == 0) {
		if (debug) mrlog("mrsend: no change, nothing to do");
		return;
	}
	if (!start_winsock()) return;

	/* Prepare the report */
	p = big_malloc("mrsend()", report_size+1);
	p[0] = '\0';
	if (is == 1) {
		snprcat(p, report_size, "status %s.%s green %s",
			machine, test, message);
	} else {
		snprcat(p, report_size, "status %s.%s %s %s",
			machine, test, color, message);
	}

	for (mp = mrdisplay; mp; mp = mp->next) {
		mp->s = -1;
	}
	for (mp = mrdisplay; mp; mp = mp->next) {
		mp->s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
		if (mp->s == -1) {
			mrlog("mrsend: socket failed: %d", WSAGetLastError());
			continue;
		}

		memset(&my_addr, 0, sizeof(my_addr));
		my_addr.sin_family = AF_INET;
		my_addr.sin_port = 0;
		my_addr.sin_addr.s_addr = inet_addr(bind_addr);
		if (bind(mp->s, (struct sockaddr *)&my_addr, sizeof my_addr) < 0) {
			mrlog("mrsend: bind(%s) failed: [%d]", bind_addr, WSAGetLastError());
			closesocket(mp->s);
			mp->s = -1;
			continue;
		}

		l_optval.l_onoff = 1;
		l_optval.l_linger = 5;
		nonblock = 1;
		if (ioctlsocket(mp->s, FIONBIO, &nonblock) == SOCKET_ERROR) {
			mrlog("mrsend: ioctlsocket failed: %d", WSAGetLastError());
			closesocket(mp->s);
			mp->s = -1;
			continue;
		}
		if (setsockopt(mp->s, SOL_SOCKET, SO_LINGER, (const char*)&l_optval, sizeof(l_optval)) == SOCKET_ERROR) {
			mrlog("mrsend: setsockopt failed: %d", WSAGetLastError());
			closesocket(mp->s);
			mp->s = -1;
			continue;
		}

		if (debug) mrlog("Using address %s, port %d\n",
				inet_ntoa(mp->in_addr.sin_addr),
				ntohs(mp->in_addr.sin_port));
		if (connect(mp->s, (struct sockaddr *)&mp->in_addr, sizeof(mp->in_addr)) == SOCKET_ERROR) {
			if (WSAGetLastError() != WSAEWOULDBLOCK) {
				mrlog("mrsend: connect: %d", WSAGetLastError());
				l_optval.l_onoff = 0;
				l_optval.l_linger = 0;
				setsockopt(mp->s, SOL_SOCKET, SO_LINGER, (const char*)&l_optval, sizeof(l_optval));
				closesocket(mp->s);
				mp->s = -1;
				continue;
			}
		}

		mp->pdata = p;
		mp->remaining = strlen(p);
	}

	time_t start_time = time(NULL);

	for(;;) {
		struct timeval timeo;
		fd_set wfds;
		int len;
		int tot_remaining;
		timeo.tv_sec = 1;
		timeo.tv_usec = 0;
		FD_ZERO(&wfds);
		tot_remaining = 0;
		for (mp = mrdisplay; mp; mp = mp->next) {
			if (mp->s != -1) {
				if (mp->remaining > 0) {
					FD_SET(mp->s, &wfds);
					tot_remaining += mp->remaining;
				}
			}
		}
		if (tot_remaining == 0) {
			/* all data sent to displays */
			goto cleanup;
		}
		if (time(NULL) > start_time + 10 || time(NULL) < start_time) {
			mrlog("mrsend: send loop timed out");
			/* this should not take more than 10 seconds. Network problem, so bail out */
			goto cleanup;
		}
		select(255 /* ignored on winsock */, NULL, &wfds, NULL, &timeo);
		for (mp = mrdisplay; mp; mp = mp->next) {
			if (mp->s != -1) {
				if (mp->remaining > 0) {
					len = send(mp->s, mp->pdata, mp->remaining, 0);
					if (len == SOCKET_ERROR) {
						continue;
					}
					mp->pdata += len;
					mp->remaining -= len;
					if (mp->remaining == 0) {
						shutdown(mp->s, SD_BOTH);
					}
				}
			}
		}
	}

	cleanup:

	/* initiate socket shutdowns */
	for (mp = mrdisplay; mp; mp = mp->next) {
		if (mp->s != -1) {
			shutdown(mp->s, SD_BOTH);
		}
	}
	/* gracefully terminate sockets, finally applying force */
	for (mp = mrdisplay; mp; mp = mp->next) {
		int i;
		if (mp->s != -1) {
			for (i = 0; i < 10; i++) {
				if (closesocket(mp->s) == WSAEWOULDBLOCK) {
					Sleep(1000); /* wait for all data to be sent */
				}
			}
			/* force the socket shut */
			l_optval.l_onoff = 0;
			l_optval.l_linger = 0;
			setsockopt(mp->s, SOL_SOCKET, SO_LINGER, (const char*)&l_optval, sizeof(l_optval));
			closesocket(mp->s);
			mp->s = -1;
		}
	}
	big_free("mrsend()", p);
}