GCC Code Coverage Report


Directory: ./
File: boot/FPPINIT_Config.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 1000 1284 77.9%
Functions: 66 73 90.4%
Branches: 1594 3783 42.1%

Line Branch Exec Source
1 /*
2 * This file is part of the Falcon Player (FPP) and is Copyright (C)
3 * 2013-2024 by the Falcon Player Developers.
4 *
5 * The Falcon Player (FPP) is free software, and is covered under
6 * multiple Open Source licenses. Please see the included 'LICENSES'
7 * file for descriptions of what files are covered by each license.
8 *
9 * This source file is covered under the LGPL v2.1 as described in the
10 * included LICENSE.LGPL file.
11 */
12
13 #include <algorithm>
14 #include <chrono>
15 #include "fpp-json.h"
16 #include <cctype>
17 #include <cerrno>
18 #include <cmath>
19 #include <cstdio>
20 #include <cstdlib>
21 #include <cstring>
22 #include <fcntl.h>
23 #include <filesystem>
24 #include <fstream>
25 #include <functional>
26 #include <iterator>
27 #include <map>
28 #include <pwd.h>
29 #include <sys/stat.h>
30 #include <sys/wait.h>
31 #include <thread>
32 #include <unistd.h>
33 #include <vector>
34
35 #if __has_include(<gpiod.hpp>)
36 #include <gpiod.hpp>
37 #define HASGPIOD
38 #if __has_include(<gpiodcxx/chip.hpp>)
39 #define IS_GPIOD_CXX_V2
40 #endif
41 #endif
42
43 #include "FPPINIT.h"
44
45 39 void DetectCape() {
46
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 35 times.
39 if (!FileExists("/etc/fpp/container")) {
47 #ifdef CAPEDETECT
48 4 int count = 0;
49 #ifdef PLATFORM_PI
50 2 modprobe("i2c-dev");
51 #endif
52
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (!FileExists(I2C_DEV)) {
53 4 printf("FPP - Waiting up to 3s for %s to appear for Cape/Hat detection\n", I2C_DEV.c_str());
54 }
55
5/6
✓ Branch 0 taken 2404 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2400 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2400 times.
✓ Branch 5 taken 4 times.
2404 while (!FileExists(I2C_DEV) && count < 600) {
56
1/2
✓ Branch 0 taken 2400 times.
✗ Branch 1 not taken.
2400 std::this_thread::sleep_for(std::chrono::milliseconds(5));
57 2400 count++;
58 }
59 4 printf("FPP - Checking for Cape/Hat\n");
60
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 exec("/opt/fpp/src/fppcapedetect -no-set-permissions");
61 #endif
62 }
63
3/6
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39 times.
✗ Branch 5 not taken.
43 PutFileContents(FPP_MEDIA_DIR + "/tmp/cape_detect_done", "1");
64 39 }
65
66 39 void checkSSHKeys() {
67 39 int keyCount = 0;
68 39 int pubCount = 0;
69
5/8
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 217 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 217 times.
✓ Branch 7 taken 39 times.
256 for (const auto& entry : std::filesystem::directory_iterator("/etc/ssh")) {
70
3/4
✓ Branch 0 taken 217 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176 times.
✓ Branch 3 taken 41 times.
217 if (entry.is_regular_file()) {
71
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 const auto filename = entry.path().filename();
72
5/8
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 176 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 134 times.
✓ Branch 7 taken 42 times.
372 if (contains(filename, "ssh_host")) {
73
4/6
✓ Branch 0 taken 134 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 134 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 67 times.
✓ Branch 5 taken 67 times.
134 if (filename.extension() == ".pub") {
74 67 pubCount++;
75 } else {
76 67 keyCount++;
77 }
78 }
79 176 }
80 39 }
81 // make sure we have at least two private and public keys (really should be three, but some platforms don't support ed25519, so we'll just check for two)
82
3/4
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
39 if (keyCount >= 2 && pubCount >= 2) {
83 32 return;
84 }
85 7 printf(" - Regenerating SSH keys\n");
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (FileExists("/dev/hwrng")) {
87 // if the hwrng exists, use it to seed the urandom generator
88 // with some random data
89 ✗ exec("dd if=/dev/hwrng of=/dev/urandom count=1 bs=4096 status=none");
90 } else {
91 // No hardware RNG to seed from: ssh-keygen's getrandom() can block
92 // waiting for the CRNG to seed on a freshly booted board with little
93 // entropy. fppinit no longer waits for haveged on every boot (it's only
94 // needed right here -- for first-boot key generation on a board without
95 // an RNG), so start it on demand to seed the pool before generating keys.
96
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
14 exec("/usr/bin/systemctl start haveged.service");
97 }
98
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
14 execbg("/usr/bin/ssh-keygen -q -N \"\" -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key &");
99
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
14 execbg("/usr/bin/ssh-keygen -q -N \"\" -t ed25519 -f /etc/ssh/ssh_host_ed25519_key &");
100
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
14 execbg("/usr/bin/ssh-keygen -q -N \"\" -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key &");
101 }
102
103 // Copies files/config from the /boot partition to /home/fpp/media
104 // On the Pi, /boot (or /boot/firmware) is vfat and thus the
105 // user could stick a default config on there
106 39 void handleBootPartition() {
107
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 std::string bootDir = "/boot";
108
2/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
39 if (DirectoryExists("/boot/firmware")) {
109
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 bootDir = "/boot/firmware";
110 }
111
3/6
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 39 times.
39 if (FileExists(bootDir + "/fpp_boot.sh")) {
112 ✗ std::string cmd = "/bin/bash " + bootDir + "/fpp_boot.sh";
113 ✗ exec(cmd);
114 ✗ }
115
4/6
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 37 times.
39 if (DirectoryExists(bootDir + "/fpp")) {
116
4/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
2 if (!FileExists(bootDir + "/fpp/copy_done")) {
117
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 std::string cmd = "/usr/bin/cp -a " + bootDir + "/fpp/* " + FPP_MEDIA_DIR;
118
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 exec(cmd);
119
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 PutFileContents(bootDir + "/fpp/copy_done", "1");
120 1 }
121 }
122 39 }
123
124 43 void checkHostName() {
125 43 std::string hn;
126
3/4
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✓ Branch 3 taken 6 times.
43 if (FileExists("/etc/fpp/container")) {
127
2/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
74 std::string CID = execAndReturn("/usr/bin/head -1 /proc/1/cgroup | sed -e \"s/.*docker-//\" | cut -c1-12");
128
2/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
37 hn = execAndReturn("/usr/bin/hostname");
129
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 TrimWhiteSpace(hn);
130
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 TrimWhiteSpace(CID);
131
2/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
37 setRawSetting("HostName", hn);
132
3/6
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
✗ Branch 5 not taken.
111 setRawSetting("HostDescription", "Docker ID: " + CID);
133 37 } else {
134
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 getRawSetting("HostName", hn);
135 // By default on installation, hostname is fpp, but it does not appear in the settings file
136
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 1 times.
6 if (hn == "") {
137
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 hn = "fpp";
138 }
139 // Goes to a root shell below; the UI only stores [A-Za-z0-9-] names.
140
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
6 if (!isShellSafeWord(hn)) {
141
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("Ignoring invalid HostName setting\n");
142 1 return;
143 }
144 char hostname[256];
145 5 int result = gethostname(hostname, 256);
146
4/8
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
5 if (result == 0 && hn != hostname) {
147 // need to reset the hostname
148
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 printf("Changing hostname from %s to %s\n", hostname, hn.c_str());
149
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string cmd = "/usr/bin/hostname " + hn;
150
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 exec(cmd);
151
152
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
13 PutFileContents("/etc/hostname", hn + "\n");
153
154
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 std::string hosts = GetFileContents("/etc/hosts");
155
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::vector<std::string> lines = split(hosts, '\n');
156
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 hosts = "";
157 5 bool found = false;
158
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
17 for (auto& line : lines) {
159
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if (line.starts_with("127.0.1.1")) {
160
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 hosts += "127.0.1.1\t";
161
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 hosts += hn;
162 2 found = true;
163 } else {
164
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 hosts += line;
165 }
166
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 hosts += "\n";
167 }
168
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
5 if (!found) {
169
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 hosts += "127.0.1.1\t";
170
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 hosts += hn;
171 }
172
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
10 PutFileContents("/etc/hosts", hosts);
173
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 execbg("/usr/bin/systemctl restart avahi-daemon &");
174 5 }
175 }
176
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 1 times.
43 }
177
178 45 void runScripts(const std::string tp, bool userBefore) {
179
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 std::string pfx = "FPPDIR=/opt/fpp SRCDIR=/opt/fpp/src ";
180
181
8/14
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 45 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 42 times.
✓ Branch 8 taken 45 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 42 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
45 if (userBefore && FileExists(FPP_MEDIA_DIR + "/scripts/UserCallbackHook.sh")) {
182
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 printf("FPP - Running UserCallbackHook.sh %s\n", tp.c_str());
183
4/8
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3 execbg(pfx + FPP_MEDIA_DIR + "/scripts/UserCallbackHook.sh " + tp);
184 }
185
6/10
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 45 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 45 times.
48 for (const auto& entry : std::filesystem::directory_iterator(FPP_MEDIA_DIR + "/plugins")) {
186
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 if (entry.is_directory()) {
187
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 std::string filename = entry.path().filename();
188
5/10
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
3 std::string cmd = FPP_MEDIA_DIR + "/plugins/" + filename + "/scripts/" + tp + ".sh";
189
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 if (FileExists(cmd)) {
190
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 printf("FPP - Running plugin %s script for %s\n", filename.c_str(), tp.c_str());
191
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 execbg(pfx + cmd);
192 }
193 3 }
194 45 }
195
3/14
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 45 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 45 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
45 if (!userBefore && FileExists(FPP_MEDIA_DIR + "/scripts/UserCallbackHook.sh")) {
196 ✗ printf("FPP - Running UserCallbackHook.sh %s\n", tp.c_str());
197 ✗ execbg(pfx + FPP_MEDIA_DIR + "/scripts/UserCallbackHook.sh " + tp);
198 }
199 45 }
200
201 39 void checkFSTAB() {
202
2/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
39 std::string cont = GetFileContents("/etc/fstab");
203
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 2 times.
39 if (cont.find("home/fpp/media") == std::string::npos) {
204
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 cont += "\n";
205
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 cont += "#####################################\n";
206
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 cont += "#/dev/sda1 /home/fpp/media auto defaults,noatime,nodiratime,exec,nofail,flush,uid=1000,gid=1000 0 0\n";
207
1/2
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
37 cont += "#####################################\n";
208
2/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
74 PutFileContents("/etc/fstab", cont);
209 }
210 39 }
211
212 39 void createDirectories() {
213 static std::vector<std::string> DIRS = { "", "config", "effects", "logs", "music", "playlists", "scripts", "sequences",
214 "upload", "videos", "plugins", "plugindata", "exim4", "images", "cache",
215
3/8
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
117 "backups", "tmp", "virtualdisplay_assets" };
216
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 printf("FPP - Checking for required directories\n");
217 39 uid_t fppUid = 0;
218 39 gid_t fppGid = 0;
219
2/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
39 bool haveFppUser = GetUserIds("fpp", &fppUid, &fppGid);
220
2/2
✓ Branch 0 taken 702 times.
✓ Branch 1 taken 39 times.
741 for (auto& d : DIRS) {
221
2/4
✓ Branch 0 taken 702 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 702 times.
✗ Branch 3 not taken.
702 std::string dir = FPP_MEDIA_DIR + "/" + d;
222
3/4
✓ Branch 0 taken 702 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 582 times.
702 if (!DirectoryExists(dir)) {
223
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 printf(" Creating directory %s\n", dir.c_str());
224
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 119 times.
120 if (mkdir(dir.c_str(), 0775) != 0) {
225 // A media directory that cannot be created leaves the web UI
226 // unable to save anything; say why here, since this goes to
227 // the journal (journalctl -u fppinit) as well as to
228 // media/logs, which is exactly what is missing.
229
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf(" Could not create %s: %s\n", dir.c_str(), strerror(errno));
230 1 continue;
231 }
232
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 111 times.
119 if (haveFppUser) {
233 8 chown(dir.c_str(), fppUid, fppGid);
234 }
235 }
236
2/2
✓ Branch 0 taken 701 times.
✓ Branch 1 taken 1 times.
702 }
237 39 }
238
239 39 void setupApache() {
240
3/8
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
39 static const std::string UIPASSCONF = FPP_MEDIA_DIR + "/config/ui-password-config.conf";
241
3/8
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
39 static const std::string HTPWD = FPP_MEDIA_DIR + "/config/.htpasswd";
242
3/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 10 times.
39 if (!FileExists(UIPASSCONF)) {
243
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 std::string content = "<RequireAny>\n Require all granted\n</RequireAny>\n\nSetEnvIf Host ^ LOCAL_PROTECT=0\n";
244
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 PutFileContents(UIPASSCONF, content);
245 29 } /* else {
246 std::string content = GetFileContents(UIPASSCONF);
247 if (content.find("php_value") != std::string::npos) {
248 printf(" Modifying .htaccess file\n");
249 std::vector<std::string> lines = split(content, '\n');
250 content = "";
251 for (auto& line : lines) {
252 if (line.find("php_value") == std::string::npos) {
253 content += line;
254 }
255 content += "\n";
256 }
257 PutFileContents(UIPASSCONF, content);
258 }
259 } */
260
3/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 10 times.
39 if (!FileExists(HTPWD)) {
261
2/4
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
✗ Branch 3 not taken.
58 PutFileContents(HTPWD, "");
262 }
263 // Apache sends /api's CORS headers while this file exists; www's
264 // SetupCrossOriginAPI() keeps it in step when the setting changes.
265
3/8
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
39 static const std::string CROSSORIGIN = FPP_MEDIA_DIR + "/config/api-cross-origin";
266 39 std::string allow;
267
6/20
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 39 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 39 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 39 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 39 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
117 if (getRawSetting("AllowCrossOriginAPI", allow) && allow == "1") {
268 ✗ if (!FileExists(CROSSORIGIN)) {
269 ✗ PutFileContents(CROSSORIGIN, "Written by FPP for the AllowCrossOriginAPI setting\n");
270 }
271
2/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 39 times.
39 } else if (FileExists(CROSSORIGIN)) {
272 ✗ unlink(CROSSORIGIN.c_str());
273 }
274 /* if (!FileExists("/opt/fpp/www/proxy/.htaccess")) {
275 printf("Creating proxy .htaccess link\n");
276 if (!FileExists(FPP_MEDIA_DIR + "/config/proxies")) {
277 PutFileContents(FPP_MEDIA_DIR + "/config/proxies", "");
278 }
279 symlink((FPP_MEDIA_DIR + "/config/proxies").c_str(), "/opt/fpp/www/proxy/.htaccess");
280 } */
281 39 }
282
283 39 void handleBootActions() {
284 39 std::string v;
285
6/18
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 39 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 39 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 39 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 39 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
117 if (getRawSetting("BootActions", v) && !v.empty()) {
286 ✗ exec("/opt/fpp/scripts/handle_boot_actions");
287 }
288 39 }
289
290 40 inline const std::string& mapBBBLedValue(const std::string& v) {
291 #ifdef PLATFORM_BB64
292
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 17 times.
24 if (v == "cpu") {
293
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
7 static const std::string activity = "activity";
294 7 return activity;
295 }
296 #endif
297 33 return v;
298 }
299
300 #if defined(PLATFORM_BBB) || defined(PLATFORM_BB64)
301 // User LED <index>'s trigger: its BBBLeds<index> setting, or the board default
302 // when that is unset. A default the kernel doesn't offer is left alone: an
303 // original PocketBeagle has no eMMC and so no mmc1 trigger, and the kernel
304 // refuses the write anyway.
305 40 static void setBBBLed(int index, int offset, const std::string& def) {
306
2/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
40 std::string path = "/sys/class/leds/beaglebone:green:usr" + std::to_string(index + offset) + "/trigger";
307 40 std::string led;
308
9/18
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 28 times.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 40 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 40 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 12 times.
✓ Branch 13 taken 28 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
40 if (getRawSetting("BBBLeds" + std::to_string(index), led) && !led.empty()) {
309
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
12 PutFileContents(path, mapBBBLedValue(led));
310 12 return;
311 }
312
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
28 const std::string& value = mapBBBLedValue(def);
313
3/6
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
28 std::string offered = " " + GetFileContents(path) + " ";
314 28 std::replace(offered.begin(), offered.end(), '\n', ' ');
315
16/30
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 24 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 24 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 23 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 24 times.
✓ Branch 13 taken 4 times.
✓ Branch 14 taken 24 times.
✓ Branch 15 taken 4 times.
✓ Branch 16 taken 28 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 28 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 27 times.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
28 if (offered.find(" " + value + " ") != std::string::npos || offered.find(" [" + value + "] ") != std::string::npos) {
316
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 PutFileContents(path, value);
317 }
318
4/4
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 12 times.
52 }
319 #endif
320
321 #ifdef PLATFORM_BB64
322 //
323 // The PocketBeagle2's identity lives in an on-board EEPROM that u-boot reads to
324 // decide how much DDR the board has. Some boards leave the factory with it
325 // blank or half-written, and until now that was only ever noticed by the
326 // flashing paths (SD/BB64-AutoFlash.sh, SD/flash_storage.sh) -- a board that
327 // reached FPP any other way kept an unusable identity, which also costs it its
328 // M5- stats UUID.
329 //
330 // The detection is done here rather than in the shell script because the script
331 // is only cheap on a board that needs nothing done to it in the *industrial*
332 // case: on a healthy base board its "programmed PB20 but has eMMC" cross-check
333 // waits out the full eMMC timeout, ~10s, every single boot. That check is
334 // there to stop a misidentified board being FLASHED, which is not what is
335 // happening here -- by the time we boot, u-boot has already sized the RAM. So
336 // read the two fields that decide whether anything needs doing, and only fork
337 // the script when they say it does. A healthy board costs one 62-byte read.
338 //
339 // These must stay exactly the conditions check_pb2_eeprom.sh decides NEEDS_FIX
340 // from. Anything flagged here that the script calls healthy is forked again on
341 // every boot and never fixed; anything the script would repair that is not
342 // flagged here is never repaired at boot.
343 //
344 // Bytes 0..0x3d are the whole identity blob u-boot parses: the AA55 33EE
345 // header, the board-info record (name, version, serial), the DDR record and
346 // the 0xFE end marker. A factory board has no 0xFF anywhere in it. The
347 // template write can stop part way, and the serial-number write is a separate
348 // step that can still succeed afterwards -- leaving a valid magic and unit
349 // number in front of a blank board ID. That board boots without a usable
350 // identity and gives scripts/get_uuid no board serial, so any 0xFF in the blob
351 // counts as unprogrammed. The repair only fills bytes that are still 0xFF, so
352 // this flags exactly what it can fix.
353 //
354 static constexpr int PB2_IDENTITY_LEN = 0x3e;
355 7 static bool pb2EepromValid(const std::string& path) {
356
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 std::ifstream in(path, std::ios::binary);
357
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
7 if (!in.good()) {
358 ✗ return false;
359 }
360 unsigned char buf[PB2_IDENTITY_LEN];
361
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 in.read((char*)buf, sizeof(buf));
362
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (in.gcount() != (std::streamsize)sizeof(buf)) {
363 ✗ return false;
364 }
365
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
7 if (buf[0] != 0xAA || buf[1] != 0x55) {
366 1 return false;
367 }
368
2/2
✓ Branch 0 taken 315 times.
✓ Branch 1 taken 5 times.
320 for (int i = 2; i < PB2_IDENTITY_LEN; i++) {
369
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 314 times.
315 if (buf[i] == 0xFF) {
370 1 return false;
371 }
372 }
373 // The six ASCII digits of the unit number at 50..55.
374
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 5 times.
35 for (int i = 50; i < 56; i++) {
375
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
30 if (buf[i] < '0' || buf[i] > '9') {
376 ✗ return false;
377 }
378 }
379 5 return true;
380 7 }
381
382 // Both paths are overridable so this can be exercised against fixtures, exactly
383 // as capes/drivers/bb64/*.sh already allow. Nothing in FPP sets them, and the
384 // same names are honoured by the script we fork, so a fixture run stays a
385 // fixture run all the way down.
386 12 static std::string pb2Path(const char* env, const char* dflt) {
387 12 const char* v = getenv(env);
388
9/16
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
42 return (v && *v) ? std::string(v) : std::string(dflt);
389 }
390
391 6 static void checkPB2EEPROM() {
392 // Only the PocketBeagle2 family has this EEPROM at this address with this
393 // layout. The model string does not distinguish base from industrial, but
394 // it does not need to -- the script works that out if it is called.
395
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::ifstream m(pb2Path("PB2_MODEL", "/proc/device-tree/model"), std::ios::binary);
396
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if (!m.good()) {
397 ✗ return;
398 }
399
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 std::string model((std::istreambuf_iterator<char>(m)), std::istreambuf_iterator<char>());
400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (model.find("PocketBeagle2") == std::string::npos) {
401 ✗ return;
402 }
403
404
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 const std::string eeprom = pb2Path("PB2_EEPROM", "/sys/bus/i2c/devices/0-0050/eeprom");
405
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
6 if (!FileExists(eeprom)) {
406 // Nothing to repair: with 0x50 silent there is nothing to write to.
407 // The script's full diagnosis of why costs a 10s wait and cannot fix
408 // it from here, so leave that to the flashing path and just say so.
409
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("FPP - PocketBeagle2: no EEPROM at %s, board identity unavailable\n", eeprom.c_str());
410 1 return;
411 }
412
3/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 2 times.
5 if (pb2EepromValid(eeprom)) {
413 3 return;
414 }
415
416
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 printf("FPP - PocketBeagle2 EEPROM identity is blank or malformed, repairing\n");
417
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 exec("/bin/bash /opt/fpp/capes/drivers/bb64/check_pb2_eeprom.sh");
418
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if (pb2EepromValid(eeprom)) {
419 // u-boot read the old contents at power-on, so an industrial board that
420 // came up as the 512MB base variant stays that way until it reboots.
421
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 printf("FPP - PocketBeagle2 EEPROM repaired; reboot for u-boot to pick up the identity\n");
422 }
423
6/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
14 }
424 #endif
425
426 49 void configureBBB() {
427 #ifdef PLATFORM_BBB
428
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if (FileExists("/dev/mmcblk1")) {
429 // full size beagle, check the bootloader
430 ✗ int fd = open("/dev/mmcblk1", O_RDONLY);
431 ✗ lseek(fd, 393488, SEEK_SET);
432 uint8_t buf[25];
433 ✗ read(fd, buf, 23);
434 ✗ close(fd);
435 ✗ buf[23] = 0;
436 ✗ std::string uboot = (const char*)buf;
437 ✗ if (uboot != "U-Boot 2022.04-g5509547") {
438 ✗ printf("Installing new bootloader\n");
439 ✗ exec("/opt/fpp/bin.bbb/bootloader/install.sh");
440 ✗ setRawSetting("rebootFlag", "1");
441 }
442 ✗ } else {
443 // its a pocketbeagle
444 // bug in kernel/device tree on pcoketbeagle where in P2-36 is not
445 // properly set to be AIN so sensors won't read properly
446
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 exec("/usr/sbin/i2cset -y -f 0 0x24 9 5");
447 }
448
449 // Beagle LEDS
450 4 std::string pled;
451
6/18
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
12 if (getRawSetting("BBBLedPWR", pled) && !pled.empty()) {
452 ✗ if (pled == "0") {
453 ✗ pled = "0x00";
454 } else {
455 ✗ pled = "0x38";
456 }
457 ✗ exec("/usr/sbin/i2cset -f -y 0 0x24 0x0b 0x6e");
458 ✗ exec("/usr/sbin/i2cset -f -y 0 0x24 0x13 " + pled);
459 ✗ exec("/usr/sbin/i2cset -f -y 0 0x24 0x0b 0x6e");
460 ✗ exec("/usr/sbin/i2cset -f -y 0 0x24 0x13 " + pled);
461 }
462 #endif
463 #ifdef PLATFORM_BB64
464 6 checkPB2EEPROM();
465 #endif
466 #if defined(PLATFORM_BBB) || defined(PLATFORM_BB64)
467
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
10 int offset = FileExists("/sys/class/leds/beaglebone:green:usr0/trigger") ? 0 : 1;
468
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
20 setBBBLed(0, offset, "heartbeat");
469
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
20 setBBBLed(1, offset, "mmc0");
470
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
20 setBBBLed(2, offset, "cpu");
471
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 setBBBLed(3, offset, "mmc1");
472 #endif
473 49 }
474
475 // Fan thermal trip settings. The web UI (PrintFanThermalSettings in
476 // www/common.php) creates settings named FanTrip_<zone type stripped to
477 // alphanumerics>_<trip index> holding degrees C for thermal zones that have a
478 // fan cooling device bound to them (the Pi5 case/active-cooler fan, cape fans
479 // wired into a thermal zone via device tree). Trip points reset to their
480 // device tree defaults on every boot, so applyThermalSettings() runs during
481 // boot; it is also invoked directly ("fppinit applyThermal") when one of the
482 // settings is changed in the UI.
483 //
484 // The first pass each boot records the untouched device tree trip values into
485 // a snapshot in media/tmp (cleared on every boot) BEFORE applying any
486 // settings, so resetThermalSettings() ("fppinit resetThermal", the UI's
487 // "Reset to Defaults" button) can restore the hardware defaults without a
488 // reboot.
489 static const std::string FAN_TRIP_DEFAULTS_FILE = FPP_MEDIA_DIR + "/tmp/fan_thermal_defaults.json";
490 static const std::string FAN_PROBE_FILE = FPP_MEDIA_DIR + "/tmp/fan_probe.json";
491
492 10 static std::string fanTripKey(const std::string& ztype, int trip) {
493 10 std::string key;
494
2/2
✓ Branch 0 taken 110 times.
✓ Branch 1 taken 10 times.
120 for (char c : ztype) {
495
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 10 times.
110 if (isalnum((unsigned char) c)) {
496
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 key += c;
497 }
498 }
499
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 key += "_";
500
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 key += std::to_string(trip);
501 10 return key;
502 ✗ }
503
504 // Walk every "active" trip point of every thermal zone, calling
505 // cb(tripTempFile, "<sanitized zone type>_<trip index>"). Passive/critical
506 // trips belong to the kernel's throttle/shutdown logic and are never visited.
507 4 static void forEachActiveTripPoint(const std::function<void(const std::string&, const std::string&)>& cb) {
508
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 for (int zn = 0; zn < 32; zn++) {
509
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 std::string base = "/sys/class/thermal/thermal_zone" + std::to_string(zn);
510
4/6
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 3 times.
7 if (!FileExists(base + "/type")) {
511 4 break;
512 }
513
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 std::string ztype = GetFileContents(base + "/type");
514
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 TrimWhiteSpace(ztype);
515
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 for (int t = 0; t < 16; t++) {
516
3/6
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
15 std::string tripFile = base + "/trip_point_" + std::to_string(t) + "_temp";
517
3/4
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 12 times.
15 if (!FileExists(tripFile)) {
518 3 break;
519 }
520
4/8
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
12 std::string tripType = GetFileContents(base + "/trip_point_" + std::to_string(t) + "_type");
521
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 TrimWhiteSpace(tripType);
522
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 10 times.
12 if (tripType != "active") {
523 2 continue;
524 }
525
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 cb(tripFile, fanTripKey(ztype, t));
526
5/5
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 2 times.
17 }
527
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
7 }
528 4 }
529
530 // captureDefaults must ONLY be set from the boot paths, where sysfs still holds
531 // the untouched device tree values. Capturing during an on-demand apply (the
532 // UI changing a setting) could record an already-customized temperature as the
533 // "default" if the snapshot had been lost, which would make a later reset
534 // restore the user's value instead of the hardware one.
535 76 void applyThermalSettings(bool captureDefaults) {
536
3/4
✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 4 times.
76 if (FileExists("/etc/fpp/container")) {
537 72 return;
538 }
539
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Json::Value defaults;
540
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if (FileExists(FAN_TRIP_DEFAULTS_FILE)) {
541 ✗ LoadJsonFromString(GetFileContents(FAN_TRIP_DEFAULTS_FILE), defaults, JsonRoot::Object);
542 }
543 4 bool defaultsChanged = false;
544
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 forEachActiveTripPoint([&](const std::string& tripFile, const std::string& key) {
545
4/8
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
10 if (captureDefaults && !JsonHas(defaults, key)) {
546
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 std::string cur = GetFileContents(tripFile);
547
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 TrimWhiteSpace(cur);
548
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (!cur.empty()) {
549
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 defaults[key] = atoi(cur.c_str());
550 10 defaultsChanged = true;
551 }
552 10 }
553 // Read as a string and parse a float: the setting holds degrees C to one
554 // decimal place so that whole degrees F survive the conversion both ways
555 // (see PutSetting() in www/api/controllers/settings.php). getRawSettingInt()
556 // must not be used here - its hand-rolled digit loop does not stop at the
557 // decimal point and would turn "29.4" into 2884.
558 10 std::string tempStr;
559
4/6
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 8 times.
10 if (getRawSetting("FanTrip_" + key, tempStr)) {
560 2 double temp = strtod(tempStr.c_str(), nullptr);
561
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (temp > 0) {
562
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 printf("FPP - Setting fan trip point %s to %.1fC\n", key.c_str(), temp);
563
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 PutFileContents(tripFile, std::to_string((int) std::lround(temp * 1000.0)));
564 }
565 }
566 10 });
567
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 if (defaultsChanged) {
568
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 PutFileContents(FAN_TRIP_DEFAULTS_FILE, SaveJsonToString(defaults));
569 }
570 4 }
571
572 ✗ void resetThermalSettings() {
573 ✗ if (FileExists("/etc/fpp/container")) {
574 ✗ return;
575 }
576 // Remove all FanTrip_ settings (same rewrite approach as setRawSetting)
577 ✗ std::string content = GetFileContents(FPP_MEDIA_DIR + "/settings");
578 ✗ std::vector<std::string> lines = split(content, '\n');
579 ✗ content = "";
580 ✗ for (auto& line : lines) {
581 ✗ if (!line.empty() && !line.starts_with("FanTrip_")) {
582 ✗ content += line;
583 ✗ content += "\n";
584 }
585 }
586 ✗ PutFileContents(FPP_MEDIA_DIR + "/settings", content);
587
588 // Restore the device tree default temperatures captured at boot. If the
589 // snapshot is somehow gone (media/tmp cleared by hand mid-run), the
590 // settings removed above still restore the defaults on the next boot, so
591 // warn rather than fail.
592 ✗ Json::Value defaults;
593 ✗ if (FileExists(FAN_TRIP_DEFAULTS_FILE) && LoadJsonFromString(GetFileContents(FAN_TRIP_DEFAULTS_FILE), defaults, JsonRoot::Object)) {
594 ✗ forEachActiveTripPoint([&](const std::string& tripFile, const std::string& key) {
595 ✗ if (JsonHas(defaults, key)) {
596 ✗ printf("FPP - Restoring fan trip point %s to %dmC\n", key.c_str(), defaults[key].asInt());
597 ✗ PutFileContents(tripFile, std::to_string(defaults[key].asInt()));
598 }
599 ✗ });
600 } else {
601 ✗ printf("FPP - No fan trip point defaults snapshot; settings cleared, defaults restore on next boot\n");
602 }
603 ✗ }
604
605 // A pwm-fan hwmon node always exposes fanN_input (the tachometer) even when no
606 // fan -- or a dead fan -- is wired to it: it simply reads 0 RPM. That is
607 // indistinguishable from a healthy fan the thermal governor has merely turned
608 // off, so the reading is worse than useless (it looks like a stalled fan). To
609 // tell "off" from "absent/dead", force each fan on and read its tachometer.
610 //
611 // Lowering a trip point does NOT reliably wake the (poll-disabled) thermal
612 // governor on the Pi5/K16Pro kernels, and driving the cooling-device cur_state
613 // ramps only gradually, so drive the hwmon PWM directly (pwm1_enable=1 +
614 // pwm1=max). A healthy fan spins up to thousands of RPM within ~150ms; an
615 // absent/dead one stays 0. The pre-probe PWM state is restored afterwards (the
616 // governor reasserts control on the next thermal event).
617 //
618 // The result is written to media/tmp/fan_probe.json (wiped every boot), keyed by
619 // "<hwmon name>:<fan index>", so Sensors::DetectFanSensors() in fppd can suppress
620 // the RPM display for a fan whose tachometer can neither be controlled nor read.
621 // This runs during the boot "start" phase, before fppd caches its sensor list.
622 39 void probeFanPresence() {
623
3/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 4 times.
39 if (FileExists("/etc/fpp/container")) {
624 35 return;
625 }
626
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Json::Value result;
627
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 for (int h = 0; h < 32; h++) {
628
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 std::string hwmon = "/sys/class/hwmon/hwmon" + std::to_string(h);
629
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 8 times.
12 if (!DirectoryExists(hwmon)) {
630 4 break;
631 }
632 8 std::vector<int> fans;
633
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 8 times.
72 for (int f = 1; f <= 8; f++) {
634
6/10
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 64 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 64 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 62 times.
64 if (FileExists(hwmon + "/fan" + std::to_string(f) + "_input")) {
635
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 fans.push_back(f);
636 }
637 }
638
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 if (fans.empty()) {
639 6 continue;
640 }
641
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 std::string name = GetFileContents(hwmon + "/name");
642
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 TrimWhiteSpace(name);
643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (name.empty()) {
644 ✗ name = "hwmon" + std::to_string(h);
645 }
646
647 // Force the fan on via the hwmon PWM interface, remembering the current
648 // state so it can be restored. pwm1 drives every fan on a pwm-fan node.
649
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 std::string pwmFile = hwmon + "/pwm1";
650
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 std::string enFile = hwmon + "/pwm1_enable";
651
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 bool forced = FileExists(pwmFile);
652 2 std::string origPwm, origEn;
653
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (forced) {
654
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 origPwm = GetFileContents(pwmFile);
655
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 TrimWhiteSpace(origPwm);
656
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if (FileExists(enFile)) {
657
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 origEn = GetFileContents(enFile);
658
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 TrimWhiteSpace(origEn);
659
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 PutFileContents(enFile, "1");
660 }
661
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 PutFileContents(pwmFile, "255");
662 }
663
664 // Sample each tachometer until it reads non-zero (healthy fans spin up
665 // within ~150ms); cap at ~0.7s so an absent/dead fan can't stall boot.
666
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 std::vector<int> rpm(fans.size(), 0);
667
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 for (int s = 0; s < 7; s++) {
668
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 std::this_thread::sleep_for(std::chrono::milliseconds(100));
669 8 bool anyZero = false;
670
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 for (size_t fi = 0; fi < fans.size(); fi++) {
671
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (rpm[fi] == 0) {
672
4/8
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
8 std::string r = GetFileContents(hwmon + "/fan" + std::to_string(fans[fi]) + "_input");
673
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 TrimWhiteSpace(r);
674 8 rpm[fi] = atoi(r.c_str());
675
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if (rpm[fi] == 0) {
676 7 anyZero = true;
677 }
678 8 }
679 }
680
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if (!anyZero) {
681 1 break;
682 }
683 }
684
685 // Restore the pre-probe PWM state.
686
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (forced) {
687
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 PutFileContents(pwmFile, origPwm);
688
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!origEn.empty()) {
689
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 PutFileContents(enFile, origEn);
690 }
691 }
692
693
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (size_t fi = 0; fi < fans.size(); fi++) {
694
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 std::string key = name + ":" + std::to_string(fans[fi]);
695
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 Json::Value e;
696
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 e["rpm"] = rpm[fi];
697
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 e["present"] = rpm[fi] > 0;
698
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 result[key] = e;
699
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 printf("FPP - Fan probe %s: %d RPM (%s)\n", key.c_str(), rpm[fi],
700
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 rpm[fi] > 0 ? "present" : "no tach signal, RPM display suppressed");
701 2 }
702
5/5
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 6 times.
18 }
703
3/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
4 if (result.size() > 0) {
704
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 PutFileContents(FAN_PROBE_FILE, SaveJsonToString(result));
705 }
706 4 }
707
708 76 void setFileOwnership() {
709
2/4
✓ Branch 0 taken 76 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 76 times.
✗ Branch 3 not taken.
76 exec("/usr/bin/chown -R fpp:fpp " + FPP_MEDIA_DIR);
710 76 }
711
712 39 bool checkUnpartitionedSpace() {
713 39 bool ret = false;
714
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 if (!FileExists("/etc/fpp/desktop")) {
715
2/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
39 std::string sourceDev = execAndReturn("/usr/bin/findmnt -n -o SOURCE " + FPP_MEDIA_DIR);
716
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 TrimWhiteSpace(sourceDev);
717
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 35 times.
39 if (sourceDev.empty()) {
718
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 sourceDev = execAndReturn("/usr/bin/findmnt -n -o SOURCE /");
719
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 TrimWhiteSpace(sourceDev);
720 }
721
4/6
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 35 times.
78 if (startsWith(sourceDev, "/dev/")) {
722
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 sourceDev = sourceDev.substr(5);
723 4 std::string osd;
724
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 getRawSetting("storageDevice", osd);
725
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (osd != sourceDev) {
726
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 setRawSetting("storageDevice", osd);
727 }
728 4 }
729
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 std::string fs = "0";
730
3/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 31 times.
39 if (FileExists(SD_CARD_DEVICE)) {
731
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
8 fs = execAndReturn("/usr/sbin/sfdisk -F " + SD_CARD_DEVICE + " | tail -n 1");
732
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 TrimWhiteSpace(fs);
733
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 auto splits = split(fs, ' ');
734 // sfdisk missing or failing prints nothing; back() of an empty vector is undefined
735
6/10
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
10 fs = splits.empty() ? "0" : splits.back();
736
4/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 2 times.
16 if (endsWith(fs, "G")) {
737
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 fs = fs.substr(0, fs.size() - 1);
738 } else {
739
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 fs = "0";
740 }
741 8 }
742
7/10
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 35 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 35 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 35 times.
39 if (FileExists("/boot/firmware/fpp_expand_rootfs") || FileExists("/boot/fpp_expand_rootfs")) {
743
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 fs = "0";
744
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 std::string rootPart = execAndReturn("/usr/bin/findmnt -n -o SOURCE /");
745
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 TrimWhiteSpace(rootPart);
746
3/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
4 if (startsWith(rootPart, SD_CARD_DEVICE)) {
747
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 std::string lastPartNum = execAndReturn("/usr/sbin/parted " + SD_CARD_DEVICE + " -ms unit s p | tail -n 1 | cut -f 1 -d:");
748
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 TrimWhiteSpace(lastPartNum);
749
5/10
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
3 std::string startPos = execAndReturn("/usr/sbin/parted " + SD_CARD_DEVICE + " -ms unit s p | grep \"^" + lastPartNum + "\" | cut -f 2 -d: | sed 's/[^0-9]//g'");
750
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 TrimWhiteSpace(startPos);
751
6/12
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
3 std::string fdiskInstructions = "p\nd\n" + lastPartNum + "\nn\np\n" + lastPartNum + "\n" + startPos + "\n\np\nw\n";
752
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 PutFileContents("/tmp/fdisk.cmds", fdiskInstructions);
753
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 exec("/usr/sbin/fdisk " + SD_CARD_DEVICE + " < /tmp/fdisk.cmds");
754 3 unlink("/tmp/fdisk.cmds");
755
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 exec("systemctl enable fpp-expand-rootfs.service");
756
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
9 setRawSetting("rebootFlag", "1");
757 3 ret = true;
758 3 }
759 4 unlink("/boot/firmware/fpp_expand_rootfs");
760 4 unlink("/boot/fpp_expand_rootfs");
761 4 }
762 39 std::string oldfs;
763
2/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
39 getRawSetting("UnpartitionedSpace", oldfs);
764
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 9 times.
39 if (oldfs != fs) {
765
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
60 setRawSetting("UnpartitionedSpace", fs);
766 }
767 39 }
768 39 return ret;
769 }
770 1 void resizeRootFS() {
771
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 std::string rootPart = execAndReturn("/usr/bin/findmnt -n -o SOURCE /");
772
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 TrimWhiteSpace(rootPart);
773
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 exec("/usr/sbin/resize2fs " + rootPart);
774 // --no-reload is important: a bare "systemctl disable" performs an implicit
775 // daemon-reload, which on a single-core SBC (e.g. BeagleBone) takes ~11s and
776 // freezes systemd's entire job queue mid-boot -- stalling dbus, networkd, and
777 // fppinit. The removed symlink takes effect next boot regardless, so there's
778 // no reason to reload now.
779
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 exec("systemctl disable --no-reload fpp-expand-rootfs.service");
780 1 }
781 79 void setupTimezone() {
782 79 std::string s;
783
2/4
✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79 times.
✗ Branch 3 not taken.
79 getRawSetting("TimeZone", s);
784
1/2
✓ Branch 0 taken 79 times.
✗ Branch 1 not taken.
79 TrimWhiteSpace(s);
785
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 75 times.
79 if (!s.empty()) {
786 // Debian 13 (trixie) no longer ships /etc/timezone -- the timezone is
787 // tracked solely by the /etc/localtime symlink. Reading the old file
788 // therefore always returned empty, so this used to run the expensive
789 // `timedatectl set-timezone` (a dbus round-trip to systemd-timedated
790 // that blocks ~15s on a single-core SBC) plus a backgrounded
791 // `dpkg-reconfigure tzdata` on EVERY boot, and twice (fppinit start +
792 // postNetwork). Derive the current zone by reading the /etc/localtime
793 // symlink target (a single syscall, no fork) and only reconfigure when
794 // it actually differs. The target looks like
795 // ".../usr/share/zoneinfo/America/New_York"; the zone is everything
796 // after "zoneinfo/".
797 4 std::string c;
798 4 std::error_code ec;
799
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 std::filesystem::path tzTarget = std::filesystem::read_symlink("/etc/localtime", ec);
800
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (!ec) {
801
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 std::string t = tzTarget.string();
802 4 size_t pos = t.find("zoneinfo/");
803
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (pos != std::string::npos) {
804
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 c = t.substr(pos + 9); // strlen("zoneinfo/")
805 }
806 4 }
807
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 TrimWhiteSpace(c);
808
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if (!isShellSafeWord(s)) {
809 ✗ printf("Ignoring invalid TimeZone setting\n");
810
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 } else if (c != s) {
811
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 printf("Resetting timezone from %s to %s\n", c.c_str(), s.c_str());
812
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 exec("/usr/bin/timedatectl set-timezone " + s);
813
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 execbg("/usr/sbin/dpkg-reconfigure -f noninteractive tzdata &");
814 }
815 4 }
816 79 }
817
818 37 void cleanupChromiumFiles() {
819
2/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
37 exec("/usr/bin/rm -rf /home/fpp/.config/chromium/Singleton* 2>/dev/null > /dev/null");
820 37 }
821
822 42 void setupKiosk(bool force) {
823
2/4
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
42 int km = getRawSettingInt("Kiosk", 0);
824
4/4
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 36 times.
42 if (km || force) {
825
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 std::string url = "http://localhost/";
826
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 getRawSetting("KioskUrl", url);
827
828 // FPP UI doesn't delete the setting, it makes it ""
829
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
6 if (url == "\"\"") {
830
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 url = "http://localhost/";
831 }
832
833
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string value = "{\"RestoreOnStartup\": 4,\"RestoreOnStartupURLs\": [\"" + url + "\"]}";
834 6 mkdir("/etc/chromium/", 0775);
835 6 mkdir("/etc/chromium/policies", 0775);
836 6 mkdir("/etc/chromium/policies/managed", 0775);
837
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 PutFileContents("/etc/chromium/policies/managed/policy.json", value);
838 6 }
839 42 }
840 39 void checkInstallKiosk() {
841
2/4
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
39 int km = getRawSettingInt("Kiosk", 0);
842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
39 if (FileExists("/fpp_kiosk")) {
843 ✗ km = true;
844 }
845
846
6/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 38 times.
39 if (km && !FileExists("/etc/fpp/kiosk")) {
847
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 std::string s = execAndReturn("/usr/bin/systemctl is-enabled fpp-install-kiosk");
848
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 TrimWhiteSpace(s);
849
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (s == "disabled") {
850
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 exec("/usr/bin/systemctl enable fpp-install-kiosk");
851
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 exec("/usr/sbin/reboot");
852 }
853 1 }
854 39 }
855 3 void installKiosk() {
856
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 int km = getRawSettingInt("Kiosk", 0);
857
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (FileExists("/fpp_kiosk")) {
858 1 unlink("/fpp_kiosk");
859 1 km = true;
860 }
861
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 if (km && !FileExists("/etc/fpp/kiosk")) {
862 // need to re-install kiosk mode
863
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 exec("/opt/fpp/SD/FPP_Kiosk.sh");
864
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (FileExists("/etc/fpp/kiosk")) {
865 ✗ exec("/usr/sbin/reboot");
866 }
867 3 setupKiosk(true);
868 }
869 3 }
870
871 // Run "apt-get <args>" synchronously and return true only if it exited 0.
872 12 static bool runAptGet(const std::vector<std::string>& args) {
873 12 pid_t pid = fork();
874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (pid == -1) {
875 ✗ printf("Error: Failed to fork process\n");
876 ✗ return false;
877
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 } else if (pid == 0) {
878 12 std::vector<char*> argv;
879
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 argv.push_back(const_cast<char*>("apt-get"));
880
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 12 times.
78 for (const auto& a : args) {
881
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 argv.push_back(const_cast<char*>(a.c_str()));
882 }
883
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 argv.push_back(nullptr);
884 12 execvp("apt-get", argv.data());
885 // If execvp fails, exit the child directly (don't fall back into the
886 // parent's control flow).
887
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
12 printf("Error: Failed to execute apt-get\n");
888 ✗ _exit(127);
889 ✗ }
890 12 int status = 0;
891
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 waitpid(pid, &status, 0);
892
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 3 times.
12 return WIFEXITED(status) && WEXITSTATUS(status) == 0;
893 }
894
895 // A package name apt takes as one package and never as an option: Debian
896 // policy characters, 2-255 long, optional ":arch". The PHP side validates the
897 // same way before writing the list, but the file is hand-editable and
898 // restorable from a backup, and every name here becomes root apt-get argv --
899 // a leading '-' would be an apt option. Hand-rolled rather than std::regex so
900 // it cannot throw. Apt's other trap, an unanchored regex fallback for a name
901 // containing '.' that no longer exists, is closed by packageKnownToApt().
902 12 static bool validPackageName(const std::string& n) {
903
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
12 if (n.size() < 2 || n.size() > 255) {
904 ✗ return false;
905 }
906 12 size_t colon = n.find(':');
907
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 std::string base = n.substr(0, colon);
908
6/8
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 73 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
81 auto lowerAlnum = [](char c) { return (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'); };
909
6/10
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 9 times.
12 if (base.size() < 2 || !lowerAlnum(base.front()) || (!lowerAlnum(base.back()) && base.back() != '+')) {
910 3 return false;
911 }
912
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 9 times.
69 for (char c : base) {
913
6/10
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 55 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 60 times.
60 if (!lowerAlnum(c) && c != '+' && c != '.' && c != '-') {
914 ✗ return false;
915 }
916 }
917
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (colon != std::string::npos) {
918 ✗ std::string arch = n.substr(colon + 1);
919 ✗ if (arch.empty()) {
920 ✗ return false;
921 }
922 ✗ for (char c : arch) {
923 ✗ if (!lowerAlnum(c) && c != '-') {
924 ✗ return false;
925 }
926 }
927 ✗ }
928 9 return true;
929 12 }
930
931 // Whether apt's lists know this exact name. 'apt-get install' falls back to
932 // an unanchored regex for an unknown name containing '.', so a versioned
933 // name that vanished in the new release (libfoo1.2) could select something
934 // else entirely; 'apt-cache pkgnames' lists exact names only, one per line
935 // (--all-names so a virtual package name apt can install is not refused).
936 // The name has passed validPackageName() (no shell characters), so the
937 // usual execAndReturn() is fine here.
938 6 static bool packageKnownToApt(const std::string& name) {
939
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 std::string base = name.substr(0, name.find(':'));
940 6 std::string out;
941 try {
942
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 out = execAndReturn("apt-cache --all-names pkgnames " + base);
943 ✗ } catch (const std::exception&) {
944 ✗ return true; // can't check: let apt decide, as before
945 ✗ }
946
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 return ("\n" + out).find("\n" + base + "\n") != std::string::npos;
947 6 }
948
949 // Extract a package name from a userpackages.json entry. Supports both the
950 // legacy schema (a bare string) and the ownership schema
951 // ({"package": "name", "requestedBy": [...], "via": [...]} written by the PHP
952 // package helpers). Returns "" when the entry carries no usable package name,
953 // and for an entry with a non-empty "via": that is a dependency some other
954 // entry's install pulled in, and its parent's install re-pulls it under
955 // whatever the new OS calls it -- replaying the recorded (often versioned)
956 // name would fail on every boot once the release renames it.
957 14 static std::string packageNameFromJson(const Json::Value& item) {
958
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 6 times.
14 if (item.isString()) {
959 8 return item.asString();
960 }
961
9/22
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 6 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
18 if (JsonHas(item, "package") && item["package"].isString()) {
962
14/28
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 6 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 6 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 2 times.
✓ Branch 23 taken 4 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
18 if (JsonHas(item, "via") && item["via"].isArray() && !item["via"].empty()) {
963
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 return "";
964 }
965 4 return item["package"].asString();
966 }
967 ✗ return "";
968 }
969
970 // Reads the user package list into $out: size-capped so a runaway file
971 // cannot exhaust a small board's memory before it is even parsed, every name
972 // validated, duplicates dropped. Returns false when the file is missing or
973 // unusable -- nothing to replay, and nothing a retry would fix. jsoncpp's
974 // parser throws on input nested past its stack limit; the caller catches.
975 18 static bool readUserPackages(const std::string& filePath, std::vector<std::string>& out) {
976 18 std::error_code ec;
977
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 auto size = std::filesystem::file_size(filePath, ec);
978
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 10 times.
18 if (ec) {
979
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (ec == std::errc::no_such_file_or_directory) {
980
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 printf("No user package list at %s, nothing to install\n", filePath.c_str());
981 } else {
982 ✗ printf("Error: user package list %s: %s; skipping\n", filePath.c_str(), ec.message().c_str());
983 }
984 8 return false;
985 }
986
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 if (size > 4 * 1024 * 1024) {
987
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("Error: user package list is %ju bytes; refusing to process it\n", (uintmax_t)size);
988 1 return false;
989 }
990
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 Json::Value root;
991
5/6
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 5 times.
11 if (!LoadJsonFromString(GetFileContents(filePath), root, JsonRoot::Array)) {
992 // Malformed or wrong-shaped; won't fix itself on retry. The loader has
993 // already said what was wrong with it.
994
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 printf("Error: user package list %s is not usable; skipping\n", filePath.c_str());
995 2 return false;
996 }
997 // A real list is tens of entries. Beyond this the de-dup below and the
998 // one-apt-call-per-name loop after it are minutes of boot.
999
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 if (root.size() > 1000) {
1000 ✗ printf("Error: user package list has %u entries; refusing to process it\n", root.size());
1001 ✗ return false;
1002 }
1003 5 int rejected = 0;
1004 5 std::string firstRejected;
1005
7/12
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 14 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 19 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 14 times.
✓ Branch 11 taken 5 times.
19 for (const auto& item : root) {
1006
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 std::string pkg = packageNameFromJson(item);
1007
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12 times.
14 if (pkg.empty()) {
1008 2 continue;
1009 }
1010
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 9 times.
12 if (!validPackageName(pkg)) {
1011
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (rejected++ == 0) {
1012 // Printable ASCII only, truncated: this goes to the boot log.
1013
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✓ Branch 3 taken 2 times.
48 for (char c : pkg.substr(0, 64)) {
1014
3/6
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 46 times.
✗ Branch 5 not taken.
46 firstRejected += (c >= 0x20 && c < 0x7f) ? c : '?';
1015 2 }
1016 }
1017 3 continue;
1018 3 }
1019 9 bool seen = false;
1020
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 7 times.
13 for (const auto& have : out) {
1021
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (have == pkg) {
1022 2 seen = true;
1023 2 break;
1024 }
1025 }
1026
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
9 if (!seen) {
1027
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 out.push_back(pkg);
1028 }
1029
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 5 times.
14 }
1030
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (rejected) {
1031
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 printf("Skipping %d invalid package name(s) in user package list (first: '%s')\n",
1032 rejected, firstRejected.c_str());
1033 }
1034 5 return true;
1035 9 }
1036
1037 // Returns true if there is nothing to do or every package installed; false only
1038 // when an apt failure occurred that is worth retrying on the next boot. The
1039 // DPkg::Lock::Timeout option lets apt wait for a concurrent install at boot
1040 // instead of failing immediately.
1041 18 bool installPackagesFromJson(const std::string& filePath) {
1042 18 std::vector<std::string> packages;
1043 try {
1044
4/4
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 5 times.
18 if (!readUserPackages(filePath, packages)) {
1045 11 return true;
1046 }
1047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } catch (const std::exception& e) {
1048 // jsoncpp throws Json::RuntimeError on a file nested deeper than its
1049 // stack limit (a 1001-character "[[[[" file). This is fppinit: a bad
1050 // list must never take boot down.
1051
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 printf("Error: user package list could not be processed (%s); skipping\n", e.what());
1052 2 return true;
1053 2 }
1054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (packages.empty()) {
1055 ✗ return true;
1056 }
1057
1058 // Non-Debian platforms (Fedora, MacOS, ...) have no apt-get; there is
1059 // nothing we can replay. Consume the trigger rather than retrying forever.
1060
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 if (!FileExists("/usr/bin/apt-get")) {
1061 ✗ printf("apt-get not available on this platform; skipping user package install\n");
1062 ✗ return true;
1063 }
1064
1065 // Refresh the package lists first. A freshly flashed OS may ship stale/empty
1066 // lists, and this can run at boot before the network is fully up, so retry a
1067 // few times before giving up.
1068 5 bool updated = false;
1069
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 for (int i = 1; i <= 3; i++) {
1070
4/6
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 3 times.
21 if (runAptGet({ "-o", "DPkg::Lock::Timeout=60", "update" })) {
1071 4 updated = true;
1072 4 break;
1073 }
1074
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 printf("Warning: apt-get update failed (attempt %d), retrying...\n", i);
1075
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 sleep(5);
1076 }
1077
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 if (!updated) {
1078
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("Error: apt-get update never succeeded - will retry user packages on next boot\n");
1079 1 return false;
1080 }
1081
1082 4 bool allOk = true;
1083
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4 times.
10 for (const auto& pkg : packages) {
1084
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
6 if (!packageKnownToApt(pkg)) {
1085 // Renamed or dropped in the new release. Not retryable, and not
1086 // something to hand to apt's regex fallback.
1087
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("Warning: no package named %s in the new OS; skipping\n", pkg.c_str());
1088 1 continue;
1089 }
1090
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 printf("Installing: %s\n", pkg.c_str());
1091 // confdef/confold: with no stdin, dpkg's conffile prompt (a config
1092 // file the old OS left behind) would fail the install and leave the
1093 // package half-configured for every later apt run.
1094
5/10
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
60 if (!runAptGet({ "-o", "DPkg::Lock::Timeout=60", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install", "-y", pkg })) {
1095 ✗ printf("Warning: Package installation failed for %s\n", pkg.c_str());
1096 ✗ allOk = false;
1097 }
1098 }
1099 4 return allOk;
1100
9/22
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 5 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
28 }
1101
1102 // A plugin is considered "installed" if its directory contains a pluginInfo.json
1103 // manifest (same rule the web layer's GetInstalledPlugins() uses). Used to decide
1104 // whether the post-FPPOS-upgrade "plugins must be reinstalled" warning applies.
1105 18 static bool anyPluginsInstalled() {
1106
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 std::string dir = FPP_MEDIA_DIR + "/plugins";
1107
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 if (!DirectoryExists(dir)) {
1108 ✗ return false;
1109 }
1110
5/8
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 15 times.
19 for (const auto& entry : std::filesystem::directory_iterator(dir)) {
1111
11/22
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3 times.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
4 if (entry.is_directory() && FileExists(entry.path().string() + "/pluginInfo.json")) {
1112 3 return true;
1113 }
1114
6/6
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 15 times.
✓ Branch 5 taken 3 times.
24 }
1115 15 return false;
1116 18 }
1117
1118 // FPP 10 changed the default MultiSync send method from Multicast to
1119 // Unicast-to-known-remotes for fresh installs (see www/settings.json's
1120 // MultiSyncUnicast "default": 1). An FPPOS reflash replaces /opt/fpp
1121 // (settings.json included) but preserves /home/fpp/media/settings from the
1122 // prior install untouched -- so an existing multisync user who never
1123 // explicitly recorded a send method (multicast was implicit/default before
1124 // unicast existed) would otherwise silently flip to unicast the moment this
1125 // new code boots. Pin them to their historical multicast behavior instead.
1126 // (Fresh installs and normal in-place `fpp upgrade`s are handled separately,
1127 // by upgrade/122/upgrade.sh via the version-gated upgrade_config path.)
1128 18 static void migrateMultiSyncDefaultToMulticast() {
1129
4/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 4 times.
36 if (getRawSettingInt("MultiSyncEnabled", 0) != 1) {
1130 14 return;
1131 }
1132
1133 // No send method recorded at all -> the user was relying on the pre-FPP-10
1134 // implicit multicast behavior. Make it explicit.
1135
4/10
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
12 if (getRawSettingInt("MultiSyncMulticast", 0) != 1 &&
1136
10/18
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
20 getRawSettingInt("MultiSyncBroadcast", 0) != 1 &&
1137
10/16
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
8 getRawSettingInt("MultiSyncUnicast", 0) != 1) {
1138
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
4 setRawSetting("MultiSyncMulticast", "1");
1139 }
1140
1141 // Pin MultiSyncUnicast off whenever the key is simply ABSENT, independent of
1142 // what the other two are set to. This must not be folded into the branch
1143 // above: a user who had explicitly chosen multicast or broadcast skips that
1144 // branch entirely, so the key stayed absent -- and an absent key is not
1145 // neutral. It resolves differently depending on who is asking:
1146 //
1147 // www/common.php IfSettingEqualPrint() -> settings.json "default": 1
1148 // src/settings.cpp LoadSettingsInfo() -> settings.json "default": 1
1149 // getRawSettingInt() (right here) -> 0, the file is read directly
1150 //
1151 // So an upgraded box would show "Send MultiSync to ALL KNOWN remotes via
1152 // Unicast" ticked in the UI *and* have fppd genuinely unicast to every
1153 // remote, on top of whatever method the user actually chose -- while this
1154 // migration, reading raw, saw nothing wrong. Writing the key makes all
1155 // three readers agree.
1156 //
1157 // Only absence is corrected: an explicit 0 or 1 is the user's own choice.
1158 4 std::string existing;
1159
4/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
8 if (!getRawSetting("MultiSyncUnicast", existing)) {
1160
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
8 setRawSetting("MultiSyncUnicast", "0");
1161 }
1162 4 }
1163
1164 // FPP 10 removed the "Remote ..." commands. Each took the remote host as its
1165 // first argument and forwarded the rest, unchanged, to the command named here
1166 // on that host; the same thing is now the plain command with Multisync turned
1167 // on and the host in multisyncHosts. Rewrites one stored command in place.
1168 6 static bool convertRemoteCommand(Json::Value& cmd) {
1169 static const std::map<std::string, std::string> REPLACEMENTS = {
1170 { "Remote Trigger Command Preset", "Trigger Command Preset" },
1171 { "Remote Trigger Command Preset Slot", "Trigger Command Preset Slot" },
1172 { "Remote Effect Start", "Effect Start" },
1173 { "Remote FSEQ Effect Start", "FSEQ Effect Start" },
1174 { "Remote Effect Stop", "Effect Stop" },
1175 { "Remote Playlist Start", "Start Playlist" },
1176 { "Remote Run Script", "Run Script" },
1177
6/12
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 7 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
15 };
1178
10/20
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 6 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 6 times.
6 if (!cmd["command"].isString() || !cmd["args"].isArray() || cmd["args"].empty()) {
1179 ✗ return false;
1180 }
1181
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 auto it = REPLACEMENTS.find(cmd["command"].asString());
1182
6/12
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 6 times.
6 if (it == REPLACEMENTS.end() || !cmd["args"][0].isString()) {
1183 ✗ return false;
1184 }
1185 // An empty host would become "every host", and multisyncHosts is not
1186 // variable-substituted the way the old argument was; leave those for the
1187 // user to fix (the playlist validator reports them).
1188
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 std::string host = cmd["args"][0].asString();
1189
6/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
6 if (host.empty() || host.find('%') != std::string::npos) {
1190 2 return false;
1191 }
1192
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Json::Value args(Json::arrayValue);
1193
4/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 4 times.
12 for (Json::ArrayIndex i = 1; i < cmd["args"].size(); i++) {
1194
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
8 args.append(cmd["args"][i]);
1195 }
1196
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 cmd["command"] = it->second;
1197
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 cmd["args"] = args;
1198
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 cmd["multisyncCommand"] = true;
1199
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 cmd["multisyncHosts"] = host;
1200 4 return true;
1201
7/18
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
7 }
1202
1203 // Walks any stored config -- playlist, schedule, command presets, GPIO inputs
1204 // -- converting every object shaped like a command.
1205 56 static int convertRemoteCommands(Json::Value& v) {
1206 56 int count = 0;
1207
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 47 times.
56 if (v.isObject()) {
1208
6/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 5 times.
9 if (v.isMember("command") && convertRemoteCommand(v)) {
1209 4 count++;
1210 }
1211
3/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 9 times.
43 for (const auto& name : v.getMemberNames()) {
1212
2/4
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
34 count += convertRemoteCommands(v[name]);
1213 9 }
1214
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 37 times.
47 } else if (v.isArray()) {
1215
6/10
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 28 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 18 times.
✓ Branch 9 taken 10 times.
28 for (auto& e : v) {
1216
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 count += convertRemoteCommands(e);
1217 }
1218 }
1219 56 return count;
1220 }
1221
1222 // "master" mode was folded into Player in FPP 5.0 (sending sync packets became
1223 // the MultiSyncEnabled setting). The loaders in settings.cpp and config.php still
1224 // map a stored fppMode=master to player in memory, but never write it back, so the
1225 // settings file kept the old value indefinitely -- invisible to the UI and API
1226 // (both report the mapped value), but visible to backup/restore and anything
1227 // reading the file directly. Write the same mapping back once. Runs before
1228 // every fppd start; idempotent, since it only acts while fppMode is "master".
1229 3 void migrateLegacyFppMode() {
1230 3 std::string mode;
1231
11/20
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 2 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
9 if (getRawSetting("fppMode", mode) && mode == "master") {
1232
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("FPP - Converting legacy fppMode=master to player with MultiSync enabled\n");
1233
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
4 setRawSetting("fppMode", "player");
1234
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
4 setRawSetting("MultiSyncEnabled", "1");
1235 }
1236 3 }
1237
1238 // Runs before every fppd start, so fppd never loads one of the removed
1239 // commands, whether the file came from an older install, a restore, or a copy
1240 // from another player. Idempotent: a file is only parsed if it mentions a
1241 // Remote command, and only rewritten if something was converted.
1242 3 void migrateRemoteCommands() {
1243 std::vector<std::string> files = {
1244 FPP_MEDIA_DIR + "/config/schedule.json",
1245 FPP_MEDIA_DIR + "/config/commandPresets.json",
1246 FPP_MEDIA_DIR + "/config/gpio.json",
1247
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
15 };
1248
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 std::string playlistDir = FPP_MEDIA_DIR + "/playlists";
1249
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 if (DirectoryExists(playlistDir)) {
1250
5/8
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 3 times.
5 for (const auto& entry : std::filesystem::directory_iterator(playlistDir)) {
1251
8/20
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
2 if (entry.is_regular_file() && entry.path().extension() == ".json") {
1252
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 files.push_back(entry.path().string());
1253 }
1254 3 }
1255 }
1256
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3 times.
14 for (const auto& file : files) {
1257
3/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 5 times.
11 if (!FileExists(file)) {
1258 7 continue;
1259 }
1260
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string contents = GetFileContents(file);
1261
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 if (contents.find("\"Remote ") == std::string::npos) {
1262 1 continue;
1263 }
1264 try {
1265
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Json::Value root;
1266
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if (!LoadJsonFromString(contents, root)) {
1267 ✗ continue;
1268 }
1269
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 int count = convertRemoteCommands(root);
1270
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (count) {
1271
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 Json::StreamWriterBuilder wbuilder;
1272
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
12 wbuilder["indentation"] = "\t";
1273 // Keep e.g. a 1.1 duration from coming back as 1.1000000000000001.
1274
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
12 wbuilder["precision"] = 15;
1275
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 PutFileContents(file, Json::writeString(wbuilder, root));
1276
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 printf("FPP - Converted %d removed Remote command(s) to Multisync in %s\n", count, file.c_str());
1277 4 }
1278
1/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4 } catch (const std::exception& e) {
1279 ✗ printf("FPP - Could not convert Remote commands in %s: %s\n", file.c_str(), e.what());
1280 ✗ }
1281
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 }
1282
3/10
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
6 }
1283
1284 // Touched by a restore (www/backup.php, www/copystorage.php). It asks for
1285 // the part of a reflash's reconciliation a restore needs -- the restored
1286 // userpackages.json installed, the restored settings migrated -- and not the
1287 // rest: the OS and the plugins built for it are still this box's.
1288 static const char* FPP_RESTORED_MARKER = "/fpp_restored";
1289
1290 // Config-state migrations that must survive an FPPOS reflash, gated on the
1291 // same /fppos_upgraded marker as checkInstallPackages() (touched by
1292 // upgradeOS-part2.sh, which is always sourced from the target image being
1293 // flashed -- see the note in upgradeOS-part1.sh -- so this runs with current
1294 // code regardless of how old the box being upgraded was). Unlike
1295 // checkInstallPackages(), this does NOT unlink /fppos_upgraded itself: package
1296 // installs may still be retrying (e.g. no network yet), and each migration
1297 // here is written to be safely idempotent, so simply re-running on a later
1298 // boot is harmless. Add future OS-upgrade-surviving config migrations here.
1299 37 void checkConfigMigrations() {
1300
5/6
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 19 times.
37 if (FileExists("/fppos_upgraded") || FileExists(FPP_RESTORED_MARKER)) {
1301 18 migrateMultiSyncDefaultToMulticast();
1302 }
1303 37 }
1304
1305 // The URL a plugin checkout was cloned from ("remote.origin.url" in its
1306 // .git/config), or "" when it is not a git checkout.
1307 5 static std::string pluginOriginURL(const std::string& dir) {
1308
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 std::string config = GetFileContents(dir + "/.git/config");
1309 5 bool inOrigin = false;
1310
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
25 for (auto line : split(config, '\n')) {
1311 25 size_t b = line.find_first_not_of(" \t");
1312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if (b == std::string::npos) {
1313 ✗ continue;
1314 }
1315
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 line = line.substr(b);
1316
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 15 times.
25 if (line[0] == '[') {
1317
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 inOrigin = line.rfind("[remote \"origin\"]", 0) == 0;
1318
6/8
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 10 times.
15 } else if (inOrigin && line.rfind("url", 0) == 0) {
1319 5 size_t eq = line.find('=');
1320
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 if (eq != std::string::npos && line.find_first_not_of(" \t", 3) == eq) {
1321
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string url = line.substr(eq + 1);
1322 5 size_t ub = url.find_first_not_of(" \t");
1323 5 size_t ue = url.find_last_not_of(" \t\r");
1324
3/10
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
5 return ub == std::string::npos ? "" : url.substr(ub, ue - ub + 1);
1325 5 }
1326 }
1327
3/5
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
30 }
1328 ✗ return "";
1329 5 }
1330
1331 // A clone URL without what could carry a credential: the userinfo before the
1332 // host and any query or fragment, as PluginHistoryURL() does in PHP. A plugin
1333 // cloned while gitHubUser/gitHubPAT were set has the token in its origin URL
1334 // (InjectGitHubCredentials()), and the settings file is readable through the
1335 // API and carried by every backup.
1336 5 static std::string pluginURLWithoutCredentials(std::string url) {
1337
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 url = url.substr(0, url.find_first_of("?#"));
1338 5 size_t scheme = url.find("://");
1339
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 size_t hostStart = scheme == std::string::npos ? 0 : scheme + 3;
1340 5 size_t hostEnd = url.find('/', hostStart);
1341
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 size_t at = url.rfind('@', hostEnd == std::string::npos ? std::string::npos : hostEnd);
1342
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
5 if (at != std::string::npos && at >= hostStart) {
1343
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 url.erase(hostStart, at + 1 - hostStart);
1344 }
1345 10 return url;
1346 }
1347
1348 // IsOfficialPluginSrcURL(): published by the FPP project, judged on the host
1349 // and the owner, not on a prefix that any userinfo or port defeats.
1350 5 static bool isOfficialPluginURL(const std::string& url) {
1351 5 size_t scheme = url.find("://");
1352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (scheme == std::string::npos) {
1353 ✗ return false;
1354 }
1355
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 std::string rest = toLowerCopy(url.substr(scheme + 3));
1356 5 size_t slash = rest.find('/');
1357
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string host = rest.substr(0, std::min(slash, rest.find(':')));
1358
4/8
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 5 times.
5 if (host != "github.com" || slash == std::string::npos) {
1359 ✗ return false;
1360 }
1361 5 size_t owner = rest.find_first_not_of('/', slash);
1362
5/8
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
11 return owner != std::string::npos && rest.compare(owner, 15, "falconchristmas") == 0 &&
1363
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
11 (owner + 15 == rest.size() || rest[owner + 15] == '/');
1364 5 }
1365
1366 // "repoName|srcURL" records, comma-separated (the PluginUnverifiedRepos form,
1367 // see www/api/controllers/plugin.php), for every plugin installed in
1368 // pluginDir that the FPP project did not publish. A linkName alias is a
1369 // symlink to another plugin, not one itself.
1370 18 static std::string pluginSourceRecordsToVerify(const std::string& pluginDir) {
1371 18 std::string records;
1372
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 if (!DirectoryExists(pluginDir)) {
1373 ✗ return records;
1374 }
1375 18 std::vector<std::string> names;
1376
5/8
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 18 times.
24 for (const auto& entry : std::filesystem::directory_iterator(pluginDir)) {
1377
13/26
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 5 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 6 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 6 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 5 times.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
6 if (entry.is_directory() && !entry.is_symlink() && FileExists(entry.path().string() + "/pluginInfo.json")) {
1378
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 names.push_back(entry.path().filename().string());
1379 }
1380 18 }
1381
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 std::sort(names.begin(), names.end());
1382
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 18 times.
23 for (const auto& name : names) {
1383
4/8
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
5 std::string url = pluginURLWithoutCredentials(pluginOriginURL(pluginDir + "/" + name));
1384 // Published by the FPP project, never flagged.
1385
3/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 2 times.
5 if (isOfficialPluginURL(url)) {
1386 3 continue;
1387 }
1388 // ',' and '|' separate records and fields, '"' would end the setting.
1389 4 auto clean = [](std::string v) {
1390
5/10
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 98 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 98 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 98 times.
102 v.erase(std::remove_if(v.begin(), v.end(), [](char c) { return c == ',' || c == '|' || c == '"'; }), v.end());
1391 4 return v;
1392 };
1393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!records.empty()) {
1394 ✗ records += ",";
1395 }
1396
7/14
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
2 records += clean(name) + "|" + clean(url);
1397
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 }
1398 18 return records;
1399 18 }
1400
1401 // The "Unknown Plugins" health check flag (PluginUnknownEverInstalled) is
1402 // sticky because an unknown plugin's uninstall can't be trusted to undo what
1403 // its install did to the OS. A reflash replaces the OS, so start the record
1404 // over -- but the plugin clones in /home/fpp/media survive, and their scripts
1405 // still run. So rather than simply clearing it, park every surviving plugin
1406 // as unverified, keyed on the URL it was cloned from: the Plugin Manager
1407 // settles those against the plugin list (ResolveUnverifiedPlugins()) and
1408 // raises the flag again only for one that is not listed. Rebuilt from what
1409 // is on disk each time, so the retry of /fppos_upgraded on a later boot gives
1410 // the same answer.
1411 18 static void resetPluginSourceAfterOS() {
1412
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
72 setRawSetting("PluginUnknownEverInstalled", "");
1413
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
54 setRawSetting("PluginUnknownRepos", "");
1414
4/8
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 18 times.
✗ Branch 7 not taken.
54 setRawSetting("PluginUnverifiedRepos", pluginSourceRecordsToVerify(FPP_MEDIA_DIR + "/plugins"));
1415 18 }
1416
1417 37 void checkInstallPackages() {
1418 37 bool reflashed = FileExists("/fppos_upgraded");
1419
5/6
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
✓ Branch 5 taken 18 times.
37 if (!reflashed && !FileExists(FPP_RESTORED_MARKER)) {
1420 19 return;
1421 }
1422
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (reflashed) {
1423 // Only a reflash: a restore keeps this OS, so whatever an unknown
1424 // plugin's install did to it is still there, and the plugins on
1425 // disk were built for it (a File Copy that brings plugins in asks
1426 // for their reinstall itself, in copystorage.php).
1427 18 resetPluginSourceAfterOS();
1428 // An FPPOS reflash replaces /opt/fpp (new fppd, headers, plugin API
1429 // version) while /home/fpp/media -- including the plugin clones -- is
1430 // preserved, and any rootfs artifacts a plugin's fpp_install.sh dropped
1431 // are gone. Native (.so) plugins were built against the old headers;
1432 // the API version check only refuses them if every layout change was
1433 // paired with a bump, so fppd instead declines to load a native plugin
1434 // at all while it is on this list (PluginManager::
1435 // awaitingReinstallAfterOS). If plugins are present, set a persisted
1436 // flag so fppd can raise a (non-dismissible) warning prompting the user
1437 // to Reinstall All. The Plugin Manager turns "1" into the list of
1438 // plugins still to reinstall and clears it once every one has been
1439 // reinstalled or uninstalled. Set independent of the apt result below;
1440 // a retry next boot just rewrites the same value.
1441
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 15 times.
18 if (anyPluginsInstalled()) {
1442
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
12 setRawSetting("pluginReinstallNeededAfterOS", "1");
1443 }
1444 }
1445
1446 18 printf("Installing User Packages\n");
1447 // Only consume the markers once the packages actually installed. If the
1448 // install can't complete (e.g. no network yet at boot), leave them in
1449 // place so it is retried on the next boot rather than silently never
1450 // reinstalling the user's packages.
1451
4/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17 times.
✓ Branch 5 taken 1 times.
18 if (installPackagesFromJson(FPP_MEDIA_DIR + "/config/userpackages.json")) {
1452 17 unlink("/fppos_upgraded");
1453 17 unlink(FPP_RESTORED_MARKER);
1454 } else {
1455 1 printf("User package install incomplete - leaving the upgrade/restore marker set to retry next boot\n");
1456 }
1457 }
1458 37 void startZRAMSwap() {
1459
3/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 2 times.
37 if (!FileExists("/usr/sbin/zramswap")) {
1460 35 return;
1461 }
1462 // Gate on whether zram is already ACTIVE as swap, not on whether the device
1463 // node exists: kernels built with CONFIG_ZRAM=y (e.g. the BeagleBone) always
1464 // present /dev/zram0 even when nothing has configured it, so the old
1465 // FileExists("/dev/zram0") check made this a permanent no-op and zram swap
1466 // never came up. (On the Pi the systemd-zram-generator/rpi-swap path may
1467 // already have set it up, in which case /proc/swaps shows it and we skip.)
1468
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 std::string swaps = GetFileContents("/proc/swaps");
1469
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (swaps.find("zram") == std::string::npos) {
1470
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 execbg("/usr/sbin/zramswap start 2>/dev/null > /dev/null &");
1471 }
1472 2 }
1473 37 void startDiskSwap() {
1474 // The image ships a disk swap partition (e.g. mmcblk0p2) marked "noauto" in
1475 // fstab so systemd does NOT activate it during boot: swapping to eMMC/SD
1476 // wears the flash, and waiting for the swap device to be tagged by udev
1477 // would otherwise gate swap.target on the slow single-core coldplug. zram is
1478 // the primary swap; this larger disk swap is only useful for the occasional
1479 // heavy job (e.g. compiling FPP). Bring it up here, late in postNetwork, off
1480 // the boot critical path. swapon is harmless/idempotent if already active.
1481
2/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
37 exec("/usr/bin/awk '$3 == \"swap\" && $1 !~ /zram/ { print $1 }' /etc/fstab 2>/dev/null "
1482 "| while read -r dev; do /sbin/swapon \"$dev\" 2>/dev/null || true; done");
1483 37 }
1484
1485 #ifdef PLATFORM_PI
1486 // Shrink an oversized vc4-KMS CMA pool on boards that cannot afford it.
1487 //
1488 // The image ships "dtoverlay=vc4-kms-v3d,cma-256" for every Pi (FPP_Install.sh
1489 // adds it to cap the Pi4's 512MB firmware default -- issue #2679). But the
1490 // overlay's own README documents cma-256, and everything above cma-128, as
1491 // "needs 1GB", and the firmware does NOT clamp it: a 512MB Pi Zero 2 W really
1492 // comes up with CmaTotal 262144 kB. That is half the board handed to a GPU pool
1493 // on a headless controller, and it is enough to break a source rebuild -- it
1494 // leaves ~163MB usable, well under what cc1plus needs.
1495 //
1496 // So cap at cma-128, the largest size the overlay does not gate behind 1GB.
1497 // FPP's real DMA needs are far below that: the DPI envelope declared below is
1498 // 1920x997 RGB888, about 7.6MB.
1499 //
1500 // Only ever REDUCE: a deliberate smaller override (cma-64) is left alone, since
1501 // raising it would defeat the purpose. Rewrites `content` in place and sets
1502 // `changed` so the caller's existing reboot handles it; comparing before writing
1503 // keeps it idempotent, so it fires once and never loops.
1504 // MemTotal counts the CMA reservation, so it is the board's usable total, not
1505 // its marketing size: a 512MB board reports ~425-500MB, a 1GB board ~900MB+.
1506 // 700MB separates them with room on both sides.
1507 static constexpr long CMA_ONE_GB_BOARD_KB = 700000;
1508 static constexpr int CMA_MAX_UNDER_1GB = 128;
1509
1510 // Pure half: no file I/O, so it can be lifted out between the markers below and
1511 // exercised directly against sample config.txt text. Edits `content` in place
1512 // and returns true if it changed anything.
1513 // --- BEGIN capVC4CMALine ---
1514 17 static bool capVC4CMALine(std::string& content, long memKB) {
1515
3/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 2 times.
17 if (memKB <= 0 || memKB >= CMA_ONE_GB_BOARD_KB) {
1516 15 return false;
1517 }
1518 // Match the overlay line itself, never a commented-out or indented copy.
1519 // Covers both the generic overlay and the -pi5 variant.
1520 2 size_t vidx = content.find("dtoverlay=vc4-kms-v3d");
1521
4/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
2 while (vidx != std::string::npos && vidx != 0 && content[vidx - 1] != '\n') {
1522 ✗ vidx = content.find("dtoverlay=vc4-kms-v3d", vidx + 1);
1523 }
1524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (vidx == std::string::npos) {
1525 ✗ return false;
1526 }
1527 2 size_t eol = content.find("\n", vidx);
1528
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (eol == std::string::npos) {
1529 ✗ eol = content.size();
1530 }
1531
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 std::string line = content.substr(vidx, eol - vidx);
1532
1533 2 size_t cidx = line.find("cma-");
1534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (cidx == std::string::npos) {
1535 ✗ return false;
1536 }
1537 2 size_t dstart = cidx + strlen("cma-");
1538 2 size_t dend = dstart;
1539
5/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 2 times.
8 while (dend < line.size() && isdigit(static_cast<unsigned char>(line[dend]))) {
1540 6 dend++;
1541 }
1542
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (dend == dstart) {
1543 // "cma-size" (a raw byte count) or some other spelling -- leave it be.
1544 ✗ return false;
1545 }
1546 2 int current = static_cast<int>(strtol(line.c_str() + dstart, nullptr, 10));
1547
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (current <= CMA_MAX_UNDER_1GB) {
1548 1 return false;
1549 }
1550
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 line.replace(cidx, dend - cidx, "cma-" + std::to_string(CMA_MAX_UNDER_1GB));
1551
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("FPP - %ldkB board: capping vc4 CMA at %dMB (was %dMB)\n",
1552 memKB, CMA_MAX_UNDER_1GB, current);
1553
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 content.replace(vidx, eol - vidx, line);
1554 1 return true;
1555 2 }
1556 // --- END capVC4CMALine ---
1557
1558 17 static void capVC4CMAForBoard(std::string& content, bool& changed) {
1559
2/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
17 std::string meminfo = GetFileContents("/proc/meminfo");
1560 17 size_t midx = meminfo.find("MemTotal:");
1561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if (midx == std::string::npos) {
1562 ✗ return;
1563 }
1564 17 long memKB = strtol(meminfo.c_str() + midx + strlen("MemTotal:"), nullptr, 10);
1565
3/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 16 times.
17 if (capVC4CMALine(content, memKB)) {
1566
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 PutFileContents("/boot/firmware/config.txt", content);
1567 1 changed = true;
1568 }
1569
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 }
1570 #endif
1571
1572 #ifdef PLATFORM_PI
1573 // The Pi 5 has a built-in RTC, and it wins rtc0 by probe order -- it registers
1574 // around 0.35s where an i2c RTC on a cape is not up until ~2.5s. Whatever holds
1575 // rtc0 is what the kernel sets the system clock from (CONFIG_RTC_HCTOSYS_DEVICE
1576 // is "rtc0"), so on a board with no cell on the Pi's RTC header the clock is set
1577 // from an unset RTC early in boot and stays wrong until fpprtc runs seconds
1578 // later. A cape that ships a pi5 overlay variant renumbering itself to rtc0
1579 // fixes the ordering, but the Pi's own RTC is still there reading 1970, and a
1580 // user who knows there is no battery is better off with it gone entirely.
1581 //
1582 // "dtparam=rtc=off" is a stock firmware override (the rtc entry in the Pi 5
1583 // DTB's __overrides__ maps to the rpi_rtc node's status), so this needs no
1584 // overlay of FPP's own -- just the line, under a [pi5] filter so that an SD card
1585 // moved to an earlier Pi does not draw an "Unknown dtparam" warning.
1586 //
1587 // The block is rewritten from the setting, which is what makes removal work:
1588 // clear the setting and the block goes with it. Anything outside the markers is
1589 // left alone, and the block always closes with [all] so a later append does not
1590 // land inside the filter.
1591 //
1592 // It is rewritten IN PLACE, and created ahead of CapeUtils' cape-overlay-variant
1593 // block. That block is managed by stripping it and re-appending it at EOF, so if
1594 // this one were written the same way the two would leapfrog: each boot one lands
1595 // after the other, both see a changed config.txt, and both ask for a reboot.
1596 // Since this runs in fppinit's "start" action -- before networking comes up --
1597 // that loop is a box that never reaches the network to be fixed.
1598 static const std::string PI_RTC_BLOCK_BEGIN = "# FPP Pi RTC - BEGIN (managed by fppinit, do not edit)";
1599 static const std::string PI_RTC_BLOCK_END = "# FPP Pi RTC - END";
1600 // Only the marker text, matched not written: CapeUtils owns that block.
1601 static const std::string CAPE_VARIANT_BLOCK_BEGIN = "# FPP Cape Overlay Variants - BEGIN";
1602
1603 // Pure half: no file I/O, so it can be lifted out between the markers below and
1604 // exercised directly against sample config.txt text. Edits `content` in place
1605 // and returns true if it changed anything.
1606 // --- BEGIN applyDisablePiRTCBlock ---
1607 3 static bool applyDisablePiRTCBlock(std::string& content, bool disable) {
1608
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 const std::string orig = content;
1609 3 std::string desired;
1610
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (disable) {
1611
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 desired = PI_RTC_BLOCK_BEGIN + "\n[pi5]\ndtparam=rtc=off\n[all]\n" + PI_RTC_BLOCK_END + "\n";
1612 }
1613
1614 // Strip every copy written before -- more than one only from an interrupted
1615 // write, and a truncated block (BEGIN with no END) cuts to end of file rather
1616 // than leaving a marker the next run would nest inside. Remember where the
1617 // first one started: the replacement goes back THERE, not at EOF. That is
1618 // load bearing, see the note above on leapfrogging the cape variant block.
1619 3 size_t at = std::string::npos;
1620 3 size_t begin = content.find(PI_RTC_BLOCK_BEGIN);
1621
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 while (begin != std::string::npos) {
1622
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (at == std::string::npos) {
1623 2 at = begin;
1624 }
1625 2 size_t end = content.find(PI_RTC_BLOCK_END, begin);
1626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
4 end = (end == std::string::npos) ? content.length()
1627 2 : end + PI_RTC_BLOCK_END.length();
1628
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 if (end < content.length() && content[end] == '\n') {
1629 2 ++end;
1630 }
1631
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 content.erase(begin, end - begin);
1632 2 begin = content.find(PI_RTC_BLOCK_BEGIN);
1633 }
1634
1635
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (!desired.empty()) {
1636
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (at == std::string::npos) {
1637 // Creating it for the first time: go in AHEAD of the cape variant
1638 // block so that block keeps the end of the file to itself.
1639 1 at = content.find(CAPE_VARIANT_BLOCK_BEGIN);
1640
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (at == std::string::npos) {
1641 ✗ while (!content.empty() && content.back() == '\n') {
1642 ✗ content.pop_back();
1643 }
1644 ✗ content += "\n\n";
1645 ✗ at = content.length();
1646 } else {
1647
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 desired += "\n";
1648 }
1649 }
1650
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 content.insert(at, desired);
1651 }
1652 6 return content != orig;
1653 3 }
1654 // --- END applyDisablePiRTCBlock ---
1655 #endif
1656
1657 // Reconcile config.txt with the DisablePiRTC setting. Runs after DetectCape()
1658 // so a cape that ships DisablePiRTC in its defaultSettings takes effect on the
1659 // same boot it is first detected on -- that path reboots, since the setting only
1660 // means anything to the firmware. The UI toggle calls this via `fppinit
1661 // setupPiRTC` with rebootIfChanged false: the setting is declared "reboot": 1, so
1662 // the user is already being prompted and should not have the box go down under
1663 // the save.
1664 42 void setupPiRTCConfig(bool rebootIfChanged) {
1665 #ifdef PLATFORM_PI
1666
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 std::string content = GetFileContents("/boot/firmware/config.txt");
1667
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (content.empty()) {
1668 2 return;
1669 }
1670
5/8
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 times.
6 if (applyDisablePiRTCBlock(content, getRawSettingInt("DisablePiRTC", 0) != 0)) {
1671
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 PutFileContents("/boot/firmware/config.txt", content);
1672
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 printf("FPP - Pi RTC configuration changed in config.txt\n");
1673
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (rebootIfChanged) {
1674 ✗ printf("\n\nRebooting to load new settings.\n\n");
1675 ✗ exec("/usr/sbin/reboot");
1676 }
1677 }
1678 #endif
1679
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
42 }
1680
1681 #ifdef PLATFORM_PI
1682 // Suppress the initial CEC Active Source at boot that wakes projectors/TVs
1683 // (e.g. Epson L210SF, issue #2938). When enabled, adds hdmi_ignore_cec_init=1
1684 // to config.txt. Unlike hdmi_ignore_cec=1 this only suppresses the boot
1685 // broadcast — the CEC plugin can still power the display on/off on demand.
1686 //
1687 // Managed block pattern mirrors applyDisablePiRTCBlock above: strip every
1688 // prior copy (including truncated), remember first insertion point, and
1689 // re-insert ahead of the cape variant block to avoid leapfrog reboot loops.
1690 static const std::string HDMI_CEC_BLOCK_BEGIN = "# FPP HDMI CEC - BEGIN (managed by fppinit, do not edit)";
1691 static const std::string HDMI_CEC_BLOCK_END = "# FPP HDMI CEC - END";
1692
1693 // --- BEGIN applyDisableHDMICECBlock ---
1694 1 static bool applyDisableHDMICECBlock(std::string& content, bool disable) {
1695
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 const std::string orig = content;
1696 1 std::string desired;
1697
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (disable) {
1698 ✗ desired = HDMI_CEC_BLOCK_BEGIN + "\n[all]\nhdmi_ignore_cec_init=1\n[all]\n" + HDMI_CEC_BLOCK_END + "\n";
1699 }
1700
1701 1 size_t at = std::string::npos;
1702 1 size_t begin = content.find(HDMI_CEC_BLOCK_BEGIN);
1703
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 while (begin != std::string::npos) {
1704
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (at == std::string::npos) {
1705 1 at = begin;
1706 }
1707 1 size_t end = content.find(HDMI_CEC_BLOCK_END, begin);
1708
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
2 end = (end == std::string::npos) ? content.length()
1709 1 : end + HDMI_CEC_BLOCK_END.length();
1710
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 if (end < content.length() && content[end] == '\n') {
1711 1 ++end;
1712 }
1713
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 content.erase(begin, end - begin);
1714 1 begin = content.find(HDMI_CEC_BLOCK_BEGIN);
1715 }
1716
1717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!desired.empty()) {
1718 ✗ if (at == std::string::npos) {
1719 ✗ at = content.find(CAPE_VARIANT_BLOCK_BEGIN);
1720 ✗ if (at == std::string::npos) {
1721 ✗ while (!content.empty() && content.back() == '\n') {
1722 ✗ content.pop_back();
1723 }
1724 ✗ content += "\n\n";
1725 ✗ at = content.length();
1726 } else {
1727 ✗ desired += "\n";
1728 }
1729 }
1730 ✗ content.insert(at, desired);
1731 }
1732 2 return content != orig;
1733 1 }
1734 // --- END applyDisableHDMICECBlock ---
1735 #endif
1736
1737 40 void setupHDMICECConfig(bool rebootIfChanged) {
1738 #ifdef PLATFORM_PI
1739
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 std::string content = GetFileContents("/boot/firmware/config.txt");
1740
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (content.empty()) {
1741 2 return;
1742 }
1743 // Pi 5 has no firmware HDMI path (RP1/KMS), so hdmi_ignore_cec_init is
1744 // ignored. Never write the block on Pi 5; this also cleans up a stale
1745 // block left from when the setting previously defaulted to on.
1746
4/18
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
1 bool want = !isPi5() && getRawSettingInt("DisableHDMICECInit", 0) != 0;
1747
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (applyDisableHDMICECBlock(content, want)) {
1748
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 PutFileContents("/boot/firmware/config.txt", content);
1749
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("FPP - HDMI CEC configuration changed in config.txt\n");
1750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (rebootIfChanged) {
1751 ✗ printf("\n\nRebooting to load new settings.\n\n");
1752 ✗ exec("/usr/sbin/reboot");
1753 }
1754 }
1755 #endif
1756
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
40 }
1757
1758 #ifdef PLATFORM_PI
1759 // CM4/CM5 carry both a PCB antenna and a U.FL socket; the firmware picks one via
1760 // dtparam=ant1 (PCB, the default) or ant2 (U.FL). Only those base DTBs define the
1761 // ant2 override, which is what /proc/device-tree/__overrides__/ant2 tests for, and
1762 // the block is filtered to [cm4]/[cm5] anyway so a card moved into a board without
1763 // the param carries an inert block rather than a dterror. ant2 disables the PCB
1764 // antenna outright, so selecting it with nothing on the socket leaves WiFi with
1765 // almost no range -- hence a setting, not a default.
1766 //
1767 // Same managed block pattern as applyDisablePiRTCBlock above.
1768 static const std::string WIFI_ANTENNA_BLOCK_BEGIN = "# FPP WiFi Antenna - BEGIN (managed by fppinit, do not edit)";
1769 static const std::string WIFI_ANTENNA_BLOCK_END = "# FPP WiFi Antenna - END";
1770
1771 // --- BEGIN applyWifiAntennaBlock ---
1772 3 static bool applyWifiAntennaBlock(std::string& content, bool external) {
1773
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 const std::string orig = content;
1774 3 std::string desired;
1775
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (external) {
1776
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 desired = WIFI_ANTENNA_BLOCK_BEGIN + "\n[cm4]\ndtparam=ant2\n[cm5]\ndtparam=ant2\n[all]\n" + WIFI_ANTENNA_BLOCK_END + "\n";
1777 }
1778
1779 3 size_t at = std::string::npos;
1780 3 size_t begin = content.find(WIFI_ANTENNA_BLOCK_BEGIN);
1781
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 while (begin != std::string::npos) {
1782
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (at == std::string::npos) {
1783 2 at = begin;
1784 }
1785 2 size_t end = content.find(WIFI_ANTENNA_BLOCK_END, begin);
1786
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
4 end = (end == std::string::npos) ? content.length()
1787 2 : end + WIFI_ANTENNA_BLOCK_END.length();
1788
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 if (end < content.length() && content[end] == '\n') {
1789 2 ++end;
1790 }
1791
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 content.erase(begin, end - begin);
1792 2 begin = content.find(WIFI_ANTENNA_BLOCK_BEGIN);
1793 }
1794
1795
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (!desired.empty()) {
1796
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (at == std::string::npos) {
1797 1 at = content.find(CAPE_VARIANT_BLOCK_BEGIN);
1798
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (at == std::string::npos) {
1799 ✗ while (!content.empty() && content.back() == '\n') {
1800 ✗ content.pop_back();
1801 }
1802 ✗ content += "\n\n";
1803 ✗ at = content.length();
1804 } else {
1805
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 desired += "\n";
1806 }
1807 }
1808
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 content.insert(at, desired);
1809 }
1810 6 return content != orig;
1811 3 }
1812 // --- END applyWifiAntennaBlock ---
1813 #endif
1814
1815 43 void setupWifiAntennaConfig(bool rebootIfChanged) {
1816 #ifdef PLATFORM_PI
1817 // Leave config.txt alone on boards without the param: there is no setting
1818 // to reconcile (the UI hides it), and any block left from a CM is inert.
1819
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
6 if (!FileExists("/proc/device-tree/__overrides__/ant2")) {
1820 3 return;
1821 }
1822
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 std::string content = GetFileContents("/boot/firmware/config.txt");
1823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (content.empty()) {
1824 ✗ return;
1825 }
1826
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 std::string antenna = "internal";
1827
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 getRawSetting("WifiAntenna", antenna);
1828
4/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
3 if (applyWifiAntennaBlock(content, antenna == "external")) {
1829
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 PutFileContents("/boot/firmware/config.txt", content);
1830
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 printf("FPP - WiFi antenna configuration changed in config.txt\n");
1831
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (rebootIfChanged) {
1832 ✗ printf("\n\nRebooting to load new settings.\n\n");
1833 ✗ exec("/usr/sbin/reboot");
1834 }
1835 }
1836 #endif
1837
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
40 }
1838
1839 // The 64-bit Pi images keep the Pi 5's 16K-page kernel, and its modules, but
1840 // park the kernel under a name the firmware never loads; a Pi 5 would otherwise
1841 // prefer kernel_2712.img over the 4K-page kernel8.img. The developer-level
1842 // Pi16KPageKernel setting copies it back into place. The 32-bit images, images
1843 // from before this, and stock Raspberry Pi OS installs have no parked copy, and
1844 // are left alone.
1845 //
1846 // Runs at every boot as well as from the UI: an FPPOS upgrade replaces the boot
1847 // partition, which drops the active copy, and the boot pass puts it back.
1848 41 void setup16KPageKernel(bool rebootIfChanged) {
1849 #ifdef PLATFORM_PI
1850
3/8
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
12 static const std::string ACTIVE = "/boot/firmware/kernel_2712.img";
1851
3/8
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
12 static const std::string PARKED = "/boot/firmware/kernel_2712.img.fpp-disabled";
1852
3/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
4 if (!FileExists(PARKED)) {
1853 2 return;
1854 }
1855
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 bool want = getRawSettingInt("Pi16KPageKernel", 0) != 0;
1856
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 bool have = FileExists(ACTIVE);
1857 2 std::error_code ec;
1858
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 if (want && !have) {
1859 // Copy to a temporary name first so a power cut mid-copy can't leave a
1860 // truncated kernel_2712.img for the firmware to boot.
1861
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string tmp = ACTIVE + ".tmp";
1862
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 std::filesystem::copy_file(PARKED, tmp, std::filesystem::copy_options::overwrite_existing, ec);
1863
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!ec) {
1864
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 std::filesystem::rename(tmp, ACTIVE, ec);
1865 }
1866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ec) {
1867 ✗ printf("FPP - Could not enable the 16K-page kernel: %s\n", ec.message().c_str());
1868 ✗ std::filesystem::remove(tmp, ec);
1869 ✗ return;
1870 }
1871
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("FPP - Enabled the 16K-page kernel\n");
1872
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
3 } else if (!want && have) {
1873 // Park the active copy rather than deleting it: it is the one that
1874 // matches the 16K module tree, should anything have updated it.
1875
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 std::filesystem::rename(ACTIVE, PARKED, ec);
1876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ec) {
1877 ✗ printf("FPP - Could not disable the 16K-page kernel: %s\n", ec.message().c_str());
1878 ✗ return;
1879 }
1880
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("FPP - Disabled the 16K-page kernel\n");
1881 } else {
1882 ✗ return;
1883 }
1884 2 sync();
1885 // Only the Pi 5 family loads kernel_2712.img; elsewhere the change is inert.
1886
2/8
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
2 if (rebootIfChanged && isPi5()) {
1887 ✗ printf("\n\nRebooting to load new settings.\n\n");
1888 ✗ exec("/usr/sbin/reboot");
1889 }
1890 #endif
1891 37 }
1892
1893 // The pixel string config names its cape's string definition by subType, and the cape's
1894 // defaults are only copied into place when there is no config yet. Move the SD card to a
1895 // different cape and the old subType stays: the driver can't find a string definition
1896 // with that name and no outputs run at all. When that happens, and the attached cape
1897 // ships a string definition that can carry the outputs that are configured, point the
1898 // config at it.
1899
1900 // The driver a string definition is written for. Older definitions don't say and are
1901 // for the platform's original string driver.
1902 ✗ static std::string stringsDriver(const Json::Value& def) {
1903 ✗ if (def.isMember("driver") && def["driver"].isString()) {
1904 ✗ return def["driver"].asString();
1905 }
1906 #ifdef PLATFORM_PI
1907 ✗ return "RPIWS281X";
1908 #else
1909 ✗ return "BBB48String";
1910 #endif
1911 }
1912
1913 ✗ static std::string platformStringsDir() {
1914 #if defined(PLATFORM_PI)
1915 ✗ return "/opt/fpp/capes/pi/strings/";
1916 #elif defined(PLATFORM_BB64)
1917 ✗ return "/opt/fpp/capes/bb64/strings/";
1918 #elif defined(PLATFORM_BBB)
1919 // as getPlatformCapeDir() in CapeUtils: "TI AM335x PocketBeagle"
1920 ✗ std::string model = GetFileContents("/proc/device-tree/model");
1921 ✗ while (!model.empty() && model.back() == '\0') {
1922 ✗ model.pop_back();
1923 }
1924 ✗ if (model.size() > 10 && model.substr(10) == "PocketBeagle") {
1925 ✗ return "/opt/fpp/capes/pb/strings/";
1926 }
1927 ✗ return "/opt/fpp/capes/bbb/strings/";
1928 #else
1929 ✗ return "";
1930 #endif
1931 ✗ }
1932
1933 ✗ static bool stringsDefinitionExists(const std::string& name) {
1934 ✗ if (name.empty()) {
1935 ✗ return false;
1936 }
1937 ✗ if (FileExists(FPP_MEDIA_DIR + "/tmp/strings/" + name + ".json")) {
1938 ✗ return true;
1939 }
1940 ✗ std::string dir = platformStringsDir();
1941 ✗ return !dir.empty() && FileExists(dir + name + ".json");
1942 ✗ }
1943
1944 // Mirrors how each driver looks up its string definition (BBShiftStringOutput::Init,
1945 // BBB48StringOutput::Init, DPIPixelsOutput::LoadStringConfig).
1946 ✗ static bool outputHasStringsDefinition(const Json::Value& co) {
1947 ✗ std::string type = co["type"].asString();
1948 ✗ std::string subType = co["subType"].asString();
1949 ✗ if (stringsDefinitionExists(subType)) {
1950 ✗ return true;
1951 }
1952 ✗ if (type == "BBB48String") {
1953 ✗ std::string ver = co["pinoutVersion"].isString() ? co["pinoutVersion"].asString() : "";
1954 ✗ if (ver == "2.x" && stringsDefinitionExists(subType + "-v2")) {
1955 ✗ return true;
1956 }
1957 ✗ if (ver == "3.x" && stringsDefinitionExists(subType + "-v3")) {
1958 ✗ return true;
1959 }
1960 ✗ } else if (type == "DPIPixels") {
1961 ✗ if (subType == "PiHat" || subType == "rPi-MFC") {
1962 ✗ return stringsDefinitionExists(subType + "-DPIPixels");
1963 }
1964 ✗ if (subType == "rPi-28D") {
1965 ✗ return stringsDefinitionExists("rPi-28D-DPIPixels-4");
1966 }
1967 ✗ if (subType.empty() || subType == "DPIPixels") {
1968 // the driver's generic, cape-less config
1969 ✗ return true;
1970 }
1971 ✗ return stringsDefinitionExists(subType + "-DPIPixels");
1972 }
1973 ✗ return false;
1974 ✗ }
1975
1976 // Can def drive every string co has configured? Same driver, a port for every port with
1977 // pixels on it, and a differential port wherever a smart receiver is set up.
1978 ✗ static bool stringsDefinitionCompatible(const Json::Value& co, const Json::Value& def) {
1979 ✗ if (stringsDriver(def) != co["type"].asString()) {
1980 ✗ return false;
1981 }
1982 ✗ const Json::Value& defOutputs = def["outputs"];
1983 ✗ if (!defOutputs.isArray()) {
1984 ✗ return false;
1985 }
1986 ✗ std::vector<bool> differential(defOutputs.size(), false);
1987 ✗ const Json::Value& groups = def["groups"];
1988 ✗ for (Json::ArrayIndex g = 0; groups.isArray() && g < groups.size(); g++) {
1989 ✗ const Json::Value& grp = groups[g];
1990 ✗ if (!grp.isObject() || !grp["type"].isString() || grp["type"].asString() != "differential" ||
1991 ✗ !grp["start"].isConvertibleTo(Json::intValue) || !grp["count"].isConvertibleTo(Json::intValue)) {
1992 ✗ continue;
1993 }
1994 ✗ int start = grp["start"].asInt() - 1;
1995 ✗ int count = grp["count"].asInt();
1996 ✗ for (int p = std::max(start, 0); p < start + count && p < (int)differential.size(); p++) {
1997 ✗ differential[p] = true;
1998 }
1999 }
2000 ✗ const Json::Value& outputs = co["outputs"];
2001 ✗ for (Json::ArrayIndex o = 0; outputs.isArray() && o < outputs.size(); o++) {
2002 ✗ const Json::Value& out = outputs[o];
2003 ✗ if (!out.isObject() || !out["portNumber"].isConvertibleTo(Json::intValue)) {
2004 ✗ continue;
2005 }
2006 ✗ bool hasPixels = false;
2007 ✗ const Json::Value& vs = out["virtualStrings"];
2008 ✗ for (Json::ArrayIndex v = 0; vs.isArray() && v < vs.size(); v++) {
2009 ✗ if (vs[v].isObject() && vs[v]["pixelCount"].isConvertibleTo(Json::intValue) && vs[v]["pixelCount"].asInt() > 0) {
2010 ✗ hasPixels = true;
2011 }
2012 }
2013 ✗ bool smartReceiver = out["differentialType"].isConvertibleTo(Json::intValue) && out["differentialType"].asInt() != 0;
2014 ✗ if (!hasPixels && !smartReceiver) {
2015 ✗ continue;
2016 }
2017 ✗ int port = out["portNumber"].asInt();
2018 ✗ if (port < 0 || port >= (int)defOutputs.size()) {
2019 ✗ return false;
2020 }
2021 ✗ if (smartReceiver && !differential[port]) {
2022 ✗ return false;
2023 }
2024 }
2025 ✗ return true;
2026 ✗ }
2027
2028 57 static void retargetStringOutputsToCape() {
2029 #if defined(PLATFORM_PI)
2030
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 const std::string configName = "co-pixelStrings.json";
2031 #elif defined(PLATFORM_BBB) || defined(PLATFORM_BB64)
2032 ✗ const std::string configName = "co-bbbStrings.json";
2033 #else
2034
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 const std::string configName = "";
2035 #endif
2036
2/4
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57 times.
✗ Branch 3 not taken.
57 std::string configFile = FPP_MEDIA_DIR + "/config/" + configName;
2037
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 std::string capeStrings = FPP_MEDIA_DIR + "/tmp/strings";
2038
11/18
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 13 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 53 times.
✓ Branch 14 taken 57 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
57 if (configName.empty() || !FileExists(configFile) || !std::filesystem::is_directory(capeStrings)) {
2039 57 return;
2040 }
2041 ✗ Json::Value config;
2042 ✗ if (!LoadJsonFromString(GetFileContents(configFile), config, JsonRoot::Object) || !config["channelOutputs"].isArray()) {
2043 ✗ return;
2044 }
2045
2046 // The attached cape's string definitions, by file name without ".json"
2047 ✗ std::map<std::string, Json::Value> defs;
2048 ✗ std::error_code ec;
2049 ✗ for (const auto& entry : std::filesystem::directory_iterator(capeStrings, ec)) {
2050 ✗ if (!entry.is_regular_file() || entry.path().extension() != ".json") {
2051 ✗ continue;
2052 }
2053 ✗ Json::Value def;
2054 ✗ if (LoadJsonFromString(GetFileContents(entry.path().string()), def, JsonRoot::Object)) {
2055 ✗ defs[entry.path().stem().string()] = def;
2056 }
2057 ✗ }
2058 ✗ if (defs.empty()) {
2059 ✗ return;
2060 }
2061 // The cape's own default config says which of its definitions it prefers
2062 ✗ std::string preferred;
2063 ✗ Json::Value capeDefault;
2064 ✗ if (LoadJsonFromString(GetFileContents(FPP_MEDIA_DIR + "/tmp/defaults/config/" + configName), capeDefault, JsonRoot::Object) &&
2065 ✗ capeDefault["channelOutputs"].isArray() && capeDefault["channelOutputs"].size() > 0 &&
2066 ✗ capeDefault["channelOutputs"][0]["subType"].isString()) {
2067 ✗ preferred = capeDefault["channelOutputs"][0]["subType"].asString();
2068 }
2069
2070 ✗ bool changed = false;
2071 ✗ Json::Value& cos = config["channelOutputs"];
2072 ✗ for (Json::ArrayIndex x = 0; x < cos.size(); x++) {
2073 ✗ Json::Value& co = cos[x];
2074 ✗ if (!co.isObject() || !co["type"].isString() || !co["enabled"].isConvertibleTo(Json::intValue) || co["enabled"].asInt() != 1) {
2075 ✗ continue;
2076 }
2077 ✗ std::string type = co["type"].asString();
2078 ✗ if (type != "BBShiftString" && type != "BBB48String" && type != "DPIPixels") {
2079 ✗ continue;
2080 }
2081 ✗ if (outputHasStringsDefinition(co)) {
2082 ✗ continue;
2083 }
2084 // Of the definitions that fit, the cape's default first, then the smallest.
2085 ✗ std::string best;
2086 ✗ for (const auto& [name, def] : defs) {
2087 ✗ if (!stringsDefinitionCompatible(co, def)) {
2088 ✗ continue;
2089 }
2090 ✗ if (best.empty() || name == preferred ||
2091 ✗ (best != preferred && def["outputs"].size() < defs[best]["outputs"].size())) {
2092 ✗ best = name;
2093 }
2094 }
2095 ✗ std::string oldSubType = co["subType"].isString() ? co["subType"].asString() : "";
2096 ✗ if (best.empty()) {
2097 ✗ printf("FPP - No string definition for %s output '%s' and none of the cape's fit its configured outputs\n",
2098 type.c_str(), oldSubType.c_str());
2099 ✗ continue;
2100 }
2101 ✗ std::string subType = best;
2102 ✗ std::string pinoutVersion = defs[best]["pinoutVersion"].isString() ? defs[best]["pinoutVersion"].asString() : "1.x";
2103 ✗ if (type == "BBB48String") {
2104 // BBB48String finds "<subType>-v2" from subType and pinoutVersion 2.x
2105 ✗ if (endsWith(best, "-v2")) {
2106 ✗ subType = best.substr(0, best.size() - 3);
2107 ✗ pinoutVersion = "2.x";
2108 ✗ } else if (endsWith(best, "-v3")) {
2109 ✗ subType = best.substr(0, best.size() - 3);
2110 ✗ pinoutVersion = "3.x";
2111 }
2112 }
2113 ✗ printf("FPP - String definition for %s output '%s' not found, switching it to the cape's '%s'\n",
2114 type.c_str(), oldSubType.c_str(), best.c_str());
2115 ✗ co["subType"] = subType;
2116 ✗ co["pinoutVersion"] = pinoutVersion;
2117 ✗ changed = true;
2118 ✗ }
2119 ✗ if (changed) {
2120 ✗ PutFileContents(configFile, SaveJsonToString(config));
2121 }
2122
3/10
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 57 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 57 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 57 times.
171 }
2123
2124 57 void setupChannelOutputs() {
2125 #ifndef PLATFORM_PI
2126 40 retargetStringOutputsToCape();
2127 #else
2128 17 bool hasDPI = false;
2129 17 bool hasRPIMatrix = false;
2130
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 Json::Value v;
2131 // Both files are read on every boot, and fppinit has no one to restart it:
2132 // an entry with a field of the wrong JSON type is skipped, not thrown on.
2133 9 auto isOutput = [](const Json::Value& co) {
2134
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
16 return co.isObject() && co["type"].isConvertibleTo(Json::stringValue) &&
2135
5/6
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
16 co["subType"].isConvertibleTo(Json::stringValue) && co["enabled"].isConvertibleTo(Json::intValue);
2136 };
2137
4/6
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 12 times.
17 if (FileExists(FPP_MEDIA_DIR + "/config/channeloutputs.json")) {
2138
5/8
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 1 times.
5 if (LoadJsonFromString(GetFileContents(FPP_MEDIA_DIR + "/config/channeloutputs.json"), v, JsonRoot::Object)) {
2139
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 const Json::Value& cos = v["channelOutputs"];
2140
8/10
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 3 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 4 times.
8 for (Json::ArrayIndex x = 0; cos.isArray() && x < cos.size(); x++) {
2141
18/30
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 2 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
✓ Branch 23 taken 1 times.
✓ Branch 24 taken 2 times.
✓ Branch 25 taken 2 times.
✓ Branch 26 taken 1 times.
✓ Branch 27 taken 3 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
4 if (isOutput(cos[x]) && cos[x]["subType"].asString() == "RGBMatrix" && cos[x]["enabled"].asInt() == 1) {
2142 1 hasRPIMatrix = true;
2143 }
2144 }
2145 }
2146 }
2147
4/6
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 13 times.
17 if (FileExists(FPP_MEDIA_DIR + "/config/co-pixelStrings.json")) {
2148
4/8
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
4 if (LoadJsonFromString(GetFileContents(FPP_MEDIA_DIR + "/config/co-pixelStrings.json"), v, JsonRoot::Object)) {
2149 4 bool migrated = false;
2150
9/14
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✓ Branch 11 taken 4 times.
✓ Branch 12 taken 5 times.
✓ Branch 13 taken 4 times.
9 for (Json::ArrayIndex x = 0; v["channelOutputs"].isArray() && x < v["channelOutputs"].size(); x++) {
2151
5/8
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 2 times.
5 if (!isOutput(v["channelOutputs"][x])) {
2152 3 continue;
2153 }
2154
6/12
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
2 if (v["channelOutputs"][x]["type"].asString() == "RPIWS281X") {
2155 // The RPIWS281X driver has been removed. DPI drives the same pins without
2156 // conflicting with the onboard audio, so migrate the config to DPIPixels.
2157 // Capes we don't have a mapping for keep their subType; DPIPixels resolves
2158 // the matching string config at runtime.
2159
4/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
2 std::string subType = v["channelOutputs"][x]["subType"].asString();
2160
4/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
2 v["channelOutputs"][x]["type"] = "DPIPixels";
2161
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (subType == "PiHat") {
2162 ✗ v["channelOutputs"][x]["subType"] = "PiHat-DPIPixels";
2163
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 } else if (subType == "rPi-MFC") {
2164 ✗ v["channelOutputs"][x]["subType"] = "rPi-MFC-DPIPixels";
2165
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 } else if (subType == "rPi-28D") {
2166 // The rPi-28D's third output was ws2801 over SPI which DPI cannot drive.
2167 // The 4 output variant drives CN1's clock and data pins as WS281x instead.
2168
4/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
2 v["channelOutputs"][x]["subType"] = "rPi-28D-DPIPixels-4";
2169
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 Json::Value& outputs = v["channelOutputs"][x]["outputs"];
2170
7/10
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 5 times.
✓ Branch 9 taken 2 times.
7 for (Json::ArrayIndex o = 0; outputs.isArray() && o < outputs.size(); o++) {
2171
9/14
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✓ Branch 13 taken 1 times.
8 if (outputs[o].isObject() && outputs[o]["protocol"].isString() &&
2172
10/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
8 outputs[o]["protocol"].asString() == "ws2801") {
2173
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 outputs[o]["protocol"] = "ws2811";
2174 }
2175 }
2176 }
2177 2 migrated = true;
2178 2 }
2179
13/28
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 2 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 2 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 2 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
2 if (v["channelOutputs"][x]["type"].asString() == "DPIPixels" && v["channelOutputs"][x]["enabled"].asInt() == 1) {
2180 2 hasDPI = true;
2181 }
2182 }
2183
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (migrated) {
2184
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 PutFileContents(FPP_MEDIA_DIR + "/config/co-pixelStrings.json", SaveJsonToString(v));
2185 }
2186 }
2187 }
2188 // after the RPIWS281X migration so it sees the migrated DPIPixels subType
2189
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 retargetStringOutputsToCape();
2190 17 bool changed = false;
2191 // Only the RGBMatrix output still needs the onboard audio out of the way. Pixel strings
2192 // are driven by DPI now, which coexists with snd_bcm2835.
2193
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16 times.
17 if (hasRPIMatrix) {
2194
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!FileExists("/etc/modprobe.d/blacklist-bcm2835.conf")) {
2195
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
3 PutFileContents("/etc/modprobe.d/blacklist-bcm2835.conf", "blacklist snd_bcm2835");
2196 1 changed = true;
2197 }
2198 // Preemptively load the USB sound driver so it will detect before snd-dummy is created
2199 // and get the default card0 slot
2200
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 exec("modprobe snd_usb_audio");
2201
2202 // load the dummy sound driver so things that expect a sound device to be there will still work
2203
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 exec("modprobe snd-dummy");
2204
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 exec("modprobe snd-seq-dummy");
2205 } else {
2206
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
16 if (FileExists("/etc/modprobe.d/blacklist-bcm2835.conf")) {
2207 ✗ unlink("/etc/modprobe.d/blacklist-bcm2835.conf");
2208 }
2209
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
32 exec("modprobe snd-bcm2835");
2210
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
32 exec("modprobe snd_usb_audio");
2211 }
2212
2/4
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
17 std::string content = GetFileContents("/boot/firmware/config.txt");
2213
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 capVC4CMAForBoard(content, changed);
2214 17 size_t idx = content.find("dtoverlay=vc4-kms-dpi-fpp");
2215
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 std::string origLine = "";
2216
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16 times.
17 if (idx != std::string::npos) {
2217 1 size_t idx2 = content.find("\n", idx);
2218
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 origLine = content.substr(idx, idx2 - idx);
2219 }
2220
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 15 times.
17 if (hasDPI) {
2221 // The DPI overlay only bootstraps the 1920-wide, 38.4MHz pipeline; its
2222 // vertical resolution is just the boot/default mode. DPIPixelsOutput
2223 // overrides the vertical timing at runtime (sizing vactive to the longest
2224 // string and setting the frame rate purely via the vertical blanking, no
2225 // reboot). Declare the tallest envelope we support - vactive=997 (the old
2226 // 20fps mode, the lowest rate / longest string) - so every runtime mode is
2227 // a subset of what the overlay advertises.
2228
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 std::string width = "1920";
2229
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 std::string height = "997";
2230
4/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
2 std::string line = "dtoverlay=vc4-kms-dpi-fpp,rgb888,hactive=" + width + ",hfp=0,hsync=1,hbp=0,vactive=" + height + ",vfp=1,vsync=1,vbp=1";
2231
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (line != origLine) {
2232
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (origLine != "") {
2233 ✗ content.replace(idx, origLine.size(), line);
2234 } else {
2235
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 content.append(line).append("\n");
2236 }
2237
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 PutFileContents("/boot/firmware/config.txt", content);
2238 2 changed = true;
2239 }
2240
3/4
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 14 times.
17 } else if (origLine != "") {
2241 1 size_t idx2 = content.find("\n", idx);
2242
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 content.erase(idx, idx2 - idx);
2243
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 PutFileContents("/boot/firmware/config.txt", content);
2244 1 changed = true;
2245 }
2246
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 12 times.
17 if (changed) {
2247
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 printf("\n\nRebooting to load new settings.\n\n");
2248
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
10 exec("/usr/sbin/reboot");
2249 }
2250 #endif
2251 57 }
2252
2253 // Drive a GPIO line, looked up by the name the kernel exposes for it
2254 // (gpio-line-names in the device tree), to the given value. Uses libgpiod
2255 // directly rather than the gpioset/gpioinfo tools whose command line and
2256 // output format changed incompatibly between libgpiod 1.x and 2.x.
2257 //
2258 // Like gpioset, the line is released as soon as the value has been written:
2259 // the pin keeps the level the driver last wrote to it.
2260 1 static bool setNamedGPIO(const std::string& pin, int val) {
2261 #ifdef HASGPIOD
2262 1 bool found = false;
2263
5/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✓ Branch 7 taken 1 times.
12 for (const auto& entry : std::filesystem::directory_iterator("/dev")) {
2264
4/6
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 5 times.
11 if (!entry.path().filename().string().starts_with("gpiochip")) {
2265 10 continue;
2266 }
2267
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string path = entry.path().string();
2268 try {
2269 #ifdef IS_GPIOD_CXX_V2
2270
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 gpiod::chip chip(path);
2271
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 int offset = chip.get_line_offset_from_name(pin);
2272
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 if (offset < 0) {
2273 4 continue;
2274 }
2275
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 gpiod::line_settings settings;
2276
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 settings.set_direction(gpiod::line::direction::OUTPUT);
2277
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 settings.set_output_value(val ? gpiod::line::value::ACTIVE : gpiod::line::value::INACTIVE);
2278
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 gpiod::line_request request = chip.prepare_request()
2279
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 .set_consumer("FPPINIT")
2280
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
2 .add_line_settings(offset, settings)
2281
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 .do_request();
2282
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 request.release();
2283 #else
2284 gpiod::chip chip(path, gpiod::chip::OPEN_BY_PATH);
2285 gpiod::line line = chip.find_line(pin);
2286 if (!line) {
2287 continue;
2288 }
2289 int offset = line.offset();
2290 gpiod::line_request request;
2291 request.consumer = "FPPINIT";
2292 request.request_type = gpiod::line_request::DIRECTION_OUTPUT;
2293 line.request(request, val);
2294 line.release();
2295 #endif
2296
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("FPP - Set GPIO %s (%s line %d) to %d\n", pin.c_str(), path.c_str(), offset, val);
2297 1 found = true;
2298
2/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5 } catch (const std::exception& ex) {
2299 ✗ printf("FPP - Could not set GPIO %s on %s: %s\n", pin.c_str(), path.c_str(), ex.what());
2300 ✗ }
2301
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
6 }
2302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!found) {
2303 ✗ printf("FPP - Could not find a GPIO line named %s\n", pin.c_str());
2304 }
2305 1 return found;
2306 #else
2307 printf("FPP - Cannot set GPIO %s, no libgpiod support\n", pin.c_str());
2308 return false;
2309 #endif
2310 }
2311
2312 1 void handleRebootActions() {
2313
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 if (FileExists(FPP_MEDIA_DIR + "/tmp/cape-info.json")) {
2314
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 Json::Value v;
2315
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 if (LoadJsonFromString(GetFileContents(FPP_MEDIA_DIR + "/tmp/cape-info.json"), v)) {
2316
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (v.isMember("rebootActions")) {
2317
8/14
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
2 for (const auto& action : v["rebootActions"]) {
2318
4/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 if (action["type"].asString() == "gpio") {
2319
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 std::string pin = action["pin"].asString();
2320
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (pin.empty()) {
2321 ✗ continue;
2322 }
2323 1 int val = 0;
2324
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (pin[0] == '+') {
2325
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 pin = pin.substr(1);
2326 1 val = 1;
2327 }
2328
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 setNamedGPIO(pin, val);
2329
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 }
2330 }
2331 }
2332 }
2333 1 }
2334 1 }
2335