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

Syslog support #292

Merged
merged 1 commit into from
Jun 12, 2023
Merged

Syslog support #292

merged 1 commit into from
Jun 12, 2023

Conversation

vvviperrr
Copy link
Contributor

syslog logging is useful in embedded applications, e.g in buildroot software

@rfjakob
Copy link
Owner

rfjakob commented Jun 11, 2023

Hi, thanks for the PR!

But first I have to ask a stupid question: Why is this better than piping stdout and stderr to logger(1)?

@vvviperrr
Copy link
Contributor Author

Hi, thanks for the PR!

But first I have to ask a stupid question: Why is this better than piping stdout and stderr to logger(1)?

Hi. The main reason - support different syslog priorities. Sure, we can achieve this via piping earlyoom's stdout & stderr in different logger instances with different facilities\levels, but this trick is really ugly.
something like this (example from busybox sysctl script)

	xargs -0 -r -n 1 readlink -f | {
		prog_status="OK"
		while :; do
			read -r file || {
				echo "$prog_status" >&4
				break
			}
			echo "* Applying $file ..."
			/sbin/sysctl -p "$file" $SYSCTL_ARGS || prog_status="FAIL"
		done 2>&1 >&3 | /usr/bin/logger -t sysctl -p kern.err
	} 3>&1 | /usr/bin/logger -t sysctl -p kern.info

the things become more complicated, when u need start earlyoom via start-stop-daemon.

so patching earlyoom code is just handy (by adding syslog param in default conf file) & portable solution.

@rfjakob
Copy link
Owner

rfjakob commented Jun 12, 2023

Ok, understood. I will accept syslog support.

Copy link
Owner

@rfjakob rfjakob left a comment

Choose a reason for hiding this comment

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

Code looks clean but a little over-engineered :)

  1. I don't think enum LOG_LEVEL is needed. Just use the syslog levels directly.
  2. I don't think log_level_stream, log_level_color, log_level_syslog are needed. Instead, add stream, color parameters to logger.


void earlyoom_syslog_init(void)
{
if (!use_syslog) {
Copy link
Owner

Choose a reason for hiding this comment

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

Do we need this if?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just double-init check, which is does not leads to any problems, but anyway.

main.c Outdated
@@ -123,7 +123,7 @@ int main(int argc, char* argv[])
meminfo_t m = parse_meminfo();

int c;
const char* short_opt = "m:s:M:S:kingN:dvr:ph";
const char* short_opt = "m:s:M:S:kingN:Ldvr:ph";
Copy link
Owner

Choose a reason for hiding this comment

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

Please use --syslog instead of -L to be more explicit

Useful in embedded applications.

Signed-off-by: Konstantin Menyaev <KAMenyaev@sberdevices.ru>
@rfjakob rfjakob merged commit 848653f into rfjakob:master Jun 12, 2023
@rfjakob
Copy link
Owner

rfjakob commented Jun 12, 2023

I merged this, thanks. Two more things if you have time:

  1. Can you add --syslog to https://github.com/rfjakob/earlyoom/blob/master/MANPAGE.md

  2. The startup messages still go to stdout, seems to be they should be going to syslog as well:

$ ./earlyoom --syslog
earlyoom v1.7-36-g848653f
mem total: 23881 MiB, user mem total: 21593 MiB, swap total: 8191 MiB
sending SIGTERM when mem <= 10.00% and swap <= 10.00%,
        SIGKILL when mem <=  5.00% and swap <=  5.00%

rfjakob added a commit that referenced this pull request Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants