forked from PacktPublishing/Linux-Device-Drivers-Development
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user-invoke.c
42 lines (36 loc) · 984 Bytes
/
user-invoke.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <linux/init.h>
#include <linux/module.h>
#include <linux/workqueue.h> /* for work queue */
#include <linux/kmod.h>
static struct delayed_work initiate_shutdown_work;
static void delayed_shutdown(struct work_struct *work)
{
char *cmd = "/sbin/shutdown";
char *argv[] = {
cmd,
"-h",
"now",
NULL,
};
char *envp[] = {
"HOME=/",
"PATH=/sbin:/bin:/usr/sbin:/usr/bin",
NULL,
};
call_usermodehelper(cmd, argv, envp, 0);
}
static int __init my_shutdown_init( void )
{
INIT_DELAYED_WORK(&initiate_shutdown_work, delayed_shutdown);
schedule_delayed_work(&initiate_shutdown_work, msecs_to_jiffies(200));
return 0;
}
static void __exit my_shutdown_exit( void )
{
return;
}
module_init( my_shutdown_init );
module_exit( my_shutdown_exit );
MODULE_LICENSE("GPL");
MODULE_AUTHOR("John Madieu <john.madieu@gmail.com>");
MODULE_DESCRIPTION("Simple module that trigger a delayed shut down");