* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#define _GNU_SOURCE
#include <stdlib.h>
#include <ctype.h>
* Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#define _GNU_SOURCE
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
ret = epoll_create1(flags);
if (ret < 0) {
/* At this point, every error is fatal */
- perror("epoll_create1");
+ PERROR("epoll_create1");
goto error;
}
/* This *must* be freed by using lttng_poll_free() */
events->events = zmalloc(size * sizeof(struct epoll_event));
if (events->events == NULL) {
- perror("zmalloc epoll set");
+ PERROR("zmalloc epoll set");
goto error_close;
}
return 0;
error_close:
- close(events->epfd);
+ ret = close(events->epfd);
+ if (ret) {
+ PERROR("close");
+ }
error:
return -1;
}
goto end;
case ENOSPC:
case EPERM:
- /* Print perror and goto end not failing. Show must go on. */
- perror("epoll_ctl ADD");
+ /* Print PERROR and goto end not failing. Show must go on. */
+ PERROR("epoll_ctl ADD");
goto end;
default:
- perror("epoll_ctl ADD fatal");
+ PERROR("epoll_ctl ADD fatal");
goto error;
}
}
new_size = 2 * events->events_size;
ptr = realloc(events->events, new_size * sizeof(struct epoll_event));
if (ptr == NULL) {
- perror("realloc epoll add");
+ PERROR("realloc epoll add");
goto error;
}
events->events = ptr;
switch (errno) {
case ENOENT:
case EPERM:
- /* Print perror and goto end not failing. Show must go on. */
- perror("epoll_ctl DEL");
+ /* Print PERROR and goto end not failing. Show must go on. */
+ PERROR("epoll_ctl DEL");
goto end;
default:
- perror("epoll_ctl DEL fatal");
+ PERROR("epoll_ctl DEL fatal");
goto error;
}
- perror("epoll_ctl del");
+ PERROR("epoll_ctl del");
goto error;
}
} while (ret == -1 && errno == EINTR);
if (ret < 0) {
/* At this point, every error is fatal */
- perror("epoll_wait");
+ PERROR("epoll_wait");
goto error;
}
ret = read(fd, buf, sizeof(buf));
if (ret < 0) {
- perror("read set max size");
+ PERROR("read set max size");
goto error;
}
DBG("epoll set max size is %d", poll_max_size);
error:
- close(fd);
+ ret = close(fd);
+ if (ret) {
+ PERROR("close");
+ }
}
goto end;
}
if (stream->out_fd >= 0) {
- close(stream->out_fd);
+ ret = close(stream->out_fd);
+ if (ret) {
+ PERROR("close");
+ }
}
if (stream->wait_fd >= 0 && !stream->wait_fd_is_copy) {
- close(stream->wait_fd);
+ ret = close(stream->wait_fd);
+ if (ret) {
+ PERROR("close");
+ }
}
if (stream->shm_fd >= 0 && stream->wait_fd != stream->shm_fd) {
- close(stream->shm_fd);
+ ret = close(stream->shm_fd);
+ if (ret) {
+ PERROR("close");
+ }
}
if (!--stream->chan->refcount)
free_chan = stream->chan;
}
}
if (channel->wait_fd >= 0 && !channel->wait_fd_is_copy) {
- close(channel->wait_fd);
+ ret = close(channel->wait_fd);
+ if (ret) {
+ PERROR("close");
+ }
}
if (channel->shm_fd >= 0 && channel->wait_fd != channel->shm_fd) {
- close(channel->shm_fd);
+ ret = close(channel->shm_fd);
+ if (ret) {
+ PERROR("close");
+ }
}
free(channel);
end:
int err;
err = close(ctx->consumer_should_quit[i]);
- assert(!err);
+ if (err) {
+ PERROR("close");
+ }
}
error_quit_pipe:
for (i = 0; i < 2; i++) {
int err;
err = close(ctx->consumer_poll_pipe[i]);
- assert(!err);
+ if (err) {
+ PERROR("close");
+ }
}
error_poll_pipe:
free(ctx);
*/
void lttng_consumer_destroy(struct lttng_consumer_local_data *ctx)
{
- close(ctx->consumer_error_socket);
- close(ctx->consumer_thread_pipe[0]);
- close(ctx->consumer_thread_pipe[1]);
- close(ctx->consumer_poll_pipe[0]);
- close(ctx->consumer_poll_pipe[1]);
- close(ctx->consumer_should_quit[0]);
- close(ctx->consumer_should_quit[1]);
+ int ret;
+
+ ret = close(ctx->consumer_error_socket);
+ if (ret) {
+ PERROR("close");
+ }
+ ret = close(ctx->consumer_thread_pipe[0]);
+ if (ret) {
+ PERROR("close");
+ }
+ ret = close(ctx->consumer_thread_pipe[1]);
+ if (ret) {
+ PERROR("close");
+ }
+ ret = close(ctx->consumer_poll_pipe[0]);
+ if (ret) {
+ PERROR("close");
+ }
+ ret = close(ctx->consumer_poll_pipe[1]);
+ if (ret) {
+ PERROR("close");
+ }
+ ret = close(ctx->consumer_should_quit[0]);
+ if (ret) {
+ PERROR("close");
+ }
+ ret = close(ctx->consumer_should_quit[1]);
+ if (ret) {
+ PERROR("close");
+ }
unlink(ctx->consumer_command_sock_path);
free(ctx);
}
#include <stdio.h>
#include <string.h>
+#ifndef _GNU_SOURCE
+#error "lttng-tools error.h needs _GNU_SOURCE"
+#endif
+
/* Stringify the expansion of a define */
#define XSTR(d) STR(d)
#define STR(s) #s
/*
* Macro for printing message depending on command line option and verbosity.
*/
-#define __lttng_print(type, fmt, args...) \
- do { \
- if (opt_quiet == 0) { \
- if (type == PRINT_MSG) { \
- fprintf(stdout, fmt, ## args); \
- } else if (((type & PRINT_DBG) && opt_verbose == 1) || \
- ((type & (PRINT_DBG | PRINT_DBG2)) && \
- opt_verbose == 2) || \
- ((type & (PRINT_DBG | PRINT_DBG2 | PRINT_DBG3)) && \
- opt_verbose == 3)) { \
- fprintf(stderr, fmt, ## args); \
- } else if (type & (PRINT_ERR | PRINT_WARN | PRINT_BUG)) { \
- fprintf(stderr, fmt, ## args); \
- } \
- } \
+#define __lttng_print(type, fmt, args...) \
+ do { \
+ if (opt_quiet == 0 && type == PRINT_MSG) { \
+ fprintf(stdout, fmt, ## args); \
+ } else if (opt_quiet == 0 && \
+ (((type & PRINT_DBG) && opt_verbose == 1) || \
+ ((type & (PRINT_DBG | PRINT_DBG2)) && \
+ opt_verbose == 2) || \
+ ((type & (PRINT_DBG | PRINT_DBG2 | PRINT_DBG3)) && \
+ opt_verbose == 3))) { \
+ fprintf(stderr, fmt, ## args); \
+ } else if (opt_quiet == 0 && (type & (PRINT_WARN))) { \
+ fprintf(stderr, fmt, ## args); \
+ } else if (type & (PRINT_ERR | PRINT_BUG)) { \
+ fprintf(stderr, fmt, ## args); \
+ } \
} while (0);
#define MSG(fmt, args...) \
" [in %s() at " __FILE__ ":" XSTR(__LINE__) "]\n", ## args, __func__)
#define PERROR(call, args...) \
- do { \
+ do { \
char *buf; \
char tmp[200]; \
buf = strerror_r(errno, tmp, sizeof(tmp)); \
if (data->gid != getegid()) {
ret = setegid(data->gid);
if (ret < 0) {
- perror("setegid");
+ PERROR("setegid");
return EXIT_FAILURE;
}
}
if (data->uid != geteuid()) {
ret = seteuid(data->uid);
if (ret < 0) {
- perror("seteuid");
+ PERROR("seteuid");
return EXIT_FAILURE;
}
}
writelen = write(data->retval_pipe, &sendret.c[index],
writeleft);
if (writelen < 0) {
- perror("write");
+ PERROR("write");
return EXIT_FAILURE;
}
writeleft -= writelen;
ret = pipe(retval_pipe);
if (ret < 0) {
- perror("pipe");
+ PERROR("pipe");
retval.i = ret;
goto end;
}
MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | MAP_STACK,
-1, 0);
if (child_stack == MAP_FAILED) {
- perror("mmap");
+ PERROR("mmap");
retval.i = -ENOMEM;
goto close_pipe;
}
CLONE_FILES | SIGCHLD,
&run_as_data, NULL);
if (pid < 0) {
- perror("clone");
+ PERROR("clone");
retval.i = pid;
goto unmap_stack;
}
do {
readlen = read(retval_pipe[0], &retval.c[index], readleft);
if (readlen < 0) {
- perror("read");
+ PERROR("read");
ret = -1;
break;
}
*/
pid = waitpid(pid, &status, 0);
if (pid < 0 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) {
- perror("wait");
+ PERROR("wait");
retval.i = -1;
}
unmap_stack:
ret = munmap(child_stack, RUNAS_CHILD_STACK_SIZE);
if (ret < 0) {
- perror("munmap");
+ PERROR("munmap");
retval.i = ret;
}
close_pipe:
- close(retval_pipe[0]);
- close(retval_pipe[1]);
+ ret = close(retval_pipe[0]);
+ if (ret) {
+ PERROR("close");
+ }
+ ret = close(retval_pipe[1]);
+ if (ret) {
+ PERROR("close");
+ }
end:
return retval.i;
}
#include <errno.h>
#include <common/defaults.h>
+#include <common/error.h>
#include "sessiond-comm.h"
int lttcomm_connect_unix_sock(const char *pathname)
{
struct sockaddr_un sun;
- int fd;
- int ret;
+ int fd, ret, closeret;
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
- perror("socket");
+ PERROR("socket");
ret = fd;
goto error;
}
return fd;
error_connect:
- close(fd);
+ closeret = close(fd);
+ if (closeret) {
+ PERROR("close");
+ }
error:
return ret;
}
/* Blocking call */
new_fd = accept(sock, (struct sockaddr *) &sun, &len);
if (new_fd < 0) {
- perror("accept");
+ PERROR("accept");
}
return new_fd;
/* Create server socket */
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
- perror("socket");
+ PERROR("socket");
goto error;
}
(void) unlink(pathname);
ret = bind(fd, (struct sockaddr *) &sun, sizeof(sun));
if (ret < 0) {
- perror("bind");
+ PERROR("bind");
goto error;
}
ret = listen(sock, LTTNG_SESSIOND_COMM_MAX_LISTEN);
if (ret < 0) {
- perror("listen");
+ PERROR("listen");
}
return ret;
ret = recvmsg(sock, &msg, MSG_WAITALL);
if (ret < 0) {
- perror("recvmsg");
+ PERROR("recvmsg");
}
return ret;
ret = sendmsg(sock, &msg, 0);
if (ret < 0) {
- perror("sendmsg");
+ PERROR("sendmsg");
}
return ret;
*/
int lttcomm_close_unix_sock(int sock)
{
- int ret;
+ int ret, closeret;
/* Shutdown receptions and transmissions */
ret = shutdown(sock, SHUT_RDWR);
if (ret < 0) {
- perror("shutdown");
+ PERROR("shutdown");
}
- close(sock);
+ closeret = close(sock);
+ if (closeret) {
+ PERROR("close");
+ }
return ret;
}
ret = sendmsg(sock, &msg, 0);
if (ret < 0) {
- perror("sendmsg");
+ PERROR("sendmsg");
}
return ret;
}
ret = recvmsg(sock, &msg, 0);
if (ret < 0) {
- perror("recvmsg fds");
+ PERROR("recvmsg fds");
goto end;
}
if (ret != 1) {
ret = sendmsg(sock, &msg, 0);
if (ret < 0) {
- perror("sendmsg");
+ PERROR("sendmsg");
}
return ret;
ret = recvmsg(sock, &msg, 0);
if (ret < 0) {
- perror("recvmsg fds");
+ PERROR("recvmsg fds");
goto end;
}
/* Set socket for credentials retrieval */
ret = setsockopt(sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
if (ret < 0) {
- perror("setsockopt creds unix sock");
+ PERROR("setsockopt creds unix sock");
}
return ret;
stream->buf, &mmap_offset);
if (ret != 0) {
errno = -ret;
- perror("ustctl_get_mmap_read_offset");
+ PERROR("ustctl_get_mmap_read_offset");
goto end;
}
while (len > 0) {
len = 0;
} else if (ret < 0) {
errno = -ret;
- perror("Error in file write");
+ PERROR("Error in file write");
goto end;
}
/* This won't block, but will start writeout asynchronously */
ret = ustctl_snapshot(stream->chan->handle, stream->buf);
if (ret != 0) {
errno = -ret;
- perror("Getting sub-buffer snapshot.");
+ PERROR("Getting sub-buffer snapshot.");
}
return ret;
stream->buf, pos);
if (ret != 0) {
errno = -ret;
- perror("kernctl_snapshot_get_produced");
+ PERROR("kernctl_snapshot_get_produced");
}
return ret;
/* signal the poll thread */
ret = write(ctx->consumer_poll_pipe[1], "4", 1);
if (ret < 0) {
- perror("write consumer poll");
+ PERROR("write consumer poll");
}
end_nosignal:
return 0;
stream->uid, stream->gid);
if (ret < 0) {
ERR("Opening %s", stream->path_name);
- perror("open");
+ PERROR("open");
goto error;
}
stream->out_fd = ret;