#include <unistd.h>
#include <assert.h>
-#include "liblttsessiondcomm.h"
+#include <lttng/lttng-sessiond-comm.h>
/*
* Human readable error message.
{
struct sockaddr_un sun;
int fd;
- int ret = 1;
+ int ret;
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
perror("socket");
+ ret = fd;
goto error;
}
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
strncpy(sun.sun_path, pathname, sizeof(sun.sun_path));
+ sun.sun_path[sizeof(sun.sun_path) - 1] = '\0';
ret = connect(fd, (struct sockaddr *) &sun, sizeof(sun));
if (ret < 0) {
- perror("connect");
- goto error;
+ /*
+ * Don't print message on connect error, because connect
+ * is used in normal execution to detect if sessiond is
+ * alive.
+ */
+ goto error_connect;
}
return fd;
+error_connect:
+ close(fd);
error:
- return -1;
+ return ret;
}
/*
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
- strncpy(sun.sun_path, pathname, strlen(pathname));
+ strncpy(sun.sun_path, pathname, sizeof(sun.sun_path));
+ sun.sun_path[sizeof(sun.sun_path) - 1] = '\0';
+ /* Unlink the old file if present */
+ (void) unlink(pathname);
ret = bind(fd, (struct sockaddr *) &sun, sizeof(sun));
if (ret < 0) {
perror("bind");
char tmp[CMSG_SPACE(sizeof_fds)];
/*
- * Note: the consumerd receiver only supports receiving one FD at a
- * time for now.
+ * Note: the consumerd receiver only supports receiving one FD per
+ * message.
*/
assert(nb_fd == 1);