Ejemplo n.º 1
0
int
main(int argc, char *argv[])
{
	struct cmd_opts opts;
	int rc;

	switch (get_platform()) {
	case PLATFORM_UNKNOWN:
	case PLATFORM_POWERNV:
		fprintf(stderr, "%s: is not supported on the %s platform\n",
						argv[0], platform_name);
		exit(1);
	}

	/* make sure that we're running on the proper platform.	*/
	if (! valid_platform("chrp"))
		exit(1);

	memset(&opts, 0, sizeof(opts));

	/* default to DRSLOT type */
	opts.slot_type = SLOT;
	parse_options(argc, argv, &opts);

	rc = dr_lock();
	if (rc) {
		say(ERROR, "Unable to obtain Dynamic Reconfiguration lock. "
		    "Please try command again later.\n");
		exit(1);
	}

	switch (opts.slot_type) {
	    case SLOT:
	    case PCI:
		rc = lsslot_chrp_pci(&opts);
		break;

	    case PHB:
		rc = lsslot_chrp_phb(&opts);
		break;

	    case CPU:
		rc = lsslot_chrp_cpu(&opts);
		break;

	    case MEM:
		rc = lsslot_chrp_mem(&opts);
		break;

	    case PORT:
		rc = lsslot_chrp_port(&opts);
		break;
	}

	free_drc_info();
	dr_unlock();
	exit(rc);
}
Ejemplo n.º 2
0
/**
 * dr_init
 * @brief Initialization routine for drmgr and lsslot
 *
 */
inline int dr_init(void)
{
	int rc;

	rc = dr_lock();
	if (rc) {
		say(ERROR, "Unable to obtain Dynamic Reconfiguration lock. "
		    "Please try command again later.\n");
		return -1;
	}


	log_fd = open(DR_LOG_PATH, O_RDWR | O_CREAT | O_APPEND,
		      S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
	if (log_fd == -1) {
		log_fd = 0;
		say(ERROR, "Could not open log file %s\n\t%s\n", DR_LOG_PATH,
		    strerror(errno));
	} else {
		time_t t;
		char tbuf[128];

		/* Insert seperator at beginning of drmgr invocation */
		time(&t);
		strftime(tbuf, 128, "%b %d %T %G", localtime(&t));
		say(DEBUG, "\n########## %s ##########\n", tbuf);
	}

	/* Mask signals so we do not get interrupted */
	if (sig_setup()) {
		say(ERROR, "Could not mask signals to avoid interrupts\n");
		if (log_fd)
			close(log_fd);
		dr_unlock();
		return -1;
	}

	rc = check_kmods();
	if (rc) {
		if (log_fd)
			close(log_fd);
		dr_unlock();
	}

	return rc;
}