Changeset 7929
- Timestamp:
- Jul 18, 2006, 6:58:54 AM (20 years ago)
- Location:
- trunk/Ohana/src
- Files:
-
- 17 edited
-
libohana/include/ohana.h (modified) (1 diff)
-
libohana/src/CommOps.c (modified) (2 diffs)
-
libohana/src/IOBufferOps.c (modified) (2 diffs)
-
opihi/doc/pantasks.txt (modified) (1 diff)
-
opihi/include/pantasks.h (modified) (1 diff)
-
opihi/include/shell.h (modified) (2 diffs)
-
opihi/lib.shell/Makefile (modified) (2 diffs)
-
opihi/lib.shell/command_client.c (modified) (4 diffs)
-
opihi/lib.shell/gprint.c (modified) (3 diffs)
-
opihi/pantasks/ListenClients.c (modified) (2 diffs)
-
opihi/pantasks/Makefile (modified) (1 diff)
-
opihi/pantasks/SocketOps.c (modified) (4 diffs)
-
opihi/pantasks/client_shell.c (modified) (3 diffs)
-
opihi/pantasks/init.c (modified) (1 diff)
-
opihi/pantasks/pantasks_client.c (modified) (1 diff)
-
opihi/pantasks/pantasks_server.c (modified) (2 diffs)
-
opihi/pantasks/run.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libohana/include/ohana.h
r7917 r7929 173 173 int ExpectCommand (int device, int length, double timeout, IOBuffer *buffer); 174 174 int SendMessage (int device, char *format, ...); 175 int SendMessageFixed (int device, int length, char *messge); 175 176 int SendCommand (int device, int length, char *format, ...); 176 177 int SendCommandV (int device, int length, char *format, va_list argp); -
trunk/Ohana/src/libohana/src/CommOps.c
r7917 r7929 88 88 } 89 89 90 /* send a message of known size, sending the size first */ 91 int SendMessageFixed (int device, int length, char *message) { 92 93 int status; 94 95 status = SendCommand (device, 16, "NBYTES: %6d", length); 96 status = SendCommand (device, length, message); 97 return (status); 98 } 99 90 100 int SendCommand (int device, int length, char *format, ...) { 91 101 … … 108 118 vsnprintf (string, length + 1, format, argp); 109 119 110 /* fprintf (stderr, "msg: %s\n", string); */111 120 write (device, string, length); 112 121 free (string); -
trunk/Ohana/src/libohana/src/IOBufferOps.c
r7917 r7929 107 107 Nbyte = vsnprintf (&tmp, 0, format, argp); 108 108 109 if (buffer[0].Nbuffer + Nbyte + 1 >= buffer[0].Nalloc) {109 if (buffer[0].Nbuffer + Nbyte + 1>= buffer[0].Nalloc) { 110 110 buffer[0].Nalloc = buffer[0].Nbuffer + Nbyte + 64; 111 111 REALLOCATE (buffer[0].buffer, char, buffer[0].Nalloc); … … 113 113 114 114 vsnprintf (&buffer[0].buffer[buffer[0].Nbuffer], Nbyte + 1, format, argp); 115 buffer[0].Nbuffer += Nbyte + 1;115 buffer[0].Nbuffer += Nbyte; 116 116 return (TRUE); 117 117 } -
trunk/Ohana/src/opihi/doc/pantasks.txt
r7892 r7929 1 2 - additional issues: 3 4 - missing dependency for shell.h? 5 - should not return an error message in client if command is not found 6 - server input needs to place files for input on a stack which is 7 actually loaded by the RunScheduler loop 8 - have the client run a special multicommand function which passes 9 any unfound commands along to the server. the server should not 10 be running multicommand, but it probably does not hurt. 11 (the client is not allowed to send ';' to the server) 12 - the multicommand needs to be available in the 'for' and other loops 13 this probably means unifying the client and non-client forms. 14 how does multiclient get the value of the server? I tend to use 15 globals for things like that, which is probably not the best 16 practice. is the client form of the tool generic? are there other 17 circumstances which would use a client/server beyond pantasks? 18 maybe pcontrol? 19 20 the two pieces of information which need to be carried to the 21 multicommand and command functions in client/server mode are the 22 server socket and the verbosity of the error messages. these could 23 be defined on startup with globals and an init function of some sort. 1 24 2 25 I need to do some serious work on the output messages in order -
trunk/Ohana/src/opihi/include/pantasks.h
r7917 r7929 129 129 130 130 void InitPantasks (); 131 void InitPantasksServer (); 131 132 void InitPantasksClient (); 132 133 void InitTasks (); -
trunk/Ohana/src/opihi/include/shell.h
r7917 r7929 49 49 int multicommand PROTO((char *line)); 50 50 int command PROTO((char *, char **)); 51 int multicommand_client PROTO((char *line, int)); 51 52 int command_client PROTO((char *, char **)); 52 53 char *expand_vars PROTO((char *line)); … … 146 147 FILE *gprintGetFile (gpDest dest); 147 148 int gprint (gpDest dest, char *format, ...); 149 int gwrite (char *buffer, int size, int N, gpDest dest); 148 150 149 151 # endif -
trunk/Ohana/src/opihi/lib.shell/Makefile
r7917 r7929 21 21 $(SDIR)/ListOps.$(ARCH).o \ 22 22 $(SDIR)/command.$(ARCH).o \ 23 $(SDIR)/command_client.$(ARCH).o \ 23 24 $(SDIR)/CommandOps.$(ARCH).o \ 24 25 $(SDIR)/errors.$(ARCH).o \ … … 37 38 $(SDIR)/memstr.$(ARCH).o \ 38 39 $(SDIR)/multicommand.$(ARCH).o \ 40 $(SDIR)/multicommand_client.$(ARCH).o \ 39 41 $(SDIR)/parse.$(ARCH).o \ 40 42 $(SDIR)/parse_commands.$(ARCH).o \ -
trunk/Ohana/src/opihi/lib.shell/command_client.c
r7892 r7929 2 2 # define VERBOSE 0 3 3 4 /* this function acts like the standard command parser, 5 but skips the expansion of variables and vectors */ 4 // this function is identical to the normal command.c function, 5 // but it returns -1 for a missing command and does not echo the 6 // 'missing command' error message 7 6 8 int command_client (char *line, char **outline) { 7 9 … … 17 19 } 18 20 21 /* expand anything of the form $fred or $fred$sam, etc */ 22 line = expand_vars (line); /* line is freed here, new one allocated */ 23 /* expand anything of the form fred[N] */ 24 line = expand_vectors (line); /* line is freed here, new one allocated */ 25 /* solve math expresions, assign variable, if needed */ 26 line = parse (line); /* line is freed here, new one allocated */ 27 /* any entry in line of the form {foo} returns value or tmp vector / buffer */ 28 19 29 /* we may have reallocated line, return new pointer */ 20 30 *outline = line; … … 27 37 for (i = 0; i < argc; i++) targv[i] = argv[i]; 28 38 29 cmd = MatchCommand (argv[0], TRUE, FALSE); 39 // use non-verbose mode to skip 'missing command' error message 40 cmd = MatchCommand (argv[0], FALSE, FALSE); 30 41 if (cmd == NULL) { 31 status = FALSE;42 status = -1; 32 43 } else { 33 44 free (argv[0]); … … 40 51 free (argv); 41 52 53 if (!status) { 54 char *msg; 55 msg = get_variable_ptr ("ERRORMSG"); 56 if (msg != (char *) NULL) gprint (GP_ERR, "%s\n", msg); 57 } 58 59 set_int_variable ("STATUS", status); 60 if (VERBOSE) gprint (GP_ERR, "command: %s, status: %d\n", line, status); 42 61 return (status); 43 62 } -
trunk/Ohana/src/opihi/lib.shell/gprint.c
r7917 r7929 77 77 return (&streams[i]); 78 78 } 79 fprintf ( STDERR, "programming error: gprintInit not called for thread\n");79 fprintf (stderr, "programming error: gprintInit not called for thread\n"); 80 80 abort (); 81 81 } … … 90 90 if (stream[0].file != NULL) { 91 91 fflush (stream[0].file); 92 if (stream[0].file != stdout) fclose (stream[0].file); 92 if (stream[0].file == stdout) goto skip_close; 93 if (stream[0].file == stderr) goto skip_close; 94 fclose (stream[0].file); 95 96 skip_close: 93 97 stream[0].file = NULL; 94 98 } … … 146 150 stream[0].file = fopen (filename, "a"); 147 151 if (stream[0].file == NULL) { 148 fprintf ( STDERR, "cannot open file %s\n", filename);152 fprintf (stderr, "cannot open file %s\n", filename); 149 153 stream[0].file = (dest == GP_LOG) ? stdout : stderr; 150 154 } -
trunk/Ohana/src/opihi/pantasks/ListenClients.c
r7917 r7929 43 43 struct timeval timeout; 44 44 IOBuffer *outbuffer; 45 IOBuffer testbuffer; 45 46 46 47 InitClients (); 48 gprintInit (); // each thread needs to init the printing system 47 49 48 50 while (0) { … … 131 133 132 134 /* we now have a possible command from the client: run it */ 135 /* in this thread, we set the print output destination to be an 136 internal buffer, which we dump at the end of the execution */ 133 137 /* XXX : we need to handle ; in the client-parsing of commands */ 134 138 stripwhite (line); 135 139 if (*line) { 136 if (1) gprint (GP_ERR, "got command: %s\n", line); 137 SetOutBuffer (); 140 141 if (1) fprintf (stderr, "got command: %s\n", line); 142 143 /* this works: we can send a simple message */ 144 # if 0 145 SendMessage (clients[i], "first"); 146 SendMessage (clients[i], "second"); 147 # endif 148 149 /* this works: we can send a message using the IOBuffers */ 150 # if 0 151 InitIOBuffer (&testbuffer, 64); 152 PrintIOBuffer (&testbuffer, "this is a test\n"); 153 SendMessageFixed (clients[i], testbuffer.Nbuffer, testbuffer.buffer); 154 PrintIOBuffer (&testbuffer, "this is a second test\n"); 155 SendMessageFixed (clients[i], testbuffer.Nbuffer, testbuffer.buffer); 156 # endif 157 158 /* this works: we can use the printing system to write a message */ 159 # if 0 160 gprintSetBuffer (GP_LOG); 161 gprint (GP_LOG, "test is a test line\n"); 162 outbuffer = gprintGetBuffer (GP_LOG); 163 SendMessageFixed (clients[i], outbuffer[0].Nbuffer, outbuffer[0].buffer); 164 165 gprint (GP_LOG, "test is a second test line\n"); 166 outbuffer = gprintGetBuffer (GP_LOG); 167 SendMessageFixed (clients[i], outbuffer[0].Nbuffer, outbuffer[0].buffer); 168 # endif 169 170 /* this works: we can use the gprint service */ 171 # if 0 172 gprintSetBuffer (GP_LOG); 173 gprint (GP_LOG, "test is a test line\n"); 138 174 status = multicommand (line); 139 outbuffer = GetOutBuffer (); 140 141 gprint (GP_ERR, "send message: %d bytes\n", outbuffer[0].Nbuffer); 142 gwrite (outbuffer[0].buffer, 1, outbuffer[0].Nbuffer, GP_ERR); 143 gprint (GP_ERR, "end message\n"); 144 145 SendMessage (clients[i], outbuffer[0].buffer); 146 SetOutfile ("stdout"); 175 176 outbuffer = gprintGetBuffer (GP_LOG); 177 SendMessageFixed (clients[i], outbuffer[0].Nbuffer, outbuffer[0].buffer); 178 gprintSetFile (GP_LOG, "stdout"); 179 180 SendMessage (clients[i], "second"); 181 # endif 182 183 /* this only kind of works: it acts as if we hang */ 184 # if 1 185 gprintSetBuffer (GP_LOG); 186 gprintSetBuffer (GP_ERR); 187 188 // gprint (GP_LOG, "test is a test stdout\n"); 189 // gprint (GP_ERR, "test is a test stderr\n"); 190 191 status = multicommand (line); 192 fprintf (stderr, "sending response\n"); 193 194 // return the stderr messages first 195 outbuffer = gprintGetBuffer (GP_ERR); 196 SendMessageFixed (clients[i], outbuffer[0].Nbuffer, outbuffer[0].buffer); 197 fprintf (stderr, "sent stderr\n"); 198 199 outbuffer = gprintGetBuffer (GP_LOG); 200 SendMessageFixed (clients[i], outbuffer[0].Nbuffer, outbuffer[0].buffer); 201 fprintf (stderr, "sent stdout\n"); 202 203 gprintSetFile (GP_LOG, "stdout"); 204 gprintSetFile (GP_ERR, "stderr"); 205 # endif 147 206 } 148 207 free (line); -
trunk/Ohana/src/opihi/pantasks/Makefile
r7917 r7929 48 48 $(SDIR)/kill.$(ARCH).o \ 49 49 $(SDIR)/delete.$(ARCH).o \ 50 $(SDIR)/server.$(ARCH).o \ 50 51 $(SDIR)/verbose.$(ARCH).o \ 51 52 $(SDIR)/controller.$(ARCH).o \ -
trunk/Ohana/src/opihi/pantasks/SocketOps.c
r7917 r7929 30 30 Address[0].sin_addr.s_addr = INADDR_ANY; // use this line to bind any address / port? 31 31 32 retry_server: 33 32 34 # if (0) 33 35 status = inet_aton (hostip, &Address[0].sin_addr); … … 49 51 status = bind (InitSocket, (struct sockaddr *) Address, length); 50 52 if (status == -1) { 53 fprintf (stderr, "errno: %d\n", errno); 54 fprintf (stderr, "EACCES: %d\n", EACCES); 55 fprintf (stderr, "EBADF: %d\n", EBADF); 56 fprintf (stderr, "EINVAL: %d\n", EINVAL); 57 fprintf (stderr, "ENOTSOCK: %d\n", ENOTSOCK); 58 fprintf (stderr, "EFAULT: %d\n", EFAULT); 59 fprintf (stderr, "ELOOP: %d\n", ELOOP); 60 fprintf (stderr, "ENAMETOOLONG: %d\n", ENAMETOOLONG); 61 fprintf (stderr, "ENOENT: %d\n", ENOENT); 62 fprintf (stderr, "ENOMEM: %d\n", ENOMEM); 63 fprintf (stderr, "ENOTDIR: %d\n", ENOTDIR); 64 fprintf (stderr, "EROFS: %d\n", EROFS); 65 66 Address[0].sin_port ++; 67 if (Address[0].sin_port > MY_PORT + 10) exit (2); 68 fprintf (stderr, "trying next port: %d\n", Address[0].sin_port); 69 goto retry_server; 70 51 71 perror ("bind: "); 52 72 exit (2); 53 73 } 74 /* repeated starts of the server are limited by xinetd or something: 75 requires 60sec timeout of the selected socket */ 54 76 55 77 status = listen (InitSocket, 10); … … 140 162 Address.sin_family = AF_INET; 141 163 Address.sin_port = MY_PORT; 164 165 retry_client: 142 166 status = inet_aton (hostip, &Address.sin_addr); 143 167 if (!status) { … … 156 180 status = connect (InitSocket, (struct sockaddr *) &Address, length); 157 181 if (status == -1) { 182 if (errno == ECONNREFUSED) { 183 Address.sin_port ++; 184 if (Address.sin_port > MY_PORT + 10) exit (2); 185 fprintf (stderr, "trying next port: %d\n", Address.sin_port); 186 goto retry_client; 187 } 158 188 perror ("connect: "); 159 189 exit (2); -
trunk/Ohana/src/opihi/pantasks/client_shell.c
r7917 r7929 4 4 int client_shell (int argc, char **argv) { 5 5 6 int Nbad, status, server;6 int i, Nbad, status, server; 7 7 char *line, *outline, *prompt, *history; 8 8 char hostname[256], PASSWORD[256]; … … 55 55 /* XXX the exit status of command does not allow us 56 56 to distinguish 'failed command' and 'command not found' */ 57 status = command (line, &outline); 58 if (outline == NULL) { 59 gprint (GP_ERR, "programming error: command_client returned NULL\n"); 60 exit (2); 61 } 57 /* XXX eventually replace this with a multicommand parsing */ 58 status = multicommand_client (line, server); 59 add_history (line); 60 append_history (1, history); 62 61 62 free (line); 63 } 64 } 65 66 # if 0 63 67 /* command was not caught by client, send to server */ 64 68 if (*outline && !status ) { … … 70 74 // XXX add this in and print to stdout 71 75 status = ExpectMessage (server, 2.0, &message); 72 gprint (GP_ERR, "got message: %d bytes\n", message.Nbuffer); 73 gwrite (message.buffer, 1, message.Nbuffer, GP_ERR); 74 gprint (GP_ERR, "end message\n"); 76 // fprintf (stderr, "got stdout message: %d bytes\n", message.Nbuffer); 77 fwrite (message.buffer, 1, message.Nbuffer, stderr); 78 // fprintf (stderr, "end message\n"); 79 80 // fprintf (stderr, "got message: %d bytes\n", message.Nbuffer); 81 // for (i = 0; i < message.Nbuffer; i++) { 82 // fprintf (stderr, "%d %d %c\n", i, message.buffer[i], message.buffer[i]); 83 // } 84 // fwrite (message.buffer, 1, message.Nbuffer, stderr); 85 // fprintf (stderr, "end message\n"); 86 87 // XXX add this in and print to stdout 88 status = ExpectMessage (server, 2.0, &message); 89 // fprintf (stderr, "got stderr message: %d bytes\n", message.Nbuffer); 90 fwrite (message.buffer, 1, message.Nbuffer, stderr); 91 // fprintf (stderr, "end message\n"); 75 92 } 76 free (outline); 77 } 78 } 93 # endif 79 94 80 95 /* -
trunk/Ohana/src/opihi/pantasks/init.c
r7892 r7929 64 64 65 65 } 66 67 int server PROTO((int, char **)); 68 69 static Command server_cmds[] = { 70 {"server", server, "server-specific commands"}, 71 }; 72 73 void InitPantasksServer () { 74 75 int i; 76 77 InitTasks (); 78 InitJobs (); 79 InitJobIDs (); 80 81 for (i = 0; i < sizeof (cmds) / sizeof (Command); i++) { 82 AddCommand (&cmds[i]); 83 } 84 for (i = 0; i < sizeof (server_cmds) / sizeof (Command); i++) { 85 AddCommand (&server_cmds[i]); 86 } 87 88 } -
trunk/Ohana/src/opihi/pantasks/pantasks_client.c
r7917 r7929 14 14 InitData (); 15 15 InitPantasksClient (); 16 17 gprintInit (); 16 18 17 19 rl_readline_name = opihi_name; -
trunk/Ohana/src/opihi/pantasks/pantasks_server.c
r7917 r7929 29 29 InitBasic (); 30 30 InitData (); 31 InitPantasks ();31 InitPantasksServer (); 32 32 33 InitPrint ();33 gprintInit (); // each thread needs to init the printing system 34 34 35 35 // signal (SIGPIPE, gotsignal); … … 47 47 48 48 // pthread_create (&thread, NULL, &RunScheduler, NULL); 49 // pthread_create (&thread, NULL, & pantasks_RunController, NULL);49 // pthread_create (&thread, NULL, &RunController, NULL); 50 50 51 51 /* in this loop, we listen for incoming connections, validate, and -
trunk/Ohana/src/opihi/pantasks/run.c
r7917 r7929 1 1 # include "pantasks.h" 2 3 // XXX for client/server, we need to simply start or stop the 4 // appropriate threads 5 // with one thread for each of the major actions, this would 6 // make it easy to keep the controller running and stop the 7 // scheduler (don't run CheckTasks, but run everything else 8 // until nothing is left... 2 9 3 10 int run (int argc, char **argv) {
Note:
See TracChangeset
for help on using the changeset viewer.
