A Linux Port of the popular role playing game "Progress Quest"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

70 lines
1.4 KiB

/*
* This code is licensed under the terms of the WTFPL <http://www.wtfpl.net/>
* Please consider the following terms for copying, distributing and modifying
* the software:
*
* 0. You just DO WHAT THE FUCK YOU WANT TO.
*/
#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define DAEMONIZE_FATHER 0
#define DAEMONIZE_DAEMON 1
#define DAEMONIZE_ERROR -1
int daemonize(void) {
pid_t pid;
pid = fork();
if(pid < 0) {
return DAEMONIZE_ERROR;
} else if(pid > 0) {
return DAEMONIZE_FATHER;
}
umask(0);
if(setsid() < 0 ||
chdir("/") < 0 ||
NULL == freopen("/dev/null", "r", stdin ) ||
NULL == freopen("/dev/null", "w", stdout) ||
NULL == freopen("/dev/null", "w", stderr))
{
return DAEMONIZE_ERROR;
}
return DAEMONIZE_DAEMON;
}
int main(int argc, const char *argv[])
{
(void) argv;
/*
* print usage
*/
if (argc > 1) {
printf("usage: progressquestd\n");
return 0;
}
/*
* daemonizing
*/
switch(daemonize()) {
case DAEMONIZE_FATHER: return 0;
case DAEMONIZE_ERROR: return -1;
}
/*
* Since there is no way of interacting with the process,
* the game mechanics were optimized away.
*/
while (1)
sleep(9001);
return 0;
}