Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=frugalware-current.git;a=commitdiff;h=94d52712abd5eee2624fcb9c2b596192021eb387

commit 94d52712abd5eee2624fcb9c2b596192021eb387
Author: crazy <[email protected]>
Date:   Mon Jan 23 02:38:10 2017 +0100

systemd-231-11-x86_64
* backport compile fix for gperf 3.1.x, see :
https://github.com/systemd/systemd/issues/5039
* change default of mounting /proc to use 'hidepid=2' , in short this option 
will just show
* own running PIDs in `ps` or `top` , etc. Folks have a line in fstab for that 
won't see any
* difference , new installs will have it by default..
* next step restrict 'dmesg' for normal users too

diff --git a/source/base/systemd/FrugalBuild b/source/base/systemd/FrugalBuild
index cdc50a1..7e01e0d 100644
--- a/source/base/systemd/FrugalBuild
+++ b/source/base/systemd/FrugalBuild
@@ -9,10 +9,10 @@ USE_SYSV_COMPAT=${USE_SYSV_COMPAT:-"y"}

pkgname=systemd
pkgver=231
-pkgrel=10
+pkgrel=11
pkgdesc="A System and Service Manager"
url="http://www.freedesktop.org/wiki/Software/systemd";
-depends=('kmod>=23-2' 'cryptsetup-luks>=1.7.2-4')
+depends=('kmod>=23-2' 'cryptsetup-luks>=1.7.2-4' 'lz4')
makedepends=('docbook-xsl' 'docbook-xml' 'intltool>=0.51.0-2' \
'gperf>=3.0.4-4' 'gnu-efi>=3.0.4-3' 'lxml>=3.5.0' 
'gobject-introspection>=1.46.0-2')
rodepends=('dbus>=1.10.10-3' "libsystemd=$pkgver" 'scriptlet-core')
@@ -36,8 +36,11 @@ source+=(
adjust-systemd-user-pam-config-file.patch \
usb-load-ehci-first.conf \
frugalware_sysusers.patch \
-        frugalware_tty.patch )
+        frugalware_tty.patch \
+       c9f7b4d356a453a01aa77a6bb74ca7ef49732c08.diff \
+       mount-proc-with-hidepid2-by-default.patch)

+## NOTE do _not_ remove mount-proc-with-hidepid2-by-default.patch , rediff 
when needed..
sha1sums=('47768103290d2023c3452bc36bc77f7b1fd798ea' \
'a2f1c341894c4841a64a56138362817ae2c57905' \
'2aa6ed34d80abee40b179e93c5eccba623fbdc7c' \
@@ -54,7 +57,9 @@ sha1sums=('47768103290d2023c3452bc36bc77f7b1fd798ea' \
'067d45c3e64f3d1dc66f707f702212e95f4162b2' \
'ecb14db2a916c96781ee2fcb8d0cd44dbe978dd7' \
'5a955e19d11b1248e4da14fddd08a7b3a0e64ca9' \
-          'b10c82b83d2f4085304605c7fb8b09d03d3998b3')
+          'b10c82b83d2f4085304605c7fb8b09d03d3998b3' \
+          '14ca4ae728757fb7ffaef35420e938fdcd252899' \
+          '72eb2e17ba562286943ee9a381fb748cdab3d148')

rodepends=('hwdata' 'systemd-sysvinit')

@@ -172,7 +177,7 @@ build()
Fcross32_delete_empty

## kill everything but udev + libs
-       Fmv usr/i686-frugalware-linux/lib/systemd/libsystemd-shared-231.so 
usr/lib32/ ## not sure something need this by now
+       Fmv usr/i686-frugalware-linux/lib/systemd/libsystemd-shared-$pkgver.so 
usr/lib32/ ## not sure something need this by now
Frm usr/i686-frugalware-linux/lib/systemd
Frm usr/i686-frugalware-linux/bin/{systemd-*,kernel-install,*ctl}
Frm usr/lib
@@ -191,6 +196,7 @@ build()

Fcd
Fsed '$(datadir)/pkgconfig' '$(libdir)/pkgconfig' Makefile.{am,in}
+       Fsed "liblz4 >= 125" "liblz4 >= 1.7" configure.ac
Fexec ./autogen.sh || Fdie
Fbuild $_Fconfopts

