Changeset 7938 for trunk/Ohana/src/opihi/lib.shell/multicommand.c
- Timestamp:
- Jul 19, 2006, 10:26:59 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/lib.shell/multicommand.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/multicommand.c
r4689 r7938 1 1 # include "opihi.h" 2 3 static int server = 0; 4 5 void multicommand_InitServer () { 6 7 char hostname[256], PASSWORD[256]; 8 9 if (server != 0) { 10 /* check if down? */ 11 fprintf (stderr, "error: server fd already defined\n"); 12 exit (1); 13 } 14 15 /* find the defined server hostname */ 16 if (VarConfig ("PANTASKS_SERVER", "%s", hostname) == NULL) { 17 gprint (GP_ERR, "pantasks server host undefined\n"); 18 exit (2); 19 } 20 21 /* attempt to connect to the server */ 22 server = GetClientSocket (hostname); 23 24 /* here we can perform the security handshaking */ 25 VarConfig ("PASSWORD", "%s", PASSWORD); 26 SendCommand (server, strlen(PASSWORD), PASSWORD); 27 28 return; 29 } 2 30 3 31 /* take input line and split into multiple lines … … 6 34 int multicommand (char *line) { 7 35 8 int done, status ;36 int done, status, verbose; 9 37 char *p, *q, *tmpline, *outline; 38 IOBuffer message; 39 40 /* if no server is defined, use 'verbose' mode for 'command' */ 41 verbose = (server == 0); 10 42 11 43 p = line; … … 21 53 stripwhite (tmpline); 22 54 if (*tmpline) { 23 status = command (tmpline, &outline); 55 56 status = command (tmpline, &outline, verbose); 57 58 if (status == -1) { 59 if (server) { 60 // send the command to the server instead 61 if (!SendMessage (server, outline)) { 62 switch (errno) { 63 case EPIPE: 64 gprint (GP_ERR, "server connection has died\n"); 65 exit (1); 66 default: 67 gprint (GP_ERR, "I/O error sending server message\n"); 68 exit (2); 69 } 70 } 71 72 // receive the resulting stderr 73 if (ExpectMessage (server, 2.0, &message)) { 74 switch (errno) { 75 case EPIPE: 76 gprint (GP_ERR, "server connection has died\n"); 77 exit (1); 78 default: 79 gprint (GP_ERR, "I/O error sending server message\n"); 80 exit (2); 81 } 82 } else { 83 gwrite (message.buffer, 1, message.Nbuffer, GP_ERR); 84 } 85 86 // receive the resulting stdout 87 if (ExpectMessage (server, 2.0, &message)) { 88 switch (errno) { 89 case EPIPE: 90 gprint (GP_ERR, "server connection has died\n"); 91 exit (1); 92 default: 93 gprint (GP_ERR, "I/O error sending server message\n"); 94 exit (2); 95 } 96 } else { 97 gwrite (message.buffer, 1, message.Nbuffer, GP_LOG); 98 } 99 } else { 100 // if no server is defined, we treat an unknown command as an error 101 status = FALSE; 102 } 103 } 104 24 105 if (outline != NULL) free (outline); 25 106 if (!status && auto_break) done = TRUE; … … 31 112 32 113 /* should skip ; surrounded by "" */ 114 115 /* commands which are not found are sent to the server socket if 116 defined. commands executed by the server return their stderr 117 and stdout streams. server commands should probably not block 118 the server for very long or multiple clients will interfere 119 with each other. 120 */
Note:
See TracChangeset
for help on using the changeset viewer.
