MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / main

Function main

src/main.c:2784–3441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2782}
2783
2784int main(int argc, char **argv) {
2785 /* Must remain the first statement: see allocator binding contract above. */
2786 cbm_alloc_init();
2787#ifndef _WIN32
2788 pid_t process_initial_ppid = getppid();
2789#else
2790 /* Captured at the same instant as POSIX: the later OpenProcess in
2791 * client_start_parent_watchdog must target the process that spawned us,
2792 * not whatever may have recycled the PID meanwhile. */
2793 DWORD process_initial_ppid = win_parent_pid_from_snapshot();
2794#endif
2795#ifdef _WIN32
2796 {
2797 int win_argc = 0;
2798 char **win_argv = cbm_win_utf8_argv(&win_argc);
2799 if (win_argv) {
2800 argc = win_argc;
2801 argv = win_argv;
2802 }
2803 }
2804#endif
2805 cbm_daemon_process_role_t role = cbm_daemon_process_role(argc, argv);
2806 if (role == CBM_DAEMON_PROCESS_WORKER) {
2807 /* Before this process writes ANYTHING. A worker's stderr is a file the
2808 * supervisor keeps for post-mortem, and setvbuf only binds before a
2809 * stream's first operation — claim it here so even the "could not
2810 * start" messages below reach disk. The header follows once the argv
2811 * grammar has been validated. */
2812 cbm_log_set_crash_durable(true);
2813 }
2814 if (role == CBM_DAEMON_PROCESS_INVALID) {
2815 (void)fprintf(stderr, "codebase-memory-mcp: invalid internal process arguments\n");
2816 return EXIT_FAILURE;
2817 }
2818#ifndef _WIN32
2819 if (role == CBM_DAEMON_PROCESS_DAEMON) {
2820 (void)umask(077);
2821 }
2822#endif
2823
2824 bool configure_stateless =
2825 role == CBM_DAEMON_PROCESS_STATELESS && argc > 1 && strcmp(argv[1], "config") == 0;
2826 if ((role != CBM_DAEMON_PROCESS_STATELESS && role != CBM_DAEMON_PROCESS_HOOK_CLIENT) ||
2827 configure_stateless) {
2828 const char *settings_cache = cbm_resolve_cache_dir();
2829 if (settings_cache && !cbm_runtime_settings_init(settings_cache)) {
2830 (void)fprintf(stderr, "codebase-memory-mcp: could not load saved runtime settings\n");
2831 return EXIT_FAILURE;
2832 }
2833 }
2834 cbm_cli_set_version(CBM_VERSION);
2835 cbm_profile_init();
2836 /* The library default stays INFO (embedders and the test runner observe
2837 * INFO records through the sink); the process policy is applied here, as
2838 * early as argv can be classified: thin frontends go quiet, detached
2839 * daemons retain INFO lifecycle records, and physical workers require
2840 * INFO because those records are their supervisor's quiet-timeout
2841 * heartbeat. */

Callers

nothing calls this directly

Calls 15

cbm_alloc_initFunction · 0.85
cbm_win_utf8_argvFunction · 0.85
cbm_daemon_process_roleFunction · 0.85
cbm_resolve_cache_dirFunction · 0.85
cbm_cli_set_versionFunction · 0.85
cbm_profile_initFunction · 0.85
cbm_log_init_for_processFunction · 0.85
main_cli_flag_presentFunction · 0.85

Tested by

no test coverage detected