diff --git a/Makefile b/Makefile index 35be742..a5e4a8a 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,17 @@ .S.o: $(CC) $(CLFAGS) $(INCLUDES) -c -o $@ $< + + +# Install +install: + cp tuved /usr/local/bin + if test -d /usr/local/etc/tuve; \ + then echo exists; \ + else mkdir /usr/local/etc/tuve; \ + fi + cp tuved.cfg /usr/local/etc/tuve + cp extra/tuved /usr/local/etc/rc.d # Clean Up The junk clean: diff --git a/config.c b/config.c index bf4de58..a8c9260 100644 --- a/config.c +++ b/config.c @@ -1,6 +1,7 @@ #include #include #include +#include int parseConfig() { config_t cfg; @@ -9,8 +10,21 @@ config_init(&cfg); - if (!config_read_file(&cfg, "./tuved.cfg")) { - fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + if (access("./tuved.cfg", F_OK) != -1) { + if (!config_read_file(&cfg, "./tuved.cfg")) { + fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + return(EXIT_FAILURE); + } + } + else if (access("/usr/local/etc/tuved.cfg", F_OK) != -1) { + if (!config_read_file(&cfg, "/usr/local/etc/tuved.cfg")) { + fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + return(EXIT_FAILURE); + } + } + else { config_destroy(&cfg); return(EXIT_FAILURE); } @@ -18,11 +32,13 @@ setting = config_lookup(&cfg, "daemon"); if (setting != NULL) { - int i = 9999; + int i = 9999; - config_setting_lookup_int(setting, "port", &i); + config_setting_lookup_int(setting, "port", &i); - printf("port: %i", i); + //printf("port: %i", i); } + return(0); + } diff --git a/extra/tuved b/extra/tuved new file mode 100755 index 0000000..f684072 --- /dev/null +++ b/extra/tuved @@ -0,0 +1,43 @@ +#!/bin/sh + +# PROVIDE: tuved +# REQUIRE: LOGIN +# BEFORE: securelevel +# KEYWORD: shutdown + +# Add the following lines to /etc/rc.conf to enable `tuved': +# +# tuved_enable="YES" +# tuved_flags="" +# +# See rsync(1) for tuved_flags +# + +. /etc/rc.subr + +name="tuved" +rcvar=tuved_enable + +command="/usr/local/bin/tuved" +start_precmd="tuved_precmd" +pidfile="/var/run/$name.pid" + +# read configuration and set defaults +load_rc_config "$name" +: ${tuved_enable="NO"} +: ${tuved_configfile:=/usr/local/etc/tuve/$name.cfg} + +required_files="${tuved_configfile}" + +command_args="-d 4 -config ${tuved_configfile}" + +tuved_precmd() +{ + if [ -f "/usr/local/etc/$name.cfg" ] && [ ! -L "/usr/local/etc/$name.cfg" ]; then + echo "Found /usr/local/etc/$name.cfg in old location. Migrating to /usr/local/etc/tuve/$name.cfg." + mv /usr/local/etc/$name.cfg /usr/local/etc/tuve/$name.cfg + ln -s /usr/local/etc/tuved/$name.cfg /usr/local/etc/$name.cfg + fi +} + +run_rc_command "$1" diff --git a/main.c b/main.c index d3d890b..7734328 100644 --- a/main.c +++ b/main.c @@ -38,7 +38,7 @@ /* Get our start time */ startTime = time(NULL); - while ((ch = getopt(argc,argv,"sl:nd:")) != -1) { + while ((ch = getopt(argc,argv,"sl:nd:c:")) != -1) { switch (ch) { case 's': logFile = stdout; @@ -54,6 +54,8 @@ if (logLevel < 1) logLevel = 1; break; + case 'c': + break; default: usage(); } @@ -66,7 +68,7 @@ /* Prepare log file */ if (logFile == 0x0) { - sprintf(logFileName,"./logs/tuved.%i.log",time(NULL)); + sprintf(logFileName,"/var/log/tuved.%i.log", time(NULL)); logFile = fopen(logFileName,"a"); } @@ -75,7 +77,26 @@ if (fork() != 0x0) exit(0x1); - writeLog(0,"Podz Daemon Starting: %i\n",startTime); + writeLog(0,"TUve Daemon Starting: %i\n",startTime); + + int fd; + FILE *somefile; + + somefile = fopen("/var/run/tuved.pid", "w"); + + //text + fprintf(somefile, "%d", getpid()); + + fclose(somefile); + + /* + //binary + pid_t pid = getpid(); + + fwrite(&pid, sizeof(pid), 1, somefile); + + write(fd, &pid, sizeof(pid)); + */ if (dbInit() == 0x1) exit(0x1); diff --git a/tuved.h b/tuved.h index 970a71d..20e28d6 100644 --- a/tuved.h +++ b/tuved.h @@ -18,7 +18,7 @@ #define NUM_THREADS 1 // Number Of Threads In The Deamon #define MYPORT 2007 // the port users will be connecting to #define BACKLOG 10 // how many pending connections queue will hold -#define LOG_FILE "./logs/tuved.log" // Default Log File +#define LOG_FILE "/var/log/tuved.log" // Default Log File #define PING_INTERVAL 20 // Interval For Pings #define MAX_PING 2 // Maximum Number Of Missed Pings #define MAX_COUNT 2