Send data pending status as part of payload instead of an invalid error
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 5 Aug 2015 18:57:36 +0000 (14:57 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 5 Aug 2015 19:55:29 +0000 (15:55 -0400)
This ensures that the session daemon's logs don't contain false
positives every time a data pending command is replied-to.

The use of invalid error codes 0 and 1 causes the log to contain
misleading entries of the form:

Sending response (size: 16, retcode: Unknown error code (0)) [...]

This commit also proves that it is possible, contrary to what the
previous comment indicated, to send a boolean value over a socket
without using undocumented error codes.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/main.c
src/lib/lttng-ctl/lttng-ctl.c

index fa5cb901e12505c2d71d6156fdd81f5701dec2e9..792f519abbddb3cae7c2a1714a42ed96fff16361 100644 (file)
@@ -3766,7 +3766,35 @@ skip_domain:
        }
        case LTTNG_DATA_PENDING:
        {
-               ret = cmd_data_pending(cmd_ctx->session);
+               int pending_ret;
+
+               /* 1 byte to return whether or not data is pending */
+               ret = setup_lttng_msg(cmd_ctx, 1);
+               if (ret < 0) {
+                       goto setup_error;
+               }
+
+               pending_ret = cmd_data_pending(cmd_ctx->session);
+               /*
+                * FIXME
+                *
+                * This function may returns 0 or 1 to indicate whether or not
+                * there is data pending. In case of error, it should return an
+                * LTTNG_ERR code. However, some code paths may still return
+                * a nondescript error code, which we handle by returning an
+                * "unknown" error.
+                */
+               if (pending_ret == 0 || pending_ret == 1) {
+                       ret = LTTNG_OK;
+               } else if (pending_ret < 0) {
+                       ret = LTTNG_ERR_UNK;
+                       goto setup_error;
+               } else {
+                       ret = pending_ret;
+                       goto setup_error;
+               }
+
+               *cmd_ctx->llm->payload = (uint8_t) pending_ret;
                break;
        }
        case LTTNG_SNAPSHOT_ADD_OUTPUT:
index 42c9d13907f4594f60f70ec01bc76fa1242f91f0..5f078c94ad67b4fbf635d77f493084d970e63cb2 100644 (file)
@@ -1880,6 +1880,7 @@ int lttng_data_pending(const char *session_name)
 {
        int ret;
        struct lttcomm_session_msg lsm;
+       uint8_t *pending = NULL;
 
        if (session_name == NULL) {
                return -LTTNG_ERR_INVALID;
@@ -1891,18 +1892,18 @@ int lttng_data_pending(const char *session_name)
        lttng_ctl_copy_string(lsm.session.name, session_name,
                        sizeof(lsm.session.name));
 
-       ret = lttng_ctl_ask_sessiond(&lsm, NULL);
-
-       /*
-        * The lttng_ctl_ask_sessiond function negate the return code if it's not
-        * LTTNG_OK so getting -1 means that the reply ret_code was 1 thus meaning
-        * that the data is available. Yes it is hackish but for now this is the
-        * only way.
-        */
-       if (ret == -1) {
-               ret = 1;
+       ret = lttng_ctl_ask_sessiond(&lsm, (void **) &pending);
+       if (ret < 0) {
+               goto end;
+       } else if (ret != 1) {
+               /* Unexpected payload size */
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
        }
 
+       ret = (int) *pending;
+end:
+       free(pending);
        return ret;
 }
 
This page took 0.028114 seconds and 4 git commands to generate.