From owner-svn-soc-all@FreeBSD.ORG Tue Aug 6 10:51:09 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B76AEF3A for ; Tue, 6 Aug 2013 10:51:09 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9646326D1 for ; Tue, 6 Aug 2013 10:51:09 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r76Ap9FP096056 for ; Tue, 6 Aug 2013 10:51:09 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r76Ap9hL096050 for svn-soc-all@FreeBSD.org; Tue, 6 Aug 2013 10:51:09 GMT (envelope-from mattbw@FreeBSD.org) Date: Tue, 6 Aug 2013 10:51:09 GMT Message-Id: <201308061051.r76Ap9hL096050@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255563 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Aug 2013 10:51:09 -0000 Author: mattbw Date: Tue Aug 6 10:51:09 2013 New Revision: 255563 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255563 Log: Split up and clean up job functions. More tidying up work with no new functionality, but hopefully iteratively refactoring the jobs code might make it easier to find the issues that seem to be causing daemon crashes and, if not, at least the code is somewhat easier to read through. Modified: soc2013/mattbw/backend/jobs.c Modified: soc2013/mattbw/backend/jobs.c ============================================================================== --- soc2013/mattbw/backend/jobs.c Tue Aug 6 06:24:37 2013 (r255562) +++ soc2013/mattbw/backend/jobs.c Tue Aug 6 10:51:09 2013 (r255563) @@ -33,7 +33,10 @@ #include "jobs.h" /* jobs_... */ #include "pkgutils.h" /* pkgutils_... */ +static bool jobs_check_id_on_package(struct pkg *pkg, gchar **split_id, const char *name, const char *version); +static bool jobs_check_split_package_ids(struct pkg_jobs *jobs, gchar ***id_splits, guint count, bool reject_non_updates); static bool jobs_do_check(const struct jobs_spec *spec, struct pkg_jobs *jobs, gchar **package_ids, guint count); +static bool jobs_do_multiple_repos(struct pkgdb *db, const struct jobs_spec *spec, gchar **package_ids, guint count); static bool jobs_do_set_repo(const struct jobs_spec *spec, struct pkg_jobs *jobs, const char *reponame); static bool jobs_do_same_repo(struct pkgdb *db, const struct jobs_spec *spec, gchar **package_ids, guint count, const char *reponame); static char **jobs_do_populate(const struct jobs_spec *spec, struct pkg_jobs *jobs, gchar **package_ids, guint count); @@ -72,21 +75,16 @@ jobs_check_package_ids(struct pkg_jobs *jobs, gchar **package_ids, guint count, bool reject_non_updates) { - bool success; - guint i; - const char *name; - const char *version; - gchar *match_id; - struct pkg *pkg; - gchar ***id_splits; + bool success; + bool split_success; + unsigned int i; + gchar ***id_splits; assert(jobs != NULL); assert(package_ids != NULL); success = false; - pkg = NULL; id_splits = NULL; - match_id = NULL; count = g_strv_length(package_ids); if (count == 0) @@ -97,45 +95,21 @@ if (id_splits == NULL) goto cleanup; + split_success = true; for (i = 0; i < count; i++) { id_splits[i] = pk_package_id_split(package_ids[i]); - if (id_splits[i] == NULL) + if (id_splits[i] == NULL) { + split_success = false; break; + } } - - if (i < count) + if (!split_success) { goto cleanup; + } /* Now do the actual checking, per package. */ - success = true; - while (success && pkg_jobs(jobs, &pkg) == EPKG_OK) { - assert(pkg != NULL); - - name = version = NULL; - pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version); - - /* Does this package's name and version match a PackageID? */ - for (i = 0; i < count; i++) { - if ((strcmp(name, - id_splits[i][PK_PACKAGE_ID_NAME]) == 0) && - (strcmp(version, - id_splits[i][PK_PACKAGE_ID_VERSION]) == 0)) { - /* Does the rest of the PackageID match up? */ - match_id = pkgutils_pkg_match_id(pkg, - id_splits[i]); - - if (match_id == NULL) - success = false; - else - free(match_id); - } - - if (success && reject_non_updates && - pkgutils_pkg_install_state(pkg) != - PK_INFO_ENUM_UPDATING) - success = false; - } - } + success = jobs_check_split_package_ids(jobs, id_splits, count, + reject_non_updates); cleanup: if (id_splits != NULL) { @@ -155,12 +129,8 @@ { bool success; unsigned int count; - unsigned int i; - char *repo; struct pkgdb *db; gchar **package_ids; - gchar **splits; - assert(spec != NULL); assert(spec->backend != NULL); @@ -169,18 +139,122 @@ success = false; package_ids = NULL; - if (spec->use_package_ids) + if (spec->use_package_ids) { package_ids = pk_backend_get_strv(spec->backend, "package_ids"); + } count = 0; - if (package_ids != NULL) + if (package_ids != NULL) { count = g_strv_length(package_ids); + } db = db_open_remote(spec->backend); - if (db == NULL) - goto cleanup; + if (db != NULL) { + if (package_ids == NULL) { + success = jobs_do_same_repo(db, spec, NULL, 0, ""); + } else { + success = jobs_do_multiple_repos(db, spec, package_ids, + count); + } + + pkgdb_close(db); + } + + return success; +} + +static bool +jobs_check_id_on_package(struct pkg *pkg, gchar **split_id, + const char *name, const char *version) +{ + bool success; + gchar *match_id; + + assert(pkg != NULL); + assert(split_id != NULL); + assert(name != NULL); + assert(version != NULL); + + success = true; + + /* Does this package's name and version match a PackageID? */ + if ((strcmp(name, split_id[PK_PACKAGE_ID_NAME]) == 0) && + (strcmp(version, split_id[PK_PACKAGE_ID_VERSION]) == 0)) { + /* Does the rest of the PackageID match up? */ + match_id = pkgutils_pkg_match_id(pkg, split_id); + + if (match_id == NULL) { + success = false; + } else { + free(match_id); + } + } + + return success; +} + + +static bool +jobs_check_split_package_ids(struct pkg_jobs *jobs, gchar ***id_splits, + guint count, bool reject_non_updates) +{ + bool success; + guint i; + int err; + const char *name; + const char *version; + struct pkg *pkg; + + assert(jobs != NULL); + assert(id_splits != NULL); + assert(0 < count); + + success = true; + while (success) { + err = pkg_jobs(jobs, &pkg); + if (err != EPKG_OK) { + success = false; + break; + } + + assert(pkg != NULL); + + name = version = NULL; + pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version); + + for (i = 0; i < count; i++) { + if (!success) { + break; + } + + assert(success); + success = jobs_check_id_on_package(pkg, id_splits[i], + name, version); + + if (success && reject_non_updates && + pkgutils_pkg_install_state(pkg) != + PK_INFO_ENUM_UPDATING) { + success = false; + } + } + } + + return success; + } - /* +/* + * Performs a job on a batch of PackageIDs whose repos may be different. + */ +static bool +jobs_do_multiple_repos(struct pkgdb *db, const struct jobs_spec *spec, + gchar **package_ids, guint count) +{ + bool success; + unsigned int i; + char *repo; + gchar **splits; + + /* * HACK ALERT * * We'd ideally like to do one job for all PackageIDs but, because @@ -188,27 +262,23 @@ * its own repo), we need to do one job per PackageID. * TODO: consider bundling PackageIDs up into separate jobs per repo? */ - if (package_ids == NULL) - success = jobs_do_same_repo(db, spec, NULL, 0, ""); - else { - - for (i = 0, success = true; i < count && success; i++) { - /* Nastily inefficient */ - splits = pk_package_id_split(package_ids[i]); - if (splits == NULL) - repo = strdup(""); - else - repo = strdup(splits[PK_PACKAGE_ID_DATA]); - g_strfreev(splits); - - success = jobs_do_same_repo(db, spec, package_ids + i, - 1, repo); - free(repo); - } - } + success = true; + for (i = 0; i < count; i++) { + if (!success) + break; -cleanup: - pkgdb_close(db); + /* Nastily inefficient */ + splits = pk_package_id_split(package_ids[i]); + if (splits == NULL) + repo = strdup(""); + else + repo = strdup(splits[PK_PACKAGE_ID_DATA]); + g_strfreev(splits); + + success = jobs_do_same_repo(db, spec, package_ids + i, + 1, repo); + free(repo); + } return success; } @@ -308,7 +378,7 @@ jobs_emit_packages(struct pkg_jobs *jobs, PkBackend *backend, pkg_info_ptr info) { - struct pkg *pkg; + struct pkg *pkg; assert(jobs != NULL); assert(backend != NULL); @@ -358,6 +428,7 @@ assert(spec != NULL); assert(jobs != NULL); + /* reponame can be NULL */ success = true;