Skip to content

Refactor/check users broke OpenBSD #2152

@oxzi

Description

@oxzi
./plugins $ make check_users
  CC       check_users.o
  CC       check_users.d/users.o
In file included from check_users.d/users.c:116:
check_users.d/../popen.h:6:1: error: unknown type name 'FILE'
    6 | FILE *spopen(const char *);
      | ^
check_users.d/../popen.h:7:13: error: unknown type name 'FILE'
    7 | int spclose(FILE *);
      |             ^
check_users.d/../popen.h:10:1: error: unknown type name 'pid_t'
   10 | pid_t *childpid = NULL;
      | ^
check_users.d/../popen.h:12:1: error: unknown type name 'FILE'
   12 | FILE *child_process = NULL;
      | ^
check_users.d/../popen.h:13:1: error: unknown type name 'FILE'
   13 | FILE *child_stderr = NULL;
      | ^
5 errors generated.
*** Error 1 in [...]/monitoring-plugins/plugins (Makefile:2869 'check_users.d/users.o': @echo "  CC ...)

After adding the required imports.

diff --git a/plugins/popen.h b/plugins/popen.h
index e318ce25..64a94294 100644
--- a/plugins/popen.h
+++ b/plugins/popen.h
@@ -3,6 +3,8 @@
  *
  *****************************************************************************/
 
+#include "common.h"
+
 FILE *spopen(const char *);
 int spclose(FILE *);
 void popen_timeout_alarm_handler(int);
./plugins $ make check_users
  CC       check_users.o
  CC       check_users.d/users.o
  CCLD     check_users
ld: error: duplicate symbol: child_process
>>> defined at popen.h:14 (./popen.h:14)
>>>            check_users.o:(child_process)
>>> defined at popen.h:14 (check_users.d/../popen.h:14)
>>>            check_users.d/users.o:(.bss+0x10)

ld: error: duplicate symbol: child_stderr_array
>>> defined at popen.h:13 (./popen.h:13)
>>>            check_users.o:(child_stderr_array)
>>> defined at popen.h:13 (check_users.d/../popen.h:13)
>>>            check_users.d/users.o:(.bss+0x8)

ld: error: duplicate symbol: child_stderr
>>> defined at popen.h:15 (./popen.h:15)
>>>            check_users.o:(child_stderr)
>>> defined at popen.h:15 (check_users.d/../popen.h:15)
>>>            check_users.d/users.o:(.bss+0x18)

ld: error: duplicate symbol: childpid
>>> defined at popen.h:12 (./popen.h:12)
>>>            check_users.o:(childpid)
>>> defined at popen.h:12 (check_users.d/../popen.h:12)
>>>            check_users.d/users.o:(.bss+0x0)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error 1 in [...]/monitoring-plugins/plugins (Makefile:2756 'check_users': @echo "  CCLD    " che...)

In particular, the refactoring in #2107 moved parts of ./plugins/check_user.c into ./plugins/check_users.d/. This new directory gets compiled independently of check_user.c. Since both are importing ./plugins/popen.h and using the global variables defined there, we end up with duplicate symbols.

# ifndef HAVE_WTSAPI32_H
# ifndef HAVE_LIBSYSTEMD
# ifndef HAVE_UTMPX_H
// Fall back option here for the others (probably still not on windows)
# include "../popen.h"
# include "../common.h"
# include "../utils.h"

The error is triggered if the system is not Windows, has not systemd, and does not support utmpx.h. On OpenBSD there is utmp.h, but not utmpx.h.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions