in_tail: support rename detection on OSX
@@ -753,16 +753,21 @@ char *flb_tail_file_name(struct flb_tail_file *file)
ssize_t s;
char tmp[128];
char *buf;
+#ifdef __APPLE__
+ char path[PATH_MAX];
+#endif
- ret = snprintf(tmp, sizeof(tmp) - 1, "/proc/%i/fd/%i", getpid(), file->fd);
- if (ret == -1) {
+ buf = flb_malloc(PATH_MAX);
+ if (!buf) {
flb_errno();
return NULL;
}
- buf = flb_malloc(PATH_MAX);
- if (!buf) {
+#ifdef __linux__
+ ret = snprintf(tmp, sizeof(tmp) - 1, "/proc/%i/fd/%i", getpid(), file->fd);
+ if (ret == -1) {
flb_errno();
+ flb_free(buf);
return NULL;
}
@@ -774,6 +779,21 @@ char *flb_tail_file_name(struct flb_tail_file *file)
}
buf[s] = '\0';
+#elif __APPLE__
+ int len;
+
+ ret = fcntl(file->fd, F_GETPATH, path);
+ if (ret == -1) {
+ flb_errno();
+ flb_free(buf);
+ return NULL;
+ }
+
+ len = strlen(path);
+ memcpy(buf, path, len);
+ buf[len] = '\0';
+#endif
+
return buf;
}
