Example #1
0
File: Main.c Project: juddy/edcde
/*++++++++++++++++++++++++++++++++++++++*/
int 
main(
        int argc,
        char **argv )
{
    int             n;
    Arg             args[MAX_ARGS];
    XEvent          event;
    XPropertyEvent *pEvent=(XPropertyEvent *)&event;
    long            mwmFunc;
    Boolean         useMaskRtn, useIconFileCacheRtn;    
    char           *dirs = NULL;
    char           *string;
	Visual         *visual;

#ifdef USERHELP
malloc_check(1);
malloc_trace(0);
#endif

    XtSetLanguageProc(NULL, NULL, NULL);
    _DtEnvControl(DT_ENV_SET); 
    

    /* Initialize the toolkit and open the display */
    style.shell = 
        XtInitialize(argv[0], XMCLASS, option_list, 1, (int *)&argc, argv);

#ifdef __osf__
    _XmColorObjCreate(style.shell, NULL, NULL);
#endif

    /* Allow all WS manipulation functions except resize and maximize */
    mwmFunc = MWM_FUNC_ALL ^ (MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE); 

    n = 0;
    XtSetArg(args[n], XmNmwmFunctions, mwmFunc); n++;
    XtSetArg(args[n], XmNuseAsyncGeometry, True); n++;
    XtSetValues(style.shell, args, n);

    /* initialize global style data */

    style.display    = XtDisplay(style.shell);
    style.screen     = DefaultScreenOfDisplay(style.display);
    style.screenNum  = DefaultScreen(style.display);
    style.colormap   = DefaultColormap(style.display, style.screenNum);
    style.root       = DefaultRootWindow(style.display);
    style.execName   = argv[0];
    style.errDialog  = NULL;
    style.tmpXmStr   = NULL;
    style.home = (char *) XtMalloc(strlen((char *) getenv("HOME")) + 1);
    strcpy(style.home, (char *) getenv("HOME"));
    style.colorDialog = NULL;
    style.backdropDialog = NULL;
    style.fontDialog = NULL;
    style.kbdDialog = NULL;
    style.mouseDialog = NULL;
    style.audioDialog = NULL;
    style.screenDialog = NULL;
    style.startupDialog = NULL;
    style.dtwmDialog = NULL;
    style.i18nDialog = NULL;
	visual = XDefaultVisual(style.display,style.screenNum);
	style.visualClass = visual->class;
    
    if (progName = DtStrrchr(argv[0], '/')) progName++;
    else progName = argv[0];

    /* Get the lock established to ensure only one dtstyle process
     * is running per screen .. first malloc enough space*/

    if (_DtGetLock (style.display, STYLE_LOCK) == 0)
    {
        _DtSimpleError (progName, DtError, NULL, "%s",
	     ((char *)GETMESSAGE(2, 5, "Style Manager is already running, second attempt aborted.")));
        exit(1);
    }

    InitDtstyleProtocol();
    SetWindowProperties();

    /* Register error handlers */
    XSetErrorHandler(ErrorHandler);
    XSetIOErrorHandler(IOErrorHandler);
    XtAppSetErrorHandler(XtWidgetToApplicationContext(style.shell),
                         ToolkitErrorHandler);
    XtAddEventHandler(style.shell, StructureNotifyMask, 0,
                         (XtEventHandler)MwmReparentNotify, NULL);

    /* set up resolution dependent layout variables */
    switch (_DtGetDisplayResolution(style.display, style.screenNum))
    {
        case LOW_RES_DISPLAY:
            style.horizontalSpacing = 
            style.verticalSpacing = 3;
            break;
            
        case MED_RES_DISPLAY:
            style.horizontalSpacing = 
            style.verticalSpacing = 5;
            break;
            
        case HIGH_RES_DISPLAY:
            style.horizontalSpacing = 
            style.verticalSpacing = 8;
            break;
    }
    
    GetApplicationResources();
    
    XmeGetIconControlInfo(style.screen, &useMaskRtn,
			  &style.useMultiColorIcons, &useIconFileCacheRtn);
    
    
    /* add the directory $HOME/.dt/backdrops */
    
    string = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops:") + 1);
    sprintf(string, "%s/.dt/backdrops:", style.home);

    dirs = (char *)XtCalloc(1, strlen("/etc/dt/backdrops:/usr/dt/backdrops") + 
			    (style.xrdb.backdropDir == NULL ? 2 :
			    strlen(style.xrdb.backdropDir)) + 
			    strlen(string) + 2);
  

    strcpy(dirs, string);
    if (style.xrdb.backdropDir) 
      {
	strcat(dirs, style.xrdb.backdropDir);
	strcat(dirs, ":"); 
      }
    strcat(dirs, "/etc/dt/backdrops:/usr/dt/backdrops");

    _DtWsmSetBackdropSearchPath(style.screen, dirs, style.useMultiColorIcons);

    if (string != NULL)
      XtFree((char *)string);
    
    if (dirs != NULL)
      XtFree((char *)dirs); 
    
    

    style.count = 0;
    /* if this is started from save session we need to set up the BMS
       first, otherwise do it after making the window. (for user perception
       for how long it takes for the dtstyle to come up) */
    if(style.xrdb.session != NULL) {
      DtInitialize (style.display, style.shell, progName, progName);
      /*Restore a session or build and display the main Window.*/
      if(!restoreSession(style.shell,style.xrdb.session))
	init_mainWindow(style.shell);
    }
    else {
      init_mainWindow(style.shell);
      DtInitialize (style.display, style.shell, progName, progName);
      InitializeAtoms();
      CheckMonitor(style.shell);
      GetDefaultPal(style.shell);
    }
    
    signal(SIGINT,(void (*)())activateCB_exitBtn); 
    signal(SIGTERM,(void (*)())activateCB_exitBtn); 

    /* to avoid defunct screen saver processes */    
    signal(SIGCHLD, (void (*)())WaitChildDeath);

    /* backdrop dialog  needs to know when the workspace changes to recolor 
       the bitmap displayed in the dialog */
    ListenForWorkspaceChange();

    /* if using COLOR builtin, style.workProcs is True */

    if ((XmeUseColorObj() != FALSE) && style.workProcs)

        XtAppAddWorkProc(XtWidgetToApplicationContext(style.shell), 
                        NewCreateD, style.shell);

    XtAppMainLoop(XtWidgetToApplicationContext(style.shell));

    return 0;
}
Example #2
0
int main(int argc, char **argv)
{
#ifndef NO_CDE
   _DtEnvControl(DT_ENV_SET);
#endif

// run as user's UID
#ifdef hpux
   setresuid(getuid(), getuid(), (uid_t)0);
#else
   seteuid(getuid());
#endif

   setlocale(LC_ALL, "");

   char *lang = getenv("LANG");
   if (lang && strcmp(lang, "C"))
    {
      errno = 0;

#ifdef NL_CAT_LOCALE
      dtprintinfo_cat = catopen("dtprintinfo", NL_CAT_LOCALE);
#else
      dtprintinfo_cat = catopen("dtprintinfo", 0);
#endif

      if ((nl_catd) errno)
         dtprintinfo_cat = (nl_catd) -1;
#ifdef hpux
      else
         msg_strings = (char **)calloc(LAST_MSG_NO, sizeof(char *));
#endif
    }

   if (dtprintinfo_cat == NULL) {
      dtprintinfo_cat = (nl_catd) -1;
   }

   if (!STRCMP(argv[1], "-help"))
    {
      char *output;
      char *cmd = new char [strlen(LIST_QUEUES) + 30];
      sprintf(cmd, "%s | awk '{print \"\\t\", $1}'", LIST_QUEUES);
      Invoke *_thread = new Invoke(cmd, &output);
      printf(MESSAGE(CommandLineHelpL), output);
      printf("\n");
      delete output;
      delete [] cmd;
      delete _thread;
      return 0;
    }

   char *progname = strrchr(argv[0], '/');
   if (progname)
      progname++;
   else
      progname = argv[0];
   if (!STRCMP(argv[1], "-populate"))
    {
      if (getuid() != 0)
       {
	 fprintf(stderr, MESSAGE(RootUserL), progname, "-populate");
	 fprintf(stderr, "\n");
	 return 1;
       }

      PrintSubSystem *prt = new PrintSubSystem(NULL);
      int n_queues = prt->NumChildren();
      // Get Print Subsystem children, (these are queues)
      Queue **queues = (Queue **)prt->Children();
      int i;
      for (i = 0; i < n_queues; i++)
       {
         DtPrinterIcon *icon = new DtPrinterIcon(NULL, NULL, queues[i],
						 INITIALIZE_PRINTERS);
	 icon->CreateActionFile();
	 delete icon;
       }
      return 0;
    }

   DtApp *app = new DtApp(progname, &argc, argv);
   app->Visible(true);
   app->Run();

   return 0;
}
Example #3
0
void
main(int argc, char **argv)
{
	int		cnt, status = 0;
	char		*date = NULL, *view = NULL, *target = NULL,
			*start = NULL, *end = NULL, *repeat = NULL,
			*numrepeat = NULL, *what = NULL, *uname, *loc;
	Props		*p = NULL;
	CSA_entry_handle	*list;
	CSA_session_handle	c_handle;
	CSA_return_code		stat;
	CSA_calendar_user	csa_user;
	DisplayType		dt;
	int			version;
	char			date_str[256];
#ifdef FNS
	char		buf[256];
#endif

	init_time();
        _DtEnvControl(DT_ENV_SET); /* set up environment variables */
	setlocale(LC_ALL, "");
	DT_catd = catopen(DTCM_CAT, NL_CAT_LOCALE);
	cm_tty_load_props(&p);
	dt = get_int_prop(p, CP_DEFAULTDISP);
#ifdef FNS
	dtfns_init();
#endif

	if (argc > 1)
	{
		cm_args(argc,argv);		/* parse command line */
		if (cm_strlen(cm_target)) 
			target = cm_target;
		else
			target = cm_get_credentials();
#ifdef FNS
		if (cmfns_use_fns(p)) {
			cmfns_lookup_calendar(target, buf, sizeof(buf));
			target = buf;
		}
#endif
		uname = cm_target2name(target);
		loc = cm_target2location(target);

		csa_user.user_name = target;
		csa_user.user_type = 0;
		csa_user.calendar_user_extensions = NULL;
		csa_user.calendar_address = target;
		stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL);
		if (stat != CSA_SUCCESS) {
		  	char *format = cm_strdup(catgets(DT_catd, 1, 206, 
					   "\nCould not open calendar %s\n"));
			fprintf(stderr, format,
				target ? target : 
				catgets(DT_catd, 1, 209, "UNKNOWN"));
			free(format);
			free(uname);
			free(loc);
			exit(1);
		}
		version = get_data_version(c_handle);
		if (!cm_date[0])
        		format_tick(now(), get_int_prop(p, CP_DATEORDERING),
		    		    get_int_prop(p, CP_DATESEPARATOR), cm_date);
		if (cm_strlen(cm_date)) date = cm_date;
		if (cm_strlen(cm_view)) view = cm_view;
		if (cm_strlen(cm_start)) start = cm_start;

		if (!cm_end[0] && cm_start[0]) {
			format_time((int)cm_getdate(cm_start, NULL) + hrsec,
				    dt, cm_end);
		}

		if (cm_strlen(cm_end)) end = cm_end;
		if (cm_strlen(cm_repeatstr)) repeat = cm_repeatstr;
		if (cm_strlen(cm_for)) numrepeat = cm_for;
		if (cm_strlen(cm_what)) what = cm_what;
		if (!cm_appt_file[0])
			status = cm_tty_insert(DT_catd, c_handle, version, 
				      date, start, end, repeat, numrepeat,
				      what, NULL, p);
		else
			status = cm_tty_insert(DT_catd, c_handle, version, date,
				      start, end, repeat, numrepeat,
				      what, cm_appt_file, p);
	} else {
		prompt_for_insert(p);
		if (cm_strlen(cm_target)) target = cm_target;
		uname = cm_target2name(target);
		loc = cm_target2location(target);

		csa_user.user_name = target;
		csa_user.user_type = 0;
		csa_user.calendar_user_extensions = NULL;
		csa_user.calendar_address = target;
		stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL);
		if (stat !=CSA_SUCCESS) {
		  	char *format = cm_strdup(catgets(DT_catd, 1, 206, 
					   "\nCould not open calendar %s\n"));
			fprintf(stderr, format, 
				target ? target : 
				catgets(DT_catd, 1, 209, "UNKNOWN"));
			free(format);
			free(uname);
			free(loc);
			exit(1);
		}
		version = get_data_version(c_handle);
		if (cm_strlen(cm_date)) date = cm_date;
		if (cm_strlen(cm_view)) view = cm_view;
		if (cm_strlen(cm_start)) start = cm_start;
		if (cm_strlen(cm_end)) end = cm_end;
		if (cm_strlen(cm_repeatstr)) repeat = cm_repeatstr;
		if (cm_strlen(cm_for)) numrepeat = cm_for;
		if (cm_strlen(cm_what)) what = cm_what;
		status = cm_tty_insert(DT_catd, c_handle, version, date, 
			      start, end, repeat, numrepeat, what, NULL, p);
	}
	if ((cnt = cm_tty_lookup(DT_catd, c_handle, version, date, view, 
					&list, p)) > 0)
		csa_free(list);
	csa_logoff(c_handle, NULL);
	props_clean_up(p);
	free(p);
	free(uname);
	free(loc);
        exit(status);
}
Example #4
0
int main(int argc, char **argv)
{
	int		cnt;
	char		index[10], *target = NULL, *date = NULL, *view = NULL,
			*uname, *loc;
	Props		*p = NULL;
	CSA_entry_handle	*list;
	CSA_session_handle	c_handle;
	CSA_return_code		stat;
	CSA_calendar_user	csa_user;
	int			version;
#ifdef FNS
	char		buf[256];
#endif

	init_time();
	setlocale(LC_ALL, "");
	_DtEnvControl(DT_ENV_SET); /* set up environment variables */
	DT_catd = catopen(DTCM_CAT, NL_CAT_LOCALE);
	cm_tty_load_props(&p);
	cm_args(argc,argv);		/* parse command line */
	target = (cm_strlen(cm_target)) ? cm_target : cm_get_credentials();

#ifdef FNS
	dtfns_init();
	if (cmfns_use_fns(p)) {
		cmfns_lookup_calendar(target, buf, sizeof(buf));
		target = buf;
	}
#endif
	if (cm_strlen(cm_date)) date = cm_date;
	if (cm_strlen(cm_view)) view = cm_view;

	uname = cm_target2name(target);
	loc = cm_target2location(target);

	csa_user.user_name = target;
	csa_user.user_type = 0;
	csa_user.calendar_user_extensions = NULL;
	csa_user.calendar_address = target;
	stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL);

	if (stat != CSA_SUCCESS) {
	  	char *format = strdup(catgets(DT_catd, 1, 188,
					   "\nCould not open calendar %s\n"));
		fprintf(stderr, format,
			target ? target : catgets(DT_catd, 1, 189, "UNKNOWN"));
		free(format);
		free(uname);
		free(loc);
		exit(1);
	}
	version = get_data_version(c_handle);

	while (!cm_index) {
		if ((cnt = cm_tty_lookup(DT_catd, c_handle, version, date, 
					view, &list, p)) <= 0) {
			csa_logoff(c_handle, NULL);
			free(uname);
			free(loc);
			exit(0);
		}
		fprintf(stdout, catgets(DT_catd, 1, 190,
				       "Item to delete (number)? "));
		fgets(index, 9, stdin);
		fprintf(stdout,"\n\n");
		if (*index < '0' || *index > '9') {
			csa_free(list);
			break;
		}
		cm_index = atoi(index);
		if (cnt >= cm_index)
			cm_tty_delete(DT_catd, c_handle, version, 
				      cm_index - 1, list);
		memset(index, '\0', 10);
		csa_free(list);
		cm_index = 0;
	}

	csa_logoff(c_handle, NULL);
	props_clean_up(p);
	free(p);
	free(uname);
	free(loc);
	return 0;
}
Example #5
0
int
main (int argc, char *argv [], char *environ [])
{
    XEvent	event;
    Boolean	dispatchEvent;

    setlocale(LC_ALL, "");

#ifndef NO_MULTIBYTE
#ifdef WSM
    /*
     * Set up environment variables for this HP DT client
     */
    _DtEnvControl(DT_ENV_SET);

    /*
     * Force LANG lookup early. 
     * (Front end may change $LANG to 'C' as part
     *  of string space reduction optimization.)
     */
     {
	 char * foo = ((char *)GETMESSAGE(44, 1, ""));
     }
#endif /* WSM */
    XtSetLanguageProc (NULL, (XtLanguageProc)NULL, NULL);
#endif
#ifdef WSM
    /*  
     * Get Identity
     */
    WmIdentity = WmReturnIdentity(argc, argv, environ);
#endif /* WSM */

    /*
     * Initialize the workspace:
     */

    InitWmGlobal (argc, argv, environ);
#ifdef WSM

    /*
     * Set up PATH variable if it must run as standalone command
     * invoker
     */
    if (wmGD.dtLite)
    {
	_DtEnvControl(DT_ENV_SET_BIN);
    }
#endif /* WSM */
    
    /*
     * MAIN EVENT HANDLING LOOP:
     */

    for (;;)
    {
        XtAppNextEvent (wmGD.mwmAppContext, &event);


        /*
	 * Check for, and process non-widget events.  The events may be
	 * reported to the root window, to some client frame window,
	 * to an icon window, or to a "special" window management window.
	 * The lock modifier is "filtered" out for window manager processing.
	 */

	wmGD.attributesWindow = 0L;

#ifdef WSM
	if ((event.type == ButtonPress) || 
	    (event.type == ButtonRelease))
	{
	    if ((wmGD.evLastButton.button != 0) &&
		ReplayedButtonEvent (&(wmGD.evLastButton), 
				     &(event.xbutton)))
	    {
		wmGD.bReplayedButton = True;
	    }
	    else
	    {
		/* save this button for next comparison */
		memcpy (&wmGD.evLastButton, &event, sizeof (XButtonEvent));
		wmGD.bReplayedButton = False;
	    }
	}
#endif /* WSM */
	dispatchEvent = True;
	if (wmGD.menuActive)
	{
	    /*
	     * Do special menu event preprocessing.
	     */

	    if (wmGD.checkHotspot || wmGD.menuUnpostKeySpec ||
		wmGD.menuActive->accelKeySpecs)
	    {
	        dispatchEvent = WmDispatchMenuEvent ((XButtonEvent *) &event);
	    }
	}

	if (dispatchEvent)
	{
	    if (ManagedRoot(event.xany.window))
	    {
	        dispatchEvent = WmDispatchWsEvent (&event);
	    }
	    else
	    {
	        dispatchEvent = WmDispatchClientEvent (&event);
	    }

	    if (dispatchEvent)
	    {
                /*
                 * Dispatch widget related event:
                 */

                XtDispatchEvent (&event);
	    }
	}
    }

} /* END OF FUNCTION main */
Example #6
0
/*******************************************************************************
 *
 * _DtSPCOpen()
 *	This is a wrapper around DtSPCOpen (i.e. XeSPCOpen) that makes sure
 *	the original environment is restored before the spawn and the DT
 *      environment is reinstated after the spawn.  It returns the value
 *	originally returned by DtSPCOpen.
 *
 ******************************************************************************/
