libcgroup / libcgroup

GNU Lesser General Public License v2.1
151 stars 39 forks source link

Incorrect systemd.h inclusion if systemd feature is disabled #413

Closed lucasdietrich closed 4 months ago

lucasdietrich commented 12 months ago

File include/Makefile.am conditionally instructs to not install systemd.h header depending on systemd feature, however header include/libcgroup.h unconditionally includes this previous header.

I'm compiling this library in the context of a Yocto environement, if I build libcgroup with --enable-systemd=no, systemd.h header is not installed in the development package, when including <libcgroup.h> from a C project this causes a gcc error saying it cannot find systemd.h header

Moving libcgroup/systemd.h to nobase_include_HEADERS in include/Makefile.am solves our issue:

# Using 'nobase_', we what groups.h in /usr/include/libcgroup/ directory
nobase_include_HEADERS = libcgroup.h libcgroup/error.h libcgroup/init.h \
             libcgroup/groups.h libcgroup/tasks.h \
             libcgroup/iterators.h libcgroup/config.h \
             libcgroup/log.h libcgroup/tools.h \
             libcgroup/systemd.h

Is this a indented ? I can elaborate a patch

ColdForest commented 12 months ago

I just ran into this as well.

kamalesh-babulal commented 12 months ago

@lucasdietrich @ColdForest Thanks for the report. I guess moving libcgroup/systemd.h out of #ifdef WITH_SYSTEMD into nobase_ will be a partial fix if libcgroup/systemd.h is to be included unconditionally in the include/Makefile.am. Additionally, it would require WITH_SYSTEMD=n version of functions included from libcgroup/systemd.h for graceful errors, instead of build failures. The function would return an error message, along with ECGROUPNOTCOMPILED? as the return value.

Another approach would be to use #ifdef WITH_SYSTEMD while adding libcgroup/systemd.h in libcgroup.h but that would require moving out the systemd configuration parser functions to out of libcgroup/systemd.h, but that doesn't sound like a great option.

Sangeetha-E commented 11 months ago

I'm encountering the same issue as well. Here is the log:

# gcc -o get_mount_point get_mount_point.c -lcgroup
In file included from get_mount_point.c:2:0:
/usr/include/libcgroup.h:22:31: fatal error: libcgroup/systemd.h: No such file or directory
 #include <libcgroup/systemd.h>
                               ^
compilation terminated.
#

Is there any available fix for this?

kamalesh-babulal commented 11 months ago

@lucasdietrich @ColdForest @Sangeetha-E Can you please give #414 a try?

lucasdietrich commented 11 months ago

I just tested your changes in my Yocto project, and everything compiled without error. The issue seems to be resolved on my side, thank you !

Steps:

  1. Building libcgroup development package with your changes
  2. Building my application linked against the compiled library
kamalesh-babulal commented 11 months ago

@lucasdietrich Thank you so much for the super quick testing. Can I include your name and email (please share) in the Reported-by: tag.

lucasdietrich commented 11 months ago

Sure Reported-by: Lucas Dietrich <lucas.dietrich@socomec.com>

kamalesh-babulal commented 4 months ago

414 resolves the reported issue, closing it.