I am trying to pass command line arguments into a module (doesn't have to be
a real time module, of course). I can get around the well-known problem of
not being able to pass numeric values by hiding them in strings. The question
is how to convert them back after - atoi does not work in the module.
To run the code (after compiling it):
% insmod args arg1='dset=1024' arg2='freq=256' arg3='rate=8' arg4='time=4'
Here's the code
#include <linux/kernel.h> /* printk */
#include <linux/module.h> /* module stuff */
#include <stdlib.h> /* atoi */
char *arg1 = "";
char *arg2 = "";
char *arg3 = "";
char *arg4 = "";
int dset = 0;
int freq = 0;
int rate = 0;
int time = 0;
int cliParse( char *ptr )
{
switch (ptr[0]) {
case 'd':
case 'D':
while ( *ptr != '=' ) ptr++;
ptr++;
/*
the following line fails - why?0
dset = atoi( ptr );
(void) printk("Decoded value = %d\n", dset);
*/
ptr++;
(void) printk("Dset: %s\n",ptr);
break;
case 'f':
case 'F':
(void) printk("Freq: %s\n",ptr);
break;
case 'r':
case 'R':
(void) printk("Rate: %s\n",ptr);
break;
case 't':
case 'T':
(void) printk("Time: %s\n",ptr);
break;
}
return (0);
}
int init_module( void )
{
(void) cliParse(arg1);
(void) cliParse(arg2);
(void) cliParse(arg3);
(void) cliParse(arg4);
return (0);
}
void cleanup_module( void )
{
}
--- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
----
For more information on Real-Time Linux see:
http://www.rtlinux.org/~rtlinux/