Skip to content

Commit

Permalink
timesync: close serial-descriptor after reading
Browse files Browse the repository at this point in the history
  • Loading branch information
blocktrron committed Oct 8, 2023
1 parent 7baa792 commit 142cbc9
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions quectel-timesync.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ int perform_timesync(int serial_fd) {

int main(int argc, char *argv[])
{
const char *serial_path;
int serial_fd = -1;
int daemon_interval = 0;
int ret;
Expand All @@ -235,7 +236,7 @@ int main(int argc, char *argv[])
debug = 1;
break;
case 'p':
serial_fd = open_serial_port(optarg);
serial_path = optarg;
break;
default:
print_usage(argv[0]);
Expand All @@ -245,26 +246,29 @@ int main(int argc, char *argv[])

if (daemon_interval && daemon_interval < 10) {
fprintf(stderr, "Invalid daemon interval. Minimum: 10\n");
ret = -1;
goto out;
return -1;
}

if (serial_fd < 0) {
if (!serial_path) {
print_usage(argv[0]);
fprintf(stderr, "No serial port specified\n");
return -1;
}

while (1) {
ret = perform_timesync(serial_fd);

serial_fd = open_serial_port(serial_path);
if (serial_fd < 0) {
fprintf(stderr, "Could not open serial port %s\n", serial_path);
} else {
ret = perform_timesync(serial_fd);
close(serial_fd);
}

if (!daemon_interval)
goto out;
return 0;

sleep(daemon_interval);
}

out:
close(serial_fd);
return ret;
return 0;
}

0 comments on commit 142cbc9

Please sign in to comment.