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