Ejemplo n.º 1
0
/*
 * destroy_session
 *
 * Unregister the provided session to the session daemon. On success, removes
 * the default configuration.
 */
static int destroy_session(struct lttng_session *session)
{
	int ret;

	ret = lttng_destroy_session(session->name);
	if (ret < 0) {
		switch (-ret) {
		case LTTNG_ERR_SESS_NOT_FOUND:
			WARN("Session name %s not found", session->name);
			break;
		default:
			ERR("%s", lttng_strerror(ret));
			break;
		}
		goto error;
	}

	MSG("Session %s destroyed", session->name);
	config_destroy_default();

	if (lttng_opt_mi) {
		ret = mi_lttng_session(writer, session, 0);
		if (ret) {
			ret = CMD_ERROR;
			goto error;
		}
	}

	ret = CMD_SUCCESS;
error:
	return ret;
}
Ejemplo n.º 2
0
static
int cleanup_session(const char *session_name)
{
	int ret;

	printf("Stopping session %s", session_name);
	ret = lttng_stop_tracing_no_wait(session_name);
	if (ret) {
		fprintf(stderr, "Failed to stop tracing\n");
		goto end;
	}

	fflush(stdout);
	do {
		ret = lttng_data_pending(session_name);
		if (ret < 0) {
			/* Return the data available call error. */
			goto end;
		}

		/*
		 * Data sleep time before retrying (in usec). Don't sleep if the call
		 * returned value indicates availability.
		 */
		if (ret) {
			usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME);
			printf(".");
			fflush(stdout);
		}
	} while (ret != 0);
	printf("\n");

	printf("Destroying session %s\n", session_name);
	ret = lttng_destroy_session(session_name);
	if (ret) {
		fprintf(stderr, "Failed to destroy the session\n");
		goto end;
	}

	ret = 0;

end:
	return ret;
}
Ejemplo n.º 3
0
/*
 *  Create a tracing session.
 *  If no name is specified, a default name is generated.
 *
 *  Returns one of the CMD_* result constants.
 */
