41 if(read(handle->
p_read, &ch_char, 1) < 0){
44 if(read(handle->
p_read, &length,
sizeof(uint32_t)) < 0){
84 buffer = malloc(ch.
length + 1);
93 printf(
"%s\n", buffer);
113 "%s serve --cmdserver pipe --config ui.interactive=True",
117 sprintf(command,
"%s -R %s", command, path);
119 if (pipe(wpipe) < 0 || pipe(rpipe) < 0) {
122 handle->
p_read = rpipe[0];
127 if ((handle->
childpid = fork()) < 0) {
133 if(dup2(c_read, STDIN_FILENO) < 0){
137 if(dup2(c_write, STDOUT_FILENO) < 0){
141 if(execl(
"/bin/sh",
"sh",
"-c", command, NULL) < 0){
166 if(kill((*handle)->childpid, SIGKILL) < 0){
170 close((*handle)->p_read);
171 close((*handle)->p_write);
197 size_t cmd_length = 0;
201 for(i = 0; i < *cmd_size; ++i){
206 cmd_length += strlen(command[i]) + 1;
209 new_cmd = malloc(cmd_length + 1);
211 for(i = 0; i < *cmd_size; ++i){
212 strcpy(new_cmd, command[i]);
213 new_cmd += strlen(command[i]) + 1;
215 new_cmd -= cmd_length;
217 *cmd_size = cmd_length - 1;
231 char runcommand[] =
"runcommand\n";
235 if(write(handle->
p_write, runcommand, strlen(runcommand)) < 0){
239 if(write(handle->
p_write, &big_endian_size,
sizeof(uint32_t)) < 0){
243 if(write(handle->
p_write, cmd_send, cmd_size) < 0){
271 length = (length > sizebuff)? sizebuff : length;
273 if(read(handle->
p_read, buffer, length) < 0){
277 buffer[length] =
'\0';
300 length = (length > buff_size)? buff_size : length;
303 if(write(handle->
p_write, &swap_size,
sizeof(uint32_t)) < 0){
306 if(write(handle->
p_write, buffer, length) < 0){
349 if(read(handle->
p_read, &exitcode,
sizeof(
int)) < 0){