Skip to content

Commit b6d70e8

Browse files
committed
cdba: Add option to disable timeout_total when set to 0
If cdba is run with "-t 0", then disable the timeout completely and keep running until manually interrupted. This is useful for non-shared boards, e.g. when cdba is just used to power up the board remotely and you then SSH into a standard Linux distro installed on the board.
1 parent 06531f3 commit b6d70e8

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

cdba.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ int main(int argc, char **argv)
609609
bool power_cycle_on_timeout = true;
610610
struct timeval timeout_inactivity_tv;
611611
struct timeval timeout_total_tv;
612+
struct timeval *timeout = NULL;
612613
struct termios *orig_tios;
613614
const char *server_binary = "cdba-server";
614615
const char *status_pipe = NULL;
@@ -709,6 +710,8 @@ int main(int argc, char **argv)
709710

710711
timeout_total_tv = get_timeout(timeout_total);
711712
timeout_inactivity_tv = get_timeout(timeout_inactivity);
713+
if (timeout_total || timeout_inactivity)
714+
timeout = &tv;
712715

713716
while (!quit) {
714717
if (received_power_off || reached_timeout) {
@@ -746,14 +749,16 @@ int main(int argc, char **argv)
746749
if (!list_empty(&work_items))
747750
FD_SET(ssh_fds[0], &wfds);
748751

749-
gettimeofday(&now, NULL);
750-
if (timeout_inactivity && timercmp(&timeout_inactivity_tv, &timeout_total_tv, <)) {
751-
timersub(&timeout_inactivity_tv, &now, &tv);
752-
} else {
753-
timersub(&timeout_total_tv, &now, &tv);
752+
if (timeout) {
753+
gettimeofday(&now, NULL);
754+
if (timeout_inactivity && (!timeout_total ||
755+
timercmp(&timeout_inactivity_tv, &timeout_total_tv, <))) {
756+
timersub(&timeout_inactivity_tv, &now, timeout);
757+
} else {
758+
timersub(&timeout_total_tv, &now, timeout);
759+
}
754760
}
755-
756-
ret = select(nfds + 1, &rfds, &wfds, NULL, &tv);
761+
ret = select(nfds + 1, &rfds, &wfds, NULL, timeout);
757762
#if 0
758763
printf("select: %d (%c%c%c)\n", ret, FD_ISSET(STDIN_FILENO, &rfds) ? 'X' : '-',
759764
FD_ISSET(ssh_fds[1], &rfds) ? 'X' : '-',

0 commit comments

Comments
 (0)