main: Copy cmd line args and print them 82/26282/1
authorMarius Vlad <marius.vlad@collabora.com>
Tue, 20 Apr 2021 11:19:08 +0000 (14:19 +0300)
committerMarius Vlad <marius.vlad@collabora.com>
Tue, 20 Apr 2021 12:51:50 +0000 (15:51 +0300)
This makes it really easy to spot on what arguments have been passed to
the compositor. When a test client will run the compositor this will be
helpful to verify that we pass the correct arguments.

Fixes a small typo along the way.

Bug-AGL: SPEC-3880

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Change-Id: Ia4198ce6bff465f479cf9a0a87c17998c5548868

src/main.c

index 5605841..126b938 100644 (file)
@@ -1520,8 +1520,9 @@ usage(int error_code)
                "Usage: agl-compositor [OPTIONS]\n"
                "\n"
                "This is " PACKAGE_STRING ", the reference compositor for\n"
-               "Automotive Grade Linux. Weston-ivi supports multiple backends, and depending\n"
-               "on which backend is in use different options will be accepted.\n"
+               "Automotive Grade Linux. " PACKAGE_STRING " supports multiple "
+               "backends,\nand depending on which backend is in use different "
+               "options will be accepted.\n"
                "\n"
                "Core options:\n"
                "\n"
@@ -1541,9 +1542,30 @@ usage(int error_code)
        exit(error_code);
 }
 
+static char *
+copy_command_line(int argc, char * const argv[])
+{
+       FILE *fp;
+       char *str = NULL;
+       size_t size = 0;
+       int i;
+
+       fp = open_memstream(&str, &size);
+       if (!fp)
+               return NULL;
+
+       fprintf(fp, "%s", argv[0]);
+       for (i = 1; i < argc; i++)
+               fprintf(fp, " %s", argv[i]);
+       fclose(fp);
+
+       return str;
+}
+
 int main(int argc, char *argv[])
 {
        struct ivi_compositor ivi = { 0 };
+       char *cmdline;
        struct wl_display *display = NULL;
        struct wl_event_loop *loop;
        struct wl_event_source *signals[3] = { 0 };
@@ -1588,6 +1610,7 @@ int main(int argc, char *argv[])
        /* Prevent any clients we spawn getting our stdin */
        os_fd_set_cloexec(STDIN_FILENO);
 
+       cmdline = copy_command_line(argc, argv);
        parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
 
        if (help)
@@ -1614,6 +1637,9 @@ int main(int argc, char *argv[])
        logger = weston_log_subscriber_create_log(logfile);
        weston_log_subscribe(log_ctx, logger, "log");
 
+       weston_log("Command line: %s\n", cmdline);
+       free(cmdline);
+
        if (load_config(&ivi.config, no_config, config_file) < 0)
                goto error_signals;
        section = weston_config_get_section(ivi.config, "core", NULL, NULL);