Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Unique session ID?


    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.

  2. #2
    I dunno if any of these might be available to your module in some way...

    Shell Scripting - Temp Files

  3. #3
    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:

    WARNING: "sys_clock_gettime" [/data/c-projects/skl/skl.ko] undefined!
    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).

    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?

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts