Esempio n. 1
0
int main(int argc, char **argv)
{
	ssize_t ret;
	int fd;

	if (argc != 2) {
		fprintf(stderr, "usage: %s <kernel core file>\n", argv[0]);
		return 1;
	}
	fname = argv[1];

	fd = open(fname, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "Cannot open %s: %s\n",
			fname, strerror(errno));
		return 2;
	}
	ret = pread(fd, ehdr.e_ident, EI_NIDENT, 0);
	if (ret != EI_NIDENT) {
		fprintf(stderr, "Read of e_ident from %s failed: %s\n",
			fname, strerror(errno));
		return 3;
	}
	if (memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0) {
		fprintf(stderr, "Missing elf signature\n");
		return 4;
	}
	if (ehdr.e_ident[EI_VERSION] != EV_CURRENT) {
		fprintf(stderr, "Bad elf version\n");
		return 5;
	}
	if ((ehdr.e_ident[EI_CLASS] != ELFCLASS32) &&
	    (ehdr.e_ident[EI_CLASS] != ELFCLASS64))
	{
		fprintf(stderr, "Unknown elf class %u\n",
			ehdr.e_ident[EI_CLASS]);
		return 6;
	}
	if ((ehdr.e_ident[EI_DATA] != ELFDATA2LSB) &&
	    (ehdr.e_ident[EI_DATA] != ELFDATA2MSB))
	{
		fprintf(stderr, "Unkown elf data order %u\n",
			ehdr.e_ident[EI_DATA]);
		return 7;
	}
	if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
		read_elf32(fd);
	else
		read_elf64(fd);

	scan_note_headers(fd);
	dump_dmesg(fd);
	close(fd);

	return 0;
}
Esempio n. 2
0
void serve_client(int fd, parameters_t *pars)
{
	sockprint(fd, "Enter 'h' for help\r\n");

	for(;;)
	{
		int key;

		if (sockprint(fd, "emergency console > ") == -1)
			break;

		if ((key = readchar(fd)) == -1)
			break;

		if (key < 32 || key > 126)
		{
			if (sockprint(fd, "\r") == -1)
				break;
			continue;
		}

		if (sockprint(fd, "%c\r\n", key) == -1)
			break;

		switch(key)
		{
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
				if (set_dmesg_loglevel(fd, key - '0') == -1)
					return;
				break;

			case 'd':
				if (dump_virtual_console(fd, pars -> vcsa0_fd) == -1)
					return;
				break;

			case '?':
			case 'h':
				if (ec_help(fd) == -1)
					return;
				break;

			case 'i':
				if (dump_loadavg(fd) == -1)
					return;
				break;

			case 'j':
				if (kill_one_proc(fd) == -1)
					return;
				break;

			case 'k':
				if (kill_procs(fd) == -1)
					return;
				break;

			case 'l':
				if (dump_dmesg(fd, pars -> dmesg_buffer, pars -> dmesg_buffer_size, 0) == -1)
					return;
				break;

			case 'm':
				if (dump_dmesg(fd, pars -> dmesg_buffer, pars -> dmesg_buffer_size, 1) == -1)
					return;
				break;

			case 'p':
				if (dump_ps(fd) == -1)
					return;
				break;

			case 'q':
				return;

			case 10:
			case 13:
				break;
			default:
				if (isupper(key))
					do_sysreq(fd, tolower(key), pars -> sysrq_fd);
				else
					sockprint(fd, "'%c' is not understood\r\n", key);
				break;
		}
	}
}