コード例 #1
0
ファイル: send_event.c プロジェクト: AlainODea/illumos-gate
void
ADM_Process_send_event(int argc, char *argv[])
{
	rscp_msg_t		Message;
	struct timespec		Timeout;
	static data_buffer_t	DataBuffer;
	dp_send_alert_t		*Parms;
	char			*Alert;


	if ((argc != 3) && (argc != 4)) {
		usage();
		exit(-1);
	}
	if (argc == 4) {
		if (strcasecmp(argv[2],  "-c") != 0) {
			usage();
			exit(-1);
		}
	}

	ADM_Start();

	Parms = (dp_send_alert_t *)&DataBuffer;
	Alert = (char *)(&((char *)Parms)[sizeof (dp_send_alert_t)]);
	if (argc == 3) {
		Parms->critical = 0;
		(void) strcpy(Alert, argv[2]);
	} else {
		Parms->critical = 1;
		(void) strcpy(Alert, argv[3]);
	}
	if (strlen(Alert) > 80) {
		(void) fprintf(stderr, "\n%s\n\n",
		    gettext("scadm: event message can't exceed 80 characters"));
		exit(-1);
	}

	Message.type = DP_SEND_ALERT;
	Message.len  = sizeof (dp_send_alert_t) + strlen(Alert) + 1;
	Message.data = Parms;
	ADM_Send(&Message);

	Timeout.tv_nsec = 0;
	Timeout.tv_sec  = ADM_TIMEOUT;
	ADM_Recv(&Message, &Timeout, DP_SEND_ALERT_R,
	    sizeof (dp_send_alert_r_t));

	if (*(int *)Message.data != 0) {
		(void) fprintf(stderr, "\n%s\n\n",
		    gettext("scadm: could not send alert"));
		exit(-1);
	}

	ADM_Free(&Message);
}
コード例 #2
0
ファイル: eventlog.c プロジェクト: andreiw/polaris
static void
ADM_Process_old_event_log()
{
	char			timebuf[32];
	char			messBuff[256];
	char			eventMsgBuf[256];
	rscp_msg_t		Message;
	struct timespec		Timeout;
	dp_get_event_log_r_t	*rscReply;
	char			*datap;
	dp_event_log_entry_t	entry;
	int			i, len, entryhdrsize;

	ADM_Start();

	Message.type = DP_GET_EVENT_LOG;
	Message.len = 0;
	Message.data = NULL;
	ADM_Send(&Message);

	Timeout.tv_nsec = 0;
	Timeout.tv_sec  = ADM_TIMEOUT;
	ADM_Recv(&Message, &Timeout,
	    DP_GET_EVENT_LOG_R, sizeof (*rscReply));

	/* Print the event log messages */
	rscReply = (dp_get_event_log_r_t *)Message.data;
	datap = (char *)rscReply->data;
	for (i = 0; i < rscReply->entry_count; i++) {
		entryhdrsize = sizeof (entry) - sizeof (entry.param);
		(void) memcpy(&entry, datap, entryhdrsize);
		datap += entryhdrsize;
		(void) memcpy(&entry.param, datap, entry.paramLen);
		(void) strftime(timebuf, sizeof (timebuf), "%b %d %H:%M:%S",
		    gmtime((time_t *)&entry.eventTime));
		(void) sprintf(messBuff, "%s : %08lx: \"", timebuf,
		    entry.eventId);
		len = expandEventLogMessage(entry.eventId, entry.param,
		    entry.paramLen, eventMsgBuf);
		(void) strncat(messBuff, eventMsgBuf, len);
		(void) strcat(messBuff, "\"\r\n");
		(void) printf(messBuff);
		datap += entry.paramLen;
	}

	ADM_Free(&Message);
}
コード例 #3
0
ファイル: configlog.c プロジェクト: andreiw/polaris
void
ADM_Process_fru_log(int all)
{
	rscp_msg_t		Message;
	struct timespec		Timeout;
	dp_get_config_log_r_t	*rscReply;
	rsci64			bytes_remaining, seqno;
	rsci16			request_size, response_size;
	dp_get_config_log_t	rscCmd;

	ADM_Start();

	/*
	 * Start by sending a zero-length request to ALOM, so that
	 * we can learn the length of the console log.  We expect
	 * ALOM to return the length of the entire log.  We get
	 * a snapshot of the length of the log here - it may however
	 * continue to grow as we're reading it.  We read only as
	 * much of the log as we get in this snapshot.
	 */
	rscCmd.start_seq = 0;
	rscCmd.length = 0;
	Message.type = DP_GET_CONFIG_LOG;
	Message.len = sizeof (rscCmd);
	Message.data = (char *)&rscCmd;
	ADM_Send(&Message);

	Timeout.tv_nsec = 0;
	Timeout.tv_sec  = ADM_TIMEOUT;
	ADM_Recv(&Message, &Timeout,
	    DP_GET_CONFIG_LOG_R, sizeof (*rscReply));

	rscReply = (dp_get_config_log_r_t *)Message.data;

	/*
	 * If we do not want the whole log, and the log is bigger than
	 * the length limit, then fetch just the last ADM_DEFAULT_LOG_LENGTH
	 * bytes from the log.  Else just get the whole thing.
	 */
	if ((all == 0) && (rscReply->remaining_log_bytes >
	    ADM_DEFAULT_LOG_LENGTH)) {
		bytes_remaining = ADM_DEFAULT_LOG_LENGTH;
		seqno = (rscReply->remaining_log_bytes +
		    rscReply->next_seq) - bytes_remaining;
	} else {
		bytes_remaining = rscReply->remaining_log_bytes;
		seqno = rscReply->next_seq;
	}
	request_size = sizeof (rscReply->buffer);
	ADM_Free(&Message);

	/*
	 * Timeout for RSC response.
	 */
	Timeout.tv_nsec = 0;
	Timeout.tv_sec  = ADM_TIMEOUT;

	/*
	 * This loop runs as long as there is data in the log, or until
	 * we hit the default limit (above).  It's possible that ALOM may
	 * shrink the log - we need to account for this.  If ALOM returns
	 * no data, we bail out.
	 */
	while (bytes_remaining) {
		rscCmd.start_seq = seqno;
		rscCmd.length = (bytes_remaining < request_size) ?
		    bytes_remaining : request_size;
		Message.type = DP_GET_CONFIG_LOG;
		Message.len = sizeof (rscCmd);
		Message.data = (char *)&rscCmd;
		ADM_Send(&Message);

		ADM_Recv(&Message, &Timeout,
		    DP_GET_CONFIG_LOG_R, sizeof (*rscReply));

		rscReply = (dp_get_config_log_r_t *)Message.data;

		/* If ALOM returns zero bytes, we're done. */
		response_size = rscReply->length;
		if (response_size == 0) {
			ADM_Free(&Message);
			break;
		}
		bytes_remaining -= response_size;
		if (rscReply->remaining_log_bytes < bytes_remaining) {
			bytes_remaining = rscReply->remaining_log_bytes;
		}

		/*
		 * If the byte at the original sequence number is no
		 * longer in the log, print a message.
		 */
		if (rscReply->next_seq > seqno + response_size) {
			printf(gettext("\nscadm: lost %d bytes of log data\n"),
			    rscReply->next_seq - (seqno + response_size));
		}
		seqno = rscReply->next_seq;

		/* Print the config log */
		if (fwrite(rscReply->buffer, sizeof (char), response_size,
		    stdout) != response_size) {
			perror(gettext("\ncouldn't write config log buffer"
			    " to stdout"));
			ADM_Free(&Message);
			break;
		}
		ADM_Free(&Message);
	}
	putchar('\n');
}
コード例 #4
0
ファイル: eventlog.c プロジェクト: andreiw/polaris
static int
ADM_Process_new_event_log(int all)
{
	char			timebuf[32];
	char			messBuff[256];
	char			eventMsgBuf[256];
	rscp_msg_t		Message;
	struct timespec		Timeout;
	dp_get_event_log2_r_t	*rscReply;
	char			*datap;
	dp_event_log_entry_t	entry;
	int			i, len, entryhdrsize, sent_ok;
	rsci64			events_remaining, seqno;
	rsci16			request_size, returned_events;
	dp_get_event_log2_t	rscCmd;

	ADM_Start();

	/*
	 * Start by sending a zero-length request to ALOM, so that
	 * we can learn the length of the console log.  We expect
	 * ALOM to return the length of the entire log.  We get
	 * a snapshot of the length of the log here - it may however
	 * continue to grow as we're reading it.  We read only as
	 * much of the log as we get in this snapshot.
	 *
	 * If the command fails, we quietly return failure here so
	 * that the caller can re-try with the old/legacy command.
	 */
	rscCmd.start_seq = 0;
	rscCmd.length = 0;
	Message.type = DP_GET_EVENT_LOG2;
	Message.len = sizeof (rscCmd);
	Message.data = (char *)&rscCmd;
	if (ADM_Send_ret(&Message) != 0) {
		return (1);
	}

	Timeout.tv_nsec = 0;
	Timeout.tv_sec  = ADM_TIMEOUT;
	ADM_Recv(&Message, &Timeout,
	    DP_GET_EVENT_LOG2_R, sizeof (*rscReply));

	rscReply = (dp_get_event_log2_r_t *)Message.data;

	/*
	 * Fetch an fixed number of events from the end of
	 * the log if at least that many exist, and we were not
	 * asked to fetch all the events.
	 */
	if ((all == 0) &&
	    (rscReply->remaining_log_events > DEFAULT_NUM_EVENTS)) {
		events_remaining = DEFAULT_NUM_EVENTS;
		seqno = (rscReply->remaining_log_events +
		    rscReply->next_seq) - events_remaining;
	} else {
		events_remaining = rscReply->remaining_log_events;
		seqno = rscReply->next_seq;
	}
	request_size = sizeof (rscReply->buffer);
	ADM_Free(&Message);

	/*
	 * This loop runs as long as there is data in the log, or until
	 * we hit the default limit (above).  It's possible that ALOM may
	 * shrink the log - we need to account for this.  If ALOM returns
	 * no data, we bail out.
	 */
	while (events_remaining) {
		rscCmd.start_seq = seqno;
		rscCmd.length = request_size;
		Message.type = DP_GET_EVENT_LOG2;
		Message.len = sizeof (rscCmd);
		Message.data = (char *)&rscCmd;
		ADM_Send(&Message);

		Timeout.tv_nsec = 0;
		Timeout.tv_sec  = ADM_TIMEOUT;
		ADM_Recv(&Message, &Timeout,
		    DP_GET_EVENT_LOG2_R, sizeof (*rscReply));

		rscReply = (dp_get_event_log2_r_t *)Message.data;

		/* If ALOM returns zero events, we're done. */
		returned_events = rscReply->num_events;
		if (returned_events == 0) {
			ADM_Free(&Message);
			break;
		}

		/*
		 * if the event at the original sequence number is no
		 * longer in the log, print a message
		 */
		if (seqno + returned_events < rscReply->next_seq) {
			printf(gettext("\nscadm: lost %d events\n"),
			    rscReply->next_seq - (seqno + returned_events));
		}

		/*
		 * get ready for next main loop iteration
		 */
		seqno = rscReply->next_seq;
		events_remaining -= returned_events;

		/* Print the event log messages */
		datap = rscReply->buffer;

		for (i = 0; i < returned_events; i++) {
			entryhdrsize = sizeof (entry) - sizeof (entry.param);
			(void) memcpy(&entry, datap, entryhdrsize);
			datap += entryhdrsize;
			(void) memcpy(&entry.param, datap, entry.paramLen);
			(void) strftime(timebuf, sizeof (timebuf),
			    "%b %d %H:%M:%S",
			    gmtime((time_t *)&entry.eventTime));
			(void) sprintf(messBuff, "%s : %08lx: \"", timebuf,
			    entry.eventId);
			len = expandEventLogMessage(entry.eventId, entry.param,
			    entry.paramLen, eventMsgBuf);
			(void) strncat(messBuff, eventMsgBuf, len);
			(void) strcat(messBuff, "\"\r\n");
			(void) printf(messBuff);
			datap += entry.paramLen;
		}

		ADM_Free(&Message);
	}
	return (0);
}
コード例 #5
0
ファイル: status.c プロジェクト: AlainODea/illumos-gate
void
ADM_Process_status(int verbose)
{
	rscp_msg_t		Message;
	struct timespec		Timeout;
	dp_rsc_status_r_t	*rscStatus;


	ADM_Start();

	Message.type = DP_RSC_STATUS;
	Message.len  = 0;
	Message.data = NULL;
	ADM_Send(&Message);

	Timeout.tv_nsec = 0;
	Timeout.tv_sec  = ADM_TIMEOUT;
	ADM_Recv(&Message, &Timeout,
	    DP_RSC_STATUS_R, sizeof (dp_rsc_status_r_t));

	/* Print the status */
	rscStatus = (dp_rsc_status_r_t *)Message.data;
	(void) printf("\n");
	(void) printf("%s v%d.%d\n",
	    gettext("SC Version"),
	    rscStatus->release_rev_major, rscStatus->release_rev_minor);
	(void) printf("%s v%d.%d.%d\n",
	    gettext("SC Bootmon Version: "),
	    rscStatus->bootmon_rev_major, rscStatus->bootmon_rev_minor,
	    rscStatus->bootmon_rev_micro);
	if (verbose) {
		(void) printf("%s %08lX\r\n\n", gettext("SC Bootmon checksum:"),
		    rscStatus->bm_cksum);
	}

	(void) printf("%s v%d.%d.%d\n",
	    gettext("SC Firmware Version: "),
	    rscStatus->main_rev_major, rscStatus->main_rev_minor,
	    rscStatus->main_rev_micro);
	if (verbose) {
		(void) printf("%s %02d\r\n", gettext("SC Build Release:"),
		    rscStatus->rsc_build);
	}

	(void) printf("\n");


	if (verbose) {
		(void) printf("%s %08lX\r\n\n",
		    gettext("SC firmware checksum:"), rscStatus->fw_cksum);
		(void) printf("%s %s\r\n\n",
		    gettext("SC firmware built:"), rscStatus->creationDate);
		(void) printf("%s %ld%s\r\n\r\n",
		    gettext("SC System Memory Size:"), rscStatus->sys_mem,
		    gettext("MB"));
		(void) printf("%s %lx\r\n\r\n",
		    gettext("SC NVRAM Version ="), rscStatus->nvram_version);
	}
	/*
	 * Not currently implemented in firmware
	 * (void) printf("%s = %d\n",
	 *  gettext("Users currently logged in"), rscStatus->nusers);
	 */

	if (verbose) {
		/* 4388953 Display SC board type */
		(void) printf("%s %d\r\n\r\n",
		    gettext("SC hardware type:"), rscStatus->hardware_rev);
	}

	ADM_Free(&Message);
}