Most of the commands were not returning a valid error code to the user.
Add "UST invalid context" lttcomm code and enforce "-t TYPE" for
add-context command.
Change error message for enable/disable event/channel in order to make
it standard for those commands and more meaningful to the user.
Signed-off-by: David Goulet <dgoulet@efficios.com>
struct lttng_event_context *ctx, char *event_name,
char *channel_name)
{
- int ret = LTTCOMM_OK, have_event = 0;
+ int ret = LTTCOMM_OK, have_event = 0, no_chan = 1;
struct lttng_ht_iter iter;
struct lttng_ht *chan_ht;
struct ltt_ust_channel *uchan = NULL;
} else if (!uchan && !have_event) { /* Add ctx all events, all channels */
/* For all channels */
cds_lfht_for_each_entry(chan_ht->ht, &iter.iter, uchan, node.node) {
+ no_chan = 0;
ret = add_uctx_to_channel(usess, domain, uchan, ctx);
if (ret < 0) {
- ERR("Context added to channel %s failed", uchan->name);
+ ERR("Context failed for channel %s", uchan->name);
continue;
}
}
ret = LTTCOMM_FATAL;
break;
case -EINVAL:
- ret = LTTCOMM_UST_CONTEXT_FAIL;
+ ret = LTTCOMM_UST_CONTEXT_INVAL;
break;
case -ENOSYS:
ret = LTTCOMM_UNKNOWN_DOMAIN;
break;
}
+ if (no_chan) {
+ ret = LTTCOMM_UST_CHAN_NOT_FOUND;
+ }
+
error:
return ret;
}
ret = cmd_disable_event(cmd_ctx->session, cmd_ctx->lsm->domain.type,
cmd_ctx->lsm->u.disable.channel_name,
cmd_ctx->lsm->u.disable.name);
- ret = LTTCOMM_OK;
break;
}
case LTTNG_DISABLE_ALL_EVENT:
if (ret < 0) {
if (ret != -EEXIST) {
ERR("Trace directory creation error");
- ret = LTTCOMM_CREATE_FAIL;
+ ret = LTTCOMM_CREATE_DIR_FAIL;
goto error;
}
}
}
}
+ if (!opt_type) {
+ ERR("Missing mandatory -t TYPE");
+ usage(stderr);
+ ret = CMD_ERROR;
+ goto end;
+ }
+
if (!opt_session_name) {
session_name = get_session_name();
if (session_name == NULL) {
calibrate.type = LTTNG_CALIBRATE_FUNCTION;
ret = lttng_calibrate(handle, &calibrate);
if (ret < 0) {
- ret = CMD_ERROR;
goto error;
}
MSG("%s calibration done", opt_kernel ? "Kernel" : "UST");
ret = lttng_create_session(session_name, traces_path);
if (ret < 0) {
- ret = CMD_ERROR;
+ /* Don't set ret so lttng can interpret the sessiond error. */
goto error;
}
ret = lttng_destroy_session(session_name);
if (ret < 0) {
+ /* Don't set ret so lttng can interpret the sessiond error. */
goto free_name;
}
*/
static int disable_channels(char *session_name)
{
- int ret = CMD_SUCCESS;
+ int ret = CMD_SUCCESS, warn = 0;
char *channel_name;
struct lttng_domain dom;
ret = lttng_disable_channel(handle, channel_name);
if (ret < 0) {
- goto error;
+ ERR("Channel %s: %s (session %s)", channel_name,
+ lttng_strerror(ret), session_name);
+ warn = 1;
} else {
MSG("%s channel %s disabled for session %s",
- opt_kernel ? "Kernel" : "UST", channel_name,
- session_name);
+ opt_kernel ? "Kernel" : "UST", channel_name, session_name);
}
/* Next channel */
channel_name = strtok(NULL, ",");
}
+ ret = CMD_SUCCESS;
+
error:
+ if (warn) {
+ ret = CMD_WARNING;
+ }
+
lttng_destroy_handle(handle);
return ret;
*/
static int disable_events(char *session_name)
{
- int err, ret = CMD_SUCCESS;
+ int err, ret = CMD_SUCCESS, warn = 0;
char *event_name, *channel_name = NULL;
struct lttng_domain dom;
- if (opt_channel_name == NULL) {
- err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
- if (err < 0) {
- ret = CMD_FATAL;
- goto error;
- }
- } else {
- channel_name = opt_channel_name;
- }
-
- if (opt_kernel && opt_userspace) {
- ERR("Can't use -k/--kernel and -u/--userspace together");
- ret = CMD_FATAL;
- goto error;
- }
-
/* Create lttng domain */
if (opt_kernel) {
dom.type = LTTNG_DOMAIN_KERNEL;
goto error;
}
+ /* Get channel name */
+ if (opt_channel_name == NULL) {
+ err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
+ if (err < 0) {
+ ret = CMD_FATAL;
+ goto error;
+ }
+ } else {
+ channel_name = opt_channel_name;
+ }
+
handle = lttng_create_handle(session_name, &dom);
if (handle == NULL) {
ret = -1;
if (opt_disable_all) {
ret = lttng_disable_event(handle, NULL, channel_name);
if (ret < 0) {
+ /* Don't set ret so lttng can interpret the sessiond error. */
goto error;
}
/* Strip event list */
event_name = strtok(opt_event_list, ",");
while (event_name != NULL) {
- /* Kernel tracer action */
- if (opt_kernel) {
- DBG("Disabling kernel event %s in channel %s",
- event_name, channel_name);
- } else if (opt_userspace) { /* User-space tracer action */
-#if 0
- if (opt_cmd_name != NULL || opt_pid) {
- MSG("Only supporting tracing all UST processes (-u) for now.");
- ret = CMD_UNDEFINED;
- goto error;
- }
-#endif
- DBG("Disabling UST event %s in channel %s",
- event_name, channel_name);
- } else {
- ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
- goto error;
- }
+ DBG("Disabling event %s", event_name);
ret = lttng_disable_event(handle, event_name, channel_name);
if (ret < 0) {
- MSG("Unable to disable %s event %s in channel %s",
- opt_kernel ? "kernel" : "UST", event_name,
- channel_name);
+ ERR("Event %s: %s (channel %s, session %s)", event_name,
+ lttng_strerror(ret), channel_name, session_name);
+ warn = 1;
} else {
- MSG("%s event %s disabled in channel %s",
- opt_kernel ? "kernel" : "UST", event_name,
- channel_name);
+ MSG("%s event %s disabled in channel %s for session %s",
+ opt_kernel ? "kernel" : "UST", event_name, channel_name,
+ session_name);
}
/* Next event */
event_name = strtok(NULL, ",");
}
+ ret = CMD_SUCCESS;
+
end:
error:
+ if (warn) {
+ ret = CMD_WARNING;
+ }
if (opt_channel_name == NULL) {
free(channel_name);
}
*/
static int enable_channel(char *session_name)
{
- int ret = CMD_SUCCESS;
+ int ret = CMD_SUCCESS, warn = 0;
char *channel_name;
struct lttng_domain dom;
ret = lttng_enable_channel(handle, &chan);
if (ret < 0) {
- goto error;
+ ERR("Channel %s: %s (session %s)", channel_name,
+ lttng_strerror(ret), session_name);
+ warn = 1;
} else {
MSG("%s channel %s enabled for session %s",
opt_kernel ? "Kernel" : "UST", channel_name,
channel_name = strtok(NULL, ",");
}
+ ret = CMD_SUCCESS;
+
error:
+ if (warn) {
+ ret = CMD_WARNING;
+ }
+
lttng_destroy_handle(handle);
return ret;
*/
static int enable_events(char *session_name)
{
- int err, ret = CMD_SUCCESS;
+ int err, ret = CMD_SUCCESS, warn = 0;
char *event_name, *channel_name = NULL;
struct lttng_event ev;
struct lttng_domain dom;
- if (opt_channel_name == NULL) {
- err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
- if (err < 0) {
- ret = CMD_FATAL;
- goto error;
- }
- } else {
- channel_name = opt_channel_name;
- }
-
- if (opt_kernel && opt_userspace) {
- ERR("Can't use -k/--kernel and -u/--userspace together");
- ret = CMD_FATAL;
- goto error;
- }
-
/* Create lttng domain */
if (opt_kernel) {
dom.type = LTTNG_DOMAIN_KERNEL;
goto error;
}
+ if (opt_channel_name == NULL) {
+ err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
+ if (err < 0) {
+ ret = CMD_FATAL;
+ goto error;
+ }
+ } else {
+ channel_name = opt_channel_name;
+ }
+
handle = lttng_create_handle(session_name, &dom);
if (handle == NULL) {
ret = -1;
if (opt_enable_all) {
/* Default setup for enable all */
-
if (opt_kernel) {
ev.type = opt_event_type;
ev.name[0] = '\0';
}
ret = lttng_enable_event(handle, &ev, channel_name);
- if (ret == 0) {
+ if (ret < 0) {
+ ERR("Event %s: %s (channel %s, session %s)", event_name,
+ lttng_strerror(ret), channel_name, session_name);
+ warn = 1;
+ } else {
MSG("%s event %s created in channel %s",
opt_kernel ? "kernel": "UST", event_name, channel_name);
}
end:
error:
+ if (warn) {
+ ret = CMD_WARNING;
+ }
if (opt_channel_name == NULL) {
free(channel_name);
}
count = lttng_list_channels(handle, &channels);
if (count < 0) {
ret = count;
- goto error;
+ goto error_channels;
} else if (count == 0) {
- MSG("No channel found");
- goto end;
+ ERR("Channel %s not found", channel_name);
+ goto error;
}
if (channel_name == NULL) {
}
if (!chan_found && channel_name != NULL) {
- MSG("Channel %s not found", channel_name);
+ ERR("Channel %s not found", channel_name);
+ goto error;
}
-end:
- free(channels);
ret = CMD_SUCCESS;
error:
+ free(channels);
+
+error_channels:
return ret;
}
free(sessions);
if (!session_found && session_name != NULL) {
- MSG("Session %s not found", session_name);
+ ERR("Session %s not found", session_name);
}
if (session_name == NULL) {
*/
static int start_tracing(void)
{
- int ret = CMD_SUCCESS;
+ int ret;
char *session_name;
if (opt_session_name == NULL) {
ret = lttng_start_tracing(session_name);
if (ret < 0) {
+ /* Don't set ret so lttng can interpret the sessiond error. */
goto free_name;
}
+ ret = CMD_SUCCESS;
+
MSG("Tracing started for session %s", session_name);
free_name:
*/
static int stop_tracing(void)
{
- int ret = CMD_SUCCESS;
+ int ret;
char *session_name;
if (opt_session_name == NULL) {
ret = lttng_stop_tracing(session_name);
if (ret < 0) {
+ /* Don't set ret so lttng can interpret the sessiond error. */
goto free_name;
}
+ ret = CMD_SUCCESS;
+
MSG("Tracing stopped for session %s", session_name);
free_name:
/* Find command */
if (strcmp(argv[0], cmd->name) == 0) {
ret = cmd->func(argc, (const char**) argv);
- switch (ret) {
- case CMD_WARNING:
- WARN("Some command(s) went wrong");
- break;
- case CMD_ERROR:
- ERR("Command error");
- break;
- case CMD_UNDEFINED:
- ERR("Undefined command");
- break;
- case CMD_FATAL:
- ERR("Fatal error");
- break;
- }
goto end;
}
i++;
switch (opt) {
case 'h':
usage(stdout);
+ ret = 0;
goto end;
case 'v':
opt_verbose += 1;
goto end;
default:
usage(stderr);
+ ret = 1;
goto error;
}
}
* options.
*/
ret = handle_command(argc - optind, argv + optind);
- if (ret < 0) {
- if (ret == -1) {
- usage(stderr);
- } else {
- ERR("%s", lttng_strerror(ret));
- }
- goto error;
+ switch (ret) {
+ case CMD_WARNING:
+ WARN("Some command(s) went wrong");
+ break;
+ case CMD_ERROR:
+ ERR("Command error");
+ break;
+ case CMD_UNDEFINED:
+ ERR("Undefined command");
+ break;
+ case CMD_FATAL:
+ ERR("Fatal error");
+ break;
+ case -1:
+ usage(stderr);
+ ret = 1;
+ break;
+ case 0:
+ break;
+ default:
+ ERR("%s", lttng_strerror(ret));
+ break;
}
end:
- return 0;
-
error:
- return -1;
+ return ret;
}
}
ret = parse_args(argc, argv);
- if (ret < 0) {
- clean_exit(EXIT_FAILURE);
+ if (ret != 0) {
+ clean_exit(ret);
}
return 0;
[ LTTCOMM_ERR_INDEX(LTTCOMM_SESS_NOT_FOUND) ] = "Session name not found",
[ LTTCOMM_ERR_INDEX(LTTCOMM_NO_TRACE) ] = "No trace found",
[ LTTCOMM_ERR_INDEX(LTTCOMM_FATAL) ] = "Fatal error of the session daemon",
- [ LTTCOMM_ERR_INDEX(LTTCOMM_CREATE_FAIL) ] = "Create trace failed",
+ [ LTTCOMM_ERR_INDEX(LTTCOMM_CREATE_DIR_FAIL) ] = "Create directory failed",
[ LTTCOMM_ERR_INDEX(LTTCOMM_START_FAIL) ] = "Start trace failed",
[ LTTCOMM_ERR_INDEX(LTTCOMM_STOP_FAIL) ] = "Stop trace failed",
[ LTTCOMM_ERR_INDEX(LTTCOMM_NO_TRACEABLE) ] = "App is not traceable",
[ LTTCOMM_ERR_INDEX(LTTCOMM_UST_EVENT_EXIST) ] = "UST event already exist",
[ LTTCOMM_ERR_INDEX(LTTCOMM_UST_EVENT_NOT_FOUND)] = "UST event not found",
[ LTTCOMM_ERR_INDEX(LTTCOMM_UST_CONTEXT_EXIST)] = "UST context already exist",
+ [ LTTCOMM_ERR_INDEX(LTTCOMM_UST_CONTEXT_INVAL)] = "UST invalid context",
[ LTTCOMM_ERR_INDEX(CONSUMERD_COMMAND_SOCK_READY) ] = "consumerd command socket ready",
[ LTTCOMM_ERR_INDEX(CONSUMERD_SUCCESS_RECV_FD) ] = "consumerd success on receiving fds",
[ LTTCOMM_ERR_INDEX(CONSUMERD_ERROR_RECV_FD) ] = "consumerd error on receiving fds",
LTTCOMM_UNKNOWN_DOMAIN, /* Tracing domain not known */
LTTCOMM_ALLOC_FAIL, /* Trace allocation fail */
LTTCOMM_NO_SESSION, /* No session found */
- LTTCOMM_CREATE_FAIL, /* Create trace fail */
+ LTTCOMM_CREATE_DIR_FAIL, /* Create directory fail */
LTTCOMM_SESSION_FAIL, /* Create session fail */
LTTCOMM_START_FAIL, /* Start tracing fail */
LTTCOMM_STOP_FAIL, /* Stop tracing fail */
LTTCOMM_UST_EVENT_EXIST, /* UST event exist */
LTTCOMM_UST_EVENT_NOT_FOUND, /* UST event not found */
LTTCOMM_UST_CONTEXT_EXIST, /* UST context exist */
+ LTTCOMM_UST_CONTEXT_INVAL, /* UST context invalid */
CONSUMERD_COMMAND_SOCK_READY, /* when consumerd command socket ready */
CONSUMERD_SUCCESS_RECV_FD, /* success on receiving fds */