PostgreSQL services disappear after updating util-linux to 2.42

image

A downgrade of util-linux to 2.41.3 brings them back. This is with check-mk-agent 2.4.0p26.

ReleaseNotes: https://www.kernel.org/pub/linux/utils/util-linux/v2.42/v2.42-ReleaseNotes
ChangeLog: https://www.kernel.org/pub/linux/utils/util-linux/v2.42/v2.42-ChangeLog

When running /usr/x86_64-pc-linux-gnu/lib/check_mk_agent/plugins/mk_postgres.pymanually with util-linux 2.42 installed:

Traceback (most recent call last):
File “/usr/x86_64-pc-linux-gnu/lib/check_mk_agent/plugins/mk_postgres.py”, line 1355, in 
main()
~~~~^^
File “/usr/x86_64-pc-linux-gnu/lib/check_mk_agent/plugins/mk_postgres.py”, line 1350, in main
postgres.execute_all_queries()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File “/usr/x86_64-pc-linux-gnu/lib/check_mk_agent/plugins/mk_postgres.py”, line 368, in execute_all_queries
version = self.get_server_version()
File “/usr/x86_64-pc-linux-gnu/lib/check_mk_agent/plugins/mk_postgres.py”, line 231, in get_server_version
return float(“.”.join(version_as_string.split(“.”)[0:2]))
ValueError: could not convert string to float: ‘Letzte’

Or with english locale:

Traceback (most recent call last):
  File "/usr/x86_64-pc-linux-gnu/lib/check_mk_agent/plugins/mk_postgres.py", line 1355, in <module>
    main()
    ~~~~^^
  File "/usr/x86_64-pc-linux-gnu/lib/check_mk_agent/plugins/mk_postgres.py", line 1350, in main
    postgres.execute_all_queries()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/x86_64-pc-linux-gnu/lib/check_mk_agent/plugins/mk_postgres.py", line 368, in execute_all_queries
    version = self.get_server_version()
  File "/usr/x86_64-pc-linux-gnu/lib/check_mk_agent/plugins/mk_postgres.py", line 231, in get_server_version
    return float(".".join(version_as_string.split(".")[0:2]))
ValueError: could not convert string to float: 'Last'

Removing the "-", line from mk_postgres.py in

        base_cmd_list = [
            "su",
            "-",
            self.db_user,
            "-c",
            r"""PGPASSFILE=%s %s -X %s -A0 -F'%s' -f %s""",
        ]

restores the functionality with su from util-linux 2.42, though I guess it is there for a reason?

su - usually initializes the environment for the user.

How about changing the argument order?

According to the man page we should use

Usage:
 su [options] [-] [<user> [<argument>...]]

so maybe the correct code would be

        base_cmd_list = [
            "su",
            "-c",
            r"""PGPASSFILE=%s %s -X %s -A0 -F'%s' -f %s""",
            "-",
            self.db_user,
        ]

Maybe su just became strict about that.

You can try to replace “-” with --login

su(1) - Linux manual page
" It is recommended to always use the --login option (instead of its shortcut -) to avoid side effects caused by mixing environments."

My reason for trying to change the argument order was because of this changelog entry:

su:
    - ...
    - pass arguments after <user> to shell (by cgoesche)
    - ...

and -c command should be an option to su