int ret;
if (!connected) {
- ret = -ENOTCONN;
+ ret = -LTTNG_ERR_NO_SESSIOND;
goto end;
}
ret = lttcomm_send_creds_unix_sock(sessiond_socket, lsm,
sizeof(struct lttcomm_session_msg));
+ if (ret < 0) {
+ ret = -LTTNG_ERR_FATAL;
+ }
end:
return ret;
int ret;
if (!connected) {
- ret = -ENOTCONN;
+ ret = -LTTNG_ERR_NO_SESSIOND;
goto end;
}
}
ret = lttcomm_send_unix_sock(sessiond_socket, data, len);
+ if (ret < 0) {
+ ret = -LTTNG_ERR_FATAL;
+ }
end:
return ret;
int ret;
if (!connected) {
- ret = -ENOTCONN;
+ ret = -LTTNG_ERR_NO_SESSIOND;
goto end;
}
ret = lttcomm_recv_unix_sock(sessiond_socket, buf, len);
+ if (ret < 0) {
+ ret = -LTTNG_ERR_FATAL;
+ }
end:
return ret;
ret = access(sock_path, F_OK);
if (ret < 0) {
/* Not alive */
- return -1;
+ goto error;
}
ret = lttcomm_connect_unix_sock(sock_path);
if (ret < 0) {
/* Not alive */
- return -1;
+ goto error;
}
ret = lttcomm_close_unix_sock(ret);
}
return 0;
+
+error:
+ return -1;
}
/*
- * Set sessiond socket path by putting it in the global
- * sessiond_sock_path variable.
- * Returns 0 on success,
- * -ENOMEM on failure (the sessiond socket path is somehow too long)
+ * Set sessiond socket path by putting it in the global sessiond_sock_path
+ * variable.
+ *
+ * Returns 0 on success, negative value on failure (the sessiond socket path
+ * is somehow too long or ENOMEM).
*/
static int set_session_daemon_path(void)
{
ret = snprintf(sessiond_sock_path, sizeof(sessiond_sock_path),
DEFAULT_HOME_CLIENT_UNIX_SOCK, getenv("HOME"));
if ((ret < 0) || (ret >= sizeof(sessiond_sock_path))) {
- return -ENOMEM;
+ goto error;
}
}
end:
return 0;
+
+error:
+ return -1;
}
/*
ret = set_session_daemon_path();
if (ret < 0) {
- return -1; /* set_session_daemon_path() returns -ENOMEM */
+ goto error;
}
/* Connect to the sesssion daemon */
ret = lttcomm_connect_unix_sock(sessiond_sock_path);
if (ret < 0) {
- return ret;
+ goto error;
}
sessiond_socket = ret;
connected = 1;
return 0;
+
+error:
+ return -1;
}
/*
ret = connect_sessiond();
if (ret < 0) {
+ ret = -LTTNG_ERR_NO_SESSIOND;
goto end;
}
/* Send command to session daemon */
ret = send_session_msg(lsm);
if (ret < 0) {
+ /* Ret value is a valid lttng error code. */
goto end;
}
/* Send var len data */
ret = send_session_varlen(vardata, varlen);
if (ret < 0) {
+ /* Ret value is a valid lttng error code. */
goto end;
}
/* Get header from data transmission */
ret = recv_data_sessiond(&llm, sizeof(llm));
if (ret < 0) {
+ /* Ret value is a valid lttng error code. */
goto end;
}
* this point, an error is returned and data is freed.
*/
if (buf == NULL) {
- ret = -1;
+ ret = -LTTNG_ERR_INVALID;
free(data);
goto end;
}
struct lttng_handle *lttng_create_handle(const char *session_name,
struct lttng_domain *domain)
{
- struct lttng_handle *handle;
+ struct lttng_handle *handle = NULL;
+
+ if (domain == NULL) {
+ goto end;
+ }
handle = malloc(sizeof(struct lttng_handle));
if (handle == NULL) {
- perror("malloc handle");
+ PERROR("malloc handle");
goto end;
}
{
struct lttcomm_session_msg lsm;
+ if (handle == NULL || socket_path == NULL) {
+ return -LTTNG_ERR_INVALID;
+ }
+
lsm.cmd_type = LTTNG_REGISTER_CONSUMER;
copy_string(lsm.session.name, handle->session_name,
sizeof(lsm.session.name));
struct lttcomm_session_msg lsm;
if (session_name == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
lsm.cmd_type = LTTNG_START_TRACE;
struct lttcomm_session_msg lsm;
if (session_name == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
lsm.cmd_type = LTTNG_STOP_TRACE;
/* Safety check. Both are mandatory */
if (handle == NULL || ctx == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
memset(&lsm, 0, sizeof(lsm));
struct lttcomm_session_msg lsm;
if (handle == NULL || ev == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
memset(&lsm, 0, sizeof(lsm));
/* Safety check. */
if (handle == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
if (!filter_expression) {
struct lttcomm_session_msg lsm;
if (handle == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
memset(&lsm, 0, sizeof(lsm));
* NULL arguments are forbidden. No default values.
*/
if (handle == NULL || chan == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
memset(&lsm, 0, sizeof(lsm));
/* Safety check. Both are mandatory */
if (handle == NULL || name == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
memset(&lsm, 0, sizeof(lsm));
struct lttcomm_session_msg lsm;
if (handle == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
lsm.cmd_type = LTTNG_LIST_TRACEPOINTS;
struct lttcomm_session_msg lsm;
if (handle == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
lsm.cmd_type = LTTNG_LIST_TRACEPOINT_FIELDS;
struct lttng_uri *uris = NULL;
if (name == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
memset(&lsm, 0, sizeof(lsm));
/* There should never be a data URL */
size = parse_str_urls_to_uri(url, NULL, &uris);
if (size < 0) {
- return LTTNG_ERR_INVALID;
+ return -LTTNG_ERR_INVALID;
}
lsm.u.uri.size = size;
struct lttcomm_session_msg lsm;
if (session_name == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
lsm.cmd_type = LTTNG_DESTROY_SESSION;
struct lttcomm_session_msg lsm;
if (session_name == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
lsm.cmd_type = LTTNG_LIST_DOMAINS;
struct lttcomm_session_msg lsm;
if (handle == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
lsm.cmd_type = LTTNG_LIST_CHANNELS;
/* Safety check. An handle and channel name are mandatory */
if (handle == NULL || channel_name == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
lsm.cmd_type = LTTNG_LIST_EVENTS;
int lttng_set_tracing_group(const char *name)
{
if (name == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
if (asprintf(&tracing_group, "%s", name) < 0) {
- return -ENOMEM;
+ return -LTTNG_ERR_FATAL;
}
return 0;
/* Safety check. NULL pointer are forbidden */
if (handle == NULL || calibrate == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
lsm.cmd_type = LTTNG_CALIBRATE;
}
if (strlen(sessiond_sock_path) == 0) {
- /* No socket path set. Weird error */
- return -1;
+ /*
+ * No socket path set. Weird error which means the constructor was not
+ * called.
+ */
+ assert(0);
}
ret = try_connect_sessiond(sessiond_sock_path);
struct lttng_uri *uris = NULL;
if (handle == NULL || (control_url == NULL && data_url == NULL)) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
memset(&lsm, 0, sizeof(lsm));
size = parse_str_urls_to_uri(control_url, data_url, &uris);
if (size < 0) {
- return LTTNG_ERR_INVALID;
+ return -LTTNG_ERR_INVALID;
}
lsm.u.uri.size = size;
struct lttcomm_session_msg lsm;
if (handle == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
lsm.cmd_type = LTTNG_ENABLE_CONSUMER;
struct lttcomm_session_msg lsm;
if (handle == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
lsm.cmd_type = LTTNG_DISABLE_CONSUMER;
/*
* Check session daemon health for a specific health component.
*
- * Return 0 if health is OK or else 1 if BAD. A return value of -1 indicate
- * that the control library was not able to connect to the session daemon
- * health socket.
+ * Return 0 if health is OK or else 1 if BAD.
*
- * Any other positive value is an lttcomm error which can be translate with
+ * Any other negative value is a lttng error code which can be translated with
* lttng_strerror().
*/
int lttng_health_check(enum lttng_health_component c)
/* Connect to the sesssion daemon */
sock = lttcomm_connect_unix_sock(health_sock_path);
if (sock < 0) {
- ret = -1;
+ ret = -LTTNG_ERR_NO_SESSIOND;
goto error;
}
ret = lttcomm_send_unix_sock(sock, (void *)&msg, sizeof(msg));
if (ret < 0) {
+ ret = -LTTNG_ERR_FATAL;
goto close_error;
}
ret = lttcomm_recv_unix_sock(sock, (void *)&reply, sizeof(reply));
if (ret < 0) {
+ ret = -LTTNG_ERR_FATAL;
goto close_error;
}
struct lttng_uri *uris = NULL;
if (name == NULL || datetime == NULL) {
- return -1;
+ return -LTTNG_ERR_INVALID;
}
memset(&lsm, 0, sizeof(lsm));
name, datetime);
if (ret < 0) {
PERROR("snprintf session name datetime");
- return -1;
+ return -LTTNG_ERR_FATAL;
}
} else {
copy_string(lsm.session.name, name, sizeof(lsm.session.name));
/* There should never be a data URL */
size = parse_str_urls_to_uri(url, NULL, &uris);
if (size < 0) {
- return LTTNG_ERR_INVALID;
+ return -LTTNG_ERR_INVALID;
}
lsm.u.uri.size = size;
datetime);
if (ret < 0) {
PERROR("snprintf uri subdir");
- return -1;
+ return -LTTNG_ERR_FATAL;
}
}