static int create_session(void)
{
	int ret, i;
	char shm_path[LTTNG_PATH_MAX] = {};
	struct lttng_session_descriptor *session_descriptor = NULL;
	enum lttng_session_descriptor_status descriptor_status;
	enum lttng_error_code ret_code;
	struct lttng_session *sessions = NULL;
	const struct lttng_session *created_session = NULL;
	const char *created_session_name;

	/* Validate options. */
	if (opt_session_name) {
		if (strlen(opt_session_name) > NAME_MAX) {
			ERR("Session name too long. Length must be lower or equal to %d",
					NAME_MAX);
			ret = CMD_ERROR;
			goto error;
		}
		/*
		 * Check if the session name begins with "auto-" or is exactly "auto".
		 * Both are reserved for the default session name. See bug #449 to
		 * understand why we need to check both here.
		 */
		if ((strncmp(opt_session_name, DEFAULT_SESSION_NAME "-",
					strlen(DEFAULT_SESSION_NAME) + 1) == 0) ||
				(strncmp(opt_session_name, DEFAULT_SESSION_NAME,
					strlen(DEFAULT_SESSION_NAME)) == 0 &&
				strlen(opt_session_name) == strlen(DEFAULT_SESSION_NAME))) {
			ERR("%s is a reserved keyword for default session(s)",
					DEFAULT_SESSION_NAME);
			ret = CMD_ERROR;
			goto error;
		}
	}

	if (opt_snapshot && opt_live_timer) {
		ERR("Snapshot and live modes are mutually exclusive.");
		ret = CMD_ERROR;
		goto error;
	}

	if ((!opt_ctrl_url && opt_data_url) || (opt_ctrl_url && !opt_data_url)) {
		ERR("Both control and data URLs must be specified.");
		ret = CMD_ERROR;
		goto error;
	}

	session_descriptor = create_session_descriptor();
	if (!session_descriptor) {
		ret = CMD_ERROR;
		goto error;
	}
	ret_code = lttng_create_session_ext(session_descriptor);
	if (ret_code != LTTNG_OK) {
		ERR("%s", lttng_strerror(-ret_code));
		ret = CMD_ERROR;
		goto error;
	}

	descriptor_status = lttng_session_descriptor_get_session_name(
		session_descriptor, &created_session_name);
	if (descriptor_status != LTTNG_SESSION_DESCRIPTOR_STATUS_OK) {
		ERR("Failed to obtain created session name");
		ret = CMD_ERROR;
		goto error;
	}

	ret = lttng_list_sessions(&sessions);
	if (ret < 0) {
		ERR("Failed to fetch properties of created session: %s",
				lttng_strerror(ret));
		ret = CMD_ERROR;
		goto error;
	}
	for (i = 0; i < ret; i++) {
		if (!strcmp(created_session_name, sessions[i].name)) {
			created_session = &sessions[i];
			break;
		}
	}
	if (!created_session) {
		ERR("Failed to fetch properties of created session");
		ret = CMD_ERROR;
		goto error;
	}

	if (opt_shm_path) {
		char datetime_suffix[17] = {};

		/*
		 * An auto-generated session name already includes the creation
		 * timestamp.
		 */
		if (opt_session_name) {
			uint64_t creation_time;
			struct tm *timeinfo;
			time_t creation_time_t;
			size_t strftime_ret;

			ret_code = lttng_session_get_creation_time(
					created_session,
					&creation_time);
			if (ret_code != LTTNG_OK) {
				ERR("%s", lttng_strerror(-ret_code));
				ret = CMD_ERROR;
				goto error;
			}
			creation_time_t = (time_t) creation_time;
			timeinfo = localtime(&creation_time_t);
			if (!timeinfo) {
				PERROR("Failed to interpret session creation time");
				ret = CMD_ERROR;
				goto error;
			}
			strftime_ret = strftime(datetime_suffix,
					sizeof(datetime_suffix),
					"-%Y%m%d-%H%M%S", timeinfo);
			if (strftime_ret == 0) {
				ERR("Failed to format session creation time.");
				ret = CMD_ERROR;
				goto error;
			}
		}

		ret = snprintf(shm_path, sizeof(shm_path),
				"%s/%s%s", opt_shm_path, created_session_name,
				datetime_suffix);
		if (ret < 0 || ret >= sizeof(shm_path)) {
			ERR("Failed to format the shared memory path.");
			ret = CMD_ERROR;
			goto error;
		}
		ret = lttng_set_session_shm_path(created_session_name,
				shm_path);
		if (ret < 0) {
			lttng_destroy_session(created_session_name);
			ret = CMD_ERROR;
			goto error;
		}
	}

	if (opt_snapshot) {
		MSG("Snapshot session %s created.", created_session_name);
	} else if (opt_live_timer) {
		MSG("Live session %s created.", created_session_name);
	} else {
		MSG("Session %s created.", created_session_name);
	}

	if (*created_session->path && !opt_snapshot) {
		MSG("Traces will be output to %s", created_session->path);

		if (opt_live_timer) {
			MSG("Live timer interval set to %u %s", opt_live_timer,
					USEC_UNIT);
		}
	} else if (opt_snapshot) {
		struct lttng_snapshot_output_list *list;
		struct lttng_snapshot_output *iter;
		char snapshot_url[LTTNG_PATH_MAX] = {};

		ret = lttng_snapshot_list_output(created_session_name, &list);
		if (ret < 0) {
			ERR("Failed to list snapshot outputs.");
			ret = CMD_ERROR;
			goto error;
		}

		while ((iter = lttng_snapshot_output_list_get_next(list))) {
			const char *url = NULL;

			url = lttng_snapshot_output_get_ctrl_url(
					iter);
			ret = lttng_strncpy(snapshot_url, url,
					sizeof(snapshot_url));
			if (ret) {
				snapshot_url[0] = '\0';
				ERR("Failed to retrieve snapshot output destination");
			}
			break;
		}
		lttng_snapshot_output_list_destroy(list);

		if (*snapshot_url) {
			MSG("Default snapshot output set to %s",
					snapshot_url);
		}
		MSG("Every channel enabled for this session will be set to mmap output and default to overwrite mode.");
	}
	if (opt_shm_path) {
		MSG("Shared memory path set to %s", shm_path);
	}

	/* Mi output */
	if (lttng_opt_mi) {
		ret = mi_created_session(created_session_name);
		if (ret) {
			ret = CMD_ERROR;
			goto error;
		}
	}

	/* Init lttng session config */
	ret = config_init(created_session_name);
	if (ret < 0) {
		ret = CMD_ERROR;
		goto error;
	}

	ret = CMD_SUCCESS;
error:
	lttng_session_descriptor_destroy(session_descriptor);
	free(sessions);
	return ret;
}
Ejemplo n.º 4
0
static void handle_textdump_sigterm(int signal)
{
	quit = 1;
	lttng_destroy_session("test");
}