Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in portage-utils: main.c
Date: Wed, 02 Mar 2011 08:10:49
Message-Id: 20110302081039.A9C782004F@flycatcher.gentoo.org
1 vapier 11/03/02 08:10:39
2
3 Modified: main.c
4 Log:
5 restore & simplify the ROOT slash append check
6
7 Revision Changes Path
8 1.190 portage-utils/main.c
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.c?rev=1.190&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.c?rev=1.190&content-type=text/plain
12 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/main.c?r1=1.189&r2=1.190
13
14 Index: main.c
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-projects/portage-utils/main.c,v
17 retrieving revision 1.189
18 retrieving revision 1.190
19 diff -u -r1.189 -r1.190
20 --- main.c 2 Mar 2011 07:55:57 -0000 1.189
21 +++ main.c 2 Mar 2011 08:10:39 -0000 1.190
22 @@ -1,7 +1,7 @@
23 /*
24 * Copyright 2005-2008 Gentoo Foundation
25 * Distributed under the terms of the GNU General Public License v2
26 - * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.c,v 1.189 2011/03/02 07:55:57 vapier Exp $
27 + * $Header: /var/cvsroot/gentoo-projects/portage-utils/main.c,v 1.190 2011/03/02 08:10:39 vapier Exp $
28 *
29 * Copyright 2005-2008 Ned Ludd - <solar@g.o>
30 * Copyright 2005-2008 Mike Frysinger - <vapier@g.o>
31 @@ -542,7 +542,7 @@
32 break;
33 case _Q_STR:
34 free(*var->value.s);
35 - *var->value.s = xstrdup(value);
36 + *var->value.s = xstrdup_len(value, &var->value_len);
37 break;
38 case _Q_ISTR:
39 strincr_var(var->name, value, var->value.s, &var->value_len);
40 @@ -678,6 +678,7 @@
41 };
42 bool nocolor = 0;
43
44 + env_vars *var;
45 env_vars vars_to_read[] = {
46 #define _Q_EV(t, V, set, lset, d) \
47 { \
48 @@ -691,6 +692,7 @@
49 #define _Q_EVS(t, V, v, d) _Q_EV(t, V, .value.s = &v, .value_len = strlen(d), d)
50 #define _Q_EVB(t, V, v, d) _Q_EV(t, V, .value.b = &v, .value_len = 0, d)
51
52 + _Q_EVS(STR, ROOT, portroot, "/")
53 _Q_EVS(STR, ACCEPT_LICENSE, accept_license, "")
54 _Q_EVS(ISTR, INSTALL_MASK, install_mask, "")
55 _Q_EVS(STR, ARCH, portarch, "")
56 @@ -702,7 +704,6 @@
57 _Q_EVS(STR, PORTAGE_BINHOST, binhost, DEFAULT_PORTAGE_BINHOST)
58 _Q_EVS(STR, PORTAGE_TMPDIR, port_tmpdir, EPREFIX "/var/tmp/portage/")
59 _Q_EVS(STR, PKGDIR, pkgdir, EPREFIX "/usr/portage/packages/")
60 - _Q_EVS(STR, ROOT, portroot, "/")
61 /* XXX: This needs to not have a leading slash since some of the q
62 * utils use chdir(root) && chdir(portvdb). Once those are
63 * fixed, we can add a proper leading slash here. */
64 @@ -713,9 +714,11 @@
65 };
66
67 /* initialize all the strings with their default value */
68 - for (i = 0; vars_to_read[i].name; ++i)
69 - if (vars_to_read[i].type != _Q_BOOL)
70 - *vars_to_read[i].value.s = xstrdup(vars_to_read[i].default_value);
71 + for (i = 0; vars_to_read[i].name; ++i) {
72 + var = &vars_to_read[i];
73 + if (var->type != _Q_BOOL)
74 + *var->value.s = xstrdup(var->default_value);
75 + }
76
77 /* walk all the stacked profiles */
78 read_portage_profile(EPREFIX "/etc/make.profile", vars_to_read);
79 @@ -727,19 +730,28 @@
80
81 /* finally, check the env */
82 for (i = 0; vars_to_read[i].name; ++i) {
83 - s = getenv(vars_to_read[i].name);
84 + var = &vars_to_read[i];
85 + s = getenv(var->name);
86 if (s != NULL)
87 - set_portage_env_var(&vars_to_read[i], s);
88 + set_portage_env_var(var, s);
89 if (getenv("DEBUG") IF_DEBUG(|| 1)) {
90 - fprintf(stderr, "%s = ", vars_to_read[i].name);
91 + fprintf(stderr, "%s = ", var->name);
92 switch (vars_to_read[i].type) {
93 - case _Q_BOOL: fprintf(stderr, "%i\n", *vars_to_read[i].value.b); break;
94 + case _Q_BOOL: fprintf(stderr, "%i\n", *var->value.b); break;
95 case _Q_STR:
96 - case _Q_ISTR: fprintf(stderr, "%s\n", *vars_to_read[i].value.s); break;
97 + case _Q_ISTR: fprintf(stderr, "%s\n", *var->value.s); break;
98 }
99 }
100 }
101
102 + /* Make sure ROOT always ends in a slash */
103 + var = &vars_to_read[0];
104 + if ((*var->value.s)[var->value_len - 1] != '/') {
105 + portroot = xrealloc(portroot, var->value_len + 2);
106 + portroot[var->value_len] = '/';
107 + portroot[var->value_len + 1] = '\0';
108 + }
109 +
110 if (getenv("PORTAGE_QUIET") != NULL)
111 quiet = 1;