Commit febc2a2d authored by Ophélie Gagnard's avatar Ophélie Gagnard

src/main.*: Add the possibility to give the paths of the fluentbit files...

src/main.*: Add the possibility to give the paths of the fluentbit files (exec, lib, conf...) and the log file as an argument of the program.
parent a6ec4e5f
This diff is collapsed.
......@@ -266,25 +266,22 @@ cdef cypclass SymlinkNode(Node):
fwrite(self.formatted.data(), 1, self.formatted.size(), stream)
cdef int start(const char *path) nogil:
cdef int start(const char *path_to_scan, const char *fb_exec_path, const char *fb_lib_path, const char *fb_conf_path, const char *log_path) nogil:
printf("TEST TEST TEST TEST TEST\n\n") # DEBUG
# TODO replace 4096 by PATH_MAX (yet it will not be perfect)
cdef char resolved_path[4096]
cdef char resolved_scan_path[4096]
cdef char resolved_log_path[4096]
cdef pid_t wait_error = -1 # DEBUG
cdef char* program_name = "fluentbit"
cdef char* arg1 = "-e"
cdef char* arg2 = "/etc/fluentbit_wendelin.so"
cdef char* arg3 = "-c"
cdef char* arg4 = "/etc/flb.conf"
cdef char* program_name = <char*>"fluent-bit"
cdef pid_t child_pid = -1 # DEBUG
child_pid = fork() # DEBUG
cdef int err
#cdef char ip_address[100]
#cdef FILE *address_path = fopen("/sys/class/net/ens3/address", "r")
if child_pid == 0: # CHILD
err = execlp("/sbin/fluent-bit", program_name, arg1, arg2, arg3, arg4, 0)
err = execlp(fb_exec_path, program_name, <char*>"-e", fb_lib_path, <char*>"-c", fb_conf_path, 0)
fprintf(stderr, "ERROR with execlp() in CHILD: %d\n", err)
else: # PARENT
printf("WELCOME TO PARENT\n\n") # DEBUG
......@@ -304,7 +301,7 @@ cdef int start(const char *path) nogil:
dev_whitelist_paths.append(b'/boot/efi')
dev_whitelist_paths.append(b'/root')
dev_whitelist_paths.append(b'/sysroot')
dev_whitelist_paths.append(path)
dev_whitelist_paths.append(path_to_scan)
dev_whitelist = cyplist[dev_t]()
for p in dev_whitelist_paths:
......@@ -313,11 +310,11 @@ cdef int start(const char *path) nogil:
p_dev = p_stat.st_data.st_dev
dev_whitelist.append(p_dev)
realpath(path, resolved_path)
fprintf(stderr, resolved_path) # DEBUG
realpath(path_to_scan, resolved_scan_path)
fprintf(stderr, resolved_scan_path) # DEBUG
fprintf(stderr, "\n") # DEBUG
fflush(stderr) # DEBUG
node = make_node(resolved_path, resolved_path)
node = make_node(resolved_scan_path, resolved_scan_path)
if node is NULL:
return -1
......@@ -327,7 +324,11 @@ cdef int start(const char *path) nogil:
node = consume active_node
#""" # DEBUG
result = fopen('/var/log/metadata_collect.log', 'w')
realpath(log_path, resolved_log_path)
fprintf(stderr, resolved_log_path) # DEBUG
fprintf(stderr, "\n") # DEBUG
fflush(stderr) # DEBUG
result = fopen(resolved_log_path, 'w')
if result is NULL:
fprintf(stderr, 'Error creating the log file.\n') # DEBUG
fflush(stderr)
......@@ -357,10 +358,20 @@ cdef int start(const char *path) nogil:
return 0
cdef public int main(int argc, char* argv[]) nogil:
if argc >= 2:
return start(<char*>argv[1])
else:
return start(<char*>'/')
cdef char* path_to_scan = "/"
cdef char* fb_exec_path = "/sbin/fluent-bit"
cdef char* fb_lib_path = "/etc/fluentbit_wendelin.so"
cdef char* fb_conf_path = "/etc/flb.conf"
cdef char* log_path = "/var/log/metadata_collect.log"
if argc == 2:
path_to_scan = <char*>argv[1]
elif argc == 6:
path_to_scan = <char*>argv[1]
fb_exec_path = <char*>argv[2]
fb_lib_path = <char*>argv[3]
fb_conf_path = <char*>argv[4]
log_path = <char*>argv[5]
return start(<char*>path_to_scan, <char*>fb_exec_path, <char*>fb_lib_path, <char*>fb_conf_path, <char*>log_path)
#def python_main():
# start(<char*>'.')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment