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

mendersoftware / mender-mcu / 1748303724

02 Apr 2025 10:28AM UTC coverage: 57.632% (+0.6%) from 57.008%
1748303724

push

gitlab-ci

danielskinstad
fix: store `MENDER_UPDATE_STATE_REBOOT` before calling install callback

In the `zephyr-image` update module we set the pending image in
the install callback. If we don't store the next state before
setting the pending image, a spontaneous reboot in
`MENDER_UPDATE_STATE_INSTALL` will simply go to failure and stay in the
unconfirmed image in slot 1. By storing the next state, we assure that
the deployment will be marked as a failure and that we don't end up in
the wrong image.

Changelog: None
Ticket: None

Signed-off-by: Daniel Skinstad Drabitzius <daniel.drabitzius@northern.tech>

11 of 11 new or added lines in 1 file covered. (100.0%)

623 existing lines in 14 files now uncovered.

2273 of 3944 relevant lines covered (57.63%)

70.63 hits per line

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

80.0
/src/core/update-module.c
1
/**
2
 * @file      update-module.c
3
 * @brief     Mender update Module implementation
4
 *
5
 * Copyright Northern.tech AS
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19

20
#include "alloc.h"
21
#include "log.h"
22
#include "update-module.h"
23
#include "utils.h"
24

25
/**
26
 * @brief Mender update modules list
27
 */
28
static mender_update_module_t **update_modules_list  = NULL;
29
static size_t                   update_modules_count = 0;
30

31
mender_err_t
32
mender_update_module_register(mender_update_module_t *update_module) {
42✔
33
    assert(NULL != update_module);
42✔
34

35
    mender_update_module_t **tmp;
36
    mender_err_t             ret = MENDER_OK;
42✔
37

38
    for (size_t i = 0; i < update_modules_count; i++) {
42✔
39
        if (StringEqual(update_module->artifact_type, update_modules_list[i]->artifact_type)) {
×
40
            mender_log_error("Not registering another update module for artifact type: %s", update_module->artifact_type);
×
41
            return MENDER_FAIL;
×
42
        }
43
    }
44

45
    /* Add mender artifact type to the list */
46
    if (NULL == (tmp = (mender_update_module_t **)mender_realloc(update_modules_list, (update_modules_count + 1) * sizeof(mender_update_module_t *)))) {
42✔
47
        mender_log_error("Unable to allocate memory for update modules list");
×
48
        ret = MENDER_FAIL;
×
49
        goto END;
×
50
    }
51
    update_modules_list                         = tmp;
42✔
52
    update_modules_list[update_modules_count++] = update_module;
42✔
53
    ret                                         = MENDER_OK;
42✔
54

55
END:
42✔
56

57
    return ret;
42✔
58
}
59

60
void
UNCOV
61
mender_update_module_unregister_all(void) {
13✔
UNCOV
62
    if (NULL != update_modules_list) {
13✔
UNCOV
63
        for (size_t update_module_index = 0; update_module_index < update_modules_count; update_module_index++) {
26✔
UNCOV
64
            mender_free(update_modules_list[update_module_index]);
13✔
65
        }
UNCOV
66
        FREE_AND_NULL(update_modules_list);
13✔
67
    }
UNCOV
68
    update_modules_count = 0;
13✔
UNCOV
69
}
13✔
70

71
mender_update_module_t *
72
mender_update_module_get(const char *artifact_type) {
38✔
73
    mender_update_module_t *ret = NULL;
38✔
74

75
    /* Treatment depending of the type */
76
    if (NULL != update_modules_list) {
38✔
77
        for (size_t update_module_index = 0; (NULL == ret) && (update_module_index < update_modules_count); update_module_index++) {
76✔
78
            /* Check artifact type */
79
            if (StringEqual(artifact_type, update_modules_list[update_module_index]->artifact_type)) {
38✔
80
                ret = update_modules_list[update_module_index];
38✔
81
            }
82
        }
83
    }
84

85
    return ret;
38✔
86
}
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