LCOV - code coverage report
Current view: top level - src/app - bootstrap.c (source / functions) Coverage Total Hit
Test: coverage-functional.info Lines: 100.0 % 19 19
Test Date: 2026-04-20 19:54:24 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /* SPDX-License-Identifier: GPL-3.0-or-later */
       2              : /* Copyright 2026 Peter Csaszar */
       3              : 
       4              : /**
       5              :  * @file app/bootstrap.c
       6              :  * @brief Shared startup path: directories, logger.
       7              :  */
       8              : 
       9              : #include "app/bootstrap.h"
      10              : 
      11              : #include "logger.h"
      12              : #include "fs_util.h"
      13              : #include "platform/path.h"
      14              : 
      15              : #include <stdio.h>
      16              : #include <string.h>
      17              : 
      18            2 : int app_bootstrap(AppContext *ctx, const char *program_name) {
      19            2 :     if (!ctx || !program_name) return -1;
      20              : 
      21            2 :     memset(ctx, 0, sizeof(*ctx));
      22            2 :     ctx->cache_dir  = platform_cache_dir();
      23            2 :     ctx->config_dir = platform_config_dir();
      24              : 
      25            2 :     if (ctx->cache_dir)  fs_mkdir_p(ctx->cache_dir, 0700);
      26            2 :     if (ctx->config_dir) fs_mkdir_p(ctx->config_dir, 0700);
      27              : 
      28            2 :     const char *base = ctx->cache_dir ? ctx->cache_dir : "/tmp/tg-cli";
      29            2 :     snprintf(ctx->log_path, sizeof(ctx->log_path), "%s/logs", base);
      30            2 :     fs_mkdir_p(ctx->log_path, 0700);
      31              : 
      32            2 :     size_t dir_len = strlen(ctx->log_path);
      33            2 :     snprintf(ctx->log_path + dir_len, sizeof(ctx->log_path) - dir_len,
      34              :              "/%s.log", program_name);
      35              : 
      36            2 :     logger_init(ctx->log_path, LOG_INFO);
      37            2 :     logger_log(LOG_INFO, "%s starting", program_name);
      38            2 :     return 0;
      39              : }
      40              : 
      41            2 : void app_shutdown(AppContext *ctx) {
      42              :     (void)ctx;
      43            2 :     logger_log(LOG_INFO, "shutdown");
      44            2 :     logger_close();
      45            2 : }
        

Generated by: LCOV version 2.0-1