static const struct option options[] = {
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'V' },
static const struct option options[] = {
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'V' },
{ "recover-fatal", no_argument, 0, 'R' },
{ "recompute-aliases", no_argument, 0, 'a' },
{ "remove-pathless", no_argument, 0, 'P' },
{ "recover-fatal", no_argument, 0, 'R' },
{ "recompute-aliases", no_argument, 0, 'a' },
{ "remove-pathless", no_argument, 0, 'P' },
" --recover, -r Run database recovery\n"
" --recompute-aliases, -a Recompute aliases\n"
" --remove-pathless, -P Remove pathless tracks\n"
" --recover, -r Run database recovery\n"
" --recompute-aliases, -a Recompute aliases\n"
" --remove-pathless, -P Remove pathless tracks\n"
int main(int argc, char **argv) {
int n, dump = 0, undump = 0, recover = TRACKDB_NO_RECOVER, recompute = 0;
int remove_pathless = 0, fd;
int main(int argc, char **argv) {
int n, dump = 0, undump = 0, recover = TRACKDB_NO_RECOVER, recompute = 0;
int remove_pathless = 0, fd;
- while((n = getopt_long(argc, argv, "hVc:dDurRaP", options, 0)) >= 0) {
+ while((n = getopt_long(argc, argv, "hVc:dDurRaPR", options, 0)) >= 0) {
case 'R': recover = TRACKDB_FATAL_RECOVER; break;
case 'a': recompute = 1; break;
case 'P': remove_pathless = 1; break;
case 'R': recover = TRACKDB_FATAL_RECOVER; break;
case 'a': recompute = 1; break;
case 'P': remove_pathless = 1; break;
if(rename(tmp, path) < 0)
disorder_fatal(errno, "error renaming %s to %s", tmp, path);
} else if(undump) {
if(rename(tmp, path) < 0)
disorder_fatal(errno, "error renaming %s to %s", tmp, path);
} else if(undump) {
+ /* Open the dump file before changing UID */
+ if(!(fp = fopen(path, "r")))
+ disorder_fatal(errno, "error opening %s", path);
+ if(changeuid)
+ become_mortal();
/* the databases or logfiles might end up with wrong permissions
* if new ones are created */
if(getuid() == 0)
disorder_info("you might need to chown database files");
/* the databases or logfiles might end up with wrong permissions
* if new ones are created */
if(getuid() == 0)
disorder_info("you might need to chown database files");