From: <dan...@us...> - 2007-06-13 18:22:48
|
Revision: 945 http://svn.sourceforge.net/cegcc/?rev=945&view=rev Author: dannybackx Date: 2007-06-13 11:22:30 -0700 (Wed, 13 Jun 2007) Log Message: ----------- * rshd.c : Remove #include <pkfuncs.h>. * Makefile : Add references to PipeLib directory so rshd can be built without installing PipeLib. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/Makefile trunk/cegcc/tools/rshd/rshd.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-06-13 15:23:43 UTC (rev 944) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-06-13 18:22:30 UTC (rev 945) @@ -1,3 +1,9 @@ +2007-06-13 Danny Backx <dan...@us...> + + * rshd.c : Remove #include <pkfuncs.h>. + * Makefile : Add references to PipeLib directory so rshd can be built + without installing PipeLib. + 2007-06-10 Pedro Alves <ped...@po...> Initial import. Modified: trunk/cegcc/tools/rshd/Makefile =================================================================== --- trunk/cegcc/tools/rshd/Makefile 2007-06-13 15:23:43 UTC (rev 944) +++ trunk/cegcc/tools/rshd/Makefile 2007-06-13 18:22:30 UTC (rev 945) @@ -1,6 +1,6 @@ TARGET=arm-wince-mingw32ce -LDFLAGS=-lws2 -lPipeLib -CFLAGS=-O0 -g3 +LDFLAGS=-lws2 -L../PipeLib/PipeLib -lPipeLib +CFLAGS=-O0 -g3 -I../PipeLib/PipeLib WARNFLAGS=-Wall -Wextra INCLUDES= Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-06-13 15:23:43 UTC (rev 944) +++ trunk/cegcc/tools/rshd/rshd.c 2007-06-13 18:22:30 UTC (rev 945) @@ -31,7 +31,6 @@ #include <windows.h> #include <winsock2.h> -#include <pkfuncs.h> #include <PipeLib.h> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-06-20 01:30:42
|
Revision: 975 http://svn.sourceforge.net/cegcc/?rev=975&view=rev Author: pedroalves Date: 2007-06-19 18:30:38 -0700 (Tue, 19 Jun 2007) Log Message: ----------- * rshd.c (init_client_data): Init refcount as 0. (rsh_userok): Don't compile. (rexec_userok): Delete. (create_child): Handle program arguments. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/rshd.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-06-19 22:21:16 UTC (rev 974) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-06-20 01:30:38 UTC (rev 975) @@ -1,3 +1,10 @@ +2007-06-20 Pedro Alves <ped...@po...> + + * rshd.c (init_client_data): Init refcount as 0. + (rsh_userok): Don't compile. + (rexec_userok): Delete. + (create_child): Handle program arguments. + 2007-06-13 Danny Backx <dan...@us...> * rshd.c : Remove #include <pkfuncs.h>. Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-06-19 22:21:16 UTC (rev 974) +++ trunk/cegcc/tools/rshd/rshd.c 2007-06-20 01:30:38 UTC (rev 975) @@ -176,6 +176,8 @@ static int clientid = 0; int i; + data->refcount = 0; + memset (&data->sin, 0, sizeof (data->sin)); data->clientid = ++clientid; @@ -190,6 +192,7 @@ data->stop = FALSE; } +#if 0 /* check if hostname is in users .rhost file */ static int rsh_userok (const char *hostname, const char *user) @@ -226,23 +229,7 @@ (void)user; return 1; } - -int -rexec_userok (const char *user, const char *pass) -{ -#if 0 - struct passwd *pw; - char s[256] = ""; - if ((pw = getpwnam(user)) == NULL) - return 0; - - if (strncmp(pw->pw_passwd, pass, 13) != 0) - return 0; #endif - (void)user; - (void)pass; - return 1; -} static DWORD WINAPI stdin_thread (void *arg) @@ -441,14 +428,21 @@ } argslen = 0; - args = ""; + args = program; + /* TODO: program paths with embedded spaces? */ + args = strchr (args, ' '); + if (args != NULL) + *args++ = '\0'; + else + args = ""; + argslen = strlen (args); + wargs = alloca ((argslen + 1) * sizeof (wchar_t)); + mbstowcs (wargs, args, argslen + 1); + /* PROGRAM is now free from args. */ to_back_slashes (program); - wargs = alloca ((argslen + 1) * sizeof (wchar_t)); - mbstowcs (wargs, args, argslen); wprogram = alloca ((strlen (program) + 1) * sizeof (wchar_t)); mbstowcs (wprogram, program, strlen (program) + 1); - /* Do the PipeLib/WinCE dup dance. */ for (i = 0; i < 3; i++) @@ -480,7 +474,7 @@ if (!ret) { DWORD err = GetLastError (); - fprintf (stderr, "Error creating process \"%s%s\", (error %d): %s\n", + fprintf (stderr, "Error creating process \"%s %s\", (error %d): %s\n", program, args, (int) err, strwinerror (err)); for (i = 0; i < 3; i++) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-06-24 23:40:09
|
Revision: 1004 http://svn.sourceforge.net/cegcc/?rev=1004&view=rev Author: pedroalves Date: 2007-06-24 16:40:06 -0700 (Sun, 24 Jun 2007) Log Message: ----------- * rshd.c (GetStdioPathW, SetStdioPathW): Declare. (SafeCloseHandle): New function. (stdin_thread): Don't close the reading side of the pipe too early. Use SafeCloseHandle. Don't echo data back. Add debug output into rshd's console. (stdout_thread): Use SafeCloseHandle. Add debug output into rshd's console. (stderr_thread): Use SafeCloseHandle. Add debug output into rshd's console. (create_child): Add PROCESS_INFORMATION* parameter. Create child suspended. Use SafeCloseHandle. (connect_stderr): Make it static. (handle_connection): Don't store the children't pids. Pass a new PROCESS_INFORMATION local var to create_child. Resume child after starting the stdin/stdout/stderr threads. Always wait for the three threads to finish. If the child dies before closing stdin, stdout and stderr, close our ends of the pipe. Use SafeCloseHandle. * tester.c (main): Remove sleeps. * Makefile (STRIP): New. (UNSTRIPPED_BINS): New. (STRIPPED_BINS, LIBS, TARGETS): Delete. (OBJECTS): New. (bins, libs): Delete. (rshd.exe): Rename to ... (rshd_unstripped.exe): ... this. (rshd-stripped.exe): Rename to ... (rshd.exe): ... this. (tester.exe): Rename to ... (tester_unstripped.exe): ... this. (tester-stripped.exe): Rename to ... (tester.exe): ... this. (download-rshd): New rule. (download-tester): New rule. (download): Depend on download-rshd and download-tester to do the work. (clean): Clean $(OBJECTS), $(BINS) and $(UNSTRIPPED_BINS) (.PHONY): Add dependencies on download-rshd and download-tester. * TODO: Remove already implemented items. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/Makefile trunk/cegcc/tools/rshd/TODO trunk/cegcc/tools/rshd/rshd.c trunk/cegcc/tools/rshd/tester.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-06-24 22:58:14 UTC (rev 1003) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-06-24 23:40:06 UTC (rev 1004) @@ -1,3 +1,44 @@ +2007-06-25 Pedro Alves <ped...@po...> + + * rshd.c (GetStdioPathW, SetStdioPathW): Declare. + (SafeCloseHandle): New function. + (stdin_thread): Don't close the reading side of the pipe too early. + Use SafeCloseHandle. Don't echo data back. Add debug output + into rshd's console. + (stdout_thread): Use SafeCloseHandle. Add debug output + into rshd's console. + (stderr_thread): Use SafeCloseHandle. Add debug output + into rshd's console. + (create_child): Add PROCESS_INFORMATION* parameter. Create child + suspended. Use SafeCloseHandle. + (connect_stderr): Make it static. + (handle_connection): Don't store the children't pids. Pass a new + PROCESS_INFORMATION local var to create_child. Resume child after + starting the stdin/stdout/stderr threads. Always wait for the three + threads to finish. If the child dies before closing stdin, stdout + and stderr, close our ends of the pipe. Use SafeCloseHandle. + * tester.c (main): Remove sleeps. + * Makefile (STRIP): New. + (UNSTRIPPED_BINS): New. + (STRIPPED_BINS, LIBS, TARGETS): Delete. + (OBJECTS): New. + (bins, libs): Delete. + (rshd.exe): Rename to ... + (rshd_unstripped.exe): ... this. + (rshd-stripped.exe): Rename to ... + (rshd.exe): ... this. + (tester.exe): Rename to ... + (tester_unstripped.exe): ... this. + (tester-stripped.exe): Rename to ... + (tester.exe): ... this. + (download-rshd): New rule. + (download-tester): New rule. + (download): Depend on download-rshd and download-tester to do the work. + (clean): Clean $(OBJECTS), $(BINS) and $(UNSTRIPPED_BINS) + (.PHONY): Add dependencies on download-rshd and download-tester. + + * TODO: Remove already implemented items. + 2007-06-20 Pedro Alves <ped...@po...> * rshd.c (init_client_data): Init refcount as 0. Modified: trunk/cegcc/tools/rshd/Makefile =================================================================== --- trunk/cegcc/tools/rshd/Makefile 2007-06-24 22:58:14 UTC (rev 1003) +++ trunk/cegcc/tools/rshd/Makefile 2007-06-24 23:40:06 UTC (rev 1004) @@ -8,12 +8,12 @@ ALLFLAGS=$(CFLAGS) $(INCLUDES) $(WARNFLAGS) CC=$(TARGET)-gcc +STRIP=$(TARGET)-strip +UNSTRIPPED_BINS = rshd_unstripped.exe tester_unstripped.exe BINS = rshd.exe tester.exe -STRIPPED_BINS = rshd-stripped.exe tester-stripped.exe -LIBS = -TARGETS = $(BINS) $(LIBS) +OBJECTS=rshd.o tester.o srcdir=. distdir=rshd-0.1.0 @@ -28,27 +28,29 @@ rshd.exe all: $(TARGETS) -bins: $(BINS) -libs: $(LIBS) -rshd.exe: rshd.c Makefile +rshd_unstripped.exe: rshd.c Makefile $(CC) -o $@ $< $(ALLFLAGS) $(LDFLAGS) -rshd-stripped.exe: rshd.exe - $(TARGET)-strip $< -o $@ +rshd.exe: rshd_unstripped.exe + $(STRIP) $< -o $@ -tester.exe: tester.c Makefile +tester_unstripped.exe: tester.c Makefile $(CC) -o $@ $< $(ALLFLAGS) -tester-stripped.exe: tester.exe +tester.exe: tester_unstripped.exe $(TARGET)-strip $< -o $@ -download: rshd-stripped.exe tester-stripped.exe - pcp rshd-stripped.exe ":/rshd.exe" - pcp tester-stripped.exe ":/tester.exe" +download: download-rshd download-tester +download-rshd: rshd.exe + pcp $< ":/rshd.exe" + +download-tester: tester.exe + pcp $< ":/tester.exe" + clean: - rm -f $(BINS) $(STRIPPED_BINS) $(LIBS) + rm -f $(OBJECTS) $(BINS) $(UNSTRIPPED_BINS) dist: srcdist bindist @@ -73,4 +75,4 @@ $(TAR) $(TARFLAGS)cf $(distdir)-bin$(TARFILEEXT) $(distdir) -.PHONY: all install download clean dist bindist srcdist +.PHONY: all install download download-rshd download-tester clean dist bindist srcdist Modified: trunk/cegcc/tools/rshd/TODO =================================================================== --- trunk/cegcc/tools/rshd/TODO 2007-06-24 22:58:14 UTC (rev 1003) +++ trunk/cegcc/tools/rshd/TODO 2007-06-24 23:40:06 UTC (rev 1004) @@ -1,8 +1,3 @@ -- Handle/test/pass child command line args. - -- What should be done with stdin echo? Should we do it, or not? Need - to test against a real rshd server see what happens there. - - autotoolize. - Write a proper README.txt file. Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-06-24 22:58:14 UTC (rev 1003) +++ trunk/cegcc/tools/rshd/rshd.c 2007-06-24 23:40:06 UTC (rev 1004) @@ -34,6 +34,10 @@ #include <PipeLib.h> +/* from coredll.dll */ +extern BOOL GetStdioPathW (int, wchar_t*, DWORD*); +extern BOOL SetStdioPathW (int, const wchar_t*); + #ifndef COUNTOF #define COUNTOF(STR) (sizeof (STR) / sizeof ((STR)[0])) #endif @@ -192,6 +196,19 @@ data->stop = FALSE; } +static BOOL +SafeCloseHandle (HANDLE *h) +{ + if (*h == INVALID_HANDLE_VALUE) + return TRUE; + + if (!CloseHandle (*h)) + return FALSE; + + *h = INVALID_HANDLE_VALUE; + return TRUE; +} + #if 0 /* check if hostname is in users .rhost file */ static int @@ -239,10 +256,6 @@ addref_data (data); - /* We don't need the reading side. */ - CloseHandle (data->readh[0]); - data->readh[0] = INVALID_HANDLE_VALUE; - while (!data->stop) { int read = 0; @@ -274,27 +287,29 @@ if (read) { - int written; DWORD dwwritten; - -#if 1 - /* echo data back ... */ - written = send (data->sockfd, buf, read, 0); - if (written < 0) - logprintf ("%s: write ERROR, winerr %d\n", - thread_name, - GetLastError ()); - else if (written < read) - logprintf ("%s: ERROR only wrote %d of %d bytes\n", - thread_name, written, read); -#endif - - /* ... and stuff it into the child's stdin. */ + /* Stuff it into the child's stdin. */ if (!WriteFile (data->writeh[0], buf, read, &dwwritten, NULL)) { logprintf ("%s: broken pipe (2)\n", thread_name); break; } + else + { + /* We can't close the reading side of the pipe until the + child opens its version. Since it will only be open on the + first stdin access, we have to wait until the write side + returns something - which means the child opened stdin. */ + SafeCloseHandle (&data->readh[0]); + } + + if (debug) + { + printf ("0: (%d)", read); + fflush (stdout); + write (fileno (stdout), buf, read); + printf ("\n"); + } } } @@ -320,14 +335,13 @@ logprintf ("%s: broken pipe\n", thread_name); break; } - else if (data->writeh[1] != INVALID_HANDLE_VALUE) + else { /* We can't close the write side of the pipe until the child opens its version. Since it will only be open on the first stdout access, we have to wait until the read side returns something - which means the child opened stdout. */ - CloseHandle (data->writeh[1]); - data->writeh[1] = INVALID_HANDLE_VALUE; + SafeCloseHandle (&data->writeh[1]); } if (read) { @@ -339,6 +353,14 @@ else if ((DWORD) written < read) logprintf ("%s: ERROR only wrote %d of %d bytes\n", thread_name, written, read); + + if (debug) + { + printf ("1: (%u)", (unsigned)read); + fflush (stdout); + write (fileno (stdout), buf, read); + printf ("\n"); + } } } @@ -372,14 +394,13 @@ logprintf ("%s: broken pipe\n", thread_name); break; } - else if (data->writeh[2] != INVALID_HANDLE_VALUE) + else { /* We can't close the write side of the pipe until the child opens its version. Since it will only be open on the first stderr access, we have to wait until the read side returns something - which means the child opened stderr. */ - CloseHandle (data->writeh[2]); - data->writeh[2] = INVALID_HANDLE_VALUE; + SafeCloseHandle (&data->writeh[2]); } if (read) { @@ -391,6 +412,14 @@ else if ((DWORD) written < read) logprintf ("%s: ERROR only wrote %d of %d bytes\n", thread_name, written, read); + + if (debug) + { + printf ("2: (%u)", (unsigned) read); + fflush (stdout); + write (fileno (stdout), buf, read); + printf ("\n"); + } } } @@ -410,15 +439,15 @@ /* Start a new process. Returns the new process' handle on success, NULL on failure. */ static HANDLE -create_child (char *program, HANDLE *readh, HANDLE *writeh) +create_child (char *program, HANDLE *readh, HANDLE *writeh, PROCESS_INFORMATION *pi) { BOOL ret; char *args; int argslen; - PROCESS_INFORMATION pi; wchar_t *wargs, *wprogram; wchar_t prev_path[3][MAX_PATH]; size_t i; + DWORD flags; if (program == NULL || program[0] == '\0') { @@ -456,17 +485,17 @@ GetStdioPathW (i, prev_path[i], &dwLen); SetStdioPathW (i, devname); } - + flags = CREATE_SUSPENDED; ret = CreateProcessW (wprogram, /* image name */ wargs, /* command line */ NULL, /* security, not supported */ NULL, /* thread, not supported */ FALSE, /* inherit handles, not supported */ - 0, /* start flags */ + flags, /* start flags */ NULL, /* environment, not supported */ NULL, /* current directory, not supported */ NULL, /* start info, not supported */ - &pi); /* proc info */ + pi); /* proc info */ for (i = 0; i < 3; i++) SetStdioPathW (i, prev_path[i]); @@ -479,18 +508,15 @@ for (i = 0; i < 3; i++) { - CloseHandle (readh[i]); - CloseHandle (writeh[i]); + SafeCloseHandle (&readh[i]); + SafeCloseHandle (&writeh[i]); } return NULL; } else logprintf ("Process created: %s\n", program); - CloseHandle (pi.hThread); - pi.hThread = NULL; - - return pi.hProcess; + return pi->hProcess; } static int @@ -524,7 +550,7 @@ } } -int +static int connect_stderr (int in, unsigned short stderr_port) { int s; @@ -572,6 +598,7 @@ static WINAPI DWORD handle_connection (void *arg) { + PROCESS_INFORMATION pi = { 0 }; int s2 = (int) arg; /* sizeof (void*) == sizeof (int) */ int stderrsockfd = -1; unsigned short stderr_port = 0; @@ -590,7 +617,7 @@ HANDLE waith[4]; HANDLE hndproc; - DWORD tid[3]; + DWORD stopped; size_t i; int enabled = 1; /* int disabled = 0; */ @@ -734,7 +761,7 @@ send (s2, "", 1, 0); logprintf ("handle_connection: starting command... \n"); - hndproc = create_child (command, client_data->readh, client_data->writeh); + hndproc = create_child (command, client_data->readh, client_data->writeh, &pi); if (!hndproc) { logprintf ("handle_connection: ERROR can't create child process, " @@ -745,34 +772,96 @@ client_data->sockfd = s2; client_data->stderrsockfd = stderrsockfd; - waith[0] = CreateThread (NULL, 0, stdin_thread, client_data, 0, &tid[0]); - waith[1] = CreateThread (NULL, 0, stdout_thread, client_data, 0, &tid[1]); - waith[2] = CreateThread (NULL, 0, stderr_thread, client_data, 0, &tid[2]); + waith[0] = CreateThread (NULL, 0, stdin_thread, client_data, 0, NULL); + waith[1] = CreateThread (NULL, 0, stdout_thread, client_data, 0, NULL); + waith[2] = CreateThread (NULL, 0, stderr_thread, client_data, 0, NULL); waith[3] = hndproc; - switch (WaitForMultipleObjects (COUNTOF (waith), waith, FALSE, INFINITE)) + ResumeThread (pi.hThread); + CloseHandle (pi.hThread); + pi.hThread = NULL; + + /* Wait for stdin/stdout/stderr to close before exiting. */ + + i = 0; + stopped = 0; + + /* Wait for the three threads (stdin/stdout/stderr) to finish. */ + while (i < 3) { - case WAIT_OBJECT_0: - case WAIT_OBJECT_0 + 1: - case WAIT_OBJECT_0 + 2: - TerminateProcess (hndproc, 0); - break; - case WAIT_OBJECT_0 + 3: - break; - default: - logprintf ("WaitForMultipleObjects' default reached\n"); - break; + DWORD waitCount = COUNTOF (waith) - stopped; + DWORD w; + w = WaitForMultipleObjects (waitCount, waith, FALSE, INFINITE); + if (WAIT_OBJECT_0 <= w && w < WAIT_OBJECT_0 + waitCount) + { + DWORD j = w - WAIT_OBJECT_0; + HANDLE h = waith[j]; + + /* Let's not wait for this handle again. */ + CloseHandle (waith[j]); + for (;j < COUNTOF (waith) - 1; j++) + waith[j] = waith[j + 1]; + waith[COUNTOF (waith) - 1] = INVALID_HANDLE_VALUE; + + stopped++; + + if (h == hndproc && stopped < COUNTOF (waith)) + { + int k; + + /* The child died without ever opening it's side + of the pipe, so our threads didn't see it close, + because we never closed our side. */ + + /* Tell the threads we are stopping. */ + client_data->stop = 1; + + /* Close them now. */ + for (k = 0; k < 3; k++) + { + SafeCloseHandle (&client_data->writeh[k]); + SafeCloseHandle (&client_data->readh[k]); + } + + /* Also close the sockets. At least stdin + will be frequenly blocked in a recv call. */ + if (s2 != -1) + { + shutdown (s2, 2); + closesocket (s2); + s2 = -1; + client_data->sockfd = -1; + } + + if (stderrsockfd != -1) + { + shutdown (stderrsockfd, 2); + closesocket (stderrsockfd); + client_data->stderrsockfd = -1; + } + } + else if (h != hndproc) + i++; + } + else + { + logprintf ("WaitForMultipleObjects' default reached with %d : %u\n", + w, (unsigned)GetLastError ()); + goto break_wait_loop; + } } - client_data->stop = TRUE; + logprintf ("all threads gone\n"); - for (i = 0; i < 4; i++) - CloseHandle (waith[i]); + break_wait_loop: + for (i = 0; i < COUNTOF (waith); i++) + SafeCloseHandle (&waith[i]); + for (i = 0; i < 3; i++) { - CloseHandle (client_data->writeh[i]); - CloseHandle (client_data->readh[i]); + SafeCloseHandle (&client_data->writeh[i]); + SafeCloseHandle (&client_data->readh[i]); } shutdown: @@ -781,14 +870,21 @@ ntohs (client_data->sin.sin_port)); /* close sockets */ - shutdown (s2, 2); - closesocket (s2); + if (s2 != -1) + { + shutdown (s2, 2); + closesocket (s2); + } + if (stderrsockfd != -1) { shutdown (stderrsockfd, 2); closesocket (stderrsockfd); } + if (pi.hThread != NULL) + CloseHandle (pi.hThread); + release_data (client_data); /* maybe we should wait for all the still alive threads again? */ Modified: trunk/cegcc/tools/rshd/tester.c =================================================================== --- trunk/cegcc/tools/rshd/tester.c 2007-06-24 22:58:14 UTC (rev 1003) +++ trunk/cegcc/tools/rshd/tester.c 2007-06-24 23:40:06 UTC (rev 1004) @@ -3,23 +3,16 @@ int main () { - int counter = 0; int i; for (i = 0; i < 3; i++) { - printf ("counter = %d\n", counter++); - Sleep (300); - } - - for (i = 0; i < 3; i++) - { int num; - printf ("write a num:"); + printf ("write a num: "); + fflush (stdout); scanf ("%d", &num); printf ("written = %d\n", num); } printf ("exiting\n"); - Sleep (3000); return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-06-24 23:49:57
|
Revision: 1005 http://svn.sourceforge.net/cegcc/?rev=1005&view=rev Author: pedroalves Date: 2007-06-24 16:49:55 -0700 (Sun, 24 Jun 2007) Log Message: ----------- * rshd.c (handle_connection): Remove out of sync comment. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/rshd.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-06-24 23:40:06 UTC (rev 1004) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-06-24 23:49:55 UTC (rev 1005) @@ -1,5 +1,9 @@ 2007-06-25 Pedro Alves <ped...@po...> + * rshd.c (handle_connection): Remove out of sync comment. + +2007-06-25 Pedro Alves <ped...@po...> + * rshd.c (GetStdioPathW, SetStdioPathW): Declare. (SafeCloseHandle): New function. (stdin_thread): Don't close the reading side of the pipe too early. Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-06-24 23:40:06 UTC (rev 1004) +++ trunk/cegcc/tools/rshd/rshd.c 2007-06-24 23:49:55 UTC (rev 1005) @@ -887,8 +887,6 @@ release_data (client_data); - /* maybe we should wait for all the still alive threads again? */ - return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-06-26 00:35:06
|
Revision: 1010 http://svn.sourceforge.net/cegcc/?rev=1010&view=rev Author: pedroalves Date: 2007-06-25 17:32:57 -0700 (Mon, 25 Jun 2007) Log Message: ----------- * Makefile (all): Depend on $(BINS) not $(TARGETS). Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/Makefile Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-06-25 01:32:17 UTC (rev 1009) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-06-26 00:32:57 UTC (rev 1010) @@ -1,7 +1,11 @@ +2007-06-26 Pedro Alves <ped...@po...> + + * Makefile (all): Depend on $(BINS) not $(TARGETS). + 2007-06-25 Pedro Alves <ped...@po...> * rshd.c (handle_connection): Remove out of sync comment. - + 2007-06-25 Pedro Alves <ped...@po...> * rshd.c (GetStdioPathW, SetStdioPathW): Declare. @@ -62,3 +66,10 @@ * COPYING, README, TODO, ChangeLog, Makefile, rshd.c, tester.c: New files. + +Local Variables: +mode: change-log +left-margin: 8 +fill-column: 74 +version-control: never +End: Modified: trunk/cegcc/tools/rshd/Makefile =================================================================== --- trunk/cegcc/tools/rshd/Makefile 2007-06-25 01:32:17 UTC (rev 1009) +++ trunk/cegcc/tools/rshd/Makefile 2007-06-26 00:32:57 UTC (rev 1010) @@ -27,7 +27,7 @@ BINDIST_FILES=\ rshd.exe -all: $(TARGETS) +all: $(BINS) rshd_unstripped.exe: rshd.c Makefile $(CC) -o $@ $< $(ALLFLAGS) $(LDFLAGS) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-06-28 00:56:19
|
Revision: 1016 http://svn.sourceforge.net/cegcc/?rev=1016&view=rev Author: pedroalves Date: 2007-06-27 17:56:18 -0700 (Wed, 27 Jun 2007) Log Message: ----------- * rshd.c (localecho): New global. (stdin_thread, stdout_thread, stderr_thread): Exit thread with exit code of 1 if the thread is closing because the host closed. Echo to local console depending on localecho instead of debug. (create_child): Use SetPipeTag. (handle_connection): If creating the child failed, report an error message to the host. If the remote host closed the connection abruptly, kill the child. (main): Map -l option to localecho global var. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/rshd.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-06-28 00:44:14 UTC (rev 1015) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-06-28 00:56:18 UTC (rev 1016) @@ -1,3 +1,15 @@ +2007-06-28 Pedro Alves <ped...@po...> + + * rshd.c (localecho): New global. + (stdin_thread, stdout_thread, stderr_thread): Exit thread with + exit code of 1 if the thread is closing because the host closed. + Echo to local console depending on localecho instead of debug. + (create_child): Use SetPipeTag. + (handle_connection): If creating the child failed, report an error + message to the host. If the remote host closed the connection + abruptly, kill the child. + (main): Map -l option to localecho global var. + 2007-06-26 Pedro Alves <ped...@po...> * Makefile (all): Depend on $(BINS) not $(TARGETS). Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-06-28 00:44:14 UTC (rev 1015) +++ trunk/cegcc/tools/rshd/rshd.c 2007-06-28 00:56:18 UTC (rev 1016) @@ -43,6 +43,7 @@ #endif static BOOL debug = FALSE; +static BOOL localecho = FALSE; @@ -248,11 +249,18 @@ } #endif +/* All 3 threads return 0 if they are closing because the pipes were + broken due to the child closing them, and 1 if the remote side + closed the sockets before the child died. We use this knowledge in + the main WaitForMultipleObjects to kill the child if the remote + side closed the connection. */ + static DWORD WINAPI stdin_thread (void *arg) { struct client_data_t *data = arg; const char *thread_name = "stdin_thread"; + DWORD ret = 0; addref_data (data); @@ -277,7 +285,9 @@ logprintf ("%s: recv ERROR, winerr %d\n", thread_name, err); break; } - break; + if (!data->stop) + ret = 1; + goto out; } else if (read == 0) { @@ -303,7 +313,7 @@ SafeCloseHandle (&data->readh[0]); } - if (debug) + if (localecho) { printf ("0: (%d)", read); fflush (stdout); @@ -313,9 +323,10 @@ } } +out: release_data (data); - logprintf ("%s gone\n", thread_name); - return 0; + logprintf ("%s gone : %lu\n", thread_name, ret); + return ret; } static DWORD WINAPI @@ -323,6 +334,7 @@ { struct client_data_t *data = arg; const char *thread_name = "stdout_thread"; + DWORD ret = 0; addref_data (data); @@ -330,6 +342,7 @@ { DWORD read = 0; char buf[256]; + logprintf ("%s (%d): going to ReadFile\n", thread_name, __LINE__); if (!ReadFile (data->readh[1], buf, sizeof (buf), &read, FALSE)) { logprintf ("%s: broken pipe\n", thread_name); @@ -337,15 +350,20 @@ } else { + logprintf ("%s (%d): ReadFile ok: %lu\n", thread_name, __LINE__, read); /* We can't close the write side of the pipe until the child opens its version. Since it will only be open on the first stdout access, we have to wait until the read side returns something - which means the child opened stdout. */ SafeCloseHandle (&data->writeh[1]); + logprintf ("%s (%d): SafeCloseHandle ok\n", thread_name, __LINE__); } if (read) { - int written = send (data->sockfd, buf, read, 0); + int written; + logprintf ("%s (%d): going to send\n", thread_name, __LINE__); + written = send (data->sockfd, buf, read, 0); + ret = 1; if (written < 0) logprintf ("%s: write ERROR, winerr %d\n", thread_name, @@ -353,20 +371,34 @@ else if ((DWORD) written < read) logprintf ("%s: ERROR only wrote %d of %d bytes\n", thread_name, written, read); + else + { + logprintf ("%s (%d): sent ok\n", thread_name, __LINE__); + ret = 0; + } - if (debug) + if (ret) + goto out; + + logprintf ("%s (%d): going to echo\n", thread_name, __LINE__); + + if (localecho) { printf ("1: (%u)", (unsigned)read); fflush (stdout); write (fileno (stdout), buf, read); printf ("\n"); } + + logprintf ("%s (%d): going to echo: done\n", thread_name, __LINE__); } } + out: + logprintf ("%s (%d): at out\n", thread_name, __LINE__); release_data (data); - logprintf ("%s gone\n", thread_name); - return 0; + logprintf ("%s gone : %lu\n", thread_name, ret); + return ret; } static DWORD WINAPI @@ -375,6 +407,7 @@ struct client_data_t *data = arg; const char *thread_name = "stderr_thread"; int sockfd; + DWORD ret = 0; addref_data (data); @@ -405,6 +438,7 @@ if (read) { int written = send (sockfd, buf, read, 0); + ret = 1; if (written < 0) logprintf ("%s: write ERROR, winerr %d\n", thread_name, @@ -412,8 +446,13 @@ else if ((DWORD) written < read) logprintf ("%s: ERROR only wrote %d of %d bytes\n", thread_name, written, read); + else + ret = 0; - if (debug) + if (ret) + goto out; + + if (localecho) { printf ("2: (%u)", (unsigned) read); fflush (stdout); @@ -423,9 +462,10 @@ } } + out: release_data (data); - logprintf ("%s gone\n", thread_name); - return 0; + logprintf ("%s gone : %lu\n", thread_name, ret); + return ret; } static void @@ -480,6 +520,9 @@ if (!CreatePipe (&readh[i], &writeh[i], NULL, 0)) return NULL; + wsprintf (devname, L"dev%d", i); + SetPipeTag (readh[i], devname); + GetPipeName (readh[i], devname); DWORD dwLen = MAX_PATH; GetStdioPathW (i, prev_path[i], &dwLen); @@ -696,7 +739,6 @@ *p++ = c; *p = 0; - if ((stderr_port = atoi (stderrport)) > 0) { stderrsockfd = connect_stderr (s2, stderr_port); @@ -764,8 +806,12 @@ hndproc = create_child (command, client_data->readh, client_data->writeh, &pi); if (!hndproc) { + static char buf[1024]; + DWORD err = GetLastError (); logprintf ("handle_connection: ERROR can't create child process, " - "winerr %d\n", GetLastError ()); + "winerr %lu\n", err); + sprintf (buf, "can't create process\n%s\n", strwinerror (err)); + send (s2, buf, strlen (buf), 0); goto shutdown; } @@ -796,26 +842,43 @@ { DWORD j = w - WAIT_OBJECT_0; HANDLE h = waith[j]; + DWORD ec = 0; + BOOL abrupt; - /* Let's not wait for this handle again. */ - CloseHandle (waith[j]); - for (;j < COUNTOF (waith) - 1; j++) - waith[j] = waith[j + 1]; - waith[COUNTOF (waith) - 1] = INVALID_HANDLE_VALUE; - stopped++; - if (h == hndproc && stopped < COUNTOF (waith)) + /* i counts threads */ + if (h != hndproc) + i++; + + abrupt = (h != hndproc + && !client_data->stop + && (GetExitCodeThread (h, &ec) && ec == 1)); + + if (debug) { + fprintf (stderr, "j = %ld, abrupt = %d, stopped = %ld, i = %d\n", + j, abrupt, stopped, i); + fflush (stderr); + } + + if (abrupt + || (h == hndproc && stopped < COUNTOF (waith))) + { int k; - /* The child died without ever opening it's side - of the pipe, so our threads didn't see it close, - because we never closed our side. */ + /* if (h == hndproc, the child died without ever opening + it's side of the pipe, so our threads didn't see it + close, because we never closed our side. */ /* Tell the threads we are stopping. */ client_data->stop = 1; + if (abrupt) + /* A thread died abruptly. This means the remote side + is gone (SIGINT p.ex.). Let's kill the child. */ + TerminateProcess (hndproc, 1); + /* Close them now. */ for (k = 0; k < 3; k++) { @@ -840,8 +903,12 @@ client_data->stderrsockfd = -1; } } - else if (h != hndproc) - i++; + + /* Let's not wait for this handle again. */ + CloseHandle (waith[j]); + for (;j < COUNTOF (waith) - 1; j++) + waith[j] = waith[j + 1]; + waith[COUNTOF (waith) - 1] = INVALID_HANDLE_VALUE; } else { @@ -975,11 +1042,20 @@ int main (int argc, char **argv) { + int i; WSADATA wsad; WSAStartup (MAKEWORD (2, 0), &wsad); - if (argc > 1 && strcmp(argv[1], "-d") == 0) - debug = 1; + for (i = 1; i < argc; i++) + if (strcmp(argv[i], "-d") == 0) + debug = 1; + else if (strcmp(argv[i], "-l") == 0) + localecho = 1; + else + { + fprintf (stderr, "unknown option %s\n", argv[i]); + exit (1); + } accept_connections (); return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-06-29 23:17:01
|
Revision: 1022 http://svn.sourceforge.net/cegcc/?rev=1022&view=rev Author: pedroalves Date: 2007-06-29 16:16:59 -0700 (Fri, 29 Jun 2007) Log Message: ----------- * rshd.c: Include getopt.h. (logfile): New global. (logprintf): Use logfile if set. (BUFSIZE): New define. (stdin_thread): Use BUFSIZE. Echo using logprintf. (stdout_thread): Likewise. (stderr_thread): Likewise. (handle_connection): Kill a few warnings. Set stderrsockfd to -1 after closing it. Remove dead code. (progname): New global. (usage): New function. (main): Use getopt. Add -l option. * Makefile (LDFLAGS): Adjust to new PipeLib path. (CFLAGS): Likewise. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/Makefile trunk/cegcc/tools/rshd/rshd.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-06-29 17:25:16 UTC (rev 1021) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-06-29 23:16:59 UTC (rev 1022) @@ -1,3 +1,20 @@ +2007-06-30 Pedro Alves <ped...@po...> + + * rshd.c: Include getopt.h. + (logfile): New global. + (logprintf): Use logfile if set. + (BUFSIZE): New define. + (stdin_thread): Use BUFSIZE. Echo using logprintf. + (stdout_thread): Likewise. + (stderr_thread): Likewise. + (handle_connection): Kill a few warnings. Set stderrsockfd to -1 + after closing it. Remove dead code. + (progname): New global. + (usage): New function. + (main): Use getopt. Add -l option. + * Makefile (LDFLAGS): Adjust to new PipeLib path. + (CFLAGS): Likewise. + 2007-06-28 Pedro Alves <ped...@po...> * rshd.c (localecho): New global. Modified: trunk/cegcc/tools/rshd/Makefile =================================================================== --- trunk/cegcc/tools/rshd/Makefile 2007-06-29 17:25:16 UTC (rev 1021) +++ trunk/cegcc/tools/rshd/Makefile 2007-06-29 23:16:59 UTC (rev 1022) @@ -1,6 +1,6 @@ TARGET=arm-wince-mingw32ce -LDFLAGS=-lws2 -L../PipeLib/PipeLib -lPipeLib -CFLAGS=-O0 -g3 -I../PipeLib/PipeLib +LDFLAGS=-lws2 -L../PipeLib -lPipeLib +CFLAGS=-O0 -g3 -I../PipeLib WARNFLAGS=-Wall -Wextra INCLUDES= Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-06-29 17:25:16 UTC (rev 1021) +++ trunk/cegcc/tools/rshd/rshd.c 2007-06-29 23:16:59 UTC (rev 1022) @@ -28,6 +28,7 @@ #include <fcntl.h> #include <stdarg.h> #include <malloc.h> +#include <getopt.h> #include <windows.h> #include <winsock2.h> @@ -44,15 +45,16 @@ static BOOL debug = FALSE; static BOOL localecho = FALSE; +static const char* logfile = NULL; static void logprintf (const char *fmt, ...) { - if (0) + if (logfile) { - FILE *logfile = fopen("/rshd.log", "a+"); + FILE *logfile = fopen(logfile, "a+"); if (logfile) { @@ -249,6 +251,8 @@ } #endif +#define BUFSIZE 0x1000 + /* All 3 threads return 0 if they are closing because the pipes were broken due to the child closing them, and 1 if the remote side closed the sockets before the child died. We use this knowledge in @@ -267,9 +271,9 @@ while (!data->stop) { int read = 0; - char buf[1]; + char buf[BUFSIZE + 1]; - read = recv (data->sockfd, buf, sizeof(buf), 0); + read = recv (data->sockfd, buf, BUFSIZE, 0); if (read < 0) { DWORD err = WSAGetLastError (); @@ -315,10 +319,8 @@ if (localecho) { - printf ("0: (%d)", read); - fflush (stdout); - write (fileno (stdout), buf, read); - printf ("\n"); + buf[BUFSIZE] = '\0'; + logprintf ("0 (%d): %s\n", read, buf); } } } @@ -341,9 +343,9 @@ while (!data->stop) { DWORD read = 0; - char buf[256]; + char buf[BUFSIZE + 1]; logprintf ("%s (%d): going to ReadFile\n", thread_name, __LINE__); - if (!ReadFile (data->readh[1], buf, sizeof (buf), &read, FALSE)) + if (!ReadFile (data->readh[1], buf, BUFSIZE, &read, FALSE)) { logprintf ("%s: broken pipe\n", thread_name); break; @@ -380,17 +382,11 @@ if (ret) goto out; - logprintf ("%s (%d): going to echo\n", thread_name, __LINE__); - if (localecho) { - printf ("1: (%u)", (unsigned)read); - fflush (stdout); - write (fileno (stdout), buf, read); - printf ("\n"); + buf[BUFSIZE] = '\0'; + logprintf ("1 (%lu): %s\n", read, buf); } - - logprintf ("%s (%d): going to echo: done\n", thread_name, __LINE__); } } @@ -420,9 +416,9 @@ while (!data->stop) { DWORD read = 0; - char buf[256]; + char buf[BUFSIZE + 1]; - if (!ReadFile (data->readh[2], buf, sizeof (buf), &read, FALSE)) + if (!ReadFile (data->readh[2], buf, BUFSIZE, &read, FALSE)) { logprintf ("%s: broken pipe\n", thread_name); break; @@ -454,10 +450,8 @@ if (localecho) { - printf ("2: (%u)", (unsigned) read); - fflush (stdout); - write (fileno (stdout), buf, read); - printf ("\n"); + buf[BUFSIZE] = '\0'; + logprintf ("2 (%lu): %s\n", read, buf); } } } @@ -641,7 +635,7 @@ static WINAPI DWORD handle_connection (void *arg) { - PROCESS_INFORMATION pi = { 0 }; + PROCESS_INFORMATION pi; int s2 = (int) arg; /* sizeof (void*) == sizeof (int) */ int stderrsockfd = -1; unsigned short stderr_port = 0; @@ -827,18 +821,17 @@ CloseHandle (pi.hThread); pi.hThread = NULL; - /* Wait for stdin/stdout/stderr to close before exiting. */ - i = 0; stopped = 0; - /* Wait for the three threads (stdin/stdout/stderr) to finish. */ + /* Wait for the three threads (stdin/stdout/stderr) to finish, or + for the child to exit. */ while (i < 3) { DWORD waitCount = COUNTOF (waith) - stopped; DWORD w; w = WaitForMultipleObjects (waitCount, waith, FALSE, INFINITE); - if (WAIT_OBJECT_0 <= w && w < WAIT_OBJECT_0 + waitCount) + if (/* WAIT_OBJECT_0 <= w && */ w < WAIT_OBJECT_0 + waitCount) { DWORD j = w - WAIT_OBJECT_0; HANDLE h = waith[j]; @@ -887,7 +880,7 @@ } /* Also close the sockets. At least stdin - will be frequenly blocked in a recv call. */ + will be frequenly blocked in a recv call. */ if (s2 != -1) { shutdown (s2, 2); @@ -900,6 +893,7 @@ { shutdown (stderrsockfd, 2); closesocket (stderrsockfd); + stderrsockfd = -1; client_data->stderrsockfd = -1; } } @@ -949,9 +943,6 @@ closesocket (stderrsockfd); } - if (pi.hThread != NULL) - CloseHandle (pi.hThread); - release_data (client_data); return 0; @@ -1039,23 +1030,52 @@ } } +static const char* progname; + +static void usage (void) __attribute__((noreturn)); + +static void +usage (void) +{ + fprintf (stderr, +"%s: RSH server for Windows CE\n" +"Usage: rsh [-h] [-d] [-e] [-l FILE]\n" +"-h Give this help list\n" +"-d Debug mode\n" +"-e Echo child stdin/stdout/stderr to local console\n" +"-l FILE Log debug to FILE. Implies -d\n" +, progname); + exit (1); +} + int main (int argc, char **argv) { - int i; + int c; WSADATA wsad; WSAStartup (MAKEWORD (2, 0), &wsad); - for (i = 1; i < argc; i++) - if (strcmp(argv[i], "-d") == 0) - debug = 1; - else if (strcmp(argv[i], "-l") == 0) - localecho = 1; - else + progname = argv[0]; + while ((c = getopt (argc, argv, "hdel:")) != -1) + { + switch (c) { - fprintf (stderr, "unknown option %s\n", argv[i]); - exit (1); + case 'h': + usage (); + case 'd': + debug = 1; + break; + case 'e': + localecho = 1; + break; + case 'l': + logfile = optarg; + break; + default: + fprintf (stderr, "Unknown option -- %c\n", optopt); + usage (); } + } accept_connections (); return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-06-30 21:15:48
|
Revision: 1028 http://svn.sourceforge.net/cegcc/?rev=1028&view=rev Author: pedroalves Date: 2007-06-30 14:15:46 -0700 (Sat, 30 Jun 2007) Log Message: ----------- * rshd.c (stdin_thread): If connection closed gracefully but child is still running, return 1. Remove unneeded log call. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/rshd.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-06-30 21:13:29 UTC (rev 1027) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-06-30 21:15:46 UTC (rev 1028) @@ -1,5 +1,10 @@ 2007-06-30 Pedro Alves <ped...@po...> + * rshd.c (stdin_thread): If connection closed gracefully but child + is still running, return 1. Remove unneeded log call. + +2007-06-30 Pedro Alves <ped...@po...> + * Makefile (LDFLAGS): Clear. (CFLAGS): Remove PipeLib reference. (PIPELIBDIR): New. Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-06-30 21:13:29 UTC (rev 1027) +++ trunk/cegcc/tools/rshd/rshd.c 2007-06-30 21:15:46 UTC (rev 1028) @@ -296,6 +296,8 @@ else if (read == 0) { logprintf ("%s: connection closed\n", thread_name); + if (!data->stop) + ret = 1; break; } @@ -391,7 +393,6 @@ } out: - logprintf ("%s (%d): at out\n", thread_name, __LINE__); release_data (data); logprintf ("%s gone : %lu\n", thread_name, ret); return ret; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-06-30 21:37:43
|
Revision: 1029 http://svn.sourceforge.net/cegcc/?rev=1029&view=rev Author: pedroalves Date: 2007-06-30 14:37:41 -0700 (Sat, 30 Jun 2007) Log Message: ----------- * rshd.c (create_child): Add a few comments. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/rshd.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-06-30 21:15:46 UTC (rev 1028) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-06-30 21:37:41 UTC (rev 1029) @@ -1,10 +1,14 @@ 2007-06-30 Pedro Alves <ped...@po...> - * rshd.c (stdin_thread): If connection closed gracefully but child - is still running, return 1. Remove unneeded log call. + * rshd.c (create_child): Add a few comments. 2007-06-30 Pedro Alves <ped...@po...> + * rshd.c (stdin_thread): If the connection closed gracefully but + the child is still running, return 1. Remove unneeded log call. + +2007-06-30 Pedro Alves <ped...@po...> + * Makefile (LDFLAGS): Clear. (CFLAGS): Remove PipeLib reference. (PIPELIBDIR): New. Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-06-30 21:15:46 UTC (rev 1028) +++ trunk/cegcc/tools/rshd/rshd.c 2007-06-30 21:37:41 UTC (rev 1029) @@ -507,8 +507,13 @@ to_back_slashes (program); wprogram = alloca ((strlen (program) + 1) * sizeof (wchar_t)); mbstowcs (wprogram, program, strlen (program) + 1); - /* Do the PipeLib/WinCE dup dance. */ + /* Do the PipeLib/WinCE dup dance: + Create the pipes, redirect stdin/stdout/stderr to them, + create the child, which inherits the parent's + stdin/stdout/stderr paths, and restore the parent's + paths. */ + for (i = 0; i < 3; i++) { wchar_t devname[MAX_PATH]; @@ -523,6 +528,7 @@ GetStdioPathW (i, prev_path[i], &dwLen); SetStdioPathW (i, devname); } + flags = CREATE_SUSPENDED; ret = CreateProcessW (wprogram, /* image name */ wargs, /* command line */ @@ -535,6 +541,7 @@ NULL, /* start info, not supported */ pi); /* proc info */ + /* Restore the paths. */ for (i = 0; i < 3; i++) SetStdioPathW (i, prev_path[i]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-06-30 23:34:56
|
Revision: 1030 http://svn.sourceforge.net/cegcc/?rev=1030&view=rev Author: pedroalves Date: 2007-06-30 16:34:03 -0700 (Sat, 30 Jun 2007) Log Message: ----------- * rshd.c (stdin_thread): Revert previous commit - return 0 if the child is still running. (stdin_thread, stdout_thread, stderr_thread): Close reading and writing side of the pipes before returning. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/rshd.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-06-30 21:37:41 UTC (rev 1029) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-06-30 23:34:03 UTC (rev 1030) @@ -1,3 +1,10 @@ +2007-07-01 Pedro Alves <ped...@po...> + + * rshd.c (stdin_thread): Revert previous commit - return 0 if the + child is still running. + (stdin_thread, stdout_thread, stderr_thread): Close reading and + writing side of the pipes before returning. + 2007-06-30 Pedro Alves <ped...@po...> * rshd.c (create_child): Add a few comments. Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-06-30 21:37:41 UTC (rev 1029) +++ trunk/cegcc/tools/rshd/rshd.c 2007-06-30 23:34:03 UTC (rev 1030) @@ -296,8 +296,6 @@ else if (read == 0) { logprintf ("%s: connection closed\n", thread_name); - if (!data->stop) - ret = 1; break; } @@ -328,6 +326,8 @@ } out: + SafeCloseHandle (&data->readh[0]); + SafeCloseHandle (&data->writeh[0]); release_data (data); logprintf ("%s gone : %lu\n", thread_name, ret); return ret; @@ -393,6 +393,8 @@ } out: + SafeCloseHandle (&data->readh[1]); + SafeCloseHandle (&data->writeh[1]); release_data (data); logprintf ("%s gone : %lu\n", thread_name, ret); return ret; @@ -458,6 +460,8 @@ } out: + SafeCloseHandle (&data->readh[2]); + SafeCloseHandle (&data->writeh[2]); release_data (data); logprintf ("%s gone : %lu\n", thread_name, ret); return ret; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-07-02 00:56:29
|
Revision: 1035 http://svn.sourceforge.net/cegcc/?rev=1035&view=rev Author: pedroalves Date: 2007-07-01 17:54:55 -0700 (Sun, 01 Jul 2007) Log Message: ----------- * rshd.c (handle_connection): If closing because the child died, wait for stdout to flush before closing the socket. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/rshd.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-07-01 01:56:21 UTC (rev 1034) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-07-02 00:54:55 UTC (rev 1035) @@ -1,3 +1,8 @@ +2007-07-02 Pedro Alves <ped...@po...> + + * rshd.c (handle_connection): If closing because the child died, + wait for stdout to flush before closing the socket. + 2007-07-01 Pedro Alves <ped...@po...> * rshd.c (logprintf): Avoid name clash. Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-07-01 01:56:21 UTC (rev 1034) +++ trunk/cegcc/tools/rshd/rshd.c 2007-07-02 00:54:55 UTC (rev 1035) @@ -678,6 +678,7 @@ struct client_data_t* client_data; + HANDLE thread[3]; HANDLE waith[4]; HANDLE hndproc; DWORD stopped; @@ -822,6 +823,9 @@ /* send OK */ send (s2, "", 1, 0); + client_data->sockfd = s2; + client_data->stderrsockfd = stderrsockfd; + logprintf ("handle_connection: starting command... \n"); hndproc = create_child (command, client_data->readh, client_data->writeh, &pi); if (!hndproc) @@ -835,13 +839,13 @@ goto shutdown; } - client_data->sockfd = s2; - client_data->stderrsockfd = stderrsockfd; + thread[0] = CreateThread (NULL, 0, stdin_thread, client_data, 0, NULL); + thread[1] = CreateThread (NULL, 0, stdout_thread, client_data, 0, NULL); + thread[2] = CreateThread (NULL, 0, stderr_thread, client_data, 0, NULL); - waith[0] = CreateThread (NULL, 0, stdin_thread, client_data, 0, NULL); - waith[1] = CreateThread (NULL, 0, stdout_thread, client_data, 0, NULL); - waith[2] = CreateThread (NULL, 0, stderr_thread, client_data, 0, NULL); - waith[3] = hndproc; + for (i = 0; i < COUNTOF (thread); i++) + waith[i] = thread[i]; + waith[i] = hndproc; ResumeThread (pi.hThread); CloseHandle (pi.hThread); @@ -871,57 +875,66 @@ i++; abrupt = (h != hndproc - && !client_data->stop - && (GetExitCodeThread (h, &ec) && ec == 1)); + && !client_data->stop + && (GetExitCodeThread (h, &ec) && ec == 1)); - if (debug) + logprintf ("j = %ld, abrupt = %d, stopped = %ld, i = %d\n", + j, abrupt, stopped, i); + + + if (abrupt) { - fprintf (stderr, "j = %ld, abrupt = %d, stopped = %ld, i = %d\n", - j, abrupt, stopped, i); - fflush (stderr); + /* Record that we are stopping. */ + client_data->stop = 1; + + /* A thread died abruptly. This means the remote side + is gone (SIGINT p.ex.). Let's kill the child. */ + TerminateProcess (hndproc, 1); } - - if (abrupt - || (h == hndproc && stopped < COUNTOF (waith))) + else if (h == hndproc) { - int k; - - /* if (h == hndproc, the child died without ever opening - it's side of the pipe, so our threads didn't see it - close, because we never closed our side. */ - - /* Tell the threads we are stopping. */ + /* Record that we are stopping. */ client_data->stop = 1; - if (abrupt) - /* A thread died abruptly. This means the remote side - is gone (SIGINT p.ex.). Let's kill the child. */ - TerminateProcess (hndproc, 1); + /* Close our unused sides of the pipes, since the child + may have never opened its version, thus we might + never have closed them. If we don't do this, the + threads won't see the broken pipes, as the number of + readers/writers won't reach 0. */ + SafeCloseHandle (&client_data->readh[0]); + SafeCloseHandle (&client_data->writeh[1]); + SafeCloseHandle (&client_data->writeh[2]); + } - /* Close them now. */ - for (k = 0; k < 3; k++) + if (client_data->stop) + { + if (h == thread[1]) { - SafeCloseHandle (&client_data->writeh[k]); - SafeCloseHandle (&client_data->readh[k]); + /* The child is gone, and so is the stdout thread. + All the data is now flushed to the host. Close + the socket, enabling stdin_thread to unblock. */ + if (s2 != -1) + { + logprintf ("closing stdin/stdout socket\n"); + shutdown (s2, SD_BOTH); + closesocket (s2); + s2 = -1; + client_data->sockfd = -1; + } } - - /* Also close the sockets. At least stdin - will be frequenly blocked in a recv call. */ - if (s2 != -1) + else if (h == thread[2]) { - shutdown (s2, 2); - closesocket (s2); - s2 = -1; - client_data->sockfd = -1; + /* Not sure how the host rsh handles *only* stderr + closing. */ + if (stderrsockfd != -1) + { + logprintf ("closing socket stderr\n"); + shutdown (stderrsockfd, SD_BOTH); + closesocket (stderrsockfd); + stderrsockfd = -1; + client_data->stderrsockfd = -1; + } } - - if (stderrsockfd != -1) - { - shutdown (stderrsockfd, 2); - closesocket (stderrsockfd); - stderrsockfd = -1; - client_data->stderrsockfd = -1; - } } /* Let's not wait for this handle again. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-09-08 02:07:52
|
Revision: 1059 http://cegcc.svn.sourceforge.net/cegcc/?rev=1059&view=rev Author: pedroalves Date: 2007-09-07 19:06:52 -0700 (Fri, 07 Sep 2007) Log Message: ----------- Fixes the "child has closed already, but the host didn't realize it" bug I saw frequently here. There current code expected that the child closed before the stdout pipe, but that was racy, and sometimes not true. Classic "with debug on, I don't see it" bug. * rshd.c (create_child): On pipe creation failure, close the pipes that had already been created. (handle_connection): If closing because the child died, close the stdout/stdin and stderr sockets if stdout or stderr pipes have respectivelly already closed. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/rshd.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-09-03 20:21:03 UTC (rev 1058) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-09-08 02:06:52 UTC (rev 1059) @@ -1,3 +1,11 @@ +2007-09-08 Pedro Alves <ped...@po...> + + * rshd.c (create_child): On pipe creation failure, close the pipes + that had already been created. + (handle_connection): If closing because the child died, close the + stdout/stdin and stderr sockets if stdout or stderr pipes have + respectivelly already closed. + 2007-07-02 Pedro Alves <ped...@po...> Danny Backx <dan...@us...> Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-09-03 20:21:03 UTC (rev 1058) +++ trunk/cegcc/tools/rshd/rshd.c 2007-09-08 02:06:52 UTC (rev 1059) @@ -538,8 +538,10 @@ for (i = 0; i < 3; i++) { wchar_t devname[MAX_PATH]; + child->readh[i] = child->writeh[i] = INVALID_HANDLE_VALUE; if (!CreatePipe (&child->readh[i], &child->writeh[i], NULL, 0)) { + size_t j; char buf[1024]; DWORD err = GetLastError (); if (err == ERROR_FILE_NOT_FOUND) @@ -556,6 +558,15 @@ logprintf ("%s", buf); } send (child->sockfd, buf, strlen (buf), 0); + + /* Close the previously succeeded pipes. */ + for (j = 0; j < i; j++) + { + wchar_t devname[MAX_PATH]; + SafeCloseHandle (&child->readh[j]); + SafeCloseHandle (&child->writeh[j]); + } + return NULL; } @@ -578,7 +589,7 @@ NULL, /* environment, not supported */ NULL, /* current directory, not supported */ NULL, /* start info, not supported */ - pi); /* proc info */ + pi); /* proc info */ /* Restore the paths. */ for (i = 0; i < 3; i++) @@ -706,6 +717,7 @@ HANDLE thread[3]; HANDLE waith[4]; + HANDLE allh[4]; HANDLE hndproc; DWORD stopped; size_t i; @@ -866,6 +878,9 @@ waith[i] = thread[i]; waith[i] = hndproc; + for (i = 0; i < COUNTOF (waith); i++) + allh[i] = waith[i]; + ResumeThread (pi.hThread); CloseHandle (pi.hThread); pi.hThread = NULL; @@ -886,6 +901,7 @@ HANDLE h = waith[j]; DWORD ec = 0; BOOL abrupt; + const char *name = "<?>"; stopped++; @@ -897,10 +913,37 @@ && !client_data->stop && (GetExitCodeThread (h, &ec) && ec == 1)); - logprintf ("j = %ld, abrupt = %d, stopped = %ld, i = %d\n", - j, abrupt, stopped, i); + { + int m; + const struct + { + HANDLE h; + const char *name; + HANDLE *m; + } hi[] = + { + { thread[0], "stdin", &allh[0] }, + { thread[1], "stdout", &allh[1] }, + { thread[2], "stderr", &allh[2] }, + { hndproc, "child", &allh[3] }, + }; + for (m = 0; m < COUNTOF (hi); m++) + { + if (hi[m].h == h) + { + name = hi[m].name; + /* record the fact that the object corresponding + to h is now closed. */ + *hi[m].m = INVALID_HANDLE_VALUE; + break; + } + } + } + logprintf ("j = %ld, abrupt = %d, stopped = %ld, i = %d, \"%s\"\n", + j, abrupt, stopped, i, name); + if (abrupt) { /* Record that we are stopping. */ @@ -927,7 +970,7 @@ if (client_data->stop) { - if (h == thread[1]) + if (allh[1] == INVALID_HANDLE_VALUE) { /* The child is gone, and so is the stdout thread. All the data is now flushed to the host. Close @@ -941,7 +984,8 @@ client_data->sockfd = -1; } } - else if (h == thread[2]) + + if (allh[2] == INVALID_HANDLE_VALUE) { /* Not sure how the host rsh handles *only* stderr closing. */ @@ -965,7 +1009,7 @@ else { logprintf ("WaitForMultipleObjects' default reached with %d : %u\n", - w, (unsigned)GetLastError ()); + w, (unsigned) GetLastError ()); goto break_wait_loop; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-06-29 23:26:50
|
Revision: 1023 http://svn.sourceforge.net/cegcc/?rev=1023&view=rev Author: pedroalves Date: 2007-06-29 16:26:06 -0700 (Fri, 29 Jun 2007) Log Message: ----------- * Makefile (LDFLAGS): Clear. (CFLAGS): Remove PipeLib reference. (PIPELIBDIR): New. (LIBS): New. (INCLUDES): Add -I$(PIPELIBDIR). (rshd_unstripped.exe): Link with $(LIBS). (download): Don't download tester.exe by default. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/Makefile Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-06-29 23:16:59 UTC (rev 1022) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-06-29 23:26:06 UTC (rev 1023) @@ -1,5 +1,15 @@ 2007-06-30 Pedro Alves <ped...@po...> + * Makefile (LDFLAGS): Clear. + (CFLAGS): Remove PipeLib reference. + (PIPELIBDIR): New. + (LIBS): New. + (INCLUDES): Add -I$(PIPELIBDIR). + (rshd_unstripped.exe): Link with $(LIBS). + (download): Don't download tester.exe by default. + +2007-06-30 Pedro Alves <ped...@po...> + * rshd.c: Include getopt.h. (logfile): New global. (logprintf): Use logfile if set. Modified: trunk/cegcc/tools/rshd/Makefile =================================================================== --- trunk/cegcc/tools/rshd/Makefile 2007-06-29 23:16:59 UTC (rev 1022) +++ trunk/cegcc/tools/rshd/Makefile 2007-06-29 23:26:06 UTC (rev 1023) @@ -1,9 +1,12 @@ TARGET=arm-wince-mingw32ce -LDFLAGS=-lws2 -L../PipeLib -lPipeLib -CFLAGS=-O0 -g3 -I../PipeLib + +LDFLAGS= +CFLAGS=-O0 -g3 WARNFLAGS=-Wall -Wextra -INCLUDES= +PIPELIBDIR=../PipeLib +LIBS=-lws2 -L$(PIPELIBDIR) -lPipeLib +INCLUDES=-I$(PIPELIBDIR) ALLFLAGS=$(CFLAGS) $(INCLUDES) $(WARNFLAGS) @@ -27,10 +30,10 @@ BINDIST_FILES=\ rshd.exe -all: $(BINS) +all: $(BINS) rshd_unstripped.exe: rshd.c Makefile - $(CC) -o $@ $< $(ALLFLAGS) $(LDFLAGS) + $(CC) -o $@ $< $(ALLFLAGS) $(LDFLAGS) $(LIBS) rshd.exe: rshd_unstripped.exe $(STRIP) $< -o $@ @@ -41,7 +44,7 @@ tester.exe: tester_unstripped.exe $(TARGET)-strip $< -o $@ -download: download-rshd download-tester +download: download-rshd download-rshd: rshd.exe pcp $< ":/rshd.exe" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-07-01 01:56:24
|
Revision: 1034 http://svn.sourceforge.net/cegcc/?rev=1034&view=rev Author: pedroalves Date: 2007-06-30 18:56:21 -0700 (Sat, 30 Jun 2007) Log Message: ----------- * rshd.c (logprintf): Avoid name clash. (initclientdata): Clear the correct pipes. (stdin_thread): Enhance comment. Add a totalread variable, and logprint it. (stdout_thread): Add a totalread variable, and logprint it. (stderr_thread): Likewise. (connect_stderr): Remove unneeded extra closesocket. (usage): Print to stdout instead of stderr. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/rshd.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-07-01 01:47:48 UTC (rev 1033) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-07-01 01:56:21 UTC (rev 1034) @@ -1,5 +1,16 @@ 2007-07-01 Pedro Alves <ped...@po...> + * rshd.c (logprintf): Avoid name clash. + (initclientdata): Clear the correct pipes. + (stdin_thread): Enhance comment. Add a totalread variable, and + logprint it. + (stdout_thread): Add a totalread variable, and logprint it. + (stderr_thread): Likewise. + (connect_stderr): Remove unneeded extra closesocket. + (usage): Print to stdout instead of stderr. + +2007-07-01 Pedro Alves <ped...@po...> + * rshd.c (stdin_thread): Revert previous commit - return 0 if the child is still running. (stdin_thread, stdout_thread, stderr_thread): Close reading and Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-07-01 01:47:48 UTC (rev 1033) +++ trunk/cegcc/tools/rshd/rshd.c 2007-07-01 01:56:21 UTC (rev 1034) @@ -54,15 +54,15 @@ { if (logfile) { - FILE *logfile = fopen(logfile, "a+"); + FILE *f = fopen(logfile, "a+"); - if (logfile) + if (f) { va_list ap; va_start (ap, fmt); - vfprintf (logfile, fmt, ap); + vfprintf (f, fmt, ap); va_end (ap); - fclose (logfile); + fclose (f); } } else if (debug) @@ -192,8 +192,8 @@ for (i = 0; i < 3; i++) { - data->readh[0] = INVALID_HANDLE_VALUE; - data->writeh[0] = INVALID_HANDLE_VALUE; + data->readh[i] = INVALID_HANDLE_VALUE; + data->writeh[i] = INVALID_HANDLE_VALUE; } data->stop = FALSE; @@ -257,7 +257,7 @@ broken due to the child closing them, and 1 if the remote side closed the sockets before the child died. We use this knowledge in the main WaitForMultipleObjects to kill the child if the remote - side closed the connection. */ + side closed the connection abruptly (user 'CTRL-C'ed, p.ex). */ static DWORD WINAPI stdin_thread (void *arg) @@ -265,6 +265,7 @@ struct client_data_t *data = arg; const char *thread_name = "stdin_thread"; DWORD ret = 0; + DWORD totalread = 0; addref_data (data); @@ -298,11 +299,17 @@ logprintf ("%s: connection closed\n", thread_name); break; } - - if (read) + else { DWORD dwwritten; + + totalread += read; + + logprintf ("%s (%d): totalread = %lu\n", + thread_name, __LINE__, totalread); + /* Stuff it into the child's stdin. */ + logprintf ("%s (%d): going to WriteFile\n", thread_name, __LINE__); if (!WriteFile (data->writeh[0], buf, read, &dwwritten, NULL)) { logprintf ("%s: broken pipe (2)\n", thread_name); @@ -316,6 +323,7 @@ returns something - which means the child opened stdin. */ SafeCloseHandle (&data->readh[0]); } + logprintf ("%s: written to pipe\n", thread_name); if (localecho) { @@ -339,6 +347,7 @@ struct client_data_t *data = arg; const char *thread_name = "stdout_thread"; DWORD ret = 0; + DWORD totalread = 0; addref_data (data); @@ -354,17 +363,18 @@ } else { - logprintf ("%s (%d): ReadFile ok: %lu\n", thread_name, __LINE__, read); /* We can't close the write side of the pipe until the child opens its version. Since it will only be open on the first stdout access, we have to wait until the read side returns something - which means the child opened stdout. */ SafeCloseHandle (&data->writeh[1]); - logprintf ("%s (%d): SafeCloseHandle ok\n", thread_name, __LINE__); } if (read) { int written; + totalread += read; + logprintf ("%s (%d): totalread = %lu\n", + thread_name, __LINE__, totalread); logprintf ("%s (%d): going to send\n", thread_name, __LINE__); written = send (data->sockfd, buf, read, 0); ret = 1; @@ -407,6 +417,7 @@ const char *thread_name = "stderr_thread"; int sockfd; DWORD ret = 0; + DWORD totalread = 0; addref_data (data); @@ -436,7 +447,11 @@ } if (read) { - int written = send (sockfd, buf, read, 0); + int written; + totalread += read; + logprintf ("%s (%d): totalread = %lu\n", + thread_name, __LINE__, totalread); + written = send (sockfd, buf, read, 0); ret = 1; if (written < 0) logprintf ("%s: write ERROR, winerr %d\n", @@ -633,7 +648,6 @@ } logprintf ("connect: %s\n", strwinerror (WSAGetLastError ()));; - closesocket (s); return -1; } @@ -1049,7 +1063,7 @@ static void usage (void) { - fprintf (stderr, + printf ( "%s: RSH server for Windows CE\n" "Usage: rsh [-h] [-d] [-e] [-l FILE]\n" "-h Give this help list\n" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ped...@us...> - 2007-07-02 01:46:15
|
Revision: 1037 http://svn.sourceforge.net/cegcc/?rev=1037&view=rev Author: pedroalves Date: 2007-07-01 18:46:14 -0700 (Sun, 01 Jul 2007) Log Message: ----------- * rshd.c (create_child): Pass struct client_data_t* as parameter, instead of the pipe array pointers. Report CreatePipe and CreateProcess failures to the host. (handle_connection): Pass client_data to create_child. Don't report create_child failures here. Modified Paths: -------------- trunk/cegcc/tools/rshd/ChangeLog trunk/cegcc/tools/rshd/rshd.c Modified: trunk/cegcc/tools/rshd/ChangeLog =================================================================== --- trunk/cegcc/tools/rshd/ChangeLog 2007-07-02 01:20:56 UTC (rev 1036) +++ trunk/cegcc/tools/rshd/ChangeLog 2007-07-02 01:46:14 UTC (rev 1037) @@ -1,5 +1,14 @@ 2007-07-02 Pedro Alves <ped...@po...> + Danny Backx <dan...@us...> + * rshd.c (create_child): Pass struct client_data_t* as parameter, + instead of the pipe array pointers. Report CreatePipe and + CreateProcess failures to the host. + (handle_connection): Pass client_data to create_child. Don't report + create_child failures here. + +2007-07-02 Pedro Alves <ped...@po...> + * rshd.c (handle_connection): If closing because the child died, wait for stdout to flush before closing the socket. Modified: trunk/cegcc/tools/rshd/rshd.c =================================================================== --- trunk/cegcc/tools/rshd/rshd.c 2007-07-02 01:20:56 UTC (rev 1036) +++ trunk/cegcc/tools/rshd/rshd.c 2007-07-02 01:46:14 UTC (rev 1037) @@ -493,7 +493,9 @@ /* Start a new process. Returns the new process' handle on success, NULL on failure. */ static HANDLE -create_child (char *program, HANDLE *readh, HANDLE *writeh, PROCESS_INFORMATION *pi) +create_child (char *program, + struct client_data_t* child, + PROCESS_INFORMATION *pi) { BOOL ret; char *args; @@ -536,13 +538,31 @@ for (i = 0; i < 3; i++) { wchar_t devname[MAX_PATH]; - if (!CreatePipe (&readh[i], &writeh[i], NULL, 0)) - return NULL; + if (!CreatePipe (&child->readh[i], &child->writeh[i], NULL, 0)) + { + char buf[1024]; + DWORD err = GetLastError (); + if (err == ERROR_FILE_NOT_FOUND) + { + sprintf (buf, + "Error creating pipe. " + "Copy PipeDev.dll to the device.\n"); + logprintf ("%s", buf); + } + else + { + sprintf (buf, "Error creating pipe\n" + "%s (%lu)\n", strwinerror (err), err); + logprintf ("%s", buf); + } + send (child->sockfd, buf, strlen (buf), 0); + return NULL; + } wsprintf (devname, L"dev%d", i); - SetPipeTag (readh[i], devname); + SetPipeTag (child->readh[i], devname); - GetPipeName (readh[i], devname); + GetPipeName (child->readh[i], devname); DWORD dwLen = MAX_PATH; GetStdioPathW (i, prev_path[i], &dwLen); SetStdioPathW (i, devname); @@ -567,13 +587,19 @@ if (!ret) { DWORD err = GetLastError (); - fprintf (stderr, "Error creating process \"%s %s\", (error %d): %s\n", - program, args, (int) err, strwinerror (err)); + char buf[1024]; + sprintf (buf, + "Error creating process \"%s\"\n" + "%s (error %lu)\n", + program, strwinerror (err), err); + logprintf ("%s", buf); + send (child->sockfd, buf, strlen (buf), 0); + for (i = 0; i < 3; i++) { - SafeCloseHandle (&readh[i]); - SafeCloseHandle (&writeh[i]); + SafeCloseHandle (&child->readh[i]); + SafeCloseHandle (&child->writeh[i]); } return NULL; } @@ -827,17 +853,10 @@ client_data->stderrsockfd = stderrsockfd; logprintf ("handle_connection: starting command... \n"); - hndproc = create_child (command, client_data->readh, client_data->writeh, &pi); + hndproc = create_child (command, client_data, &pi); if (!hndproc) - { - static char buf[1024]; - DWORD err = GetLastError (); - logprintf ("handle_connection: ERROR can't create child process, " - "winerr %lu\n", err); - sprintf (buf, "can't create process\n%s\n", strwinerror (err)); - send (s2, buf, strlen (buf), 0); - goto shutdown; - } + /* create_child already reports the errors to the host. */ + goto shutdown; thread[0] = CreateThread (NULL, 0, stdin_thread, client_data, 0, NULL); thread[1] = CreateThread (NULL, 0, stdout_thread, client_data, 0, NULL); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |