X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafm-launch.c;h=839194340389e7f8e2c1bb9489cfb59246c6f43e;hb=6f6d04fef9f08d756a37d17333f5b9b9a6b72dd2;hp=13f2bf9f3aab90ca78f8dd2d019c11d11afdb960;hpb=dc4d29d0b8c3393ab8ba85b6278fd231b1191509;p=src%2Fapp-framework-main.git diff --git a/src/afm-launch.c b/src/afm-launch.c index 13f2bf9..8391943 100644 --- a/src/afm-launch.c +++ b/src/afm-launch.c @@ -1,5 +1,5 @@ /* - Copyright 2015 IoT.bzh + Copyright 2015, 2016 IoT.bzh author: José Bollo @@ -109,6 +109,7 @@ static const char readystr[] = "READY=1"; */ static const int ready_timeout = 1500; +#if defined(DUMP_LAUNCHERS) /* * dump all the known launchers to the 'file' */ @@ -132,6 +133,7 @@ static void dump_launchers(FILE *file) fprintf(file, "\n"); } } +#endif /* * update 'cread' to point the the next token @@ -141,8 +143,8 @@ static void dump_launchers(FILE *file) static int next_token(struct confread *cread) { int idx = cread->index + cread->length; - cread->index = idx + strspn(&cread->buffer[idx], separators); - cread->length = strcspn(&cread->buffer[cread->index], separators); + cread->index = idx + (int)strspn(&cread->buffer[idx], separators); + cread->length = (int)strcspn(&cread->buffer[cread->index], separators); return cread->length; } @@ -156,11 +158,11 @@ static int read_line(struct confread *cread) { while (fgets(cread->buffer, sizeof cread->buffer, cread->file) != NULL) { cread->lineno++; - cread->index = strspn(cread->buffer, separators); + cread->index = (int)strspn(cread->buffer, separators); if (cread->buffer[cread->index] && cread->buffer[cread->index] != '#') { - cread->length = strcspn(&cread->buffer[cread->index], - separators); + cread->length = (int)strcspn( + &cread->buffer[cread->index], separators); assert(cread->length > 0); return cread->length; } @@ -183,7 +185,7 @@ static const char **read_vector(struct confread *cread) int index0, length0; const char **vector; char *args; - int count, length; + unsigned count, length; /* record origin */ index0 = cread->index; @@ -194,7 +196,7 @@ static const char **read_vector(struct confread *cread) length = 0; while(cread->length) { count++; - length += cread->length; + length += (unsigned)cread->length; next_token(cread); } @@ -210,7 +212,8 @@ static const char **read_vector(struct confread *cread) count = 0; while(cread->length) { vector[count++] = args; - memcpy(args, &cread->buffer[cread->index], cread->length); + memcpy(args, &cread->buffer[cread->index], + (unsigned)cread->length); args += cread->length; *args++ = 0; next_token(cread); @@ -247,7 +250,7 @@ static struct type_list *read_type(struct confread *cread) } /* allocate structure */ - result = malloc(sizeof(struct type_list) + length); + result = malloc(sizeof(struct type_list) + (unsigned)length); if (result == NULL) { ERROR("%s:%d: out of memory", cread->filepath, cread->lineno); errno = ENOMEM; @@ -255,7 +258,7 @@ static struct type_list *read_type(struct confread *cread) } /* fill the structure */ - memcpy(result->type, &cread->buffer[index], length); + memcpy(result->type, &cread->buffer[index], (unsigned)length); result->type[length] = 0; return result; } @@ -486,6 +489,7 @@ static int mkport() /* %% % %a appid desc->appid +%b bindings desc->bindings %c content desc->content %D datadir params->datadir %H height desc->height @@ -493,7 +497,6 @@ static int mkport() %I icondir FWK_ICON_DIR %m mime-type desc->type %n name desc->name -%p plugins desc->plugins %P port params->port %r rootdir desc->path %R readyfd params->readyfd @@ -531,7 +534,7 @@ static union arguments instantiate_arguments( const char * const *iter; const char *p, *v; char *data, c, sep; - int n, s; + unsigned n, s; union arguments result; char port[20], width[20], height[20], readyfd[20], mini[3]; @@ -570,6 +573,9 @@ static union arguments instantiate_arguments( c = *p++; switch (c) { case 'a': v = desc->appid; break; + case 'b': + v = "" /*TODO:desc->bindings*/; + break; case 'c': v = desc->content; break; case 'D': v = params->datadir; break; case 'H': @@ -588,9 +594,6 @@ static union arguments instantiate_arguments( params->port); v = port; break; - case 'p': - v = "" /*TODO:desc->plugins*/; - break; case 'R': if(!data) sprintf(readyfd, "%d", @@ -615,7 +618,7 @@ static union arguments instantiate_arguments( if (data) data = stpcpy(data, v); else - s += strlen(v); + s += (unsigned)strlen(v); } } /* terminate the argument */ @@ -668,7 +671,7 @@ static pid_t launch( ) { int rc; - char **args; + char **args, **env; pid_t pid; int rpipe[2]; struct pollfd pfd; @@ -683,9 +686,13 @@ static pid_t launch( /* instanciate the arguments */ params->readyfd = rpipe[1]; args = instantiate_arguments(exec->args, desc, params, 1).vector; - if (args == NULL) { + env = instantiate_arguments((const char * const*)environ, + desc, params, 1).vector; + if (args == NULL || env == NULL) { close(rpipe[0]); close(rpipe[1]); + free(args); + free(env); ERROR("out of memory in master"); errno = ENOMEM; return -1; @@ -700,6 +707,7 @@ static pid_t launch( close(rpipe[0]); close(rpipe[1]); free(args); + free(env); ERROR("master fork failed: %m"); return -1; } @@ -709,6 +717,7 @@ static pid_t launch( close(rpipe[1]); free(args); + free(env); pfd.fd = rpipe[0]; pfd.events = POLLIN; @@ -758,7 +767,7 @@ static pid_t launch( } /* executes the process */ - rc = execve(args[0], args, environ); + rc = execve(args[0], args, env); ERROR("failed to exec master %s: %m", args[0]); _exit(1); return -1; @@ -847,7 +856,7 @@ static struct desc_launcher *search_launcher(const char *type, for (dl = launchers ; dl ; dl = dl->next) if (dl->mode == mode) for (tl = dl->types ; tl != NULL ; tl = tl->next) - if (!strcmp(tl->type, type)) + if (!strcasecmp(tl->type, type)) return dl; return NULL; } @@ -891,7 +900,7 @@ int afm_launch(struct afm_launch_desc *desc, pid_t children[2], char **uri) /* prepare paths */ rc = snprintf(datadir, sizeof datadir, "%s/%s", desc->home, desc->appid); - if (rc < 0 || rc >= sizeof datadir) { + if (rc < 0 || rc >= (int)sizeof datadir) { ERROR("overflow for datadir"); errno = EINVAL; return -1; @@ -931,10 +940,15 @@ int afm_launch_initialize() if (s && s != e) groupid = s; /* the original groupid is used */ else - groupid = -1; + groupid = (gid_t)-1; + /* reads the configuration file */ rc = read_configuration_file(FWK_LAUNCH_CONF); - /* dump_launchers(stderr); */ +#if defined(DUMP_LAUNCHERS) + if (!rc) + dump_launchers(stderr); +#endif + return rc; }