Skip to content

Commit d03ba55

Browse files
fujimotosedsiper
authored andcommitted
in_tail: use "uint64_t" for inodes on all platforms
`ino_t` can be 32-bit on Windows. Since Windows's inode (NTFS's file id) is 64-bit in size, we cannot rely on that type. Also Windows interprets "%lu" as 32-bit int. We need to be careful to use PRIu64 for inodes, otherwise, it would cause an instant memory crash. Signed-off-by: Fujimoto Seiji <[email protected]>
1 parent 0daa930 commit d03ba55

File tree

4 files changed

+28
-33
lines changed

4 files changed

+28
-33
lines changed

plugins/in_tail/tail.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static int in_tail_collect_static(struct flb_input_instance *ins,
141141
switch (ret) {
142142
case FLB_TAIL_ERROR:
143143
/* Could not longer read the file */
144-
flb_plg_debug(ctx->ins, "inode=%lu collect static ERROR",
144+
flb_plg_debug(ctx->ins, "inode=%"PRIu64" collect static ERROR",
145145
file->inode);
146146
flb_tail_file_remove(file);
147147
break;
@@ -151,12 +151,12 @@ static int in_tail_collect_static(struct flb_input_instance *ins,
151151
break;
152152
case FLB_TAIL_WAIT:
153153
if (file->config->exit_on_eof) {
154-
flb_plg_info(ctx->ins, "inode=%lu file=%s ended, stop",
154+
flb_plg_info(ctx->ins, "inode=%"PRIu64" file=%s ended, stop",
155155
file->inode, file->name);
156156
flb_engine_exit(config);
157157
}
158158
/* Promote file to 'events' type handler */
159-
flb_plg_debug(ctx->ins, "inode=%lu file=%s promote to TAIL_EVENT",
159+
flb_plg_debug(ctx->ins, "inode=%"PRIu64" file=%s promote to TAIL_EVENT",
160160
file->inode, file->name);
161161

162162
/*

plugins/in_tail/tail_file.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
749749

750750
/* Seek if required */
751751
if (file->offset > 0) {
752-
flb_plg_debug(ctx->ins, "inode=%lu appended file following on offset=%lu",
752+
flb_plg_debug(ctx->ins, "inode=%"PRIu64" appended file following on offset=%lu",
753753
file->inode, file->offset);
754754
offset = lseek(file->fd, file->offset, SEEK_SET);
755755
if (offset == -1) {
@@ -765,7 +765,7 @@ int flb_tail_file_append(char *path, struct stat *st, int mode,
765765
flb_metrics_sum(FLB_TAIL_METRIC_F_OPENED, 1, ctx->ins->metrics);
766766
#endif
767767

768-
flb_plg_debug(ctx->ins, "inode=%lu appended as %s", file->inode, path);
768+
flb_plg_debug(ctx->ins, "inode=%"PRIu64" appended as %s", file->inode, path);
769769
return 0;
770770

771771
error:
@@ -789,7 +789,7 @@ void flb_tail_file_remove(struct flb_tail_file *file)
789789

790790
ctx = file->config;
791791

792-
flb_plg_debug(ctx->ins, "inode=%lu removing file name %s",
792+
flb_plg_debug(ctx->ins, "inode=%"PRIu64" removing file name %s",
793793
file->inode, file->name);
794794

795795
if (file->rotated > 0) {
@@ -930,7 +930,7 @@ int flb_tail_file_chunk(struct flb_tail_file *file)
930930
*/
931931
ret = process_content(file, &processed_bytes);
932932
if (ret < 0) {
933-
flb_plg_debug(ctx->ins, "inode=%lu file=%s process content ERROR",
933+
flb_plg_debug(ctx->ins, "inode=%"PRIu64" file=%s process content ERROR",
934934
file->inode, file->name);
935935
return FLB_TAIL_ERROR;
936936
}
@@ -999,20 +999,19 @@ int flb_tail_file_is_rotated(struct flb_tail_config *ctx,
999999
}
10001000

10011001
/* Check if the 'original monitored file' is a link and rotated */
1002-
#ifndef _MSC_VER
10031002
if (file->is_link == FLB_TRUE) {
10041003
ret = lstat(file->name, &st);
10051004
if (ret == -1) {
10061005
/* Broken link or missing file */
10071006
if (errno == ENOENT) {
1008-
flb_plg_info(ctx->ins, "inode=%lu link_rotated: %s",
1007+
flb_plg_info(ctx->ins, "inode=%"PRIu64" link_rotated: %s",
10091008
file->link_inode, file->name);
10101009
return FLB_TRUE;
10111010
}
10121011
else {
10131012
flb_errno();
10141013
flb_plg_error(ctx->ins,
1015-
"link_inode=%lu cannot detect if file: %s",
1014+
"link_inode=%"PRIu64" cannot detect if file: %s",
10161015
file->link_inode, file->name);
10171016
return -1;
10181017
}
@@ -1027,13 +1026,12 @@ int flb_tail_file_is_rotated(struct flb_tail_config *ctx,
10271026
return FLB_TRUE;
10281027
}
10291028
}
1030-
#endif
10311029

10321030
/* Retrieve the real file name, operating system lookup */
10331031
name = flb_tail_file_name(file);
10341032
if (!name) {
10351033
flb_plg_error(ctx->ins,
1036-
"inode=%lu cannot detect if file was rotated: %s",
1034+
"inode=%"PRIu64" cannot detect if file was rotated: %s",
10371035
file->inode, file->name);
10381036
return -1;
10391037
}
@@ -1054,7 +1052,7 @@ int flb_tail_file_is_rotated(struct flb_tail_config *ctx,
10541052
return FLB_FALSE;
10551053
}
10561054

1057-
flb_plg_debug(ctx->ins, "inode=%lu rotated: %s => %s",
1055+
flb_plg_debug(ctx->ins, "inode=%"PRIu64" rotated: %s => %s",
10581056
file->inode, file->name, name);
10591057

10601058
flb_free(name);
@@ -1222,13 +1220,13 @@ int flb_tail_file_rotated(struct flb_tail_file *file)
12221220
return -1;
12231221
}
12241222

1225-
flb_plg_debug(ctx->ins, "inode=%lu rotated %s -> %s",
1223+
flb_plg_debug(ctx->ins, "inode=%"PRIu64" rotated %s -> %s",
12261224
file->inode, file->name, name);
12271225

12281226
/* Update local file entry */
12291227
tmp = file->name;
12301228
flb_tail_file_name_dup(name, file);
1231-
flb_plg_info(ctx->ins, "inode=%lu handle rotation(): %s => %s",
1229+
flb_plg_info(ctx->ins, "inode=%"PRIu64" handle rotation(): %s => %s",
12321230
file->inode, tmp, file->name);
12331231
if (file->rotated == 0) {
12341232
file->rotated = time(NULL);
@@ -1321,7 +1319,8 @@ int flb_tail_file_purge(struct flb_input_instance *ins,
13211319
ret = fstat(file->fd, &st);
13221320
if (ret == 0) {
13231321
flb_plg_debug(ctx->ins,
1324-
"inode=%lu purge rotated file %s (offset=%lu / size = %lu)",
1322+
"inode=%"PRIu64" purge rotated file %s " \
1323+
"(offset=%lu / size = %"PRIu64")",
13251324
file->inode, file->name, file->offset, st.st_size);
13261325
if (file->pending_bytes > 0 && flb_input_buf_paused(ins)) {
13271326
flb_plg_warn(ctx->ins, "purged rotated file while data "
@@ -1331,7 +1330,7 @@ int flb_tail_file_purge(struct flb_input_instance *ins,
13311330
}
13321331
else {
13331332
flb_plg_debug(ctx->ins,
1334-
"inode=%lu purge rotated file %s (offset=%lu)",
1333+
"inode=%"PRIu64" purge rotated file %s (offset=%lu)",
13351334
file->inode, file->name, file->offset);
13361335
}
13371336

plugins/in_tail/tail_file_internal.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,9 @@ struct flb_tail_file {
3737
off_t size;
3838
off_t offset;
3939
off_t last_line;
40-
#ifdef _MSC_VER
41-
uint64_t inode;
42-
#else
43-
ino_t inode;
44-
ino_t link_inode;
40+
uint64_t inode;
41+
uint64_t link_inode;
4542
int is_link;
46-
#endif
4743
char *name; /* target file name given by scan routine */
4844
#if !defined(__linux) || !defined(FLB_HAVE_INOTIFY)
4945
char *real_name; /* real file name in the file system */

plugins/in_tail/tail_fs_inotify.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int debug_event_mask(struct flb_tail_config *ctx,
5858

5959
/* Print info into sds */
6060
if (file) {
61-
flb_sds_printf(&buf, "inode=%lu events: ", file->inode);
61+
flb_sds_printf(&buf, "inode=%"PRIu64" events: ", file->inode);
6262
}
6363
else {
6464
flb_sds_printf(&buf, "events: ");
@@ -126,7 +126,7 @@ static int tail_fs_add(struct flb_tail_file *file, int check_rotated)
126126

127127
name = flb_tail_file_name(file);
128128
if (!name) {
129-
flb_plg_error(ctx->ins, "inode=%lu cannot get real filename for inotify",
129+
flb_plg_error(ctx->ins, "inode=%"PRIu64" cannot get real filename for inotify",
130130
file->inode);
131131
return -1;
132132
}
@@ -145,7 +145,7 @@ static int tail_fs_add(struct flb_tail_file *file, int check_rotated)
145145
return -1;
146146
}
147147
file->watch_fd = watch_fd;
148-
flb_info("inotify_fs_add(): inode=%lu watch_fd=%i name=%s",
148+
flb_info("inotify_fs_add(): inode=%"PRIu64" watch_fd=%i name=%s",
149149
file->inode, watch_fd, file->name);
150150
return 0;
151151
}
@@ -191,14 +191,14 @@ static int tail_fs_event(struct flb_input_instance *ins,
191191
debug_event_mask(ctx, file, ev.mask);
192192

193193
if (ev.mask & IN_IGNORED) {
194-
flb_plg_debug(ctx->ins, "inode=%lu watch_fd=%i IN_IGNORED",
194+
flb_plg_debug(ctx->ins, "inode=%"PRIu64" watch_fd=%i IN_IGNORED",
195195
file->inode, ev.wd);
196196
return -1;
197197
}
198198

199199
/* Check file rotation (only if it has not been rotated before) */
200200
if (ev.mask & IN_MOVE_SELF && file->rotated == 0) {
201-
flb_plg_debug(ins, "inode=%lu rotated IN_MOVE SELF '%s'",
201+
flb_plg_debug(ins, "inode=%"PRIu64" rotated IN_MOVE SELF '%s'",
202202
file->inode, file->name);
203203

204204
/* A rotated file must be re-registered */
@@ -209,7 +209,7 @@ static int tail_fs_event(struct flb_input_instance *ins,
209209

210210
ret = fstat(file->fd, &st);
211211
if (ret == -1) {
212-
flb_plg_debug(ins, "inode=%lu error stat(2) %s, removing",
212+
flb_plg_debug(ins, "inode=%"PRIu64" error stat(2) %s, removing",
213213
file->inode, file->name);
214214
flb_tail_file_remove(file);
215215
return 0;
@@ -221,7 +221,7 @@ static int tail_fs_event(struct flb_input_instance *ins,
221221
if (ev.mask & IN_ATTRIB) {
222222
/* Check if the file have been deleted */
223223
if (st.st_nlink == 0) {
224-
flb_plg_debug(ins, "inode=%lu file has been deleted: %s",
224+
flb_plg_debug(ins, "inode=%"PRIu64" file has been deleted: %s",
225225
file->inode, file->name);
226226

227227
#ifdef FLB_HAVE_SQLDB
@@ -250,7 +250,7 @@ static int tail_fs_event(struct flb_input_instance *ins,
250250
return -1;
251251
}
252252

253-
flb_plg_debug(ctx->ins, "inode=%lu file truncated %s",
253+
flb_plg_debug(ctx->ins, "inode=%"PRIu64" file truncated %s",
254254
file->inode, file->name);
255255
file->offset = offset;
256256
file->buf_len = 0;
@@ -335,7 +335,7 @@ int flb_tail_fs_add(struct flb_tail_file *file)
335335

336336
ret = tail_fs_add(file, FLB_TRUE);
337337
if (ret == -1) {
338-
flb_plg_error(ctx->ins, "inode=%lu cannot register file %s",
338+
flb_plg_error(ctx->ins, "inode=%"PRIu64" cannot register file %s",
339339
file->inode, file->name);
340340
return -1;
341341
}
@@ -349,7 +349,7 @@ int flb_tail_fs_remove(struct flb_tail_file *file)
349349
return 0;
350350
}
351351

352-
flb_info("inotify_fs_remove(): inode=%lu watch_fd=%i",
352+
flb_info("inotify_fs_remove(): inode=%"PRIu64" watch_fd=%i",
353353
file->inode, file->watch_fd);
354354

355355
inotify_rm_watch(file->config->fd_notify, file->watch_fd);

0 commit comments

Comments
 (0)