{"action":"opened","issue":{"url":"https://api.github.com/repos/rsyslog/rsyslog/issues/1090","repository_url":"https://api.github.com/repos/rsyslog/rsyslog","labels_url":"https://api.github.com/repos/rsyslog/rsyslog/issues/1090/labels{/name}","comments_url":"https://api.github.com/repos/rsyslog/rsyslog/issues/1090/comments","events_url":"https://api.github.com/repos/rsyslog/rsyslog/issues/1090/events","html_url":"https://github.com/rsyslog/rsyslog/issues/1090","id":165292343,"number":1090,"title":"reopenOnTruncate is not obeyed unless a state file was loaded","user":{"login":"orls","id":155430,"avatar_url":"https://avatars.githubusercontent.com/u/155430?v=3","gravatar_id":"","url":"https://api.github.com/users/orls","html_url":"https://github.com/orls","followers_url":"https://api.github.com/users/orls/followers","following_url":"https://api.github.com/users/orls/following{/other_user}","gists_url":"https://api.github.com/users/orls/gists{/gist_id}","starred_url":"https://api.github.com/users/orls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orls/subscriptions","organizations_url":"https://api.github.com/users/orls/orgs","repos_url":"https://api.github.com/users/orls/repos","events_url":"https://api.github.com/users/orls/events{/privacy}","received_events_url":"https://api.github.com/users/orls/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-13T10:51:22Z","updated_at":"2016-07-13T10:51:22Z","closed_at":null,"body":"`imfile` inputs with the `reopenOnTruncate` flag do not reopen when the file is truncated, unless rsyslogd had a state file present for the relevant file when it started.\r\n\r\nThis doesn't seem to be a problem with the actual usage of `reopenOnTruncate` flag inside the stream objects; instead, it seems that in these cases, `imfile` is not correctly constructing the streams, or passing the flag value to them, in this case. This was confirmed by patching in some extra debug logging in stream.c -- the stream obj sees a value of `false` for the relevant property within `strmHandleEOFMonitor`.\r\n\r\nThis has been observed on 8.16.0 and 8.20.0\r\n\r\n**_Steps to reproduce:_**\r\n\r\nUsing a minimal `rsyslog.conf` file:\r\n\r\n```\r\nmodule(load=\"imfile\")\r\n\r\ntemplate(name=\"a\" type=\"list\") {\r\n         property(name=\"msg\")\r\n         constant(value=\"\\n\")\r\n}\r\n\r\nruleset(name=\"a\") {\r\n    action(type=\"omfile\" file=\"/var/log/rsyslogd-out.log\" template=\"a\")\r\n}\r\n\r\ninput(type=\"imfile\" file=\"/var/log/a.log\" tag=\"info\"  severity=\"info\"  facility=\"local0\" reopenOnTruncate=\"on\" ruleset=\"a\")\r\n```\r\n\r\nRun rsyslog, send content to the file then truncate it:\r\n\r\n```sh\r\n/usr/local/sbin/rsyslogd\r\n\r\necho 1 >> /var/log/a.log\r\necho 2 >> /var/log/a.log\r\n\r\ntruncate -s 0 /var/log/a.log\r\n\r\necho 3 >> /var/log/a.log\r\necho 4 >> /var/log/a.log\r\necho 5 >> /var/log/a.log\r\n\r\ncat /var/log/rsyslogd-out.log\r\n```\r\n\r\n**_Expected Output_:**\r\n\r\n`/var/log/rsyslogd-out.log` should contain:\r\n\r\n```\r\n1\r\n2\r\n3\r\n4\r\n5\r\n```\r\n\r\n**_Actual Output_:**\r\n`/var/log/rsyslogd-out.log` contains:\r\n\r\n```\r\n1\r\n2\r\n5\r\n```\r\n\r\nFrom this, you can see that rsyslogd is behaving as if the reopenOnTruncate flag was never added. It looks exactly like #511 – even though this version includes #662 and the relevant config.\r\n\r\nHowever... repeating the test _with state files present_ shows the expected behaviour. A simple way to demonstrate this is to stop and start rsyslogd before the test.\r\n\r\nOn a completely clean environment, run the following:\r\n\r\n```sh\r\n/usr/local/sbin/rsyslogd\r\nkill $(cat /var/run/rsyslogd.pid)\r\n/usr/local/sbin/rsyslogd\r\n\r\necho 1 >> /var/log/a.log\r\necho 2 >> /var/log/a.log\r\n\r\ntruncate -s 0 /var/log/a.log\r\n\r\necho 3 >> /var/log/a.log\r\necho 4 >> /var/log/a.log\r\necho 5 >> /var/log/a.log\r\n\r\ncat /var/log/rsyslogd-out.log\r\n```\r\n\r\nThis yields the expected output (numbers 1 to 5)\r\n\r\nWe can prove that it's related to state files by repeating that test, but cleaning up state files before the restart:\r\n\r\n```sh\r\n/usr/local/sbin/rsyslogd\r\nkill $(cat /var/run/rsyslogd.pid)\r\nsleep 1 # wait for state files to be written\r\nrm /imfile*\r\n/usr/local/sbin/rsyslogd\r\n\r\necho 1 >> /var/log/a.log\r\necho 2 >> /var/log/a.log\r\n\r\ntruncate -s 0 /var/log/a.log\r\n\r\necho 3 >> /var/log/a.log\r\necho 4 >> /var/log/a.log\r\necho 5 >> /var/log/a.log\r\n\r\ncat /var/log/rsyslogd-out.log\r\n```\r\n\r\nThis again shows the 'bad' output, missing `3` and `4`\r\n\r\n"}}
{"actor":{"display_login":"orls"}}