=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rsync/flist.c,v retrieving revision 1.24 retrieving revision 1.25 diff -c -r1.24 -r1.25 *** src/usr.bin/rsync/flist.c 2019/04/04 04:19:54 1.24 --- src/usr.bin/rsync/flist.c 2019/05/08 20:00:25 1.25 *************** *** 1,4 **** ! /* $Id: flist.c,v 1.24 2019/04/04 04:19:54 bket Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * Copyright (c) 2019 Florian Obser --- 1,4 ---- ! /* $Id: flist.c,v 1.25 2019/05/08 20:00:25 benno Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * Copyright (c) 2019 Florian Obser *************** *** 81,87 **** new = calloc(*sz, sizeof(struct flist)); if (new == NULL) { ! ERR(sess, "calloc"); return 0; } --- 81,87 ---- new = calloc(*sz, sizeof(struct flist)); if (new == NULL) { ! ERR("calloc"); return 0; } *************** *** 106,112 **** if (strcmp(f->path, fnext->path) == 0) { new[j++] = *f; i++; ! WARNX(sess, "%s: duplicate path: %s", f->wpath, f->path); free(fnext->path); free(fnext->link); --- 106,112 ---- if (strcmp(f->path, fnext->path) == 0) { new[j++] = *f; i++; ! WARNX("%s: duplicate path: %s", f->wpath, f->path); free(fnext->path); free(fnext->link); *************** *** 114,120 **** continue; } ! ERRX(sess, "%s: duplicate working path for " "possibly different file: %s, %s", f->wpath, f->path, fnext->path); free(new); --- 114,120 ---- continue; } ! ERRX("%s: duplicate working path for " "possibly different file: %s, %s", f->wpath, f->path, fnext->path); free(new); *************** *** 166,176 **** if (cp != NULL && cp[1] != '\0') continue; fl[i].st.flags |= FLSTAT_TOP_DIR; ! LOG4(sess, "%s: top-level", fl[i].wpath); } } else if (flsz) { fl[0].st.flags |= FLSTAT_TOP_DIR; ! LOG4(sess, "%s: top-level", fl[0].wpath); } } --- 166,176 ---- if (cp != NULL && cp[1] != '\0') continue; fl[i].st.flags |= FLSTAT_TOP_DIR; ! LOG4("%s: top-level", fl[i].wpath); } } else if (flsz) { fl[0].st.flags |= FLSTAT_TOP_DIR; ! LOG4("%s: top-level", fl[0].wpath); } } *************** *** 191,205 **** return 1; if (ent->fts_info == FTS_DC) { ! WARNX(sess, "%s: directory cycle", ent->fts_path); } else if (ent->fts_info == FTS_DNR) { errno = ent->fts_errno; ! WARN(sess, "%s: unreadable directory", ent->fts_path); } else if (ent->fts_info == FTS_DOT) { ! WARNX(sess, "%s: skipping dot-file", ent->fts_path); } else if (ent->fts_info == FTS_ERR) { errno = ent->fts_errno; ! WARN(sess, "%s", ent->fts_path); } else if (ent->fts_info == FTS_DEFAULT) { if ((sess->opts->devices && (S_ISBLK(ent->fts_statp->st_mode) || S_ISCHR(ent->fts_statp->st_mode))) || --- 191,205 ---- return 1; if (ent->fts_info == FTS_DC) { ! WARNX("%s: directory cycle", ent->fts_path); } else if (ent->fts_info == FTS_DNR) { errno = ent->fts_errno; ! WARN("%s: unreadable directory", ent->fts_path); } else if (ent->fts_info == FTS_DOT) { ! WARNX("%s: skipping dot-file", ent->fts_path); } else if (ent->fts_info == FTS_ERR) { errno = ent->fts_errno; ! WARN("%s", ent->fts_path); } else if (ent->fts_info == FTS_DEFAULT) { if ((sess->opts->devices && (S_ISBLK(ent->fts_statp->st_mode) || S_ISCHR(ent->fts_statp->st_mode))) || *************** *** 208,217 **** S_ISSOCK(ent->fts_statp->st_mode)))) { return 1; } ! WARNX(sess, "%s: skipping special", ent->fts_path); } else if (ent->fts_info == FTS_NS) { errno = ent->fts_errno; ! WARN(sess, "%s: could not stat", ent->fts_path); } return 0; --- 208,217 ---- S_ISSOCK(ent->fts_statp->st_mode)))) { return 1; } ! WARNX("%s: skipping special", ent->fts_path); } else if (ent->fts_info == FTS_NS) { errno = ent->fts_errno; ! WARN("%s: could not stat", ent->fts_path); } return 0; *************** *** 265,271 **** /* Double-check that we've no pending multiplexed data. */ ! LOG2(sess, "sending file metadata list: %zu", flsz); for (i = 0; i < flsz; i++) { f = &fl[i]; --- 265,271 ---- /* Double-check that we've no pending multiplexed data. */ ! LOG2("sending file metadata list: %zu", flsz); for (i = 0; i < flsz; i++) { f = &fl[i]; *************** *** 284,290 **** if (sess->mplex_reads && io_read_check(sess, fdin) && !io_read_flush(sess, fdin)) { ! ERRX1(sess, "io_read_flush"); goto out; } --- 284,290 ---- if (sess->mplex_reads && io_read_check(sess, fdin) && !io_read_flush(sess, fdin)) { ! ERRX1("io_read_flush"); goto out; } *************** *** 299,305 **** if ((FLSTAT_TOP_DIR & f->st.flags)) flag |= FLIST_TOP_LEVEL; ! LOG3(sess, "%s: sending file metadata: " "size %jd, mtime %jd, mode %o", fn, (intmax_t)f->st.size, (intmax_t)f->st.mtime, f->st.mode); --- 299,305 ---- if ((FLSTAT_TOP_DIR & f->st.flags)) flag |= FLIST_TOP_LEVEL; ! LOG3("%s: sending file metadata: " "size %jd, mtime %jd, mode %o", fn, (intmax_t)f->st.size, (intmax_t)f->st.mtime, f->st.mode); *************** *** 308,329 **** /* FIXME: buffer this. */ if (!io_write_byte(sess, fdout, flag)) { ! ERRX1(sess, "io_write_byte"); goto out; } else if (!io_write_int(sess, fdout, sz)) { ! ERRX1(sess, "io_write_int"); goto out; } else if (!io_write_buf(sess, fdout, fn, sz)) { ! ERRX1(sess, "io_write_buf"); goto out; } else if (!io_write_long(sess, fdout, f->st.size)) { ! ERRX1(sess, "io_write_long"); goto out; } else if (!io_write_uint(sess, fdout, (uint32_t)f->st.mtime)) { ! ERRX1(sess, "io_write_uint"); goto out; } else if (!io_write_uint(sess, fdout, f->st.mode)) { ! ERRX1(sess, "io_write_uint"); goto out; } --- 308,329 ---- /* FIXME: buffer this. */ if (!io_write_byte(sess, fdout, flag)) { ! ERRX1("io_write_byte"); goto out; } else if (!io_write_int(sess, fdout, sz)) { ! ERRX1("io_write_int"); goto out; } else if (!io_write_buf(sess, fdout, fn, sz)) { ! ERRX1("io_write_buf"); goto out; } else if (!io_write_long(sess, fdout, f->st.size)) { ! ERRX1("io_write_long"); goto out; } else if (!io_write_uint(sess, fdout, (uint32_t)f->st.mtime)) { ! ERRX1("io_write_uint"); goto out; } else if (!io_write_uint(sess, fdout, f->st.mode)) { ! ERRX1("io_write_uint"); goto out; } *************** *** 331,341 **** if (sess->opts->preserve_uids) { if (!io_write_uint(sess, fdout, f->st.uid)) { ! ERRX1(sess, "io_write_uint"); goto out; } if (!idents_add(sess, 0, &uids, &uidsz, f->st.uid)) { ! ERRX1(sess, "idents_add"); goto out; } } --- 331,341 ---- if (sess->opts->preserve_uids) { if (!io_write_uint(sess, fdout, f->st.uid)) { ! ERRX1("io_write_uint"); goto out; } if (!idents_add(sess, 0, &uids, &uidsz, f->st.uid)) { ! ERRX1("idents_add"); goto out; } } *************** *** 344,354 **** if (sess->opts->preserve_gids) { if (!io_write_uint(sess, fdout, f->st.gid)) { ! ERRX1(sess, "io_write_uint"); goto out; } if (!idents_add(sess, 1, &gids, &gidsz, f->st.gid)) { ! ERRX1(sess, "idents_add"); goto out; } } --- 344,354 ---- if (sess->opts->preserve_gids) { if (!io_write_uint(sess, fdout, f->st.gid)) { ! ERRX1("io_write_uint"); goto out; } if (!idents_add(sess, 1, &gids, &gidsz, f->st.gid)) { ! ERRX1("idents_add"); goto out; } } *************** *** 360,366 **** (sess->opts->specials && (S_ISFIFO(f->st.mode) || S_ISSOCK(f->st.mode)))) { if (!io_write_int(sess, fdout, f->st.rdev)) { ! ERRX1(sess, "io_write_int"); goto out; } } --- 360,366 ---- (sess->opts->specials && (S_ISFIFO(f->st.mode) || S_ISSOCK(f->st.mode)))) { if (!io_write_int(sess, fdout, f->st.rdev)) { ! ERRX1("io_write_int"); goto out; } } *************** *** 373,383 **** sz = strlen(f->link); assert(sz < INT32_MAX); if (!io_write_int(sess, fdout, sz)) { ! ERRX1(sess, "io_write_int"); goto out; } if (!io_write_buf(sess, fdout, fn, sz)) { ! ERRX1(sess, "io_write_buf"); goto out; } } --- 373,383 ---- sz = strlen(f->link); assert(sz < INT32_MAX); if (!io_write_int(sess, fdout, sz)) { ! ERRX1("io_write_int"); goto out; } if (!io_write_buf(sess, fdout, fn, sz)) { ! ERRX1("io_write_buf"); goto out; } } *************** *** 389,412 **** /* Signal end of file list. */ if (!io_write_byte(sess, fdout, 0)) { ! ERRX1(sess, "io_write_byte"); goto out; } /* Conditionally write identifier lists. */ if (sess->opts->preserve_uids && !sess->opts->numeric_ids) { ! LOG2(sess, "sending uid list: %zu", uidsz); if (!idents_send(sess, fdout, uids, uidsz)) { ! ERRX1(sess, "idents_send"); goto out; } } if (sess->opts->preserve_gids && !sess->opts->numeric_ids) { ! LOG2(sess, "sending gid list: %zu", gidsz); if (!idents_send(sess, fdout, gids, gidsz)) { ! ERRX1(sess, "idents_send"); goto out; } } --- 389,412 ---- /* Signal end of file list. */ if (!io_write_byte(sess, fdout, 0)) { ! ERRX1("io_write_byte"); goto out; } /* Conditionally write identifier lists. */ if (sess->opts->preserve_uids && !sess->opts->numeric_ids) { ! LOG2("sending uid list: %zu", uidsz); if (!idents_send(sess, fdout, uids, uidsz)) { ! ERRX1("idents_send"); goto out; } } if (sess->opts->preserve_gids && !sess->opts->numeric_ids) { ! LOG2("sending gid list: %zu", gidsz); if (!idents_send(sess, fdout, gids, gidsz)) { ! ERRX1("idents_send"); goto out; } } *************** *** 444,450 **** if (FLIST_NAME_SAME & flags) { if (!io_read_byte(sess, fd, &bval)) { ! ERRX1(sess, "io_read_byte"); return 0; } partial = bval; --- 444,450 ---- if (FLIST_NAME_SAME & flags) { if (!io_read_byte(sess, fd, &bval)) { ! ERRX1("io_read_byte"); return 0; } partial = bval; *************** *** 454,465 **** if (FLIST_NAME_LONG & flags) { if (!io_read_size(sess, fd, &pathlen)) { ! ERRX1(sess, "io_read_size"); return 0; } } else { if (!io_read_byte(sess, fd, &bval)) { ! ERRX1(sess, "io_read_byte"); return 0; } pathlen = bval; --- 454,465 ---- if (FLIST_NAME_LONG & flags) { if (!io_read_size(sess, fd, &pathlen)) { ! ERRX1("io_read_size"); return 0; } } else { if (!io_read_byte(sess, fd, &bval)) { ! ERRX1("io_read_byte"); return 0; } pathlen = bval; *************** *** 469,480 **** /* FIXME: maximum pathname length. */ if ((len = pathlen + partial) == 0) { ! ERRX(sess, "security violation: zero-length pathname"); return 0; } if ((f->path = malloc(len + 1)) == NULL) { ! ERR(sess, "malloc"); return 0; } f->path[len] = '\0'; --- 469,480 ---- /* FIXME: maximum pathname length. */ if ((len = pathlen + partial) == 0) { ! ERRX("security violation: zero-length pathname"); return 0; } if ((f->path = malloc(len + 1)) == NULL) { ! ERR("malloc"); return 0; } f->path[len] = '\0'; *************** *** 483,494 **** memcpy(f->path, last, partial); if (!io_read_buf(sess, fd, f->path + partial, pathlen)) { ! ERRX1(sess, "io_read_buf"); return 0; } if (f->path[0] == '/') { ! ERRX(sess, "security violation: absolute pathname: %s", f->path); return 0; } --- 483,494 ---- memcpy(f->path, last, partial); if (!io_read_buf(sess, fd, f->path + partial, pathlen)) { ! ERRX1("io_read_buf"); return 0; } if (f->path[0] == '/') { ! ERRX("security violation: absolute pathname: %s", f->path); return 0; } *************** *** 497,503 **** (len > 2 && strcmp(f->path + len - 3, "/..") == 0) || (len > 2 && strncmp(f->path, "../", 3) == 0) || strcmp(f->path, "..") == 0) { ! ERRX(sess, "%s: security violation: backtracking pathname", f->path); return 0; } --- 497,503 ---- (len > 2 && strcmp(f->path + len - 3, "/..") == 0) || (len > 2 && strncmp(f->path, "../", 3) == 0) || strcmp(f->path, "..") == 0) { ! ERRX("%s: security violation: backtracking pathname", f->path); return 0; } *************** *** 526,532 **** pp = recallocarray(*fl, *max, *max + FLIST_CHUNK_SIZE, sizeof(struct flist)); if (pp == NULL) { ! ERR(sess, "recallocarray"); return 0; } *fl = pp; --- 526,532 ---- pp = recallocarray(*fl, *max, *max + FLIST_CHUNK_SIZE, sizeof(struct flist)); if (pp == NULL) { ! ERR("recallocarray"); return 0; } *fl = pp; *************** *** 551,557 **** */ if ((f->path = strdup(path)) == NULL) { ! ERR(sess, "strdup"); return 0; } --- 551,557 ---- */ if ((f->path = strdup(path)) == NULL) { ! ERR("strdup"); return 0; } *************** *** 573,579 **** if (S_ISLNK(st->st_mode)) { f->link = symlink_read(sess, f->path); if (f->link == NULL) { ! ERRX1(sess, "symlink_read"); return 0; } } --- 573,579 ---- if (S_ISLNK(st->st_mode)) { f->link = symlink_read(sess, f->path); if (f->link == NULL) { ! ERRX1("symlink_read"); return 0; } } *************** *** 604,616 **** for (;;) { if (!io_read_byte(sess, fd, &flag)) { ! ERRX1(sess, "io_read_byte"); goto out; } else if (flag == 0) break; if (!flist_realloc(sess, &fl, &flsz, &flmax)) { ! ERRX1(sess, "flist_realloc"); goto out; } --- 604,616 ---- for (;;) { if (!io_read_byte(sess, fd, &flag)) { ! ERRX1("io_read_byte"); goto out; } else if (flag == 0) break; if (!flist_realloc(sess, &fl, &flsz, &flmax)) { ! ERRX1("flist_realloc"); goto out; } *************** *** 620,633 **** /* Filename first. */ if (!flist_recv_name(sess, fd, ff, flag, last)) { ! ERRX1(sess, "flist_recv_name"); goto out; } /* Read the file size. */ if (!io_read_long(sess, fd, &lval)) { ! ERRX1(sess, "io_read_long"); goto out; } ff->st.size = lval; --- 620,633 ---- /* Filename first. */ if (!flist_recv_name(sess, fd, ff, flag, last)) { ! ERRX1("flist_recv_name"); goto out; } /* Read the file size. */ if (!io_read_long(sess, fd, &lval)) { ! ERRX1("io_read_long"); goto out; } ff->st.size = lval; *************** *** 636,647 **** if (!(FLIST_TIME_SAME & flag)) { if (!io_read_uint(sess, fd, &uival)) { ! ERRX1(sess, "io_read_int"); goto out; } ff->st.mtime = uival; /* beyond 2038 */ } else if (fflast == NULL) { ! ERRX(sess, "same time without last entry"); goto out; } else ff->st.mtime = fflast->st.mtime; --- 636,647 ---- if (!(FLIST_TIME_SAME & flag)) { if (!io_read_uint(sess, fd, &uival)) { ! ERRX1("io_read_int"); goto out; } ff->st.mtime = uival; /* beyond 2038 */ } else if (fflast == NULL) { ! ERRX("same time without last entry"); goto out; } else ff->st.mtime = fflast->st.mtime; *************** *** 650,661 **** if (!(FLIST_MODE_SAME & flag)) { if (!io_read_uint(sess, fd, &uival)) { ! ERRX1(sess, "io_read_int"); goto out; } ff->st.mode = uival; } else if (fflast == NULL) { ! ERRX(sess, "same mode without last entry"); goto out; } else ff->st.mode = fflast->st.mode; --- 650,661 ---- if (!(FLIST_MODE_SAME & flag)) { if (!io_read_uint(sess, fd, &uival)) { ! ERRX1("io_read_int"); goto out; } ff->st.mode = uival; } else if (fflast == NULL) { ! ERRX("same mode without last entry"); goto out; } else ff->st.mode = fflast->st.mode; *************** *** 665,676 **** if (sess->opts->preserve_uids) { if (!(FLIST_UID_SAME & flag)) { if (!io_read_uint(sess, fd, &uival)) { ! ERRX1(sess, "io_read_int"); goto out; } ff->st.uid = uival; } else if (fflast == NULL) { ! ERRX(sess, "same uid without last entry"); goto out; } else ff->st.uid = fflast->st.uid; --- 665,676 ---- if (sess->opts->preserve_uids) { if (!(FLIST_UID_SAME & flag)) { if (!io_read_uint(sess, fd, &uival)) { ! ERRX1("io_read_int"); goto out; } ff->st.uid = uival; } else if (fflast == NULL) { ! ERRX("same uid without last entry"); goto out; } else ff->st.uid = fflast->st.uid; *************** *** 681,692 **** if (sess->opts->preserve_gids) { if (!(FLIST_GID_SAME & flag)) { if (!io_read_uint(sess, fd, &uival)) { ! ERRX1(sess, "io_read_int"); goto out; } ff->st.gid = uival; } else if (fflast == NULL) { ! ERRX(sess, "same gid without last entry"); goto out; } else ff->st.gid = fflast->st.gid; --- 681,692 ---- if (sess->opts->preserve_gids) { if (!(FLIST_GID_SAME & flag)) { if (!io_read_uint(sess, fd, &uival)) { ! ERRX1("io_read_int"); goto out; } ff->st.gid = uival; } else if (fflast == NULL) { ! ERRX("same gid without last entry"); goto out; } else ff->st.gid = fflast->st.gid; *************** *** 700,711 **** S_ISSOCK(ff->st.mode)))) { if (!(FLIST_RDEV_SAME & flag)) { if (!io_read_int(sess, fd, &ival)) { ! ERRX1(sess, "io_read_int"); goto out; } ff->st.rdev = ival; } else if (fflast == NULL) { ! ERRX(sess, "same device without last entry"); goto out; } else ff->st.rdev = fflast->st.rdev; --- 700,711 ---- S_ISSOCK(ff->st.mode)))) { if (!(FLIST_RDEV_SAME & flag)) { if (!io_read_int(sess, fd, &ival)) { ! ERRX1("io_read_int"); goto out; } ff->st.rdev = ival; } else if (fflast == NULL) { ! ERRX("same device without last entry"); goto out; } else ff->st.rdev = fflast->st.rdev; *************** *** 716,739 **** if (S_ISLNK(ff->st.mode) && sess->opts->preserve_links) { if (!io_read_size(sess, fd, &lsz)) { ! ERRX1(sess, "io_read_size"); goto out; } else if (lsz == 0) { ! ERRX(sess, "empty link name"); goto out; } ff->link = calloc(lsz + 1, 1); if (ff->link == NULL) { ! ERR(sess, "calloc"); goto out; } if (!io_read_buf(sess, fd, ff->link, lsz)) { ! ERRX1(sess, "io_read_buf"); goto out; } } ! LOG3(sess, "%s: received file metadata: " "size %jd, mtime %jd, mode %o, rdev (%d, %d)", ff->path, (intmax_t)ff->st.size, (intmax_t)ff->st.mtime, ff->st.mode, --- 716,739 ---- if (S_ISLNK(ff->st.mode) && sess->opts->preserve_links) { if (!io_read_size(sess, fd, &lsz)) { ! ERRX1("io_read_size"); goto out; } else if (lsz == 0) { ! ERRX("empty link name"); goto out; } ff->link = calloc(lsz + 1, 1); if (ff->link == NULL) { ! ERR("calloc"); goto out; } if (!io_read_buf(sess, fd, ff->link, lsz)) { ! ERRX1("io_read_buf"); goto out; } } ! LOG3("%s: received file metadata: " "size %jd, mtime %jd, mode %o, rdev (%d, %d)", ff->path, (intmax_t)ff->st.size, (intmax_t)ff->st.mtime, ff->st.mode, *************** *** 747,769 **** if (sess->opts->preserve_uids && !sess->opts->numeric_ids) { if (!idents_recv(sess, fd, &uids, &uidsz)) { ! ERRX1(sess, "idents_recv"); goto out; } ! LOG2(sess, "received uid list: %zu", uidsz); } if (sess->opts->preserve_gids && !sess->opts->numeric_ids) { if (!idents_recv(sess, fd, &gids, &gidsz)) { ! ERRX1(sess, "idents_recv"); goto out; } ! LOG2(sess, "received gid list: %zu", gidsz); } /* Remember to order the received list. */ ! LOG2(sess, "received file metadata list: %zu", flsz); qsort(fl, flsz, sizeof(struct flist), flist_cmp); flist_topdirs(sess, fl, flsz); *sz = flsz; --- 747,769 ---- if (sess->opts->preserve_uids && !sess->opts->numeric_ids) { if (!idents_recv(sess, fd, &uids, &uidsz)) { ! ERRX1("idents_recv"); goto out; } ! LOG2("received uid list: %zu", uidsz); } if (sess->opts->preserve_gids && !sess->opts->numeric_ids) { if (!idents_recv(sess, fd, &gids, &gidsz)) { ! ERRX1("idents_recv"); goto out; } ! LOG2("received gid list: %zu", gidsz); } /* Remember to order the received list. */ ! LOG2("received file metadata list: %zu", flsz); qsort(fl, flsz, sizeof(struct flist), flist_cmp); flist_topdirs(sess, fl, flsz); *sz = flsz; *************** *** 821,867 **** */ if (lstat(root, &st) == -1) { ! ERR(sess, "%s: lstat", root); return 0; } else if (S_ISREG(st.st_mode)) { if (!flist_realloc(sess, fl, sz, max)) { ! ERRX1(sess, "flist_realloc"); return 0; } f = &(*fl)[(*sz) - 1]; assert(f != NULL); if (!flist_append(sess, f, &st, root)) { ! ERRX1(sess, "flist_append"); return 0; } if (unveil(root, "r") == -1) { ! ERR(sess, "%s: unveil", root); return 0; } return 1; } else if (S_ISLNK(st.st_mode)) { if (!sess->opts->preserve_links) { ! WARNX(sess, "%s: skipping symlink", root); return 1; } else if (!flist_realloc(sess, fl, sz, max)) { ! ERRX1(sess, "flist_realloc"); return 0; } f = &(*fl)[(*sz) - 1]; assert(f != NULL); if (!flist_append(sess, f, &st, root)) { ! ERRX1(sess, "flist_append"); return 0; } if (unveil(root, "r") == -1) { ! ERR(sess, "%s: unveil", root); return 0; } return 1; } else if (!S_ISDIR(st.st_mode)) { ! WARNX(sess, "%s: skipping special", root); return 1; } --- 821,867 ---- */ if (lstat(root, &st) == -1) { ! ERR("%s: lstat", root); return 0; } else if (S_ISREG(st.st_mode)) { if (!flist_realloc(sess, fl, sz, max)) { ! ERRX1("flist_realloc"); return 0; } f = &(*fl)[(*sz) - 1]; assert(f != NULL); if (!flist_append(sess, f, &st, root)) { ! ERRX1("flist_append"); return 0; } if (unveil(root, "r") == -1) { ! ERR("%s: unveil", root); return 0; } return 1; } else if (S_ISLNK(st.st_mode)) { if (!sess->opts->preserve_links) { ! WARNX("%s: skipping symlink", root); return 1; } else if (!flist_realloc(sess, fl, sz, max)) { ! ERRX1("flist_realloc"); return 0; } f = &(*fl)[(*sz) - 1]; assert(f != NULL); if (!flist_append(sess, f, &st, root)) { ! ERRX1("flist_append"); return 0; } if (unveil(root, "r") == -1) { ! ERR("%s: unveil", root); return 0; } return 1; } else if (!S_ISDIR(st.st_mode)) { ! WARNX("%s: skipping special", root); return 1; } *************** *** 894,900 **** */ if ((fts = fts_open(cargv, FTS_PHYSICAL, NULL)) == NULL) { ! ERR(sess, "fts_open"); return 0; } --- 894,900 ---- */ if ((fts = fts_open(cargv, FTS_PHYSICAL, NULL)) == NULL) { ! ERR("fts_open"); return 0; } *************** *** 910,916 **** assert(ent->fts_statp != NULL); if (S_ISLNK(ent->fts_statp->st_mode) && !sess->opts->preserve_links) { ! WARNX(sess, "%s: skipping symlink", ent->fts_path); continue; } --- 910,916 ---- assert(ent->fts_statp != NULL); if (S_ISLNK(ent->fts_statp->st_mode) && !sess->opts->preserve_links) { ! WARNX("%s: skipping symlink", ent->fts_path); continue; } *************** *** 933,939 **** continue; if ((xdev = malloc(sizeof(dev_t))) == NULL) { ! ERRX1(sess, "malloc"); goto out; } --- 933,939 ---- continue; if ((xdev = malloc(sizeof(dev_t))) == NULL) { ! ERRX1("malloc"); goto out; } *************** *** 949,955 **** if (nxdev) if ((xdev = realloc(xdev, sizeof(dev_t))) == NULL) { ! ERRX1(sess, "realloc"); goto out; } xdev[nxdev] = ent->fts_statp->st_dev; --- 949,955 ---- if (nxdev) if ((xdev = realloc(xdev, sizeof(dev_t))) == NULL) { ! ERRX1("realloc"); goto out; } xdev[nxdev] = ent->fts_statp->st_dev; *************** *** 959,965 **** /* Allocate a new file entry. */ if (!flist_realloc(sess, fl, sz, max)) { ! ERRX1(sess, "flist_realloc"); goto out; } flsz++; --- 959,965 ---- /* Allocate a new file entry. */ if (!flist_realloc(sess, fl, sz, max)) { ! ERRX1("flist_realloc"); goto out; } flsz++; *************** *** 969,981 **** if (ent->fts_path[stripdir] == '\0') { if (asprintf(&f->path, "%s.", ent->fts_path) < 0) { ! ERR(sess, "asprintf"); f->path = NULL; goto out; } } else { if ((f->path = strdup(ent->fts_path)) == NULL) { ! ERR(sess, "strdup"); goto out; } } --- 969,981 ---- if (ent->fts_path[stripdir] == '\0') { if (asprintf(&f->path, "%s.", ent->fts_path) < 0) { ! ERR("asprintf"); f->path = NULL; goto out; } } else { if ((f->path = strdup(ent->fts_path)) == NULL) { ! ERR("strdup"); goto out; } } *************** *** 988,994 **** if (S_ISLNK(ent->fts_statp->st_mode)) { f->link = symlink_read(sess, f->path); if (f->link == NULL) { ! ERRX1(sess, "symlink_read"); goto out; } } --- 988,994 ---- if (S_ISLNK(ent->fts_statp->st_mode)) { f->link = symlink_read(sess, f->path); if (f->link == NULL) { ! ERRX1("symlink_read"); goto out; } } *************** *** 997,1011 **** errno = 0; } if (errno) { ! ERR(sess, "fts_read"); goto out; } if (unveil(root, "r") == -1) { ! ERR(sess, "%s: unveil", root); goto out; } ! LOG3(sess, "generated %zu filenames: %s", flsz, root); rc = 1; out: fts_close(fts); --- 997,1011 ---- errno = 0; } if (errno) { ! ERR("fts_read"); goto out; } if (unveil(root, "r") == -1) { ! ERR("%s: unveil", root); goto out; } ! LOG3("generated %zu filenames: %s", flsz, root); rc = 1; out: fts_close(fts); *************** *** 1032,1042 **** break; if (i == argc) { ! LOG2(sess, "recursively generated %zu filenames", *sz); return 1; } ! ERRX1(sess, "flist_gen_dirent"); flist_free(*flp, max); *flp = NULL; *sz = 0; --- 1032,1042 ---- break; if (i == argc) { ! LOG2("recursively generated %zu filenames", *sz); return 1; } ! ERRX1("flist_gen_dirent"); flist_free(*flp, max); *flp = NULL; *sz = 0; *************** *** 1060,1066 **** assert(argc); if ((fl = calloc(argc, sizeof(struct flist))) == NULL) { ! ERR(sess, "calloc"); return 0; } --- 1060,1066 ---- assert(argc); if ((fl = calloc(argc, sizeof(struct flist))) == NULL) { ! ERR("calloc"); return 0; } *************** *** 1068,1074 **** if (argv[i][0] == '\0') continue; if (lstat(argv[i], &st) == -1) { ! ERR(sess, "%s: lstat", argv[i]); goto out; } --- 1068,1074 ---- if (argv[i][0] == '\0') continue; if (lstat(argv[i], &st) == -1) { ! ERR("%s: lstat", argv[i]); goto out; } *************** *** 1080,1094 **** */ if (S_ISDIR(st.st_mode)) { ! WARNX(sess, "%s: skipping directory", argv[i]); continue; } else if (S_ISLNK(st.st_mode)) { if (!sess->opts->preserve_links) { ! WARNX(sess, "%s: skipping symlink", argv[i]); continue; } } else if (!S_ISREG(st.st_mode)) { ! WARNX(sess, "%s: skipping special", argv[i]); continue; } --- 1080,1094 ---- */ if (S_ISDIR(st.st_mode)) { ! WARNX("%s: skipping directory", argv[i]); continue; } else if (S_ISLNK(st.st_mode)) { if (!sess->opts->preserve_links) { ! WARNX("%s: skipping symlink", argv[i]); continue; } } else if (!S_ISREG(st.st_mode)) { ! WARNX("%s: skipping special", argv[i]); continue; } *************** *** 1099,1114 **** /* Add this file to our file-system worldview. */ if (unveil(argv[i], "r") == -1) { ! ERR(sess, "%s: unveil", argv[i]); goto out; } if (!flist_append(sess, f, &st, argv[i])) { ! ERRX1(sess, "flist_append"); goto out; } } ! LOG2(sess, "non-recursively generated %zu filenames", flsz); *sz = flsz; *flp = fl; return 1; --- 1099,1114 ---- /* Add this file to our file-system worldview. */ if (unveil(argv[i], "r") == -1) { ! ERR("%s: unveil", argv[i]); goto out; } if (!flist_append(sess, f, &st, argv[i])) { ! ERRX1("flist_append"); goto out; } } ! LOG2("non-recursively generated %zu filenames", flsz); *sz = flsz; *flp = fl; return 1; *************** *** 1141,1147 **** /* After scanning, lock our file-system view. */ if (unveil(NULL, NULL) == -1) { ! ERR(sess, "unveil"); return 0; } if (!rc) --- 1141,1147 ---- /* After scanning, lock our file-system view. */ if (unveil(NULL, NULL) == -1) { ! ERR("unveil"); return 0; } if (!rc) *************** *** 1154,1160 **** return 1; } ! ERRX1(sess, "flist_dedupe"); flist_free(*flp, *sz); *flp = NULL; *sz = 0; --- 1154,1160 ---- return 1; } ! ERRX1("flist_dedupe"); flist_free(*flp, *sz); *flp = NULL; *sz = 0; *************** *** 1206,1212 **** return 1; if ((cargv = calloc(cargvs + 1, sizeof(char *))) == NULL) { ! ERR(sess, "calloc"); return 0; } --- 1206,1212 ---- return 1; if ((cargv = calloc(cargvs + 1, sizeof(char *))) == NULL) { ! ERR("calloc"); return 0; } *************** *** 1221,1227 **** assert(cargvs == 1); assert(S_ISDIR(wfl[0].st.mode)); if (asprintf(&cargv[0], "%s/", root) < 0) { ! ERR(sess, "asprintf"); cargv[0] = NULL; goto out; } --- 1221,1227 ---- assert(cargvs == 1); assert(S_ISDIR(wfl[0].st.mode)); if (asprintf(&cargv[0], "%s/", root) < 0) { ! ERR("asprintf"); cargv[0] = NULL; goto out; } *************** *** 1234,1251 **** assert(strcmp(wfl[i].wpath, ".")); c = asprintf(&cargv[j], "%s/%s", root, wfl[i].wpath); if (c < 0) { ! ERR(sess, "asprintf"); cargv[j] = NULL; goto out; } ! LOG4(sess, "%s: will scan for deletions", cargv[j]); j++; } assert(j == cargvs); cargv[j] = NULL; } ! LOG2(sess, "delete from %zu directories", cargvs); /* * Next, use the standard hcreate(3) hashtable interface to hash --- 1234,1251 ---- assert(strcmp(wfl[i].wpath, ".")); c = asprintf(&cargv[j], "%s/%s", root, wfl[i].wpath); if (c < 0) { ! ERR("asprintf"); cargv[j] = NULL; goto out; } ! LOG4("%s: will scan for deletions", cargv[j]); j++; } assert(j == cargvs); cargv[j] = NULL; } ! LOG2("delete from %zu directories", cargvs); /* * Next, use the standard hcreate(3) hashtable interface to hash *************** *** 1257,1277 **** */ if (!hcreate(wflsz)) { ! ERR(sess, "hcreate"); goto out; } for (i = 0; i < wflsz; i++) { memset(&hent, 0, sizeof(ENTRY)); if ((hent.key = strdup(wfl[i].wpath)) == NULL) { ! ERR(sess, "strdup"); goto out; } if ((hentp = hsearch(hent, ENTER)) == NULL) { ! ERR(sess, "hsearch"); goto out; } else if (hentp->key != hent.key) { ! ERRX(sess, "%s: duplicate", wfl[i].wpath); free(hent.key); goto out; } --- 1257,1277 ---- */ if (!hcreate(wflsz)) { ! ERR("hcreate"); goto out; } for (i = 0; i < wflsz; i++) { memset(&hent, 0, sizeof(ENTRY)); if ((hent.key = strdup(wfl[i].wpath)) == NULL) { ! ERR("strdup"); goto out; } if ((hentp = hsearch(hent, ENTER)) == NULL) { ! ERR("hsearch"); goto out; } else if (hentp->key != hent.key) { ! ERRX("%s: duplicate", wfl[i].wpath); free(hent.key); goto out; } *************** *** 1284,1290 **** */ if ((fts = fts_open(cargv, FTS_PHYSICAL, NULL)) == NULL) { ! ERR(sess, "fts_open"); goto out; } --- 1284,1290 ---- */ if ((fts = fts_open(cargv, FTS_PHYSICAL, NULL)) == NULL) { ! ERR("fts_open"); goto out; } *************** *** 1312,1318 **** flag = 0; for (i = 0; i < wflsz; i++) { if (stat(wfl[i].path, &st) == -1) { ! ERR(sess, "%s: stat", wfl[i].path); goto out; } if (ent->fts_statp->st_dev == st.st_dev) { --- 1312,1318 ---- flag = 0; for (i = 0; i < wflsz; i++) { if (stat(wfl[i].path, &st) == -1) { ! ERR("%s: stat", wfl[i].path); goto out; } if (ent->fts_statp->st_dev == st.st_dev) { *************** *** 1334,1346 **** /* Not found: we'll delete it. */ if (!flist_realloc(sess, fl, sz, &max)) { ! ERRX1(sess, "flist_realloc"); goto out; } f = &(*fl)[*sz - 1]; if ((f->path = strdup(ent->fts_path)) == NULL) { ! ERR(sess, "strdup"); goto out; } f->wpath = f->path + stripdir; --- 1334,1346 ---- /* Not found: we'll delete it. */ if (!flist_realloc(sess, fl, sz, &max)) { ! ERRX1("flist_realloc"); goto out; } f = &(*fl)[*sz - 1]; if ((f->path = strdup(ent->fts_path)) == NULL) { ! ERR("strdup"); goto out; } f->wpath = f->path + stripdir; *************** *** 1349,1355 **** } if (errno) { ! ERR(sess, "fts_read"); goto out; } --- 1349,1355 ---- } if (errno) { ! ERR("fts_read"); goto out; } *************** *** 1384,1397 **** assert(sess->opts->recursive); for (i = flsz - 1; i >= 0; i--) { ! LOG1(sess, "%s: deleting", fl[i].wpath); if (sess->opts->dry_run) continue; assert(root != -1); flag = S_ISDIR(fl[i].st.mode) ? AT_REMOVEDIR : 0; if (unlinkat(root, fl[i].wpath, flag) == -1 && errno != ENOENT) { ! ERR(sess, "%s: unlinkat", fl[i].wpath); return 0; } } --- 1384,1397 ---- assert(sess->opts->recursive); for (i = flsz - 1; i >= 0; i--) { ! LOG1("%s: deleting", fl[i].wpath); if (sess->opts->dry_run) continue; assert(root != -1); flag = S_ISDIR(fl[i].st.mode) ? AT_REMOVEDIR : 0; if (unlinkat(root, fl[i].wpath, flag) == -1 && errno != ENOENT) { ! ERR("%s: unlinkat", fl[i].wpath); return 0; } }