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

logger: target server required if using port option #2684

Open
systemdlete opened this issue Jan 6, 2024 · 1 comment
Open

logger: target server required if using port option #2684

systemdlete opened this issue Jan 6, 2024 · 1 comment

Comments

@systemdlete
Copy link

systemdlete commented Jan 6, 2024

Actual Behavior:
A call to logger such as

logger -P 513 This is a test message

does not work. It seems that the call MUST include the target syslog server if the port parameter (-P) is specified:

logger -n targserv -P 513 This is a test message

works.

Expected behavior:
Calls to logger specifying a port number should not require that the target server be specified. This is useful for performing local testing of, say, a new ruleset in rsyslog without having to type out the name or address of the target syslog server. The current behavior of logger is not indicated explicitly in the current documentation for logger.

Environment:
devuan daedalus (debian bookworm) / rsyslog 8.2302.0 / logger 2.38.1
devaun chimaera (debian bullseye) / rsyslog 8.2102.0 / logger 2.36.1
possibly other configurations, untested
THERE IS NO SYSTEMD ON DEVUAN

Error Handling;
If the current behavior is intentional, then the user should be alerted to the need to specify a target syslog server with an error message clearly stating this.

If the current behavior is not intentional, then the program should handle the invocation without an error and make its best attempt to send the log message to a default syslog server. (See my comment about this, below.) If, for whatever reason, logger cannot locate a working default syslogger on the local system, then it should error out.

BTW, it is understood that the default UDP protocol does not guarantee delivery of a log message. But if the message is simply headed to the syslog on the local host, it should be able to detect the presence or lack thereof since the facilities are on the same host.

Documentation:
If the current behavior is intentional, then the documentation for logger should be explicit in stating that the syslog server option (-n) MUST be provided if the port (-P) option is specified. This should be pointed out in the paragraph explaining the -P option (and possibly the -n option).

Otherwise, if the current behavior is not intentional, it should be corrected to accept the local syslog server by default. If there are multiple instances of a syslogger running on the local system, then the default should be the same as the default address of the local host. If the default address can not be deduced by fairly straightforward hints and assumptions, then the user should be directed to specify a target. Again, this should be pointed out in the paragraph explaining the -P option in the logger documentation.

If none of this is possible due to support issues for unusual system configurations, the documentation STILL needs to be updated to reflect this.

In conclusion, the documentation needs revision under any circumstances. Too much time is wasted running this issue down when returning to work involving logger calls after long periods of doing other things; it is too difficult to remember this (implicit?) requirement.

@karelzak
Copy link
Collaborator

It seems the code in the logger to connect the server is ready (as it uses getaddrinfo() where NULL as the node is expected to get loopback interface address), but it's triggered only if the server name is specified.

It seems a trivial patch may improve it:

diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index e1d270de8..e35220a16 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -923,7 +923,7 @@ static void generate_syslog_header(struct logger_ctl *const ctl)
 /* just open, nothing else */
 static void __logger_open(struct logger_ctl *ctl)
 {
-       if (ctl->server) {
+       if (ctl->server || ctl->port) {
                ctl->fd = inet_socket(ctl->server, ctl->port, &ctl->socket_type);
        } else {
                if (!ctl->unix_socket)

The ideal is to use strace to see what happens.

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

No branches or pull requests

2 participants