2020#include "close_fds.h"
2121#include "seccomp_notify.h"
2222#include "runtime_args.h"
23+ #include "healthcheck.h"
2324
2425#include <sys/stat.h>
2526#include <locale.h>
@@ -46,14 +47,18 @@ int main(int argc, char *argv[])
4647 _cleanup_close_ int dev_null_r_cleanup = -1 ;
4748 _cleanup_close_ int dev_null_w_cleanup = -1 ;
4849 _cleanup_close_ int dummyfd = -1 ;
49-
5050 int initialize_ec = initialize_cli (argc , argv );
5151 if (initialize_ec >= 0 ) {
5252 exit (initialize_ec );
5353 }
5454
5555 process_cli ();
5656
57+ /* Initialize healthcheck subsystem - always initialize for automatic discovery */
58+ if (!healthcheck_init ()) {
59+ pexit ("Failed to initialize healthcheck subsystem" );
60+ }
61+
5762 attempt_oom_adjust (-1000 );
5863
5964 /* ignoring SIGPIPE prevents conmon from being spuriously killed */
@@ -396,7 +401,6 @@ int main(int argc, char *argv[])
396401 }
397402
398403 container_pid = atoi (contents );
399- ndebugf ("container PID: %d" , container_pid );
400404
401405 g_hash_table_insert (pid_to_handler , (pid_t * )& container_pid , container_exit_cb );
402406
@@ -408,6 +412,38 @@ int main(int argc, char *argv[])
408412 if ((opt_api_version >= 1 || !opt_exec ) && sync_pipe_fd >= 0 )
409413 write_or_close_sync_fd (& sync_pipe_fd , container_pid , NULL );
410414
415+ /* Configure healthcheck - automatic discovery from OCI config.json */
416+ /* Only start healthcheck timers if explicitly enabled via CLI flag */
417+ if (opt_bundle_path != NULL && opt_enable_healthcheck ) {
418+ healthcheck_config_t config ;
419+ memset (& config , 0 , sizeof (config ));
420+
421+ if (healthcheck_discover_from_oci_config (opt_bundle_path , & config )) {
422+ healthcheck_timer_t * timer = healthcheck_timer_new (opt_cid , & config );
423+ if (timer != NULL ) {
424+ if (healthcheck_timer_start (timer )) {
425+ if (active_healthcheck_timers != NULL ) {
426+ hash_table_put (active_healthcheck_timers , opt_cid , timer );
427+ ninfof ("Started healthcheck for container %s" , opt_cid );
428+ } else {
429+ nwarnf ("Active healthcheck timers table is NULL" );
430+ healthcheck_timer_free (timer );
431+ }
432+ } else {
433+ nwarnf ("Failed to start healthcheck for container %s" , opt_cid );
434+ healthcheck_timer_free (timer );
435+ }
436+ } else {
437+ nwarnf ("Failed to create healthcheck timer for container %s" , opt_cid );
438+ }
439+ } else {
440+ nwarnf ("Failed to discover healthcheck config from OCI bundle" );
441+ }
442+
443+ /* Always free the config, regardless of success or failure */
444+ healthcheck_config_free (& config );
445+ }
446+
411447#ifdef __linux__
412448 setup_oom_handling (container_pid );
413449#endif
@@ -495,6 +531,9 @@ int main(int argc, char *argv[])
495531 g_source_remove (signal_fd_tag );
496532 close (signal_fd );
497533
534+ /* Cleanup healthcheck timers */
535+ healthcheck_cleanup ();
536+
498537 /*
499538 * Podman injects some fd's into the conmon process so that exposed ports are kept busy while
500539 * the container runs. Close them before we notify the container exited, so that they can be
0 commit comments