X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=ltt-sessiond%2Fust-comm.c;fp=ltt-sessiond%2Fust-comm.c;h=accd4276d27c48156bfebb3e0a92602f75b6c60f;hb=099e26bda04bd3e02eee5b0a17fc0d7f47e3f8ea;hp=0000000000000000000000000000000000000000;hpb=3817e7df7aa29d8f52f1a4909b4fa6b660494323;p=lttng-tools.git diff --git a/ltt-sessiond/ust-comm.c b/ltt-sessiond/ust-comm.c new file mode 100644 index 000000000..accd4276d --- /dev/null +++ b/ltt-sessiond/ust-comm.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2011 - David Goulet + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; only version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +#include "ust-comm.h" + +/* + * Send msg containing a command to an UST application via sock and wait for + * the reply. + * + * Return -1 on error or if reply fails else return 0. + */ +int ustcomm_send_command(int sock, struct lttcomm_ust_msg *msg) +{ + ssize_t len; + struct lttcomm_ust_reply reply; + + DBG("Sending UST command %d to sock %d", msg->cmd, sock); + + /* Send UST msg */ + len = lttcomm_send_unix_sock(sock, msg, sizeof(*msg)); + if (len < 0) { + goto error; + } + + DBG("Receiving UST reply on sock %d", sock); + + /* Get UST reply */ + len = lttcomm_recv_unix_sock(sock, &reply, sizeof(reply)); + if (len < 0) { + goto error; + } + + if (reply.ret_code != LTTCOMM_OK) { + goto error; + } + + return 0; + +error: + return -1; +}