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)
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
#-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 ../../debian.package.unsafe/unsafe-boot-metadata-collect-agent/sbin/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
%.cpp: %.pyx
@echo "[Cython Compiling $^ -> $@]"
......@@ -78,6 +78,11 @@ clean:
-rm -f *.o
-rm -f -r build
-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
.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
from libc.stdio cimport fprintf, fopen, fclose, fread, fwrite, FILE, stdout, printf, ferror
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.digest cimport MessageDigest, md5sum, sha1sum, sha256sum, sha512sum
......@@ -249,53 +250,69 @@ cdef cypclass SymlinkNode(Node):
cdef int start(string path) nogil:
global scheduler
scheduler = Scheduler()
ignore_paths = cyplist[string]()
ignore_paths.append(b'/opt/slapgrid')
ignore_paths.append(b'/srv/slapgrid')
cdef char* program_name = "fluentbit"
cdef char* arg1 = "-e"
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]()
dev_whitelist_paths.append(b'.')
dev_whitelist_paths.append(b'/')
dev_whitelist_paths.append(b'/boot')
global scheduler
scheduler = Scheduler()
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)
ignore_paths = cyplist[string]()
ignore_paths.append(b'/opt/slapgrid')
ignore_paths.append(b'/srv/slapgrid')
node = make_node(path, path)
if node is NULL:
return -1
dev_whitelist_paths = cyplist[string]()
dev_whitelist_paths.append(b'.')
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')
if result is NULL:
return -1
scheduler.finish()
fprintf(result, '[\n')
node.write_node(result)
fprintf(result, ' {}\n]\n')
node = consume active_node
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:
return start(<char*>'.')
def python_main():
start(<char*>'.')
#def python_main():
# 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