Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
boot_id.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 OpenUAS
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef USHER_BOOT_ID_H
19#define USHER_BOOT_ID_H
20
21/**
22 * @file boot_id.h
23 * @brief Read Linux's boot-unique identifier for pose-log session provenance.
24 * @details A boot ID distinguishes monotonic timestamps from two daemon runs after a
25 * board reboot. Failure is nonfatal and intentionally represented as "unknown" so
26 * logging remains available on non-Linux development systems.
27 */
28
29#include <fcntl.h>
30#include <stdio.h>
31
32/** @brief Fill a 36-character boot UUID or the stable fallback "unknown".
33 * @param result Caller buffer of exactly 37 bytes, including the terminator.
34 * @details Input is strictly validated instead of trusting procfs text, because this
35 * value becomes durable log metadata and should never contain a partial read. */
36static inline void usher_boot_id(char result[37])
37{
38 const char unknown[] = "unknown";
39 for (size_t index = 0; index < sizeof(unknown); ++index) result[index] = unknown[index];
40 FILE *file = fopen("/proc/sys/kernel/random/boot_id", "r");
41 if (file == NULL) return;
42 int descriptor = fileno(file);
43 if (descriptor < 0 || fcntl(descriptor, F_SETFD, FD_CLOEXEC) != 0) {
44 fclose(file);
45 return;
46 }
47 char value[38];
48 size_t length = fread(value, 1, sizeof(value), file);
49 int closed = fclose(file);
50 if (closed != 0 || length != 37 || value[36] != '\n') return;
51 for (size_t index = 0; index < 36; ++index) {
52 if (index == 8 || index == 13 || index == 18 || index == 23) {
53 if (value[index] != '-') return;
54 } else if (!((value[index] >= '0' && value[index] <= '9')
55 || (value[index] >= 'a' && value[index] <= 'f'))) return;
56 }
57 for (size_t index = 0; index < 36; ++index) result[index] = value[index];
58 result[36] = '\0';
59}
60
61#endif
static void usher_boot_id(char result[37])
Fill a 36-character boot UUID or the stable fallback "unknown".
Definition boot_id.h:36
int descriptor
Definition chdk_pipe.c:142
struct usher_control_result result
Definition usher.c:377