+
+
+
+int lttctl_daemon_hybrid_finish(struct lttctl_handle *handle, char *trace_name)
+{
+ char channel_path[PATH_MAX] = "";
+ pid_t pid;
+ int ret;
+ char *lttd_path = getenv("LTT_DAEMON");
+
+ if(lttd_path == NULL) lttd_path =
+ PACKAGE_BIN_DIR "/lttd";
+
+ strcat(channel_path, channel_root);
+ strcat(channel_path, "/");
+ strcat(channel_path, trace_name);
+
+
+ ret = lttctl_stop(handle, trace_name);
+ if(ret != 0) goto stop_error;
+
+ pid = fork();
+
+ if(pid > 0) {
+ int status = 0;
+ /* parent */
+
+ ret = waitpid(pid, &status, 0);
+ if(ret == -1) {
+ ret = errno;
+ perror("Error in waitpid");
+ goto destroy_error;
+ }
+
+ ret = 0;
+ if(WIFEXITED(status))
+ ret = WEXITSTATUS(status);
+ if(ret) goto destroy_error;
+
+ } else if(pid == 0) {
+ /* child */
+ int ret;
+ if(append_trace)
+ ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c",
+ channel_path, "-d", "-a", "-N", num_threads, "-f", NULL);
+ else
+ ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c",
+ channel_path, "-d", "-N", num_threads, "-f", NULL);
+ if(ret) {
+ ret = errno;
+ perror("Error in executing the lttd daemon");
+ exit(ret);
+ }
+ } else {
+ /* error */
+ perror("Error in forking for lttd daemon");
+ }
+
+ ret = lttctl_destroy_trace(handle, trace_name);
+ if(ret != 0) goto destroy_error;
+
+ return 0;
+
+ /* error handling */
+destroy_error:
+ printf("Hybrid trace destroy error\n");
+stop_error:
+ return ret;
+}
+
+
+