- * Spawn a session daemon by forking and execv.
- */
-static int spawn_sessiond(char *pathname)
-{
- int ret = 0;
- pid_t pid;
-
- MSG("Spawning a session daemon");
- pid = fork();
- if (pid == 0) {
- /*
- * Spawn session daemon and tell
- * it to signal us when ready.
- */
- execlp(pathname, "lttng-sessiond", "--sig-parent", "--quiet", NULL);
- /* execlp only returns if error happened */
- if (errno == ENOENT) {
- ERR("No session daemon found. Use --sessiond-path.");
- } else {
- perror("execlp");
- }
- kill(getppid(), SIGTERM); /* unpause parent */
- exit(EXIT_FAILURE);
- } else if (pid > 0) {
- /* Wait for lttng-sessiond to start */
- pause();
- goto end;
- } else {
- perror("fork");
- ret = -1;
- goto end;
- }
-
-end:
- return ret;
-}
-
-/*
- * check_sessiond
- *
- * Check if the session daemon is available using
- * the liblttngctl API for the check. If not, try to
- * spawn a daemon.
- */
-static int check_sessiond(void)
-{
- int ret;
- char *pathname = NULL, *alloc_pathname = NULL;
-
- ret = lttng_session_daemon_alive();
- if (ret == 0) { /* not alive */
- /* Try command line option path */
- if (opt_sessiond_path != NULL) {
- ret = access(opt_sessiond_path, F_OK | X_OK);
- if (ret < 0) {
- ERR("No such file: %s", opt_sessiond_path);
- goto end;
- }
- pathname = opt_sessiond_path;
- } else {
- /* Try LTTNG_SESSIOND_PATH env variable */
- pathname = getenv(LTTNG_SESSIOND_PATH_ENV);
- }
-
- /* Let's rock and roll */
- if (pathname == NULL) {
- ret = asprintf(&alloc_pathname, INSTALL_BIN_PATH "/lttng-sessiond");
- if (ret < 0) {
- perror("asprintf spawn sessiond");
- goto end;
- }
- pathname = alloc_pathname;
- }
-
- ret = spawn_sessiond(pathname);
- free(alloc_pathname);
- if (ret < 0) {
- ERR("Problem occurs when starting %s", pathname);
- goto end;
- }
- }
-
-end:
- return ret;
-}
-
-/*
- * Check for the "help" option in the argv. If found, return 1 else return 0.
- */
-static int check_help_command(int argc, char **argv)
-{
- int i;
-
- for (i = 0; i < argc; i++) {
- if ((strncmp(argv[i], "-h", 2) == 0) ||
- strncmp(argv[i], "--h", 3) == 0) {
- return 1;
- }
- }
-
- return 0;
-}
-
-/*
- * parse_args
- *
- * Parse command line arguments.
- * Return 0 if OK, else -1