/* author: folkert@feedface.com */

#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>



#define CHILDTIME	(30)
#define STARTTIME	(300)

#define CMD "/System/Library/Frameworks/Carbon.framework/Versions/Current/Support/LaunchCFMApp" 
#define ARG "/Volumes/DATA/folkert/Applications/EarthDesk 1.2.6/EarthDesk"
char *cmd= CMD;
char *arg[2]= {CMD,ARG};

int main(int argc, char **args)
{
	pid_t pid;
	int stat;
	
	//daemonize
	if ((pid= fork()) < 0)
		exit(-1);
	if (pid > 0)
		exit(0);
	chdir("/");
	freopen("/dev/zero","r",stdin);
	freopen("/dev/null","a",stdout);
	freopen("/dev/null","a",stderr);

	while (1) {

		if ((pid= fork()) < 0)
			exit(-1);

		if (pid > 0) { //father
			sleep(CHILDTIME);
			kill(pid,SIGKILL);
			pid= waitpid(pid,&stat,0);
		} else { //child
			execve(cmd,arg,NULL);
			exit(0);
		}	
		
		sleep(STARTTIME);
	}

}