Skip to content

generic_agent: Close log on exit#5879

Merged
larsewi merged 1 commit into
cfengine:masterfrom
btriller:generic-agent-close-fd
Sep 22, 2025
Merged

generic_agent: Close log on exit#5879
larsewi merged 1 commit into
cfengine:masterfrom
btriller:generic-agent-close-fd

Conversation

@btriller

@btriller btriller commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

Albeit optional to closelog(), ensure to closelog() on exit. Otherwise valgrind --track-fds=yes complains in case e.g. cf-promises is run but can't find its policy file.

% valgrind --track-fds=yes cf-promises -f nonexistent.cf
==4177819== Memcheck, a memory error detector
==4177819== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==4177819== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==4177819== Command: cf-promises -f nonexistent.cf
==4177819==
   error: Can't stat file '/home/btriller/.cfagent/inputs/nonexistent.cf' for parsing. (stat: No such file or directory)
==4177819==
==4177819== FILE DESCRIPTORS: 4 open (3 std) at exit.
==4177819== Open AF_UNIX socket 3: <unknown>
==4177819==    at 0x4ACADB7: socket (syscall-template.S:120)
==4177819==    by 0x4AC0D20: openlog_internal (syslog.c:347)
==4177819==    by 0x4AC1395: __vsyslog_internal (syslog.c:279)
==4177819==    by 0x4AC1575: syslog (syslog.c:91)
==4177819==    by 0x4907E34: LogToSystemLog (logging.c:284)
==4177819==    by 0x4907F70: LogToSystemLogStructured (logging.c:343)
==4177819==    by 0x4908339: VLogNoFormat (logging.c:508)
==4177819==    by 0x49081B6: Log (logging.c:559)
==4177819==    by 0x48D8C9B: Cf3ParseFile (loading.c:87)
==4177819==    by 0x48D8F4F: LoadPolicyFile (loading.c:343)
==4177819==    by 0x48D9535: LoadPolicy (loading.c:503)
==4177819==    by 0x10A851: main (cf-promises.c:156)
==4177819==
==4177819==
==4177819== HEAP SUMMARY:
==4177819==     in use at exit: 328,524 bytes in 6,335 blocks
==4177819==   total heap usage: 23,282 allocs, 16,947 frees, 8,495,524 bytes allocated
==4177819==
==4177819== LEAK SUMMARY:
==4177819==    definitely lost: 0 bytes in 0 blocks
==4177819==    indirectly lost: 0 bytes in 0 blocks
==4177819==      possibly lost: 0 bytes in 0 blocks
==4177819==    still reachable: 328,524 bytes in 6,335 blocks
==4177819==         suppressed: 0 bytes in 0 blocks
==4177819== Rerun with --leak-check=full to see details of leaked memory
==4177819==
==4177819== For lists of detected and suppressed errors, rerun with: -s
==4177819== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Albeit optional to closelog(), ensure to closelog() on exit. Otherwise
valgrind --track-fds=yes complains in case e.g. cf-promises is run but
can't find its policy file.

% valgrind --track-fds=yes cf-promises -f nonexistent.cf
==4177819== Memcheck, a memory error detector
==4177819== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==4177819== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==4177819== Command: cf-promises -f nonexistent.cf
==4177819==
   error: Can't stat file '/home/btriller/.cfagent/inputs/nonexistent.cf' for parsing. (stat: No such file or directory)
==4177819==
==4177819== FILE DESCRIPTORS: 4 open (3 std) at exit.
==4177819== Open AF_UNIX socket 3: <unknown>
==4177819==    at 0x4ACADB7: socket (syscall-template.S:120)
==4177819==    by 0x4AC0D20: openlog_internal (syslog.c:347)
==4177819==    by 0x4AC1395: __vsyslog_internal (syslog.c:279)
==4177819==    by 0x4AC1575: syslog (syslog.c:91)
==4177819==    by 0x4907E34: LogToSystemLog (logging.c:284)
==4177819==    by 0x4907F70: LogToSystemLogStructured (logging.c:343)
==4177819==    by 0x4908339: VLogNoFormat (logging.c:508)
==4177819==    by 0x49081B6: Log (logging.c:559)
==4177819==    by 0x48D8C9B: Cf3ParseFile (loading.c:87)
==4177819==    by 0x48D8F4F: LoadPolicyFile (loading.c:343)
==4177819==    by 0x48D9535: LoadPolicy (loading.c:503)
==4177819==    by 0x10A851: main (cf-promises.c:156)
==4177819==
==4177819==
==4177819== HEAP SUMMARY:
==4177819==     in use at exit: 328,524 bytes in 6,335 blocks
==4177819==   total heap usage: 23,282 allocs, 16,947 frees, 8,495,524 bytes allocated
==4177819==
==4177819== LEAK SUMMARY:
==4177819==    definitely lost: 0 bytes in 0 blocks
==4177819==    indirectly lost: 0 bytes in 0 blocks
==4177819==      possibly lost: 0 bytes in 0 blocks
==4177819==    still reachable: 328,524 bytes in 6,335 blocks
==4177819==         suppressed: 0 bytes in 0 blocks
==4177819== Rerun with --leak-check=full to see details of leaked memory
==4177819==
==4177819== For lists of detected and suppressed errors, rerun with: -s
==4177819== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
@larsewi larsewi self-requested a review September 12, 2025 08:29
@larsewi

larsewi commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

@cf-bottom Jenkins please :)

@larsewi

larsewi commented Sep 16, 2025

Copy link
Copy Markdown
Contributor

Will have to get back to this next week :)

@cfengine cfengine deleted a comment from cf-bottom Sep 19, 2025
@cfengine cfengine deleted a comment from cf-bottom Sep 19, 2025
@cfengine cfengine deleted a comment from cf-bottom Sep 19, 2025
@cf-bottom

Copy link
Copy Markdown

@larsewi larsewi merged commit 669d1a9 into cfengine:master Sep 22, 2025
36 checks passed
@btriller btriller deleted the generic-agent-close-fd branch September 22, 2025 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants