FreeBSD/usr.sbin/watchdogd/watchdogd.c
/*
 * Main program loop which is iterated every second.
 */
Main program loop which is iterated every second.
Main program loop which is iterated every second .
static void
watchdog_loop(void)
{
	struct timespec ts_start, ts_end;
	struct stat sb;
	long waited;
	int error, failed;
	while (end_program != 2) {
		failed = 0;
		error = watchdog_getuptime(&ts_start);
		if (error) {
			end_program = 1;
			goto try_end;
		}
		if (test_cmd != NULL)
			failed = system(test_cmd);
		else
			failed = stat("/etc", &sb);
		error = watchdog_getuptime(&ts_end);
		if (error) {
			end_program = 1;
			goto try_end;
		}
		if (failed == 0)
			watchdog_patpat(timeout|WD_ACTIVE);
		waited = watchdog_check_dogfunction_time(&ts_start, &ts_end);
		if (nap - waited > 0)
			sleep(nap - waited);
try_end:
		if (end_program != 0) {
			if (watchdog_onoff(0) == 0) {
				end_program = 2;
			} else {
				warnx("Could not stop the watchdog, not exiting");
				end_program = 0;
			}
		}
	}
}
static void watchdog_loop ( void ) { struct timespec ts_start , ts_end ; struct stat sb ; long waited ; int error , failed ; while ( end_program != 2 ) { failed = 0 ; error = watchdog_getuptime ( & ts_start ) ; if ( error ) { end_program = 1 ; goto try_end ; } if ( test_cmd != NULL ) failed = system ( test_cmd ) ; else failed = stat ( " " , & sb ) ; error = watchdog_getuptime ( & ts_end ) ; if ( error ) { end_program = 1 ; goto try_end ; } if ( failed == 0 ) watchdog_patpat ( timeout | WD_ACTIVE ) ; waited = watchdog_check_dogfunction_time ( & ts_start , & ts_end ) ; if ( nap - waited > 0 ) sleep ( nap - waited ) ; try_end : if ( end_program != 0 ) { if ( watchdog_onoff ( 0 ) == 0 ) { end_program = 2 ; } else { warnx ( " " ) ; end_program = 0 ; } } } }
Main program loop which is iterated every second.
Main program loop which is iterated every second .