This third patch documents (and in one instance, enforces) return values for functions of lttng-ctl, calibrate and create.
It also fixes the test of getgroups(), which cannot return (grp_id < -1). ------------------------------ >From 6739ca025c89937cd4e37c933715532fdc39ced0 Mon, 30 Jan 2012 15:54:01 -0500 From: Daniel U. Thibault <[email protected]> Date: Mon, 30 Jan 2012 15:53:49 -0500 Subject: [PATCH] lttng-tools lttng-ctl, calibrate and create : Document return values Signed-off-by: Daniel U. Thibault <[email protected]> diff --git a/lttng2-lttng-tools-2.0-pre18+-5c73c59/src/bin/lttng/commands/calibrate.c b/lttng2-lttng-tools-2.0-pre18+-5c73c59/src/bin/lttng/commands/calibrate.c index a3c7b52..a60cadf 100644 --- a/lttng2-lttng-tools-2.0-pre18+-5c73c59/src/bin/lttng/commands/calibrate.c +++ b/lttng2-lttng-tools-2.0-pre18+-5c73c59/src/bin/lttng/commands/calibrate.c @@ -182,6 +182,8 @@ /* * Calibrate LTTng tracer. + * + * Returns a CMD_* error. */ int cmd_calibrate(int argc, const char **argv) { diff --git a/lttng2-lttng-tools-2.0-pre18+-5c73c59/src/bin/lttng/commands/create.c b/lttng2-lttng-tools-2.0-pre18+-5c73c59/src/bin/lttng/commands/create.c index 34754c7..9dc3752 100644 --- a/lttng2-lttng-tools-2.0-pre18+-5c73c59/src/bin/lttng/commands/create.c +++ b/lttng2-lttng-tools-2.0-pre18+-5c73c59/src/bin/lttng/commands/create.c @@ -52,17 +52,18 @@ { fprintf(ofp, "usage: lttng create [options] [NAME]\n"); fprintf(ofp, "\n"); + fprintf(ofp, " The default NAME is 'auto-yyyymmdd-hhmmss'\n"); fprintf(ofp, " -h, --help Show this help\n"); - fprintf(ofp, " --list-options Simple listing of options\n"); + fprintf(ofp, " --list-options Simple listing of options\n"); fprintf(ofp, " -o, --output PATH Specify output path for traces\n"); fprintf(ofp, "\n"); } /* - * create_session + * Create a tracing session. + * If no name is specified, a default name is generated. * - * Create a tracing session. If no name specified, a default name will be - * generated. + * Returns one of the CMD_* result constants. */ static int create_session() { @@ -147,9 +148,9 @@ } /* - * cmd_create - * * The 'create <options>' first level command + * + * Returns one of the CMD_* result constants. */ int cmd_create(int argc, const char **argv) { diff --git a/lttng2-lttng-tools-2.0-pre18+-5c73c59/src/lib/lttng-ctl/lttng-ctl.c b/lttng2-lttng-tools-2.0-pre18+-5c73c59/src/lib/lttng-ctl/lttng-ctl.c index 6cc04ef..537934f 100644 --- a/lttng2-lttng-tools-2.0-pre18+-5c73c59/src/lib/lttng-ctl/lttng-ctl.c +++ b/lttng2-lttng-tools-2.0-pre18+-5c73c59/src/lib/lttng-ctl/lttng-ctl.c @@ -83,8 +83,8 @@ /* * Send lttcomm_session_msg to the session daemon. * - * On success, return 0 - * On error, return error code + * On success, returns the number of bytes sent (>=0) + * On error, returns -1 */ static int send_session_msg(struct lttcomm_session_msg *lsm) { @@ -105,8 +105,8 @@ /* * Receive data from the sessiond socket. * - * On success, return 0 - * On error, return recv() error code + * On success, returns the number of bytes received (>=0) + * On error, returns -1 (recvmsg() error) or -ENOTCONN */ static int recv_data_sessiond(void *buf, size_t len) { @@ -124,7 +124,7 @@ } /* - * Check if the specified group name exist. + * Check if we are in the specified group. * * If yes return 1, else return -1. */ @@ -153,13 +153,14 @@ } /* Alloc group list of the right size */ + /* Note that malloc(0) will return a valid pointer */ grp_list = malloc(grp_list_size * sizeof(gid_t)); if (!grp_list) { - ret = -1; + perror("malloc"); goto end; } grp_id = getgroups(grp_list_size, grp_list); - if (grp_id < -1) { + if (grp_id < 0) { perror("getgroups"); goto free_list; } @@ -209,8 +210,10 @@ } /* - * Set sessiond socket path by putting it in the global sessiond_sock_path - * variable. + * 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) */ static int set_session_daemon_path(void) { @@ -268,7 +271,7 @@ ret = set_session_daemon_path(); if (ret < 0) { - return ret; + return -1; /* set_session_daemon_path() returns -ENOMEM */ } /* Connect to the sesssion daemon */ @@ -284,7 +287,8 @@ } /* - * Clean disconnect the session daemon. + * Clean disconnect from the session daemon. + * On success, return 0. On error, return -1. */ static int disconnect_sessiond(void) { @@ -373,6 +377,7 @@ /* * Create lttng handle and return pointer. + * The returned pointer will be NULL in case of malloc() error. */ struct lttng_handle *lttng_create_handle(const char *session_name, struct lttng_domain *domain) @@ -408,6 +413,7 @@ /* * Register an outside consumer. + * Returns size of returned session payload data or a negative error code. */ int lttng_register_consumer(struct lttng_handle *handle, const char *socket_path) @@ -425,7 +431,8 @@ } /* - * Start tracing for all trace of the session. + * Start tracing for all traces of the session. + * Returns size of returned session payload data or a negative error code. */ int lttng_start_tracing(const char *session_name) { @@ -443,7 +450,8 @@ } /* - * Stop tracing for all trace of the session. + * Stop tracing for all traces of the session. + * Returns size of returned session payload data or a negative error code. */ int lttng_stop_tracing(const char *session_name) { @@ -496,7 +504,10 @@ } /* - * Enable event + * Enable event(s) for a channel. + * If no event name is specified, all events are enabled. + * If no channel name is specified, the default 'channel0' is used. + * Returns size of returned session payload data or a negative error code. */ int lttng_enable_event(struct lttng_handle *handle, struct lttng_event *ev, const char *channel_name) @@ -532,7 +543,10 @@ } /* - * Disable event of a channel and domain. + * Disable event(s) of a channel and domain. + * If no event name is specified, all events are disabled. + * If no channel name is specified, the default 'channel0' is used. + * Returns size of returned session payload data or a negative error code. */ int lttng_disable_event(struct lttng_handle *handle, const char *name, const char *channel_name) @@ -567,7 +581,8 @@ } /* - * Enable channel per domain + * Enable channel per domain + * Returns size of returned session payload data or a negative error code. */ int lttng_enable_channel(struct lttng_handle *handle, struct lttng_channel *chan) @@ -594,7 +609,8 @@ } /* - * All tracing will be stopped for registered events of the channel. + * All tracing will be stopped for registered events of the channel. + * Returns size of returned session payload data or a negative error code. */ int lttng_disable_channel(struct lttng_handle *handle, const char *name) { @@ -619,10 +635,10 @@ } /* - * List all available tracepoints of domain. - * - * Return the size (bytes) of the list and set the events array. - * On error, return negative value. + * Lists all available tracepoints of domain. + * Sets the contents of the events array. + * Returns the number of lttng_event entries in events; + * on error, returns a negative value. */ int lttng_list_tracepoints(struct lttng_handle *handle, struct lttng_event **events) @@ -646,10 +662,12 @@ } /* - * Return a human readable string of code + * Returns a human readable string describing + * the error code (a negative value). */ const char *lttng_strerror(int code) { + /* lttcomm error codes range from -LTTCOMM_OK down to -LTTCOMM_NR */ if (code > -LTTCOMM_OK) { return "Ended with errors"; } @@ -658,7 +676,8 @@ } /* - * Create a brand new session using name. + * Create a brand new session using name and path. + * Returns size of returned session payload data or a negative error code. */ int lttng_create_session(const char *name, const char *path) { @@ -673,6 +692,7 @@ /* * Destroy session using name. + * Returns size of returned session payload data or a negative error code. */ int lttng_destroy_session(const char *session_name) { @@ -691,9 +711,9 @@ /* * Ask the session daemon for all available sessions. - * - * Return number of session. - * On error, return negative value. + * Sets the contents of the sessions array. + * Returns the number of lttng_session entries in sessions; + * on error, returns a negative value. */ int lttng_list_sessions(struct lttng_session **sessions) { @@ -710,7 +730,10 @@ } /* - * List domain of a session. + * Ask the session daemon for all available domains of a session. + * Sets the contents of the domains array. + * Returns the number of lttng_domain entries in domains; + * on error, returns a negative value. */ int lttng_list_domains(const char *session_name, struct lttng_domain **domains) @@ -735,7 +758,10 @@ } /* - * List channels of a session + * Ask the session daemon for all available channels of a session. + * Sets the contents of the channels array. + * Returns the number of lttng_channel entries in channels; + * on error, returns a negative value. */ int lttng_list_channels(struct lttng_handle *handle, struct lttng_channel **channels) @@ -762,7 +788,10 @@ } /* - * List events of a session channel. + * Ask the session daemon for all available events of a session channel. + * Sets the contents of the events array. + * Returns the number of lttng_event entries in events; + * on error, returns a negative value. */ int lttng_list_events(struct lttng_handle *handle, const char *channel_name, struct lttng_event **events) @@ -792,8 +821,9 @@ } /* - * Set tracing group variable with name. This function allocate memory pointed - * by tracing_group. + * Sets the tracing_group variable with name. + * This function allocates memory pointed to by tracing_group. + * On success, returns 0, on error, returns -1 (null name) or -ENOMEM. */ int lttng_set_tracing_group(const char *name) { @@ -831,6 +861,7 @@ /* * Set default channel attributes. + * If either or both of the arguments are null, nothing happens. */ void lttng_channel_set_default_attr(struct lttng_domain *domain, struct lttng_channel_attr *attr) @@ -875,7 +906,7 @@ * Check if session daemon is alive. * * Return 1 if alive or 0 if not. - * On error return -1 + * On error returns a negative value. */ int lttng_session_daemon_alive(void) { ------------------------------ Daniel U. Thibault R & D pour la défense Canada - Valcartier (RDDC Valcartier) / Defence R&D Canada - Valcartier (DRDC Valcartier) Système de systèmes (SdS) / System of Systems (SoS) Solutions informatiques et expérimentations (SIE) / Computing Solutions and Experimentations (CSE) 2459 Boul. Pie XI Nord Québec, QC G3J 1X5 CANADA Vox : (418) 844-4000 x4245 Fax : (418) 844-4538 NAC: 918V QSDJ Gouvernement du Canada / Government of Canada <http://www.valcartier.drdc-rddc.gc.ca/> _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
