Commit 005d12c5 authored by Ophélie Gagnard's avatar Ophélie Gagnard

Send a better data structure to Wendelin. Send a string which is json-compliant again.

parent 036bdd8e
......@@ -2,7 +2,7 @@
from libcythonplus.list cimport cyplist
from libc.stdio cimport fprintf, fopen, fclose, fread, fwrite, FILE, stdout, stderr, printf, ferror
from libc.stdio cimport fprintf, fopen, fclose, fread, fwrite, FILE, stdout, stderr, printf, ferror, fscanf, fflush
from runtime.runtime cimport SequentialMailBox, BatchMailBox, NullResult, Scheduler
from runtime.unistd cimport pid_t, execlp, fork, sleep
......@@ -14,6 +14,8 @@ from stdlib.fmt cimport sprintf
from stdlib.string cimport string
from stdlib.dirent cimport DIR, struct_dirent, opendir, readdir, closedir
from posix.stdlib cimport realpath
from posix.unistd cimport readlink
......@@ -40,9 +42,8 @@ cdef cypclass Node activable:
void format_node(self):
self.formatted = sprintf("""\
{
"%s": {
"stat": %s
}
"path": "%s",
"stat": %s
},
""",
self.path,
......@@ -128,7 +129,6 @@ cdef cypclass DirNode(Node):
cdef enum:
BUFSIZE = 64 * 1024
cdef cypclass FileNode(Node):
string md5_data
string sha1_data
......@@ -194,14 +194,13 @@ cdef cypclass FileNode(Node):
else:
self.formatted = sprintf("""\
{
"%s": {
"stat": %s,
"digests": {
"md5": "%s",
"sha1": "%s",
"sha256": "%s",
"sha512": "%s"
}
"path": "%s",
"stat": %s,
"hash": {
"md5": "%s",
"sha1": "%s",
"sha256": "%s",
"sha512": "%s"
}
},
""",
......@@ -235,10 +234,9 @@ cdef cypclass SymlinkNode(Node):
else:
self.formatted = sprintf("""\
{
"%s": {
"stat": %s,
"target": "%s"
}
"path": "%s",
"stat": %s,
"target": "%s"
},
""",
self.path,
......@@ -250,21 +248,25 @@ cdef cypclass SymlinkNode(Node):
fwrite(self.formatted.data(), 1, self.formatted.size(), stream)
cdef int start(string path) nogil:
cdef int start(const char *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 pid_t wait_error = -1 # DEBUG
cdef char* program_name = "fluentbit"
cdef char* arg1 = "-e"
cdef char* arg2 = "/etc/fluentbit_wendelin.so"
cdef char* arg2 = "flb/fluentbit_wendelin.so"
cdef char* arg3 = "-c"
cdef char* arg4 = "/etc/flb.conf"
cdef char* arg4 = "flb/flb.conf"
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("flb/fluent-bit", program_name, arg1, arg2, arg3, arg4, 0)
fprintf(stderr, "ERROR with execlp() in CHILD: %d\n", err)
else: # PARENT
......@@ -290,11 +292,20 @@ cdef int start(string path) nogil:
if p_stat is not NULL:
p_dev = p_stat.st_data.st_dev
dev_whitelist.append(p_dev)
node = make_node(path, path)
fprintf(stderr, "test 001\n") # DEBUG
fflush(stderr) # DEBUG
realpath(path, resolved_path)
fprintf(stderr, resolved_path) # DEBUG
fprintf(stderr, "\n") # DEBUG
fflush(stderr) # DEBUG
node = make_node(resolved_path, resolved_path)
if node is NULL:
return -1
fprintf(stderr, "test 002\n") # DEBUG
fflush(stderr) # DEBUG
active_node = activate(consume node)
active_node.build_node(NULL, consume dev_whitelist, consume ignore_paths)
......@@ -310,7 +321,10 @@ cdef int start(string path) nogil:
printf("WRITE_NOTE STAGE\n\n") # DEBUG
fscanf(address_path, "%s", ip_address)
fclose(address_path)
fprintf(result, '[\n')
fprintf(result, '"%s",\n', ip_address)
node.write_node(result)
fprintf(result, ' {}\n]\n')
fprintf(result, 'fluentbit_end\n')
......@@ -319,12 +333,10 @@ cdef int start(string path) nogil:
#""" # DEBUG
del scheduler
fprintf(stderr, "WAITING [error version]\n\n")
printf("WAITING...\n\n")
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 [error version]\n\n")
printf("WAITING ENDS NOW!\n\n")
fprintf(stderr, "WAITING ENDS\n\n")
return 0
......
This diff is collapsed.
This diff is collapsed.
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