Skip to content

Commit

Permalink
in_calyptia_fleet: add support for creating configuration files for w…
Browse files Browse the repository at this point in the history
…in32.

Signed-off-by: Phillip Whelan <[email protected]>
  • Loading branch information
pwhelan committed Sep 15, 2023
1 parent 47b7af2 commit 881088f
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions plugins/in_calyptia_fleet/in_calyptia_fleet.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ static int get_calyptia_fleet_id_by_name(struct flb_in_calyptia_fleet_config *ct
return 0;
}

#ifdef FLB_SYSTEM_WINDOWS
#define link(a, b) CreateHardLinkA(b, a, 0)
#endif

/* cb_collect callback */
static int in_calyptia_fleet_collect(struct flb_input_instance *ins,
struct flb_config *config,
Expand All @@ -656,6 +660,10 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins,
char *data;
size_t b_sent;
int ret = -1;
#ifdef FLB_SYSTEM_WINDOWS
DWORD err;
LPSTR lpMsg;
#endif

u_conn = flb_upstream_conn_get(ctx->u);

Expand Down Expand Up @@ -810,7 +818,16 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins,
flb_sds_destroy(cfgoldname);
}

link(cfgname, cfgnewname);
if (!link(cfgname, cfgnewname)) {
#ifdef FLB_SYSTEM_WINDOWS
err = GetLastError();
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, err, 0, &lpMsg, 0, NULL);
flb_plg_error(ctx->ins, "unable to create hard link: %s", lpMsg);
#else
flb_errno();
#endif
}

// FORCE THE RELOAD!!!
flb_plg_info(ctx->ins, "force the reloading of the configuration file=%d.", ctx->event_fd);
Expand All @@ -825,7 +842,7 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins,
flb_sds_destroy(cfgoldname);
goto reload_error;
}
else {
else {
FLB_INPUT_RETURN(0);
}
}
Expand All @@ -841,11 +858,17 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins,
FLB_INPUT_RETURN(ret);
}

#ifdef FLB_SYSTEM_WINDOWS
#define _mkdir(a, b) mkdir(a)
#else
#define _mkdir(a, b) mkdir(a, b)
#endif

// recursively create directories, based on:
// https://stackoverflow.com/a/2336245
// who found it at:
// http://nion.modprobe.de/blog/archives/357-Recursive-directory-creation.html
static int _mkdir(const char *dir, int perms) {
static int __mkdir(const char *dir, int perms) {
char tmp[255];
char *ptr = NULL;
size_t len;
Expand All @@ -865,23 +888,23 @@ static int _mkdir(const char *dir, int perms) {
if (*ptr == '/') {
*ptr = 0;
if (access(tmp, F_OK) != 0) {
ret = mkdir(tmp, perms);
ret = _mkdir(tmp, perms);
if (ret != 0) {
return ret;
}
}
*ptr = '/';
}
}
return mkdir(tmp, perms);
return _mkdir(tmp, perms);
}

static int create_fleet_directory(struct flb_in_calyptia_fleet_config *ctx)
{
flb_sds_t myfleetdir;

if (access(ctx->config_dir, F_OK) != 0) {
if (_mkdir(ctx->config_dir, 0700) != 0) {
if (__mkdir(ctx->config_dir, 0700) != 0) {
return -1;
}
}
Expand All @@ -898,7 +921,7 @@ static int create_fleet_directory(struct flb_in_calyptia_fleet_config *ctx)
}

if (access(myfleetdir, F_OK) != 0) {
if (_mkdir(myfleetdir, 0700) !=0) {
if (__mkdir(myfleetdir, 0700) !=0) {
return -1;
}
}
Expand All @@ -922,7 +945,7 @@ static int load_fleet_config(struct flb_in_calyptia_fleet_config *ctx)
if (exists_cur_fleet_config(ctx) == FLB_TRUE) {
execute_reload(ctx, cur_fleet_config_filename(ctx));
}
else if (exists_new_fleet_config(ctx) == FLB_TRUE) {
else if (exists_new_fleet_config(ctx) == FLB_TRUE) {
execute_reload(ctx, new_fleet_config_filename(ctx));
}
}
Expand Down

0 comments on commit 881088f

Please sign in to comment.