Ejemplo n.º 1
0
/* enqueue the the kernel message into the message queue.
 * The provided msg string is not freed - thus must be done
 * by the caller.
 * rgerhards, 2008-04-12
 */
static rsRetVal
enqMsg(uchar *msg, uchar* pszTag, syslog_pri_t pri, struct timeval *tp, struct json_object *json)
{
	struct syslogTime st;
	msg_t *pMsg;
	DEFiRet;

	assert(msg != NULL);
	assert(pszTag != NULL);

	if(tp == NULL) {
		CHKiRet(msgConstruct(&pMsg));
	} else {
		datetime.timeval2syslogTime(tp, &st);
		CHKiRet(msgConstructWithTime(&pMsg, &st, tp->tv_sec));
	}
	MsgSetFlowControlType(pMsg, eFLOWCTL_LIGHT_DELAY);
	MsgSetInputName(pMsg, pInputName);
	MsgSetRawMsgWOSize(pMsg, (char*)msg);
	MsgSetMSGoffs(pMsg, 0);	/* we do not have a header... */
	MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp());
	MsgSetRcvFromIP(pMsg, pLocalHostIP);
	MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName()));
	MsgSetTAG(pMsg, pszTag, ustrlen(pszTag));
	msgSetPRI(pMsg, pri);
	pMsg->json = json;
	CHKiRet(submitMsg(pMsg));

finalize_it:
	RETiRet;
}
Ejemplo n.º 2
0
/* enqueue the the kernel message into the message queue.
 * The provided msg string is not freed - thus must be done
 * by the caller.
 * rgerhards, 2008-04-12
 */
static rsRetVal
enqMsg(uchar *msg, uchar* pszTag, int iFacility, int iSeverity)
{
	DEFiRet;
	msg_t *pMsg;

	assert(msg != NULL);
	assert(pszTag != NULL);

	CHKiRet(msgConstruct(&pMsg));
	MsgSetFlowControlType(pMsg, eFLOWCTL_LIGHT_DELAY);
	MsgSetInputName(pMsg, pInputName);
	MsgSetRawMsgWOSize(pMsg, (char*)msg);
	MsgSetMSGoffs(pMsg, 0);	/* we do not have a header... */
	MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp());
	MsgSetRcvFromIP(pMsg, pLocalHostIP);
	MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName()));
	MsgSetTAG(pMsg, pszTag, ustrlen(pszTag));
	pMsg->iFacility = LOG_FAC(iFacility);
	pMsg->iSeverity = LOG_PRI(iSeverity);
	CHKiRet(submitMsg(pMsg));

finalize_it:
	RETiRet;
}
Ejemplo n.º 3
0
int32 ClientAgent::TimedSubmit(void* arg)
{
	BMessage* msg(reinterpret_cast<BMessage*>(arg));
	ClientAgent* agent;
	ClientWindow* window;
	BString buffer;
	int32 i;
	bool addtofHistory(true);

	if (msg->FindPointer("agent", reinterpret_cast<void**>(&agent)) != B_OK) {
		printf(":ERROR: no valid agent pointer found in TimedSubmit, bailing...\n");
		return -1;
	}

	if (msg->FindPointer("window", reinterpret_cast<void**>(&window)) != B_OK) {
		printf(":ERROR: no valid window pointer found in TimedSubmit, bailing...\n");
		return -1;
	}

	bool delay(!msg->HasBool("delay"));
	bool autoexec(msg->FindBool("autoexec"));
	if (autoexec) addtofHistory = false;

	BMessenger agentMsgr(agent);
	BMessage submitMsg(M_SUBMIT);
	submitMsg.AddBool("history", addtofHistory);
	submitMsg.AddBool("clear", false);

	for (i = 0; (msg->HasString("data", i)) && (agentMsgr.IsValid()) &&
					(false == agent->CancelMultilineTextPaste());
		 ++i) {
		BString data;

		msg->FindString("data", i, &data);

		// add a space so /'s don't get triggered as commands
		if (!autoexec) data.Prepend(" ");

		if (!submitMsg.HasString("input"))
			submitMsg.AddString("input", data);
		else
			submitMsg.ReplaceString("input", data);
		// :TODO: wade 020101 move locks to ParseCmd?
		if (agentMsgr.IsValid()) {
			agentMsgr.SendMessage(&submitMsg);

			// A small attempt to appease the
			// kicker gods
			if (delay) snooze(600000);
		}
	}

	delete msg;
	return 0;
}
Ejemplo n.º 4
0
/* This function receives data from a socket indicated to be ready
 * to receive and submits the message received for processing.
 * rgerhards, 2007-12-20
 * Interface changed so that this function is passed the array index
 * of the socket which is to be processed. This eases access to the
 * growing number of properties. -- rgerhards, 2008-08-01
 */
static rsRetVal
readLog(int fd, uchar *pRcv, int iMaxLine)
{
	DEFiRet;
	struct strbuf data;
	struct strbuf ctl;
	struct log_ctl hdr;
	int flags;
	msg_t *pMsg;
	int ret;
	char errStr[1024];

	data.buf = (char*)pRcv;
	data.maxlen = iMaxLine;
	ctl.maxlen = sizeof (struct log_ctl);
	ctl.buf = (caddr_t)&hdr;
	flags = 0;
	ret = getmsg(fd, &ctl, &data, &flags);
	if(ret < 0) {
		if(errno == EINTR) {
			FINALIZE;
		} else 	{
			int en = errno;
			rs_strerror_r(errno, errStr, sizeof(errStr));
			DBGPRINTF("imsolaris: stream input error on fd %d: %s.\n", fd, errStr);
			errmsg.LogError(en, NO_ERRCODE, "imsolaris: stream input error: %s", errStr);
			tryRecover();
		}	
	} else {
		DBGPRINTF("imsolaris: message from log stream %d: %s\n", fd, pRcv);
		pRcv[data.len] = '\0'; /* make sure it is a valid C-String */
		CHKiRet(msgConstruct(&pMsg));
		MsgSetInputName(pMsg, pInputName);
		MsgSetRawMsg(pMsg, (char*)pRcv, strlen((char*)pRcv));
		MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName()));
		pMsg->iFacility = LOG_FAC(hdr.pri);
		pMsg->iSeverity = LOG_PRI(hdr.pri);
		pMsg->msgFlags = NEEDS_PARSING | NO_PRI_IN_RAW;
		CHKiRet(submitMsg(pMsg));
	}

finalize_it:
	RETiRet;
}