Skip to content
6 changes: 6 additions & 0 deletions include/fluent-bit/flb_downstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include <fluent-bit/flb_config.h>
#include <fluent-bit/flb_io.h>
#include <fluent-bit/flb_stream.h>
#ifdef FLB_HAVE_UNIX_SOCKET
#include <sys/stat.h>
#endif

struct flb_connection;

Expand All @@ -42,6 +45,9 @@ struct flb_downstream {
unsigned short int port;
flb_sockfd_t server_fd;
struct flb_connection *dgram_connection;
#ifdef FLB_HAVE_UNIX_SOCKET
struct stat unix_socket;
#endif

struct mk_list busy_queue;
struct mk_list destroy_queue;
Expand Down
6 changes: 6 additions & 0 deletions include/fluent-bit/http_server/flb_http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ struct flb_input_instance;
#define FLB_HTTP_SERVER_INGRESS_QUEUE_BYTE_LIMIT (256 * 1024 * 1024)

struct flb_http_server_config {
char *unix_path;
char *unix_perm;
int http2;
int idle_timeout; /* seconds */
size_t buffer_max_size;
Expand All @@ -88,6 +90,8 @@ struct flb_http_server_options {

char *address;
unsigned short int port;
char *unix_path;
char *unix_perm;
struct flb_tls *tls_provider;
int networking_flags;
struct flb_net_setup *networking_setup;
Expand Down Expand Up @@ -125,6 +129,8 @@ struct flb_http_server {
struct mk_event listener_event;
char *address;
unsigned short int port;
char *unix_path;
char *unix_perm;
struct flb_tls *tls_provider;
int networking_flags;
struct flb_net_setup *networking_setup;
Expand Down
49 changes: 0 additions & 49 deletions plugins/in_forward/fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,57 +46,8 @@ static int setup_users(struct flb_in_fw_config *ctx,
struct flb_input_instance *ins);

#ifdef FLB_HAVE_UNIX_SOCKET
static int remove_existing_socket_file(char *socket_path)
{
struct stat file_data;
int result;

result = stat(socket_path, &file_data);

if (result == -1) {
if (errno == ENOENT) {
return 0;
}

flb_errno();

return -1;
}

if (S_ISSOCK(file_data.st_mode) == 0) {
return -2;
}

result = unlink(socket_path);

if (result != 0) {
return -3;
}

return 0;
}

static int fw_unix_create(struct flb_in_fw_config *ctx)
{
int ret;

ret = remove_existing_socket_file(ctx->unix_path);

if (ret != 0) {
if (ret == -2) {
flb_plg_error(ctx->ins,
"%s exists and it is not a unix socket. Aborting",
ctx->unix_path);
}
else {
flb_plg_error(ctx->ins,
"could not remove existing unix socket %s. Aborting",
ctx->unix_path);
}

return -1;
}

ctx->downstream = flb_downstream_create(FLB_TRANSPORT_UNIX_STREAM,
ctx->ins->flags,
ctx->unix_path,
Expand Down
7 changes: 1 addition & 6 deletions plugins/in_forward/fw_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,7 @@ int fw_config_destroy(struct flb_in_fw_config *config)
flb_downstream_destroy(config->downstream);
}

if (config->unix_path) {
unlink(config->unix_path);
}
else {
flb_free(config->tcp_port);
}
flb_free(config->tcp_port);

fw_destroy_shared_key(config);
flb_sds_destroy(config->self_hostname);
Expand Down
57 changes: 1 addition & 56 deletions plugins/in_syslog/syslog_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,9 @@

#include "syslog.h"

static int remove_existing_socket_file(char *socket_path)
{
struct stat file_data;
int result;

result = stat(socket_path, &file_data);

if (result == -1) {
if (errno == ENOENT) {
return 0;
}

flb_errno();

return -1;
}

if (S_ISSOCK(file_data.st_mode) == 0) {
return -2;
}

result = unlink(socket_path);

if (result != 0) {
return -3;
}

return 0;
}

#if !defined(FLB_SYSTEM_WINDOWS)
static int syslog_server_unix_create(struct flb_syslog *ctx)
{
int result;
int mode;
struct flb_tls *tls;

Expand All @@ -87,23 +56,6 @@ static int syslog_server_unix_create(struct flb_syslog *ctx)
return -1;
}

result = remove_existing_socket_file(ctx->unix_path);

if (result != 0) {
if (result == -2) {
flb_plg_error(ctx->ins,
"%s exists and it is not a unix socket. Aborting",
ctx->unix_path);
}
else {
flb_plg_error(ctx->ins,
"could not remove existing unix socket %s. Aborting",
ctx->unix_path);
}

return -1;
}

ctx->downstream = flb_downstream_create(mode,
ctx->ins->flags,
ctx->unix_path,
Expand Down Expand Up @@ -222,14 +174,7 @@ int syslog_server_destroy(struct flb_syslog *ctx)
ctx->downstream = NULL;
}

if (ctx->mode == FLB_SYSLOG_UNIX_TCP || ctx->mode == FLB_SYSLOG_UNIX_UDP) {
if (ctx->unix_path) {
unlink(ctx->unix_path);
}
}
else {
flb_free(ctx->port);
}
flb_free(ctx->port);

return 0;
}
49 changes: 0 additions & 49 deletions plugins/in_unix_socket/unix_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,36 +69,6 @@ static int in_unix_socket_collect(struct flb_input_instance *in,
return 0;
}

static int remove_existing_socket_file(char *socket_path)
{
struct stat file_data;
int result;

result = stat(socket_path, &file_data);

if (result == -1) {
if (errno == ENOENT) {
return 0;
}

flb_errno();

return -1;
}

if (S_ISSOCK(file_data.st_mode) == 0) {
return -2;
}

result = unlink(socket_path);

if (result != 0) {
return -3;
}

return 0;
}

/* Initialize plugin */
static int in_unix_socket_init(struct flb_input_instance *in,
struct flb_config *config, void *data)
Expand All @@ -125,25 +95,6 @@ static int in_unix_socket_init(struct flb_input_instance *in,
/* Set the context */
flb_input_set_context(in, ctx);

ret = remove_existing_socket_file(ctx->listen);

if (ret != 0) {
if (ret == -2) {
flb_plg_error(ctx->ins,
"%s exists and it is not a unix socket. Aborting",
ctx->listen);
}
else {
flb_plg_error(ctx->ins,
"could not remove existing unix socket %s. Aborting",
ctx->listen);
}

unix_socket_config_destroy(ctx);

return -1;
}

mode = FLB_TRANSPORT_UNIX_STREAM;

if (ctx->socket_mode != NULL &&
Expand Down
Loading