Changeset 40776
- Timestamp:
- Jun 2, 2019, 5:35:03 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20190329/src/opihi/lib.shell/multicommand.c
r39457 r40776 74 74 tmpline = strncreate (p, q - p); 75 75 stripwhite (tmpline); 76 if (*tmpline) {77 76 78 if (bufferPending) { 79 // flush old messages 80 ExpectMessage (server, 0.2, &message); 81 bufferPending = FALSE; 82 } 77 // empty command, free and continue 78 if (*tmpline == 0) { 79 free (tmpline); 80 p = q + 1; 81 continue; 82 } 83 83 84 status = command (tmpline, &outline, verbose); 84 if (bufferPending) { 85 // flush old messages 86 ExpectMessage (server, 0.2, &message); 87 bufferPending = FALSE; 88 } 85 89 86 if (status == -1) { 87 if (server) { 88 // send the command to the server instead 89 if (!SendMessage (server, "%s", outline)) { 90 switch (errno) { 91 case EPIPE: 92 gprint (GP_ERR, "server connection has died\n"); 93 exit (32); 94 default: 95 gprint (GP_ERR, "server is busy...32\n"); 96 bufferPending = TRUE; 97 goto escape; 98 } 90 // input tmpline is freed by command 91 status = command (tmpline, &outline, verbose); 92 93 if (status == -1) { 94 if (server) { 95 // send the command to the server instead 96 if (!SendMessage (server, "%s", outline)) { 97 switch (errno) { 98 case EPIPE: 99 gprint (GP_ERR, "server connection has died\n"); 100 exit (32); 101 default: 102 gprint (GP_ERR, "server is busy...32\n"); 103 bufferPending = TRUE; 104 goto escape; 99 105 } 106 } 100 107 101 // receive the command exit status 102 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 103 switch (errno) { 104 case EPIPE: 105 gprint (GP_ERR, "server connection has died\n"); 106 exit (33); 107 default: 108 gprint (GP_ERR, "server is busy...33\n"); 109 bufferPending = TRUE; 110 goto escape; 111 } 112 } else { 113 sscanf (message.buffer, "STATUS %d", &status); 114 } 115 116 // receive the resulting stderr 117 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 118 switch (errno) { 119 case EPIPE: 120 gprint (GP_ERR, "server connection has died\n"); 121 exit (34); 122 default: 123 gprint (GP_ERR, "server is busy...34\n"); 124 bufferPending = TRUE; 125 goto escape; 126 } 127 } else { 128 gwrite (message.buffer, 1, message.Nbuffer, GP_ERR); 129 } 130 131 // receive the resulting stdout 132 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 133 switch (errno) { 134 case EPIPE: 135 gprint (GP_ERR, "server connection has died\n"); 136 exit (35); 137 default: 138 gprint (GP_ERR, "server is busy...35\n"); 139 bufferPending = TRUE; 140 goto escape; 141 } 142 } else { 143 gwrite (message.buffer, 1, message.Nbuffer, GP_LOG); 108 // receive the command exit status 109 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 110 switch (errno) { 111 case EPIPE: 112 gprint (GP_ERR, "server connection has died\n"); 113 exit (33); 114 default: 115 gprint (GP_ERR, "server is busy...33\n"); 116 bufferPending = TRUE; 117 goto escape; 144 118 } 145 119 } else { 146 // if no server is defined, we treat an unknown command as an error 147 status = FALSE; 148 } 149 } 150 escape: 151 if (outline != NULL) free (outline); 152 if (!status && auto_break) done = TRUE; 120 sscanf (message.buffer, "STATUS %d", &status); 121 } 122 123 // receive the resulting stderr 124 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 125 switch (errno) { 126 case EPIPE: 127 gprint (GP_ERR, "server connection has died\n"); 128 exit (34); 129 default: 130 gprint (GP_ERR, "server is busy...34\n"); 131 bufferPending = TRUE; 132 goto escape; 133 } 134 } else { 135 gwrite (message.buffer, 1, message.Nbuffer, GP_ERR); 136 } 137 138 // receive the resulting stdout 139 if (ExpectMessage (server, MSG_TIMEOUT, &message)) { 140 switch (errno) { 141 case EPIPE: 142 gprint (GP_ERR, "server connection has died\n"); 143 exit (35); 144 default: 145 gprint (GP_ERR, "server is busy...35\n"); 146 bufferPending = TRUE; 147 goto escape; 148 } 149 } else { 150 gwrite (message.buffer, 1, message.Nbuffer, GP_LOG); 151 } 152 } else { 153 // if no server is defined, we treat an unknown command as an error 154 status = FALSE; 155 } 153 156 } 157 escape: 158 if (outline != NULL) free (outline); 159 if (!status && auto_break) done = TRUE; 160 154 161 p = q + 1; 155 162 }
Note:
See TracChangeset
for help on using the changeset viewer.