SPC_Channel_Ptr
_DtSPCOpen(
    char *hostname,
    int iomode,
    char *errorMessage)
{
    SPC_Channel_Ptr	chan;
    _Xgetpwparams	pwd_buf;
    struct passwd *	pwd_ret;

    /*
     * Restore the original environment
     */
    (void) _DtEnvControl (DT_ENV_RESTORE_PRE_DT);

    /*
     * Map some env var paths to execHost.
     */
    (void) _DtEnvMapForRemote(hostname);

    if ((chan = XeSPCOpen(hostname, iomode)) == SPC_ERROR)
    {
        uid_t		this_uid;
        char		*username;

        switch (DtSPCErrorNumber)
        {
        case SPC_Unknown_Host:
            (void) sprintf (errorMessage,
                            errorUnknownHost,
                            hostname);
            break;
        case SPC_Bad_Connect:
            (void) sprintf (errorMessage,
                            errorBadConnect,
                            hostname,
                            SPC_SERVICE,
                            _cmdClientHost);
            break;
        case SPC_Bad_Service:
            (void) sprintf (errorMessage,
                            errorBadService,
                            SPC_SERVICE,
                            _cmdClientHost);
            break;
        case SPC_Register_Handshake:
            this_uid = getuid();
            if((pwd_ret = _XGetpwuid(this_uid, pwd_buf)) ==
                    NULL)
                username = NULL;
            else
                username = pwd_ret->pw_name;
            (void) sprintf (errorMessage,
                            errorRegisterHandshake,
                            hostname,
                            username,
                            this_uid,
                            _cmdClientHost,
                            hostname);
            break;
        case SPC_Register_Username:
            this_uid = getuid();
            if((pwd_ret = _XGetpwuid(this_uid, pwd_buf)) ==
                    NULL)
                username = NULL;
            else
                username = pwd_ret->pw_name;
            (void) sprintf (errorMessage,
                            errorRegisterUsername,
                            hostname,
                            username);
            break;
        case SPC_Register_Netrc:
            (void) sprintf (errorMessage,
                            errorRegisterNetrc,
                            hostname);
            break;
        case SPC_Env_Too_Big:
            (void) sprintf (errorMessage,
                            errorEnvTooBig,
                            hostname,
                            SPC_BUFSIZ);
            break;
        case SPC_Connection_EOF:
#ifdef __hpux
            (void) sprintf (errorMessage,
                            errorInetSecurity,
                            hostname,
                            _cmdClientHost,
                            SPC_SERVICE,
                            _cmdClientHost,
                            SPC_SERVICE,
                            INETD_SECURITY_FILE,
                            hostname);

#else /* __hpux */
            (void) sprintf (errorMessage,
                            errorBadConnect,
                            hostname,
                            SPC_SERVICE,
                            _cmdClientHost);
#endif /* __hpux */
            break;
        default:
            /*
             * SPC_Register_Open:
             */
            (void) sprintf (errorMessage,
                            errorRegisterOpen,
                            hostname);
        }
    }

    /*
     * Restore some env var paths.
     */
    (void) _DtEnvRestoreLocal();

    /*
     * Restore the DT environment
     */
    (void) _DtEnvControl (DT_ENV_RESTORE_POST_DT);

    return chan;
}
Example #7
0
int
_DtCmdCommandInvokerExecute (
    char *errorMessage,		/* MODIFIED */
    DtSvcMsgContext replyContext,	/* OBSOLETE -- always NULL */
    int  winMask,
    char *contextHost,
    char *contextDir,
    char *contextFile,		/* OBSOLETE -- always NULL */
    char *execParms,
    char *execHost,
    char *execString,
    char *procId,
    char *tmpFiles,
    DtCmdInvExecuteProc success_proc,
    void *success_data,
    DtCmdInvExecuteProc failure_proc,
    void *failure_data)

