commit 08578a35f60be8657db97b705f27a55ab61850c8 from: Stefan Sperling date: Fri Jan 22 11:05:05 2021 UTC make close(2) failure checks consistent; check 'close() == -1' everywhere ok millert, naddy commit - 56b63ca4ab1049de6fa2d6910ce22c16e2b42a53 commit + 08578a35f60be8657db97b705f27a55ab61850c8 blob - 3986b23c81fbc180d2bf37f92161e9fd2855949c blob + b26da2a0b727f30ffdba6e4970dafa32b3856f53 --- lib/buf.c +++ lib/buf.c @@ -303,7 +303,7 @@ buf_write(BUF *b, const char *path, mode_t mode) if (fchmod(fd, mode) < 0) err = got_error_from_errno2("fchmod", path); - if (close(fd) != 0 && err == NULL) + if (close(fd) == -1 && err == NULL) err = got_error_from_errno2("close", path); return err; @@ -328,7 +328,7 @@ buf_write_stmp(BUF *b, char *template) (void)unlink(template); } - if (close(fd) != 0 && err == NULL) + if (close(fd) == -1 && err == NULL) err = got_error_from_errno("close"); return err; blob - 134a933494056e53673c29dc390c0621d0fdb1c2 blob + bc5756e623d51979c01828389337089965f782a8 --- lib/fetch.c +++ lib/fetch.c @@ -557,7 +557,7 @@ got_fetch_pack(struct got_object_id **pack_hash, struc GOT_PATH_PROG_FETCH_PACK, tmppackpath); } - if (close(imsg_fetchfds[1]) != 0) { + if (close(imsg_fetchfds[1]) == -1) { err = got_error_from_errno("close"); goto done; } @@ -732,7 +732,7 @@ got_fetch_pack(struct got_object_id **pack_hash, struc } else if (idxpid == 0) got_privsep_exec_child(imsg_idxfds, GOT_PATH_PROG_INDEX_PACK, tmppackpath); - if (close(imsg_idxfds[1]) != 0) { + if (close(imsg_idxfds[1]) == -1) { err = got_error_from_errno("close"); goto done; } blob - bc4cf864a87ae6ca01a4fa56e150cef5110d17aa blob + 71a5d735012116d324357ccca04f1c7be867e6c2 --- lib/lockfile.c +++ lib/lockfile.c @@ -82,7 +82,7 @@ got_lockfile_unlock(struct got_lockfile *lf) if (lf->path && lf->fd != -1 && unlink(lf->path) != 0) err = got_error_from_errno("unlink"); - if (lf->fd != -1 && close(lf->fd) != 0 && err == NULL) + if (lf->fd != -1 && close(lf->fd) == -1 && err == NULL) err = got_error_from_errno("close"); free(lf->path); free(lf->locked_path); blob - 7fe404aef7be55ad09e966e88a09b5f50694bda7 blob + b85e7651429752168e6f8eff2b764fe8bba2d501 --- lib/object.c +++ lib/object.c @@ -237,7 +237,7 @@ start_pack_privsep_child(struct got_pack *pack, struct /* not reached */ } - if (close(imsg_fds[1]) != 0) + if (close(imsg_fds[1]) == -1) return got_error_from_errno("close"); pack->privsep_child->imsg_fd = imsg_fds[0]; pack->privsep_child->pid = pid; @@ -362,7 +362,7 @@ read_object_header_privsep(struct got_object **obj, st /* not reached */ } - if (close(imsg_fds[1]) != 0) { + if (close(imsg_fds[1]) == -1) { err = got_error_from_errno("close"); free(ibuf); return err; @@ -542,7 +542,7 @@ read_commit_privsep(struct got_commit_object **commit, /* not reached */ } - if (close(imsg_fds[1]) != 0) { + if (close(imsg_fds[1]) == -1) { err = got_error_from_errno("close"); free(ibuf); return err; @@ -731,7 +731,7 @@ read_tree_privsep(struct got_tree_object **tree, int o /* not reached */ } - if (close(imsg_fds[1]) != 0) { + if (close(imsg_fds[1]) == -1) { err = got_error_from_errno("close"); free(ibuf); return err; @@ -1087,7 +1087,7 @@ read_blob_privsep(uint8_t **outbuf, size_t *size, size /* not reached */ } - if (close(imsg_fds[1]) != 0) { + if (close(imsg_fds[1]) == -1) { err = got_error_from_errno("close"); free(ibuf); return err; @@ -1163,7 +1163,7 @@ open_blob(struct got_blob_object **blob, struct got_re } if (outbuf) { - if (close(outfd) != 0 && err == NULL) + if (close(outfd) == -1 && err == NULL) err = got_error_from_errno("close"); outfd = -1; (*blob)->f = fmemopen(outbuf, size, "rb"); @@ -1444,7 +1444,7 @@ read_tag_privsep(struct got_tag_object **tag, int obj_ /* not reached */ } - if (close(imsg_fds[1]) != 0) { + if (close(imsg_fds[1]) == -1) { err = got_error_from_errno("close"); free(ibuf); return err; blob - 69a6e9627e2dc2a7d0090ee468fbae0ab966ad61 blob + 5b8443903a0b59be4df01a675d1d07201d2df656 --- lib/object_create.c +++ lib/object_create.c @@ -203,7 +203,7 @@ got_object_blob_file_create(struct got_object_id **id, rewind(*blobfile); done: free(header); - if (fd != -1 && close(fd) != 0 && err == NULL) + if (fd != -1 && close(fd) == -1 && err == NULL) err = got_error_from_errno("close"); if (err) { free(*id); blob - b46583a6e3ce2fe952e1c30726026d492c7f5734 blob + 712b0f55c1bb511c3d3829528964d5036a503d9d --- lib/pack.c +++ lib/pack.c @@ -408,7 +408,7 @@ got_packidx_close(struct got_packidx *packidx) free(packidx->hdr.large_offsets); free(packidx->hdr.trailer); } - if (close(packidx->fd) != 0 && err == NULL) + if (close(packidx->fd) == -1 && err == NULL) err = got_error_from_errno("close"); free(packidx); @@ -525,7 +525,7 @@ got_pack_stop_privsep_child(struct got_pack *pack) if (err) return err; err = got_privsep_wait_for_child(pack->privsep_child->pid); - if (close(pack->privsep_child->imsg_fd) != 0 && err == NULL) + if (close(pack->privsep_child->imsg_fd) == -1 && err == NULL) err = got_error_from_errno("close"); free(pack->privsep_child); pack->privsep_child = NULL; @@ -540,7 +540,7 @@ got_pack_close(struct got_pack *pack) err = got_pack_stop_privsep_child(pack); if (pack->map && munmap(pack->map, pack->filesize) == -1 && !err) err = got_error_from_errno("munmap"); - if (pack->fd != -1 && close(pack->fd) != 0 && err == NULL) + if (pack->fd != -1 && close(pack->fd) == -1 && err == NULL) err = got_error_from_errno("close"); pack->fd = -1; free(pack->path_packfile); blob - 4fb6f24032dafb92991f1671b8252d6b045fa81b blob + 2a8fcc8c9e2afd1ce22356056ac095e73d2c28c3 --- lib/privsep.c +++ lib/privsep.c @@ -2307,7 +2307,7 @@ got_privsep_unveil_exec_helpers(void) void got_privsep_exec_child(int imsg_fds[2], const char *path, const char *repo_path) { - if (close(imsg_fds[0]) != 0) { + if (close(imsg_fds[0]) == -1) { fprintf(stderr, "%s: %s\n", getprogname(), strerror(errno)); _exit(1); } blob - 4a6e13fd0afc2e6e9bb7a10467c39500a78a8734 blob + 1118dcefd897d4540eae1a9353d4bec5937e454d --- lib/repository.c +++ lib/repository.c @@ -740,7 +740,7 @@ got_repo_close(struct got_repository *repo) repo->privsep_children[i].pid); if (child_err && err == NULL) err = child_err; - if (close(repo->privsep_children[i].imsg_fd) != 0 && + if (close(repo->privsep_children[i].imsg_fd) == -1 && err == NULL) err = got_error_from_errno("close"); } blob - 987475721d0a49779239dc049fb56d6ac2e2b2fb blob + 2d9ccf00b3ed3c679a91587ccfd6c31854daf288 --- lib/worktree.c +++ lib/worktree.c @@ -504,7 +504,7 @@ got_worktree_close(struct got_worktree *worktree) free(worktree->base_commit_id); free(worktree->head_ref_name); if (worktree->lockfd != -1) { - if (close(worktree->lockfd) != 0) + if (close(worktree->lockfd) == -1) err = got_error_from_errno2("close", got_worktree_get_root_path(worktree)); } @@ -914,7 +914,7 @@ done: if (symlinkf && fclose(symlinkf) == EOF && err == NULL) err = got_error_from_errno2("fclose", symlink_path); free(symlink_path); - if (merged_fd != -1 && close(merged_fd) != 0 && err == NULL) + if (merged_fd != -1 && close(merged_fd) == -1 && err == NULL) err = got_error_from_errno("close"); if (f_orig && fclose(f_orig) == EOF && err == NULL) err = got_error_from_errno("fclose"); @@ -1581,7 +1581,7 @@ install_blob(struct got_worktree *worktree, const char } done: - if (fd != -1 && close(fd) != 0 && err == NULL) + if (fd != -1 && close(fd) == -1 && err == NULL) err = got_error_from_errno("close"); if (tmppath != NULL && unlink(tmppath) == -1 && err == NULL) err = got_error_from_errno2("unlink", tmppath); @@ -3623,7 +3623,7 @@ worktree_status(struct got_worktree *worktree, const c } done: free_ignores(&arg.ignores); - if (fd != -1 && close(fd) != 0 && err == NULL) + if (fd != -1 && close(fd) == -1 && err == NULL) err = got_error_from_errno("close"); free(ondisk_path); return err; blob - e2a99e9244c1e8aa84a417baa7dee7d96f020631 blob + 092a8f96cc20191276eeb1029676466039e7d80a --- libexec/got-read-blob/got-read-blob.c +++ libexec/got-read-blob/got-read-blob.c @@ -167,11 +167,11 @@ done: if (fclose(f) == EOF && err == NULL) err = got_error_from_errno("fclose"); } else if (imsg.fd != -1) { - if (close(imsg.fd) != 0 && err == NULL) + if (close(imsg.fd) == -1 && err == NULL) err = got_error_from_errno("close"); } if (imsg_outfd.fd != -1) { - if (close(imsg_outfd.fd) != 0 && err == NULL) + if (close(imsg_outfd.fd) == -1 && err == NULL) err = got_error_from_errno("close"); } @@ -190,7 +190,7 @@ done: got_privsep_send_error(&ibuf, err); } } - if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL) + if (close(GOT_IMSG_FD_CHILD) == -1 && err == NULL) err = got_error_from_errno("close"); return err ? 1 : 0; } blob - c87a051695b4876e48e59e310d957c7230135fb0 blob + 41be1eaa285e55bb1d8159555c63bdfa79adee92 --- libexec/got-read-commit/got-read-commit.c +++ libexec/got-read-commit/got-read-commit.c @@ -151,7 +151,7 @@ done: if (fclose(f) == EOF && err == NULL) err = got_error_from_errno("fclose"); } else if (imsg.fd != -1) { - if (close(imsg.fd) != 0 && err == NULL) + if (close(imsg.fd) == -1 && err == NULL) err = got_error_from_errno("close"); } imsg_free(&imsg); @@ -166,7 +166,7 @@ done: got_privsep_send_error(&ibuf, err); } } - if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL) + if (close(GOT_IMSG_FD_CHILD) == -1 && err == NULL) err = got_error_from_errno("close"); return err ? 1 : 0; } blob - b0457c7fd3f8239ee5f52338976899dd8ccaefee blob + eadef712009b2da9a414361c8395ccbd43f2b1aa --- libexec/got-read-gitconfig/got-read-gitconfig.c +++ libexec/got-read-gitconfig/got-read-gitconfig.c @@ -406,7 +406,7 @@ main(int argc, char *argv[]) got_privsep_send_error(&ibuf, err); } } - if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL) + if (close(GOT_IMSG_FD_CHILD) == -1 && err == NULL) err = got_error_from_errno("close"); return err ? 1 : 0; } blob - 2fe537dc6e1f300194d9d5d74a0b2e170c9a0010 blob + 682d443c685d81724cfda1569e2030e2bb02b87c --- libexec/got-read-gotconfig/got-read-gotconfig.c +++ libexec/got-read-gotconfig/got-read-gotconfig.c @@ -392,7 +392,7 @@ main(int argc, char *argv[]) got_privsep_send_error(&ibuf, err); } } - if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL) + if (close(GOT_IMSG_FD_CHILD) == -1 && err == NULL) err = got_error_from_errno("close"); return err ? 1 : 0; } blob - 5e190138a78d67199c00504c2c04e47659ff322c blob + 96f238defd60d0d973d36d4b4e6c4a60845cefa6 --- libexec/got-read-object/got-read-object.c +++ libexec/got-read-object/got-read-object.c @@ -111,7 +111,7 @@ main(int argc, char *argv[]) err = got_privsep_send_obj(&ibuf, obj); done: - if (close(imsg.fd) != 0 && err == NULL) + if (close(imsg.fd) == -1 && err == NULL) err = got_error_from_errno("close"); imsg_free(&imsg); if (obj) @@ -127,7 +127,7 @@ done: got_privsep_send_error(&ibuf, err); } } - if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL) + if (close(GOT_IMSG_FD_CHILD) == -1 && err == NULL) err = got_error_from_errno("close"); return err ? 1 : 0; } blob - f753b89137938f9238c2baf1620368646f2ff8c1 blob + dd8568736e94cba3323acae81feb8506fe869f9f --- libexec/got-read-pack/got-read-pack.c +++ libexec/got-read-pack/got-read-pack.c @@ -1009,7 +1009,7 @@ main(int argc, char *argv[]) break; } - if (imsg.fd != -1 && close(imsg.fd) != 0 && err == NULL) + if (imsg.fd != -1 && close(imsg.fd) == -1 && err == NULL) err = got_error_from_errno("close"); imsg_free(&imsg); if (err) @@ -1028,7 +1028,7 @@ main(int argc, char *argv[]) got_privsep_send_error(&ibuf, err); } } - if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL) + if (close(GOT_IMSG_FD_CHILD) == -1 && err == NULL) err = got_error_from_errno("close"); return err ? 1 : 0; } blob - 69d50c0fc848f0a018c842f5226edd670aa1f4c9 blob + 2ee8df0c70c373be7f85f0670e55b5684d877bc2 --- libexec/got-read-tag/got-read-tag.c +++ libexec/got-read-tag/got-read-tag.c @@ -143,7 +143,7 @@ done: if (fclose(f) == EOF && err == NULL) err = got_error_from_errno("fclose"); } else if (imsg.fd != -1) { - if (close(imsg.fd) != 0 && err == NULL) + if (close(imsg.fd) == -1 && err == NULL) err = got_error_from_errno("close"); } imsg_free(&imsg); @@ -158,7 +158,7 @@ done: got_privsep_send_error(&ibuf, err); } } - if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL) + if (close(GOT_IMSG_FD_CHILD) == -1 && err == NULL) err = got_error_from_errno("close"); return err ? 1 : 0; } blob - a2f17b2558df8d398aee3beceb01e40e84812c3f blob + 03b252f3eacb482e43069dd99ef3766fbc09fc74 --- libexec/got-read-tree/got-read-tree.c +++ libexec/got-read-tree/got-read-tree.c @@ -149,7 +149,7 @@ done: if (fclose(f) == EOF && err == NULL) err = got_error_from_errno("fclose"); } else if (imsg.fd != -1) { - if (close(imsg.fd) != 0 && err == NULL) + if (close(imsg.fd) == -1 && err == NULL) err = got_error_from_errno("close"); } imsg_free(&imsg); @@ -164,7 +164,7 @@ done: got_privsep_send_error(&ibuf, err); } } - if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL) + if (close(GOT_IMSG_FD_CHILD) == -1 && err == NULL) err = got_error_from_errno("close"); return err ? 1 : 0; }