static int fileLock(File *f) { assert(!canwlock(&f->fs->elk)); wlock(&f->lk); if(!chkSource(f)){ fileUnlock(f); return 0; } return 1; }
static int fileLock(File *f) { assert(!vtCanLock(f->fs->elk)); vtLock(f->lk); if(!chkSource(f)){ fileUnlock(f); return 0; } return 1; }
int main (int argc, char* argv[]) { bkupInfo info; bkupType type; int len; int rst; /* return status */ if (getuid() != ROOT_UID) { fprintf(stderr, "must be root\n"); exit(1); } if (argc <= 2) { usage(); } umask(defUmask); memset(&info, 0, sizeof(info)); info.dest = argv[2]; info.src = index(argv[1], ':'); if (info.src) { info.host = index(argv[1], '@'); if (!info.host || info.host > info.src) { /* no user specified, or `@' appeared after `:' */ info.host = argv[1]; info.user = DefaultUser; } else { *info.host = '\0'; ++info.host; info.user = argv[1]; } *info.src = '\0'; ++info.src; } else { info.src = argv[1]; } if (*info.src != '/') goto errorExit; /* src must be full path */ if (*info.dest != '/') goto errorExit; /* dest must be full path */ len = strlen(info.src) - 1; if (info.src[len] == '/') { /* strip tail '/' */ info.src[len] = '\0'; } len = strlen(info.dest) - 1; if (info.dest[len] == '/') { info.dest[len] = '\0'; } if (info.host) { makeSshKey(&info); } chkDest(&info); if (info.host) { exit(doRemote(&info)); } type = chkSource(&info); openFilesLocal(&info); switch (type) { case bkupFirstTime: info.func = firstTimeBackup; break; case bkupRecurrent: info.func = recurrentBackup; break; default: errExit(("wrong bkup type (%d)", type)); } rst = dirwalk(info.src, &info); closeFiles(&info); if ((type == bkupRecurrent) && unlink(info.oldJpath)) { errSysRet(("unlink(%s)", info.oldJpath)); } rst = runCommands(&info); removeFiles(&info); if (type == bkupFirstTime && !rst) { if (info.jpath && unlink(info.jpath)) { errSysRet(("unlink(%s)", info.jpath)); } } exit(!rst); errorExit: fprintf(stderr, "Source and Destination directories must be full path\n"); exit(1); return 0; /* to make gcc happy */ }