bakaid commented on a change in pull request #604: MINIFICPP-926 Create nanofi 
tailfile processor for tailing file by configurable chunk size
URL: https://github.com/apache/nifi-minifi-cpp/pull/604#discussion_r300647026
 
 

 ##########
 File path: nanofi/src/api/ecu.c
 ##########
 @@ -0,0 +1,130 @@
+
+#include "api/ecu.h"
+#include "api/nanofi.h"
+#include "core/string_utils.h"
+#include "core/cstructs.h"
+#include "core/file_utils.h"
+#include "core/flowfiles.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <limits.h>
+#include <signal.h>
+#include <sys/stat.h>
+
+nifi_instance * instance = NULL;
+standalone_processor * proc = NULL;
+flow_file_list ff_list;
+int curr_offset = 0;
+int stopped = 0;
+
+void signal_handler(int signum) {
+    if (signum == SIGINT || signum == SIGTERM) {
+        stopped = 1;
+    }
+}
+
+void set_offset(int offset) {
+    curr_offset = offset;
+}
+
+int get_offset() {
+    return curr_offset;
+}
+
+void on_trigger_tailfilechunk(processor_session * ps, processor_context * ctx) 
{
+    char file_path[4096] = {0};
+    char chunk_size[50] = {0};
+
+    free_flow_file_list(&ff_list);
+
+    if (get_property(ctx, "file_path", file_path, sizeof(file_path)) != 0) {
+        return;
+    }
+
+    if (get_property(ctx, "chunk_size", chunk_size, sizeof(chunk_size)) != 0) {
+        return;
+    }
+
+    errno = 0;
+    unsigned long chunk_size_value = strtol(chunk_size, NULL, 10);
+
+    if (errno == ERANGE || chunk_size_value == LONG_MAX || chunk_size_value == 
LONG_MIN) {
 
 Review comment:
   You are comparing an unsigned long to LONG_MAX and LONG_MIN (this is related 
to the previous comment). By the way, strtoul returning ULONG_MAX without errno 
being set to ERANGE means that the unsigned long was indeed ULONG_MAX, and not 
an error. However, errno being EINVAL means that no conversion could be 
performed, but the current code does not treat this as an error (unfortunately 
EINVAL is not required to be set by the standard, but is done anyway by any 
reasonable implementation).
   So this condition should really only be:
   `if (errno != 0)`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to