Skip to content

Commit 1ec8307

Browse files
fujimotosedsiper
authored andcommitted
in_tail: start using our new POSIX emulation
In this commit, we actually start using "win32.h" in various parts of in_tail. This commit removes a lot of Windows-specific ifdefs in the code base, since we don't need them anymore thanks to our new POSIX emulation. Signed-off-by: Fujimoto Seiji <[email protected]>
1 parent d03ba55 commit 1ec8307

File tree

4 files changed

+12
-75
lines changed

4 files changed

+12
-75
lines changed

plugins/in_tail/tail_file.c

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -41,55 +41,15 @@
4141
#include "tail_multiline.h"
4242
#include "tail_scan.h"
4343

44-
#ifdef _MSC_VER
45-
static int get_inode(int fd, uint64_t *inode, struct flb_tail_config *ctx)
46-
{
47-
HANDLE h;
48-
BY_HANDLE_FILE_INFORMATION info;
49-
50-
h = _get_osfhandle(fd);
51-
if (h == INVALID_HANDLE_VALUE) {
52-
flb_plg_error(ctx->ins, "cannot convert fd:%i into HANDLE", fd);
53-
return -1;
54-
}
55-
56-
if (GetFileInformationByHandle(h, &info) == 0) {
57-
flb_plg_error(ctx->ins, "cannot get file info for fd:%i", fd);
58-
return -1;
59-
}
60-
*inode = (uint64_t) info.nFileIndexHigh;
61-
*inode = *inode << 32 | info.nFileIndexLow;
62-
return 0;
63-
}
44+
#ifdef FLB_SYSTEM_WINDOWS
45+
#include "win32.h"
6446
#endif
6547

6648
static inline void consume_bytes(char *buf, int bytes, int length)
6749
{
6850
memmove(buf, buf + bytes, length - bytes);
6951
}
7052

71-
#ifdef _MSC_VER
72-
/*
73-
* Open a file for reading. We need to use CreateFileA() instead of
74-
* open(2) to avoid automatic file locking.
75-
*/
76-
static int open_file(const char *path)
77-
{
78-
HANDLE h;
79-
h = CreateFileA(path,
80-
GENERIC_READ,
81-
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
82-
NULL, /* lpSecurityAttributes */
83-
OPEN_EXISTING, /* dwCreationDisposition */
84-
0, /* dwFlagsAndAttributes */
85-
NULL); /* hTemplateFile */
86-
if (h == INVALID_HANDLE_VALUE) {
87-
return -1;
88-
}
89-
return _open_osfhandle((intptr_t) h, _O_RDONLY);
90-
}
91-
#endif
92-
9353
static int unpack_and_pack(msgpack_packer *pck, msgpack_object *root,
9454
const char *key, size_t key_len,
9555
const char *val, size_t val_len)
@@ -599,11 +559,7 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
599559
return -1;
600560
}
601561

602-
#ifdef _MSC_VER
603-
fd = open_file(path);
604-
#else
605562
fd = open(path, O_RDONLY);
606-
#endif
607563
if (fd == -1) {
608564
flb_errno();
609565
flb_plg_error(ctx->ins, "cannot open %s", path);
@@ -621,7 +577,6 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
621577
file->fd = fd;
622578

623579
/* On non-windows environments check if the original path is a link */
624-
#ifndef _MSC_VER
625580
struct stat lst;
626581
ret = lstat(path, &lst);
627582
if (ret == 0) {
@@ -630,7 +585,6 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
630585
file->link_inode = lst.st_ino;
631586
}
632587
}
633-
#endif
634588

635589
/*
636590
* Duplicate string into 'file' structure, the called function
@@ -649,13 +603,7 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
649603
goto error;
650604
}
651605

652-
#ifdef _MSC_VER
653-
if (get_inode(fd, &file->inode, ctx)) {
654-
goto error;
655-
}
656-
#else
657606
file->inode = st->st_ino;
658-
#endif
659607
file->offset = 0;
660608
file->size = st->st_size;
661609
file->buf_len = 0;

plugins/in_tail/tail_file.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#include "tail_config.h"
3333
#include "tail_file_internal.h"
3434

35+
#ifdef FLB_SYSTEM_WINDOWS
36+
#include "win32.h"
37+
#endif
38+
3539
#ifdef FLB_HAVE_REGEX
3640
#define FLB_HASH_TABLE_SIZE 50
3741
#endif

plugins/in_tail/tail_fs_stat.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include "tail_config.h"
3232
#include "tail_signal.h"
3333

34+
#ifdef FLB_SYSTEM_WINDOWS
35+
#include "win32.h"
36+
#endif
37+
3438
struct fs_stat {
3539
/* last time check */
3640
time_t checked;
@@ -145,25 +149,6 @@ static int tail_fs_check(struct flb_input_instance *ins,
145149
file->pending_bytes = 0;
146150
}
147151

148-
#ifdef FLB_SYSTEM_WINDOWS
149-
HANDLE h;
150-
FILE_STANDARD_INFO info;
151-
152-
h = _get_osfhandle(file->fd);
153-
if (GetFileInformationByHandleEx(h, FileStandardInfo,
154-
&info, sizeof(info))) {
155-
if (info.DeletePending) {
156-
flb_plg_debug(ctx->ins, "file is to be delete: %s", file->name);
157-
#ifdef FLB_HAVE_SQLDB
158-
if (ctx->db) {
159-
flb_tail_db_file_delete(file, ctx);
160-
}
161-
#endif
162-
flb_tail_file_remove(file);
163-
continue;
164-
}
165-
}
166-
#endif
167152

168153
/* Discover the current file name for the open file descriptor */
169154
name = flb_tail_file_name(file);

plugins/in_tail/tail_scan_win32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
#include <fluent-bit/flb_input_plugin.h>
2929
#include <fluent-bit/flb_utils.h>
3030

31-
#include <sys/types.h>
32-
#include <sys/stat.h>
3331
#include <shlwapi.h>
3432

3533
#include "tail.h"
3634
#include "tail_file.h"
3735
#include "tail_signal.h"
3836
#include "tail_config.h"
3937

38+
#include "win32.h"
39+
4040
static int tail_is_excluded(char *path, struct flb_tail_config *ctx)
4141
{
4242
struct mk_list *head;

0 commit comments

Comments
 (0)