summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2019-04-15 11:32:50 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2019-05-07 12:55:38 +0200
commit0de84364e374591b71826e56302e5228bc0d2dab (patch)
treedc3ae051d9fdd11896c6829b985f086dfd77de3c /apt-pkg/contrib
parentab67c39b9cdd28d11dd43fe48bd1fdeab60d4c2f (diff)
Prevent shutdown while running dpkg
As long as we are running dpkg, keep an inhibitor that blocks us from shutting down. LP: #1820886 (cherry picked from commit 96aef11a5cf400377a52f7e93e70944b17e249d1) (cherry picked from commit 8ea79afcadead5a5b7d94bf8623cb833859f6d80) (cherry picked from commit c5b8a857f2535fe284426cefda2fbd1bbb3d5808) Also fixup prepare-release for CI to handle [linux-any] build-dep, and do the whole autoconf / makefile stuff.
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/fileutl.cc48
-rw-r--r--apt-pkg/contrib/fileutl.h2
2 files changed, 50 insertions, 0 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