|
|
@@ -67,6 +67,7 @@ static void
|
|
|
file_unlock_cleanup(int argc, void **argv)
|
|
|
{
|
|
|
int lockfd = *(int*)argv[0];
|
|
|
+ const char *lock_desc = argv[1];
|
|
|
struct flock fl;
|
|
|
|
|
|
assert(lockfd >= 0);
|
|
|
@@ -74,7 +75,7 @@ file_unlock_cleanup(int argc, void **argv)
|
|
|
file_lock_setup(&fl, F_UNLCK);
|
|
|
|
|
|
if (fcntl(lockfd, F_SETLK, &fl) == -1)
|
|
|
- ohshite(_("unable to unlock dpkg status database"));
|
|
|
+ ohshite(_("unable to unlock %s"), lock_desc);
|
|
|
}
|
|
|
|
|
|
void
|
|
|
@@ -108,21 +109,28 @@ file_is_locked(int lockfd, const char *filename)
|
|
|
/* lockfd must be allocated statically as its addresses is passed to
|
|
|
* a cleanup handler. */
|
|
|
void
|
|
|
-file_lock(int *lockfd, const char *filename,
|
|
|
- const char *emsg, const char *emsg_eagain)
|
|
|
+file_lock(int *lockfd, enum file_lock_flags flags, const char *filename,
|
|
|
+ const char *desc)
|
|
|
{
|
|
|
struct flock fl;
|
|
|
+ int lock_cmd;
|
|
|
|
|
|
setcloexec(*lockfd, filename);
|
|
|
|
|
|
file_lock_setup(&fl, F_WRLCK);
|
|
|
|
|
|
- if (fcntl(*lockfd, emsg_eagain ? F_SETLK : F_SETLKW, &fl) == -1) {
|
|
|
- if (emsg_eagain && (errno == EACCES || errno == EAGAIN))
|
|
|
- ohshit(emsg_eagain);
|
|
|
- ohshite(emsg);
|
|
|
+ if (flags == FILE_LOCK_WAIT)
|
|
|
+ lock_cmd = F_SETLKW;
|
|
|
+ else
|
|
|
+ lock_cmd = F_SETLK;
|
|
|
+
|
|
|
+ if (fcntl(*lockfd, lock_cmd, &fl) == -1) {
|
|
|
+ if (errno == EACCES || errno == EAGAIN)
|
|
|
+ ohshit(_("%s is locked by another process"), desc);
|
|
|
+ else
|
|
|
+ ohshite(_("unable to lock %s"), desc);
|
|
|
}
|
|
|
|
|
|
- push_cleanup(file_unlock_cleanup, ~0, NULL, 0, 1, lockfd);
|
|
|
+ push_cleanup(file_unlock_cleanup, ~0, NULL, 0, 2, lockfd, desc);
|
|
|
}
|
|
|
|