/*----------------------------------------------------------------------+*/ int close_channel_object (SPC_Channel_Ptr channel) /*----------------------------------------------------------------------+*/ { Wire *wirelist, *next_wire; int i; SPC_Channel_Ptr trail, ptr; /* Remove the channel from the activation list */ if(spc_activation_list == channel) spc_activation_list = channel->next; else { trail = spc_activation_list; while(trail) { ptr = trail->next; if(ptr == channel) { trail->next = ptr->next; break; } trail=ptr; } if(!trail) { SPC_Error(SPC_Closed_Channel); return(SPC_ERROR); } } /* Deallocate any memory allocated to the subfields */ if(IS_SPCIO_DEALLOC_ARGV(channel->IOMode)) SPC_Free_Envp(channel->argv); SPC_Free_Envp(channel->envp); wirelist=channel->wire_list; while(wirelist) { next_wire=wirelist->next; free_wire(wirelist); wirelist=next_wire; } for(i=1; i<3; i++) if(channel->linebufs[i]) free((char *)channel->linebufs[i]); /* Free the queue associated with the channel */ SPC_Flush_Queued_Data(channel); Xe_release_queue(channel->queued_remote_data); /* Deallocate the channel */ free((char *)channel); return(TRUE); }
/*----------------------------------------------------------------------+*/ SPC_MakeSystemCommand(SPC_Channel_Ptr channel) /*----------------------------------------------------------------------+*/ { XeString shell; XeString *argv; XeString *tmp_argv; XeChar newargtwo[_POSIX_ARG_MAX]; int argtwolen=0, tmplen=0; /* Allocate our memory up front */ argv=Alloc_Argv(4); newargtwo[argtwolen]=0; /* copy path into newargtwo */ strncat(newargtwo, channel->path, _POSIX_ARG_MAX-1); strcat(newargtwo, (XeString)" "); argtwolen=strlen(newargtwo); /* copy argv into newargtwo */ for(tmp_argv=channel->argv; tmp_argv && *tmp_argv; tmp_argv++) { tmplen=strlen(*tmp_argv)+1; /* Room for extra space */ if((tmplen+argtwolen)<_POSIX_ARG_MAX-1) { strcat(newargtwo, *tmp_argv); strcat(newargtwo, (XeString)" "); argtwolen += tmplen; } else { XeChar *errbuf; errbuf = malloc(sizeof(XeChar) * 100); if (errbuf) { SPC_Free_Envp(argv); sprintf(errbuf,"(%d chars), max. length is %d",tmplen,_POSIX_ARG_MAX); SPC_Error(SPC_Arg_Too_Long, tmp_argv, _POSIX_ARG_MAX); free(errbuf); } return(SPC_ERROR); } } /* get a shell -- First use the value of $SB_SHELL (if any), then try $SHELL, then use DEFAULT_SHELL */ if(!(shell=getenv((XeString)"SB_SHELL"))) if(!(shell=getenv((XeString)"SHELL"))) shell = DEFAULT_SHELL; /* setup argv properly */ argv[0]=SPC_copy_string(shell); argv[1]=SPC_copy_string((XeString)"-c"); argv[2]=SPC_copy_string(newargtwo); argv[3]=NULL; channel->argv = argv; channel->IOMode |= SPCIO_DEALLOC_ARGV; /* Now set this shell as the path */ channel->path = shell; return(TRUE); }