[Pm-utils] A "pm-echo" that actually returns the error code of
write(2)
Stefan Seyfried
seife at suse.de
Fri Mar 16 09:10:19 PDT 2007
Hi,
sooner or later we will want to return error codes from suspend back
up the stack to the application.
When doing "echo foo > /sys/power/state", i get a return code of 1,
instead of 22 for EINVAL, which would be the correct return code:
root at strolchi:/# echo foo > /sys/power/state
bash: echo: write error: Invalid argument
root at strolchi:/# echo $?
1
root at strolchi:/# /tmp/pm-echo foo > /sys/power/state
write failed: Invalid argument
root at strolchi:/# echo $?
22
pm-echo.c is as trivial as it gets (attached, and inline for your viewing
pleasure):
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv)
{
ssize_t count;
int ret, err;
if (argc != 2) {
fprintf(stderr, "only one argument, please\n");
return 255;
}
count = write(1, argv[1], strlen(argv[1]));
if (count < 0) {
err = errno;
fprintf(stderr, "write failed: %s\n", strerror(err));
return err;
}
ret = close(1);
if (ret) {
err = errno;
fprintf(stderr, "close failed: %s\n", strerror(err));
return err;
}
return 0;
}
And as simple as it is, it is probably wrong somewhere, but you get
the idea :-)
--
Stefan Seyfried
"Any ideas, John?"
"Well, surrounding them's out."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pm-echo.c
Type: text/x-c++src
Size: 596 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/pm-utils/attachments/20070316/7bd1e180/pm-echo.c++
More information about the Pm-utils
mailing list