Results 1 to 3 of 3
Hello,
I'm new to kernel programming. My kernel module commits the sin of saving a file to disk every time it gets unloaded. I'm aware it's a naughty thing to ...
- 06-23-2008 #1Just Joined!
- Join Date
- Dec 2006
- Posts
- 13
Unique session ID?
Hello,
I'm new to kernel programming. My kernel module commits the sin of saving a file to disk every time it gets unloaded. I'm aware it's a naughty thing to do. The module will be loaded at boot, and unloaded when the system shuts down.
I'm trying to find a way to generate a unique filename every time the module gets unloaded.
My first idea is to use some sort of a "session ID", if such a concept exists in Linux. Is there such a thing as a unique ID that identifies the current "session"? By "session", I mean the time between you boot into and shut down Linux.
As far as I know, there is no way to get the current local time from kernelspace, as the kernel has no concept of timezones, daylight savings, etc. That would have been my second option. I don't suppose there exists a way to obtain the current time after all? How about time since the epoch?
Lastly, although I hate the approach, is there a way to generate a random filename that is more or less guaranteed to be unique?
Thank you in advance for the help, and sorry for breaking some unwritten rules of kernel module programming.
- 06-23-2008 #2Linux Guru
- Join Date
- Nov 2007
- Posts
- 1,679
I dunno if any of these might be available to your module in some way...
Shell Scripting - Temp Files
- 06-24-2008 #3Just Joined!
- Join Date
- Dec 2006
- Posts
- 13
Thanks for the tip. I never knew that existed, and it may be useful in the future.
Unfortunately, it seems that very few things are available to module programmers. We can't even use the C standard library.
I'm very confused. According to chapter 3 of the Linux Kernel Module Programming Guide, the functions that are available to module programmers are the ones that were exported by the kernel, and they can all be found in /proc/kallsyms. I searched /proc/kallsyms for clock or time related functions, and found sys_clock_gettime(), which would have suited my needs. However, when I call that function in my module, I get this warning:
And checking the source where that function is defined confirms that it is not exported (there should have been an EXPORT_SYMBOL or an EXPORT_SYMBOL_GPL macro right after the function definition's end).Code:WARNING: "sys_clock_gettime" [/data/c-projects/skl/skl.ko] undefined!
Then what is it doing in /proc/kallsyms? And how can I get a list of all the functions that are really available to me as a module programmer?


Reply With Quote
