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

Modify the program to be run at boot time.

Improve first working version.
(Note: last version before the first test on the capri002.)
parent 87ba7f51
/root/metadata-collect-agent/target/x86_64-unknown-linux-musl/release/metadata-collect-agent
\ No newline at end of file
...@@ -54,8 +54,8 @@ nopython: main.cpp#$(EXE) ...@@ -54,8 +54,8 @@ nopython: main.cpp#$(EXE)
make fake_python.o make fake_python.o
g++ -O2 -g -Wno-unused-result -Wsign-compare -pthread -I/usr/include/python3.7 main.cpp fake_python.o -lcrypto -lfmt -o metadata-collect-agent g++ -O2 -g -Wno-unused-result -Wsign-compare -pthread -I/usr/include/python3.7 main.cpp fake_python.o -lcrypto -lfmt -o metadata-collect-agent
#-ln -f ../../metadata-collect-agent metadata-collect-agent #-ln -f ../../metadata-collect-agent metadata-collect-agent
-ln -f metadata-collect-agent ../../dracut.module/90metadata-collect/metadata-collect-agent #-ln -f metadata-collect-agent ../../dracut.module/90metadata-collect/metadata-collect-agent
-ln -f metadata-collect-agent ../../debian.package.unsafe/unsafe-boot-metadata-collect-agent/sbin/metadata-collect-agent #-ln -f metadata-collect-agent ../../debian.package.unsafe/unsafe-boot-metadata-collect-agent/sbin/metadata-collect-agent
%.cpp: %.pyx %.cpp: %.pyx
@echo "[Cython Compiling $^ -> $@]" @echo "[Cython Compiling $^ -> $@]"
...@@ -78,6 +78,11 @@ clean: ...@@ -78,6 +78,11 @@ clean:
-rm -f *.o -rm -f *.o
-rm -f -r build -rm -f -r build
-rm -f *.json -rm -f *.json
-rm -f /var/log/metadata_collect.log
-rm -f metadata-collect-agent
-rm -f ../../dracut.module/90metadata-collect/metadata-collect-agent
-rm -f ../../debian.package.unsafe/unsafe-boot-metadata-collect-agent/sbin/metadata-collect-agent
-rm -rf logs
.PHONY: all run nopython runnopython clean .PHONY: all run nopython runnopython clean
.PRECIOUS: %.cpp .PRECIOUS: %.cpp
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -5,6 +5,7 @@ from libcythonplus.list cimport cyplist ...@@ -5,6 +5,7 @@ from libcythonplus.list cimport cyplist
from libc.stdio cimport fprintf, fopen, fclose, fread, fwrite, FILE, stdout, printf, ferror from libc.stdio cimport fprintf, fopen, fclose, fread, fwrite, FILE, stdout, printf, ferror
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 stdlib.stat cimport Stat, dev_t from stdlib.stat cimport Stat, dev_t
from stdlib.digest cimport MessageDigest, md5sum, sha1sum, sha256sum, sha512sum from stdlib.digest cimport MessageDigest, md5sum, sha1sum, sha256sum, sha512sum
...@@ -249,53 +250,69 @@ cdef cypclass SymlinkNode(Node): ...@@ -249,53 +250,69 @@ cdef cypclass SymlinkNode(Node):
cdef int start(string path) nogil: cdef int start(string path) nogil:
global scheduler
scheduler = Scheduler()
ignore_paths = cyplist[string]() cdef char* program_name = "fluentbit"
ignore_paths.append(b'/opt/slapgrid') cdef char* arg1 = "-e"
ignore_paths.append(b'/srv/slapgrid') cdef char* arg2 = "/home/test/work/90metadata-collect/fluentbit_wendelin.so"
cdef char* arg3 = "-c"
cdef char* arg4 = "/home/test/work/90metadata-collect/flb.conf"
cdef pid_t child_pid = -1 # DEBUG
child_pid = fork() # DEBUG
cdef int err
if child_pid == 0: # CHILD
err = execlp("/home/test/work/90metadata-collect/fluentbit", program_name, arg1, arg2, arg3, arg4, 0)
printf("ERROR with execlp() in CHILD: %d\n", err)
else: # PARENT
dev_whitelist_paths = cyplist[string]() global scheduler
dev_whitelist_paths.append(b'.') scheduler = Scheduler()
dev_whitelist_paths.append(b'/')
dev_whitelist_paths.append(b'/boot')
dev_whitelist = cyplist[dev_t]() ignore_paths = cyplist[string]()
for p in dev_whitelist_paths: ignore_paths.append(b'/opt/slapgrid')
p_stat = Stat(p) ignore_paths.append(b'/srv/slapgrid')
if p_stat is not NULL:
p_dev = p_stat.st_data.st_dev
dev_whitelist.append(p_dev)
node = make_node(path, path) dev_whitelist_paths = cyplist[string]()
if node is NULL: dev_whitelist_paths.append(b'.')
return -1 dev_whitelist_paths.append(b'/')
dev_whitelist_paths.append(b'/boot')
active_node = activate(consume node) 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)
active_node.build_node(NULL, consume dev_whitelist, consume ignore_paths) node = make_node(path, path)
if node is NULL:
return -1
scheduler.finish() active_node = activate(consume node)
node = consume active_node active_node.build_node(NULL, consume dev_whitelist, consume ignore_paths)
result = fopen('result.json', 'w') scheduler.finish()
if result is NULL:
return -1
fprintf(result, '[\n') node = consume active_node
node.write_node(result)
fprintf(result, ' {}\n]\n')
fclose(result) #""" # DEBUG
result = fopen('/var/log/metadata_collect.log', 'w')
if result is NULL:
return -1
del scheduler fprintf(result, '[\n')
node.write_node(result)
fprintf(result, ' {}\n]\n')
fprintf(result, 'fluentbit_end\n')
return 0 fclose(result)
#""" # DEBUG
del scheduler
return 0
cdef public int main() nogil: cdef public int main() nogil:
return start(<char*>'.') return start(<char*>'.')
def python_main(): #def python_main():
start(<char*>'.') # start(<char*>'.')
cdef extern from *:
ctypedef int pid_t
cdef extern from "<unistd.h>" nogil:
int execvp(const char *file, char *const argv[])
int execlp(const char *file, const char *arg, ...)
pid_t fork()
unsigned int sleep(unsigned int seconds)
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