{
    int ioMode, i, index1;
    int windowType;
    pid_t commandPid;
    char context[MAXPATHLEN];
    char tmpDir [MAXPATHLEN];
    char **commandArray;
    SPC_Channel_Ptr cmdChannel;
    char *theCommand = NULL;
    Boolean terminalRequest = False;
    char *commandArray2[MAX_EXEC_ARGS];
    Boolean localExecution = True;
    Boolean xhostError;
    static unsigned long requestNum = 0;
    char *toolRequest = NULL;	/* backward compatibility kludge */


    myassert( !(contextFile && replyContext) );

    /*
     * Check for a valid window-type.
     * This check is probably redundant but it converts the mask bits into
     * small integer values used by the rest of the command invoker code.
     */
    if ((windowType=
                DtCmdGetWindowType(winMask))== -1)
    {
        (void) sprintf (errorMessage, errorRequest, toolRequest,
                        DtTERMINAL, DtPERM_TERMINAL, DtOUTPUT_ONLY,
                        DtSHARED_OUTPUT, "" /* Obsolete shell window */,
                        DtNO_STDIO);
        return (_CMD_EXECUTE_FATAL);
    }

    /*
     * Create the command to be exec'ed.
     */
    if (windowType == PERM_TERMINAL || windowType == TERMINAL)
    {
        _DtCmdCreateTerminalCommand (&theCommand, windowType, execString,
                                     execParms, execHost, procId, tmpFiles);
        terminalRequest = True;
    }
    else
    {
        /*
         * NO-STDIO || START-SESSION request.
         */

        theCommand = XtMalloc(
                         + strlen (cmd_Resources.dtexecPath)
                         + strlen(" -open ") + 4 /* waitTime len */
                         + strlen(" -ttprocid ") + strlen(_DtActNULL_GUARD(procId))
                         + strlen(_DtActNULL_GUARD(tmpFiles))
                         + strlen (execString)
                         + 5 /* for 2 quotes,2 blanks,null */);

        sprintf(theCommand,"%s -open %d -ttprocid '%s' %s %s",
                cmd_Resources.dtexecPath,
                0 /* wait time zero for NO_STDIO */,
                _DtActNULL_GUARD(procId),
                _DtActNULL_GUARD(tmpFiles),
                execString);

    }

    /*
     * See if the request requires Remote Execution.
     */
    localExecution = _DtIsSameHost(execHost,NULL);

    /*
     * If this is a terminalRequest and the Command Invoker subprocess
     * is not executable, return now.
     */
    if (localExecution && terminalRequest && !cmd_Globals.subprocess_ok)
    {
        if (!(_DtCmdCheckForExecutable (cmd_Resources.dtexecPath)))
        {
            (void) sprintf (errorMessage, cmd_Globals.error_subprocess,
                            cmd_Resources.dtexecPath);
            XtFree ((char *) theCommand);
            return (_CMD_EXECUTE_FAILURE);
        }
        else
            cmd_Globals.subprocess_ok = True;
    }

    /*
     * If this is a terminalRequest and the terminal emulator
     * is not executable, return now.
     */
    if (localExecution && terminalRequest && !cmd_Globals.terminal_ok)
    {
        if (!(_DtCmdCheckForExecutable (cmd_Resources.localTerminal)))
        {
            (void) sprintf (errorMessage, cmd_Globals.error_terminal,
                            cmd_Resources.localTerminal);
            XtFree ((char *) theCommand);
            return (_CMD_EXECUTE_FAILURE);
        }
        else
            cmd_Globals.terminal_ok = True;
    }

    /*
     * Break the command into something execvp or SPCSpawn can handle
     * and then free "theCommand" if this is a termianl-based request.
     */
    commandArray = (char **) XtMalloc (MAX_EXEC_ARGS * sizeof (char *));
    _DtCmdStringToArrayOfStrings (theCommand, commandArray);

    XtFree (theCommand);

    if (!localExecution)
    {
        char *netfile;
        char *argv[4];
        char *tmp;

        /* REMOTE Execution */

        ioMode = SPCIO_NOIO | SPCIO_SYNC_TERMINATOR | SPCIO_FORCE_CONTEXT;

        if ((cmdChannel = (_DtSPCOpen(execHost,
                                      ioMode,
                                      errorMessage))) == SPC_ERROR)
        {
            Cmd_FreeAllocatedStringVector (commandArray);
            return (_CMD_EXECUTE_FAILURE);
        }

        /* Old syntax should no longer appear in contextHost/Dir */
        myassert( (contextHost?*contextHost != '*':1) &&
                  (contextDir?*contextDir != '*':1) );
        /*
         * Create a "netfile" for the cwd to be used.
         */
        netfile = (char *) tt_host_file_netfile (
                      ((contextHost == NULL) ? execHost : contextHost),
                      ((contextDir  == NULL) ? (char *) getenv ("HOME") : contextDir));

        if (tt_pointer_error (netfile) != TT_OK) {
            (void) sprintf (errorMessage, cmd_Globals.error_directory_name_map,
                            ((contextDir  == NULL) ? (char *) getenv ("HOME") : contextDir),
                            ((contextHost == NULL) ? execHost : contextHost),
                            tt_status_message (tt_pointer_error(netfile)));
            Cmd_FreeAllocatedStringVector (commandArray);
            return (_CMD_EXECUTE_FAILURE);
        }
        (void) strcpy (context, netfile);
        tt_free (netfile);

        /*
         * First check to see if the "dtexecPath" is executable on
         * the remote execution host by executing it with no
         * options which will cause it to immediately die.
         *
         * There is no need to set up termination handler for this
         * because we don't care when it dies, we only care about
         * whether or not it can be executed.
         */

        argv[0] = cmd_Resources.dtexecPath;
        argv[1] = (char *) NULL;

        if ((_DtSPCSpawn(argv[0], context, argv, NULL, cmdChannel,
                         execHost, contextHost, contextDir, errorMessage))
                == SPC_ERROR)
        {
            if (DtSPCErrorNumber != SPC_cannot_Chdir &&
                    DtSPCErrorNumber != SPC_Cannot_Fork  &&
                    DtSPCErrorNumber != SPC_Env_Too_Big  &&
                    DtSPCErrorNumber != SPC_Arg_Too_Long)
                /*
                 * The Error message must mention that the dtexec
                 * process is not executable so must overwrite the
                 * error message returned by the Spawn function with
                 * an appropriate message.
                 */
                (void) sprintf (errorMessage, errorRemoteSubprocess, execHost,
                                cmd_Resources.dtexecPath);
            DtSPCClose(cmdChannel);
            Cmd_FreeAllocatedStringVector (commandArray);
            return (_CMD_EXECUTE_FAILURE);
        }

        /* The dtexec process is now known to exist on the remote host */

        /*
         *  Now run a test to see if the command is executable
         *  on this exec host.
         */
        _DtCmdStringToArrayOfStrings (execString, commandArray2);

        tmp = (char *) XtMalloc (strlen (commandArray2[0]) +
                                 strlen ("whence ") + 2);
        (void) sprintf (tmp, "whence %s", commandArray2[0]);

        _DtCmdFreeStringVector (commandArray2);

        argv[0] = "ksh";
        argv[1] = "-c";
        argv[2] = tmp;
        argv[3] = (char *) NULL;

        /*
         * Reopen the channel
         */
        if ((cmdChannel = (_DtSPCOpen(execHost,
                                      ioMode,
                                      errorMessage))) == SPC_ERROR)
        {
            Cmd_FreeAllocatedStringVector (commandArray);
            return (_CMD_EXECUTE_FAILURE);
        }

        /*
         * Set up a callback to be invoked when the test command
         * terminates.
         */
        _DtSvcProcessLock();
        if ((DtSPCRegisterTerminator(cmdChannel,
                                     (SPC_TerminateHandlerType) CheckCommandTerminator,
                                     (void *) ++requestNum)) == SPC_ERROR)
        {
            DtSPCClose(cmdChannel);
            Cmd_FreeAllocatedStringVector (commandArray);
            (void) strcpy (errorMessage, errorSpcTerminator);
            XtFree ((char *) tmp);
            _DtSvcProcessUnlock();
            return (_CMD_EXECUTE_FAILURE);
        }

        if ((_DtSPCSpawn(argv[0], context, argv, NULL, cmdChannel,
                         execHost, contextHost, contextDir, errorMessage))
                == SPC_ERROR)
        {
            DtSPCClose(cmdChannel);
            (void) sprintf (errorMessage, errorRemoteSubprocess, execHost,
                            argv[0]);
            Cmd_FreeAllocatedStringVector (commandArray);
            XtFree ((char *) tmp);
            _DtSvcProcessUnlock();
            return (_CMD_EXECUTE_FAILURE);
        }
        /*
         * The command line checking process has been spawned.
         * There is nothing left to do but to queue the request
         * and return to the client's main loop.  The command
         * line will be executed after the above spawned process
         * terminates.
         */
        QueueRequest (cmdChannel, context, execHost, execString,
                      commandArray, windowType, requestNum, replyContext,
                      success_proc, success_data, failure_proc, failure_data);
        _DtSvcProcessUnlock();
        XtFree(tmp);
        return (_CMD_EXECUTE_QUEUED);
    }
    else
    {
        /* LOCAL Execution */

        /*
         * Must first check to see if the execvp will potentially fail.
         *
         * Since the terminal emulator is pre-appended onto the execution
         * string, don't want to check it (should have been done during
         * startup (in _DtInitializeCommandInvoker)) but must check the
         * execution string that was passed in as part of the message.
         */
        /* Break the command into something execvp can handle */
        _DtCmdStringToArrayOfStrings (execString, commandArray2);

        if (!_DtCmdCheckForExecutable (commandArray2[0]))
        {
            (void) sprintf (errorMessage, errorExec, commandArray2[0]);
            Cmd_FreeAllocatedStringVector (commandArray);
            _DtCmdFreeStringVector (commandArray2);
            return (_CMD_EXECUTE_FAILURE);
        }
        _DtCmdFreeStringVector (commandArray2);

        /*
         * Save the current directory and then "chdir" to the directory
         * to do the execution.  If the chdir fails, return.
         */
        (void) getcwd (tmpDir, MAXPATHLEN);

        if (!_DtCmdValidDir (_cmdClientHost, contextDir, contextHost))
        {
            Cmd_FreeAllocatedStringVector (commandArray);
            (void) sprintf (errorMessage, errorChdir, contextDir, execHost);
            (void) chdir (tmpDir);
            return (_CMD_EXECUTE_FAILURE);
        }

        /*
         * Restore the original environment and remove any DT
         * specific environment variables that were added.
         */
        (void) _DtEnvControl (DT_ENV_RESTORE_PRE_DT);

        /* Fork and then execvp the execution string */
        for (index1 = 0; (index1 < 10) &&
                ((commandPid = fork ()) < 0); index1++)
        {
            /* Out of resources ? */
            if (errno != EAGAIN)
                break;
            /* If not out of resources, sleep and try again */
            (void) sleep ((unsigned long) 2);
        }

        if (commandPid < 0)
        {
            Cmd_FreeAllocatedStringVector (commandArray);
            (void) chdir (tmpDir);
            (void) sprintf(errorMessage, errorFork, execHost);
            (void) _DtEnvControl (DT_ENV_RESTORE_POST_DT);
            return (_CMD_EXECUTE_FAILURE);
        }

        if (commandPid == 0)
        {

#if defined(__hp_osf) || defined(__osf__) || defined(CSRG_BASED)
            setsid() ;
#else
            (void) setpgrp ();
#endif

            if (!terminalRequest )
            {
                int fd;

                /*
                 * Close stdout and redirect it to /dev/null.  If this
                 * is not done and the request writes to stdout, the
                 * output will be queued in an "unlinked" file in
                 * /tmp until the client using this code terminates.
                 */
                if ((fd = open ("/dev/null", O_RDWR)) > 0)
                    (void) dup2 (fd, fileno (stdout));
            }

            /*
             * Mark file descriptiors >=3 as "Close on Exec".
             */
            {
                long	open_max;

                open_max = sysconf(_SC_OPEN_MAX);
                if (open_max == -1)
                {
#ifdef _SUN_OS
                    open_max = NOFILE;
#else
#if defined(USL) || defined(__uxp__) || defined(_AIX)
                    open_max = FOPEN_MAX;
#else
                    open_max = FD_SETSIZE;
#endif
#endif /* _SUN_OS */
                }

                for (i=3; i < open_max; i++)
                    (void) fcntl (i, F_SETFD, 1);
            }


            (void) execvp (commandArray[0], commandArray);

            /* Should never get here, but if you do, must exit */

            /*
             * The following message will be written to the errorlog
             * file if the request is not a terminal requests or
             * to the terminal window if the request requires a
             * terminal.
             */
            (void) sprintf (errorMessage, errorExec, commandArray[0]);
            (void) printf ("%s\n", errorMessage);
            (void) _exit (1);
        }

        /*
         * Restore the pre-fork environment.
         */
        (void) chdir (tmpDir);
        (void) _DtEnvControl (DT_ENV_RESTORE_POST_DT);
    }

    Cmd_FreeAllocatedStringVector (commandArray);

    return (_CMD_EXECUTE_SUCCESS);
}
Example #8
0
int
_DtSPCSpawn(
    char		*path,
    char		*cwd,
    char		**args,
    char		**env,
    SPC_Channel_Ptr	chan,
    char		*execHost,
    char		*contextHost,
    char		*contextDir,
    char		*errorMessage)
{
    int	retVal;

    /*
     * Restore the original environment
     */
    (void) _DtEnvControl (DT_ENV_RESTORE_PRE_DT);

    /*
     * Map some env var paths to execHost.
     */
    (void) _DtEnvMapForRemote(execHost);

    if ((retVal = XeSPCSpawn(path,
                             cwd,
                             args,
                             env,
                             chan)) == SPC_ERROR)
    {
        switch (DtSPCErrorNumber)
        {
        case SPC_cannot_Chdir:
            (void) sprintf (errorMessage,
                            errorChdir,
                            contextDir,
                            execHost);
            break;
        case SPC_Cannot_Fork:
            (void) sprintf (errorMessage,
                            errorFork,
                            execHost);
            break;
        case SPC_Env_Too_Big:
        case SPC_Arg_Too_Long:
            (void) sprintf (errorMessage,
                            errorLength,
                            SPC_BUFSIZ);
            break;
        default:
            /*
             * SPC_Cannot_Exec
             */
            (void) sprintf (errorMessage,
                            errorSpawn,
                            execHost,
                            path);
        }
    }

    /*
     * Restore some env var paths.
     */
    (void) _DtEnvRestoreLocal();

    /*
     * Restore the DT environment
     */
    (void) _DtEnvControl (DT_ENV_RESTORE_POST_DT);

    /*
     * Return the result of DtSPCSpawn
     */
    return retVal;
}
Example #9
0
int main(int argc, char **argv)
{
	int		cnt;
	char		*target = NULL, *date = NULL, *view = NULL,
			*uname, *loc;
	Props		*p = NULL;
	CSA_session_handle	c_handle;
	CSA_entry_handle	*list;
	CSA_return_code		stat;
	CSA_calendar_user	csa_user;
	int			version;
#ifdef FNS
	char		buf[256];
#endif

	init_time();
	_DtEnvControl(DT_ENV_SET); /* set up environment variables */
	setlocale(LC_ALL, "");
	DT_catd = catopen(DTCM_CAT, NL_CAT_LOCALE);
	cm_tty_load_props(&p);
	cm_args(argc,argv);		/* parse command line */

	target = (cm_strlen(cm_target)) ? cm_target : cm_get_credentials();
#ifdef FNS
	dtfns_init();
	if (cmfns_use_fns(p)) {
		cmfns_lookup_calendar(target, buf, sizeof(buf));
		target = buf;
	}
#endif
	uname = cm_target2name(target);
	loc = cm_target2location(target);

	csa_user.user_name = target;
	csa_user.user_type = 0;
	csa_user.calendar_user_extensions = NULL;
	csa_user.calendar_address = target;
	stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL);

	if (stat != CSA_SUCCESS) {
		char *format = cm_strdup(catgets(DT_catd, 1, 208, 
				   "\nCould not open calendar \"%s\"\n"));
		fprintf(stderr, format, 
			target ? target : catgets(DT_catd, 1, 209, "UNKNOWN"));
		free(format);
		free(uname);
		free(loc);
		exit(1);
	}
	version = get_data_version(c_handle);
	if (cm_strlen(cm_date)) date = cm_date;
	if (cm_strlen(cm_view)) view = cm_view;

	if ((cnt = cm_tty_lookup(DT_catd, c_handle, version, date, view, 
				 &list, p)) > 0)
		csa_free(list);
	csa_logoff(c_handle, NULL);
	props_clean_up(p);
	free(p);
	free(uname);
	free(loc);
	return 0;
}
Example #10
0
File: Main.c Project: juddy/edcde
int
main( 
     int argc,
     char **argv ) 
{
    Display *display;
    Arg args[20];
    int n=0;
    char *actionName;
    int numArgs = 0;
    DtActionArg *ap = NULL;
  
    XtSetLanguageProc(NULL, NULL, NULL);
    _DtEnvControl(DT_ENV_SET);
    (void) signal(SIGCHLD, (void (*)())SIG_IGN);

    /*  Initialize the toolkit and open the display  */
    XtToolkitInitialize() ;
    appContext = XtCreateApplicationContext() ;
    if ( !(display = XtOpenDisplay( appContext, NULL, argv[0], "Dtaction", 
                             option_list, 
			     sizeof(option_list)/sizeof(XrmOptionDescRec),
			     &argc, argv)) )
    {
	setlocale(LC_ALL, "");
        fprintf(stderr, "%s", GETMESSAGE(1,11,"Can't open display.\n"));
	exit(-1);
    }
  
    XtSetArg(args[n], XmNallowShellResize, True); n++;
    XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
    XtSetArg(args[n], XmNheight, 1); n++;
    XtSetArg(args[n], XmNwidth, 1); n++;
    toplevel = XtAppCreateShell( argv[0], "Dtaction", 
            topLevelShellWidgetClass, display, args, n) ;

    XtRealizeWidget(toplevel);

    display = XtDisplay (toplevel);
    XtGetApplicationResources(toplevel, &appArgs, 
	resources, XtNumber(resources), NULL, 0);

    password = XtMalloc(1);
    password[0] = '\0';
    stars = XtMalloc(1);
    stars[0] = '\0';

   /*  Get Dt initialized  */
   if (DtInitialize (display, toplevel, argv[0], "Dtaction") == False)
   {
      /* Fatal Error: could not connect to the messaging system. */
      /* DtInitialize() has already logged an appropriate error msg */
      exit(-1);
   }

   /*
    * If the request specified that it wanted to run as a different
    * user, then take care of prompting for a password, and doing any
    * necessary verification and logging.
    */
   CheckUserRequest();
   
   /* Load the filetype/action dbs; DtInvokeAction() requires this */
   DtDbLoad();

   /*
    * Get the requested action name
    */
    if ( (actionName = argv[1]) == NULL)
    {
	fprintf(stderr, "%s", GETMESSAGE(1,10,"No action name specified.\n"));
	exit(-1);
    }

    if ( argc > 2 ) 
    {
	/*
	 * create an action arg array for the file objects for
	 * this action.  This number of objects should be one
	 * less than the argument count. The returned vector will
	 * be terminated by a null pointer.
	 */
	numArgs= argc - 2;
	ap = (DtActionArg *) XtCalloc(numArgs,sizeof(DtActionArg)); 
    }

	/*
	 * This client is restricted to FILE arguments.
	 * for the time being.
	 */
    for ( n = 0; n < numArgs; n++) {
        ap[n].argClass    = DtACTION_FILE;
	ap[n].u.file.name = argv[n+2];
    }

    actionId = DtActionInvoke(toplevel, actionName, ap, numArgs,
        appArgs.termOpts,
        appArgs.execHost,
        appArgs.contextDir,
        True,			/* use indicator */
        (DtActionCallbackProc) actionStatusCallback,
        NULL);

    /*
     * Set up a timer if we didn't get a valid procId -- since there will
     * be no invocation update in that case.
     * We must invoke XtMainLoop() at least once, to force any prompt or
     * error dialogs to get posted.
     */
    if ( !actionId)
	    XtAppAddTimeOut(appContext,
		10, (XtTimerCallbackProc)CheckForDone,
			   NULL);

    XtAppMainLoop(appContext);

    return EXIT_SUCCESS;
}
Example #11
0
/*
 * ------------------------------------------------------------------------
 * Name: main
 *
 * Description:
 *
 *     main function for the DtPrint Dialog Manager.
 *
 * Return value:
 *
 *     This function never returns.
 *
 */
