[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Can't externally acquire lock on /var/lib/apt/lists/lock



Hi Francesco,

Francesco Pretto wrote:

> --------------------------------------
> #!/bin/bash
> set -e
> (
>     flock --exclusive --nonblock 200
>     # do something inside /var/lib/apt/lists
>     sleep 50 # Taking some time to test if the lock works
> ) 200>/var/lib/apt/lists/lock
> --------------------------------------
> 
> It doesn't work in the sense that trying to launch apt-get update
> during the sleep time will simply works, like no lock was set. What am
> I doing wrong?

The problem is that apt use fcntl(2) locks, not flock(2) locks.

| $ apt-get source apt
| $ cd apt-*
| $ grep -R "Could not open lock file" . --include='*.cc' -C15 -h
[...]
|    int FD = open(File.c_str(),O_RDWR | O_CREAT | O_NOFOLLOW,0640);
[...]
|    SetCloseExec(FD,true);
|       
|    // Aquire a write lock
|    struct flock fl;
|    fl.l_type = F_WRLCK;
|    fl.l_whence = SEEK_SET;
|    fl.l_start = 0;
|    fl.l_len = 0;
|    if (fcntl(FD,F_SETLK,&fl) == -1)
|    {
| $

I do not know how to use fcntl locks from a shell script.  I would
suggest trying a scripting language like Perl or Python instead.

As for your general question about offline update using APT, I
don’t know if there’s something appropriate available already.  I
would recommend looking at reprepro, apt-offline, and
http://batmat.net/apt-offline/ and asking in the deity mailing list
(to reach APT developers) or debian-user (to reach fellow users).

Hope that helps,
Jonathan


Reply to: