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

src: Do not run fluent-bit anymore.

Clean up.
parent 42085b4a
This diff is collapsed.
......@@ -252,120 +252,64 @@ cdef cypclass SymlinkNode(Node):
fwrite(self.formatted.data(), 1, self.formatted.size(), stream)
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
cdef int start(const char *path_to_scan, const char *log_path) nogil:
# TODO replace 4096 by PATH_MAX (yet it will not be perfect)
cdef char resolved_scan_path[4096]
cdef char resolved_log_path[4096]
cdef pid_t wait_error = -1 # DEBUG
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
fprintf(stdout, "path_to_scan: %s\n", path_to_scan)
fprintf(stdout, "fb_exec_path: %s\n", fb_exec_path)
fprintf(stdout, "fb_lib_path: %s\n", fb_lib_path)
fprintf(stdout, "fb_conf_path: %s\n", fb_conf_path)
fprintf(stdout, "log_path: %s\n", log_path)
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
sleep(2) # TODO error handling ; check if a wait can be made to wait for the child to perform execlp() (instead of the sleep)
global scheduler
scheduler = Scheduler()
ignore_paths = cyplist[string]()
ignore_paths.append(b'/opt/slapgrid')
ignore_paths.append(b'/srv/slapgrid')
dev_whitelist_paths = cyplist[string]()
dev_whitelist_paths.append(b'.')
dev_whitelist_paths.append(b'/')
dev_whitelist_paths.append(b'/boot/efi')
dev_whitelist_paths.append(b'/root')
dev_whitelist_paths.append(b'/sysroot')
dev_whitelist_paths.append(path_to_scan)
dev_whitelist = cyplist[dev_t]()
for p in dev_whitelist_paths:
p_stat = Stat(p)
if p_stat is not NULL:
p_dev = p_stat.st_data.st_dev
dev_whitelist.append(p_dev)
realpath(path_to_scan, resolved_scan_path)
fputs(resolved_scan_path, stderr) # DEBUG
fputs("\n", stderr) # DEBUG
fflush(stderr) # DEBUG
node = make_node(resolved_scan_path, resolved_scan_path)
if node is NULL:
return -1
active_node = activate(consume node)
active_node.build_node(NULL, consume dev_whitelist, consume ignore_paths)
scheduler.finish()
node = consume active_node
#""" # DEBUG
realpath(log_path, resolved_log_path)
fputs(resolved_log_path, stderr) # DEBUG
fputs("\n", stderr) # 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)
return -1
fprintf(stderr, 'Log opened successfully.\n') # DEBUG
fprintf(stderr, "WRITE_NOTE STAGE\n\n") # DEBUG
#fscanf(address_path, "%s", ip_address)
#fclose(address_path)
#fprintf(result, '{"mac_address": "%s"}\n', ip_address)
node.write_node(result)
fprintf(result, '{}\n')
fprintf(result, 'fluentbit_end\n')
fclose(result)
#""" # DEBUG
del scheduler
fprintf(stderr, "WAITING for fluent-bit to end\n\n")
wait_error = wait(NULL) # TODO improve this call (error handling, etc.)
#wait_error = waitpid(child_pid, NULL, 1) # TODO improve this call (error handling, etc.)
fprintf(stderr, "WAITING ENDS\n\n")
fflush(stderr) # DEBUG
return 0
global scheduler
scheduler = Scheduler()
ignore_paths = cyplist[string]()
ignore_paths.append(b'/opt/slapgrid')
ignore_paths.append(b'/srv/slapgrid')
dev_whitelist_paths = cyplist[string]()
dev_whitelist_paths.append(b'.')
dev_whitelist_paths.append(b'/')
dev_whitelist_paths.append(b'/boot/efi')
dev_whitelist_paths.append(b'/root')
dev_whitelist_paths.append(b'/sysroot')
dev_whitelist_paths.append(path_to_scan)
dev_whitelist = cyplist[dev_t]()
for p in dev_whitelist_paths:
p_stat = Stat(p)
if p_stat is not NULL:
p_dev = p_stat.st_data.st_dev
dev_whitelist.append(p_dev)
realpath(path_to_scan, resolved_scan_path)
node = make_node(resolved_scan_path, resolved_scan_path)
if node is NULL:
return -1
active_node = activate(consume node)
active_node.build_node(NULL, consume dev_whitelist, consume ignore_paths)
scheduler.finish()
node = consume active_node
realpath(log_path, resolved_log_path)
result = fopen(resolved_log_path, 'w')
if result is NULL:
fprintf(stderr, 'Error creating the log file.\n')
fflush(stderr)
return -1
node.write_node(result)
fclose(result)
del scheduler
return 0
cdef public int main(int argc, char* argv[]) nogil:
cdef char* path_to_scan = "/"
cdef char* fb_exec_path = "/sbin/fluent-bit"
cdef char* fb_lib_path = "/lib/libfluentbit_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]
if argc >= 3:
fb_exec_path = <char*>argv[2]
if argc >= 4:
fb_lib_path = <char*>argv[3]
if argc >= 5:
fb_conf_path = <char*>argv[4]
if argc >=6:
log_path = <char*>argv[5]
log_path = <char*>argv[2]
fputs(path_to_scan, stderr)
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*>'.')
return start(<char*>path_to_scan, <char*>log_path)
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