From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 017761384B4 for ; Thu, 26 Nov 2015 10:39:36 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7B57F21C109; Thu, 26 Nov 2015 10:39:31 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 5A25B21C107 for ; Thu, 26 Nov 2015 10:39:30 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 2F17F340688 for ; Thu, 26 Nov 2015 10:39:29 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id D6427F50 for ; Thu, 26 Nov 2015 10:39:24 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1448533401.9ff62a4efd3cc34e852c55b3c52441a2a481d7cf.vapier@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: qglsa.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 9ff62a4efd3cc34e852c55b3c52441a2a481d7cf X-VCS-Branch: master Date: Thu, 26 Nov 2015 10:39:24 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: ed1d28cf-1b59-442f-82a1-7b96e2d1ae83 X-Archives-Hash: 320b5e0f4af4f08df41d61e2a02002fd commit: 9ff62a4efd3cc34e852c55b3c52441a2a481d7cf Author: Mike Frysinger gentoo org> AuthorDate: Thu Nov 26 10:23:21 2015 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Thu Nov 26 10:23:21 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=9ff62a4e qglsa: rewrite main body to support overlays Mostly mechanical changes to split the large body of code out of main and into a standalone function. Don't spend time splitting this up into smaller commits as qglsa has been disabled for quite some time. URL: https://bugs.gentoo.org/553260 qglsa.c | 115 +++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 66 insertions(+), 49 deletions(-) diff --git a/qglsa.c b/qglsa.c index 7fba5c7..7bc350f 100644 --- a/qglsa.c +++ b/qglsa.c @@ -29,6 +29,10 @@ static const char * const qglsa_opts_help[] = { }; #define qglsa_usage(ret) usage(ret, QGLSA_FLAGS, qglsa_long_opts, qglsa_opts_help, lookup_applet_idx("qglsa")) +typedef enum { + GLSA_FUNKYTOWN, GLSA_LIST, GLSA_DUMP, GLSA_TEST, GLSA_FIX, GLSA_INJECT +} qglsa_action; + static char *qglsa_load_list(void); static char *qglsa_load_list(void) { @@ -146,69 +150,35 @@ static void qglsa_act_list(char *glsa) } */ -int qglsa_main(int argc, char **argv) + +static int +qglsa_run_action(const char *overlay, qglsa_action action, const char *fixed_list, + bool all_glsas, unsigned int ind, int argc, char **argv) { - enum { GLSA_FUNKYTOWN, GLSA_LIST, GLSA_DUMP, GLSA_TEST, GLSA_FIX, GLSA_INJECT }; int i; DIR *dir; struct dirent *dentry; char *buf; size_t buflen = 0; - char *s, *p, *glsa_fixed_list; - int action = GLSA_FUNKYTOWN; - int all_glsas = 0; + char *s, *p; + int overlay_fd, glsa_fd; - DBG("argc=%d argv[0]=%s argv[1]=%s", - argc, argv[0], argc > 1 ? argv[1] : "NULL?"); - - while ((i = GETOPT_LONG(QGLSA, qglsa, "")) != -1) { -#define set_action(a) { if (action == 0) action = a; else err("cannot specify more than one action at a time"); } - switch (i) { - case 'l': set_action(GLSA_LIST); break; - case 'd': set_action(GLSA_DUMP); break; - case 't': set_action(GLSA_TEST); break; - case 'p': pretend = 1; break; - case 'f': set_action(GLSA_FIX); break; - case 'i': set_action(GLSA_INJECT); break; - COMMON_GETOPTS_CASES(qglsa) - } - } - if (action == GLSA_FUNKYTOWN) - qglsa_usage(EXIT_FAILURE); - if (action != GLSA_LIST && optind == argc) - err("specified action requires a list, either 'all', 'new', or GLSA numbers"); - - glsa_fixed_list = NULL; - for (i = optind; i < argc; ++i) { - if (!strcmp(argv[i], "all")) { - all_glsas = 1; - if (optind+1 != argc) - err("You may only use class names by themselves"); - } else if (!strcmp(argv[i], "new")) { - all_glsas = 0; - if (optind+1 != argc) - err("You may only use class names by themselves"); - } - } - glsa_fixed_list = qglsa_load_list(); - - int portdir_fd, glsa_fd; - portdir_fd = open(portdir, O_RDONLY|O_CLOEXEC|O_PATH); - glsa_fd = openat(portdir_fd, "metadata/glsa", O_RDONLY|O_CLOEXEC); + overlay_fd = open(overlay, O_RDONLY|O_CLOEXEC|O_PATH); + glsa_fd = openat(overlay_fd, "metadata/glsa", O_RDONLY|O_CLOEXEC); switch (action) { /*case GLSA_FIX:*/ case GLSA_INJECT: buf = NULL; - for (i = optind; i < argc; ++i) { + for (i = ind; i < argc; ++i) { free(buf); xasprintf(&buf, "glsa-%s.xml", argv[i]); if (faccessat(glsa_fd, buf, R_OK, 0)) { warnp("Skipping invalid GLSA '%s'", argv[i]); continue; } - if (glsa_fixed_list) { - if (strstr(glsa_fixed_list, argv[i])) { + if (fixed_list) { + if (strstr(fixed_list, argv[i])) { warn("Skipping already installed GLSA %s", argv[i]); continue; } @@ -243,8 +213,8 @@ int qglsa_main(int argc, char **argv) glsa_id[len - 5] = '\0'; /* see if we want to skip glsa's already fixed */ - if (!all_glsas && glsa_fixed_list) { - if (strstr(glsa_fixed_list, glsa_id)) + if (!all_glsas && fixed_list) { + if (strstr(fixed_list, glsa_id)) continue; } @@ -302,13 +272,60 @@ int qglsa_main(int argc, char **argv) closedir(dir); } - free(glsa_fixed_list); close(glsa_fd); - close(portdir_fd); + close(overlay_fd); return EXIT_SUCCESS; } +int qglsa_main(int argc, char **argv) +{ + int i; + char *fixed_list; + qglsa_action action = GLSA_FUNKYTOWN; + bool all_glsas = false; + + DBG("argc=%d argv[0]=%s argv[1]=%s", + argc, argv[0], argc > 1 ? argv[1] : "NULL?"); + + while ((i = GETOPT_LONG(QGLSA, qglsa, "")) != -1) { +#define set_action(a) { if (action == 0) action = a; else err("cannot specify more than one action at a time"); } + switch (i) { + case 'l': set_action(GLSA_LIST); break; + case 'd': set_action(GLSA_DUMP); break; + case 't': set_action(GLSA_TEST); break; + case 'p': pretend = 1; break; + case 'f': set_action(GLSA_FIX); break; + case 'i': set_action(GLSA_INJECT); break; + COMMON_GETOPTS_CASES(qglsa) + } + } + if (action == GLSA_FUNKYTOWN) + qglsa_usage(EXIT_FAILURE); + if (action != GLSA_LIST && optind == argc) + err("specified action requires a list, either 'all', 'new', or GLSA numbers"); + + for (i = optind; i < argc; ++i) { + if (!strcmp(argv[i], "all")) { + all_glsas = true; + if (optind+1 != argc) + err("You may only use class names by themselves"); + } else if (!strcmp(argv[i], "new")) { + all_glsas = false; + if (optind+1 != argc) + err("You may only use class names by themselves"); + } + } + fixed_list = qglsa_load_list(); + + int ret = 0; + size_t n; + const char *overlay; + array_for_each(overlays, n, overlay) + ret |= qglsa_run_action(overlay, action, fixed_list, all_glsas, optind, argc, argv); + return ret; +} + #else DEFINE_APPLET_STUB(qglsa) #endif