summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/contrib/fileutl.cc48
-rw-r--r--apt-pkg/contrib/fileutl.h2
-rw-r--r--apt-pkg/deb/dpkgpm.cc16
-rw-r--r--apt-pkg/makefile5
4 files changed, 70 insertions, 1 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 5d283bdf5..f2642e5dc 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -67,6 +67,9 @@
#ifdef HAVE_LZ4
#include <lz4frame.h>
#endif
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-bus.h>
+#endif
#include <endian.h>
#include <stdint.h>
@@ -3029,3 +3032,48 @@ bool DropPrivileges() /*{{{*/
return true;
}
/*}}}*/
+int Inhibit(const char *what, const char *who, const char *why, const char *mode) /*{{{*/
+{
+#ifdef HAVE_SYSTEMD
+ sd_bus_error error = SD_BUS_ERROR_NULL;
+ sd_bus_message *m = NULL;
+ sd_bus *bus = NULL;
+ int fd;
+ int r;
+
+ r = sd_bus_open_system(&bus);
+ if (r < 0)
+ goto out;
+
+ r = sd_bus_call_method(bus,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ "Inhibit",
+ &error,
+ &m,
+ "ssss",
+ what,
+ who,
+ why,
+ mode);
+ if (r < 0)
+ goto out;
+
+ r = sd_bus_message_read(m, "h", &fd);
+ if (r < 0)
+ goto out;
+
+ // We received a file descriptor, return it - systemd will close the read fd
+ // on free, so let's duplicate it here.
+ r = dup(fd);
+out:
+ sd_bus_error_free(&error);
+ sd_bus_message_unref(m);
+ sd_bus_unref(bus);
+ return r;
+#else
+ return -ENOTSUP;
+#endif
+}
+ /*}}}*/
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index 7ee302d7b..32e5612bf 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -253,4 +253,6 @@ bool Popen(const char* Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode,
bool Popen(const char* Args[], FileFd &Fd, pid_t &Child, FileFd::OpenMode Mode);
+APT_HIDDEN int Inhibit(const char *what, const char *who, const char *why, const char *mode);
+
#endif
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index 7a3d1d1f4..05bee9286 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -1232,6 +1232,22 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress)
return (I.Pkg->Flags & pkgCache::Flag::Essential) != 0;
};
+ struct Inhibitor
+ {
+ int Fd = -1;
+ Inhibitor()
+ {
+ if (_config->FindB("DPkg::Inhibit-Shutdown", true))
+ Fd = Inhibit("shutdown", "APT", "APT is installing or removing packages", "block");
+ }
+ ~Inhibitor()
+ {
+ if (Fd > 0)
+ close(Fd);
+ }
+ } inhibitor;
+
+
pkgPackageManager::SigINTStop = false;
d->progress = progress;
diff --git a/apt-pkg/makefile b/apt-pkg/makefile
index 789d3f2fd..b66e9b272 100644
--- a/apt-pkg/makefile
+++ b/apt-pkg/makefile
@@ -12,7 +12,7 @@ include ../buildlib/defaults.mak
# The library name and version (indirectly used from init.h)
include ../buildlib/libversion.mak
-CPPFLAGS+=-DAPT_PKG_EXPOSE_STRING_VIEW
+CPPFLAGS+=-DAPT_PKG_EXPOSE_STRING_VIEW $(SYSTEMD_CFLAGS)
LIBRARY=apt-pkg
MAJOR=$(LIBAPTPKG_MAJOR)
MINOR=$(LIBAPTPKG_RELEASE)
@@ -29,6 +29,9 @@ endif
ifeq ($(HAVE_LZ4),yes)
SLIBS+= -llz4
endif
+ifeq ($(HAVE_SYSTEMD),yes)
+SLIBS+= $(SYSTEMD_LIBS)
+endif
APT_DOMAIN:=libapt-pkg$(LIBAPTPKG_MAJOR)
SOURCE = $(sort $(wildcard *.cc */*.cc))