Remove fork() for the lttng view spawn viewer
authorDavid Goulet <dgoulet@efficios.com>
Wed, 8 Feb 2012 20:22:39 +0000 (15:22 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 8 Feb 2012 20:22:39 +0000 (15:22 -0500)
We can now ctrl+c the viewer :). The fork() is useless since the command
does nothing else after the exec().

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng/commands/view.c

index aa8d612b57e92825e8217e6452c0a3f378aa9a99..793804b4e9b95ad7ddf9d5c3dcfd510d25fe217b 100644 (file)
@@ -198,7 +198,6 @@ error:
 static int spawn_viewer(const char *trace_path)
 {
        int ret = 0;
-       pid_t pid;
        struct stat status;
        const char *viewer_bin = NULL;
        struct viewers *viewer;
@@ -211,61 +210,53 @@ static int spawn_viewer(const char *trace_path)
                goto error;
        }
 
-       pid = fork();
-       if (pid == 0) {
-               switch (viewer->type) {
-               case VIEWER_BABELTRACE:
-                       if (stat(babeltrace_bin, &status) == 0) {
-                               viewer_bin = babeltrace_bin;
-                       } else {
-                               viewer_bin = viewer->exec_name;
-                       }
-                       argv = alloc_argv_from_local_opts(babeltrace_opts,
-                                       ARRAY_SIZE(babeltrace_opts), trace_path);
-                       break;
+       switch (viewer->type) {
+       case VIEWER_BABELTRACE:
+               if (stat(babeltrace_bin, &status) == 0) {
+                       viewer_bin = babeltrace_bin;
+               } else {
+                       viewer_bin = viewer->exec_name;
+               }
+               argv = alloc_argv_from_local_opts(babeltrace_opts,
+                               ARRAY_SIZE(babeltrace_opts), trace_path);
+               break;
 #if 0
-               case VIEWER_LTTV_GUI:
-                       if (stat(lttv_gui_bin, &status) == 0) {
-                               viewer_bin = lttv_gui_bin;
-                       } else {
-                               viewer_bin = viewer->exec_name;
-                       }
-                       argv = alloc_argv_from_local_opts(lttv_gui_opts,
-                                       ARRAY_SIZE(lttv_gui_opts), trace_path);
-                       break;
+       case VIEWER_LTTV_GUI:
+               if (stat(lttv_gui_bin, &status) == 0) {
+                       viewer_bin = lttv_gui_bin;
+               } else {
+                       viewer_bin = viewer->exec_name;
+               }
+               argv = alloc_argv_from_local_opts(lttv_gui_opts,
+                               ARRAY_SIZE(lttv_gui_opts), trace_path);
+               break;
 #endif
-               case VIEWER_USER_DEFINED:
-                       argv = alloc_argv_from_user_opts(opt_viewer, trace_path);
-                       if (argv) {
-                               viewer_bin = argv[0];
-                       }
-                       break;
-               default:
-                       viewer_bin = viewers[VIEWER_BABELTRACE].exec_name;
-                       argv = alloc_argv_from_local_opts(babeltrace_opts,
-                                       ARRAY_SIZE(babeltrace_opts), trace_path);
-                       break;
+       case VIEWER_USER_DEFINED:
+               argv = alloc_argv_from_user_opts(opt_viewer, trace_path);
+               if (argv) {
+                       viewer_bin = argv[0];
                }
+               break;
+       default:
+               viewer_bin = viewers[VIEWER_BABELTRACE].exec_name;
+               argv = alloc_argv_from_local_opts(babeltrace_opts,
+                               ARRAY_SIZE(babeltrace_opts), trace_path);
+               break;
+       }
 
-               if (argv == NULL) {
-                       ret = CMD_FATAL;
-                       goto error;
-               }
+       if (argv == NULL) {
+               ret = CMD_FATAL;
+               goto error;
+       }
 
-               DBG("Using %s viewer", viewer_bin);
+       DBG("Using %s viewer", viewer_bin);
 
-               ret = execvp(viewer_bin, argv);
-               if (ret) {
-                       PERROR("exec: %s", viewer_bin);
-                       free(argv);
-                       ret = CMD_FATAL;
-                       goto error;
-               }
-       } else if (pid > 0) {
-               ret = CMD_SUCCESS;
-       } else {
-               PERROR("Fork trace viewer");
+       ret = execvp(viewer_bin, argv);
+       if (ret) {
+               PERROR("exec: %s", viewer_bin);
+               free(argv);
                ret = CMD_FATAL;
+               goto error;
        }
 
 error:
This page took 0.027348 seconds and 4 git commands to generate.