/*
 * Shows uptime in days. Returns output 2x -> made for MRTG.
 *
 * This program is in the public domain.
 */

#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/time.h>

#include <stdio.h>

int 
main(void)
{
	struct timeval boottime, currenttime;
	struct timezone tz;
	int mib[2], uptime;
	size_t len;

	mib[0] = CTL_KERN;
	mib[1] = KERN_BOOTTIME;
	len = sizeof(boottime);

	if (sysctl(mib, 2, &boottime, &len, NULL, 0) != 0)
		return (0);

	if (gettimeofday(&currenttime, &tz) != 0)
		return (0);

	uptime = (currenttime.tv_sec - boottime.tv_sec) / 86400;
	
	printf("%d\n%d\n", uptime, uptime);

	return (0);
}
