aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Groffen <grobian@gentoo.org>2024-07-03 21:40:24 +0200
committerFabian Groffen <grobian@gentoo.org>2024-07-03 21:40:24 +0200
commit2b1acbd8bf41f4ad327202a975270a7f435ed241 (patch)
treedf4509ea527f8babcd9d6e22d73f53977073a4dc
parentlibq/Makefile: fix out-of-srcdir build (diff)
downloadportage-utils-2b1acbd8bf41f4ad327202a975270a7f435ed241.tar.gz
portage-utils-2b1acbd8bf41f4ad327202a975270a7f435ed241.tar.bz2
portage-utils-2b1acbd8bf41f4ad327202a975270a7f435ed241.zip
main: handle --root and -q early during startup
Need to handle --root before we read profiles, -q to silence warnings from that profile reading. Signed-off-by: Fabian Groffen <grobian@gentoo.org>
-rw-r--r--applets.h7
-rw-r--r--main.c71
-rw-r--r--tests/qdepends/list08.good2
3 files changed, 51 insertions, 29 deletions
diff --git a/applets.h b/applets.h
index 8e78f21c..f650bc04 100644
--- a/applets.h
+++ b/applets.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2005-2021 Gentoo Foundation
+ * Copyright 2005-2024 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
*
* Copyright 2005-2010 Ned Ludd - <solar@gentoo.org>
@@ -144,9 +144,9 @@ static const struct applet_t {
"Print version and exit", \
NULL
#define COMMON_GETOPTS_CASES(applet) \
- case 0x1: portroot = optarg; break; \
+ case 0x1: /* already handled early in main */ break; \
case 'v': ++verbose; break; \
- case 'q': setup_quiet(); break; \
+ case 'q': /* already handled early in main */ break; \
case 'V': version_barf(); break; \
case 'h': applet ## _usage(EXIT_SUCCESS); break; \
case 'C': if (!nocolor) { \
@@ -184,7 +184,6 @@ extern char *main_overlay;
extern int twidth;
extern bool nocolor;
-void setup_quiet(void);
void version_barf(void);
void usage(int status, const char *flags, struct option const opts[],
const char * const help[], const char *desc, int blabber);
diff --git a/main.c b/main.c
index 5d7c97d2..9ea76663 100644
--- a/main.c
+++ b/main.c
@@ -72,7 +72,7 @@ init_coredumps(void)
}
#endif
-void
+static void
setup_quiet(void)
{
/* "e" for FD_CLOEXEC */
@@ -979,18 +979,6 @@ initialize_portage_env(void)
const char *configroot = getenv("PORTAGE_CONFIGROOT");
char *primary_overlay = NULL;
- /* initialize all the properties with their default value */
- for (i = 0; vars_to_read[i].name; ++i) {
- var = &vars_to_read[i];
- switch (var->type) {
- case _Q_BOOL: *var->value.b = var->default_value; break;
- case _Q_STR:
- case _Q_ISTR: *var->value.s = xstrdup(var->default_value); break;
- case _Q_ISET: *var->value.t = (set *)var->default_value; break;
- }
- var->src = xstrdup(STR_DEFAULT);
- }
-
package_masks = create_set();
/* figure out where to find our config files */
@@ -1240,9 +1228,19 @@ int main(int argc, char **argv)
IF_DEBUG(init_coredumps());
argv0 = argv[0];
- /* note: setting nocolor here is pointless, since
- * initialize_portage_env is going to re-init nocolor, so make
- * sure we modify the default instead. */
+ /* initialise all the properties with their default value */
+ for (i = 0; vars_to_read[i].name; ++i) {
+ env_vars *var = &vars_to_read[i];
+ switch (var->type) {
+ case _Q_BOOL: *var->value.b = var->default_value; break;
+ case _Q_STR:
+ case _Q_ISTR: *var->value.s = xstrdup(var->default_value); break;
+ case _Q_ISET: *var->value.t = (set *)var->default_value; break;
+ }
+ var->src = xstrdup(STR_DEFAULT);
+ }
+
+ /* disable colours when not writing to a terminal */
twidth = 0;
nocolor = 0;
if (fstat(fileno(stdout), &st) != -1) {
@@ -1258,21 +1256,47 @@ int main(int argc, char **argv)
} else {
nocolor = 1;
}
- vars_to_read[7].default_value = (char *)nocolor; /* NOCOLOR */
+ if (nocolor == 1)
+ set_portage_env_var(&vars_to_read[7], "true", "terminal"); /* NOCOLOR */
/* We can use getopt here, but only in POSIX mode (which stops at
* the first non-option argument) because otherwise argv is
* modified, this basically sulks, because ideally we parse and
* handle the common options here. Because we are parsing profiles
- * and stuff at this point we need -q for bug #735134, so do lame
- * matching for that */
+ * and stuff at this point we need -q for bug #735134, and --root so
+ * do lame matching for that */
for (i = 1; i < argc; i++) {
- if (argv[i] != NULL && argv[i][0] == '-' &&
- (argv[i][1] == 'q' || strcmp(&argv[i][1], "-quiet") == 0))
- {
- setup_quiet();
+ if (argv[i] != NULL && argv[i][0] == '-') {
+ if (argv[i][1] == '-') {
+ if (strcmp(&argv[i][2], "quiet") == 0) {
+ setup_quiet();
+ } else if (strcmp(&argv[i][2], "root") == 0 &&
+ argv[i + 1] != NULL)
+ {
+ char realroot[_Q_PATH_MAX];
+ char *root;
+ if (realpath(argv[i + 1], realroot) != NULL)
+ root = realroot;
+ else
+ root = argv[i + 1];
+ set_portage_env_var(&vars_to_read[0], root,
+ "command line"); /* ROOT */
+ }
+ } else {
+ char *p;
+
+ /* must handle combinations of options like -Rq :( */
+ for (p = &argv[i][1]; *p != '\0'; p++) {
+ switch (*p) {
+ case 'q':
+ setup_quiet();
+ break;
+ }
+ }
+ }
}
}
+
/* same for env-based fallback */
if (getenv("PORTAGE_QUIET") != NULL)
setup_quiet();
@@ -1283,6 +1307,5 @@ int main(int argc, char **argv)
initialize_portage_env();
optind = 0;
- quiet = 0;
return q_main(argc, argv);
}
diff --git a/tests/qdepends/list08.good b/tests/qdepends/list08.good
index 9aaf42d4..a68a5a69 100644
--- a/tests/qdepends/list08.good
+++ b/tests/qdepends/list08.good
@@ -1 +1 @@
-x11-apps/xdm-1.1.11-r3: !<sys-apps/systemd-187 >=media-fonts/font-util-1.2.0 >=sys-devel/autoconf-2.68 >=sys-devel/automake-1.12:1.12 >=sys-devel/automake-1.13:1.13 >=sys-devel/libtool-2.2.6a >=x11-apps/xinit-1.0.2-r3 >=x11-misc/util-macros-1.17 sys-devel/libtool sys-devel/m4 virtual/pkgconfig x11-apps/sessreg x11-apps/xconsole x11-apps/xrdb x11-libs/libX11 x11-libs/libXaw x11-libs/libXdmcp x11-libs/libXinerama x11-libs/libXmu x11-libs/libXt x11-proto/xineramaproto x11-proto/xproto
+x11-apps/xdm: !<sys-apps/systemd-187 >=media-fonts/font-util-1.2.0 >=sys-devel/autoconf-2.68 >=sys-devel/automake-1.12:1.12 >=sys-devel/automake-1.13:1.13 >=sys-devel/libtool-2.2.6a >=x11-apps/xinit-1.0.2-r3 >=x11-misc/util-macros-1.17 sys-devel/libtool sys-devel/m4 virtual/pkgconfig x11-apps/sessreg x11-apps/xconsole x11-apps/xrdb x11-libs/libX11 x11-libs/libXaw x11-libs/libXdmcp x11-libs/libXinerama x11-libs/libXmu x11-libs/libXt x11-proto/xineramaproto x11-proto/xproto