Skip to content

Commit 5bade34

Browse files
authored
Merge pull request #85 from stephan-gh/local
cdba: Add option to run cdba-server locally without ssh and without timeout
2 parents 61babbf + b6d70e8 commit 5bade34

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

README

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ from sandbox/cdba/cdba-server. Available devices are read from $HOME/.cdba
1919
= Client side
2020
The client is invoked as:
2121

22-
cdba -b <board> -h <host> [-c <power-cylce-count>] [-s <status-fifo>] boot.img
22+
cdba -b <board> [-h <host>] [-c <power-cylce-count>] [-s <status-fifo>] [boot.img]
2323

2424
<host> will be connected to using ssh and <board> will be selected for
25-
operation. As the board's fastboot interface shows up the given boot.img will
26-
be transfered and booted on the device.
25+
operation. As the board's fastboot interface shows up the given boot.img
26+
will be transfered and booted on the device. If <host> is omitted, the
27+
cdba-server is started locally without using ssh. If [boot.img] is omitted,
28+
"fastboot continue" is run to boot the installed operating system.
2729

2830
The board will execute until the key sequence ^A q is invoked or the board
2931
outputs a sequence of 20 ~ (tilde) chards in a row.

cdba.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ static int fork_ssh(const char *host, const char *cmd, int *pipes)
103103
close(piped_stderr[0]);
104104
close(piped_stderr[1]);
105105

106-
execl("/usr/bin/ssh", "ssh", host, cmd, NULL);
107-
err(1, "launching ssh failed");
106+
if (host) {
107+
execlp("ssh", "ssh", host, cmd, NULL);
108+
err(1, "launching ssh failed");
109+
} else {
110+
execlp(cmd, cmd, NULL);
111+
err(1, "launching cdba-server failed");
112+
}
108113
default:
109114
close(piped_stdin[0]);
110115
close(piped_stdout[1]);
@@ -583,12 +588,12 @@ static void usage(void)
583588
{
584589
extern const char *__progname;
585590

586-
fprintf(stderr, "usage: %s -b <board> -h <host> [-t <timeout>] "
587-
"[-T <inactivity-timeout>] <boot.img>\n",
591+
fprintf(stderr, "usage: %s -b <board> [-h <host>] [-t <timeout>] "
592+
"[-T <inactivity-timeout>] [boot.img]\n",
588593
__progname);
589-
fprintf(stderr, "usage: %s -i -b <board> -h <host>\n",
594+
fprintf(stderr, "usage: %s -i -b <board> [-h <host>]\n",
590595
__progname);
591-
fprintf(stderr, "usage: %s -l -h <host>\n",
596+
fprintf(stderr, "usage: %s -l [-h <host>]\n",
592597
__progname);
593598
exit(1);
594599
}
@@ -604,6 +609,7 @@ int main(int argc, char **argv)
604609
bool power_cycle_on_timeout = true;
605610
struct timeval timeout_inactivity_tv;
606611
struct timeval timeout_total_tv;
612+
struct timeval *timeout = NULL;
607613
struct termios *orig_tios;
608614
const char *server_binary = "cdba-server";
609615
const char *status_pipe = NULL;
@@ -667,9 +673,6 @@ int main(int argc, char **argv)
667673
}
668674
}
669675

670-
if (!host)
671-
usage();
672-
673676
switch (verb) {
674677
case CDBA_BOOT:
675678
if (optind > argc || !board)
@@ -707,6 +710,8 @@ int main(int argc, char **argv)
707710

708711
timeout_total_tv = get_timeout(timeout_total);
709712
timeout_inactivity_tv = get_timeout(timeout_inactivity);
713+
if (timeout_total || timeout_inactivity)
714+
timeout = &tv;
710715

711716
while (!quit) {
712717
if (received_power_off || reached_timeout) {
@@ -744,14 +749,16 @@ int main(int argc, char **argv)
744749
if (!list_empty(&work_items))
745750
FD_SET(ssh_fds[0], &wfds);
746751

747-
gettimeofday(&now, NULL);
748-
if (timeout_inactivity && timercmp(&timeout_inactivity_tv, &timeout_total_tv, <)) {
749-
timersub(&timeout_inactivity_tv, &now, &tv);
750-
} else {
751-
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+
}
752760
}
753-
754-
ret = select(nfds + 1, &rfds, &wfds, NULL, &tv);
761+
ret = select(nfds + 1, &rfds, &wfds, NULL, timeout);
755762
#if 0
756763
printf("select: %d (%c%c%c)\n", ret, FD_ISSET(STDIN_FILENO, &rfds) ? 'X' : '-',
757764
FD_ISSET(ssh_fds[1], &rfds) ? 'X' : '-',

0 commit comments

Comments
 (0)