#include #include #include #include #include #include #include #include #include int ct; void reset(int sig){ if(sig == SIGHUP)ct = 0; } int main(int argc, char *argv[]){ struct timeval tv; struct input_event i; fd_set pfd; int retval, timeout; if(argc < 3){ fprintf(stderr, "Console screensaver by Rebane\n"); fprintf(stderr, "Use: %s timeout command\n", argv[0]); return(1); } signal(SIGHUP, reset); ct = 0; timeout = atoi(argv[1]); while(1){ FD_ZERO(&pfd); FD_SET(0, &pfd); tv.tv_sec = 1; tv.tv_usec = 0; retval = select(1, &pfd, NULL, NULL, &tv); if(retval > 0){ read(0, &i, sizeof(struct input_event)); ct = 0; }else if(!retval){ ct++; if(ct >= timeout){ system(argv[2]); ct = 0; } } } }