Commit bb995b19 authored by Julian Andres Klode's avatar Julian Andres Klode

Introduce frontend locking

parent b783bd08
......@@ -11,7 +11,7 @@ Build-Depends: apt (>= 1.0.9.4),
debhelper (>= 9),
dh-python,
fakeroot,
libapt-pkg-dev (>= 1.4~beta3),
libapt-pkg-dev (>= 1.7~alpha2ubuntu1~),
python-all-dev (>= 2.7),
python-all-dbg,
python3-all-dev (>= 3.3),
......
......@@ -2524,6 +2524,35 @@ following three functions:
Unlock the global pkgsystem. This reverts the effect of
:func:`pkgsystem_lock`.
Since version 1.7, APT switches to the frontend locking approach where
dpkg has two lock files, :file:`lock-frontend` and :file:`lock`, the
latter being called the inner lock in apt.
When running dpkg, the inner lock must be released before calling dpkg
and reacquired afterwards. When not using APT functions to run dpkg,
the variable `DPKG_FRONTEND_LOCKED` must be set to tell dpkg to not
acquire the :file:`lock-frontend` lock.
These functions usually do not need to be used by external code.
.. function:: pkgsystem_unlock_inner()
Release the :file:`lock` lock file to allow dpkg to be run.
.. versionadded:: 1.7
.. function:: pkgsystem_lock_inner()
Release the :file:`lock` lock file after a dpkg run.
.. versionadded:: 1.7
.. function:: pkgsystem_is_locked()
Returns true if the global lock is hold. Can be used to check whether
:meth:`pkgsystem_unlock_inner` needs to be called.
.. versionadded:: 1.7
Other classes
--------------
......
......@@ -28,6 +28,10 @@ Added
* A new method :meth:`apt.cache.Cache.fix_broken` has been added.
* New methods for frontend locking have been added:
:meth:`apt_pkg.pkgsystem_lock_inner`,
:meth:`apt_pkg.pkgsystem_unlock_inner`,
:meth:`apt_pkg.pkgsystem_is_locked` (starting in alpha 3).
Deprecated
----------
......
......@@ -545,8 +545,8 @@ static PyObject *GetLock(PyObject *Self,PyObject *Args)
static char *doc_PkgSystemLock =
"pkgsystem_lock() -> bool\n\n"
"Acquire the global lock for the package system by using /var/lib/dpkg/lock\n"
"to do the locking. From Python 2.6 on, the apt_pkg.SystemLock context\n"
"Acquire the global lock for the package system by using /var/lib/dpkg/lock-frontend\n"
"and /var/lib/dpkg/lock to do the locking. From Python 2.6 on, the apt_pkg.SystemLock context\n"
"manager is available and should be used instead.";
static PyObject *PkgSystemLock(PyObject *Self,PyObject *Args)
{
......@@ -569,6 +569,57 @@ static PyObject *PkgSystemUnLock(PyObject *Self,PyObject *Args)
bool res = _system->UnLock();
Py_INCREF(Py_None);
return HandleErrors(PyBool_FromLong(res));
}
static char *doc_PkgSystemLockInner =
"pkgsystem_lock_inner() -> bool\n\n"
"Reacquire the dpkg 'lock' lock file. Must be called only after\n"
":meth:`pkgsystem_unlock_inner` and only around invocations of dpkg.\n"
"\n"
".. versionadded:: 1.7";
static PyObject *PkgSystemLockInner(PyObject *Self,PyObject *Args)
{
if (PyArg_ParseTuple(Args,"") == 0)
return 0;
bool res = _system->LockInner();
Py_INCREF(Py_None);
return HandleErrors(PyBool_FromLong(res));
}
static char *doc_PkgSystemUnLockInner =
"pkgsystem_unlock_inner() -> bool\n\n"
"Release the dpkg lock file 'lock'. To be called before manually\n"
"invoking dpkg.\n"
"\n"
".. versionadded:: 1.7";
static PyObject *PkgSystemUnLockInner(PyObject *Self,PyObject *Args)
{
if (PyArg_ParseTuple(Args,"") == 0)
return 0;
bool res = _system->UnLockInner();
Py_INCREF(Py_None);
return HandleErrors(PyBool_FromLong(res));
}
static char *doc_PkgSystemIsLocked =
"pkgsystem_is_locked() -> bool\n\n"
"Check if the system is locked. Can be used to check whether the inner\n"
"lock needs to be released or not in generic code.\n"
"\n"
".. versionadded:: 1.7";
static PyObject *PkgSystemIsLocked(PyObject *Self,PyObject *Args)
{
if (PyArg_ParseTuple(Args,"") == 0)
return 0;
bool res = _system->IsLocked();
Py_INCREF(Py_None);
return HandleErrors(PyBool_FromLong(res));
}
......@@ -601,6 +652,9 @@ static PyMethodDef methods[] =
{"get_lock",GetLock,METH_VARARGS,doc_GetLock},
{"pkgsystem_lock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock},
{"pkgsystem_unlock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock},
{"pkgsystem_lock_inner",PkgSystemLockInner,METH_VARARGS,doc_PkgSystemLockInner},
{"pkgsystem_unlock_inner",PkgSystemUnLockInner,METH_VARARGS,doc_PkgSystemUnLockInner},
{"pkgsystem_is_locked",PkgSystemIsLocked,METH_VARARGS,doc_PkgSystemIsLocked},
// Command line
{"read_config_file",LoadConfig,METH_VARARGS,doc_LoadConfig},
......
......@@ -155,6 +155,10 @@ def pkgsystem_unlock() -> None: ...
def read_config_file(configuration: Configuration, path: str) -> None: ...
def read_config_dir(configuration: Configuration, path: str) -> None: ...
def pkgsystem_lock_inner() -> None: ...
def pkgsystem_unlock_inner() -> None: ...
def pkgsystem_is_locked() -> bool: ...
SELSTATE_HOLD: int
class Acquire:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment