public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Crutcher Dunnavant <crutcher@redhat.com>
To: linux-kernel@vger.kernel.org
Subject: update to SysRQ patch
Date: Tue, 31 Oct 2000 11:12:38 -0500	[thread overview]
Message-ID: <20001031111238.A23294@devserv.devel.redhat.com> (raw)

Oops, the second example module I posted did bad things on 
SMP based machines, so here is a respin of it:


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sysrq.h>

/*
 * This is a example of some of the more complex things that
 * the SysRQ registration patch makes possible
 */

void dumpfake_handler (int key, struct pt_regs *pt_regs,
			struct kbd_struct *kbd, struct tty_struct *tty) {
	int i = key - '0';
	printk("<1>Dump fake-device %d\n00 A2 F4 9C 8D 01 34 42\n", i);
}

struct sysrq_key_op dumpfake_op = {
	handler:	dumpfake_handler,
	help_msg:	"dump-fake0-9",
	action_msg:	"Dumping Fake Device\n"
};

struct sysrq_key_op *op_stash[10];
int overloaded = 0;

void overload_handler (int, struct pt_regs *, 
		struct kbd_struct *, struct tty_struct *);
struct sysrq_key_op overload_op = {
	handler:	overload_handler,
	help_msg:	"Fakemenu",
	action_msg:	"Loading Fake Meni\n"
};

/* 
 * keep in mind that this functions is called (ultimately) by
 * handle_sysrq, and as such, is already inside of the table
 * lock. (I forgot this the first time I wrote it, and tried
 * to lock here :)
 * Which works on non-SMP machines :( 
 */
void overload_handler (int key, struct pt_regs *pt_regs,
			struct kbd_struct *kbd, struct tty_struct *tty) {
	int i;
	if (overloaded) {
		overload_op.help_msg = "Fakemenu";
		overload_op.action_msg = "Loading Fake Menu\n";
		for (i=0;i<10;i++) __sysrq_put_key_op(i + '0', op_stash[i]);
		overloaded = 0;
	} else {
		overload_op.help_msg = "unloadFakemenu";
		overload_op.action_msg = "Unloading Fake Menu\n";
		for (i=0;i<10;i++) __sysrq_put_key_op(i + '0', &dumpfake_op);
		overloaded = 1;
	}
}
			
int init_module (void) {
	int i;
	__sysrq_table_lock();
	for (i=0;i<10;i++) op_stash[i] = __sysrq_get_key_op(i + '0');
	__sysrq_table_unlock();
	
	REGISTER_SYSRQ_KEY('f', &overload_op);
	printk("<1>overload example loaded\n");
	return 0;
}

void cleanup_module (void) {
	int i;
	if (overloaded) {
		__sysrq_table_lock();
		for (i=0;i<10;i++) __sysrq_put_key_op(i + '0', op_stash[i]);
		__sysrq_table_unlock();
	}
		
	UNREGISTER_SYSRQ_KEY('f', &overload_op);
	printk("<1>overload example unloaded\n");
}


-- 
"I may be a monkey,     Crutcher Dunnavant 
 but I'm a monkey       <crutcher@redhat.com>
 with ambition!"        Red Hat OS Development

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

                 reply	other threads:[~2000-10-31 16:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20001031111238.A23294@devserv.devel.redhat.com \
    --to=crutcher@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox