summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINSUN PYO <insun.pyo@samsung.com>2018-08-17 17:20:57 +0900
committerINSUN PYO <insun.pyo@samsung.com>2018-08-24 13:21:18 +0900
commit50edceef0dae5772a8a485dad60e3a964fd92525 (patch)
tree15b6350d6141cc23a85931e4e28a160434c38209
parent57c273eb9592f85f6f8b50ce13742e4cab29d1ab (diff)
downloadsystem-plugin-50edceef0dae5772a8a485dad60e3a964fd92525.tar.gz
system-plugin-50edceef0dae5772a8a485dad60e3a964fd92525.tar.bz2
system-plugin-50edceef0dae5772a8a485dad60e3a964fd92525.zip
Signed-off-by: INSUN PYO <insun.pyo@samsung.com> Change-Id: I03965070c0b486c05506708b0911af9db434619a
-rw-r--r--CMakeLists.txt3
-rw-r--r--packaging/system-plugin.spec38
-rw-r--r--src/session-bind/CMakeLists.txt16
-rw-r--r--src/session-bind/session-bind.c48
-rw-r--r--units/session-bind.service13
5 files changed, 114 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..e339888
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,3 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 3.9.4)
+
+ADD_SUBDIRECTORY(src/session-bind)
diff --git a/packaging/system-plugin.spec b/packaging/system-plugin.spec
index 5936bda..66b3540 100644
--- a/packaging/system-plugin.spec
+++ b/packaging/system-plugin.spec
@@ -1,6 +1,3 @@
-#%define _unpackaged_files_terminate_build 0
-#%define debug_package %{nil}
-
Name: system-plugin
Summary: Target specific system configuration files
Version: 0.1
@@ -12,7 +9,9 @@ Source1: %{name}.manifest
Requires(post): /usr/bin/systemctl
Requires(post): /usr/bin/udevadm
+BuildRequires: cmake
BuildRequires: pkgconfig(libsystemd)
+BuildRequires: pkgconfig(libtzplatform-config)
%description
This package provides target specific system configuration files.
@@ -92,6 +91,13 @@ BuildArch: noarch
%description feature-namespace
This package provides namespace separation of user sessions.
+%package feature-session-bind
+Summary: System utils for mounting user session contents
+Requires: %{name} = %{version}-%{release}
+
+%description feature-session-bind
+This package provides a mount utils for user sessions.
+
%package config-env-headless
Summary: System configuration files for headless images
Requires: %{name} = %{version}-%{release}
@@ -134,12 +140,14 @@ This package provides configuration files for /etc/fstab(remount) and resize2fs@
%prep
%setup -q
+cp %{SOURCE1} .
%build
-cp %{SOURCE1} .
+%cmake .
%install
rm -rf %{buildroot}
+%{make_install}
mkdir -p %{buildroot}%{_unitdir}
mkdir -p %{buildroot}%{_userunitdir}
@@ -218,6 +226,11 @@ ln -s ../wait-mount@.service %{buildroot}%{_userunitdir}/basic.target.wants/wait
mkdir -p %{buildroot}%{_unitdir}/user@.service.d
install -m 644 units/namespace.conf %{buildroot}%{_unitdir}/user@.service.d/
+# session-bind
+mkdir -p %{buildroot}%{_userunitdir}/basic.target.wants
+install -m 644 units/session-bind.service %{buildroot}%{_userunitdir}
+ln -s ../session-bind.service %{buildroot}%{_userunitdir}/basic.target.wants/session-bind.service
+
%clean
rm -rf %{buildroot}
@@ -313,6 +326,23 @@ rm -f %{_sbindir}/e4crypt
%license LICENSE.Apache-2.0
%{_unitdir}/user@.service.d/namespace.conf
+%files feature-session-bind
+%manifest %{name}.manifest
+%license LICENSE.Apache-2.0
+%{_bindir}/session-bind
+%{_userunitdir}/session-bind.service
+%{_userunitdir}/basic.target.wants/session-bind.service
+
+%post feature-session-bind
+echo ""
+echo "------------------------------------------------------------------------"
+echo "When you install this system-plugin-feature-session-bind rpm separately,"
+echo "you are required to execute this command"
+echo ""
+echo "root#) setcap cap_sys_admin=ei /usr/bin/session-bind"
+echo "------------------------------------------------------------------------"
+echo ""
+
%files config-env-headless
%manifest %{name}.manifest
%license LICENSE.Apache-2.0
diff --git a/src/session-bind/CMakeLists.txt b/src/session-bind/CMakeLists.txt
new file mode 100644
index 0000000..dddfd25
--- /dev/null
+++ b/src/session-bind/CMakeLists.txt
@@ -0,0 +1,16 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 3.9.4)
+PROJECT(session-bind C)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED libtzplatform-config)
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
+
+ADD_EXECUTABLE(${PROJECT_NAME} session-bind.c)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -pie)
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
diff --git a/src/session-bind/session-bind.c b/src/session-bind/session-bind.c
new file mode 100644
index 0000000..30a2ae7
--- /dev/null
+++ b/src/session-bind/session-bind.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <sys/mount.h>
+#include <tzplatform_config.h>
+
+// For compatibility, Using hard-coded path
+#define LEGACY_APPS_DIR "/opt/usr/apps"
+#define LEGACY_CONTENTS_DIR "/opt/usr/media"
+
+int main(int argc, char *argv[])
+{
+ int r;
+ const char *user_app;
+ const char *user_content;
+
+ user_app = tzplatform_getenv(TZ_USER_APP);
+ r = mount(user_app, LEGACY_APPS_DIR, NULL, MS_BIND, NULL);
+ if (r < 0) {
+ fprintf(stderr, "user app bind mount failed - %d\n", errno);
+ return r;
+ }
+
+ user_content = tzplatform_getenv(TZ_USER_CONTENT);
+ r = mount(user_content, LEGACY_CONTENTS_DIR, NULL, MS_BIND, NULL);
+ if (r < 0) {
+ fprintf(stderr, "user content bind mount failed - %d\n", errno);
+ return r;
+ }
+
+ return 0;
+}
diff --git a/units/session-bind.service b/units/session-bind.service
new file mode 100644
index 0000000..fa96bd9
--- /dev/null
+++ b/units/session-bind.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=User session bind mount for %U
+DefaultDependencies=no
+Wants=wait-mount@opt-usr.service
+After=wait-mount@opt-usr.service
+Before=basic.target
+ConditionPathIsMountPoint=!/opt/usr/apps
+ConditionPathIsMountPoint=!/opt/usr/media
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/usr/bin/session-bind