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:

[EMAIL PROTECTED]:/# echo foo > /sys/power/state
bash: echo: write error: Invalid argument
[EMAIL PROTECTED]:/# echo $?
1
[EMAIL PROTECTED]:/# /tmp/pm-echo foo > /sys/power/state
write failed: Invalid argument
[EMAIL PROTECTED]:/# 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." 
#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;
}
_______________________________________________
Pm-utils mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pm-utils

Reply via email to