Пример #1
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;
}
Пример #2
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);
}
Пример #3
0
/**
 * dr_fini
 * @brief Cleanup routine for drmgr and lsslot
 *
 */
inline void
dr_fini(void)
{
	struct stat sbuf;
	int max_dr_log_sz = 25000;
	int rc;
	time_t t;
	char tbuf[128];

	free_drc_info();

	if (! log_fd)
		return;

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

	close(log_fd);

	/* Check for log rotation */
	rc = stat(DR_LOG_PATH, &sbuf);
	if (rc) {
		fprintf(stderr, "Cannot determine log size to check for "
			"rotation:\n\t%s\n", strerror(errno));
		return;
	}

	if (sbuf.st_size >= max_dr_log_sz) {
		fprintf(stderr, "Rotating logs...\n");

		rc = unlink(DR_LOG_PATH0);
		if (rc && (errno != ENOENT)) {
			fprintf(stderr, "Could not remove %s\n\t%s\n",
				DR_LOG_PATH0, strerror(errno));
			return;
		}

		rc = rename(DR_LOG_PATH, DR_LOG_PATH0);
		if (rc) {
			fprintf(stderr, "Could not rename %s to %s\n\t%s\n",
				DR_LOG_PATH, DR_LOG_PATH0, strerror(errno));
			return;
		}
	}

	dr_unlock();
}