Use the utils functions found in common/utils.h on pipes operations
(open/close).
Acked-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
#include <common/hashtable/hashtable.h>
#include <common/sessiond-comm/relayd.h>
#include <common/uri.h>
#include <common/hashtable/hashtable.h>
#include <common/sessiond-comm/relayd.h>
#include <common/uri.h>
+#include <common/utils.h>
#include "lttng-relayd.h"
#include "lttng-relayd.h"
static
void cleanup(void)
{
static
void cleanup(void)
{
- for (i = 0; i < 2; i++) {
- if (thread_quit_pipe[i] >= 0) {
- ret = close(thread_quit_pipe[i]);
- if (ret) {
- PERROR("close");
- }
- }
- }
+ /* Close thread quit pipes */
+ utils_close_pipe(thread_quit_pipe);
+
+ /* Close relay cmd pipes */
+ utils_close_pipe(relay_cmd_pipe);
static
int init_thread_quit_pipe(void)
{
static
int init_thread_quit_pipe(void)
{
- int ret, i;
-
- 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;
- }
- }
+ ret = utils_create_pipe_cloexec(thread_quit_pipe);
*/
static int create_relay_cmd_pipe(void)
{
*/
static int create_relay_cmd_pipe(void)
{
- int ret, i;
-
- ret = pipe(relay_cmd_pipe);
- if (ret < 0) {
- PERROR("relay cmd pipe");
- goto error;
- }
- for (i = 0; i < 2; i++) {
- ret = fcntl(relay_cmd_pipe[i], F_SETFD, FD_CLOEXEC);
- if (ret < 0) {
- PERROR("fcntl relay_cmd_pipe");
- goto error;
- }
- }
+ ret = utils_create_pipe_cloexec(relay_cmd_pipe);
/* Parse arguments */
progname = argv[0];
if ((ret = parse_args(argc, argv) < 0)) {
/* Parse arguments */
progname = argv[0];
if ((ret = parse_args(argc, argv) < 0)) {
}
if ((ret = set_signal_handler()) < 0) {
}
if ((ret = set_signal_handler()) < 0) {
ret = daemon(0, 0);
if (ret < 0) {
PERROR("daemon");
ret = daemon(0, 0);
if (ret < 0) {
PERROR("daemon");
if (control_uri->port < 1024 || data_uri->port < 1024) {
ERR("Need to be root to use ports < 1024");
ret = -1;
if (control_uri->port < 1024 || data_uri->port < 1024) {
ERR("Need to be root to use ports < 1024");
ret = -1;
if (!ret) {
exit(EXIT_SUCCESS);
}
if (!ret) {
exit(EXIT_SUCCESS);
}
error:
exit(EXIT_FAILURE);
}
error:
exit(EXIT_FAILURE);
}