#include "config.h"
#endif /* HAVE_CONFIG_H */
-#ifdef HAVE_UNISTD_H
#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#ifdef HAVE_FCNTL_H
#include <fcntl.h>
-#endif /* HAVE_FCNTL_H */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
-#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
-#endif /* HAVE_SYS_TYPES_H */
#include <sys/param.h>
-#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
-#endif /* HAVE_SYS_STAT_H */
#include <time.h>
#include <sys/file.h>
+#include <arpa/inet.h>
-#include <netatalk/endian.h>
#include <atalk/cnid_dbd_private.h>
#include <atalk/logger.h>
#include <atalk/volinfo.h>
int main(int argc, char *argv[])
{
struct db_param *dbp;
- int err = 0;
+ int err = 0, ret, delete_bdb = 0;
int ctrlfd, clntfd;
char *logconfig;
set_processname("cnid_dbd");
- /* FIXME: implement -d from cnid_metad */
- if (argc != 5) {
- LOG(log_error, logtype_cnid, "main: not enough arguments");
- exit(1);
+ while (( ret = getopt( argc, argv, "vVd")) != -1 ) {
+ switch (ret) {
+ case 'v':
+ case 'V':
+ printf("cnid_dbd (Netatalk %s)\n", VERSION);
+ return -1;
+ case 'd':
+ delete_bdb = 1;
+ break;
+ }
}
- ctrlfd = atoi(argv[2]);
- clntfd = atoi(argv[3]);
- logconfig = strdup(argv[4]);
- setuplog(logconfig);
+ if (argc - optind != 4) {
+ LOG(log_error, logtype_cnid, "main: not enough arguments");
+ exit(EXIT_FAILURE);
+ }
/* Load .volinfo file */
- if (loadvolinfo(argv[1], &volinfo) == -1) {
+ if (loadvolinfo(argv[optind], &volinfo) == -1) {
LOG(log_error, logtype_cnid, "Cant load volinfo for \"%s\"", argv[1]);
exit(EXIT_FAILURE);
}
strncpy(dbpath, volinfo.v_dbpath, MAXPATHLEN - strlen("/.AppleDB"));
strcat(dbpath, "/.AppleDB");
+ ctrlfd = atoi(argv[optind + 1]);
+ clntfd = atoi(argv[optind + 2]);
+
+ setuplog("default:note", NULL);
+
if (vol_load_charsets(&volinfo) == -1) {
LOG(log_error, logtype_cnid, "Error loading charsets!");
exit(EXIT_FAILURE);
}
}
+ if (delete_bdb && (db_locked == LOCK_EXCL)) {
+ LOG(log_warning, logtype_cnid, "main: too many CNID db opening attempts, wiping the slate clean");
+ chdir(dbpath);
+ system("rm -f cnid2.db lock log.* __db.*");
+ if ((db_locked = get_lock(LOCK_EXCL, dbpath)) != LOCK_EXCL) {
+ LOG(log_error, logtype_cnid, "main: fatal db lock error");
+ exit(EXIT_FAILURE);
+ }
+ }
+
set_signal();
/* SIGINT and SIGTERM are always off, unless we are in pselect */