示例#1
0
/***************************************************************************
 *                                                                         *
 * Routine:   ConvertDropName                                              *
 *                                                                         *
 * Purpose:  Convert the "object" received from bms to a full path name    *
 *           note:  I am making BIG assumptions about the format of the    *
 *                  file I am getting from dtfile. "<host> - <path>"      *
 * WARNING:  I have used an Xe function directly (XeIsLocalHostP), rather  *
 *           than include Dt/Connect.h, which was causing bad things to    *
 *           happen at build time, probably because dticon is not ansi-   *
 *           clean (it tried to get c++ version of /usr/include/stdlib.h?) *
 *           It's simply too late to clean up the ansi... (the bell tolls) *
 *                                                                         *
 ***************************************************************************/
static char *
ConvertDropName( char *objects)
{
    char *host;
    char *path;
    char *fullName;
    char *tmp;
    char *netfile;

    host = objects;
    tmp = strchr(objects,' ');
    if (tmp==NULL)      /* shouldn't happen */
      return (strdup(strchr(objects, '/')));

    /* check if same host */
    tmp[0] = '\0';
    if ((Boolean)XeIsLocalHostP(host))
    {
        tmp[0] = ' ';
        return (strdup(strchr(objects, '/')));
    }

    /* different host... get full path name */
    path = tmp+3;      /* skip past the " - " */

    /* Convert to a valid name on the local host. */
    netfile = tt_host_file_netfile(host, path);
    fullName = tt_netfile_file(netfile);
    tt_free(netfile);

    tmp[0] = ' ';      /* put back the " " after host name */
    return (fullName);
}
示例#2
0
int 
_DtIsOpenableDirContext(
        char *path,
        char **ret_path )
{
   char *real_path = NULL;
   char * tmp_real_path;
   DIR *dirp;
   int ret_status;
   Tt_status status;
   char * host;
   char * filename;
   char * netfile;

   if (ret_path)
      *ret_path = NULL;

   host = _DtHostString(path);
   filename = _DtPathname(path);
   if (host)
   {
      netfile = tt_host_file_netfile(host, filename);
      if ((status = tt_ptr_error(netfile)) == TT_OK)
      {
         tmp_real_path = tt_netfile_file(netfile);
         status = tt_ptr_error(real_path);
         tt_free(netfile);
      }

      if (status != TT_OK) {
         real_path = NULL;
      } else {
	 real_path = XtNewString(tmp_real_path);
	 tt_free(tmp_real_path);
      }

      XtFree(filename);
      XtFree(host);
   }
   else
      real_path = filename;

   if (real_path && ((dirp = opendir (real_path)) != NULL)) 
   {
      closedir (dirp);
      ret_status = 1;
      if (ret_path)
         *ret_path = real_path;
   }
   else
   {
      ret_status = 0;
      if (real_path)
         XtFree(real_path);
   }

   return (ret_status);
}
示例#3
0
文件: TTFile.C 项目: juddy/edcde
TTFile::TTFile
	(
	const CString & host, 
	const CString & path
	) : CString(), status(TT_OK)
{
    char * temp = tt_host_file_netfile(host.data(), path.data());

    if ((status = tt_ptr_error(temp)) != TT_OK)
	Throw (TT_Exception(temp));

    contents = tt_netfile_file(temp);
    tt_free(temp);

    if ((status = tt_ptr_error(contents)) != TT_OK)
	Throw (TT_Exception(contents));
}
示例#4
0
static char *get_path_from_context (
	char 		*context)
{
   char			*host = NULL;
   char			*file = NULL;
   char			*netfile = NULL;
   char			*path = NULL;
   char			tmp[MAXPATHLEN];
   char			*pch;

   /*
    * Break context into its host and file parts.
    */
   if (context == NULL)
      return (NULL);

   (void) strcpy (tmp, context);
   file = tmp;

   if ((pch = (char *) strchr (tmp, ':')) != NULL) {
      host = tmp;
      file = pch + 1;
      *pch = '\000';
   }

   if (!host)
      return (strdup (file));

   netfile = (char *) tt_host_file_netfile (host, file);
   if (tt_ptr_error (netfile) != TT_OK) {
      SPC_Error (SPC_Cannot_Create_Netfilename, context, host);
      return (NULL);
   }

   path = (char *) tt_netfile_file (netfile);
   tt_free (netfile);
   if (tt_ptr_error (path) != TT_OK) {
      SPC_Error (SPC_Cannot_Create_Netfilename, context, host);
      return (NULL);
   }

   return (path);
}
示例#5
0
/*----------------------------------------------------------------------+*/
int exec_proc_local_channel_object(SPC_Channel_Ptr channel)
/*----------------------------------------------------------------------+*/
{
    sigset_t newsigmask, oldsigmask;
    pid_t pid;
    int result;
    XeString *envp;
    XeString dir = XeString_NULL;
    int retval;
    int i, reuse_pid = 0;
    
    call_parent_method(channel, exec_proc, (channel), result);
    
    if(result==SPC_ERROR)
	return(SPC_ERROR);

    /* Check to see if the channel pathname points to a valid executable.
       We do this by using the _path_search function.  If the channel
       has a PATH variable set in its local environment, use it,
       otherwise use the "global" environment.  We can accomplish this
       by using the spc_getenv call in the _path_search call.  If the
       channel doesn't have a PATH variable, then spc_getenv will
       return NULL, which indicates use of the global environment.
   */

    if(!_path_search(SPC_Getenv("PATH", channel->envp),
		    channel->path,
		    executable_predicate)) {
      SPC_Error(SPC_Cannot_Exec, channel->path);
      return(SPC_ERROR);
    }
       
    /* If we were passed a host:dir to cd to, make sure it exists. */
    /* We want to do this before we fork the child.                */

    if((channel->context_dir) && (channel->context_dir[0])) {
	struct stat	stat_info;
	Boolean ok = FALSE;
	
	_DtSvcProcessLock();
	if (SPC_client_version_number < SPC_PROTOCOL_VERSION_CDE_BASE)
	   dir = get_path_from_context(channel->context_dir);
	else {
	   /*
	    * context_dir is actually a "netfile" so it needs to
	    * be converted to a "real" path.
	    */
	   dir = (char *) tt_netfile_file (channel->context_dir);
	   if (tt_ptr_error (dir) != TT_OK) 
	      dir = NULL;
	}
	_DtSvcProcessUnlock();

	if (dir == NULL)
	    /* can't make connection ... */;
	else if (stat(dir,&stat_info) != 0)	
	    /* directory not there */;

	else if ((stat_info.st_mode & S_IFDIR) == 0)
	    /* path is not a directory ... */;
	else
	    ok = TRUE;
	
	if (!ok && IS_SPCIO_FORCE_CONTEXT(channel->IOMode)) {
	    if (dir != NULL && (strcmp (dir, channel->context_dir) != 0))
	       SPC_Error(SPC_cannot_Chdir, dir);
	    SPC_Error(SPC_cannot_Chdir, channel->context_dir);
	    XeFree(dir);
	    dir = XeString_NULL;
	    return(SPC_ERROR);
	}
    }

    if(mempf0(channel, pre_fork)==SPC_ERROR)
	return(SPC_ERROR);
    
    /* When using HP NLIO (xj0input) we have a problem.  Namely,  */
    /* the xj0 processs uses signal() to deal with SIGCLD which   */	
    /* is incompatible with sigaction/sigprogmask/etc.  Even      */
    /* though xj0 resets the signal handler, since the signal     */
    /* routines are incompatible, our original handler gets lost. */
    /* Hence, we need to reset it.  We do it here everytime we    */
    /* fork a child just to be on the safe side.                  */

    SPC_ResetTerminator();
    
    sigemptyset(&newsigmask);
    sigemptyset(&oldsigmask);
    sigaddset(&newsigmask, SIGCHLD);
    
    if (sigprocmask(SIG_BLOCK, &newsigmask, &oldsigmask) == ERROR)
	return(SPC_ERROR);
    
    pid = channel->pid = fork();
    
    /*
     * Must save this pid so that when the daemon's timer goes off,
     * if there has been no activity and there are no sub-processes
     * running, the daemon can exit.
     */
    i = 0;
    _DtSvcProcessLock();
    if (SPC_pid_list == NULL)
      /*
       * Create the first block plus the NULL terminator.
       */
      SPC_pid_list = (pid_t *) malloc (2 * sizeof (pid_t));
    else {
      /*
       * If a dead pid entry exists, reuse it; otherwise, must create 
       * room for the new pid.
       */
      for (i = 0; SPC_pid_list[i] != NULL; i++)
        if (SPC_pid_list[i] == SPCD_DEAD_PROCESS) {
	  SPC_pid_list[i] = pid;
	  reuse_pid = 1;
	  break;
	}
      if (!reuse_pid)
	SPC_pid_list = (pid_t *) realloc (SPC_pid_list, 
					   (i+2) * sizeof (pid_t));
    }
    if (!reuse_pid) {
      SPC_pid_list[i] = pid;
      SPC_pid_list[i+1] = NULL;
    }
    _DtSvcProcessUnlock();

    if (pid) {
	XeFree(dir);
	
	/* Did we really fork? */
	if (pid == ERROR) {
	  SPC_Error(SPC_Cannot_Fork);
	  retval = SPC_ERROR;
	} else {
	  /* Do any set up for the parent process here */
	  mempf1(channel, post_fork, pid);
	  retval = TRUE;
	}
	
	/* Reinstate the old signal mask (unblock SIGCLD). */
	
	sigprocmask(SIG_SETMASK, &oldsigmask, (sigset_t *)NULL);
	return(retval);
    }
    else {
	/* Child process: connect wires, make environment and exec sub-process */
	
	sigprocmask(SIG_SETMASK, &oldsigmask, (sigset_t *)NULL);
	
	/* Make sure the child is the process group leader.  In the case of
	   ptys, we also want to break the current terminal affiliation.
	   We want to be the process group leader so XeSPCKillProcess (which
	   does a kill(-pid, 9)) will kill all processes associated with us.
	   
	   For PTY's, we need to break the terminal affiliation so the next
	   open (which will be a pty) will cause us to become affiliated with
	   the pty.  We do this so when the parent process closes the master
	   side of the pty, the slave side processes get SIGHUP.  If they
	   ignore SIGHUP, they will never die.  So it goes...
	   */

	if(IS_SPCIO_PTY(channel->IOMode))
	    setsid();
	else {
	    pid_t tmppid = getpid();
	    if(setpgid(tmppid, tmppid) == -1) 
		fprintf(stderr, (XeString)"setpgid failed, errno: %d\n", errno);
	}
	
	/* Connect wires to sub-process standard files */
	result=mempf1(channel, post_fork, pid);
	
	if(result!=SPC_ERROR) {
	    int		indx = -1;
	    int		i;
	    char	**ppch;

	    /*
	     * Before adding in the list of environment variables 
	     * from the environment variable files, must search 
	     * the list for LANG definitions.  If found, the
	     * last definition must be putenv'ed to assure the 
	     * multi-byte parsing code is using the correct locale.
	     */
	    for (i = 0, ppch = channel->envp; *ppch; *ppch++, i++)
	       if (!strncmp (*ppch, "LANG=", 5))
		  indx = i;

	    if (indx != -1)
	       resolve_variable_reference (&channel->envp[indx]);

	    _DtSvcProcessLock();
	    if (!setlocale (LC_CTYPE, ""))
	       /*
		* setlocale failed - log a message but execute 
		* the command anyway.
		*/ 
	       if (SPC_Print_Protocol != NULL)
		  (void) fprintf(SPC_Print_Protocol,
		      "+++> Failed to 'setlocale'; LANG = %s\n",
		      getenv("LANG"));
	    /* Mix in the stashed environment */
	    
	    for(envp=channel->envp; *envp; envp++)
		resolve_variable_reference(&*envp);

	    if (SPC_mount_point_env_var != NULL)
		/*
		 * The mount point environment variable was 
		 * inherited by the daemon or was given to the
		 * daemon via the command line.  In either case
		 * this subprocess must inherit the daemon's
		 * value.
		 */
		(void) putenv (SPC_mount_point_env_var);
	    _DtSvcProcessUnlock();

	    /* Connect to the context directory */
	    /* We have already validated this guy exists */

	    if(dir) 
		Xechdir(dir);
	}
	
	XeFree(dir);

	if(result!=SPC_ERROR) {
	    /* Execute */
	    /* Compiler barfs without cast ? */
#if defined(__hpux_8_0) || defined(__aix)
            result=execvp(channel->path, channel->argv);
#else
	    result=execvp(channel->path, channel->argv);
#endif
	    /* If we return from exec, it failed */
	    SPC_Error(SPC_Cannot_Exec, channel->path);
	}
	
	/* We want to get rid of this child image (carefully) */
	_exit(42);
	
    }
}