diff --git a/source/base/systemd/c9f7b4d356a453a01aa77a6bb74ca7ef49732c08.diff 
b/source/base/systemd/c9f7b4d356a453a01aa77a6bb74ca7ef49732c08.diff
new file mode 100644
index 0000000..641e503
--- /dev/null
+++ b/source/base/systemd/c9f7b4d356a453a01aa77a6bb74ca7ef49732c08.diff
@@ -0,0 +1,267 @@
+diff --git a/configure.ac b/configure.ac
+index 11bd46c..d58fff5 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -255,6 +255,28 @@ AC_CHECK_SIZEOF(rlim_t,,[
+        #include <sys/resource.h>
+ ])
+
++GPERF_TEST="$(echo foo,bar | ${GPERF} -L ANSI-C)"
++
++AC_COMPILE_IFELSE(
++        [AC_LANG_PROGRAM([
++                #include <string.h>
++                const char * in_word_set(const char *, size_t);
++                $GPERF_TEST]
++        )],
++        [GPERF_LEN_TYPE=size_t],
++        [AC_COMPILE_IFELSE(
++                [AC_LANG_PROGRAM([
++                        #include <string.h>
++                        const char * in_word_set(const char *, unsigned);
++                        $GPERF_TEST]
++                )],
++                [GPERF_LEN_TYPE=unsigned],
++                [AC_MSG_ERROR([** unable to determine gperf len type])]
++        )]
++)
++
++AC_DEFINE_UNQUOTED([GPERF_LEN_TYPE], [$GPERF_LEN_TYPE], [gperf len type])
++
+ # 
------------------------------------------------------------------------------
+ # we use python to build the man page index
+ have_python=no
+diff --git a/src/basic/af-list.c b/src/basic/af-list.c
+index 3fac9c5..4b291d1 100644
+--- a/src/basic/af-list.c
++++ b/src/basic/af-list.c
+@@ -23,7 +23,7 @@
+ #include "af-list.h"
+ #include "macro.h"
+
+-static const struct af_name* lookup_af(register const char *str, register 
unsigned int len);
++static const struct af_name* lookup_af(register const char *str, register 
GPERF_LEN_TYPE len);
+
+ #include "af-from-name.h"
+ #include "af-to-name.h"
+diff --git a/src/basic/arphrd-list.c b/src/basic/arphrd-list.c
+index 6792d1e..2d598dc 100644
+--- a/src/basic/arphrd-list.c
++++ b/src/basic/arphrd-list.c
+@@ -23,7 +23,7 @@
+ #include "arphrd-list.h"
+ #include "macro.h"
+
+-static const struct arphrd_name* lookup_arphrd(register const char *str, 
register unsigned int len);
++static const struct arphrd_name* lookup_arphrd(register const char *str, 
register GPERF_LEN_TYPE len);
+
+ #include "arphrd-from-name.h"
+ #include "arphrd-to-name.h"
+diff --git a/src/basic/cap-list.c b/src/basic/cap-list.c
+index 3e773a0..d68cc78 100644
+--- a/src/basic/cap-list.c
++++ b/src/basic/cap-list.c
+@@ -26,7 +26,7 @@
+ #include "parse-util.h"
+ #include "util.h"
+
+-static const struct capability_name* lookup_capability(register const char 
*str, register unsigned int len);
++static const struct capability_name* lookup_capability(register const char 
*str, register GPERF_LEN_TYPE len);
+
+ #include "cap-from-name.h"
+ #include "cap-to-name.h"
+diff --git a/src/basic/errno-list.c b/src/basic/errno-list.c
+index 31b66ba..c6a01ee 100644
+--- a/src/basic/errno-list.c
++++ b/src/basic/errno-list.c
+@@ -23,7 +23,7 @@
+ #include "macro.h"
+
+ static const struct errno_name* lookup_errno(register const char *str,
+-                                             register unsigned int len);
++                                             register GPERF_LEN_TYPE len);
+
+ #include "errno-from-name.h"
+ #include "errno-to-name.h"
+diff --git a/src/core/load-fragment.h b/src/core/load-fragment.h
+index bbac2d8..fc27a07 100644
+--- a/src/core/load-fragment.h
++++ b/src/core/load-fragment.h
+@@ -120,7 +120,7 @@ int config_parse_restrict_namespaces(const char *unit, 
const char *filename, uns
+ int config_parse_bind_paths(const char *unit, const char *filename, unsigned 
line, const char *section, unsigned section_line, const char *lvalue, int 
ltype, const char *rvalue, void *data, void *userdata);
+
+ /* gperf prototypes */
+-const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, 
unsigned length);
++const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, 
GPERF_LEN_TYPE length);
+ extern const char load_fragment_gperf_nulstr[];
+
+ typedef enum Disabled {
+diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h
+index 99d9149..d1520c4 100644
+--- a/src/journal/journald-server.h
++++ b/src/journal/journald-server.h
+@@ -179,7 +179,7 @@ void server_dispatch_message(Server *s, struct iovec 
*iovec, unsigned n, unsigne
+ void server_driver_message(Server *s, sd_id128_t message_id, const char 
*format, ...) _printf_(3,0) _sentinel_;
+
+ /* gperf lookup function */
+-const struct ConfigPerfItem* journald_gperf_lookup(const char *key, unsigned 
length);
++const struct ConfigPerfItem* journald_gperf_lookup(const char *key, 
GPERF_LEN_TYPE length);
+
+ int config_parse_storage(const char *unit, const char *filename, unsigned 
line, const char *section, unsigned section_line, const char *lvalue, int 
ltype, const char *rvalue, void *data, void *userdata);
+
+diff --git a/src/login/logind.h b/src/login/logind.h
+index 086fa1e..7556ee2 100644
+--- a/src/login/logind.h
++++ b/src/login/logind.h
+@@ -182,7 +182,7 @@ int manager_unit_is_active(Manager *manager, const char 
*unit);
+ int manager_job_is_active(Manager *manager, const char *path);
+
+ /* gperf lookup function */
+-const struct ConfigPerfItem* logind_gperf_lookup(const char *key, unsigned 
length);
++const struct ConfigPerfItem* logind_gperf_lookup(const char *key, 
GPERF_LEN_TYPE length);
+
+ int manager_set_lid_switch_ignore(Manager *m, usec_t until);
+
+diff --git a/src/network/networkd-netdev.h b/src/network/networkd-netdev.h
+index 70ff947..37c7431 100644
+--- a/src/network/networkd-netdev.h
++++ b/src/network/networkd-netdev.h
+@@ -175,7 +175,7 @@ NetDevKind netdev_kind_from_string(const char *d) _pure_;
+ int config_parse_netdev_kind(const char *unit, const char *filename, unsigned 
line, const char *section, unsigned section_line, const char *lvalue, int 
ltype, const char *rvalue, void *data, void *userdata);
+
+ /* gperf */
+-const struct ConfigPerfItem* network_netdev_gperf_lookup(const char *key, 
unsigned length);
++const struct ConfigPerfItem* network_netdev_gperf_lookup(const char *key, 
GPERF_LEN_TYPE length);
+
+ /* Macros which append INTERFACE= to the message */
+
+diff --git a/src/network/networkd-conf.h b/src/network/networkd-conf.h
+index 9381962..1136975 100644
+--- a/src/network/networkd-conf.h
++++ b/src/network/networkd-conf.h
+@@ -23,7 +23,7 @@ typedef struct Manager Manager;
+
+ int manager_parse_config_file(Manager *m);
+
+-const struct ConfigPerfItem* networkd_gperf_lookup(const char *key, unsigned 
length);
++const struct ConfigPerfItem* networkd_gperf_lookup(const char *key, 
GPERF_LEN_TYPE length);
+
+ int config_parse_duid_type(
+                 const char *unit,
+diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h
+index 4cf784f..b7da9d2 100644
+--- a/src/network/networkd-network.h
++++ b/src/network/networkd-network.h
+@@ -244,7 +244,7 @@ int config_parse_ntp(const char *unit, const char 
*filename, unsigned line, cons
+ /* Legacy IPv4LL support */
+ int config_parse_ipv4ll(const char *unit, const char *filename, unsigned 
line, const char *section, unsigned section_line, const char *lvalue, int 
ltype, const char *rvalue, void *data, void *userdata);
+
+-const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, 
unsigned length);
++const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, 
GPERF_LEN_TYPE length);
+
+ extern const sd_bus_vtable network_vtable[];
+
+diff --git a/src/nspawn/nspawn-settings.h b/src/nspawn/nspawn-settings.h
+index 4bd0c64..e9ea087 100644
+--- a/src/nspawn/nspawn-settings.h
++++ b/src/nspawn/nspawn-settings.h
+@@ -103,7 +103,7 @@ bool settings_private_network(Settings *s);
+
+ DEFINE_TRIVIAL_CLEANUP_FUNC(Settings*, settings_free);
+
+-const struct ConfigPerfItem* nspawn_gperf_lookup(const char *key, unsigned 
length);
++const struct ConfigPerfItem* nspawn_gperf_lookup(const char *key, 
GPERF_LEN_TYPE length);
+
+ int config_parse_capability(const char *unit, const char *filename, unsigned 
line, const char *section, unsigned section_line, const char *lvalue, int 
ltype, const char *rvalue, void *data, void *userdata);
+ int config_parse_id128(const char *unit, const char *filename, unsigned line, 
const char *section, unsigned section_line, const char *lvalue, int ltype, 
const char *rvalue, void *data, void *userdata);
+diff --git a/src/resolve/dns-type.c b/src/resolve/dns-type.c
+index aaf5ed6..d89ae28 100644
+--- a/src/resolve/dns-type.c
++++ b/src/resolve/dns-type.c
+@@ -29,7 +29,7 @@ typedef const struct {
+ } dns_type;
+
+ static const struct dns_type_name *
+-lookup_dns_type (register const char *str, register unsigned int len);
++lookup_dns_type (register const char *str, register GPERF_LEN_TYPE len);
+
+ #include "dns_type-from-name.h"
+ #include "dns_type-to-name.h"
+diff --git a/src/resolve/resolved-conf.h b/src/resolve/resolved-conf.h
+index fc425a3..8184d6c 100644
+--- a/src/resolve/resolved-conf.h
++++ b/src/resolve/resolved-conf.h
+@@ -41,7 +41,7 @@ int manager_parse_search_domains_and_warn(Manager *m, const 
char *string);
+ int manager_add_dns_server_by_string(Manager *m, DnsServerType type, const 
char *word);
+ int manager_parse_dns_server_string_and_warn(Manager *m, DnsServerType type, 
const char *string);
+
+-const struct ConfigPerfItem* resolved_gperf_lookup(const char *key, unsigned 
length);
++const struct ConfigPerfItem* resolved_gperf_lookup(const char *key, 
GPERF_LEN_TYPE length);
+
+ int config_parse_dns_servers(const char *unit, const char *filename, unsigned 
line, const char *section, unsigned section_line, const char *lvalue, int 
ltype, const char *rvalue, void *data, void *userdata);
+ int config_parse_search_domains(const char *unit, const char *filename, 
unsigned line, const char *section, unsigned section_line, const char *lvalue, 
int ltype, const char *rvalue, void *data, void *userdata);
+diff --git a/src/test/test-af-list.c b/src/test/test-af-list.c
+index aeaa092..e247913 100644
+--- a/src/test/test-af-list.c
++++ b/src/test/test-af-list.c
+@@ -24,7 +24,7 @@
+ #include "string-util.h"
+ #include "util.h"
+
+-static const struct af_name* lookup_af(register const char *str, register 
unsigned int len);
++static const struct af_name* lookup_af(register const char *str, register 
GPERF_LEN_TYPE len);
+
+ #include "af-from-name.h"
+ #include "af-list.h"
+diff --git a/src/test/test-arphrd-list.c b/src/test/test-arphrd-list.c
+index f3989ad..8f4f342 100644
+--- a/src/test/test-arphrd-list.c
++++ b/src/test/test-arphrd-list.c
+@@ -24,7 +24,7 @@
+ #include "string-util.h"
+ #include "util.h"
+
+-static const struct arphrd_name* lookup_arphrd(register const char *str, 
register unsigned int len);
++static const struct arphrd_name* lookup_arphrd(register const char *str, 
register GPERF_LEN_TYPE len);
+
+ #include "arphrd-from-name.h"
+ #include "arphrd-list.h"
+diff --git a/src/timesync/timesyncd-conf.h b/src/timesync/timesyncd-conf.h
+index cba0724..0280697 100644
+--- a/src/timesync/timesyncd-conf.h
++++ b/src/timesync/timesyncd-conf.h
+@@ -22,7 +22,7 @@
+ #include "conf-parser.h"
+ #include "timesyncd-manager.h"
+
+-const struct ConfigPerfItem* timesyncd_gperf_lookup(const char *key, unsigned 
length);
++const struct ConfigPerfItem* timesyncd_gperf_lookup(const char *key, 
GPERF_LEN_TYPE length);
+
+ int manager_parse_server_string(Manager *m, ServerType type, const char 
*string);
+
+diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h
+index a99060d..5a25cec 100644
+--- a/src/udev/net/link-config.h
++++ b/src/udev/net/link-config.h
+@@ -94,7 +94,7 @@ const char *mac_policy_to_string(MACPolicy p) _const_;
+ MACPolicy mac_policy_from_string(const char *p) _pure_;
+
+ /* gperf lookup function */
+-const struct ConfigPerfItem* link_config_gperf_lookup(const char *key, 
unsigned length);
++const struct ConfigPerfItem* link_config_gperf_lookup(const char *key, 
GPERF_LEN_TYPE length);
+
+ int config_parse_mac_policy(const char *unit, const char *filename, unsigned 
line, const char *section, unsigned section_line, const char *lvalue, int 
ltype, const char *rvalue, void *data, void *userdata);
+ int config_parse_name_policy(const char *unit, const char *filename, unsigned 
line, const char *section, unsigned section_line, const char *lvalue, int 
ltype, const char *rvalue, void *data, void *userdata);
+diff --git a/src/udev/udev-builtin-keyboard.c 
b/src/udev/udev-builtin-keyboard.c
+index aa10bea..0902411 100644
+--- a/src/udev/udev-builtin-keyboard.c
++++ b/src/udev/udev-builtin-keyboard.c
+@@ -29,7 +29,7 @@
+ #include "string-util.h"
+ #include "udev.h"
+
+-static const struct key *keyboard_lookup_key(const char *str, unsigned len);
++static const struct key *keyboard_lookup_key(const char *str, GPERF_LEN_TYPE 
len);
+ #include "keyboard-keys-from-name.h"
+
+ static int install_force_release(struct udev_device *dev, const unsigned 
*release, unsigned release_count) {
diff --git a/source/base/systemd/mount-proc-with-hidepid2-by-default.patch 
b/source/base/systemd/mount-proc-with-hidepid2-by-default.patch
new file mode 100644
index 0000000..fc33cfd
--- /dev/null
+++ b/source/base/systemd/mount-proc-with-hidepid2-by-default.patch
@@ -0,0 +1,12 @@
+diff -Naur systemd-231/src/core/mount-setup.c 
systemd-231-p/src/core/mount-setup.c
+--- systemd-231/src/core/mount-setup.c 2016-07-25 21:49:47.000000000 +0200
++++ systemd-231-p/src/core/mount-setup.c       2017-01-22 23:47:14.970418407 
+0100
+@@ -73,7 +73,7 @@
+ static const MountPoint mount_table[] = {
+         { "sysfs",       "/sys",                      "sysfs",      NULL,     
                 MS_NOSUID|MS_NOEXEC|MS_NODEV,
+           NULL,          MNT_FATAL|MNT_IN_CONTAINER },
+-        { "proc",        "/proc",                     "proc",       NULL,     
                 MS_NOSUID|MS_NOEXEC|MS_NODEV,
++        { "proc",        "/proc",                     "proc",       
"hidepid=2",               MS_NOSUID|MS_NOEXEC|MS_NODEV,
+           NULL,          MNT_FATAL|MNT_IN_CONTAINER },
+         { "devtmpfs",    "/dev",                      "devtmpfs",   
"mode=755",                MS_NOSUID|MS_STRICTATIME,
+           NULL,          MNT_FATAL|MNT_IN_CONTAINER },
diff --git a/source/base/systemd/revert-coredump-rework.patch 
b/source/base/systemd/revert-coredump-rework.patch
deleted file mode 100644
index fde6c56..0000000
--- a/source/base/systemd/revert-coredump-rework.patch
+++ /dev/null
@@ -1,1199 +0,0 @@
-diff -Naur systemd-229/configure.ac systemd-229-p/configure.ac
---- systemd-229/configure.ac   2016-02-11 17:28:00.000000000 +0100
-+++ systemd-229-p/configure.ac 2016-04-05 10:02:21.887034159 +0200
-@@ -1106,7 +1106,6 @@
- AC_ARG_ENABLE(coredump, AS_HELP_STRING([--disable-coredump], [disable 
coredump hook]))
- if test "x$enable_coredump" != "xno"; then
-         have_coredump=yes
--        M4_DEFINES="$M4_DEFINES -DENABLE_COREDUMP"
- fi
- AM_CONDITIONAL(ENABLE_COREDUMP, [test "$have_coredump" = "yes"])
-
-diff -Naur systemd-229/Makefile.am systemd-229-p/Makefile.am
---- systemd-229/Makefile.am    2016-02-11 17:28:00.000000000 +0100
-+++ systemd-229-p/Makefile.am  2016-04-05 10:07:06.584767344 +0200
-@@ -4413,15 +4413,6 @@
-       $(ELFUTILS_LIBS)
- endif
-
--nodist_systemunit_DATA += \
--      units/[email protected]
--
--dist_systemunit_DATA += \
--      units/systemd-coredump.socket
--
--SOCKETS_TARGET_WANTS += \
--      systemd-coredump.socket
--
- rootlibexec_PROGRAMS += \
-       systemd-coredump
-
-@@ -4462,8 +4453,7 @@
- endif
-
- EXTRA_DIST += \
--      sysctl.d/50-coredump.conf.in \
--      units/[email protected]
-+      sysctl.d/50-coredump.conf.in
-
- # 
------------------------------------------------------------------------------
- if ENABLE_BINFMT
-@@ -4870,6 +4860,7 @@
- GENERAL_ALIASES += \
-       $(systemunitdir)/systemd-timesyncd.service 
$(pkgsysconfdir)/system/sysinit.target.wants/systemd-timesyncd.service
-
-+
- nodist_pkgsysconf_DATA += \
-       src/timesync/timesyncd.conf
-
-diff -Naur systemd-229/README systemd-229-p/README
---- systemd-229/README 2016-02-11 17:28:00.000000000 +0100
-+++ systemd-229-p/README       2016-04-05 10:02:21.886034132 +0200
-@@ -203,9 +203,6 @@
-         Similarly, the kdbus dbus1 proxy daemon requires the
-         "systemd-bus-proxy" system user and group to exist.
-
--        Similarly, the coredump support requires the
--        "systemd-coredump" system user and group to exist.
--
- NSS:
-         systemd ships with three NSS modules:
-
-diff -Naur systemd-229/src/basic/socket-util.c 
systemd-229-p/src/basic/socket-util.c
---- systemd-229/src/basic/socket-util.c        2016-02-11 17:28:00.000000000 
+0100
-+++ systemd-229-p/src/basic/socket-util.c      2016-04-05 10:07:06.584767344 
+0200
-@@ -871,13 +871,14 @@
-                 struct cmsghdr cmsghdr;
-                 uint8_t buf[CMSG_SPACE(sizeof(int))];
-         } control = {};
-+        struct cmsghdr *cmsg;
-+
-         struct msghdr mh = {
-                 .msg_name = (struct sockaddr*) sa,
-                 .msg_namelen = len,
-                 .msg_control = &control,
-                 .msg_controllen = sizeof(control),
-         };
--        struct cmsghdr *cmsg;
-
-         assert(transport_fd >= 0);
-         assert(fd >= 0);
-diff -Naur systemd-229/src/coredump/coredump.c 
systemd-229-p/src/coredump/coredump.c
---- systemd-229/src/coredump/coredump.c        2016-02-11 17:28:00.000000000 
+0100
-+++ systemd-229-p/src/coredump/coredump.c      2016-04-05 10:07:06.586767398 
+0200
-@@ -24,13 +24,12 @@
- #include <unistd.h>
-
- #ifdef HAVE_ELFUTILS
--#include <dwarf.h>
--#include <elfutils/libdwfl.h>
-+#  include <dwarf.h>
-+#  include <elfutils/libdwfl.h>
- #endif
-
- #include "sd-journal.h"
- #include "sd-login.h"
--#include "sd-daemon.h"
-
- #include "acl-util.h"
- #include "alloc-util.h"
-@@ -52,7 +51,6 @@
- #include "mkdir.h"
- #include "parse-util.h"
- #include "process-util.h"
--#include "socket-util.h"
- #include "special.h"
- #include "stacktrace.h"
- #include "string-table.h"
-@@ -64,10 +62,12 @@
- /* The maximum size up to which we process coredumps */
- #define PROCESS_SIZE_MAX ((uint64_t) (2LLU*1024LLU*1024LLU*1024LLU))
-
--/* The maximum size up to which we leave the coredump around on disk */
-+/* The maximum size up to which we leave the coredump around on
-+ * disk */
- #define EXTERNAL_SIZE_MAX PROCESS_SIZE_MAX
-
--/* The maximum size up to which we store the coredump in the journal */
-+/* The maximum size up to which we store the coredump in the
-+ * journal */
- #define JOURNAL_SIZE_MAX ((size_t) (767LU*1024LU*1024LU))
-
- /* Make sure to not make this larger than the maximum journal entry
-@@ -75,17 +75,14 @@
- assert_cc(JOURNAL_SIZE_MAX <= DATA_SIZE_MAX);
-
- enum {
--        /* We use this as array indexes for a couple of special fields we use 
for naming coredumping files, and
--         * attaching xattrs */
--        CONTEXT_PID,
--        CONTEXT_UID,
--        CONTEXT_GID,
--        CONTEXT_SIGNAL,
--        CONTEXT_TIMESTAMP,
--        CONTEXT_RLIMIT,
--        CONTEXT_COMM,
--        CONTEXT_EXE,
--        _CONTEXT_MAX
-+        INFO_PID,
-+        INFO_UID,
-+        INFO_GID,
-+        INFO_SIGNAL,
-+        INFO_TIMESTAMP,
-+        INFO_COMM,
-+        INFO_EXE,
-+        _INFO_LEN
- };
-
- typedef enum CoredumpStorage {
-@@ -176,16 +173,16 @@
-         return 0;
- }
-
--static int fix_xattr(int fd, const char *context[_CONTEXT_MAX]) {
-+static int fix_xattr(int fd, const char *info[_INFO_LEN]) {
-
--        static const char * const xattrs[_CONTEXT_MAX] = {
--                [CONTEXT_PID] = "user.coredump.pid",
--                [CONTEXT_UID] = "user.coredump.uid",
--                [CONTEXT_GID] = "user.coredump.gid",
--                [CONTEXT_SIGNAL] = "user.coredump.signal",
--                [CONTEXT_TIMESTAMP] = "user.coredump.timestamp",
--                [CONTEXT_COMM] = "user.coredump.comm",
--                [CONTEXT_EXE] = "user.coredump.exe",
-+        static const char * const xattrs[_INFO_LEN] = {
-+                [INFO_PID] = "user.coredump.pid",
-+                [INFO_UID] = "user.coredump.uid",
-+                [INFO_GID] = "user.coredump.gid",
-+                [INFO_SIGNAL] = "user.coredump.signal",
-+                [INFO_TIMESTAMP] = "user.coredump.timestamp",
-+                [INFO_COMM] = "user.coredump.comm",
-+                [INFO_EXE] = "user.coredump.exe",
-         };
-
-         int r = 0;
-@@ -196,13 +193,13 @@
-         /* Attach some metadata to coredumps via extended
-          * attributes. Just because we can. */
-
--        for (i = 0; i < _CONTEXT_MAX; i++) {
-+        for (i = 0; i < _INFO_LEN; i++) {
-                 int k;
-
--                if (isempty(context[i]) || !xattrs[i])
-+                if (isempty(info[i]) || !xattrs[i])
-                         continue;
-
--                k = fsetxattr(fd, xattrs[i], context[i], strlen(context[i]), 
XATTR_CREATE);
-+                k = fsetxattr(fd, xattrs[i], info[i], strlen(info[i]), 
XATTR_CREATE);
-                 if (k < 0 && r == 0)
-                         r = -errno;
-         }
-@@ -216,18 +213,18 @@
-                 int fd,
-                 const char *filename,
-                 const char *target,
--                const char *context[_CONTEXT_MAX],
-+                const char *info[_INFO_LEN],
-                 uid_t uid) {
-
-         assert(fd >= 0);
-         assert(filename);
-         assert(target);
--        assert(context);
-+        assert(info);
-
-         /* Ignore errors on these */
--        (void) fchmod(fd, 0640);
--        (void) fix_acl(fd, uid);
--        (void) fix_xattr(fd, context);
-+        fchmod(fd, 0640);
-+        fix_acl(fd, uid);
-+        fix_xattr(fd, info);
-
-         if (fsync(fd) < 0)
-                 return log_error_errno(errno, "Failed to sync coredump %s: 
%m", filename);
-@@ -255,18 +252,18 @@
-         return 1;
- }
-
--static int make_filename(const char *context[_CONTEXT_MAX], char **ret) {
-+static int make_filename(const char *info[_INFO_LEN], char **ret) {
-         _cleanup_free_ char *c = NULL, *u = NULL, *p = NULL, *t = NULL;
-         sd_id128_t boot = {};
-         int r;
-
--        assert(context);
-+        assert(info);
-
--        c = filename_escape(context[CONTEXT_COMM]);
-+        c = filename_escape(info[INFO_COMM]);
-         if (!c)
-                 return -ENOMEM;
-
--        u = filename_escape(context[CONTEXT_UID]);
-+        u = filename_escape(info[INFO_UID]);
-         if (!u)
-                 return -ENOMEM;
-
-@@ -274,11 +271,11 @@
-         if (r < 0)
-                 return r;
-
--        p = filename_escape(context[CONTEXT_PID]);
-+        p = filename_escape(info[INFO_PID]);
-         if (!p)
-                 return -ENOMEM;
-
--        t = filename_escape(context[CONTEXT_TIMESTAMP]);
-+        t = filename_escape(info[INFO_TIMESTAMP]);
-         if (!t)
-                 return -ENOMEM;
-
-@@ -295,8 +292,8 @@
- }
-
- static int save_external_coredump(
--                const char *context[_CONTEXT_MAX],
--                int input_fd,
-+                const char *info[_INFO_LEN],
-+                uid_t uid,
-                 char **ret_filename,
-                 int *ret_node_fd,
-                 int *ret_data_fd,
-@@ -304,34 +301,16 @@
-
-         _cleanup_free_ char *fn = NULL, *tmp = NULL;
-         _cleanup_close_ int fd = -1;
--        uint64_t rlimit, max_size;
-         struct stat st;
--        uid_t uid;
-         int r;
-
--        assert(context);
-+        assert(info);
-         assert(ret_filename);
-         assert(ret_node_fd);
-         assert(ret_data_fd);
-         assert(ret_size);
-
--        r = parse_uid(context[CONTEXT_UID], &uid);
--        if (r < 0)
--                return log_error_errno(r, "Failed to parse UID: %m");
--
--        r = safe_atou64(context[CONTEXT_RLIMIT], &rlimit);
--        if (r < 0)
--                return log_error_errno(r, "Failed to parse resource limit: 
%s", context[CONTEXT_RLIMIT]);
--        if (rlimit <= 0) {
--                /* Is coredumping disabled? Then don't bother 
saving/processing the coredump */
--                log_info("Core Dumping has been disabled for process %s 
(%s).", context[CONTEXT_PID], context[CONTEXT_COMM]);
--                return -EBADSLT;
--        }
--
--        /* Never store more than the process configured, or than we actually 
shall keep or process */
--        max_size = MIN(rlimit, MAX(arg_process_size_max, 
arg_external_size_max));
--
--        r = make_filename(context, &fn);
-+        r = make_filename(info, &fn);
-         if (r < 0)
-                 return log_error_errno(r, "Failed to determine coredump file 
name: %m");
-
-@@ -345,12 +324,12 @@
-         if (fd < 0)
-                 return log_error_errno(errno, "Failed to create coredump file 
%s: %m", tmp);
-
--        r = copy_bytes(input_fd, fd, max_size, false);
-+        r = copy_bytes(STDIN_FILENO, fd, arg_process_size_max, false);
-         if (r == -EFBIG) {
--                log_error("Coredump of %s (%s) is larger than configured 
processing limit, refusing.", context[CONTEXT_PID], context[CONTEXT_COMM]);
-+                log_error("Coredump of %s (%s) is larger than configured 
processing limit, refusing.", info[INFO_PID], info[INFO_COMM]);
-                 goto fail;
-         } else if (IN_SET(r, -EDQUOT, -ENOSPC)) {
--                log_error("Not enough disk space for coredump of %s (%s), 
refusing.", context[CONTEXT_PID], context[CONTEXT_COMM]);
-+                log_error("Not enough disk space for coredump of %s (%s), 
refusing.", info[INFO_PID], info[INFO_COMM]);
-                 goto fail;
-         } else if (r < 0) {
-                 log_error_errno(r, "Failed to dump coredump to file: %m");
-@@ -399,7 +378,7 @@
-                         goto fail_compressed;
-                 }
-
--                r = fix_permissions(fd_compressed, tmp_compressed, 
fn_compressed, context, uid);
-+                r = fix_permissions(fd_compressed, tmp_compressed, 
fn_compressed, info, uid);
-                 if (r < 0)
-                         goto fail_compressed;
-
-@@ -417,13 +396,13 @@
-                 return 0;
-
-         fail_compressed:
--                (void) unlink(tmp_compressed);
-+                unlink_noerrno(tmp_compressed);
-         }
-
- uncompressed:
- #endif
-
--        r = fix_permissions(fd, tmp, fn, context, uid);
-+        r = fix_permissions(fd, tmp, fn, info, uid);
-         if (r < 0)
-                 goto fail;
-
-@@ -438,7 +417,7 @@
-         return 0;
-
- fail:
--        (void) unlink(tmp);
-+        unlink_noerrno(tmp);
-         return r;
- }
-
-@@ -560,473 +539,186 @@
-         return 0;
- }
-
--static int change_uid_gid(const char *context[]) {
--        uid_t uid;
--        gid_t gid;
--        int r;
-+int main(int argc, char* argv[]) {
-
--        r = parse_uid(context[CONTEXT_UID], &uid);
--        if (r < 0)
--                return r;
--
--        if (uid <= SYSTEM_UID_MAX) {
--                const char *user = "systemd-coredump";
--
--                r = get_user_creds(&user, &uid, &gid, NULL, NULL);
--                if (r < 0) {
--                        log_warning_errno(r, "Cannot resolve %s user. 
Proceeding to dump core as root: %m", user);
--                        uid = gid = 0;
--                }
--        } else {
--                r = parse_gid(context[CONTEXT_GID], &gid);
--                if (r < 0)
--                        return r;
--        }
-+        /* The small core field we allocate on the stack, to keep things 
simple */
-+        char
-+                *core_pid = NULL, *core_uid = NULL, *core_gid = NULL, 
*core_signal = NULL,
-+                *core_session = NULL, *core_exe = NULL, *core_comm = NULL, 
*core_cmdline = NULL,
-+                *core_cgroup = NULL, *core_cwd = NULL, *core_root = NULL, 
*core_unit = NULL,
-+                *core_slice = NULL;
-
--        return drop_privileges(uid, gid, 0);
--}
-+        /* The larger ones we allocate on the heap */
-+        _cleanup_free_ char
-+                *core_timestamp = NULL,  *core_message = NULL, *coredump_data 
= NULL, *core_owner_uid = NULL,
-+                *core_open_fds = NULL, *core_proc_status = NULL, 
*core_proc_maps = NULL, *core_proc_limits = NULL,
-+                *core_proc_cgroup = NULL, *core_environ = NULL;
-
--static int submit_coredump(
--                const char *context[_CONTEXT_MAX],
--                struct iovec *iovec,
--                size_t n_iovec_allocated,
--                size_t n_iovec,
--                int input_fd) {
-+        _cleanup_free_ char *exe = NULL, *comm = NULL, *filename = NULL;
-+        const char *info[_INFO_LEN];
-
-         _cleanup_close_ int coredump_fd = -1, coredump_node_fd = -1;
--        _cleanup_free_ char *core_message = NULL, *filename = NULL, 
*coredump_data = NULL;
--        uint64_t coredump_size;
--        int r;
--
--        assert(context);
--        assert(iovec);
--        assert(n_iovec_allocated >= n_iovec + 3);
--        assert(input_fd >= 0);
--
--        /* Vacuum before we write anything again */
--        (void) coredump_vacuum(-1, arg_keep_free, arg_max_use);
-
--        /* Always stream the coredump to disk, if that's possible */
--        r = save_external_coredump(context, input_fd, &filename, 
&coredump_node_fd, &coredump_fd, &coredump_size);
--        if (r < 0)
--                /* Skip whole core dumping part */
--                goto log;
--
--        /* If we don't want to keep the coredump on disk, remove it now, as 
later on we will lack the privileges for
--         * it. However, we keep the fd to it, so that we can still process it 
and log it. */
--        r = maybe_remove_external_coredump(filename, coredump_size);
--        if (r < 0)
--                return r;
--        if (r == 0) {
--                const char *coredump_filename;
--
--                coredump_filename = strjoina("COREDUMP_FILENAME=", filename);
--                IOVEC_SET_STRING(iovec[n_iovec++], coredump_filename);
--        }
--
--        /* Vacuum again, but exclude the coredump we just created */
--        (void) coredump_vacuum(coredump_node_fd >= 0 ? coredump_node_fd : 
coredump_fd, arg_keep_free, arg_max_use);
--
--        /* Now, let's drop privileges to become the user who owns the 
segfaulted process and allocate the coredump
--         * memory under the user's uid. This also ensures that the 
credentials journald will see are the ones of the
--         * coredumping user, thus making sure the user gets access to the 
core dump. Let's also get rid of all
--         * capabilities, if we run as root, we won't need them anymore. */
--        r = change_uid_gid(context);
--        if (r < 0)
--                return log_error_errno(r, "Failed to drop privileges: %m");
--
--#ifdef HAVE_ELFUTILS
--        /* Try to get a strack trace if we can */
--        if (coredump_size <= arg_process_size_max) {
--                _cleanup_free_ char *stacktrace = NULL;
--
--                r = coredump_make_stack_trace(coredump_fd, 
context[CONTEXT_EXE], &stacktrace);
--                if (r >= 0)
--                        core_message = strjoin("MESSAGE=Process ", 
context[CONTEXT_PID], " (", context[CONTEXT_COMM], ") of user ", 
context[CONTEXT_UID], " dumped core.\n\n", stacktrace, NULL);
--                else if (r == -EINVAL)
--                        log_warning("Failed to generate stack trace: %s", 
dwfl_errmsg(dwfl_errno()));
--                else
--                        log_warning_errno(r, "Failed to generate stack trace: 
%m");
--        }
--
--        if (!core_message)
--#endif
--log:
--        core_message = strjoin("MESSAGE=Process ", context[CONTEXT_PID], " 
(", context[CONTEXT_COMM], ") of user ", context[CONTEXT_UID], " dumped core.", 
NULL);
--        if (core_message)
--                IOVEC_SET_STRING(iovec[n_iovec++], core_message);
-+        struct iovec iovec[26];
-+        uint64_t coredump_size;
-+        int r, j = 0;
-+        uid_t uid, owner_uid;
-+        gid_t gid;
-+        pid_t pid;
-+        char *t;
-+        const char *p;
-
--        /* Optionally store the entire coredump in the journal */
--        if (IN_SET(arg_storage, COREDUMP_STORAGE_JOURNAL, 
COREDUMP_STORAGE_BOTH) &&
--            coredump_size <= arg_journal_size_max) {
--                size_t sz = 0;
-+        /* Make sure we never enter a loop */
-+        prctl(PR_SET_DUMPABLE, 0);
-
--                /* Store the coredump itself in the journal */
-+        /* First, log to a safe place, since we don't know what
-+         * crashed and it might be journald which we'd rather not log
-+         * to then. */
-+        log_set_target(LOG_TARGET_KMSG);
-+        log_open();
-
--                r = allocate_journal_field(coredump_fd, (size_t) 
coredump_size, &coredump_data, &sz);
--                if (r >= 0) {
--                        iovec[n_iovec].iov_base = coredump_data;
--                        iovec[n_iovec].iov_len = sz;
--                        n_iovec++;
--                }
-+        if (argc < INFO_COMM + 1) {
-+                log_error("Not enough arguments passed from kernel (%d, 
expected %d).",
-+                          argc - 1, INFO_COMM + 1 - 1);
-+                r = -EINVAL;
-+                goto finish;
-         }
-
--        assert(n_iovec <= n_iovec_allocated);
--
--        r = sd_journal_sendv(iovec, n_iovec);
--        if (r < 0)
--                return log_error_errno(r, "Failed to log coredump: %m");
--
--        return 0;
--}
--
--static void map_context_fields(const struct iovec *iovec, const char 
*context[]) {
--
--        static const char * const context_field_names[_CONTEXT_MAX] = {
--                [CONTEXT_PID] = "COREDUMP_PID=",
--                [CONTEXT_UID] = "COREDUMP_UID=",
--                [CONTEXT_GID] = "COREDUMP_GID=",
--                [CONTEXT_SIGNAL] = "COREDUMP_SIGNAL=",
--                [CONTEXT_TIMESTAMP] = "COREDUMP_TIMESTAMP=",
--                [CONTEXT_COMM] = "COREDUMP_COMM=",
--                [CONTEXT_EXE] = "COREDUMP_EXE=",
--                [CONTEXT_RLIMIT] = "COREDUMP_RLIMIT=",
--        };
--
--        unsigned i;
--
--        assert(iovec);
--        assert(context);
--
--        for (i = 0; i < _CONTEXT_MAX; i++) {
--                size_t l;
--
--                l = strlen(context_field_names[i]);
--                if (iovec->iov_len < l)
--                        continue;
-+        /* Ignore all parse errors */
-+        parse_config();
-
--                if (memcmp(iovec->iov_base, context_field_names[i], l) != 0)
--                        continue;
-+        log_debug("Selected storage '%s'.", 
coredump_storage_to_string(arg_storage));
-+        log_debug("Selected compression %s.", yes_no(arg_compress));
-
--                /* Note that these strings are NUL terminated, because we 
made sure that a trailing NUL byte is in the
--                 * buffer, though not included in the iov_len count. (see 
below) */
--                context[i] = (char*) iovec->iov_base + l;
--                break;
-+        r = parse_uid(argv[INFO_UID + 1], &uid);
-+        if (r < 0) {
-+                log_error("Failed to parse UID.");
-+                goto finish;
-         }
--}
--
--static int process_socket(int fd) {
--        _cleanup_close_ int coredump_fd = -1;
--        struct iovec *iovec = NULL;
--        size_t n_iovec = 0, n_iovec_allocated = 0, i;
--        const char *context[_CONTEXT_MAX] = {};
--        int r;
--
--        assert(fd >= 0);
--
--        log_set_target(LOG_TARGET_AUTO);
--        log_parse_environment();
--        log_open();
--
--        for (;;) {
--                union {
--                        struct cmsghdr cmsghdr;
--                        uint8_t buf[CMSG_SPACE(sizeof(int))];
--                } control = {};
--                struct msghdr mh = {
--                        .msg_control = &control,
--                        .msg_controllen = sizeof(control),
--                        .msg_iovlen = 1,
--                };
--                ssize_t n;
--                int l;
--
--                if (!GREEDY_REALLOC(iovec, n_iovec_allocated, n_iovec + 3)) {
--                        r = log_oom();
--                        goto finish;
--                }
--
--                if (ioctl(fd, FIONREAD, &l) < 0) {
--                        r = log_error_errno(errno, "FIONREAD failed: %m");
--                        goto finish;
--                }
--
--                assert(l >= 0);
--
--                iovec[n_iovec].iov_len = l;
--                iovec[n_iovec].iov_base = malloc(l + 1);
--
--                if (!iovec[n_iovec].iov_base) {
--                        r = log_oom();
--                        goto finish;
--                }
--
--                mh.msg_iov = iovec + n_iovec;
--
--                n = recvmsg(fd, &mh, MSG_NOSIGNAL|MSG_CMSG_CLOEXEC);
--                if (n < 0)  {
--                        free(iovec[n_iovec].iov_base);
--                        r = log_error_errno(errno, "Failed to receive 
datagram: %m");
--                        goto finish;
--                }
--
--                if (n == 0) {
--                        struct cmsghdr *cmsg, *found = NULL;
--                        /* The final zero-length datagram carries the file 
descriptor and tells us that we're done. */
--
--                        free(iovec[n_iovec].iov_base);
--
--                        CMSG_FOREACH(cmsg, &mh) {
--                                if (cmsg->cmsg_level == SOL_SOCKET &&
--                                    cmsg->cmsg_type == SCM_RIGHTS &&
--                                    cmsg->cmsg_len == CMSG_LEN(sizeof(int))) {
--                                        assert(!found);
--                                        found = cmsg;
--                                }
--                        }
--
--                        if (!found) {
--                                log_error("Coredump file descriptor 
missing.");
--                                r = -EBADMSG;
--                                goto finish;
--                        }
-
--                        assert(coredump_fd < 0);
--                        coredump_fd = *(int*) CMSG_DATA(found);
--                        break;
--                }
--
--                /* Add trailing NUL byte, in case these are strings */
--                ((char*) iovec[n_iovec].iov_base)[n] = 0;
--                iovec[n_iovec].iov_len = (size_t) n;
--
--                cmsg_close_all(&mh);
--                map_context_fields(iovec + n_iovec, context);
--                n_iovec++;
-+        r = parse_pid(argv[INFO_PID + 1], &pid);
-+        if (r < 0) {
-+                log_error("Failed to parse PID.");
-+                goto finish;
-         }
-
--        if (!GREEDY_REALLOC(iovec, n_iovec_allocated, n_iovec + 3)) {
--                r = log_oom();
-+        r = parse_gid(argv[INFO_GID + 1], &gid);
-+        if (r < 0) {
-+                log_error("Failed to parse GID.");
-                 goto finish;
-         }
-
--        /* Make sure we we got all data we really need */
--        assert(context[CONTEXT_PID]);
--        assert(context[CONTEXT_UID]);
--        assert(context[CONTEXT_GID]);
--        assert(context[CONTEXT_SIGNAL]);
--        assert(context[CONTEXT_TIMESTAMP]);
--        assert(context[CONTEXT_RLIMIT]);
--        assert(context[CONTEXT_COMM]);
--        assert(coredump_fd >= 0);
--
--        r = submit_coredump(context, iovec, n_iovec_allocated, n_iovec, 
coredump_fd);
--
--finish:
--        for (i = 0; i < n_iovec; i++)
--                free(iovec[i].iov_base);
--        free(iovec);
--
--        return r;
--}
--
--static int send_iovec(const struct iovec iovec[], size_t n_iovec, int 
input_fd) {
--
--        static const union sockaddr_union sa = {
--                .un.sun_family = AF_UNIX,
--                .un.sun_path = "/run/systemd/coredump",
--        };
--        _cleanup_close_ int fd = -1;
--        size_t i;
--        int r;
--
--        assert(iovec || n_iovec <= 0);
--        assert(input_fd >= 0);
--
--        fd = socket(AF_UNIX, SOCK_SEQPACKET|SOCK_CLOEXEC, 0);
--        if (fd < 0)
--                return log_error_errno(errno, "Failed to create coredump 
socket: %m");
--
--        if (connect(fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + 
strlen(sa.un.sun_path)) < 0)
--                return log_error_errno(errno, "Failed to connect to coredump 
service: %m");
--
--        for (i = 0; i < n_iovec; i++) {
--                ssize_t n;
--                assert(iovec[i].iov_len > 0);
--
--                n = send(fd, iovec[i].iov_base, iovec[i].iov_len, 
MSG_NOSIGNAL);
--                if (n < 0)
--                        return log_error_errno(errno, "Failed to send 
coredump datagram: %m");
-+        if (get_process_comm(pid, &comm) < 0) {
-+                log_warning("Failed to get COMM, falling back to the command 
line.");
-+                comm = strv_join(argv + INFO_COMM + 1, " ");
-         }
-
--        r = send_one_fd(fd, input_fd, 0);
--        if (r < 0)
--                return log_error_errno(r, "Failed to send coredump fd: %m");
--
--        return 0;
--}
--
--static int process_journald_crash(const char *context[], int input_fd) {
--        _cleanup_close_ int coredump_fd = -1, coredump_node_fd = -1;
--        _cleanup_free_ char *filename = NULL;
--        uint64_t coredump_size;
--        int r;
--
--        assert(context);
--        assert(input_fd >= 0);
--
--        /* If we are journald, we cut things short, don't write to the 
journal, but still create a coredump. */
--
--        if (arg_storage != COREDUMP_STORAGE_NONE)
--                arg_storage = COREDUMP_STORAGE_EXTERNAL;
--
--        r = save_external_coredump(context, input_fd, &filename, 
&coredump_node_fd, &coredump_fd, &coredump_size);
--        if (r < 0)
--                return r;
-+        if (get_process_exe(pid, &exe) < 0)
-+                log_warning("Failed to get EXE.");
-+
-+        info[INFO_PID] = argv[INFO_PID + 1];
-+        info[INFO_UID] = argv[INFO_UID + 1];
-+        info[INFO_GID] = argv[INFO_GID + 1];
-+        info[INFO_SIGNAL] = argv[INFO_SIGNAL + 1];
-+        info[INFO_TIMESTAMP] = argv[INFO_TIMESTAMP + 1];
-+        info[INFO_COMM] = comm;
-+        info[INFO_EXE] = exe;
-
--        r = maybe_remove_external_coredump(filename, coredump_size);
--        if (r < 0)
--                return r;
--
--        log_info("Detected coredump of the journal daemon itself, diverted to 
%s.", filename);
--        return 0;
--}
--
--static int process_kernel(int argc, char* argv[]) {
--
--        /* The small core field we allocate on the stack, to keep things 
simple */
--        char
--                *core_pid = NULL, *core_uid = NULL, *core_gid = NULL, 
*core_signal = NULL,
--                *core_session = NULL, *core_exe = NULL, *core_comm = NULL, 
*core_cmdline = NULL,
--                *core_cgroup = NULL, *core_cwd = NULL, *core_root = NULL, 
*core_unit = NULL,
--                *core_user_unit = NULL, *core_slice = NULL, *core_timestamp = 
NULL, *core_rlimit = NULL;
--
--        /* The larger ones we allocate on the heap */
--        _cleanup_free_ char
--                *core_owner_uid = NULL, *core_open_fds = NULL, 
*core_proc_status = NULL,
--                *core_proc_maps = NULL, *core_proc_limits = NULL, 
*core_proc_cgroup = NULL, *core_environ = NULL;
--
--        _cleanup_free_ char *exe = NULL, *comm = NULL;
--        const char *context[_CONTEXT_MAX];
--        struct iovec iovec[25];
--        size_t n_iovec = 0;
--        uid_t owner_uid;
--        const char *p;
--        pid_t pid;
--        char *t;
--        int r;
--
--        if (argc < CONTEXT_COMM + 1) {
--                log_error("Not enough arguments passed from kernel (%i, 
expected %i).", argc - 1, CONTEXT_COMM + 1 - 1);
--                return -EINVAL;
--        }
-+        if (cg_pid_get_unit(pid, &t) >= 0) {
-
--        r = parse_pid(argv[CONTEXT_PID + 1], &pid);
--        if (r < 0)
--                return log_error_errno(r, "Failed to parse PID.");
-+                if (streq(t, SPECIAL_JOURNALD_SERVICE)) {
-+                        free(t);
-
--        r = get_process_comm(pid, &comm);
--        if (r < 0) {
--                log_warning_errno(r, "Failed to get COMM, falling back to the 
command line: %m");
--                comm = strv_join(argv + CONTEXT_COMM + 1, " ");
--                if (!comm)
--                        return log_oom();
--        }
-+                        /* If we are journald, we cut things short,
-+                         * don't write to the journal, but still
-+                         * create a coredump. */
-
--        r = get_process_exe(pid, &exe);
--        if (r < 0)
--                log_warning_errno(r, "Failed to get EXE, ignoring: %m");
-+                        if (arg_storage != COREDUMP_STORAGE_NONE)
-+                                arg_storage = COREDUMP_STORAGE_EXTERNAL;
-
--        context[CONTEXT_PID] = argv[CONTEXT_PID + 1];
--        context[CONTEXT_UID] = argv[CONTEXT_UID + 1];
--        context[CONTEXT_GID] = argv[CONTEXT_GID + 1];
--        context[CONTEXT_SIGNAL] = argv[CONTEXT_SIGNAL + 1];
--        context[CONTEXT_TIMESTAMP] = argv[CONTEXT_TIMESTAMP + 1];
--        context[CONTEXT_RLIMIT] = argv[CONTEXT_RLIMIT + 1];
--        context[CONTEXT_COMM] = comm;
--        context[CONTEXT_EXE] = exe;
-+                        r = save_external_coredump(info, uid, &filename, 
&coredump_node_fd, &coredump_fd, &coredump_size);
-+                        if (r < 0)
-+                                goto finish;
-
--        if (cg_pid_get_unit(pid, &t) >= 0) {
-+                        r = maybe_remove_external_coredump(filename, 
coredump_size);
-+                        if (r < 0)
-+                                goto finish;
-
--                if (streq(t, SPECIAL_JOURNALD_SERVICE)) {
--                        free(t);
--                        return process_journald_crash(context, STDIN_FILENO);
-+                        log_info("Detected coredump of the journal daemon 
itself, diverted to %s.", filename);
-+                        goto finish;
-                 }
-
-                 core_unit = strjoina("COREDUMP_UNIT=", t);
-                 free(t);
-
--                IOVEC_SET_STRING(iovec[n_iovec++], core_unit);
-+        } else if (cg_pid_get_user_unit(pid, &t) >= 0) {
-+                core_unit = strjoina("COREDUMP_USER_UNIT=", t);
-+                free(t);
-         }
-
--        /* OK, now we know it's not the journal, hence we can make use of it 
now. */
-+        if (core_unit)
-+                IOVEC_SET_STRING(iovec[j++], core_unit);
-+
-+        /* OK, now we know it's not the journal, hence we can make use
-+         * of it now. */
-         log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
-         log_open();
-
--        if (cg_pid_get_user_unit(pid, &t) >= 0) {
--                core_user_unit = strjoina("COREDUMP_USER_UNIT=", t);
--                free(t);
--
--                IOVEC_SET_STRING(iovec[n_iovec++], core_user_unit);
--        }
--
--        core_pid = strjoina("COREDUMP_PID=", context[CONTEXT_PID]);
--        IOVEC_SET_STRING(iovec[n_iovec++], core_pid);
-+        core_pid = strjoina("COREDUMP_PID=", info[INFO_PID]);
-+        IOVEC_SET_STRING(iovec[j++], core_pid);
-
--        core_uid = strjoina("COREDUMP_UID=", context[CONTEXT_UID]);
--        IOVEC_SET_STRING(iovec[n_iovec++], core_uid);
-+        core_uid = strjoina("COREDUMP_UID=", info[INFO_UID]);
-+        IOVEC_SET_STRING(iovec[j++], core_uid);
-
--        core_gid = strjoina("COREDUMP_GID=", context[CONTEXT_GID]);
--        IOVEC_SET_STRING(iovec[n_iovec++], core_gid);
-+        core_gid = strjoina("COREDUMP_GID=", info[INFO_GID]);
-+        IOVEC_SET_STRING(iovec[j++], core_gid);
-
--        core_signal = strjoina("COREDUMP_SIGNAL=", context[CONTEXT_SIGNAL]);
--        IOVEC_SET_STRING(iovec[n_iovec++], core_signal);
--
--        core_rlimit = strjoina("COREDUMP_RLIMIT=", context[CONTEXT_RLIMIT]);
--        IOVEC_SET_STRING(iovec[n_iovec++], core_rlimit);
-+        core_signal = strjoina("COREDUMP_SIGNAL=", info[INFO_SIGNAL]);
-+        IOVEC_SET_STRING(iovec[j++], core_signal);
-
-         if (sd_pid_get_session(pid, &t) >= 0) {
-                 core_session = strjoina("COREDUMP_SESSION=", t);
-                 free(t);
-
--                IOVEC_SET_STRING(iovec[n_iovec++], core_session);
-+                IOVEC_SET_STRING(iovec[j++], core_session);
-         }
-
-         if (sd_pid_get_owner_uid(pid, &owner_uid) >= 0) {
--                r = asprintf(&core_owner_uid, "COREDUMP_OWNER_UID=" UID_FMT, 
owner_uid);
-+                r = asprintf(&core_owner_uid,
-+                             "COREDUMP_OWNER_UID=" UID_FMT, owner_uid);
-                 if (r > 0)
--                        IOVEC_SET_STRING(iovec[n_iovec++], core_owner_uid);
-+                        IOVEC_SET_STRING(iovec[j++], core_owner_uid);
-         }
-
-         if (sd_pid_get_slice(pid, &t) >= 0) {
-                 core_slice = strjoina("COREDUMP_SLICE=", t);
-                 free(t);
-
--                IOVEC_SET_STRING(iovec[n_iovec++], core_slice);
-+                IOVEC_SET_STRING(iovec[j++], core_slice);
-         }
-
-         if (comm) {
-                 core_comm = strjoina("COREDUMP_COMM=", comm);
--                IOVEC_SET_STRING(iovec[n_iovec++], core_comm);
-+                IOVEC_SET_STRING(iovec[j++], core_comm);
-         }
-
-         if (exe) {
-                 core_exe = strjoina("COREDUMP_EXE=", exe);
--                IOVEC_SET_STRING(iovec[n_iovec++], core_exe);
-+                IOVEC_SET_STRING(iovec[j++], core_exe);
-         }
-
-         if (get_process_cmdline(pid, 0, false, &t) >= 0) {
-                 core_cmdline = strjoina("COREDUMP_CMDLINE=", t);
-                 free(t);
-
--                IOVEC_SET_STRING(iovec[n_iovec++], core_cmdline);
-+                IOVEC_SET_STRING(iovec[j++], core_cmdline);
-         }
-
-         if (cg_pid_get_path_shifted(pid, NULL, &t) >= 0) {
-                 core_cgroup = strjoina("COREDUMP_CGROUP=", t);
-                 free(t);
-
--                IOVEC_SET_STRING(iovec[n_iovec++], core_cgroup);
-+                IOVEC_SET_STRING(iovec[j++], core_cgroup);
-         }
-
-         if (compose_open_fds(pid, &t) >= 0) {
-@@ -1034,7 +726,7 @@
-                 free(t);
-
-                 if (core_open_fds)
--                        IOVEC_SET_STRING(iovec[n_iovec++], core_open_fds);
-+                        IOVEC_SET_STRING(iovec[j++], core_open_fds);
-         }
-
-         p = procfs_file_alloca(pid, "status");
-@@ -1043,7 +735,7 @@
-                 free(t);
-
-                 if (core_proc_status)
--                        IOVEC_SET_STRING(iovec[n_iovec++], core_proc_status);
-+                        IOVEC_SET_STRING(iovec[j++], core_proc_status);
-         }
-
-         p = procfs_file_alloca(pid, "maps");
-@@ -1052,7 +744,7 @@
-                 free(t);
-
-                 if (core_proc_maps)
--                        IOVEC_SET_STRING(iovec[n_iovec++], core_proc_maps);
-+                        IOVEC_SET_STRING(iovec[j++], core_proc_maps);
-         }
-
-         p = procfs_file_alloca(pid, "limits");
-@@ -1061,7 +753,7 @@
-                 free(t);
-
-                 if (core_proc_limits)
--                        IOVEC_SET_STRING(iovec[n_iovec++], core_proc_limits);
-+                        IOVEC_SET_STRING(iovec[j++], core_proc_limits);
-         }
-
-         p = procfs_file_alloca(pid, "cgroup");
-@@ -1070,21 +762,21 @@
-                 free(t);
-
-                 if (core_proc_cgroup)
--                        IOVEC_SET_STRING(iovec[n_iovec++], core_proc_cgroup);
-+                        IOVEC_SET_STRING(iovec[j++], core_proc_cgroup);
-         }
-
-         if (get_process_cwd(pid, &t) >= 0) {
-                 core_cwd = strjoina("COREDUMP_CWD=", t);
-                 free(t);
-
--                IOVEC_SET_STRING(iovec[n_iovec++], core_cwd);
-+                IOVEC_SET_STRING(iovec[j++], core_cwd);
-         }
-
-         if (get_process_root(pid, &t) >= 0) {
-                 core_root = strjoina("COREDUMP_ROOT=", t);
-                 free(t);
-
--                IOVEC_SET_STRING(iovec[n_iovec++], core_root);
-+                IOVEC_SET_STRING(iovec[j++], core_root);
-         }
-
-         if (get_process_environ(pid, &t) >= 0) {
-@@ -1092,57 +784,97 @@
-                 free(t);
-
-                 if (core_environ)
--                        IOVEC_SET_STRING(iovec[n_iovec++], core_environ);
-+                        IOVEC_SET_STRING(iovec[j++], core_environ);
-         }
-
--        core_timestamp = strjoina("COREDUMP_TIMESTAMP=", 
context[CONTEXT_TIMESTAMP], "000000", NULL);
--        IOVEC_SET_STRING(iovec[n_iovec++], core_timestamp);
-+        core_timestamp = strjoin("COREDUMP_TIMESTAMP=", info[INFO_TIMESTAMP], 
"000000", NULL);
-+        if (core_timestamp)
-+                IOVEC_SET_STRING(iovec[j++], core_timestamp);
-
--        IOVEC_SET_STRING(iovec[n_iovec++], 
"MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1");
-+        IOVEC_SET_STRING(iovec[j++], 
"MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1");
-
-         assert_cc(2 == LOG_CRIT);
--        IOVEC_SET_STRING(iovec[n_iovec++], "PRIORITY=2");
--
--        assert(n_iovec <= ELEMENTSOF(iovec));
--
--        return send_iovec(iovec, n_iovec, STDIN_FILENO);
--}
--
--int main(int argc, char *argv[]) {
--        int r;
-+        IOVEC_SET_STRING(iovec[j++], "PRIORITY=2");
-
--        /* First, log to a safe place, since we don't know what crashed and 
it might be journald which we'd rather not
--         * log to then. */
-+        /* Vacuum before we write anything again */
-+        coredump_vacuum(-1, arg_keep_free, arg_max_use);
-
--        log_set_target(LOG_TARGET_KMSG);
--        log_open();
-+        /* Always stream the coredump to disk, if that's possible */
-+        r = save_external_coredump(info, uid, &filename, &coredump_node_fd, 
&coredump_fd, &coredump_size);
-+        if (r < 0)
-+                /* skip whole core dumping part */
-+                goto log;
-
--        /* Make sure we never enter a loop */
--        (void) prctl(PR_SET_DUMPABLE, 0);
-+        /* If we don't want to keep the coredump on disk, remove it
-+         * now, as later on we will lack the privileges for
-+         * it. However, we keep the fd to it, so that we can still
-+         * process it and log it. */
-+        r = maybe_remove_external_coredump(filename, coredump_size);
-+        if (r < 0)
-+                goto finish;
-+        if (r == 0) {
-+                const char *coredump_filename;
-
--        /* Ignore all parse errors */
--        (void) parse_config();
-+                coredump_filename = strjoina("COREDUMP_FILENAME=", filename);
-+                IOVEC_SET_STRING(iovec[j++], coredump_filename);
-+        }
-
--        log_debug("Selected storage '%s'.", 
coredump_storage_to_string(arg_storage));
--        log_debug("Selected compression %s.", yes_no(arg_compress));
-+        /* Vacuum again, but exclude the coredump we just created */
-+        coredump_vacuum(coredump_node_fd >= 0 ? coredump_node_fd : 
coredump_fd, arg_keep_free, arg_max_use);
-
--        r = sd_listen_fds(false);
-+        /* Now, let's drop privileges to become the user who owns the
-+         * segfaulted process and allocate the coredump memory under
-+         * the user's uid. This also ensures that the credentials
-+         * journald will see are the ones of the coredumping user,
-+         * thus making sure the user gets access to the core
-+         * dump. Let's also get rid of all capabilities, if we run as
-+         * root, we won't need them anymore. */
-+        r = drop_privileges(uid, gid, 0);
-         if (r < 0) {
--                log_error_errno(r, "Failed to determine number of file 
descriptor: %m");
-+                log_error_errno(r, "Failed to drop privileges: %m");
-                 goto finish;
-         }
-
--        /* If we got an fd passed, we are running in coredumpd mode. 
Otherwise we are invoked from the kernel as
--         * coredump handler */
--        if (r == 0)
--                r = process_kernel(argc, argv);
--        else if (r == 1)
--                r = process_socket(SD_LISTEN_FDS_START);
--        else {
--                log_error("Received unexpected number of file descriptors.");
--                r = -EINVAL;
-+#ifdef HAVE_ELFUTILS
-+        /* Try to get a strack trace if we can */
-+        if (coredump_size <= arg_process_size_max) {
-+                _cleanup_free_ char *stacktrace = NULL;
-+
-+                r = coredump_make_stack_trace(coredump_fd, exe, &stacktrace);
-+                if (r >= 0)
-+                        core_message = strjoin("MESSAGE=Process ", 
info[INFO_PID], " (", comm, ") of user ", info[INFO_UID], " dumped core.\n\n", 
stacktrace, NULL);
-+                else if (r == -EINVAL)
-+                        log_warning("Failed to generate stack trace: %s", 
dwfl_errmsg(dwfl_errno()));
-+                else
-+                        log_warning_errno(r, "Failed to generate stack trace: 
%m");
-+        }
-+
-+        if (!core_message)
-+#endif
-+log:
-+        core_message = strjoin("MESSAGE=Process ", info[INFO_PID], " (", 
comm, ") of user ", info[INFO_UID], " dumped core.", NULL);
-+        if (core_message)
-+                IOVEC_SET_STRING(iovec[j++], core_message);
-+
-+        /* Optionally store the entire coredump in the journal */
-+        if (IN_SET(arg_storage, COREDUMP_STORAGE_JOURNAL, 
COREDUMP_STORAGE_BOTH) &&
-+            coredump_size <= arg_journal_size_max) {
-+                size_t sz = 0;
-+
-+                /* Store the coredump itself in the journal */
-+
-+                r = allocate_journal_field(coredump_fd, (size_t) 
coredump_size, &coredump_data, &sz);
-+                if (r >= 0) {
-+                        iovec[j].iov_base = coredump_data;
-+                        iovec[j].iov_len = sz;
-+                        j++;
-+                }
-         }
-
-+        r = sd_journal_sendv(iovec, j);
-+        if (r < 0)
-+                log_error_errno(r, "Failed to log coredump: %m");
-+
- finish:
-         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
- }
-diff -Naur systemd-229/sysctl.d/50-coredump.conf.in 
systemd-229-p/sysctl.d/50-coredump.conf.in
---- systemd-229/sysctl.d/50-coredump.conf.in   2016-02-11 17:28:00.000000000 
+0100
-+++ systemd-229-p/sysctl.d/50-coredump.conf.in 2016-04-05 10:07:02.033643265 
+0200
-@@ -9,4 +9,4 @@
- # and systemd-coredump(8) and core(5) for the explanation of the
- # setting below.
-
--kernel.core_pattern=|@rootlibexecdir@/systemd-coredump %P %u %g %s %t %c %e
-+kernel.core_pattern=|@rootlibexecdir@/systemd-coredump %P %u %g %s %t %e
-diff -Naur systemd-229/sysusers.d/systemd.conf.m4 
systemd-229-p/sysusers.d/systemd.conf.m4
---- systemd-229/sysusers.d/systemd.conf.m4     2016-02-11 17:28:00.000000000 
+0100
-+++ systemd-229-p/sysusers.d/systemd.conf.m4   2016-04-05 10:02:21.887034159 
+0200
-@@ -16,6 +16,3 @@
- m4_ifdef(`ENABLE_TIMESYNCD',
- u systemd-timesync  - "systemd Time Synchronization"
- )m4_dnl
--m4_ifdef(`ENABLE_COREDUMP',
--u systemd-coredump  - "systemd Core Dumper"
--)m4_dnl
-diff -Naur systemd-229/units/.gitignore systemd-229-p/units/.gitignore
---- systemd-229/units/.gitignore       2016-02-11 17:28:00.000000000 +0100
-+++ systemd-229-p/units/.gitignore     2016-04-05 10:07:06.586767398 +0200
-@@ -25,7 +25,6 @@
- /systemd-binfmt.service
- /systemd-bootchart.service
- /systemd-bus-proxyd.service
--/[email protected]
- /systemd-firstboot.service
- /systemd-fsck-root.service
- /[email protected]
-diff -Naur systemd-229/units/[email protected] 
systemd-229-p/units/[email protected]
---- systemd-229/units/[email protected]     2016-02-11 
17:28:00.000000000 +0100
-+++ systemd-229-p/units/[email protected]   1970-01-01 
01:00:00.000000000 +0100
-@@ -1,24 +0,0 @@
--#  This file is part of systemd.
--#
--#  systemd is free software; you can redistribute it and/or modify it
--#  under the terms of the GNU Lesser General Public License as published by
--#  the Free Software Foundation; either version 2.1 of the License, or
--#  (at your option) any later version.
--
--[Unit]
--Description=Process Core Dump
--Documentation=man:systemd-coredump(8)
--DefaultDependencies=no
--RequiresMountsFor=/var/lib/systemd/coredump
--Conflicts=shutdown.target
--After=systemd-remount-fs.service systemd-journald.socket
--Requires=systemd-journald.socket
--Before=shutdown.target
--
--[Service]
--ExecStart=-@rootlibexecdir@/systemd-coredump
--Nice=9
--OOMScoreAdjust=500
--PrivateNetwork=yes
--ProtectSystem=full
--RuntimeMaxSec=5min
-diff -Naur systemd-229/units/systemd-coredump.socket 
systemd-229-p/units/systemd-coredump.socket
---- systemd-229/units/systemd-coredump.socket  2016-02-11 17:28:00.000000000 
+0100
-+++ systemd-229-p/units/systemd-coredump.socket        1970-01-01 
01:00:00.000000000 +0100
-@@ -1,17 +0,0 @@
--#  This file is part of systemd.
--#
--#  systemd is free software; you can redistribute it and/or modify it
--#  under the terms of the GNU Lesser General Public License as published by
--#  the Free Software Foundation; either version 2.1 of the License, or
--#  (at your option) any later version.
--
--[Unit]
--Description=Process Core Dump Socket
--Documentation=man:systemd-coredump(8)
--DefaultDependencies=no
--
--[Socket]
--ListenSequentialPacket=/run/systemd/coredump
--SocketMode=0600
--Accept=yes
--MaxConnections=16
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to