Example #1
0
static void domsr(int cpu, int msr, int bit)
{
	char fpath[32];
	unsigned long long data;
	int fd;

	sprintf(fpath, "/dev/cpu/%d/msr", cpu);
	fd = open(fpath, O_RDWR);
	if (fd == -1) {
		switch (errno) {
		case ENOENT:
			SYSERRprintf("Warning: cpu %d offline?, imc_log not set\n", cpu);
			return;
		default:
			SYSERRprintf("Cannot open %s to set imc_log\n", fpath);
			exit(1);
		}
	}
	if (pread(fd, &data, sizeof data, msr) != sizeof data) {
		SYSERRprintf("Cannot read MSR_ERROR_CONTROL from %s\n", fpath);
		exit(1);
	}
	data |= bit;
	if (pwrite(fd, &data, sizeof data, msr) != sizeof data) {
		SYSERRprintf("Cannot write MSR_ERROR_CONTROL to %s\n", fpath);
		exit(1);
	}
	if (pread(fd, &data, sizeof data, msr) != sizeof data) {
		SYSERRprintf("Cannot re-read MSR_ERROR_CONTROL from %s\n", fpath);
		exit(1);
	}
	if ((data & bit) == 0)
		Lprintf("No DIMM detection available on cpu %d (normal in virtual environments)\n", cpu);
	close(fd);
}
Example #2
0
char *read_field(char *base, char *name)
{
	char *fn, *val;
	int n, fd;
	struct stat st;
	char *s;
	char *buf = NULL;

	asprintf(&fn, "%s/%s", base, name);
	fd = open(fn, O_RDONLY);
	if (fstat(fd, &st) < 0)
		goto bad;		
	buf = xalloc(st.st_size);
	free(fn);
	if (fd < 0) 
		goto bad;
	n = read(fd, buf, st.st_size);
	close(fd);
	if (n < 0)
		goto  bad;
	val = xalloc(n);
	memcpy(val, buf, n);
	free(buf);
	s = strchr(val, '\n');
	if (s)
		*s = 0;
	return  val;

bad:
	SYSERRprintf("Cannot read sysfs field %s/%s", base, name);
	return xstrdup("");
}
Example #3
0
void bus_setup(void)
{
	bus_trigger = config_string("socket", "bus-uc-threshold-trigger");
	if (bus_trigger && trigger_check(bus_trigger) < 0) {
		SYSERRprintf("Cannot access bus threshold trigger `%s'",
				bus_trigger);
		exit(1);
	}

	iomca_trigger = config_string("socket", "iomca-threshold-trigger");
	if (iomca_trigger && trigger_check(iomca_trigger) < 0) {
		SYSERRprintf("Cannot access iomca threshold trigger `%s'",
				iomca_trigger);
		exit(1);
	}
}
Example #4
0
/* Send a command to the mcelog server and dump output */
void ask_server(char *command) 
{
	struct sockaddr_un sun;
	int fd;
	FILE * fp;
	int n;
	char buf[1024];
	char *path = config_string("server", "socket-path");
	if (!path)
		path = SOCKET_PATH;

	fd = socket(PF_UNIX, SOCK_STREAM, 0);
	if (fd < 0) {
		SYSERRprintf("client socket");
		return;
	}

	sun.sun_family = AF_UNIX;
	sun.sun_path[sizeof(sun.sun_path)-1] = 0;
	strncpy(sun.sun_path, path, sizeof(sun.sun_path)-1);

	if (connect(fd, (struct sockaddr *)&sun, 
			sizeof(struct sockaddr_un)) < 0)
		SYSERRprintf("client connect");
	
	n = strlen(command);
	if (write(fd, command, n) != n)
		SYSERRprintf("client command write");

	if ((fp = fdopen(fd, "r")) != NULL) {
		while (fgets(buf, sizeof buf, fp)) {
			n = strlen(buf);
			if (n >= 5 && !memcmp(buf + n - 5, "done\n", 5)) {
				fclose(fp);
				return;
			}

			fputs(buf, stdout);
		}
		fclose(fp);
	}

	SYSERRprintf("client read");
}
Example #5
0
int config_trigger(const char *header, const char *base, struct bucket_conf *bc)
{
	char *s;
	char *name;
	int n;

	asprintf(&name, "%s-threshold", base);
	s = config_string(header, name);
	if (s) {
		if (bucket_conf_init(bc, s) < 0) {
			unparseable("trigger", header, name);
			return -1;
		}
	}
	free(name);

	asprintf(&name, "%s-trigger", base);
	s = config_string(header, name);
	if (s) {
		/* no $PATH */
		if (trigger_check(s) != 0) {
			SYSERRprintf("Trigger `%s' not executable\n", s);
			exit(1);
		}
		bc->trigger = s;
	}
	free(name);

	bc->log = 0;
	asprintf(&name, "%s-log", base);
	n = config_bool(header, name);
	if (n >= 0)
		bc->log = n;
	free(name);

	return 0;
}