Return code while writing to procfs
Hi,
I am a newbie in Module programming. I wanted to know whether i can return a specific exit code other than predefined ones while writing to a proc entry. For example if there is an error while writing to a proc entry can i have an exit code like e.g. 1234. This will help me in more specifically pointing out the reason for the error. For example i do $bash] echo "This echo whill fail" > /proc/dummy/waste Suppose the write failed because of Error "Some weired Error", which i have defined to be error number 1234 in my error file, i should get 1234 in $? on the shell prompt. But all the friends i asked for help told me that they dont know of any such way, and they can return only whether command suceeded or command failed. I cannot pin point reason behind the error :( But i think there has to be atleast some work around to get specific exit code, so that i can parse an error file for that exit code, and echo the specific reason. Thanks in advance..... |
Hya,
I somewhat think you have to use C to satisfy your wish. Even in that case, I do not think you can have 1234 as an exit code. I may be wrong but exit code needs to be 8 bit. Happy Penguins! |
Hi,
By 1234 i meant any code other than -1, 0 and 1. That is when i echo something to proc, i should be able to return a specific code which represents a specific error; rather than just telling that there was an error or not. |
Quote:
To show this, consider the module made of a file waste.c: Code:
#include <linux/kernel.h> Code:
$ sudo modprobe waste |
Why not just proc_create_entry for "code" and/or "message" (below dummy) as well to expose more info if necessary ???.
|
Hi syg00,
The problem with having another proc entry e.g. /proc/dummy/code for error code comes,when i have almost simultaneous writes on the proc/dummy/waste. The first command fails, and the /proc/dummy/code has the error code e.g. 12, but before i read /proc/dummy/code another write to dummy/waste is successfull, and i wont see specific reason for the error as /proc/dummy/code shows 0. So i think osor's way seems to be the best solution , but my bash does not give those messages when i tried running osor's code. my bash version is 3.00.15. Do i need to enable something in bash for that? |
Quote:
Code:
$ /bin/echo "foo" > /proc/dummy/waste |
All times are GMT -5. The time now is 03:47 PM. |