Skip to content

Commit

Permalink
Fix incorrect device_id initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lars18th authored and Jalle19 committed Sep 9, 2024
1 parent 67cab8b commit 209f02c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/minisatip.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ void set_options(int argc, char *argv[]) {
opts.timeout_sec = 30000;
opts.adapter_timeout = 30000;
opts.daemon = 1;
opts.device_id = 1;
opts.device_id = 0;
opts.dvr_buffer = DVR_BUFFER;
opts.adapter_buffer = ADAPTER_BUFFER;
opts.udp_threshold = 25;
Expand Down Expand Up @@ -2010,27 +2010,31 @@ int main(int argc, char *argv[]) {

int readBootID() {
opts.bootid = 0;
opts.device_id = 0;
int local_device_id = 0;
char bootid_path[256];

// Read existing values
snprintf(bootid_path, sizeof(bootid_path) - 1, "%s/bootid", opts.cache_dir);
FILE *f = fopen(bootid_path, "rt");
__attribute__((unused)) int rv;
if (f) {
rv = fscanf(f, "%d %d %s", &opts.bootid, &opts.device_id, opts.uuid);
rv = fscanf(f, "%d %d %s", &opts.bootid, &local_device_id, opts.uuid);
fclose(f);
}

// Increment bootid and set defaults if values are missing
opts.bootid++;
if (opts.device_id < 1) {
opts.device_id = 1;
if (local_device_id < 1) {
local_device_id = 1;
}
if (!strcmp(opts.uuid, "")) {
uuid4_generate(opts.uuid);
}

if (opts.device_id < 1) {
opts.device_id = local_device_id;
}

// Store new values
f = fopen(bootid_path, "wt");
if (f) {
Expand Down

0 comments on commit 209f02c

Please sign in to comment.