@@ -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