Пример #1
0
int
fmtmsg(long classification, const char *label, int severity,
	const char *text, const char *action, const char *tag)
{
	FILE *console;
	const char *p, *sevstr;
	int result;

	/* Validate label constraints, if not null. */
	if (label != MM_NULLLBL) {
		/*
		 * Two fields, separated by a colon.  The first field is up to
		 * 10 bytes, the second is up to 14 bytes.
		 */
		p = strchr(label, ':');
		if (p ==  NULL || p - label > 10 || strlen(p + 1) > 14)
			return (MM_NOTOK);
	}
	/* Validate severity argument. */
	if ((sevstr = severity2str(severity)) == NULL)
		return (MM_NOTOK);

	/*
	 * Fact in search for a better place: XSH5 does not define any
	 * functionality for `classification' bits other than the display
	 * subclassification.
	 */

	result = 0;

	if (classification & MM_PRINT) {
		if (writeit(stderr, msgverb(getenv("MSGVERB")),
		    label, sevstr, text, action, tag) < 0)
			result |= MM_NOMSG;
	}
	/* Similar to MM_PRINT but ignoring $MSGVERB. */
	if (classification & MM_CONSOLE) {
		if ((console = fopen(_PATH_CONSOLE, "w")) != NULL) {
			if (writeit(console, MM_VERBALL,
			    label, sevstr, text, action, tag) < 0)
				result |= MM_NOCON;
			/*
			 * Ignore result: does not constitute ``generate a
			 * console message.''
			 */
			(void)fclose(console);
		} else {
			result |= MM_NOCON;
		}
	}

	if (result == (MM_NOMSG | MM_NOCON))
		result = MM_NOTOK;

	return (result == 0 ? MM_OK : result);
}
Пример #2
0
SaErrorT discover_domain(SaHpiDomainIdT domain_id, SaHpiSessionIdT session_id, SaHpiRptEntryT entry)
{
	
	SaErrorT	err;
	SaHpiRptInfoT	rpt_info_before;
	SaHpiRptInfoT   rpt_info_after;
	SaHpiEntryIdT	current;
	SaHpiEntryIdT   next;

        err = saHpiResourcesDiscover(session_id);
        if (SA_OK != err) {
                error("saHpiResourcesDiscover", err);
                return err;
        }
 	warn("list_resources: discover done");       
        /* grab copy of the update counter before traversing RPT */
        err = saHpiRptInfoGet(session_id, &rpt_info_before);
        if (SA_OK != err) {
                error("saHpiRptInfoGet", err);
                return err;
        }
        
        warn("Scanning RPT...");
        next = SAHPI_FIRST_ENTRY;
        do {
                char tmp_epath[128];
                current = next;
                err = saHpiRptEntryGet(session_id, current, &next, &entry);
                if (SA_OK != err) {
                        if (current != SAHPI_FIRST_ENTRY) {
                                error("saHpiRptEntryGet", err);
                                return err;
                        } else {
                                warn("Empty RPT\n");
                                break;
                        }
                }

		printf("***Records:\n");
                printf("%s\n", (char *)entry.ResourceTag.Data);
                printf("Entry ID: %d\n", (int) entry.EntryId);
                printf("Resource ID: %d\n", (int) entry.ResourceId);
                printf("Domain ID: %d\n", (int) entry.DomainId);
                printf("Revision: %c\n", entry.ResourceInfo.ResourceRev);
                printf("Version: %c\n", entry.ResourceInfo.SpecificVer);
		printf("Device Support: %d\n", entry.ResourceInfo.DeviceSupport);
		printf("Manufacturer ID: %d\n", (int) entry.ResourceInfo.ManufacturerId);
		printf("Product ID: %d\n", (int) entry.ResourceInfo.ProductId);
		printf("Firmware Major, Minor, Aux: %d %d %d\n", 
		       entry.ResourceInfo.FirmwareMajorRev, 
		       entry.ResourceInfo.FirmwareMinorRev,
		       entry.ResourceInfo.AuxFirmwareRev);
                printf("Severity: %s\n",severity2str(entry.ResourceSeverity));
                
                rpt_cap2str(entry.ResourceCapabilities);
                                
                printf("Entity Path:\n");
                entitypath2string(&entry.ResourceEntity, tmp_epath, sizeof(tmp_epath));
                printf("\t%s\n", tmp_epath);
                printf("\tResourceTag: ");
                       display_textbuffer(entry.ResourceTag);

                if (entry.ResourceCapabilities & SAHPI_CAPABILITY_RDR)
                        list_rdr(session_id, entry.ResourceId);

                if (entry.ResourceCapabilities & SAHPI_CAPABILITY_SEL)
                        list_sel(session_id, entry.ResourceId);
#if 0
                /* if the resource is also a domain, then 
                 * traverse its RPT */        
                if (entry.ResourceCapabilities & SAHPI_CAPABILITY_DOMAIN) {
                        err = discover_domain(entry.DomainId);
                        if (SA_OK != err)
                                return err;
                }
#endif
                printf("\tEntryId: %d\n", next);
        } while (next != SAHPI_LAST_ENTRY);

	printf("SAHPI_LAST_ENTRY\n");
		
        /* wait for update in RPT */
        while (1) {
                err = saHpiRptInfoGet(session_id, &rpt_info_after);
                if (SA_OK != err) {
                        error("saHpiRptInfoGet", err);
                        return err;
                }
                if (rpt_info_before.UpdateCount != rpt_info_after.UpdateCount) {
                        rpt_info_before = rpt_info_after;
                } else
			break;
        };

        return SA_OK;
}
Пример #3
0
void list_sel(SaHpiSessionIdT session_id, SaHpiResourceIdT resource_id)
{
        char str[256];

        printf("SEL Info:\n");

        SaHpiSelInfoT info;        
        SaErrorT rv = saHpiEventLogInfoGet(session_id, resource_id, &info);

        if (rv != SA_OK) {
                printf( "Error=%d reading SEL info\n", rv);
                return;
        }

        printf("\tEntries in SEL: %d\n", info.Entries);
        printf("\tSize: %d\n", info.Size);

        time2str(info.UpdateTimestamp, str);
        printf("\tUpdateTimestamp: %s\n", str);

        time2str(info.CurrentTime, str);
        printf("\tCurrentTime    : %s\n", str);
        printf("\tEnabled: %s\n", info.Enabled ? "true" : "false");
        printf("\tOverflowFlag: %s\n", info.OverflowFlag ? "true" : "false");
        printf("\tOverflowAction: " );

        switch(info.OverflowAction) {
        case SAHPI_SEL_OVERFLOW_DROP:
                printf("SAHPI_SEL_OVERFLOW_DROP\n");
                break;

        case SAHPI_SEL_OVERFLOW_WRAP:
                printf("SAHPI_SEL_OVERFLOW_WRAP\n");
                break;

        case SAHPI_SEL_OVERFLOW_WRITELAST:
                printf("SAHPI_SEL_OVERFLOW_WRITELAST\n");
                break;

        default:
                printf("unknown(0x%x)\n", info.OverflowAction);
                break;
        }

        printf("\tDeleteEntrySupported: %s\n", info.DeleteEntrySupported ? "true" : "false" );

		if (info.Entries == 0)
				return;
		//else 
        // read sel records
        SaHpiSelEntryIdT current = SAHPI_OLDEST_ENTRY;

        do {
                SaHpiSelEntryIdT prev;
                SaHpiSelEntryIdT next;
                SaHpiSelEntryT   entry;
                SaHpiRdrT        rdr;
                SaHpiRptEntryT   res;

                rv = saHpiEventLogEntryGet(session_id, resource_id, current, &prev, &next, &entry, &rdr, &res);

                if (rv != SA_OK) {
                        printf( "Error=%d reading SEL entry %d\n", rv, current);
                        return;
                }

                printf("\t\tEntry %d, prev %d, next %d\n", entry.EntryId, prev, next);
                time2str(entry.Timestamp, str);
                printf("\t\t\tTimestamp:            %s\n", str);

                SaHpiRptEntryT rres;

                rv = saHpiRptEntryGetByResourceId(session_id, entry.Event.Source, &rres );

                if ( rv != SA_OK )
                printf("\t\t\tSource:               unknown\n" );
                else {
                        entitypath2string( &rres.ResourceEntity, str, sizeof(str));
                printf("\t\t\tSource:               %s\n", str );
                }

                printf("\t\t\tEventType:            %s\n", eventtype2str(entry.Event.EventType));
                time2str(entry.Timestamp, str);
                printf("\t\t\tEvent timestamp:      %s\n", str);
                printf("\t\t\tSeverity:             %s\n", severity2str( entry.Event.Severity ) );

                switch(entry.Event.EventType) {
                case SAHPI_ET_SENSOR:
                        {
                                SaHpiSensorEventT *se = &entry.Event.EventDataUnion.SensorEvent;
                printf("\t\t\tSensorNum:            %d\n", se->SensorNum );
                printf("\t\t\tSensorType:           %s\n", get_sensor_type(se->SensorType ) );
                printf("\t\t\tEventCategory:        %s\n", get_sensor_category( se->EventCategory ) );
                printf("\t\t\tAssertion:            %s\n", se->Assertion ? "TRUE" : "FALSE" );
                        }

                        break;

                case SAHPI_ET_HOTSWAP:
                        {
                                SaHpiHotSwapEventT *he = &entry.Event.EventDataUnion.HotSwapEvent;
                printf("\t\t\tHotSwapState:         %s\n",
                                      hotswapstate2str( he->HotSwapState ) );
                printf("\t\t\tPreviousHotSwapState: %s\n",
                                        hotswapstate2str( he->PreviousHotSwapState ) );
                        }

                        break;

                case SAHPI_ET_WATCHDOG:
                        break;

                case SAHPI_ET_OEM:
                        break;

                case SAHPI_ET_USER:
                        break;
                }
                
                current = next;
        } while(current != SAHPI_NO_MORE_ENTRIES);
}
Пример #4
0
SaErrorT discover_domain(SaHpiDomainIdT domain_id)
{
	SaErrorT 	err;
	SaHpiSessionIdT session_id;
	SaHpiRptInfoT	rpt_info_before;
	SaHpiRptInfoT	rpt_info_after;
	SaHpiEntryIdT	current;
	SaHpiEntryIdT	next = SAHPI_FIRST_ENTRY;
	SaHpiRptEntryT	entry;
	
	if (next == SAHPI_LAST_ENTRY)
		return SA_OK;

	/* every domain requires a new session */
  	err = saHpiSessionOpen(domain_id, &session_id, NULL);
	if (SA_OK != err) {
		error("saHpiSessionOpen", err);
		return err;
	}

	/* force regeneration of the RPT */
 	err = saHpiResourcesDiscover(session_id);
	if (SA_OK != err) {
		error("saHpiResourcesDiscover", err);
		return err;
	}

	/* grab copy of the update counter before traversing RPT */
	err = saHpiRptInfoGet(session_id, &rpt_info_before);
	if (SA_OK != err) {
		error("saHpiRptInfoGet", err);
		return err;
	}

	do {
		int i;
		current = next;
		err = saHpiRptEntryGet(session_id, current, &next, &entry);
		if (SA_OK != err) {
			error("saHpiRptEntryGet", err);
			return err;
		}

		printf("%s\n", (char *)entry.ResourceTag.Data);
		printf("Entry ID: %x\n", (int) entry.EntryId);
		printf("Resource ID: %x\n", (int) entry.ResourceId);
		printf("Domain ID: %x\n", (int) entry.DomainId);
		printf("Revision: %c\n", entry.ResourceInfo.ResourceRev);
		printf("Version: %c\n", entry.ResourceInfo.SpecificVer);
		printf("Severity: %s\n",severity2str(entry.ResourceSeverity));

		printf("Entity Path:\n");
		for ( i=0; i<SAHPI_MAX_ENTITY_PATH; i++ )
		{
			SaHpiEntityT tmp = entry.ResourceEntity.Entry[i];
			if (tmp.EntityType <= SAHPI_ENT_UNSPECIFIED)
				break;

			printf("\t{%s, %i}\n", type2string(tmp.EntityType),
			       tmp.EntityInstance);
		}

		display_entity_capabilities(entry.ResourceCapabilities);
		printf("\n");

		/* if the resource is also a domain, then 
		 * traverse its RPT */	
		if (entry.ResourceCapabilities & SAHPI_CAPABILITY_DOMAIN) {
			err = discover_domain(entry.DomainId);
			if (SA_OK != err)
				return err;
		}
	} while (next != SAHPI_LAST_ENTRY);

	/* get a copy of update counter to see if we missed anything */
	err = saHpiRptInfoGet(session_id, &rpt_info_after);
	if (SA_OK != err) {
		error("saHpiRptInfoGet", err);
		return err;
	}

	if (rpt_info_after.UpdateCount != rpt_info_before.UpdateCount) {
		err = SA_ERR_HPI_ERROR;
		error("RPT table changed while obtaining resource info", err);
		return err;
	}

	return SA_OK;
}