/*----------------------------------------------------------------------+*/ int exec_proc_channel_object (SPC_Channel_Ptr channel) /*----------------------------------------------------------------------+*/ { XeString *tmp_argv; int iomode=channel->IOMode; /* If there is no argv specified, fix it up to be the convention (argv[0] = file pathname) */ if (channel->argv == NULL) { tmp_argv=Alloc_Argv(2); if(tmp_argv==SPC_ERROR) return(SPC_ERROR); tmp_argv[0]=SPC_copy_string(channel->path); tmp_argv[1]=NULL; channel->argv = tmp_argv; channel->IOMode |= SPCIO_DEALLOC_ARGV; } if(IS_SPCIO_WAIT(channel->IOMode)) XeSPCRegisterTerminator(channel, NULL, NULL); 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); }