Adds 2017 to copyrights
[src/app-framework-main.git] / src / afm-launch.c
index 237a7ed..bb528e5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- Copyright 2015, 2016 IoT.bzh
+ Copyright 2015, 2016, 2017 IoT.bzh
 
  author: José Bollo <jose.bollo@iot.bzh>
 
@@ -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
@@ -669,7 +671,7 @@ static pid_t launch(
 )
 {
        int rc;
-       char **args;
+       char **args, **env;
        pid_t pid;
        int rpipe[2];
        struct pollfd pfd;
@@ -684,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;
@@ -701,6 +707,7 @@ static pid_t launch(
                close(rpipe[0]);
                close(rpipe[1]);
                free(args);
+               free(env);
                ERROR("master fork failed: %m");
                return -1;
        }
@@ -710,6 +717,7 @@ static pid_t launch(
 
                close(rpipe[1]);
                free(args);
+               free(env);
                pfd.fd = rpipe[0];
                pfd.events = POLLIN;
 
@@ -759,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;
@@ -848,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;
 }
@@ -934,8 +942,13 @@ int afm_launch_initialize()
        else
                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;
 }