pkg

Check-in [c6280bd2b6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:pkg check -d: Fix double locking errors Rather than lock/release in fix_deps, let the caller handle the upgrade on the lock it already holds. Rather than releasing the lock completely after each action just downgrade it to ADVISORY again so that the next action can upgrade it again. This is mostly noticeable when passing multiple patterns to pkg-check.
Timelines: family | ancestors | descendants | both | trunk | gsoc2013
Files: files | file ages | folders
SHA1: c6280bd2b6f7a87ab89c55e7fd4992b07f4aa623
User & Date: bryan@shatow.net 2014-06-11 18:26:01
Context
2014-06-11
22:54
Do not use '||' in WHERE clauses. check-in: 1339d6ff08 user: vsevolod@highsecure.ru tags: trunk, gsoc2013
18:26
pkg check -d: Fix double locking errors Rather than lock/release in fix_deps, let the caller handle the upgrade on the lock it already holds. Rather than releasing the lock completely after each action just downgrade it to ADVISORY again so that the next action can upgrade it again. This is mostly noticeable when passing multiple patterns to pkg-check. check-in: c6280bd2b6 user: bryan@shatow.net tags: trunk, gsoc2013
18:25
Ad a pkgdb_downgrade_lock() to go from EXCLUSIVE to ADVISORY check-in: 9c196b93c3 user: bryan@shatow.net tags: trunk, gsoc2013
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/check.c.

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
...
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
...
397
398
399
400
401
402
403

404

405
406
407
408
409
410
411
...
412
413
414
415
416
417
418

419

420
421
422
423
424
425
426
...
432
433
434
435
436
437
438
439

440
441
442
443
444
445
446
		pkgs[i++] = e->origin;

	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) {
		free(pkgs);
		return (EPKG_ENODB);
	}

	if (pkgdb_obtain_lock(db, PKGDB_LOCK_ADVISORY) != EPKG_OK) {
		pkgdb_close(db);
		free(pkgs);
		warnx("Cannot get an advisory lock on a database, it is locked by another process");
		return (EX_TEMPFAIL);
	}

	if (pkg_jobs_new(&jobs, PKG_JOBS_INSTALL, db) != EPKG_OK) {
		goto cleanup;
	}

	pkg_jobs_set_flags(jobs, f);

	if (pkg_jobs_add(jobs, MATCH_EXACT, pkgs, nbpkgs) == EPKG_FATAL) {
................................................................................
	}

cleanup:
	if (pkgs != NULL)
		free(pkgs);
	if (jobs != NULL)
		pkg_jobs_free(jobs);
	pkgdb_release_lock(db, PKGDB_LOCK_ADVISORY);

	return (EPKG_OK);
}

static void
check_summary(struct pkgdb *db, struct deps_head *dh)
{
................................................................................
				if (pkgdb_upgrade_lock(db, PKGDB_LOCK_ADVISORY,
						PKGDB_LOCK_EXCLUSIVE) == EPKG_OK) {
					if (verbose)
						pkg_printf("Recomputing size and checksums: %n\n", pkg);
					if (pkg_recompute(db, pkg) != EPKG_OK) {
						rc = EX_DATAERR;
					}

					pkgdb_release_lock(db, PKGDB_LOCK_EXCLUSIVE);

				}
				else {
					rc = EX_TEMPFAIL;
				}
			}
			if (reanalyse_shlibs) {
				if (pkgdb_upgrade_lock(db, PKGDB_LOCK_ADVISORY,
................................................................................
						PKGDB_LOCK_EXCLUSIVE) == EPKG_OK) {
					if (verbose)
						pkg_printf("Reanalyzing files for shlibs: %n\n", pkg);
					if (pkgdb_reanalyse_shlibs(db, pkg) != EPKG_OK) {
						pkg_printf("Failed to reanalyse for shlibs: %n\n", pkg);
						rc = EX_UNAVAILABLE;
					}

					pkgdb_release_lock(db, PKGDB_LOCK_EXCLUSIVE);

				}
				else {
					rc = EX_TEMPFAIL;
				}
			}
		}

................................................................................
				ret = fix_deps(db, &dh, nbpkgs, yes);
				if (ret == EPKG_OK)
					check_summary(db, &dh);
				else if (ret == EPKG_ENODB) {
					db = NULL;
					rc = EX_IOERR;
				}
				pkgdb_release_lock(db, PKGDB_LOCK_EXCLUSIVE);

				if (rc == EX_IOERR)
					goto cleanup;
			}
			else {
				rc = EX_TEMPFAIL;
				goto cleanup;
			}







<
<
<
<
<
<
<







 







<







 







>
|
>







 







>
|
>







 







|
>







147
148
149
150
151
152
153







154
155
156
157
158
159
160
...
188
189
190
191
192
193
194

195
196
197
198
199
200
201
...
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
...
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
...
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
		pkgs[i++] = e->origin;

	if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) {
		free(pkgs);
		return (EPKG_ENODB);
	}








	if (pkg_jobs_new(&jobs, PKG_JOBS_INSTALL, db) != EPKG_OK) {
		goto cleanup;
	}

	pkg_jobs_set_flags(jobs, f);

	if (pkg_jobs_add(jobs, MATCH_EXACT, pkgs, nbpkgs) == EPKG_FATAL) {
................................................................................
	}

cleanup:
	if (pkgs != NULL)
		free(pkgs);
	if (jobs != NULL)
		pkg_jobs_free(jobs);


	return (EPKG_OK);
}

static void
check_summary(struct pkgdb *db, struct deps_head *dh)
{
................................................................................
				if (pkgdb_upgrade_lock(db, PKGDB_LOCK_ADVISORY,
						PKGDB_LOCK_EXCLUSIVE) == EPKG_OK) {
					if (verbose)
						pkg_printf("Recomputing size and checksums: %n\n", pkg);
					if (pkg_recompute(db, pkg) != EPKG_OK) {
						rc = EX_DATAERR;
					}
					pkgdb_downgrade_lock(db,
					    PKGDB_LOCK_EXCLUSIVE,
					    PKGDB_LOCK_ADVISORY);
				}
				else {
					rc = EX_TEMPFAIL;
				}
			}
			if (reanalyse_shlibs) {
				if (pkgdb_upgrade_lock(db, PKGDB_LOCK_ADVISORY,
................................................................................
						PKGDB_LOCK_EXCLUSIVE) == EPKG_OK) {
					if (verbose)
						pkg_printf("Reanalyzing files for shlibs: %n\n", pkg);
					if (pkgdb_reanalyse_shlibs(db, pkg) != EPKG_OK) {
						pkg_printf("Failed to reanalyse for shlibs: %n\n", pkg);
						rc = EX_UNAVAILABLE;
					}
					pkgdb_downgrade_lock(db,
					    PKGDB_LOCK_EXCLUSIVE,
					    PKGDB_LOCK_ADVISORY);
				}
				else {
					rc = EX_TEMPFAIL;
				}
			}
		}

................................................................................
				ret = fix_deps(db, &dh, nbpkgs, yes);
				if (ret == EPKG_OK)
					check_summary(db, &dh);
				else if (ret == EPKG_ENODB) {
					db = NULL;
					rc = EX_IOERR;
				}
				pkgdb_downgrade_lock(db, PKGDB_LOCK_EXCLUSIVE,
				    PKGDB_LOCK_ADVISORY);
				if (rc == EX_IOERR)
					goto cleanup;
			}
			else {
				rc = EX_TEMPFAIL;
				goto cleanup;
			}