From: David Goulet Date: Fri, 2 Mar 2012 20:00:16 +0000 (-0500) Subject: Merge branch 'master' of git://git.lttng.org/lttng-tools X-Git-Tag: v2.0.0-rc3~19 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=e71aad1fa4b06a5f91ddceace42366f3d79bd77e;hp=-c Merge branch 'master' of git://git.lttng.org/lttng-tools --- e71aad1fa4b06a5f91ddceace42366f3d79bd77e diff --combined src/bin/lttng-sessiond/main.c index 8654031f1,17ef7f71c..2ef18ae09 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@@ -17,6 -17,7 +17,6 @@@ */ #define _GNU_SOURCE -#include #include #include #include @@@ -39,7 -40,6 +39,7 @@@ #include #include +#include #include #include #include @@@ -122,22 -122,22 +122,22 @@@ static char client_unix_sock_path[PATH_ static char wait_shm_path[PATH_MAX]; /* Sockets and FDs */ - static int client_sock; - static int apps_sock; - static int kernel_tracer_fd; - static int kernel_poll_pipe[2]; + static int client_sock = -1; + static int apps_sock = -1; + static int kernel_tracer_fd = -1; + static int kernel_poll_pipe[2] = { -1, -1 }; /* * Quit pipe for all threads. This permits a single cancellation point * for all threads when receiving an event on the pipe. */ - static int thread_quit_pipe[2]; + static int thread_quit_pipe[2] = { -1, -1 }; /* * This pipe is used to inform the thread managing application communication * that a command is queued and ready to be processed. */ - static int apps_cmd_pipe[2]; + static int apps_cmd_pipe[2] = { -1, -1 }; /* Pthread, Mutexes and Semaphores */ static pthread_t apps_thread; @@@ -295,22 -295,14 +295,22 @@@ static gid_t allowed_group(void */ static int init_thread_quit_pipe(void) { - int ret; + int ret, i; - ret = pipe2(thread_quit_pipe, O_CLOEXEC); + ret = pipe(thread_quit_pipe); if (ret < 0) { PERROR("thread quit pipe"); goto error; } + for (i = 0; i < 2; i++) { + ret = fcntl(thread_quit_pipe[i], F_SETFD, FD_CLOEXEC); + if (ret < 0) { + PERROR("fcntl"); + goto error; + } + } + error: return ret; } @@@ -386,7 -378,7 +386,7 @@@ static void stop_threads(void */ static void cleanup(void) { - int ret; + int ret, i; char *cmd; struct ltt_session *sess, *stmp; @@@ -427,13 -419,44 +427,44 @@@ if (is_root && !opt_no_kernel) { DBG2("Closing kernel fd"); - close(kernel_tracer_fd); + if (kernel_tracer_fd >= 0) { + ret = close(kernel_tracer_fd); + if (ret) { + PERROR("close"); + } + } DBG("Unloading kernel modules"); modprobe_remove_lttng_all(); } - close(thread_quit_pipe[0]); - close(thread_quit_pipe[1]); + /* + * Closing all pipes used for communication between threads. + */ + for (i = 0; i < 2; i++) { + if (kernel_poll_pipe[i] >= 0) { + ret = close(kernel_poll_pipe[i]); + if (ret) { + PERROR("close"); + } + + } + } + for (i = 0; i < 2; i++) { + if (thread_quit_pipe[i] >= 0) { + ret = close(thread_quit_pipe[i]); + if (ret) { + PERROR("close"); + } + } + } + for (i = 0; i < 2; i++) { + if (apps_cmd_pipe[i] >= 0) { + ret = close(apps_cmd_pipe[i]); + if (ret) { + PERROR("close"); + } + } + } /* */ DBG("%c[%d;%dm*** assert failed :-) *** ==> %c[%dm%c[%d;%dm" @@@ -497,7 -520,7 +528,7 @@@ static int send_kconsumer_channel_strea DBG("Sending channel %d to consumer", lkm.u.channel.channel_key); ret = lttcomm_send_unix_sock(sock, &lkm, sizeof(lkm)); if (ret < 0) { - perror("send consumer channel"); + PERROR("send consumer channel"); goto error; } @@@ -519,12 -542,12 +550,12 @@@ DBG("Sending stream %d to consumer", lkm.u.stream.stream_key); ret = lttcomm_send_unix_sock(sock, &lkm, sizeof(lkm)); if (ret < 0) { - perror("send consumer stream"); + PERROR("send consumer stream"); goto error; } ret = lttcomm_send_fds_unix_sock(sock, &stream->fd, 1); if (ret < 0) { - perror("send consumer stream ancillary data"); + PERROR("send consumer stream ancillary data"); goto error; } } @@@ -564,7 -587,7 +595,7 @@@ static int send_kconsumer_session_strea DBG("Sending metadata channel %d to consumer", lkm.u.stream.stream_key); ret = lttcomm_send_unix_sock(sock, &lkm, sizeof(lkm)); if (ret < 0) { - perror("send consumer channel"); + PERROR("send consumer channel"); goto error; } @@@ -582,12 -605,12 +613,12 @@@ DBG("Sending metadata stream %d to consumer", lkm.u.stream.stream_key); ret = lttcomm_send_unix_sock(sock, &lkm, sizeof(lkm)); if (ret < 0) { - perror("send consumer stream"); + PERROR("send consumer stream"); goto error; } ret = lttcomm_send_fds_unix_sock(sock, &session->metadata_stream_fd, 1); if (ret < 0) { - perror("send consumer stream"); + PERROR("send consumer stream"); goto error; } } @@@ -648,7 -671,7 +679,7 @@@ static int setup_lttng_msg(struct comma cmd_ctx->llm = zmalloc(sizeof(struct lttcomm_lttng_msg) + buf_size); if (cmd_ctx->llm == NULL) { - perror("zmalloc"); + PERROR("zmalloc"); ret = -ENOMEM; goto error; } @@@ -808,7 -831,7 +839,7 @@@ static void *thread_manage_kernel(void ret = create_thread_poll_set(&events, 2); if (ret < 0) { - goto error; + goto error_poll_create; } ret = lttng_poll_add(&events, kernel_poll_pipe[0], LPOLLIN); @@@ -893,12 -916,9 +924,9 @@@ } error: - DBG("Kernel thread dying"); - close(kernel_poll_pipe[0]); - close(kernel_poll_pipe[1]); - lttng_poll_clean(&events); - + error_poll_create: + DBG("Kernel thread dying"); return NULL; } @@@ -907,7 -927,7 +935,7 @@@ */ static void *thread_manage_consumer(void *data) { - int sock = 0, i, ret, pollfd; + int sock = -1, i, ret, pollfd; uint32_t revents, nb_fd; enum lttcomm_return_code code; struct lttng_poll_event events; @@@ -917,7 -937,7 +945,7 @@@ ret = lttcomm_listen_unix_sock(consumer_data->err_sock); if (ret < 0) { - goto error; + goto error_listen; } /* @@@ -926,7 -946,7 +954,7 @@@ */ ret = create_thread_poll_set(&events, 2); if (ret < 0) { - goto error; + goto error_poll; } ret = lttng_poll_add(&events, consumer_data->err_sock, LPOLLIN | LPOLLRDHUP); @@@ -1058,16 -1078,33 +1086,33 @@@ restart_poll ERR("consumer return code : %s", lttcomm_get_readable_code(-code)); error: - DBG("consumer thread dying"); - close(consumer_data->err_sock); - close(consumer_data->cmd_sock); - close(sock); + if (consumer_data->err_sock >= 0) { + ret = close(consumer_data->err_sock); + if (ret) { + PERROR("close"); + } + } + if (consumer_data->cmd_sock >= 0) { + ret = close(consumer_data->cmd_sock); + if (ret) { + PERROR("close"); + } + } + if (sock >= 0) { + ret = close(sock); + if (ret) { + PERROR("close"); + } + } unlink(consumer_data->err_unix_sock_path); unlink(consumer_data->cmd_unix_sock_path); consumer_data->pid = 0; lttng_poll_clean(&events); + error_poll: + error_listen: + DBG("consumer thread cleanup completed"); return NULL; } @@@ -1089,7 -1126,7 +1134,7 @@@ static void *thread_manage_apps(void *d ret = create_thread_poll_set(&events, 2); if (ret < 0) { - goto error; + goto error_poll_create; } ret = lttng_poll_add(&events, apps_cmd_pipe[0], LPOLLIN | LPOLLRDHUP); @@@ -1138,7 -1175,7 +1183,7 @@@ /* Empty pipe */ ret = read(apps_cmd_pipe[0], &ust_cmd, sizeof(ust_cmd)); if (ret < 0 || ret < sizeof(ust_cmd)) { - perror("read apps cmd pipe"); + PERROR("read apps cmd pipe"); goto error; } @@@ -1209,12 -1246,9 +1254,9 @@@ } error: - DBG("Application communication apps dying"); - close(apps_cmd_pipe[0]); - close(apps_cmd_pipe[1]); - lttng_poll_clean(&events); - + error_poll_create: + DBG("Application communication apps thread cleanup complete"); rcu_thread_offline(); rcu_unregister_thread(); return NULL; @@@ -1261,7 -1295,7 +1303,7 @@@ static void *thread_dispatch_ust_regist ret = write(apps_cmd_pipe[1], ust_cmd, sizeof(struct ust_command)); if (ret < 0) { - perror("write apps cmd pipe"); + PERROR("write apps cmd pipe"); if (errno == EBADF) { /* * We can't inform the application thread to process @@@ -1289,7 -1323,7 +1331,7 @@@ error */ static void *thread_registration_apps(void *data) { - int sock = 0, i, ret, pollfd; + int sock = -1, i, ret, pollfd; uint32_t revents, nb_fd; struct lttng_poll_event events; /* @@@ -1302,7 -1336,7 +1344,7 @@@ ret = lttcomm_listen_unix_sock(apps_sock); if (ret < 0) { - goto error; + goto error_listen; } /* @@@ -1311,13 -1345,13 +1353,13 @@@ */ ret = create_thread_poll_set(&events, 2); if (ret < 0) { - goto error; + goto error_create_poll; } /* Add the application registration socket */ ret = lttng_poll_add(&events, apps_sock, LPOLLIN | LPOLLRDHUP); if (ret < 0) { - goto error; + goto error_poll_add; } /* Notify all applications to register */ @@@ -1371,7 -1405,7 +1413,7 @@@ /* Create UST registration command for enqueuing */ ust_cmd = zmalloc(sizeof(struct ust_command)); if (ust_cmd == NULL) { - perror("ust command zmalloc"); + PERROR("ust command zmalloc"); goto error; } @@@ -1383,12 -1417,16 +1425,16 @@@ sizeof(struct ust_register_msg)); if (ret < 0 || ret < sizeof(struct ust_register_msg)) { if (ret < 0) { - perror("lttcomm_recv_unix_sock register apps"); + PERROR("lttcomm_recv_unix_sock register apps"); } else { ERR("Wrong size received on apps register"); } free(ust_cmd); - close(sock); + ret = close(sock); + if (ret) { + PERROR("close"); + } + sock = -1; continue; } @@@ -1418,16 -1456,28 +1464,28 @@@ } error: - DBG("UST Registration thread dying"); - /* Notify that the registration thread is gone */ notify_ust_apps(0); - close(apps_sock); - close(sock); + if (apps_sock >= 0) { + ret = close(apps_sock); + if (ret) { + PERROR("close"); + } + } + if (clock >= 0) { + ret = close(sock); + if (ret) { + PERROR("close"); + } + } unlink(apps_unix_sock_path); + error_poll_add: lttng_poll_clean(&events); + error_listen: + error_create_poll: + DBG("UST Registration thread cleanup complete"); return NULL; } @@@ -1667,17 -1717,17 +1725,17 @@@ static pid_t spawn_consumerd(struct con break; } default: - perror("unknown consumer type"); + PERROR("unknown consumer type"); exit(EXIT_FAILURE); } if (errno != 0) { - perror("kernel start consumer exec"); + PERROR("kernel start consumer exec"); } exit(EXIT_FAILURE); } else if (pid > 0) { ret = pid; } else { - perror("start consumer fork"); + PERROR("start consumer fork"); ret = -errno; } error: @@@ -1768,19 -1818,25 +1826,25 @@@ static int init_kernel_tracer(void error_version: modprobe_remove_lttng_control(); - close(kernel_tracer_fd); - kernel_tracer_fd = 0; + ret = close(kernel_tracer_fd); + if (ret) { + PERROR("close"); + } + kernel_tracer_fd = -1; return LTTCOMM_KERN_VERSION; error_modules: - close(kernel_tracer_fd); + ret = close(kernel_tracer_fd); + if (ret) { + PERROR("close"); + } error_open: modprobe_remove_lttng_control(); error: WARN("No kernel tracer available"); - kernel_tracer_fd = 0; + kernel_tracer_fd = -1; return LTTCOMM_KERN_NA; } @@@ -2917,12 -2973,11 +2981,12 @@@ error /* * Command LTTNG_CREATE_SESSION processed by the client thread. */ -static int cmd_create_session(char *name, char *path, struct ucred *creds) +static int cmd_create_session(char *name, char *path, lttng_sock_cred *creds) { int ret; - ret = session_create(name, path, creds->uid, creds->gid); + ret = session_create(name, path, LTTNG_SOCK_GET_UID_CRED(creds), + LTTNG_SOCK_GET_GID_CRED(creds)); if (ret != LTTCOMM_OK) { goto error; } @@@ -2951,7 -3006,7 +3015,7 @@@ static int cmd_destroy_session(struct l */ ret = notify_thread_pipe(kernel_poll_pipe[1]); if (ret < 0) { - perror("write kernel poll pipe"); + PERROR("write kernel poll pipe"); } ret = session_destroy(session); @@@ -3258,7 -3313,7 +3322,7 @@@ static int process_client_msg(struct co } /* Kernel tracer check */ - if (kernel_tracer_fd == 0) { + if (kernel_tracer_fd == -1) { /* Basically, load kernel tracer modules */ ret = init_kernel_tracer(); if (ret != 0) { @@@ -3348,8 -3403,7 +3412,8 @@@ skip_domain */ if (need_tracing_session) { if (!session_access_ok(cmd_ctx->session, - cmd_ctx->creds.uid, cmd_ctx->creds.gid)) { + LTTNG_SOCK_GET_UID_CRED(&cmd_ctx->creds), + LTTNG_SOCK_GET_GID_CRED(&cmd_ctx->creds))) { ret = LTTCOMM_EPERM; goto error; } @@@ -3542,9 -3596,7 +3606,9 @@@ unsigned int nr_sessions; session_lock_list(); - nr_sessions = lttng_sessions_count(cmd_ctx->creds.uid, cmd_ctx->creds.gid); + nr_sessions = lttng_sessions_count( + LTTNG_SOCK_GET_UID_CRED(&cmd_ctx->creds), + LTTNG_SOCK_GET_GID_CRED(&cmd_ctx->creds)); ret = setup_lttng_msg(cmd_ctx, sizeof(struct lttng_session) * nr_sessions); if (ret < 0) { @@@ -3554,8 -3606,7 +3618,8 @@@ /* Filled the session array */ list_lttng_sessions((struct lttng_session *)(cmd_ctx->llm->payload), - cmd_ctx->creds.uid, cmd_ctx->creds.gid); + LTTNG_SOCK_GET_UID_CRED(&cmd_ctx->creds), + LTTNG_SOCK_GET_GID_CRED(&cmd_ctx->creds)); session_unlock_list(); @@@ -3602,7 -3653,7 +3666,7 @@@ init_setup_error */ static void *thread_manage_clients(void *data) { - int sock = 0, ret, i, pollfd; + int sock = -1, ret, i, pollfd; uint32_t revents, nb_fd; struct command_ctx *cmd_ctx = NULL; struct lttng_poll_event events; @@@ -3692,14 -3743,14 +3756,14 @@@ /* Allocate context command to process the client request */ cmd_ctx = zmalloc(sizeof(struct command_ctx)); if (cmd_ctx == NULL) { - perror("zmalloc cmd_ctx"); + PERROR("zmalloc cmd_ctx"); goto error; } /* Allocate data buffer for reception */ cmd_ctx->lsm = zmalloc(sizeof(struct lttcomm_session_msg)); if (cmd_ctx->lsm == NULL) { - perror("zmalloc cmd_ctx->lsm"); + PERROR("zmalloc cmd_ctx->lsm"); goto error; } @@@ -3716,7 -3767,11 +3780,11 @@@ sizeof(struct lttcomm_session_msg), &cmd_ctx->creds); if (ret <= 0) { DBG("Nothing recv() from client... continuing"); - close(sock); + ret = close(sock); + if (ret) { + PERROR("close"); + } + sock = -1; free(cmd_ctx); continue; } @@@ -3752,7 -3807,11 +3820,11 @@@ } /* End of transmission */ - close(sock); + ret = close(sock); + if (ret) { + PERROR("close"); + } + sock = -1; clean_command_ctx(&cmd_ctx); } @@@ -3760,8 -3819,18 +3832,18 @@@ error: DBG("Client thread dying"); unlink(client_unix_sock_path); - close(client_sock); - close(sock); + if (client_sock >= 0) { + ret = close(client_sock); + if (ret) { + PERROR("close"); + } + } + if (sock >= 0) { + ret = close(sock); + if (ret) { + PERROR("close"); + } + } lttng_poll_clean(&events); clean_command_ctx(&cmd_ctx); @@@ -3945,7 -4014,7 +4027,7 @@@ static int init_daemon_socket(void ret = chmod(client_unix_sock_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); if (ret < 0) { ERR("Set file permissions failed: %s", client_unix_sock_path); - perror("chmod"); + PERROR("chmod"); goto end; } @@@ -3962,7 -4031,7 +4044,7 @@@ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (ret < 0) { ERR("Set file permissions failed: %s", apps_unix_sock_path); - perror("chmod"); + PERROR("chmod"); goto end; } @@@ -4007,42 -4076,42 +4089,42 @@@ static int set_permissions(char *rundir ret = chown(rundir, 0, gid); if (ret < 0) { ERR("Unable to set group on %s", rundir); - perror("chown"); + PERROR("chown"); } /* Ensure tracing group can search the run dir */ ret = chmod(rundir, S_IRWXU | S_IXGRP | S_IXOTH); if (ret < 0) { ERR("Unable to set permissions on %s", rundir); - perror("chmod"); + PERROR("chmod"); } /* lttng client socket path */ ret = chown(client_unix_sock_path, 0, gid); if (ret < 0) { ERR("Unable to set group on %s", client_unix_sock_path); - perror("chown"); + PERROR("chown"); } /* kconsumer error socket path */ ret = chown(kconsumer_data.err_unix_sock_path, 0, gid); if (ret < 0) { ERR("Unable to set group on %s", kconsumer_data.err_unix_sock_path); - perror("chown"); + PERROR("chown"); } /* 64-bit ustconsumer error socket path */ ret = chown(ustconsumer64_data.err_unix_sock_path, 0, gid); if (ret < 0) { ERR("Unable to set group on %s", ustconsumer64_data.err_unix_sock_path); - perror("chown"); + PERROR("chown"); } /* 32-bit ustconsumer compat32 error socket path */ ret = chown(ustconsumer32_data.err_unix_sock_path, 0, gid); if (ret < 0) { ERR("Unable to set group on %s", ustconsumer32_data.err_unix_sock_path); - perror("chown"); + PERROR("chown"); } DBG("All permissions are set"); @@@ -4053,52 -4122,20 +4135,54 @@@ end /* * Create the pipe used to wake up the kernel thread. + * Closed in cleanup(). */ static int create_kernel_poll_pipe(void) { - return pipe2(kernel_poll_pipe, O_CLOEXEC); + int ret, i; + + ret = pipe(kernel_poll_pipe); + if (ret < 0) { + PERROR("kernel poll pipe"); + goto error; + } + + for (i = 0; i < 2; i++) { + ret = fcntl(kernel_poll_pipe[i], F_SETFD, FD_CLOEXEC); + if (ret < 0) { + PERROR("fcntl kernel_poll_pipe"); + goto error; + } + } + +error: + return ret; } /* * Create the application command pipe to wake thread_manage_apps. + * Closed in cleanup(). */ static int create_apps_cmd_pipe(void) { - return pipe2(apps_cmd_pipe, O_CLOEXEC); + int ret, i; + + ret = pipe(apps_cmd_pipe); + if (ret < 0) { + PERROR("apps cmd pipe"); + goto error; + } + + for (i = 0; i < 2; i++) { + ret = fcntl(apps_cmd_pipe[i], F_SETFD, FD_CLOEXEC); + if (ret < 0) { + PERROR("fcntl apps_cmd_pipe"); + goto error; + } + } + +error: + return ret; } /* @@@ -4219,7 -4256,7 +4303,7 @@@ static int set_signal_handler(void sigset_t sigset; if ((ret = sigemptyset(&sigset)) < 0) { - perror("sigemptyset"); + PERROR("sigemptyset"); return ret; } @@@ -4227,17 -4264,17 +4311,17 @@@ sa.sa_mask = sigset; sa.sa_flags = 0; if ((ret = sigaction(SIGTERM, &sa, NULL)) < 0) { - perror("sigaction"); + PERROR("sigaction"); return ret; } if ((ret = sigaction(SIGINT, &sa, NULL)) < 0) { - perror("sigaction"); + PERROR("sigaction"); return ret; } if ((ret = sigaction(SIGPIPE, &sa, NULL)) < 0) { - perror("sigaction"); + PERROR("sigaction"); return ret; } @@@ -4261,7 -4298,7 +4345,7 @@@ static void set_ulimit(void ret = setrlimit(RLIMIT_NOFILE, &lim); if (ret < 0) { - perror("failed to set open files limit"); + PERROR("failed to set open files limit"); } } @@@ -4295,7 -4332,7 +4379,7 @@@ int main(int argc, char **argv if (opt_daemon) { ret = daemon(0, 0); if (ret < 0) { - perror("daemon"); + PERROR("daemon"); goto error; } } @@@ -4499,7 -4536,7 +4583,7 @@@ ret = pthread_create(&client_thread, NULL, thread_manage_clients, (void *) NULL); if (ret != 0) { - perror("pthread_create clients"); + PERROR("pthread_create clients"); goto exit_client; } @@@ -4507,7 -4544,7 +4591,7 @@@ ret = pthread_create(&dispatch_thread, NULL, thread_dispatch_ust_registration, (void *) NULL); if (ret != 0) { - perror("pthread_create dispatch"); + PERROR("pthread_create dispatch"); goto exit_dispatch; } @@@ -4515,7 -4552,7 +4599,7 @@@ ret = pthread_create(®_apps_thread, NULL, thread_registration_apps, (void *) NULL); if (ret != 0) { - perror("pthread_create registration"); + PERROR("pthread_create registration"); goto exit_reg_apps; } @@@ -4523,7 -4560,7 +4607,7 @@@ ret = pthread_create(&apps_thread, NULL, thread_manage_apps, (void *) NULL); if (ret != 0) { - perror("pthread_create apps"); + PERROR("pthread_create apps"); goto exit_apps; } @@@ -4531,47 -4568,47 +4615,47 @@@ ret = pthread_create(&kernel_thread, NULL, thread_manage_kernel, (void *) NULL); if (ret != 0) { - perror("pthread_create kernel"); + PERROR("pthread_create kernel"); goto exit_kernel; } ret = pthread_join(kernel_thread, &status); if (ret != 0) { - perror("pthread_join"); + PERROR("pthread_join"); goto error; /* join error, exit without cleanup */ } exit_kernel: ret = pthread_join(apps_thread, &status); if (ret != 0) { - perror("pthread_join"); + PERROR("pthread_join"); goto error; /* join error, exit without cleanup */ } exit_apps: ret = pthread_join(reg_apps_thread, &status); if (ret != 0) { - perror("pthread_join"); + PERROR("pthread_join"); goto error; /* join error, exit without cleanup */ } exit_reg_apps: ret = pthread_join(dispatch_thread, &status); if (ret != 0) { - perror("pthread_join"); + PERROR("pthread_join"); goto error; /* join error, exit without cleanup */ } exit_dispatch: ret = pthread_join(client_thread, &status); if (ret != 0) { - perror("pthread_join"); + PERROR("pthread_join"); goto error; /* join error, exit without cleanup */ } ret = join_consumer_thread(&kconsumer_data); if (ret != 0) { - perror("join_consumer"); + PERROR("join_consumer"); goto error; /* join error, exit without cleanup */ } diff --combined src/bin/lttng-sessiond/shm.c index 55d00e67f,ce1844fe8..432d07ece --- a/src/bin/lttng-sessiond/shm.c +++ b/src/bin/lttng-sessiond/shm.c @@@ -51,7 -51,7 +51,7 @@@ static int get_wait_shm(char *shm_path ret = chown(shm_path, 0, 0); if (ret < 0) { if (errno != ENOENT) { - perror("chown wait shm"); + PERROR("chown wait shm"); goto error; } } @@@ -65,7 -65,7 +65,7 @@@ ret = chown(shm_path, getuid(), getgid()); if (ret < 0) { if (errno != ENOENT) { - perror("chown wait shm"); + PERROR("chown wait shm"); goto error; } } @@@ -77,7 -77,7 +77,7 @@@ ret = chmod(shm_path, mode); if (ret < 0) { if (errno != ENOENT) { - perror("chmod wait shm"); + PERROR("chmod wait shm"); goto error; } } @@@ -94,25 -94,21 +94,25 @@@ */ wait_shm_fd = shm_open(shm_path, O_RDWR | O_CREAT, mode); if (wait_shm_fd < 0) { - perror("shm_open wait shm"); + PERROR("shm_open wait shm"); goto error; } ret = ftruncate(wait_shm_fd, mmap_size); if (ret < 0) { - perror("ftruncate wait shm"); + PERROR("ftruncate wait shm"); exit(EXIT_FAILURE); } +#ifndef __FreeBSD__ ret = fchmod(wait_shm_fd, mode); if (ret < 0) { - perror("fchmod"); + PERROR("fchmod"); exit(EXIT_FAILURE); } +#else +#warning "FreeBSD does not support setting file mode on shm FD. Remember that for secure use, lttng-sessiond should be started before applications linked on lttng-ust." +#endif DBG("Got the wait shm fd %d", wait_shm_fd); @@@ -149,7 -145,7 +149,7 @@@ char *shm_ust_get_mmap(char *shm_path, /* close shm fd immediately after taking the mmap reference */ ret = close(wait_shm_fd); if (ret) { - perror("Error closing fd"); + PERROR("Error closing fd"); } if (wait_shm_mmap == MAP_FAILED) { diff --combined src/common/compat/poll.h index bb046c342,7af2ef050..e3a13cede --- a/src/common/compat/poll.h +++ b/src/common/compat/poll.h @@@ -50,6 -50,7 +50,7 @@@ static inline void __lttng_poll_free(vo */ #ifdef HAVE_EPOLL #include + #include /* See man epoll(7) for this define path */ #define COMPAT_EPOLL_PROC_PATH "/proc/sys/fs/epoll/max_user_watches" @@@ -146,8 -147,13 +147,13 @@@ static inline void lttng_poll_reset(str */ static inline void lttng_poll_clean(struct lttng_poll_event *events) { + int ret; + if (events) { - close(events->epfd); + ret = close(events->epfd); + if (ret) { + perror("close"); + } __lttng_poll_free((void *) events->events); } } @@@ -179,17 -185,10 +185,17 @@@ enum LPOLLRDBAND = POLLRDBAND, LPOLLWRNORM = POLLWRNORM, LPOLLWRBAND = POLLWRBAND, +#if __linux__ LPOLLMSG = POLLMSG, + LPOLLRDHUP = POLLRDHUP, +#elif defined(__FreeBSD__) + LPOLLMSG = 0, + LPOLLRDHUP = 0, +#else +#error "Please add support for your OS." +#endif /* __linux__ */ LPOLLERR = POLLERR, LPOLLHUP = POLLHUP | POLLNVAL, - LPOLLRDHUP = POLLRDHUP, /* Close on exec feature does not exist for poll(2) */ LTTNG_CLOEXEC = 0xdead, }; diff --combined src/common/consumer.c index ae59b6b60,9c54b84cf..e7d51078e --- a/src/common/consumer.c +++ b/src/common/consumer.c @@@ -19,6 -19,7 +19,6 @@@ #define _GNU_SOURCE #include -#include #include #include #include @@@ -173,13 -174,22 +173,22 @@@ void consumer_del_stream(struct lttng_c 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; @@@ -360,10 -370,16 +369,16 @@@ void consumer_del_channel(struct lttng_ } } 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: @@@ -607,7 -623,7 +622,7 @@@ void lttng_consumer_sync_trace_file if (orig_offset < stream->chan->max_sb_size) { return; } - sync_file_range(outfd, orig_offset - stream->chan->max_sb_size, + lttng_sync_file_range(outfd, orig_offset - stream->chan->max_sb_size, stream->chan->max_sb_size, SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE @@@ -698,14 -714,18 +713,18 @@@ error_thread_pipe 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); @@@ -718,13 -738,36 +737,36 @@@ error */ 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); } @@@ -748,8 -791,6 +790,8 @@@ ssize_t lttng_consumer_on_read_subbuffe ERR("Unknown consumer_data type"); assert(0); } + + return 0; } /* diff --combined src/common/error.h index 14b5e7c67,93c947c0d..e5255e4a4 --- a/src/common/error.h +++ b/src/common/error.h @@@ -22,6 -22,10 +22,10 @@@ #include #include + #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 @@@ -40,21 -44,22 +44,22 @@@ extern int opt_verbose /* * 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...) \ @@@ -75,22 -80,9 +80,23 @@@ " [in %s() at " __FILE__ ":" XSTR(__LINE__) "]\n", ## args, __func__) #define _PERROR(fmt, args...) \ - __lttng_print(PRINT_ERR, "perror " fmt "\n", ## args) + __lttng_print(PRINT_ERR, "PERROR: " fmt \ + " [in %s() at " __FILE__ ":" XSTR(__LINE__) "]\n", ## args, __func__) +#if !defined(__linux__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE)) +/* + * Version using XSI strerror_r. + */ +#define PERROR(call, args...) \ + do { \ + char buf[200]; \ + strerror_r(errno, buf, sizeof(buf)); \ + _PERROR(call ": %s", ## args, buf); \ + } while(0); +#else +/* + * Version using GNU strerror_r, for linux with appropriate defines. + */ #define PERROR(call, args...) \ do { \ char *buf; \ @@@ -98,6 -90,5 +104,6 @@@ buf = strerror_r(errno, tmp, sizeof(tmp)); \ _PERROR(call ": %s", ## args, buf); \ } while(0); +#endif #endif /* _ERROR_H */ diff --combined src/common/runas.c index 4742a792e,60e02a2bf..e0c317c4e --- a/src/common/runas.c +++ b/src/common/runas.c @@@ -28,29 -28,16 +28,29 @@@ #include #include #include -#include +#include #include +#include +#include #include "runas.h" #define RUNAS_CHILD_STACK_SIZE 10485760 -#ifndef MAP_STACK -#define MAP_STACK 0 +#ifdef __FreeBSD__ +/* FreeBSD MAP_STACK always return -ENOMEM */ +#define LTTNG_MAP_STACK 0 +#else +#define LTTNG_MAP_STACK MAP_STACK +#endif + +#ifndef MAP_GROWSDOWN +#define MAP_GROWSDOWN 0 +#endif + +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON #endif struct run_as_data { @@@ -167,14 -154,14 +167,14 @@@ int child_run_as(void *_data 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; } } @@@ -190,7 -177,7 +190,7 @@@ writelen = write(data->retval_pipe, &sendret.c[index], writeleft); if (writelen < 0) { - perror("write"); + PERROR("write"); return EXIT_FAILURE; } writeleft -= writelen; @@@ -200,7 -187,7 +200,7 @@@ } static -int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid) +int run_as_clone(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid) { struct run_as_data run_as_data; int ret = 0; @@@ -227,7 -214,7 +227,7 @@@ ret = pipe(retval_pipe); if (ret < 0) { - perror("pipe"); + PERROR("pipe"); retval.i = ret; goto end; } @@@ -238,10 -225,10 +238,10 @@@ run_as_data.retval_pipe = retval_pipe[1]; /* write end */ child_stack = mmap(NULL, RUNAS_CHILD_STACK_SIZE, PROT_WRITE | PROT_READ, - MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | MAP_STACK, + MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS | LTTNG_MAP_STACK, -1, 0); if (child_stack == MAP_FAILED) { - perror("mmap"); + PERROR("mmap"); retval.i = -ENOMEM; goto close_pipe; } @@@ -249,10 -236,11 +249,10 @@@ * Pointing to the middle of the stack to support architectures * where the stack grows up (HPPA). */ - pid = clone(child_run_as, child_stack + (RUNAS_CHILD_STACK_SIZE / 2), - CLONE_FILES | SIGCHLD, - &run_as_data, NULL); + pid = lttng_clone_files(child_run_as, child_stack + (RUNAS_CHILD_STACK_SIZE / 2), + &run_as_data); if (pid < 0) { - perror("clone"); + PERROR("clone"); retval.i = pid; goto unmap_stack; } @@@ -262,7 -250,7 +262,7 @@@ do { readlen = read(retval_pipe[0], &retval.c[index], readleft); if (readlen < 0) { - perror("read"); + PERROR("read"); ret = -1; break; } @@@ -276,45 -264,28 +276,51 @@@ */ 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; } +/* + * To be used on setups where gdb has issues debugging programs using + * clone/rfork. Note that this is for debuging ONLY, and should not be + * considered secure. + */ +static +int run_as_noclone(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid) +{ + return cmd(data); +} + +static +int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid) +{ + if (!getenv("LTTNG_DEBUG_NOCLONE")) { + DBG("Using run_as_clone"); + return run_as_clone(cmd, data, uid, gid); + } else { + DBG("Using run_as_noclone"); + return run_as_noclone(cmd, data, uid, gid); + } +} + int run_as_mkdir_recursive(const char *path, mode_t mode, uid_t uid, gid_t gid) { struct run_as_mkdir_data data; diff --combined src/common/sessiond-comm/sessiond-comm.c index 3b224c6ff,8a5ff1d3f..aa24e82dd --- a/src/common/sessiond-comm/sessiond-comm.c +++ b/src/common/sessiond-comm/sessiond-comm.c @@@ -24,10 -24,12 +24,11 @@@ #include #include #include -#include #include #include #include + #include #include "sessiond-comm.h" @@@ -140,12 -142,11 +141,11 @@@ const char *lttcomm_get_readable_code(e 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; } @@@ -167,7 -168,10 +167,10 @@@ return fd; error_connect: - close(fd); + closeret = close(fd); + if (closeret) { + PERROR("close"); + } error: return ret; } @@@ -185,7 -189,7 +188,7 @@@ int lttcomm_accept_unix_sock(int sock /* Blocking call */ new_fd = accept(sock, (struct sockaddr *) &sun, &len); if (new_fd < 0) { - perror("accept"); + PERROR("accept"); } return new_fd; @@@ -203,7 -207,7 +206,7 @@@ int lttcomm_create_unix_sock(const cha /* Create server socket */ if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { - perror("socket"); + PERROR("socket"); goto error; } @@@ -216,7 -220,7 +219,7 @@@ (void) unlink(pathname); ret = bind(fd, (struct sockaddr *) &sun, sizeof(sun)); if (ret < 0) { - perror("bind"); + PERROR("bind"); goto error; } @@@ -235,7 -239,7 +238,7 @@@ int lttcomm_listen_unix_sock(int sock ret = listen(sock, LTTNG_SESSIOND_COMM_MAX_LISTEN); if (ret < 0) { - perror("listen"); + PERROR("listen"); } return ret; @@@ -262,7 -266,7 +265,7 @@@ ssize_t lttcomm_recv_unix_sock(int sock ret = recvmsg(sock, &msg, MSG_WAITALL); if (ret < 0) { - perror("recvmsg"); + PERROR("recvmsg"); } return ret; @@@ -288,7 -292,7 +291,7 @@@ ssize_t lttcomm_send_unix_sock(int sock ret = sendmsg(sock, &msg, 0); if (ret < 0) { - perror("sendmsg"); + PERROR("sendmsg"); } return ret; @@@ -299,15 -303,18 +302,18 @@@ */ 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; } @@@ -350,7 -357,7 +356,7 @@@ ssize_t lttcomm_send_fds_unix_sock(int ret = sendmsg(sock, &msg, 0); if (ret < 0) { - perror("sendmsg"); + PERROR("sendmsg"); } return ret; } @@@ -385,7 -392,7 +391,7 @@@ ssize_t lttcomm_recv_fds_unix_sock(int ret = recvmsg(sock, &msg, 0); if (ret < 0) { - perror("recvmsg fds"); + PERROR("recvmsg fds"); goto end; } if (ret != 1) { @@@ -411,7 -418,7 +417,7 @@@ } if (cmsg->cmsg_len != CMSG_LEN(sizeof_fds)) { fprintf(stderr, "Error: Received %zu bytes of ancillary data, expected %zu\n", - cmsg->cmsg_len, CMSG_LEN(sizeof_fds)); + (size_t) cmsg->cmsg_len, (size_t) CMSG_LEN(sizeof_fds)); ret = -1; goto end; } @@@ -429,14 -436,12 +435,14 @@@ end ssize_t lttcomm_send_creds_unix_sock(int sock, void *buf, size_t len) { struct msghdr msg; - struct cmsghdr *cmptr; struct iovec iov[1]; ssize_t ret = -1; - struct ucred *creds; - size_t sizeof_cred = sizeof(struct ucred); +#ifdef __linux__ + struct cmsghdr *cmptr; + size_t sizeof_cred = sizeof(lttng_sock_cred); char anc_buf[CMSG_SPACE(sizeof_cred)]; + lttng_sock_cred *creds; +#endif /* __linux__ */ memset(&msg, 0, sizeof(msg)); @@@ -445,25 -450,23 +451,25 @@@ msg.msg_iov = iov; msg.msg_iovlen = 1; +#ifdef __linux__ msg.msg_control = (caddr_t) anc_buf; msg.msg_controllen = CMSG_LEN(sizeof_cred); cmptr = CMSG_FIRSTHDR(&msg); cmptr->cmsg_level = SOL_SOCKET; - cmptr->cmsg_type = SCM_CREDENTIALS; + cmptr->cmsg_type = LTTNG_SOCK_CREDS; cmptr->cmsg_len = CMSG_LEN(sizeof_cred); - creds = (struct ucred *) CMSG_DATA(cmptr); + creds = (lttng_sock_cred*) CMSG_DATA(cmptr); - creds->uid = geteuid(); - creds->gid = getegid(); - creds->pid = getpid(); + LTTNG_SOCK_SET_UID_CRED(creds, geteuid()); + LTTNG_SOCK_SET_GID_CRED(creds, getegid()); + LTTNG_SOCK_SET_PID_CRED(creds, getpid()); +#endif /* __linux__ */ ret = sendmsg(sock, &msg, 0); if (ret < 0) { - perror("sendmsg"); + PERROR("sendmsg"); } return ret; @@@ -475,16 -478,14 +481,16 @@@ * Returns the size of received data, or negative error value. */ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len, - struct ucred *creds) + lttng_sock_cred *creds) { struct msghdr msg; - struct cmsghdr *cmptr; struct iovec iov[1]; ssize_t ret; - size_t sizeof_cred = sizeof(struct ucred); +#ifdef __linux__ + struct cmsghdr *cmptr; + size_t sizeof_cred = sizeof(lttng_sock_cred); char anc_buf[CMSG_SPACE(sizeof_cred)]; +#endif /* __linux__ */ memset(&msg, 0, sizeof(msg)); @@@ -500,18 -501,15 +506,18 @@@ msg.msg_iov = iov; msg.msg_iovlen = 1; +#ifdef __linux__ msg.msg_control = anc_buf; msg.msg_controllen = sizeof(anc_buf); +#endif /* __linux__ */ ret = recvmsg(sock, &msg, 0); if (ret < 0) { - perror("recvmsg fds"); + PERROR("recvmsg fds"); goto end; } +#ifdef __linux__ if (msg.msg_flags & MSG_CTRUNC) { fprintf(stderr, "Error: Control message truncated.\n"); ret = -1; @@@ -526,7 -524,7 +532,7 @@@ } if (cmptr->cmsg_level != SOL_SOCKET || - cmptr->cmsg_type != SCM_CREDENTIALS) { + cmptr->cmsg_type != LTTNG_SOCK_CREDS) { fprintf(stderr, "Didn't received any credentials\n"); ret = -1; goto end; @@@ -534,24 -532,12 +540,24 @@@ if (cmptr->cmsg_len != CMSG_LEN(sizeof_cred)) { fprintf(stderr, "Error: Received %zu bytes of ancillary data, expected %zu\n", - cmptr->cmsg_len, CMSG_LEN(sizeof_cred)); + (size_t) cmptr->cmsg_len, (size_t) CMSG_LEN(sizeof_cred)); ret = -1; goto end; } memcpy(creds, CMSG_DATA(cmptr), sizeof_cred); +#elif defined(__FreeBSD__) + { + int peer_ret; + + peer_ret = getpeereid(sock, &creds->uid, &creds->gid); + if (peer_ret != 0) { + return peer_ret; + } + } +#else +#error "Please implement credential support for your OS." +#endif /* __linux__ */ end: return ret; @@@ -560,7 -546,6 +566,7 @@@ /* * Set socket option to use credentials passing. */ +#ifdef __linux__ int lttcomm_setsockopt_creds_unix_sock(int sock) { int ret, on = 1; @@@ -568,15 -553,8 +574,15 @@@ /* 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; } +#elif defined(__FreeBSD__) +int lttcomm_setsockopt_creds_unix_sock(int sock) +{ + return 0; +} +#else +#error "Please implement credential support for your OS." +#endif /* __linux__ */ diff --combined src/common/ust-consumer/ust-consumer.c index c8ba08460,20d0405a3..8dec2d783 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@@ -19,20 -19,19 +19,20 @@@ #define _GNU_SOURCE #include -#include #include #include #include #include #include #include +#include #include #include #include #include #include +#include #include "ust-consumer.h" @@@ -59,7 -58,7 +59,7 @@@ ssize_t lttng_ustconsumer_on_read_subbu 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) { @@@ -68,11 -67,11 +68,11 @@@ 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 */ - sync_file_range(outfd, stream->out_fd_offset, ret, + lttng_sync_file_range(outfd, stream->out_fd_offset, ret, SYNC_FILE_RANGE_WRITE); stream->out_fd_offset += ret; } @@@ -110,7 -109,7 +110,7 @@@ int lttng_ustconsumer_take_snapshot(str 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; @@@ -132,7 -131,7 +132,7 @@@ int lttng_ustconsumer_get_produced_snap stream->buf, pos); if (ret != 0) { errno = -ret; - perror("kernctl_snapshot_get_produced"); + PERROR("kernctl_snapshot_get_produced"); } return ret; @@@ -261,7 -260,7 +261,7 @@@ end /* 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; @@@ -401,7 -400,7 +401,7 @@@ int lttng_ustconsumer_on_recv_stream(st stream->uid, stream->gid); if (ret < 0) { ERR("Opening %s", stream->path_name); - perror("open"); + PERROR("open"); goto error; } stream->out_fd = ret;