Beispiel #1
0
int send_counters(const char *client, struct cntr *p1cntr, struct cntr *cntr)
{
	char buf[4096]="";
	counters_to_str(buf, sizeof(buf),
		client,
		STATUS_RUNNING,
		" " /* normally the path for status server */,
		p1cntr, cntr);
	if(async_write_str(CMD_GEN, buf))
	{
		logp("Error when sending counters to client.\n");
		return -1;
	}
	return 0;
}
Beispiel #2
0
void write_status(const char *client, char phase, const char *path, struct cntr *p1cntr, struct cntr *cntr)
{
	static time_t lasttime=0;
	if(status_wfd>=0 && client)
	{
		char *w=NULL;
		time_t now=0;
		time_t diff=0;
		static char wbuf[1024]="";

		// Only update every 2 seconds.
		now=time(NULL);
		diff=now-lasttime;
		if(diff<2)
		{
			// Might as well do this in case they fiddled their
			// clock back in time.
			if(diff<0) lasttime=now;
			return;
		}
		lasttime=now;

		counters_to_str(wbuf, sizeof(wbuf),
			client, phase, path, p1cntr, cntr);

		w=wbuf;
		while(*w)
		{
			size_t wl=0;
			if((wl=write(status_wfd, w, strlen(w)))<0)
			{
				logp("error writing status down pipe to server: %s\n", strerror(errno));
				close_fd(&status_wfd);
				break;
			}
			w+=wl;
		}
	}
}