chiark / gitweb /
Prep v239: Add new user-runtime-dir main() function as user_runtime_dir().
authorSven Eden <yamakuzure@gmx.net>
Wed, 29 Aug 2018 06:33:20 +0000 (08:33 +0200)
committerSven Eden <yamakuzure@gmx.net>
Wed, 29 Aug 2018 06:33:20 +0000 (08:33 +0200)
src/login/meson.build
src/login/user-runtime-dir.c
src/login/user-runtime-dir.h [new file with mode: 0644]

index 2ead576655ac8ca4997b5f1b643744790307cae8..0eac0d3ccbbd4f8a386cb4878cdfdc6a6d42641a 100644 (file)
@@ -50,6 +50,7 @@ liblogind_core_sources = files('''
 liblogind_core_sources += [files('''
         elogind-dbus.c
         elogind-dbus.h
+        user-runtime-dir.c
 '''.split()),
         libcore_la_sources,
         sleep_files,
@@ -86,7 +87,7 @@ loginctl_sources = files('''
 # '''.split())
 #endif // 0
 
-#if 1 /// elogind has some additional files:
+#if 1 /// elogind has and needs some additional files:
 loginctl_sources += files('''
         eloginctl.c
         eloginctl.h
index 8f38e58a9672c964ace425d144f50871b0ed407f..3cd5afee3fcb7633f9d422be36ca7ad859ee8678 100644 (file)
@@ -1,21 +1,24 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
-//#include <stdint.h>
-//#include <sys/mount.h>
+#include <stdint.h>
+#include <sys/mount.h>
 
-//#include "fs-util.h"
-//#include "label.h"
+#include "fs-util.h"
+#include "label.h"
 //#include "logind.h"
-//#include "mkdir.h"
-//#include "mount-util.h"
-//#include "path-util.h"
-//#include "rm-rf.h"
-//#include "smack-util.h"
-//#include "stdio-util.h"
-//#include "string-util.h"
-//#include "strv.h"
-//#include "user-util.h"
-
+#include "mkdir.h"
+#include "mount-util.h"
+#include "path-util.h"
+#include "rm-rf.h"
+#include "smack-util.h"
+#include "stdio-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "user-util.h"
+/// Additional includes needed by elogind
+#include "user-runtime-dir.h"
+
+#if 0 /// UNNEEDED by elogind
 static int gather_configuration(size_t *runtime_dir_size) {
         Manager m = {};
         int r;
@@ -29,6 +32,7 @@ static int gather_configuration(size_t *runtime_dir_size) {
         *runtime_dir_size = m.runtime_dir_size;
         return 0;
 }
+#endif // 0
 
 static int user_mkdir_runtime_path(const char *runtime_path, uid_t uid, gid_t gid, size_t runtime_dir_size) {
         int r;
@@ -111,10 +115,14 @@ static int user_remove_runtime_path(const char *runtime_path) {
         return r;
 }
 
+#if 0 /// having a User instance, elogind can ask its manager directly.
 static int do_mount(const char *runtime_path, uid_t uid, gid_t gid) {
         size_t runtime_dir_size;
 
         assert_se(gather_configuration(&runtime_dir_size) == 0);
+#else
+static int do_mount(const char *runtime_path, size_t runtime_dir_size, uid_t uid, gid_t gid) {
+#endif // 0
 
         log_debug("Will mount %s owned by "UID_FMT":"GID_FMT, runtime_path, uid, gid);
         return user_mkdir_runtime_path(runtime_path, uid, gid, runtime_dir_size);
@@ -125,6 +133,7 @@ static int do_umount(const char *runtime_path) {
         return user_remove_runtime_path(runtime_path);
 }
 
+#if 0 /// elogind does this internally as we have no unit chain being init.
 int main(int argc, char *argv[]) {
         const char *user;
         uid_t uid;
@@ -156,7 +165,6 @@ int main(int argc, char *argv[]) {
                                 user);
                 return EXIT_FAILURE;
         }
-
         xsprintf(runtime_path, "/run/user/" UID_FMT, uid);
 
         if (streq(argv[1], "start"))
@@ -168,3 +176,21 @@ int main(int argc, char *argv[]) {
 
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }
+#else
+int user_runtime_dir(const char *verb, User *u) {
+        int r;
+
+        assert_se(verb);
+        assert_se(u);
+        assert_se(u->manager);
+        
+        if (streq(verb, "start"))
+                r = do_mount(u->runtime_path, u->manager->runtime_dir_size, u->uid, u->gid);
+        else if (streq(verb, "stop"))
+                r = do_umount(u->runtime_path);
+        else
+                assert_not_reached("Unknown verb!");
+
+        return r;
+}
+#endif // 0
diff --git a/src/login/user-runtime-dir.h b/src/login/user-runtime-dir.h
new file mode 100644 (file)
index 0000000..7cef5f4
--- /dev/null
@@ -0,0 +1,28 @@
+#pragma once
+#ifndef ELOGIND_SRC_LOGIN_USER_RUNTIME_DIR_H_INCLUDED
+#define ELOGIND_SRC_LOGIN_USER_RUNTIME_DIR_H_INCLUDED
+
+/***
+  This file is part of elogind.
+
+  Copyright 2017 Sven Eden
+
+  elogind 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.
+
+  elogind is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with elogind; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "logind.h"
+
+int user_runtime_dir(const char *verb, User *u);
+
+#endif // ELOGIND_SRC_LOGIN_USER_RUNTIME_DIR_H_INCLUDED