diff options
author | Mike Frysinger <vapier@gentoo.org> | 2014-02-16 21:14:24 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2014-02-16 21:14:24 +0000 |
commit | 8a2857f3ced8f191b56a3e690cacf03a3a745d67 (patch) | |
tree | 7d068af7d631e9073893504d0c19a5bb65bf7558 | |
parent | qcache/qcheck: use O_CLOEXEC in more places (diff) | |
download | portage-utils-8a2857f3ced8f191b56a3e690cacf03a3a745d67.tar.gz portage-utils-8a2857f3ced8f191b56a3e690cacf03a3a745d67.tar.bz2 portage-utils-8a2857f3ced8f191b56a3e690cacf03a3a745d67.zip |
start using O_PATH
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | libq/profile.c | 2 | ||||
-rw-r--r-- | libq/scandirat.c | 3 | ||||
-rw-r--r-- | libq/vdb.c | 12 | ||||
-rw-r--r-- | libq/xmkdir.c | 1 | ||||
-rw-r--r-- | porting.h | 5 | ||||
-rw-r--r-- | qmerge.c | 13 | ||||
-rw-r--r-- | qtbz2.c | 6 | ||||
-rw-r--r-- | qxpak.c | 6 |
9 files changed, 30 insertions, 21 deletions
@@ -11,8 +11,6 @@ - speed up queue structure ... append walks the whole list -- use O_PATH with fd's that are only used to open other files - - qmerge - dep resolver needs spanktastic love. - needs safe deleting (merge in place rather than unmerge;merge) @@ -35,6 +33,7 @@ foo-(1234)_alpha(56789) - these limits should not be an issue for all practical purposes - need to handle USE deps like: cat/pkg-123[foo(+)] + - show support slots like: qmerge -U automake:1.12 - qcache: - need to convert it to new metadata/md5 style diff --git a/libq/profile.c b/libq/profile.c index 707695dc..75f3cb03 100644 --- a/libq/profile.c +++ b/libq/profile.c @@ -10,7 +10,7 @@ q_profile_walk_at(int dir_fd, const char *dir, const char *file, char *buf; /* Pop open this profile dir */ - subdir_fd = openat(dir_fd, dir, O_RDONLY|O_CLOEXEC); + subdir_fd = openat(dir_fd, dir, O_RDONLY|O_CLOEXEC|O_PATH); if (subdir_fd < 0) return data; diff --git a/libq/scandirat.c b/libq/scandirat.c index 76a5d4a2..0a848283 100644 --- a/libq/scandirat.c +++ b/libq/scandirat.c @@ -1,7 +1,7 @@ /* * Copyright 2005-2011 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/scandirat.c,v 1.7 2013/11/17 10:26:53 grobian Exp $ + * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/scandirat.c,v 1.8 2014/02/16 21:14:24 vapier Exp $ * * Copyright 2005-2010 Ned Ludd - <solar@gentoo.org> * Copyright 2005-2011 Mike Frysinger - <vapier@gentoo.org> @@ -29,6 +29,7 @@ static int scandirat(int dir_fd, const char *dir, struct dirent ***dirlist, DIR *dirp; struct dirent *de, **ret; + /* Cannot use O_PATH as we want to use fdopendir() */ fd = openat(dir_fd, dir, O_RDONLY|O_CLOEXEC); if (fd == -1) return -1; @@ -1,7 +1,7 @@ /* * Copyright 2005-2011 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/vdb.c,v 1.5 2012/10/28 06:27:59 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/vdb.c,v 1.6 2014/02/16 21:14:24 vapier Exp $ * * Copyright 2005-2010 Ned Ludd - <solar@gentoo.org> * Copyright 2005-2011 Mike Frysinger - <vapier@gentoo.org> @@ -24,7 +24,7 @@ _q_static q_vdb_ctx *q_vdb_open(/*const char *sroot, const char *svdb*/void) if (!sroot) sroot = portroot; - ctx->portroot_fd = open(sroot, O_RDONLY|O_CLOEXEC); + ctx->portroot_fd = open(sroot, O_RDONLY|O_CLOEXEC|O_PATH); if (ctx->portroot_fd == -1) { warnp("could not open root: %s", sroot); goto f_error; @@ -36,6 +36,7 @@ _q_static q_vdb_ctx *q_vdb_open(/*const char *sroot, const char *svdb*/void) svdb++; if (*svdb == '\0') svdb = "."; + /* Cannot use O_PATH as we want to use fdopendir() */ ctx->vdb_fd = openat(ctx->portroot_fd, svdb, O_RDONLY|O_CLOEXEC); if (ctx->vdb_fd == -1) { warnp("could not open vdb: %s (in root %s)", svdb, sroot); @@ -114,6 +115,7 @@ _q_static q_vdb_cat_ctx *q_vdb_open_cat(q_vdb_ctx *ctx, const char *name) int fd; DIR *dir; + /* Cannot use O_PATH as we want to use fdopendir() */ fd = openat(ctx->vdb_fd, name, O_RDONLY|O_CLOEXEC); if (fd == -1) return NULL; @@ -194,9 +196,10 @@ _q_static q_vdb_pkg_ctx *q_vdb_open_pkg(q_vdb_cat_ctx *cat_ctx, const char *name q_vdb_pkg_ctx *pkg_ctx; int fd; - fd = openat(cat_ctx->fd, name, O_RDONLY|O_CLOEXEC); +// fd = openat(cat_ctx->fd, name, O_RDONLY|O_CLOEXEC|O_PATH); if (fd == -1) return NULL; + fd = -1; pkg_ctx = xmalloc(sizeof(*pkg_ctx)); pkg_ctx->name = name; @@ -251,7 +254,8 @@ _q_static FILE *q_vdb_pkg_fopenat(q_vdb_pkg_ctx *pkg_ctx, const char *file, _q_static void q_vdb_close_pkg(q_vdb_pkg_ctx *pkg_ctx) { - close(pkg_ctx->fd); + if (pkg_ctx->fd != -1) + close(pkg_ctx->fd); free(pkg_ctx); } diff --git a/libq/xmkdir.c b/libq/xmkdir.c index eb0123ad..600e6d08 100644 --- a/libq/xmkdir.c +++ b/libq/xmkdir.c @@ -43,6 +43,7 @@ _q_static int rm_rf_at(int dfd, const char *path) DIR *dir; struct dirent *de; + /* Cannot use O_PATH as we want to use fdopendir() */ subdfd = openat(dfd, path, O_RDONLY|O_CLOEXEC|O_NOFOLLOW); if (subdfd < 0) return -1; @@ -1,7 +1,7 @@ /* * Copyright 2005-2013 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/portage-utils/porting.h,v 1.1 2013/09/29 22:42:36 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/portage-utils/porting.h,v 1.2 2014/02/16 21:14:24 vapier Exp $ * * Copyright 2005-2008 Ned Ludd - <solar@gentoo.org> * Copyright 2005-2013 Mike Frysinger - <vapier@gentoo.org> @@ -66,6 +66,9 @@ #ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif +#ifndef O_PATH +#define O_PATH 0 +#endif #ifndef CONFIG_EPREFIX #define CONFIG_EPREFIX "/" @@ -1,7 +1,7 @@ /* * Copyright 2005-2010 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/portage-utils/qmerge.c,v 1.131 2014/01/07 19:17:25 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/portage-utils/qmerge.c,v 1.132 2014/02/16 21:14:24 vapier Exp $ * * Copyright 2005-2010 Ned Ludd - <solar@gentoo.org> * Copyright 2005-2010 Mike Frysinger - <vapier@gentoo.org> @@ -65,7 +65,7 @@ static const char * const qmerge_opts_help[] = { COMMON_OPTS_HELP }; -static const char qmerge_rcsid[] = "$Id: qmerge.c,v 1.131 2014/01/07 19:17:25 vapier Exp $"; +static const char qmerge_rcsid[] = "$Id: qmerge.c,v 1.132 2014/02/16 21:14:24 vapier Exp $"; #define qmerge_usage(ret) usage(ret, QMERGE_FLAGS, qmerge_long_opts, qmerge_opts_help, lookup_applet_idx("qmerge")) char search_pkgs = 0; @@ -237,7 +237,7 @@ _q_static char *best_version(const char *catname, const char *pkgname) /* Make sure these dirs exist before we try walking them */ switch (vdb_check) { case 1: { - int fd = open(portroot, O_RDONLY|O_CLOEXEC); + int fd = open(portroot, O_RDONLY|O_CLOEXEC|O_PATH); if (fd >= 0) { /* skip leading slash */ vdb_check = faccessat(fd, portvdb + 1, X_OK, 0); @@ -483,10 +483,11 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst, ret = -1; /* Get handles to these subdirs */ + /* Cannot use O_PATH as we want to use fdopendir() */ subfd_src = openat(fd_src, src, O_RDONLY|O_CLOEXEC); if (subfd_src < 0) return ret; - subfd_dst = openat(fd_dst, dst, O_RDONLY|O_CLOEXEC); + subfd_dst = openat(fd_dst, dst, O_RDONLY|O_CLOEXEC|O_PATH); if (subfd_dst < 0) { close(subfd_src); return ret; @@ -1038,7 +1039,7 @@ pkg_unmerge(const char *cat, const char *pkgname, queue *keep) return 0; /* Get a handle to the root to play with */ - portroot_fd = open(portroot, O_RDONLY | O_CLOEXEC); + portroot_fd = open(portroot, O_RDONLY|O_CLOEXEC|O_PATH); if (portroot_fd == -1) { warnp("unable to read %s", portroot); goto done; @@ -1048,7 +1049,7 @@ pkg_unmerge(const char *cat, const char *pkgname, queue *keep) /* Note: This vdb_path must be absolute since we use it in pkg_run_func() */ xasprintf(&vdb_path, "%s%s/%s/%s/", portroot, portvdb, cat, pkgname); xasprintf(&T, "%stemp", vdb_path); - vdb_fd = openat(portroot_fd, vdb_path, O_RDONLY | O_CLOEXEC); + vdb_fd = openat(portroot_fd, vdb_path, O_RDONLY|O_CLOEXEC|O_PATH); if (vdb_fd == -1) { warnp("unable to read %s", vdb_path); goto done; @@ -1,7 +1,7 @@ /* * Copyright 2005-2010 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/portage-utils/qtbz2.c,v 1.21 2012/11/17 18:44:58 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/portage-utils/qtbz2.c,v 1.22 2014/02/16 21:14:24 vapier Exp $ * * Copyright 2005-2010 Ned Ludd - <solar@gentoo.org> * Copyright 2005-2010 Mike Frysinger - <vapier@gentoo.org> @@ -46,7 +46,7 @@ static const char * const qtbz2_opts_help[] = { "Write files to stdout", COMMON_OPTS_HELP }; -static const char qtbz2_rcsid[] = "$Id: qtbz2.c,v 1.21 2012/11/17 18:44:58 vapier Exp $"; +static const char qtbz2_rcsid[] = "$Id: qtbz2.c,v 1.22 2014/02/16 21:14:24 vapier Exp $"; #define qtbz2_usage(ret) usage(ret, QTBZ2_FLAGS, qtbz2_long_opts, qtbz2_opts_help, lookup_applet_idx("qtbz2")) static char tbz2_stdout = 0; @@ -263,7 +263,7 @@ int qtbz2_main(int argc, char **argv) case 'd': if (dir_fd != AT_FDCWD) err("Only use -d once"); - dir_fd = open(optarg, O_RDONLY|O_CLOEXEC); + dir_fd = open(optarg, O_RDONLY|O_CLOEXEC|O_PATH); break; } } @@ -1,7 +1,7 @@ /* * Copyright 2005-2010 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/portage-utils/qxpak.c,v 1.26 2013/04/21 04:28:10 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/portage-utils/qxpak.c,v 1.27 2014/02/16 21:14:24 vapier Exp $ * * Copyright 2005-2010 Ned Ludd - <solar@gentoo.org> * Copyright 2005-2010 Mike Frysinger - <vapier@gentoo.org> @@ -46,7 +46,7 @@ static const char * const qxpak_opts_help[] = { "Write files to stdout", COMMON_OPTS_HELP }; -static const char qxpak_rcsid[] = "$Id: qxpak.c,v 1.26 2013/04/21 04:28:10 vapier Exp $"; +static const char qxpak_rcsid[] = "$Id: qxpak.c,v 1.27 2014/02/16 21:14:24 vapier Exp $"; #define qxpak_usage(ret) usage(ret, QXPAK_FLAGS, qxpak_long_opts, qxpak_opts_help, lookup_applet_idx("qxpak")) typedef struct { @@ -397,7 +397,7 @@ int qxpak_main(int argc, char **argv) case 'd': if (dir_fd != AT_FDCWD) err("Only use -d once"); - dir_fd = open(optarg, O_RDONLY|O_CLOEXEC); + dir_fd = open(optarg, O_RDONLY|O_CLOEXEC|O_PATH); break; } } |