X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafm-run.c;h=18824f94030c74c9adfe24d8f04f597e8143e673;hb=4cd8d99ab22ab339d54203bf977648af71d91499;hp=91e2a0bcf8a92e836333f9e788c008a805be4d21;hpb=f4f91abe09bd0d3a4bc9bc06b073f1acbd374786;p=src%2Fapp-framework-main.git diff --git a/src/afm-run.c b/src/afm-run.c index 91e2a0b..18824f9 100644 --- a/src/afm-run.c +++ b/src/afm-run.c @@ -1,5 +1,5 @@ /* - Copyright 2015 IoT.bzh + Copyright 2015, 2016 IoT.bzh author: José Bollo @@ -16,6 +16,8 @@ limitations under the License. */ +#define _GNU_SOURCE + #include #include #include @@ -27,7 +29,14 @@ #include #include -#include +#include +#if SIMULATE_LIBSMACK +#include "simulation/smack.h" +#else +#include +#endif + +#include #include "verbose.h" #include "utils-dir.h" @@ -95,6 +104,7 @@ static int runnerid = 0; * home directory of the user. */ static const char fwk_user_app_dir[] = FWK_USER_APP_DIR; +static const char fwk_user_app_label[] = FWK_USER_APP_DIR_LABEL; /* * Path of the root directory for applications of the @@ -388,18 +398,18 @@ static int fill_launch_desc(struct json_object *appli, return -1; } - /* plugins */ + /* bindings */ { /* TODO */ static const char *null = NULL; - desc->plugins = &null; + desc->bindings = &null; } /* finaly */ desc->home = homeappdir; desc->mode = mode; return 0; -}; +} /**************** report state of runner *********************/ @@ -613,7 +623,6 @@ struct json_object *afm_run_state(int runid) int afm_run_init() { char buf[2048]; - char dir[PATH_MAX]; int rc; uid_t me; struct passwd passwd, *pw; @@ -632,25 +641,34 @@ int afm_run_init() ERROR("getpwuid_r failed for uid=%d: %m",(int)me); return -1; } - rc = snprintf(dir, sizeof dir, "%s/%s", passwd.pw_dir, - fwk_user_app_dir); - if (rc >= sizeof dir) { - ERROR("buffer overflow in user_app_dir for uid=%d",(int)me); + rc = asprintf(&homeappdir, "%s/%s", passwd.pw_dir, fwk_user_app_dir); + if (rc < 0) { + errno = ENOMEM; + ERROR("allocating homeappdir for uid=%d failed", (int)me); return -1; } - rc = create_directory(dir, 0755, 1); + rc = create_directory(homeappdir, 0755, 1); if (rc && errno != EEXIST) { - ERROR("creation of directory %s failed in user_app_dir: %m", - dir); + ERROR("creation of directory %s failed: %m", homeappdir); + free(homeappdir); return -1; } - homeappdir = strdup(dir); - if (homeappdir == NULL) { - errno = ENOMEM; - ERROR("out of memory in user_app_dir for %s : %m", dir); + rc = smack_remove_label_for_path(homeappdir, + XATTR_NAME_SMACKTRANSMUTE, 0); + if (rc < 0 && errno != ENODATA) { + ERROR("can't remove smack transmutation of directory %s: %m", + homeappdir); + free(homeappdir); + return -1; + } + rc = smack_set_label_for_path(homeappdir, XATTR_NAME_SMACK, 0, + fwk_user_app_label); + if (rc < 0) { + ERROR("can't set smack label %s to directory %s: %m", + fwk_user_app_label, homeappdir); + free(homeappdir); return -1; } - /* install signal handlers */ siga.sa_flags = SA_SIGINFO | SA_NOCLDWAIT; sigemptyset(&siga.sa_mask);