Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daemon: decouple init logic from main loop #699

Closed
wants to merge 1 commit into from

Conversation

ngortheone
Copy link
Contributor

main() func contained both initialization and main loop logic. This made certain operations like restarting problematic and required dirty hacks in form of goto jumps.

This commit moves the main loop logic into daemon_eventloop(), cleans up main, and makes restart logic clear: daemon_mainloop() is run in a loop with a restart condition checked at the end.

@ngortheone
Copy link
Contributor Author

Kyua tests are passing

 make
rm -f .depend
echo daemon.full: /usr/lib/libc.a /usr/lib/libutil.a >> .depend
cc  -O2 -pipe -fno-common -march=znver3  -fPIE -mretpoline -g -gz=zlib -MD  -MF.depend.daemon.o -MTdaemon.o -std=gnu99 -Wno-format-zero-length -fstack-protector-strong -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wunused-parameter -Wcast-align -Wstrict-prototypes -Wchar-subscripts -Wnested-externs -Wold-style-definition -Wno-pointer-sign -Wdate-time -Wmissing-variable-declarations -Wthread-safety -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Wno-error=unused-but-set-variable -Wno-error=array-parameter -Wno-error=deprecated-non-prototype -Wno-error=unused-but-set-parameter  -Qunused-arguments    -c daemon.c -o daemon.o
cc -O2 -pipe -fno-common -march=znver3 -fPIE -mretpoline -g -gz=zlib -std=gnu99 -Wno-format-zero-length -fstack-protector-strong -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wunused-parameter -Wcast-align -Wstrict-prototypes -Wchar-subscripts -Wnested-externs -Wold-style-definition -Wno-pointer-sign -Wdate-time -Wmissing-variable-declarations -Wthread-safety -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Wno-error=unused-but-set-variable -Wno-error=array-parameter -Wno-error=deprecated-non-prototype -Wno-error=unused-but-set-parameter -Qunused-arguments  -Wl,-znow -Wl,-zrelro -pie -Wl,-zretpolineplt   -o daemon.full daemon.o  -L/opt/ngor/src/git.freebsd.org/src/lib/libutil -lutil
objcopy --only-keep-debug daemon.full daemon.debug
objcopy --strip-debug --add-gnu-debuglink=daemon.debug  daemon.full daemon
===> tests (all)

[21:48:05] ngor@zen /home/ngor/src/git.freebsd.org/src/usr.sbin/daemon
> su -
Password:⏎  

root@zen:~ # cp -f /home/ngor/src/git.freebsd.org/src/usr.sbin/daemon/daemon /usr/sbin/daemon
root@zen:~ # chmod -w /usr/sbin/daemon
root@zen:~ # ^D
[21:48:23] ngor@zen /home/ngor/src/git.freebsd.org/src/usr.sbin/daemon
> cd tests/
[21:48:26] ngor@zen /home/ngor/src/git.freebsd.org/src/usr.sbin/daemon/tests
> kyua test
daemon_test:both_pidfile  ->  passed  [0.020s]
daemon_test:chdir  ->  passed  [0.013s]
daemon_test:child_pidfile  ->  passed  [0.013s]
daemon_test:child_pidfile_lock  ->  passed  [0.012s]
daemon_test:newsyslog  ->  passed  [0.441s]
daemon_test:output_file  ->  passed  [0.010s]
daemon_test:restart_child  ->  passed  [2.060s]
daemon_test:supervisor_pidfile  ->  passed  [0.014s]
daemon_test:supervisor_pidfile_lock  ->  passed  [0.012s]
daemon_test:title  ->  passed  [0.013s]
daemon_test:user  ->  skipped: Requires root privileges  [0.000s]

@ngortheone
Copy link
Contributor Author

cc @kevans91

Copy link
Contributor

@kevans91 kevans91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks pretty good, just a couple nits.

usr.sbin/daemon/daemon.c Outdated Show resolved Hide resolved
usr.sbin/daemon/daemon.c Show resolved Hide resolved
usr.sbin/daemon/daemon.c Outdated Show resolved Hide resolved
usr.sbin/daemon/daemon.c Outdated Show resolved Hide resolved
main() func contained both initialization and main loop logic.
This made certain operations like restarting problematic and
required dirty hacks in form of goto jumps.

This commit moves the main loop logic into daemon_eventloop(),
cleans up main, and makes restart logic clear: daemon_mainloop()
is run in a loop with a restart condition checked at the end.
freebsd-git pushed a commit that referenced this pull request Mar 23, 2023
main() func contained both initialization and main loop logic.
This made certain operations like restarting problematic and
required dirty hacks in form of goto jumps.

This commit moves the main loop logic into daemon_eventloop(),
cleans up main, and makes restart logic clear: daemon_mainloop()
is run in a loop with a restart condition checked at the end.

Reviewed by:	kevans
Pull Request:	#699
@ngortheone
Copy link
Contributor Author

merged by @kevans91 4c41f4a0d67fc93cfb07ad5287f02d024d19ef5a

@ngortheone ngortheone closed this Mar 23, 2023
@ngortheone ngortheone deleted the daemon_refactoring_4 branch March 23, 2023 03:21
@igalic
Copy link
Contributor

igalic commented Mar 23, 2023

there is no daemon_mainloop() any more, but the commit message still referenced it

bsdjhb pushed a commit to bsdjhb/cheribsd that referenced this pull request Apr 21, 2023
main() func contained both initialization and main loop logic.
This made certain operations like restarting problematic and
required dirty hacks in form of goto jumps.

This commit moves the main loop logic into daemon_eventloop(),
cleans up main, and makes restart logic clear: daemon_mainloop()
is run in a loop with a restart condition checked at the end.

Reviewed by:	kevans
Pull Request:	freebsd/freebsd-src#699
@emaste emaste added the merged label Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants