Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: /
Date: Thu, 26 Nov 2015 10:39:36
Message-Id: 1448533401.9ff62a4efd3cc34e852c55b3c52441a2a481d7cf.vapier@gentoo
1 commit: 9ff62a4efd3cc34e852c55b3c52441a2a481d7cf
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Thu Nov 26 10:23:21 2015 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Thu Nov 26 10:23:21 2015 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=9ff62a4e
7
8 qglsa: rewrite main body to support overlays
9
10 Mostly mechanical changes to split the large body of code out of
11 main and into a standalone function. Don't spend time splitting
12 this up into smaller commits as qglsa has been disabled for quite
13 some time.
14
15 URL: https://bugs.gentoo.org/553260
16
17 qglsa.c | 115 +++++++++++++++++++++++++++++++++++++---------------------------
18 1 file changed, 66 insertions(+), 49 deletions(-)
19
20 diff --git a/qglsa.c b/qglsa.c
21 index 7fba5c7..7bc350f 100644
22 --- a/qglsa.c
23 +++ b/qglsa.c
24 @@ -29,6 +29,10 @@ static const char * const qglsa_opts_help[] = {
25 };
26 #define qglsa_usage(ret) usage(ret, QGLSA_FLAGS, qglsa_long_opts, qglsa_opts_help, lookup_applet_idx("qglsa"))
27
28 +typedef enum {
29 + GLSA_FUNKYTOWN, GLSA_LIST, GLSA_DUMP, GLSA_TEST, GLSA_FIX, GLSA_INJECT
30 +} qglsa_action;
31 +
32 static char *qglsa_load_list(void);
33 static char *qglsa_load_list(void)
34 {
35 @@ -146,69 +150,35 @@ static void qglsa_act_list(char *glsa)
36
37 }
38 */
39 -int qglsa_main(int argc, char **argv)
40 +
41 +static int
42 +qglsa_run_action(const char *overlay, qglsa_action action, const char *fixed_list,
43 + bool all_glsas, unsigned int ind, int argc, char **argv)
44 {
45 - enum { GLSA_FUNKYTOWN, GLSA_LIST, GLSA_DUMP, GLSA_TEST, GLSA_FIX, GLSA_INJECT };
46 int i;
47 DIR *dir;
48 struct dirent *dentry;
49 char *buf;
50 size_t buflen = 0;
51 - char *s, *p, *glsa_fixed_list;
52 - int action = GLSA_FUNKYTOWN;
53 - int all_glsas = 0;
54 + char *s, *p;
55 + int overlay_fd, glsa_fd;
56
57 - DBG("argc=%d argv[0]=%s argv[1]=%s",
58 - argc, argv[0], argc > 1 ? argv[1] : "NULL?");
59 -
60 - while ((i = GETOPT_LONG(QGLSA, qglsa, "")) != -1) {
61 -#define set_action(a) { if (action == 0) action = a; else err("cannot specify more than one action at a time"); }
62 - switch (i) {
63 - case 'l': set_action(GLSA_LIST); break;
64 - case 'd': set_action(GLSA_DUMP); break;
65 - case 't': set_action(GLSA_TEST); break;
66 - case 'p': pretend = 1; break;
67 - case 'f': set_action(GLSA_FIX); break;
68 - case 'i': set_action(GLSA_INJECT); break;
69 - COMMON_GETOPTS_CASES(qglsa)
70 - }
71 - }
72 - if (action == GLSA_FUNKYTOWN)
73 - qglsa_usage(EXIT_FAILURE);
74 - if (action != GLSA_LIST && optind == argc)
75 - err("specified action requires a list, either 'all', 'new', or GLSA numbers");
76 -
77 - glsa_fixed_list = NULL;
78 - for (i = optind; i < argc; ++i) {
79 - if (!strcmp(argv[i], "all")) {
80 - all_glsas = 1;
81 - if (optind+1 != argc)
82 - err("You may only use class names by themselves");
83 - } else if (!strcmp(argv[i], "new")) {
84 - all_glsas = 0;
85 - if (optind+1 != argc)
86 - err("You may only use class names by themselves");
87 - }
88 - }
89 - glsa_fixed_list = qglsa_load_list();
90 -
91 - int portdir_fd, glsa_fd;
92 - portdir_fd = open(portdir, O_RDONLY|O_CLOEXEC|O_PATH);
93 - glsa_fd = openat(portdir_fd, "metadata/glsa", O_RDONLY|O_CLOEXEC);
94 + overlay_fd = open(overlay, O_RDONLY|O_CLOEXEC|O_PATH);
95 + glsa_fd = openat(overlay_fd, "metadata/glsa", O_RDONLY|O_CLOEXEC);
96
97 switch (action) {
98 /*case GLSA_FIX:*/
99 case GLSA_INJECT:
100 buf = NULL;
101 - for (i = optind; i < argc; ++i) {
102 + for (i = ind; i < argc; ++i) {
103 free(buf);
104 xasprintf(&buf, "glsa-%s.xml", argv[i]);
105 if (faccessat(glsa_fd, buf, R_OK, 0)) {
106 warnp("Skipping invalid GLSA '%s'", argv[i]);
107 continue;
108 }
109 - if (glsa_fixed_list) {
110 - if (strstr(glsa_fixed_list, argv[i])) {
111 + if (fixed_list) {
112 + if (strstr(fixed_list, argv[i])) {
113 warn("Skipping already installed GLSA %s", argv[i]);
114 continue;
115 }
116 @@ -243,8 +213,8 @@ int qglsa_main(int argc, char **argv)
117 glsa_id[len - 5] = '\0';
118
119 /* see if we want to skip glsa's already fixed */
120 - if (!all_glsas && glsa_fixed_list) {
121 - if (strstr(glsa_fixed_list, glsa_id))
122 + if (!all_glsas && fixed_list) {
123 + if (strstr(fixed_list, glsa_id))
124 continue;
125 }
126
127 @@ -302,13 +272,60 @@ int qglsa_main(int argc, char **argv)
128 closedir(dir);
129 }
130
131 - free(glsa_fixed_list);
132 close(glsa_fd);
133 - close(portdir_fd);
134 + close(overlay_fd);
135
136 return EXIT_SUCCESS;
137 }
138
139 +int qglsa_main(int argc, char **argv)
140 +{
141 + int i;
142 + char *fixed_list;
143 + qglsa_action action = GLSA_FUNKYTOWN;
144 + bool all_glsas = false;
145 +
146 + DBG("argc=%d argv[0]=%s argv[1]=%s",
147 + argc, argv[0], argc > 1 ? argv[1] : "NULL?");
148 +
149 + while ((i = GETOPT_LONG(QGLSA, qglsa, "")) != -1) {
150 +#define set_action(a) { if (action == 0) action = a; else err("cannot specify more than one action at a time"); }
151 + switch (i) {
152 + case 'l': set_action(GLSA_LIST); break;
153 + case 'd': set_action(GLSA_DUMP); break;
154 + case 't': set_action(GLSA_TEST); break;
155 + case 'p': pretend = 1; break;
156 + case 'f': set_action(GLSA_FIX); break;
157 + case 'i': set_action(GLSA_INJECT); break;
158 + COMMON_GETOPTS_CASES(qglsa)
159 + }
160 + }
161 + if (action == GLSA_FUNKYTOWN)
162 + qglsa_usage(EXIT_FAILURE);
163 + if (action != GLSA_LIST && optind == argc)
164 + err("specified action requires a list, either 'all', 'new', or GLSA numbers");
165 +
166 + for (i = optind; i < argc; ++i) {
167 + if (!strcmp(argv[i], "all")) {
168 + all_glsas = true;
169 + if (optind+1 != argc)
170 + err("You may only use class names by themselves");
171 + } else if (!strcmp(argv[i], "new")) {
172 + all_glsas = false;
173 + if (optind+1 != argc)
174 + err("You may only use class names by themselves");
175 + }
176 + }
177 + fixed_list = qglsa_load_list();
178 +
179 + int ret = 0;
180 + size_t n;
181 + const char *overlay;
182 + array_for_each(overlays, n, overlay)
183 + ret |= qglsa_run_action(overlay, action, fixed_list, all_glsas, optind, argc, argv);
184 + return ret;
185 +}
186 +
187 #else
188 DEFINE_APPLET_STUB(qglsa)
189 #endif