pass through an arg

This commit is contained in:
Vincent Batts 2017-11-05 22:19:48 -05:00
parent 7e5df725d8
commit 424d185294
2 changed files with 12 additions and 6 deletions

View file

@ -11,16 +11,21 @@
int main(int argc, char ** argv) { int main(int argc, char ** argv) {
int fd = -1; int fd = -1;
int ret;
int i;
fd = open(HELLOCTL, O_RDONLY); fd = open(HELLOCTL, O_RDONLY);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "Could not open %s\n", HELLOCTL); fprintf(stderr, "Could not open %s\n", HELLOCTL);
_exit(1); _exit(1);
} }
int ret;
if (ret = ioctl(fd, 1, 1) < 0) { for (i=1; i<argc; i++) {
fprintf(stderr, "ioctl failed with: %s\n", strerror(ret)); if (ret = ioctl(fd, 1, argv[i]) < 0) {
goto done; fprintf(stderr, "ioctl failed with: %s\n", strerror(ret));
goto done;
}
} }
done: done:
close(fd); close(fd);

View file

@ -17,7 +17,8 @@ MODULE_VERSION("1.0");
static long static long
hello_control_ioctl(struct file *file, unsigned int cmd, unsigned long arg) hello_control_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
printk(KERN_INFO "[%s] received command: %d\n", __this_module.name, cmd); char * temp = arg;
printk(KERN_INFO "[%s] received command: %d (arg %s)\n", __this_module.name, cmd, arg);
return 0; return 0;
} }
@ -43,11 +44,11 @@ static const struct file_operations hello_ctl_fops = {
.read = hello_control_read, .read = hello_control_read,
}; };
static struct miscdevice hello_misc = { static struct miscdevice hello_misc = {
.minor = MISC_DYNAMIC_MINOR, .minor = MISC_DYNAMIC_MINOR,
.name = "helloctl", .name = "helloctl",
.fops = &hello_ctl_fops, .fops = &hello_ctl_fops,
.mode = 0666,
}; };
MODULE_ALIAS_MISCDEV(MISC_DYNAMIC_MINOR); MODULE_ALIAS_MISCDEV(MISC_DYNAMIC_MINOR);