* Copyright (C) 2009 Citrix Ltd.
* Copyright (C) 2017 Citrix Ltd.
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; version 2.1 only. with the special
- * exception on linking described in file LICENSE.
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
*/
-int libxl__sendmsg_fds(libxl__gc *gc, int carrier,
- const void *data, size_t datalen,
- int nfds, const int fds[], const char *what) {
- struct msghdr msg = { 0 };
- struct cmsghdr *cmsg;
- size_t spaceneeded = nfds * sizeof(fds[0]);
- char control[CMSG_SPACE(spaceneeded)];
- struct iovec iov;
- int r;
-
- iov.iov_base = (void*)data;
- iov.iov_len = datalen;
+/* return conventions: functions here return errno values */
- /* compose the message */
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
- msg.msg_control = control;
- msg.msg_controllen = sizeof(control);
+static int fishdescriptor_sendmsg_fds(int carrier,
+ int nfds, const int fds[]) {
+ struct msghdr msg = { 0 };
+ struct cmsghdr *cmsg;
+ size_t spaceneeded = nfds * sizeof(fds[0]);
+ char control[CMSG_SPACE(spaceneeded)];
+ struct iovec iov;
+ int r;
- /* attach open fd */
- cmsg = CMSG_FIRSTHDR(&msg);
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- cmsg->cmsg_len = CMSG_LEN(spaceneeded);
- memcpy(CMSG_DATA(cmsg), fds, spaceneeded);
+ iov.iov_base = &nfds;
+ iov.iov_len = sizeof(nfds);
- msg.msg_controllen = cmsg->cmsg_len;
+ /* compose the message */
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = control;
+ msg.msg_controllen = sizeof(control);
- r = sendmsg(carrier, &msg, 0);
- if (r < 0) {
- LOGE(ERROR, "failed to send fd-carrying message (%s)", what);
- return ERROR_FAIL;
- }
+ /* attach open fd */
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(spaceneeded);
+ memcpy(CMSG_DATA(cmsg), fds, spaceneeded);
+ msg.msg_controllen = cmsg->cmsg_len;
+
+ r = sendmsg(carrier, &msg, 0);
+ if (r < 0)
return 0;
}