main: log the command line
authorPekka Paalanen <pekka.paalanen@collabora.co.uk>
Thu, 11 Feb 2016 12:42:21 +0000 (14:42 +0200)
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>
Thu, 23 Jun 2016 15:14:36 +0000 (18:14 +0300)
Write the command line to the log to aid debugging. It needs to be
copied before parsing, because parsing mutates argv.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
compositor/main.c

index ec3d799..6f713c3 100644 (file)
@@ -1524,9 +1524,30 @@ load_backend(struct weston_compositor *compositor, const char *backend,
        return -1;
 }
 
+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[])
 {
        int ret = EXIT_FAILURE;
+       char *cmdline;
        struct wl_display *display;
        struct weston_compositor *ec;
        struct wl_event_source *signals[4];
@@ -1564,13 +1585,18 @@ int main(int argc, char *argv[])
                { WESTON_OPTION_STRING, "config", 'c', &config_file },
        };
 
+       cmdline = copy_command_line(argc, argv);
        parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
 
-       if (help)
+       if (help) {
+               free(cmdline);
                usage(EXIT_SUCCESS);
+       }
 
        if (version) {
                printf(PACKAGE_STRING "\n");
+               free(cmdline);
+
                return EXIT_SUCCESS;
        }
 
@@ -1583,6 +1609,8 @@ int main(int argc, char *argv[])
                   STAMP_SPACE "Build: %s\n",
                   PACKAGE_STRING, PACKAGE_URL, PACKAGE_BUGREPORT,
                   BUILD_ID);
+       weston_log("Command line: %s\n", cmdline);
+       free(cmdline);
        log_uname();
 
        verify_xdg_runtime_dir();