File 1006-logind-keep-backward-compatibility-with-UserTasksMax.patch of Package systemd.24852

From 35151e78971d8ebffe244962c98dbfdb3afa5047 Mon Sep 17 00:00:00 2001
From: Franck Bui <fbui@suse.com>
Date: Tue, 6 Nov 2018 11:51:26 +0100
Subject: [PATCH 1/1] logind: keep backward compatibility with UserTasksMax= in
 logind.conf

Since commit 284149392755f086d0a71, UserTasksMax= support has been simply
dropped.

A generator is used to automatically create an appropriate dropin that has the
same effect. However since the snippet is generated in /run, sysadmin is
encouraged to copy it in /etc to make it persistent.

The main advantages to use a generator are:

 - sysadmin is aware of this backward incompatible change

 - he will be the one who will fix logind.conf manually (to remove the use of
   UserTasksMax=)

 - he will decide how to name the snippet and possibly merge it with an
   existing one

Expect this generator to be dropped in the future.
---
 meson.build                            |  8 ++++
 src/login/compat-tasks-max-generator.c | 56 ++++++++++++++++++++++++++
 src/login/logind-core.c                |  2 +
 src/login/logind-gperf.gperf           |  2 +-
 src/login/logind-user.c                | 16 +++++---
 src/login/logind.c                     |  2 +
 src/login/logind.h                     |  3 ++
 7 files changed, 82 insertions(+), 7 deletions(-)
 create mode 100644 src/login/compat-tasks-max-generator.c

diff --git a/meson.build b/meson.build
index cfb9ffdb84..57e3fa9c85 100644
--- a/meson.build
+++ b/meson.build
@@ -2010,6 +2010,14 @@ if conf.get('ENABLE_LOGIND') == 1
                 install_rpath : rootlibexecdir,
                 install : true,
                 install_dir : rootlibexecdir)
+
+        executable('logind-compat-tasks-max-generator',
+                'src/login/compat-tasks-max-generator.c',
+                include_directories : includes,
+                link_with : [libshared, liblogind_core],
+                install_rpath : rootlibexecdir,
+                install : true,
+                install_dir : systemgeneratordir)
 endif
 
 if conf.get('HAVE_PAM') == 1
diff --git a/src/login/compat-tasks-max-generator.c b/src/login/compat-tasks-max-generator.c
new file mode 100644
index 0000000000..2fe1c92ba7
--- /dev/null
+++ b/src/login/compat-tasks-max-generator.c
@@ -0,0 +1,56 @@
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "alloc-util.h"
+#include "dropin.h"
+#include "generator.h"
+#include "logind.h"
+#include "path-util.h"
+
+static int read_manager_configuration(char **user_tasks_max) {
+        Manager m = {};
+        int r;
+
+        manager_reset_config(&m);
+        m.user_tasks_max = NULL;
+
+        r = manager_parse_config_file(&m);
+        if (r < 0)
+                return log_warning_errno(r, "Failed to parse logind.conf: %m");
+
+        if (!m.user_tasks_max)
+                return 0;
+
+        *user_tasks_max = m.user_tasks_max;
+        return 1;
+}
+
+static int run(const char *dest, const char *dest_early, const char *dest_late) {
+        _cleanup_free_ char *p = NULL;
+        char *user_tasks_max;
+        int r = 0;
+
+        umask(0022);
+
+        r = read_manager_configuration(&user_tasks_max);
+        if (r == 0)
+                return EXIT_SUCCESS;
+        if (r < 0)
+                return EXIT_FAILURE;
+
+        p = path_join(dest, "user-.slice.d", "50-limits.conf");
+        if (!p)
+                return EXIT_FAILURE;
+
+        log_warning("Creating %s to keep compatibility\n"
+                    "Please copy the snippet in /etc/systemd/system/user-.slice.d/ and remove any uses of UserTasksMax=\n", p);
+
+        r = write_drop_in_format(dest, "user-.slice", 50, "limits",
+                                 "# Automatically generated by logind-compat-tasks-max-generator\n\n"
+                                 "[Slice]\nTasksMax=%s", user_tasks_max);
+
+        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+}
+
+DEFINE_MAIN_GENERATOR_FUNCTION(run);
diff --git a/src/login/logind-core.c b/src/login/logind-core.c
index 480ec1927b..743ed577aa 100644
--- a/src/login/logind-core.c
+++ b/src/login/logind-core.c
@@ -50,6 +50,8 @@ void manager_reset_config(Manager *m) {
 
         m->holdoff_timeout_usec = 30 * USEC_PER_SEC;
 
+        m->user_tasks_max = mfree(m->user_tasks_max);
+
         m->idle_action_usec = 30 * USEC_PER_MINUTE;
         m->idle_action = HANDLE_IGNORE;
 
diff --git a/src/login/logind-gperf.gperf b/src/login/logind-gperf.gperf
index 73d96ff436..8173ea559e 100644
--- a/src/login/logind-gperf.gperf
+++ b/src/login/logind-gperf.gperf
@@ -42,4 +42,4 @@ Login.RuntimeDirectoryInodesMax,    config_parse_uint64,                0, offse
 Login.RemoveIPC,                    config_parse_bool,                  0, offsetof(Manager, remove_ipc)
 Login.InhibitorsMax,                config_parse_uint64,                0, offsetof(Manager, inhibitors_max)
 Login.SessionsMax,                  config_parse_uint64,                0, offsetof(Manager, sessions_max)
-Login.UserTasksMax,                 config_parse_compat_user_tasks_max, 0, 0
+Login.UserTasksMax,                 config_parse_compat_user_tasks_max, 0, offsetof(Manager, user_tasks_max)
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index 9ceb33cde9..9afa836e0d 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -941,16 +941,20 @@ int config_parse_compat_user_tasks_max(
                 void *data,
                 void *userdata) {
 
+        char **m = data;
+        int r;
+
         assert(filename);
         assert(lvalue);
         assert(rvalue);
 
-        log_syntax(unit, LOG_NOTICE, filename, line, 0,
-                   "Support for option %s= has been removed.",
+        log_syntax(unit, LOG_WARNING, filename, line, 0,
+                   "Support for option %s= is deprecated and will be removed.",
                    lvalue);
-        log_info("Hint: try creating /etc/systemd/system/user-.slice.d/50-limits.conf with:\n"
-                 "        [Slice]\n"
-                 "        TasksMax=%s",
-                 rvalue);
+
+        r = free_and_strdup(m, rvalue);
+        if (r < 0)
+                return log_oom();
+
         return 0;
 }
diff --git a/src/login/logind.c b/src/login/logind.c
index c50a083b03..d487f4a568 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -163,6 +163,8 @@ static Manager* manager_unref(Manager *m) {
         strv_free(m->kill_only_users);
         strv_free(m->kill_exclude_users);
 
+        free(m->user_tasks_max);
+
         free(m->scheduled_shutdown_type);
         free(m->scheduled_shutdown_tty);
         free(m->wall_message);
diff --git a/src/login/logind.h b/src/login/logind.h
index 272fcfecd4..2a9adf65fa 100644
--- a/src/login/logind.h
+++ b/src/login/logind.h
@@ -122,6 +122,9 @@ struct Manager {
 
         uint64_t runtime_dir_size;
         uint64_t runtime_dir_inodes;
+
+        char *user_tasks_max;
+
         uint64_t sessions_max;
         uint64_t inhibitors_max;
 
-- 
2.26.2

openSUSE Build Service is sponsored by