VirtualBox

Changeset 45859 in vbox for trunk/src/VBox/Additions/linux


Ignore:
Timestamp:
May 1, 2013 8:40:06 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
85446
Message:

lightdm-greeter: Proper termination on SIGTERM, improved logging.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/linux/lightdm-greeter/vbox-greeter.cpp

    r45521 r45859  
    6161#include <iprt/system.h>
    6262#include <iprt/string.h>
     63#include <iprt/thread.h>
    6364#include <iprt/time.h>
    6465
     
    108109 static int          g_iVerbosity = 0;
    109110#endif
     111static bool          g_fRunning   = true;
    110112
    111113/** Logging parameters. */
     
    354356    AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
    355357
     358    static bool s_fCredsNotFoundMsgShown = false;
    356359    int rc = VbglR3CredentialsQueryAvailability();
    357360    if (RT_FAILURE(rc))
     
    359362        if (rc != VERR_NOT_FOUND)
    360363            vboxGreeterError("vboxGreeterCheckCreds: could not query for credentials! rc=%Rrc. Aborting\n", rc);
    361 #ifdef DEBUG
    362         else
     364        else if (!s_fCredsNotFoundMsgShown)
     365        {
    363366            vboxGreeterLog("vboxGreeterCheckCreds: no credentials available\n");
    364 #endif
     367            s_fCredsNotFoundMsgShown = true;
     368        }
    365369    }
    366370    else
     
    375379        else
    376380        {
     381            vboxGreeterLog("vboxGreeterCheckCreds: credentials retrieved: user=%s, password=%s\n",
     382                           pszUsername,
    377383#ifdef DEBUG
    378             vboxGreeterLog("vboxGreeterCheckCreds: credentials retrieved: user=%s, password=%s\n",
    379                            pszUsername, pCtx->pszPassword);
    380 #else
    381             /* Don't log passwords in release mode! */
    382             vboxGreeterLog("vboxGreeterCheckCreds: credentials retrieved: user=%s, password=XXX\n",
    383                            pszUsername);
     384                           pCtx->pszPassword);
     385#else
     386                           "XXX");
    384387#endif
    385388            /* Trigger LightDM authentication with the user name just retrieved. */
     
    405408static void cb_sigterm(int signum)
    406409{
    407     vboxGreeterLog("received SIGTERM (%d), exiting\n", signum);
    408 
     410    /* Note: This handler must be reentrant-safe. */
     411#ifdef VBOX_WITH_FLTK
     412    g_fRunning = false;
     413#else
    409414    exit(RTEXITCODE_SUCCESS);
     415#endif
    410416}
    411417
     
    422428                                   gpointer pvData)
    423429{
    424     vboxGreeterLog("cb_lightdm_show_prompt: %s (%d)\n", pszText, enmType);
     430    vboxGreeterLog("cb_lightdm_show_prompt: text=%s, type=%d\n", pszText, enmType);
    425431
    426432    PVBOXGREETERCTX pCtx = (PVBOXGREETERCTX)pvData;
     
    472478                                    gpointer pvData)
    473479{
    474     vboxGreeterLog("cb_lightdm_show_message: %s (%d)\n", pszText, enmType);
     480    vboxGreeterLog("cb_lightdm_show_message: text=%s, type=%d\n", pszText, enmType);
    475481
    476482    PVBOXGREETERCTX pCtx = (PVBOXGREETERCTX)pvData;
    477     AssertPtr(pCtx);
     483    AssertPtrReturnVoid(pCtx);
    478484
    479485#ifdef VBOX_WITH_FLTK
     
    509515            if (!lightdm_greeter_start_session_sync(pGreeter, pszSession, &pError))
    510516            {
    511                 vboxGreeterError("unable to start session '%s': %s\n", 
     517                vboxGreeterError("unable to start session '%s': %s\n",
    512518                                 pszSession, pError ? pError->message : "Unknown error");
    513519            }
     
    559565
    560566    /** @todo Add domain handling? */
    561 #ifdef DEBUG
    562     vboxGreeterLog("login requested: greeter=%p, user=%s, password=%s\n",
     567    vboxGreeterLog("login button pressed: greeter=%p, user=%s, password=%s\n",
    563568                   pCtx->pGreeter,
    564569                   pszUser ? pszUser : "<NONE>",
     570#ifdef DEBUG
    565571                   pszPwd ? pszPwd : "<NONE>");
    566 #endif
    567 
    568     lightdm_greeter_respond(pCtx->pGreeter, pszPwd);
    569     lightdm_greeter_authenticate(pCtx->pGreeter, pszUser);
     572#else
     573                   /* Don't log passwords in release mode! */
     574                   "XXX");
     575#endif
     576    if (strlen(pszUser)) /* Only authenticate if username is given. */
     577    {
     578        lightdm_greeter_respond(pCtx->pGreeter, pszPwd);
     579        lightdm_greeter_authenticate(pCtx->pGreeter, pszUser);
     580    }
    570581}
    571582
     
    582593#endif
    583594{
    584 
     595    vboxGreeterLog("menu button pressed\n");
    585596}
    586597
     
    597608#endif
    598609{
     610    vboxGreeterLog("restart button pressed\n");
     611
    599612    bool fRestart = true;
    600613#ifdef VBOX_WITH_FLTK
     
    624637#endif
    625638{
     639    vboxGreeterLog("shutdown button pressed\n");
     640
    626641    bool fShutdown = true;
    627642#ifdef VBOX_WITH_FLTK
     
    706721        {
    707722            case VINF_SUCCESS:
    708 #ifdef DEBUG
     723# ifdef DEBUG
    709724                vboxGreeterLog("cb_check_creds: tsAbort %RU64 <-> %RU64\n",
    710725                               pCtx->uTsAbort, tsAbort);
    711 #endif
     726# endif
    712727                if (tsAbort != pCtx->uTsAbort)
    713728                    fAbort = true; /* Timestamps differs, abort. */
     
    744759        AssertPtr(pCtx->pLblInfo);
    745760        pCtx->pLblInfo->copy_label(szVal);
    746 # else
     761# else /* !VBOX_WITH_FLTK */
    747762        GtkLabel *pLblInfo = GTK_LABEL(gtk_builder_get_object(pCtx->pBuilder, VBOX_GREETER_UI_LBL_INFO));
    748763        AssertPtr(pLblInfo);
    749764        gtk_label_set_text(pLblInfo, szVal);
    750 # endif /* VBOX_WITH_FLTK */
     765# endif /* !VBOX_WITH_FLTK */
    751766        vboxGreeterLog("cb_check_creds: got notification from host to abort waiting\n");
    752767    }
     
    793808# endif
    794809#endif /* VBOX_WITH_GUEST_PROPS */
    795             vboxGreeterLog("cb_check_creds: waiting thread has reached timeout (%dms), exiting ...\n",
     810            vboxGreeterLog("cb_check_creds: no credentials retrieved within time (%RU32ms), giving up\n",
    796811                           pCtx->uTimeoutMS);
    797812            rc = VERR_TIMEOUT;
     
    10251040                     | VBOX_GREETER_UI_SHOW_SHUTDOWN;
    10261041#ifdef VBOX_WITH_GUEST_PROPS
    1027     uint32_t uClientId;
     1042    uint32_t uClientId = 0;
    10281043    rc = VbglR3GuestPropConnect(&uClientId);
    10291044    if (RT_SUCCESS(rc))
     
    11371152        }
    11381153    }
     1154    else
     1155        vboxGreeterError("unable to connect to guest property service, rc=%Rrc\n", rc);
    11391156#endif
    11401157    vboxGreeterLog("UI options are: %RU32\n", uOptsUI);
     
    12791296
    12801297    pWndGreeter->show();
    1281 #else
     1298#else /* !VBOX_WITH_FLTK */
    12821299    gtk_init(&argc, &argv);
    12831300
     
    13201337
    13211338    g_clear_error(&pError);
    1322 #endif
     1339#endif /* !VBOX_WITH_FLTK */
    13231340
    13241341    /* GType is needed in any case (for LightDM), whether we
     
    13481365#ifdef VBOX_WITH_GUEST_PROPS
    13491366    bool fCheckCreds = false;
    1350     if (uClientId)
     1367    if (uClientId) /* Connected to guest property service? */
    13511368    {
    13521369        char szVal[256];
    1353         rc = vbox_read_prop(uClientId,
    1354                             "/VirtualBox/GuestAdd/PAM/CredsWait",
    1355                             true /* Read-only on guest */,
     1370        rc2 = vbox_read_prop(uClientId,
     1371                             "/VirtualBox/GuestAdd/PAM/CredsWait",
     1372                             true /* Read-only on guest */,
    13561373                            szVal, sizeof(szVal), NULL /* Timestamp. */);
    1357         if (RT_SUCCESS(rc))
    1358         {
    1359             /* All calls which are checked against rc2 are not critical, e.g. it does
    1360              * not matter if they succeed or not. */
     1374        if (RT_SUCCESS(rc2))
     1375        {
    13611376            uint32_t uTimeoutMS = RT_INDEFINITE_WAIT; /* Wait infinite by default. */
    13621377            rc2 = vbox_read_prop(uClientId,
     
    13841399            if (RT_SUCCESS(rc2))
    13851400            {
    1386 #ifdef VBOX_WITH_FLTK
     1401# ifdef VBOX_WITH_FLTK
    13871402                Assert(pLblInfo);
    13881403                pLblInfo->copy_label(szVal);
    1389 #else
     1404# else
    13901405                gtk_label_set_text(pLblInfo, szVal);
    1391 #endif
     1406# endif
    13921407            }
    13931408
     
    14161431        /* Start the timer to check credentials availability. */
    14171432        if (fCheckCreds)
    1418 #ifdef VBOX_WITH_FLTK
     1433        {
     1434            vboxGreeterLog("No credentials available on startup, starting to check periodically ...\n");
     1435# ifdef VBOX_WITH_FLTK
    14191436            Fl::add_timeout(0.5 /* 500 ms */, cb_check_creds, &ctx);
    1420 #else
     1437# else
    14211438            g_timeout_add(500 /* ms */, (GSourceFunc)cb_check_creds, &ctx);
    1422 #endif
     1439# endif
     1440        }
    14231441    }
    14241442#endif /* VBOX_WITH_GUEST_PROPS */
     
    14321450    AssertPtr(pMainCtx);
    14331451
    1434     for (;;)
     1452    while (g_fRunning)
    14351453    {
    14361454        g_main_context_iteration(pMainCtx,
    14371455                                 FALSE /* No blocking */);
    14381456        Fl::check();
    1439         /** @todo Abort condition? */
    1440     }
    1441 
    1442     /** @todo Never reached so far. */
     1457        RTThreadYield();
     1458    }
     1459
    14431460    g_main_context_unref(pMainCtx);
    14441461
     
    14501467    }
    14511468# endif /* VBOX_GREETER_WITH_PNG_SUPPORT */
    1452 #else
     1469#else /* !VBOX_WITH_FLTK */
    14531470    gtk_main();
    1454 #endif
     1471    /** @todo Never reached so far. LightDM sends a SIGTERM. */
     1472#endif /* !VBOX_WITH_FLTK */
    14551473
    14561474    vboxGreeterLog("terminating\n");
    14571475
    1458     rc2 = VbglR3GuestPropDisconnect(uClientId);
    1459     AssertRC(rc2);
     1476#ifdef VBOX_WITH_GUEST_PROPS
     1477    if (uClientId)
     1478    {
     1479        rc2 = VbglR3GuestPropDisconnect(uClientId);
     1480        AssertRC(rc2);
     1481    }
     1482#endif /* VBOX_WITH_GUEST_PROPS */
    14601483
    14611484    VbglR3Term();
    14621485
    1463     vboxGreeterLog("terminated with rc=%Rrc\n", rc);
     1486    RTEXITCODE rcExit = RT_SUCCESS(rc)
     1487                      ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     1488
     1489    vboxGreeterLog("terminated with exit code %ld (rc=%Rrc)\n",
     1490                   rcExit, rc);
    14641491
    14651492    vboxGreeterLogDestroy();
    14661493
    1467     return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     1494    return rcExit;
    14681495}
    14691496
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette