#include <errno.h>
#include <stdarg.h>
#include <grp.h>
+#include <pwd.h>
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#endif
#include "database.h"
#include "housekeeping.h"
#include "tools.h"
+#include "citadel_dirs.c"
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
struct passwd *pw;
int drop_root_perms = 1;
size_t size;
-
+ int relh=0;
+ int home=0;
+ char relhome[PATH_MAX]="";
+ char ctdldir[PATH_MAX]=CTDLDIR;
+#ifdef HAVE_RUN_DIR
+ struct stat filestats;
+#endif
+
/* initialize the master context */
InitializeMasterCC();
- /* set default syslog facility */
- syslog_facility = LOG_DAEMON;
-
/* parse command-line arguments */
for (a=1; a<argc; ++a) {
if (!strncmp(argv[a], "-l", 2)) {
- safestrncpy(facility, argv[a], sizeof(facility));
+ safestrncpy(facility, &argv[a][2], sizeof(facility));
syslog_facility = SyslogFacility(facility);
enable_syslog = 1;
}
}
else if (!strncmp(argv[a], "-h", 2)) {
- safestrncpy(ctdl_home_directory, &argv[a][2],
- sizeof ctdl_home_directory);
+ relh=argv[a][2]!='/';
+ if (!relh) safestrncpy(ctdl_home_directory, &argv[a][2],
+ sizeof ctdl_home_directory);
+ else
+ safestrncpy(relhome, &argv[a][2],
+ sizeof relhome);
home_specified = 1;
+ home=1;
}
else if (!strncmp(argv[a], "-t", 2)) {
}
+ calc_dirs_n_files(relh, home, relhome, ctdldir);
+
/* daemonize, if we were asked to */
if (running_as_daemon) {
start_daemon(0);
drop_root_perms = 1;
}
- /* initialize the syslog facility */
+ /* Initialize the syslogger. Yes, we are really using 0 as the
+ * facility, because we are going to bitwise-OR the facility to
+ * the severity of each message, allowing us to write to other
+ * facilities when we need to...
+ */
if (enable_syslog) {
if (running_as_daemon) {
- openlog("citadel", LOG_NDELAY, syslog_facility);
+ openlog("citadel", LOG_NDELAY, 0);
}
else {
- openlog("citadel", LOG_PERROR|LOG_NDELAY,
- syslog_facility);
+ openlog("citadel", LOG_PERROR|LOG_NDELAY, 0);
}
setlogmask(LOG_UPTO(verbosity));
}
config.c_ipgm_secret = rand();
put_config();
+#ifdef HAVE_RUN_DIR
+ /* on some dists rundir gets purged on startup. so we need to recreate it. */
+
+ if (stat(ctdl_run_dir, &filestats)==-1){
+ pw=getpwuid(config.c_ctdluid);
+ mkdir(ctdl_run_dir, 0755);
+ chown(ctdl_run_dir, config.c_ctdluid, (pw==NULL)?-1:pw->pw_gid);
+
+ }
+
+
+#endif
+
/* Initialize... */
init_sysdep();
* Bind the server to a Unix-domain socket.
*/
CtdlRegisterServiceHook(0,
- "citadel.socket",
- citproto_begin_session,
- do_command_loop,
- do_async_loop);
+ file_citadel_socket,
+ citproto_begin_session,
+ do_command_loop,
+ do_async_loop);
/*
* Bind the server to our favorite TCP port (usually 504).