/*
- $Id: cmd_dbd.c,v 1.12 2009-10-13 22:55:37 didg Exp $
+ $Id: cmd_dbd.c,v 1.24 2009-12-21 17:00:17 franklahm Exp $
Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
static struct db_param db_param = {
NULL, /* Volume dirpath */
1, /* bdb logfile autoremove */
- 16384, /* bdb cachesize */
+ 64 * 1024, /* bdb cachesize (64 MB) */
-1, /* not used ... */
-1,
"",
return;
}
-void set_signal(void)
+static void set_signal(void)
{
struct sigaction sv;
}
}
-int get_lock(const char *dbpath)
+static int get_lock(const char *dbpath)
{
int lockfd;
char lockpath[PATH_MAX];
return lockfd;
}
-void free_lock(int lockfd)
+static void free_lock(int lockfd)
{
struct flock lock;
" -x rebuild indexes (just for completeness, mostly useless!)\n"
" -v verbose\n\n"
"WARNING:\n"
- "If you want/need to run an -r -f rebuild after adding 'cachecnid' to a volume configuration,\n"
- "you must run a rebuild with -r alone at first in order to sync all existing CNIDs from the db\n"
- "to the AppleDouble files!\n"
+ "For -r -f restore of the CNID database from the adouble files, the CNID must of course\n"
+ "be synched to them files first with a plain -r rebuild !\n"
);
}
usage();
exit(EXIT_FAILURE);
}
+ /* Inhereting perms in ad_mkdir etc requires this */
+ ad_setfuid(0);
while ((c = getopt(argc, argv, ":dsnruvxife")) != -1) {
switch(c) {
}
volpath = argv[optind];
+ setvbuf(stdout, (char *) NULL, _IONBF, 0);
+
/* Remember cwd */
if ((cdir = open(".", O_RDONLY)) < 0) {
dbd_log( LOGSTD, "Can't open dir: %s", strerror(errno));
exit(EXIT_FAILURE);
}
+ /* Sanity checks to ensure we can touch this volume */
+ if (volinfo.v_vfs_ea != AFPVOL_EA_AD && volinfo.v_vfs_ea != AFPVOL_EA_SYS) {
+ dbd_log( LOGSTD, "Unknown Extended Attributes option: %u", volinfo.v_vfs_ea);
+ exit(EXIT_FAILURE);
+ }
+
/* Put "/.AppleDB" at end of volpath, get path from volinfo file */
if ( (strlen(volinfo.v_dbpath) + strlen("/.AppleDB")) > (PATH_MAX - 1) ) {
dbd_log( LOGSTD, "Volume pathname too long");
strncpy(dbpath, volinfo.v_dbpath, PATH_MAX - 9 - 1);
strcat(dbpath, "/.AppleDB");
+ /* Check or create dbpath */
+ int dbdirfd = open(dbpath, O_RDONLY);
+ if (dbdirfd == -1 && errno == ENOENT) {
+ if (errno == ENOENT) {
+ if ((mkdir(dbpath, 0755)) != 0) {
+ dbd_log( LOGSTD, "Can't create .AppleDB for \"%s\": %s", dbpath, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ dbd_log( LOGSTD, "Somethings wrong with .AppleDB for \"%s\", giving up: %s", dbpath, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ } else {
+ close(dbdirfd);
+ }
+
/*
Before we do anything else, check if there is an instance of cnid_dbd
running already and silently exit if yes.
if (exclusive)
dbd_log( LOGDEBUG, "Finished recovery.");
- if (dbif_open(dbd, &db_param, rebuildindexes) < 0) {
+ if (dbif_open(dbd, NULL, rebuildindexes) < 0) {
dbif_close(dbd);
goto exit_failure;
}
if (dbif_dump(dbd, dumpindexes) < 0) {
dbd_log( LOGSTD, "Error dumping database");
}
- } else if ((rebuild && ! nocniddb) || (scan && nocniddb)) {
+ } else if ((rebuild && ! nocniddb) || scan) {
if (cmd_dbd_scanvol(dbd, &volinfo, flags) < 0) {
dbd_log( LOGSTD, "Error repairing database.");
}