0

I want to write some logs in a file and I have tried to import stdlib.h for system function so that I can run echo command to write a log in a file on /sdcard/ but linux kernel source code doesn't support this include. I can see other #include in sources are from /include/linux folder.

Any help?

Vatish Sharma
  • 1,536
  • 3
  • 16
  • 35
  • 2
    You cannot use the standard C library in the Linux kernel. If you want to do something, you will have to use the appropriate kernel APIs to do it. In general, achieving something like what you are asking is much more complicated from kernel code and it doesn't really make much sense (the fact that it's complicated is because no piece of code in the kernel ever needs to do such things). – Marco Bonelli Apr 20 '20 at 06:17
  • 1
    What are you trying to achieve, and why must this be done from the kernel? If it needs to run from the kernel, why do you need to write to a specific file rather than to the appropriate log facility? – Cheatah Apr 20 '20 at 06:25
  • @Cheatah I tried with the kernel log facility `dmesg` and I was able to read the logs there but it automatically clears after some time and also if i run `dmesg -c` from my application then after that I was not even able to read log for sometime. I need to pass some data from kernel module to an application in userspace so I thought about writing in a file instead of using dmesg. – Vatish Sharma Apr 20 '20 at 06:49
  • 1
    A kernel should not normally write to files. If you have a problem with log management, fix that problem. If you need to communicate with user space processes, use a more suitable mechanism like a device node. – Cheatah Apr 20 '20 at 08:58
  • 1
    https://stackoverflow.com/questions/34133497/how-to-choose-between-sys-and-proc-files-in-linux-kernel – 0andriy Apr 20 '20 at 18:57

0 Answers0