문제

I'm new to this forum and I would like to ask the experts a question. I wrote the following program ( part of a bigger thing, but this is the code that causes me trouble)

#include <unistd.h>
#include <fcntl.h>

int main()
{
    int fd;
    fd = open("/dev/watchdog",O_RDONLY);
    lseek(fd,0,SEEK_END);
    return 0;
}

The thing that bothers me is that after I run this program as root, after 20-30 seconds, the system crashes, and I can't seem to figure out why. This does not happend as a regular user. Could you please enlighten me regarding this issue?

Thanks!

PS. Yes, I know that /dev/watchdog is a character file and it's not seekable, but this seems really weird.

도움이 되었습니까?

해결책

It looks like /dev/watchdog is doing what its supposed to do. Once you open /dev/watchdog, you have to keep writing to it, otherwise the system reboots. It is probably not the lseek that is crashing it, it is the lack of writing. See the linux manpages for watchdog for more info.

When you ran as a non-root user, your open of /dev/watchdog probably just failed, so the system did not reboot. Your code is not checking for an error from open().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top