From d40a25fba4324f08a8ded5a9df6f63be3556f790 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 6 Sep 2018 08:25:31 +0900 Subject: [PATCH] Remove bind-user-contents.service bind-user-contents.service moved to system-plugin-featuer-session-bind package. Signed-off-by: INSUN PYO Change-Id: I1101b985d622f16430a3ff8947daf11c1a3b0da2 --- packaging/session-utils.spec | 4 - src/systemd-user-helper/systemd-user-helper.c | 211 +----------------- units/bind-user-contents.service | 12 - 3 files changed, 6 insertions(+), 221 deletions(-) delete mode 100644 units/bind-user-contents.service diff --git a/packaging/session-utils.spec b/packaging/session-utils.spec index 078c028..82c35e5 100644 --- a/packaging/session-utils.spec +++ b/packaging/session-utils.spec @@ -29,8 +29,6 @@ rm -rf %{buildroot} %make_install mkdir -p %{buildroot}%{_userunitdir}/basic.target.wants -install -m 644 units/bind-user-contents.service %{buildroot}%{_userunitdir}/ -ln -sf ../bind-user-contents.service %{buildroot}%{_userunitdir}/basic.target.wants/bind-user-contents.service install -m 644 units/container_postprocess.service %{buildroot}%{_userunitdir}/ #ln -sf ../container_postprocess.service %{buildroot}%{_userunitdir}/basic.target.wants/container_postprocess.service @@ -38,8 +36,6 @@ install -m 644 units/container_postprocess.service %{buildroot}%{_userunitdir}/ %license LICENSE.Apache-2.0 %manifest session-utils.manifest %{_bindir}/systemd-user-helper -%{_userunitdir}/bind-user-contents.service -%{_userunitdir}/basic.target.wants/bind-user-contents.service %{_userunitdir}/container_postprocess.service #%{_userunitdir}/basic.target.wants/container_postprocess.service diff --git a/src/systemd-user-helper/systemd-user-helper.c b/src/systemd-user-helper/systemd-user-helper.c index 6531447..763d5c0 100644 --- a/src/systemd-user-helper/systemd-user-helper.c +++ b/src/systemd-user-helper/systemd-user-helper.c @@ -27,29 +27,9 @@ #include #include #include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include -#include #include -#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) -#define PIDFILE_PATH ".systemd.pid" -// For compatibility, Using hard-coded path -#define LEGACY_CONTENTS_DIR "/opt/usr/media" -#define LEGACY_APPS_DIR "/opt/usr/apps" - -#define LAZYMOUNT_LIB LIBDIR"/liblazymount.so.0" #define CONTAINER_LIB LIBDIR"/security/pam_krate.so" #define LOAD_SYMBOL(handle, sym, name) \ @@ -62,57 +42,15 @@ } \ } while (0); -#define MOUNT_SIZE "10000k" -#define MAX_GRP_BUF_SIZE (1024 * 4) -#define GRP_NAME_SYSTEM_SHARE "system_share" - -static void *container_handle = NULL; - -static const char *systemd_arg[] = { - "/usr/lib/systemd/systemd", - "--user", - NULL -}; - -static int stop_process(char *username) -{ - int r; - - r = umount2(tzplatform_getenv(TZ_USER_CONTENT), MNT_DETACH); - if (r < 0) { - fprintf(stderr, "Warning : Failed to umount user content\n"); - } - - r = umount2(tzplatform_getenv(TZ_USER_APP), MNT_DETACH); - if (r < 0) { - fprintf(stderr, "Warning : Failed to umount application content\n"); - } - return 0; -} -static int normal_user_postprocess(char *username) +static int container_postprocess(char *username) { int r; - r = mount(tzplatform_getenv(TZ_USER_CONTENT), - LEGACY_CONTENTS_DIR, NULL, MS_BIND, NULL); - if (r < 0) { - fprintf(stderr, "user content bind mount failed - %d\n", errno); - return r; - } - - r = mount(tzplatform_getenv(TZ_USER_APP), - LEGACY_APPS_DIR, NULL, MS_BIND, NULL); - if (r < 0) { - fprintf(stderr, "user app bind mount failed - %d\n", errno); - return r; - } - - return 0; -} + static void *container_handle; + int (*handle_postprocess)(char *); -static int container_open(void) -{ - if (container_handle) + /* not support container */ + if (access(CONTAINER_LIB, F_OK)) return 0; container_handle = dlopen(CONTAINER_LIB, RTLD_LAZY); @@ -120,41 +58,6 @@ static int container_open(void) fprintf(stderr, "container module dlopen error\n"); return -1; } - return 0; -} - -static int container_preprocess(char *username) -{ - int r; - int (*handle_preprocess)(char *); - - r = container_open(); - if (r < 0) - return r; - - LOAD_SYMBOL(container_handle, handle_preprocess, "container_preprocess"); - - r = handle_preprocess(username); - if (r < 0) { - fprintf(stderr, "container module preprocess error\n"); - return r; - } - - return 0; -} - -static int container_postprocess(char *username) -{ - int r; - int (*handle_postprocess)(char *); - - /* not support container */ - if (access(CONTAINER_LIB, F_OK)) - return 0; - - r = container_open(); - if (r < 0) - return r; LOAD_SYMBOL(container_handle, handle_postprocess, "container_postprocess"); @@ -167,84 +70,8 @@ static int container_postprocess(char *username) return 0; } -static int make_pid_file(int pid, char* user_id) -{ - FILE *fp; - char pidpath[PATH_MAX]; - int r = 0; - - snprintf(pidpath, PATH_MAX, "/run/user/%s/%s", user_id, PIDFILE_PATH); - - fp = fopen(pidpath, "w+"); - if (fp != NULL) { - fprintf(fp, "%d", pid); - fclose(fp); - } else - r = -1; - - return r; -} - -static int change_smack_for_user_session() -{ - FILE *fp; - int r = 0; - - fp = fopen("/proc/self/attr/current", "w"); - - if (fp == NULL) { - r = -errno; - return r; - } - r = fputs("User", fp); - if (r == EOF) { - fclose(fp); - r = -errno; - return r; - } - fclose(fp); - - return 0; -} - -int run_child(int argc, const char *argv[], char* user_id) -{ - pid_t pid; - int r = 0; - int i; - - if (!argv) - return -EINVAL; - - pid = fork(); - - if (pid < 0) { - fprintf(stderr, "failed to fork"); - r = -errno; - } else if (pid == 0) { - r = change_smack_for_user_session(); - if (r != 0) { - fprintf(stderr, "failed to change smack\n"); - return r; - } - - for (i = 0; i < _NSIG; ++i) - signal(i, SIG_DFL); - - r = execv(argv[0], (char **)argv); - /* NOT REACH */ - } else{ - make_pid_file(pid, user_id); - r = pid; - } - - return r; -} - int main(int argc, char *argv[]) { - int r = 0; - int support_container = 0; char *operation; char *username; @@ -255,38 +82,12 @@ int main(int argc, char *argv[]) operation = argv[1]; username = argv[2]; - if (strcmp(operation, "stop") == 0) - return stop_process(username); - else if (strcmp(operation, "start") == 0) - ; /* do main code */ - else if (strcmp(operation, "bind-user-contents") == 0) - return normal_user_postprocess(username); - else if (strcmp(operation, "container_postprocess") == 0) + if (strcmp(operation, "container_postprocess") == 0) return container_postprocess(username); else { fprintf(stderr, "option is invalid(%s)\n", operation); return -2; } - /* If container supports below funcs, below line should be enabled. */ - support_container = (access(CONTAINER_LIB, F_OK) == 0) ? 1 : 0; - if (support_container) { - r = container_preprocess(username); - if (r < 0) { - fprintf(stderr, "container preprocess failed\n"); - return r; - } - } - - r = run_child(ARRAY_SIZE(systemd_arg), systemd_arg, username); - if (r < 0) { - fprintf(stderr, "systemd user execution failed\n"); - return r; - } else{ - fprintf(stderr, "success = pid = %d\n", r); - } - return 0; } - - diff --git a/units/bind-user-contents.service b/units/bind-user-contents.service deleted file mode 100644 index 19c21e8..0000000 --- a/units/bind-user-contents.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Bind Mount user contents for UID %U -DefaultDependencies=no -Wants=wait-mount@opt-usr.service -After=wait-mount@opt-usr.service -Before=basic.target -ConditionPathExists=!/usr/bin/session-bind - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/usr/bin/systemd-user-helper bind-user-contents %U -- 2.34.1