• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eclipse-bluechi / bluechi / 16572578197

28 Jul 2025 03:00PM UTC coverage: 70.652% (-3.8%) from 74.418%
16572578197

push

github

engelmi
Release BlueChi v1.1.0

Signed-off-by: Michael Engel <mengel@redhat.com>

4858 of 6876 relevant lines covered (70.65%)

947.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.27
/src/controller/main.c
1
/*
2
 * Copyright Contributors to the Eclipse BlueChi project
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 */
6
#include <errno.h>
7
#include <getopt.h>
8
#include <stdlib.h>
9

10
#include "libbluechi/common/opt.h"
11
#include "libbluechi/log/log.h"
12

13
#include "controller.h"
14

15
const struct option options[] = {
16
        { ARG_PORT,    required_argument, 0, ARG_PORT_SHORT    },
17
        { ARG_CONFIG,  required_argument, 0, ARG_CONFIG_SHORT  },
18
        { ARG_HELP,    no_argument,       0, ARG_HELP_SHORT    },
19
        { ARG_VERSION, no_argument,       0, ARG_VERSION_SHORT },
20
        { NULL,        0,                 0, '\0'              }
21
};
22

23
#define GETOPT_OPTSTRING ARG_PORT_SHORT_S ARG_HELP_SHORT_S ARG_CONFIG_SHORT_S ARG_VERSION_SHORT_S
24

25
static const char *opt_port = 0;
26
static const char *opt_config = NULL;
27

28
static void usage(char *argv[]) {
2✔
29
        printf("Usage:\n"
2✔
30
               "\t%s [options...] \n"
31
               "Available options are:\n"
32
               "\t-%c %s\t\t Print this help message.\n"
33
               "\t-%c %s\t\t The port of bluechi to connect to.\n"
34
               "\t-%c %s\t A path to a config file used to bootstrap bluechi-controller.\n"
35
               "\t-%c %s\t Print current bluechi version.\n",
36
               argv[0],
37
               ARG_HELP_SHORT,
38
               ARG_HELP,
39
               ARG_PORT_SHORT,
40
               ARG_PORT,
41
               ARG_CONFIG_SHORT,
42
               ARG_CONFIG,
43
               ARG_VERSION_SHORT,
44
               ARG_VERSION);
45
}
2✔
46

47
static int get_opts(int argc, char *argv[]) {
69✔
48
        int opt = 0;
69✔
49

50
        while ((opt = getopt_long(argc, argv, GETOPT_OPTSTRING, options, NULL)) != -1) {
69✔
51
                switch (opt) {
4✔
52
                case ARG_HELP_SHORT:
2✔
53
                        usage(argv);
2✔
54
                        return 1;
2✔
55

56
                case ARG_VERSION_SHORT:
57
                        printf("bluechi-controller version %s\n", CONFIG_H_BC_VERSION);
2✔
58
                        return 1;
2✔
59

60
                case ARG_PORT_SHORT:
×
61
                        opt_port = optarg;
×
62
                        break;
×
63

64
                case ARG_CONFIG_SHORT:
×
65
                        opt_config = optarg;
×
66
                        break;
×
67

68
                default:
×
69
                        fprintf(stderr, "Unsupported option %c\n", opt);
×
70
                        usage(argv);
×
71
                        return -EINVAL;
×
72
                }
73
        }
74

75
        return 0;
76
}
77

78

79
int main(int argc, char *argv[]) {
69✔
80
        int r = get_opts(argc, argv);
69✔
81
        if (r < 0) {
69✔
82
                return EXIT_FAILURE;
69✔
83
        } else if (r > 0) {
69✔
84
                return EXIT_SUCCESS;
85
        }
86

87
        _cleanup_controller_ Controller *controller = controller_new();
134✔
88
        if (controller == NULL) {
65✔
89
                return EXIT_FAILURE;
90
        }
91

92
        if (!controller_parse_config(controller, opt_config)) {
65✔
93
                return EXIT_FAILURE;
94
        }
95

96
        bc_log_init(controller->config);
65✔
97
        _cleanup_free_ const char *dumped_cfg = cfg_dump(controller->config);
130✔
98
        bc_log_debugf("Final configuration used:\n%s", dumped_cfg);
65✔
99

100
        if (!controller_apply_config(controller)) {
65✔
101
                return EXIT_FAILURE;
102
        }
103

104
        /* Override individual options */
105

106
        if (opt_port && !controller_set_port(controller, opt_port)) {
65✔
107
                return EXIT_FAILURE;
108
        }
109

110
        if (controller_start(controller)) {
65✔
111
                return EXIT_SUCCESS;
112
        }
113
        controller_stop(controller);
×
114
        return EXIT_FAILURE;
115
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc