LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-11-2009, 05:31 AM   #1
andpozo
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Rep: Reputation: 0
ioctl crash X


I need help, when I compile this code and insert the module breaks the X because it can be? thank you very much!

Code:
#include <linux/module.h>
#include <linux/config.h>
#include <linux/init.h>
#include <linux/tty.h>		/* For fg_console, MAX_NR_CONSOLES */
#include <linux/kd.h>		/* For KDSETLED */
#include <linux/vt.h>
#include <linux/console_struct.h>	/* For vc_cons */

MODULE_DESCRIPTION("LKD");
MODULE_AUTHOR("G08");
MODULE_LICENSE("GPL");

struct timer_list my_timer;
struct tty_driver *my_driver;
char kbledstatus = 0;

#define BLINK_DELAY   HZ/5
#define ALL_LEDS_ON   0x07
#define RESTORE_LEDS  0xFF

static void my_timer_func(unsigned long ptr)
{
	int *pstatus = (int *)ptr;

	if (*pstatus == ALL_LEDS_ON)
		*pstatus = RESTORE_LEDS;
	else
		*pstatus = ALL_LEDS_ON;

	(my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,
			    *pstatus);

	my_timer.expires = jiffies + BLINK_DELAY;
	add_timer(&my_timer);
}

static int __init kbleds_init(void)
{
	int i;

	printk(KERN_INFO "kbleds: loading\n");
	printk(KERN_INFO "kbleds: fgconsole is %x\n", fg_console);
	for (i = 0; i < MAX_NR_CONSOLES; i++) {
		if (!vc_cons[i].d)
			break;
		printk(KERN_INFO "poet_atkm: console[%i/%i] #%i, tty %lx\n", i,
		       MAX_NR_CONSOLES, vc_cons[i].d->vc_num,
		       (unsigned long)vc_cons[i].d->vc_tty);
	}
	printk(KERN_INFO "kbleds: finished scanning consoles\n");

	my_driver = vc_cons[fg_console].d->vc_tty->driver;
	printk(KERN_INFO "kbleds: tty driver magic %x\n", my_driver->magic);

	/*
	 * Set up the LED blink timer the first time
	 */
	init_timer(&my_timer);
	my_timer.function = my_timer_func;
	my_timer.data = (unsigned long)&kbledstatus;
	my_timer.expires = jiffies + BLINK_DELAY;
	add_timer(&my_timer);

	return 0;
}

static void __exit kbleds_cleanup(void)
{
	printk(KERN_INFO "kbleds: unloading...\n");
	del_timer(&my_timer);
	(my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,
			    RESTORE_LEDS);
}

module_init(kbleds_init);
module_exit(kbleds_cleanup);
 
Old 10-11-2009, 08:48 AM   #2
andpozo
LQ Newbie
 
Registered: Oct 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Kernel version

with conditional compilation for different kernel, same error

Code:
#include <linux/module.h>
#include <linux/version.h>		
#include <linux/tty.h>			/* Para MAX_NR_CONSOLES */
#include <linux/kd.h>			/* Para KDSETLED */
#include <linux/console_struct.h>	/* Para vc_cons */
#include <linux/sched.h>		/* Para nr_running() */ 

MODULE_DESCRIPTION("KGD");
MODULE_AUTHOR("G8");
MODULE_LICENSE("GPL");

struct tty_struct *my_tty = NULL;
struct tty_driver *my_driver = NULL;
struct timer_list my_timer;
char kbledstatus = 0;

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
#define IOCTL(tty_drv) (tty_drv->ioctl)
#else
#define IOCTL(tty_drv) (tty_drv->ops->ioctl)
#endif


#define BLINK_DELAY   HZ/5
#define ALL_LEDS_ON   0x07
#define RESTORE_LEDS  0xFF

static void my_timer_func(unsigned long ptr)
{
	unsigned long *pstatus = (unsigned long *)ptr;
	BUG_ON(!pstatus);

	if (*pstatus == ALL_LEDS_ON)
		*pstatus = RESTORE_LEDS;
	else
		*pstatus = ALL_LEDS_ON;

	IOCTL(my_driver)(my_tty, NULL, KDSETLED, *pstatus);

	my_timer.expires = jiffies + BLINK_DELAY;
	add_timer(&my_timer);
}

static int __init kbleds_init(void)
{
	int i;

	printk(KERN_INFO "kbleds: loading\n");
	my_tty = get_current_tty();
	BUG_ON(!my_tty);
	printk(KERN_INFO "kbleds: curret_tty %lx\n", (long int)my_tty);
	printk(KERN_INFO "kbleds: fgconsole is %x\n", my_tty->index);
	for (i = 0; i < MAX_NR_CONSOLES; i++) {
		if (!vc_cons[i].d)
			break;
		printk(KERN_INFO "kbleds: console[%i/%i] #%i, tty %lx\n", i,
		       MAX_NR_CONSOLES, vc_cons[i].d->vc_num,
		       (unsigned long)vc_cons[i].d->vc_tty);
	}
	printk(KERN_INFO "kbleds: finished scanning consoles\n");

	my_driver = my_tty->driver;
	BUG_ON(!my_driver);
	printk(KERN_INFO "kbleds: tty driver magic %x\n", my_driver->magic);

	init_timer(&my_timer);
	my_timer.function = my_timer_func;
	my_timer.data = (unsigned long)&kbledstatus;
	my_timer.expires = jiffies + BLINK_DELAY;
	add_timer(&my_timer);

	return 0;
}

static void __exit kbleds_cleanup(void)
{
	printk(KERN_INFO "kbleds: unloading...\n");
	del_timer(&my_timer);
	IOCTL(my_driver)(my_tty, NULL, KDSETLED, RESTORE_LEDS);
}


module_init(kbleds_init);
module_exit(kbleds_cleanup);

Any idea what happens?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass IOCTL arguments from usespace ioctl call devkpict Linux - Kernel 1 12-07-2007 06:45 PM
Crash, Crash, Crash, Crash and You Guessed it Crash! little_penguin SUSE / openSUSE 8 07-04-2005 09:34 AM
kde crash, then other crash, now weird problems true_atlantis Linux - Laptop and Netbook 1 04-28-2004 12:01 AM
xmms crash xine crash mplayer crash paledread Linux - Software 9 03-09-2004 07:09 AM
ioctl dummyagain Programming 2 10-06-2003 07:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration