Example #1
0
/* Log file system related error in key-value format identified by Apple 
 * system log (ASL) facility.  The key-value pairs are string pointers 
 * (char *) and are provided as variable arguments list.  A NULL value 
 * indicates end of the list.
 *
 * Keys can not contain '[', ']', space, and newline.  Values can not 
 * contain '[', ']', and newline.  If any key-value contains any of the 
 * reserved characters, the behavior is undefined.  The caller of the 
 * function should escape any occurrences of '[' and ']' by prefixing
 * it with '\'.
 * 
 * The function takes a message ID which can be used to logically group
 * different ASL messages.  Messages in same logical group have same message
 * ID and have information to describe order of the message --- first, 
 * middle, or last.
 *
 * The following message IDs have special meaning - 
 * FSLOG_MSG_FIRST - This message is the first message in its logical
 *	group.  This generates a unique message ID, creates two key-value 
 *	pairs with message ID and order of the message as "First".
 * FSLOG_MSG_LAST - This is really a MASK which should be logically OR'ed 
 *	with message ID to indicate the last message for a logical group.  
 *	This also creates two key-value pairs with message ID and order of 
 *	message as "Last".
 * FSLOG_MSG_SINGLE - This signifies that the message is the only message
 * 	in its logical group.  Therefore no extra key-values are generated 
 *	for this option.
 * For all other values of message IDs, it regards them as intermediate 
 * message and generates two key-value pairs with message ID and order of
 * message as "Middle".
 * 
 * Returns - 
 *	Message ID of the ASL message printed.  The caller should use
 * 	this value to print intermediate messages or end the logical message
 *	group.
 *	For FSLOG_MSG_SINGLE option, it returns FSLOG_MSG_SINGLE. 
 */
unsigned long fslog_err(unsigned long msg_id, ... )
{
	va_list ap;
	int num_pairs;
	char msg_id_str[21]; /* To convert 64-bit number to string with NULL char */
	char *arg;
	const char *msg_order_ptr;

	/* Count number of arguments and key-value pairs provided by user */
	num_pairs = 0;
	va_start(ap, msg_id);
	arg = va_arg(ap, char *);
	while (arg) {
		num_pairs++;
		arg = va_arg(ap, char *);
	}
	num_pairs /= 2;
	va_end(ap);

	va_start(ap, msg_id);
	if (msg_id == FSLOG_MSG_SINGLE) {
		/* Single message, do not print message ID and message order */
		(void) fslog_asl_msg(FSLOG_VAL_LEVEL, FSLOG_VAL_FACILITY, 
				num_pairs, ap, NULL);
	} else {
		if (msg_id == FSLOG_MSG_FIRST) {
			/* First message, generate random message ID */
			while ((msg_id == FSLOG_MSG_FIRST) ||
			       (msg_id == FSLOG_MSG_LAST) ||
			       (msg_id == FSLOG_MSG_SINGLE)) {
				msg_id = RandomULong();
				/* MSB is reserved for indicating last message 
				 * in sequence.  Clear the MSB while generating
				 * new message ID.
				 */
				msg_id = msg_id >> 1;
			}
			msg_order_ptr = FSLOG_VAL_ORDER_FIRST;
		} else if (msg_id & FSLOG_MSG_LAST) { 
			/* MSB set to indicate last message for this ID */
			msg_order_ptr = FSLOG_VAL_ORDER_LAST;
			/* MSB of message ID is set to indicate last message
			 * in sequence.  Clear the bit to get real message ID.
			 */
			msg_id = msg_id & ~FSLOG_MSG_LAST;
		} else {
			/* Intermediate message for this ID */
			msg_order_ptr = FSLOG_VAL_ORDER_MIDDLE;
		}

		snprintf(msg_id_str, sizeof(msg_id_str), "%lu", msg_id);
		(void) fslog_asl_msg(FSLOG_VAL_LEVEL, FSLOG_VAL_FACILITY, 
			 num_pairs, ap, 
			 FSLOG_KEY_MSG_ID, msg_id_str, 
			 FSLOG_KEY_MSG_ORDER, msg_order_ptr, NULL);
	}
Example #2
0
static u_int32_t
sfb_random(struct sfb *sp)
{
	IFCQ_CONVERT_LOCK(&sp->sfb_ifp->if_snd);
	return (RandomULong());
}