int main(int argc, char* argv[])
{
    PdmShell* pdm_shell;
    PdmMainWin* pdm_main_window;
    String* fallback_resources;
    int status;
    XEvent event;

    /*
     * Initialize environment so we can find message catalog.
     */
    _DtEnvControl(DT_ENV_SET);

    /*
     * ensure we can convert Xp attributes for this locale
     */
    if(!XSupportsLocale())
    {
	fprintf(stderr, "%s\n", PDM_MSG_ERR_X_LOCALE);
	exit(PDM_EXIT_ERROR);
    }
    /*
     * create the PDM objects for the app shell, the main window, and the
     * setup boxes
     */
    pdm_shell = PdmShellNew();
    pdm_main_window = PdmMainWinNew();
    PdmMainWinAddSetupBox(pdm_main_window, PdmPrinterBoxNew());
    PdmMainWinAddSetupBox(pdm_main_window, PdmJobBoxNew());
    /*
     * create the application shell widget
     */
    fallback_resources =
	PdmMainWinMergeFallbacks(pdm_main_window,
				 PdmShellFallbackResources,
				 XtNumber(PdmShellFallbackResources));
    status = PdmShellCreate(pdm_shell, fallback_resources, &argc, argv);
    if(0 != status)
    {
	PdmMainWinDelete(pdm_main_window);
	exit(status);
    }
    XtFree((char*)fallback_resources);
    /*
     * create the main PDM window widget hierarchy
     */
    PdmMainWinCreate(pdm_main_window,
		     pdm_shell->widget,
		     pdm_shell->print_display_spec,
		     pdm_shell->print_context_str);
    /*
     * display the PDM
     */
    PdmShellPresent(pdm_shell);
    /*
     * signal the PDM is up following startup event processing
     */
    XtAppAddWorkProc(pdm_shell->app_context,
		     PdmStartOkWorkProc, (XtPointer)NULL);
    /*
     * main loop
     */
    for(;;)
    {
	/*
	 * get the next event
	 */
	XtAppNextEvent(pdm_shell->app_context, &event);
	/*
	 * check to see if the parent video window has been destroyed
	 */
	if(event.xany.display == pdm_shell->display
	   &&
	   event.xany.window == pdm_shell->parent_window
	   &&
	   event.xany.type == DestroyNotify)
	{
	    PdmMainWinDelete(pdm_main_window);
	    exit(PDM_EXIT_CANCEL);
	}
	else
	    XtDispatchEvent(&event);
    }
    /*
     * not reached
     */
    return 0;
}
Example #12
0
pid_t
_DtTermPrimSubprocExec(Widget		  w,
		       char		 *ptyName,
		       Boolean		  consoleMode,
		       char		 *cwd,
		       char		 *cmd,
		       char		**argv,
		       Boolean		  loginShell)
{
    DtTermPrimitiveWidget tw = (DtTermPrimitiveWidget) w;
    static char *defaultCmd = (char *) 0;
    int i;
    int pty;
    pid_t pid;
    char *c;
    int err;
#ifdef	MOVE_FDS
    int saveFd[3];
#else	/* MOVE_FDS */
    int savedStderr;
#endif	/* MOVE_FDS */
    Boolean argvFree = False;
    struct sigaction sa;
    sigset_t ss;
    char buffer[BUFSIZ];
    Widget parent;
    char *namebuf;
    struct passwd * pw;
    _Xgetpwparams pw_buf;
    _Xgetloginparams login_buf;

#ifdef  ALPHA_ARCHITECTURE
    /* merge code from xterm, ignore so that TIOCSWINSZ doesn't block */
    signal(SIGTTOU, SIG_IGN);
#endif /* ALPHA_ARCHITECTURE */

    /* build a default exec command and argv list if one wasn't supplied...
     */
    /* cmd... */
    /* the command will be taken as follows:
     *	    - from the passed in cmd,
     *	    - from $SHELL,
     *	    - from the /etc/passwd entry for the /etc/utmp entry for this
     *        terminal,
     *	    - from the /etc/passwd entry for this userid, or
     *	    - /bin/sh.
     */
    if (!cmd || !*cmd) {
	if (!defaultCmd) {
	    /* from $SHELL... */
	    c = getenv("SHELL");

	    /* if not valid, try the /etc/passwd entry for the username
	     * associated with the /etc/utmp entry for this tty...
	     */
	    if (!c || !*c) {
		/* get the /etc/passwd entry for the username associated with
		 * /etc/utmp...
		 */
		if ((namebuf = _XGetlogin(login_buf)) != NULL) {
		    /* get the user's passwd entry... */
		    pw = _XGetpwnam(namebuf, pw_buf);
		    /* if we weren't able to come up with one for the
		     * username...
		     */
		    if (pw != NULL)
			c = pw->pw_shell;
		}
	    }

	    /* if not valid, try the /etc/passwd entry for the username
	     * associate with the real uid...
	     */
	    if (!c || !*c) {
		/* if we weren't able to come up with one for the userid... */
		pw = _XGetpwuid(getuid(), pw_buf);
		if (pw != NULL) {
		    c = pw->pw_shell;
		}
	    }

	    /* if not valid, use /bin/sh... */
	    if (!c || !*c) {
		c = DEFAULT_SHELL;
	    }

	    /* malloc space for this string.  It will be free'ed in the
	     * destroy function...
	     */
	    defaultCmd = XtMalloc(strlen(c) + 1);
	    (void) strcpy(defaultCmd, c);
	}

	cmd = defaultCmd;
    }

    if (!argv) {
	/* base it on cmd... */
	argv = (char **) XtMalloc(2 * sizeof(char *));
	/* if loginShell is set, then pre-pend a '-' to argv[0].  That's
	 * also why we allocate an extra byte in argv[0]...
	 */
	argv[0] = XtMalloc(strlen(cmd) + 2);
	*argv[0] = '\0';
	if (loginShell) {
	    /* pre-pend an '-' for loginShell... */
	    (void) strcat(argv[0], "-");
	    if (c = strrchr(cmd, '/')) {
		strcat(argv[0], ++c);
	    } else {
		strcat(argv[0], cmd);
	    }
	} else {
	    (void) strcat(argv[0], cmd);
	}
	/* null term the list... */
	argv[1] = (char *) 0;

	/* we will need to free it up later... */
	argvFree = True;
    }

#ifdef	OLDCODE
    /* this is left around from when we were using vfork().... */
    /* open the pty slave so that we can set the modes.
     *
     * NOTE: this code depends on support for the O_NOCTTY ioctl.  This
     *     ioctl allows us to open the device without becoming the
     *     session group leader for it.  If that can't be done, it may
     *     be necessary to rethink the way we open the pty slave...
     */
    if ((pty = open(ptyName, O_RDWR | O_NOCTTY, 0)) < 0) {
	(void) perror(ptyName);
	return((pid_t) -1);
    }
#endif	/* OLDCODE */

#ifdef	MOVE_FDS
    /* move fd[0:2] out of the way for now... */
    for (i = 0; i <= 2; i++) {
	saveFd[i] = fcntl(i, F_DUPFD, 3);
	(void) close(i);
    }
#else	/* MOVE_FDS */
    savedStderr = fcntl(2, F_DUPFD, 3);
#endif	/* MOVE_FDS */

    /* set close on exec flags on all files... */
    for (i = 0; i < _NFILE; i++) {
	(void) fcntl(i, F_SETFD, 1);
    }

    /* fork.  We can't use vfork() since we need to do lots of stuff
     * below...
     */
    if (isDebugSet('T')) {
#ifdef	BBA
#pragma BBA_IGNORE
#endif	/*BBA*/
	(void) timeStamp("about to fork()");
    }

    _DtTermProcessLock();
    for (i = 0; ((pid = FakeFork()) < 0) && (i < 10); i++) {
	/* if we are out of process slots, then let's sleep a bit and
	 * try again...
	 */
	if (errno != EAGAIN) {
	    break;
	}

	/* give it a chance to clear up... */
	(void) sleep((unsigned long) 2);
    }

    if (pid < 0) {
	(void) perror("fork()");
#ifdef	OLDCODE
	/* this is left around from when we were using vfork().... */
	(void) close(pty);
#endif	/* OLDCODE */
	return((pid_t) - 1);
    } else if (pid == 0) {
	/* child...
	 */
        _DtTermProcessUnlock();
#if defined(ALPHA_ARCHITECTURE) || defined(CSRG_BASED) || defined(LINUX_ARCHITECTURE)
        /* establish a new session for child */
        setsid();
#else
	/* do a setpgrp() so that we can... */
	(void) setpgrp();
#endif /* ALPHA_ARCHITECTURE */

#if defined(LINUX_ARCHITECTURE)
	/* set the ownership and mode of the pty... */
	(void) _DtTermPrimSetupPty(ptyName, pty);
#endif

	/* open the pty slave as our controlling terminal... */
	pty = open(ptyName, O_RDWR, 0);

	if (pty < 0) {
	    (void) perror(ptyName);
	    (void) _exit(1);
	}

#if defined(ALPHA_ARCHITECTURE) || defined(CSRG_BASED) || defined(LINUX_ARCHITECTURE)
        /* BSD needs to do this to acquire pty as controlling terminal */
        if (ioctl(pty, TIOCSCTTY, (char *)NULL) < 0) {
	    (void) close(pty);
	    (void) perror("Error acquiring pty slave as controlling terminal");
	    /* exit the subprocess */
	    _exit(1);
        }

        /* Do it when no controlling terminal doesn't work for OSF/1 */
        _DtTermPrimPtyGetDefaultModes();
#endif /* ALPHA_ARCHITECTURE */

#if !defined(LINUX_ARCHITECTURE)
	/* set the ownership and mode of the pty... */
	(void) _DtTermPrimSetupPty(ptyName, pty);
#endif /* LINUX_ARCHITECTURE */

	/* apply the ttyModes... */
	_DtTermPrimPtyInit(pty, tw->term.ttyModes, tw->term.csWidth);
	/* set the window size... */
	_DtTermPrimPtySetWindowSize(pty,
		tw->term.columns * tw->term.widthInc +
		(2 * (tw->primitive.shadow_thickness +
		      tw->primitive.highlight_thickness +
		      tw->term.marginWidth)),
		tw->term.rows * tw->term.heightInc +
		(2 * (tw->primitive.shadow_thickness +
		      tw->primitive.highlight_thickness +
		      tw->term.marginHeight)),
		tw->term.rows, tw->term.columns);

	/* if we are in console mode, turn it on... */
	if (consoleMode) {
	    _DtTermPrimPtyConsoleModeEnable(pty);
	}

#ifdef	MOVE_FDS
	/* that should have open'ed into fd 0.  Dup it into fd's 1 and 2... */
	(void) dup(pty);
	(void) dup(pty);
#else	/* MOVE_FDS */
	/* dup pty into fd's 0, 1, and 2... */
	for (i = 0; i < 3; i++) {
	    if (i != pty) {
		(void) close(i);
		(void) dup(pty);
	    }
	}
	if (pty >= 3) {
	    (void) close(pty);
	}
#endif	/* MOVE_FDS */

	/* reset any alarms... */
	(void) alarm(0);

	/* reset all signal handlers... */
	sa.sa_handler = SIG_DFL;
	(void) sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	for (i = 1; i < NSIG; i++) {
	    (void) sigaction(i, &sa, (struct sigaction *) 0);
	}

	/* unblock all signals... */
	(void) sigemptyset(&ss);
	(void) sigprocmask(SIG_SETMASK, &ss, (sigset_t *) 0);

	/*
	** Restore the original (pre-DT) environment, removing any
	** DT-specific environment variables that were added before
	** we...
	*/
#if defined(HPVUE)
#if       (OSMINORVERSION > 01)
	(void) VuEnvControl(VUE_ENV_RESTORE_PRE_VUE);
#endif /* (OSMINORVERSION > 01) */
#else   /* (HPVUE) */  
	(void) _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
#endif  /* (HPVUE) */  
            
	/*
	** set a few environment variables of our own...
	*/
	for (parent = w; !XtIsShell(parent); parent = XtParent(parent))
	    ;
	(void) sprintf(buffer, "%ld", XtWindow(parent));
	_DtTermPrimPutEnv("WINDOWID=", buffer);
	_DtTermPrimPutEnv("DISPLAY=", XDisplayString(XtDisplay(w)));
	if (((DtTermPrimitiveWidget)w)->term.emulationId) {
	    _DtTermPrimPutEnv("TERMINAL_EMULATOR=",
			      ((DtTermPrimitiveWidget)w)->term.emulationId);
	}
		 
	/* set our utmp entry... */
	(void) _DtTermPrimUtmpEntryCreate(w, getpid(),
		((DtTermPrimitiveWidget)w)->term.tpd->utmpId);

	if (isDebugSet('T')) {
#ifdef	BBA
#pragma BBA_IGNORE
#endif	/*BBA*/
	    (void) timeStamp("about to execvp()");
	}

	/* turn off suid forever...
	 */
	_DtTermPrimRemoveSuidRoot();

	/* change to the requested directory... */
	if (cwd && *cwd) {
	    (void) chdir(cwd);
	}

#ifdef	BBA
	_bA_dump();
#endif	/* BBA */
	_DtEnvControl(DT_ENV_RESTORE_PRE_DT);
	(void) execvp(cmd, argv);
	/* if we got to this point we error'ed out.  Let's write out the
	 * error...
	 */
	err = errno;
	/* restore stderr... */
	(void) close(2);
	(void) dup(savedStderr);
	/* restore errno... */
	errno = err;
	(void) perror(cmd);
	/* and we need to exit the subprocess... */
	_exit(1);
    }

    /* parent...
     */
    _DtTermProcessUnlock();
    if (isDebugSet('T')) {
#ifdef	BBA
#pragma BBA_IGNORE
#endif	/*BBA*/
	(void) timeStamp("parent resuming");
    }
#ifdef	MOVE_FDS
    /* DKS: we should check this out and see if it is necessary... */
    (void) close(0);
    (void) close(1);
    (void) close(2);
    /* move fd[0:2] back in place... */
    for (i = 0; i <= 2; i++) {
	if (saveFd[i] >= 0) { 
	    (void) fcntl(saveFd[i], F_DUPFD, i);
	    (void) close(saveFd[i]);
	}
    }
#else	/* MOVE_FDS */
    (void) close(savedStderr);
#endif	/* MOVE_FDS */

    /* clean up malloc'ed memory... */
    if (argvFree) {
	(void) XtFree(argv[0]);
	(void) XtFree((char *) argv);
    }

#ifdef	OLDCODE
    /* since we no longer open it in the parent, we probably don't want
     * to close it either...
     */
    (void) close(pty);
#endif	/* OLDCODE */

    /* assume that our child set up a utmp entry (since we have no way
     * for it to report to us) and add it to the list to cleanup)...
     */
    _DtTermPrimUtmpAddEntry(((DtTermPrimitiveWidget)w)->term.tpd->utmpId);

    return(pid);
}