//------------------------------------------------------------------- // defermsg.c // // This module demonstrates the use of a workqueue to defer the // appearance of a 'hello' message on the screen for 10 secons. // // NOTE: Developed and tested with Linux kernel version 2.6.10. // // programmer: ALLAN CRUSE // written on: 22 MAR 2005 //------------------------------------------------------------------- #include // for init_module() #include // for init_work() #include // for 'struct tty_struct' char modname[] = "defermsg"; struct workqueue_struct *myqueue; struct work_struct mywork; char message[] = "\r\n\nHello!\r\n\n"; void dowork( void *data ) { struct tty_struct *tty = (struct tty_struct *)data; tty->driver->write( tty, message, strlen( message ) ); } int init_module( void ) { printk( "<1>\nInstalling \'%s\' module\n", modname ); myqueue = create_singlethread_workqueue( "mywork" ); INIT_WORK( &mywork, dowork, current->signal->tty ); if ( !queue_delayed_work( myqueue, &mywork, HZ * 10 ) ) return -EBUSY; return 0; // SUCCESS } void cleanup_module( void ) { printk( "<1>Removing \'%s\' module\n", modname ); if ( !cancel_delayed_work( &mywork ) ) flush_workqueue( myqueue ); destroy_workqueue( myqueue ); } MODULE_LICENSE("GPL");