示例#1
0
文件: main.c 项目: Marnie86/storaged
int
main(int argc, char **argv)
{
    bool retVal;
    int opt;
    bool invertCarrier = false;

    LSPalmService * lsps = NULL;

    while ((opt = getopt(argc, argv, "chdst")) != -1)
    {
        switch (opt) {
        case 'c':
            invertCarrier = true;
            break;
        case 'd':
            setLogLevel(G_LOG_LEVEL_DEBUG);
            break;
        case 's':
            setUseSyslog(true);
            break;
        case 'h':
        default:
            PrintUsage(argv[0]);
            return EXIT_SUCCESS;
        }
    }

	// make sure we aren't already running.  
	if (!LockProcess("storaged")) {
		g_error("%s: %s daemon is already running.\n", __func__, argv[0]);
		exit(EXIT_FAILURE);
	}


    g_log_set_default_handler(logFilter, NULL);
    g_debug( "entering %s in %s", __func__, __FILE__ );

    signal(SIGTERM, term_handler);

    g_mainloop = g_main_loop_new(NULL, FALSE);


 	int ret = nyx_device_open(NYX_DEVICE_SYSTEM, "Main", &nyxSystem);
 	if(ret != NYX_ERROR_NONE)
 	{
 		g_critical("Unable to open the nyx device system");
 		abort();
 	}
 	else
 		g_debug("Initialized nyx system device");

    /**
     *  initialize the lunaservice and we want it before all the init
     *  stuff happening.
     */
    LSError lserror;
    LSErrorInit(&lserror);

    retVal = LSRegisterPalmService("com.palm.storage", &lsps, &lserror);
    if (!retVal)
    {
        g_critical ("failed in function %s with erro %s", lserror.func, lserror.message);
        LSErrorFree(&lserror);
        return EXIT_FAILURE;
    }

    SignalsInit( lsps );

    LSHandle *lsh_priv = LSPalmServiceGetPrivateConnection(lsps);
    LSHandle *lsh_pub = LSPalmServiceGetPublicConnection(lsps);

    DiskModeInterfaceInit( g_mainloop, lsh_priv, lsh_pub, invertCarrier );
    EraseInit(g_mainloop, lsh_priv);

    retVal = LSGmainAttach( lsh_priv, g_mainloop, &lserror ); 
    if ( !retVal )
    {
        g_critical( "LSGmainAttach private returned %s", lserror.message );
        LSErrorFree(&lserror);
    }
    retVal = LSGmainAttach( lsh_pub, g_mainloop, &lserror ); 
    if ( !retVal )
    {
        g_critical( "LSGmainAttach public returned %s", lserror.message );
        LSErrorFree(&lserror);
    }
    g_main_loop_run(g_mainloop);
    g_main_loop_unref(g_mainloop);

    if (!LSUnregister( lsh_priv, &lserror)) {
        g_critical( "LSUnregister private returned %s", lserror.message );
    }
    if (!LSUnregister( lsh_pub, &lserror)) {
        g_critical( "LSUnregister public returned %s", lserror.message );
    }

	UnlockProcess();

    g_debug( "exiting %s in %s", __func__, __FILE__ );

    if (!retVal)
        return EXIT_FAILURE;
    else
        return EXIT_SUCCESS;
}
示例#2
0
文件: debug.c 项目: Gaikokujin/WinNT4
BOOL xxxActivateDebugger(
    UINT fsModifiers)
{
    ULONG ArgLength;
    USER_API_MSG m;
    PACTIVATEDEBUGGERMSG a = &m.u.ActivateDebugger;
    PEPROCESS Process;
    HANDLE hDebugPort;
    NTSTATUS Status;

    if (fsModifiers & MOD_CONTROL) {
#ifdef DEBUG
        if (RipOutput(0, RIP_WARNING, "User debugger", 0, "Debug prompt", NULL)) {
            DbgBreakPoint();
        }
#endif
        return FALSE;
    } else if (fsModifiers & MOD_SHIFT) {

        /*
         * Bail out if the process is not being debugged.
         */
        if (gpepCSRSS->DebugPort == NULL)
            return FALSE;

        a->ClientId.UniqueProcess = gpepCSRSS->UniqueProcessId;
    } else {

        if ((gpqForeground == NULL) || (gpqForeground->ptiKeyboard == NULL))
            return FALSE;

        a->ClientId = gpqForeground->ptiKeyboard->Thread->Cid;

        /*
         * Bail out if the process is not being debugged.
         */
        if (!NT_SUCCESS(LockProcessByClientId(a->ClientId.UniqueProcess,
                &Process)))
            return FALSE;
        hDebugPort = Process->DebugPort;
        UnlockProcess(Process);

        if (hDebugPort == NULL)
            return FALSE;
    }

    /*
     * Send the datagram to CSR
     */
    if (CsrApiPort != NULL) {
        ArgLength = sizeof(*a);
        ArgLength |= (ArgLength << 16);
        ArgLength +=     ((sizeof( CSR_API_MSG ) - sizeof( m.u )) << 16) |
                        (FIELD_OFFSET( CSR_API_MSG, u ) - sizeof( m.h ));
        m.h.u1.Length = ArgLength;
        m.h.u2.ZeroInit = 0;
        m.CaptureBuffer = NULL;
        m.ApiNumber = CSR_MAKE_API_NUMBER( USERSRV_SERVERDLL_INDEX,
                                           UserpActivateDebugger);
        LeaveCrit();
        Status = LpcRequestPort(CsrApiPort, (PPORT_MESSAGE)&m);
        EnterCrit();
        UserAssert(NT_SUCCESS(Status));
    }

    /*
     * Don't eat this event unless we are breaking into CSR! Since we have
     * choosen an arbitrary hot key like F12 for the debug key, we need to
     * pass on the key to the application, or apps that want this key would
     * never see it. If we had an api for installing a debug hot key
     * (export or MOD_DEBUG flag to RegisterHotKey()), then it would be ok
     * to eat because the user selected the hot key. But it is not ok to
     * eat it as long as we've picked an arbitrary hot key. scottlu.
     */
    if (fsModifiers & MOD_SHIFT)
        return TRUE;
    else
        return FALSE;
}