+ else if(nth_token_is(recvbuf, "get_subbuffer", 0) == 1) {
+ do_cmd_get_subbuffer(recvbuf, src);
+ }
+ else if(nth_token_is(recvbuf, "put_subbuffer", 0) == 1) {
+ do_cmd_put_subbuffer(recvbuf, src);
+ }
+ else if(nth_token_is(recvbuf, "set_subbuf_size", 0) == 1) {
+ do_cmd_set_subbuf_size(recvbuf, src);
+ }
+ else if(nth_token_is(recvbuf, "set_subbuf_num", 0) == 1) {
+ do_cmd_set_subbuf_num(recvbuf, src);
+ }
+ else if(nth_token_is(recvbuf, "enable_marker", 0) == 1) {
+ char *channel_slash_name = nth_token(recvbuf, 1);
+ char channel_name[256]="";
+ char marker_name[256]="";
+
+ result = sscanf(channel_slash_name, "%255[^/]/%255s", channel_name, marker_name);
+
+ if(channel_name == NULL || marker_name == NULL) {
+ WARN("invalid marker name");
+ goto next_cmd;
+ }
+
+ result = ltt_marker_connect(channel_name, marker_name, "default");
+ if(result < 0) {
+ WARN("could not enable marker; channel=%s, name=%s", channel_name, marker_name);
+ }
+ }
+ else if(nth_token_is(recvbuf, "disable_marker", 0) == 1) {
+ char *channel_slash_name = nth_token(recvbuf, 1);
+ char *marker_name;
+ char *channel_name;
+
+ result = sscanf(channel_slash_name, "%a[^/]/%as", &channel_name, &marker_name);
+
+ if(channel_name == NULL || marker_name == NULL) {
+ WARN("invalid marker name");
+ goto next_cmd;
+ }
+
+ result = ltt_marker_disconnect(channel_name, marker_name, "default");
+ if(result < 0) {
+ WARN("could not disable marker; channel=%s, name=%s", channel_name, marker_name);
+ }
+ }
+ else if(nth_token_is(recvbuf, "get_pidunique", 0) == 1) {
+ char *reply;
+
+ if (asprintf(&reply, "%lld", pidunique) < 0) {
+ ERR("process_client_cmd : asprintf failed (%lld)",
+ pidunique);
+ goto next_cmd;
+ }
+
+ result = ustcomm_send_reply(&ustcomm_app.server, reply, src);
+ if(result) {
+ ERR("listener: get_pidunique: ustcomm_send_reply failed");
+ goto next_cmd;
+ }
+
+ free(reply);
+ }
+ else if(nth_token_is(recvbuf, "get_sock_path", 0) == 1) {
+ char *reply = getenv("UST_DAEMON_SOCKET");
+ if(!reply) {
+ if (asprintf(&reply, "%s/%s", SOCK_DIR, "ustd") < 0) {
+ ERR("process_client_cmd : asprintf failed (%s/ustd)",
+ SOCK_DIR);
+ goto next_cmd;
+ }
+ result = ustcomm_send_reply(&ustcomm_app.server, reply, src);
+ free(reply);
+ }
+ else {
+ result = ustcomm_send_reply(&ustcomm_app.server, reply, src);
+ }
+ if(result)
+ ERR("ustcomm_send_reply failed");
+ }
+ else if(nth_token_is(recvbuf, "set_sock_path", 0) == 1) {
+ char *sock_path = nth_token(recvbuf, 1);
+ result = setenv("UST_DAEMON_SOCKET", sock_path, 1);
+ if(result)
+ ERR("cannot set UST_DAEMON_SOCKET environment variable");
+ }
+ else if(nth_token_is(recvbuf, "force_switch", 0) == 1) {
+ do_cmd_force_switch();
+ }
+ else {
+ ERR("unable to parse message: %s", recvbuf);
+ }
+
+next_cmd:
+
+ return 0;
+}
+
+void *listener_main(void *p)
+{
+ int result;
+
+ DBG("LISTENER");
+
+ pthread_cleanup_push(listener_cleanup, NULL);
+
+ for(;;) {
+ struct mpentries mpent;
+
+ multipoll_init(&mpent);
+
+ blocked_consumers_add_to_mp(&mpent);
+ ustcomm_mp_add_app_clients(&mpent, &ustcomm_app, process_client_cmd);
+
+ result = multipoll_poll(&mpent, -1);
+ if(result == -1) {
+ ERR("error in multipoll_poll");
+ }
+
+ multipoll_destroy(&mpent);
+ }
+
+ pthread_cleanup_pop(1);
+}
+
+/* These should only be accessed in the parent thread,
+ * not the listener.
+ */
+static volatile sig_atomic_t have_listener = 0;
+static pthread_t listener_thread;