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

tests/empty-hostname.sh fails: expected hostname "localhost" not found in logs #1268

Closed
mbiebl opened this issue Nov 20, 2016 · 6 comments · Fixed by #1271
Closed

tests/empty-hostname.sh fails: expected hostname "localhost" not found in logs #1268

mbiebl opened this issue Nov 20, 2016 · 6 comments · Fixed by #1271
Assignees
Milestone

Comments

@mbiebl
Copy link
Contributor

mbiebl commented Nov 20, 2016

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=844914

I'm getting a test-suite failure

======================================================================
------------------------------------------------------------
Test: ./empty-hostname.sh
------------------------------------------------------------
rsyslogd started with pid  7403
imdiag[13500]: mainqueue empty
expected hostname "localhost" not found in logs, rsyslog.out.log is:
2016-11-20T14:10:26.205937+01:00 foo rsyslogd: [origin software="rsyslogd" swVersion="8.23.0" x-pid="7403" x-info="http://www.rsyslog.com"] start
2016-11-20T14:10:28.238432+01:00 foo rsyslogd: [origin software="rsyslogd" swVersion="8.23.0" x-pid="7403" x-info="http://www.rsyslog.com"] exiting on signal 15.
FAIL empty-hostname.sh (exit status: 1)

To reproduce the issue setup a /etc/hosts like this

127.0.0.1	foo localhost

If one uses

127.0.0.1 localhost
127.0.1.1 foo

the test succeeds. So I asume it makes certain (incorrect) assumptions about how /etc/hosts is setup

rgerhards added a commit to rgerhards/rsyslog that referenced this issue Nov 20, 2016
@rgerhards
Copy link
Member

rgerhards commented Nov 20, 2016

I have added some doc to the test. The assumptions on the hostname are valid, the probable root cause is that the preload library is not loaded for some reason. This is also clear from the hostname being returned.

@rgerhards rgerhards self-assigned this Nov 20, 2016
@mbiebl
Copy link
Contributor Author

mbiebl commented Nov 20, 2016

I added some printf debug statements to runtime/net.c

Looking at getLocalHostname(), we do get an empty hostname from
gethostname() (from the overriden library) and at
https://github.com/rsyslog/rsyslog/blob/master/runtime/net.c#L1157

hnbuf is set to localhost (as expected).

At https://github.com/rsyslog/rsyslog/blob/master/runtime/net.c#L1164
dot is NULL so it calls gethostbyname() and iterates over the aliases.
This is where things go wrong. If I have an entry like this

127.0.0.1 foo localhost

fqdn is set to foo and this is what's returned from getLocalHostname.

@mbiebl
Copy link
Contributor Author

mbiebl commented Nov 20, 2016

On a related note: if gethostname() returns a non-emtpy string, why do we not use that name but set it to localhost at
https://github.com/rsyslog/rsyslog/blob/master/runtime/net.c#L1151

UPDATE: Forget what I said here. The != 0 check is testing the return code and not the string length. So all fine

@rgerhards rgerhards added this to the v8.24 milestone Nov 21, 2016
rgerhards added a commit to rgerhards/rsyslog that referenced this issue Nov 21, 2016
…name

If gethostname() returned "", we used "localhost" as mock-up hostname.
However, this caused problems depending on how the local system name was
actually configured.

We have changed the mock.up hostname to "localhost.empty-hostname" now
to clearly indicate the problem. Not only as a side effect, this also
fixes obtaining a different hostname.

closes rsyslog#1268
rgerhards added a commit to rgerhards/rsyslog that referenced this issue Nov 21, 2016
@rgerhards
Copy link
Member

Thanks, I was obviously too focussed on the gethostname() call. Using localhost as a default obviously also brings some confusion. I think we should rename it to localhost-empty-hostname, which would be an indicator of the real problem. I'll change the code accordingly and create a PR.

@rgerhards
Copy link
Member

Note: I have also reconfigured the debian buildbot slave to showcase that problem. So hostname-related issues are hopefully sooner detected in the future.

rgerhards added a commit to rgerhards/rsyslog that referenced this issue Nov 24, 2016
…name

If gethostname() returned "", we used "localhost" as mock-up hostname.
However, this caused problems depending on how the local system name was
actually configured.

We have changed the mock-up hostname to "localhost-empty-hostname" now
to clearly indicate the problem. Also, we make sure that we do no
accidently try to resolve the mock-up hostname.

closes rsyslog#1268
rgerhards added a commit to rgerhards/rsyslog that referenced this issue Nov 24, 2016
@lock
Copy link

lock bot commented Dec 27, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants