Esempio n. 1
0
AROS_UFH3(static LONG, __detach_trampoline,
AROS_UFHA(char *,argstr,A0),
AROS_UFHA(ULONG,argsize,D0),
AROS_UFHA(struct ExecBase *,SysBase,A6))
{
    AROS_USERFUNC_INIT
    
    LONG retval;
      
    D(bug("Entering __detach_trampoline(\"%s\", %d, %x)\n", argstr, argsize, SysBase));

    /* The program has two options: either take care of telling the detacher
       process when exactly to go away, via the Detach() function, or let this
       startup code take care of it. If __detached_manages_detach is TRUE, then
       the detached process handles it, otherwise we handle it.  */
    
    if (!__detached_manages_detach)
       __Detach(RETURN_OK);

    __startup_entries_next();
    
    /* At this point the detacher process might still be around, 
      If the program forgot to detach, or if it couldn't, but in any
      case we need to tell the detacher to go away.  */
    __Detach(retval);
    
    D(bug("Leaving __detach_trampoline\n"));

    return 0;	  
    
    AROS_USERFUNC_EXIT
}
Esempio n. 2
0
static void __initcommandline(struct ExecBase *SysBase)
{
    char *ptr    = NULL;

    if (WBenchMsg || __nocommandline) {
        __startup_entries_next();
        return;
    }

    if (__argsize)
    {
        ULONG size;

        /* Copy args into buffer */
    	if (!(__args = AllocMem(__argsize+1, MEMF_ANY)))
	    return;

    	ptr = __args;
    	size= __argsize;
    	while (size--)
    	    *ptr++ = *__argstr++;
    	*ptr = 0;

    	/* Find out how many arguments we have */
	process_cmdline(&__argmax, __args, NULL);

	if (!(__argv = AllocMem (sizeof (char *) * (__argmax+1), MEMF_ANY | MEMF_CLEAR)) )
	    return;

	D(bug("arg(%d)=\"%s\", argmax=%d\n", __argsize, __args, __argmax));

	/* create argv */
	process_cmdline(&__argc, __args, __argv);
    }
    else
    {
	__argmax = 1;
	__argc = 1;
	if (!(__argv = AllocMem (sizeof (char *)*2, MEMF_CLEAR | MEMF_ANY)))
	    return;
    }

    /*
     * get program name
     */
     __argv[0] = __get_command_name();

#if DEBUG /* Debug argument parsing */

    kprintf("argc = %d\n", __argc);
    {
	int t;
	for (t=0; t<__argc; t++)
	    kprintf("argv[%d] = \"%s\"\n", t, __argv[t]);
    }

#endif

    __startup_entries_next();

    if (WBenchMsg != NULL)
        return;

    if (__argv)
	FreeMem(__argv, sizeof (char *) * (__argmax+1));

    if (__args)
	FreeMem(__args, __argsize+1);
}
Esempio n. 3
0
static void __startup_detach(void)
{
    struct CommandLineInterface *cli;
    struct Process              *newproc;
    BPTR                         mysegment = NULL;
    STRPTR                       detached_name;

    D(bug("Entering __startup_detach(\"%s\", %d, %x)\n", argstr, argsize, SysBase));

    cli = Cli();
    /* Without a CLI detaching makes no sense, just jump to
       the real program.  */
    if (!cli)
    {
        __startup_entries_next();
    }  
    else
    {
        mysegment = cli->cli_Module;
        cli->cli_Module = NULL;

        detached_name = __detached_name ? __detached_name : (STRPTR)FindTask(NULL)->tc_Node.ln_Name;
    
        {
            struct TagItem tags[] =
            {
                { NP_Seglist,   (IPTR)mysegment            },
                { NP_Entry,     (IPTR)&__detach_trampoline },
                { NP_Name,      (IPTR)detached_name        },
                { NP_Arguments, (IPTR)__argstr             },
                { NP_Cli,       TRUE                       },
                { TAG_DONE,     0                          }
            };

            __detacher_process = (struct Process *)FindTask(NULL);

            /* CreateNewProc() will take care of freeing the seglist */
            newproc = CreateNewProc(tags);
        }

        if (!newproc)
        {
            cli->cli_Module = mysegment;
            __detached_return_value = RETURN_ERROR;
        }
        else
            while (!__detacher_go_away) Wait(SIGF_SINGLE);

        if (__detached_return_value != RETURN_OK)
        {
            PutStr(FindTask(NULL)->tc_Node.ln_Name); PutStr(": Failed to detach.\n");
        }
    
        if (newproc)
        {
            Forbid();
            Signal(&newproc->pr_Task, SIGF_SINGLE);
        }

        __aros_startup.as_startup_error = __detached_return_value;
    }

    D(bug("Leaving __startup_detach\n"));
}