VirtualBox

Ignore:
Timestamp:
May 27, 2021 1:38:13 PM (4 years ago)
Author:
vboxsync
Message:

VBoxAutostart: bugref:9341: Create "VBoxAutostart.log" release log
file in the user's vbox home directory.

Don't bother with --log* options like the posix counterpart has b/c
the user cannot change them easily anyway and is better off using
environment variables if need be.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostart-win.cpp

    r85121 r89319  
    3939#include <VBox/version.h>
    4040
     41#include <iprt/dir.h>
    4142#include <iprt/env.h>
    4243#include <iprt/errcore.h>
     
    8081/** The service name is used for send to service main. */
    8182static com::Bstr g_bstrServiceName;
     83
     84/** Logging parameters. */
     85static uint32_t      g_cHistory = 10;                   /* Enable log rotation, 10 files. */
     86static uint32_t      g_uHistoryFileTime = 0;            /* No time limit, it's very low volume. */
     87static uint64_t      g_uHistoryFileSize = 100 * _1M;    /* Max 100MB per file. */
    8288
    8389
     
    289295    AssertMsg(fRc, ("%u\n", GetLastError())); NOREF(fRc);
    290296    DeregisterEventSource(hEventLog);
     297
     298    /* write it to the release log too */
     299    LogRel(("%s", pszMsg));
    291300}
    292301
     
    979988static int autostartSvcWinRunIt(int argc, char **argv)
    980989{
     990    int rc;
     991
    981992    LogFlowFuncEnter();
    982993
    983994    /*
    984      * Initialize release logging.
     995     * Initialize release logging, do this early.  This means command
     996     * line options (like --logfile &c) can't be introduced to affect
     997     * the log file parameters, but the user can't change them easily
     998     * anyway and is better off using environment variables.
    985999     */
    986     /** @todo release logging of the system-wide service. */
     1000    do
     1001    {
     1002        char szLogFile[RTPATH_MAX];
     1003        rc = com::GetVBoxUserHomeDirectory(szLogFile, sizeof(szLogFile),
     1004                                           /* :fCreateDir */ false);
     1005        if (RT_FAILURE(rc))
     1006        {
     1007            autostartSvcLogError("Failed to get VirtualBox user home directory: %Rrc\n", rc);
     1008            break;
     1009        }
     1010
     1011        if (!RTDirExists(szLogFile)) /* vbox user home dir */
     1012        {
     1013            autostartSvcLogError("%s doesn't exist\n", szLogFile);
     1014            break;
     1015        }
     1016
     1017        rc = RTPathAppend(szLogFile, sizeof(szLogFile), "VBoxAutostart.log");
     1018        if (RT_FAILURE(rc))
     1019        {
     1020            autostartSvcLogError("Failed to construct release log file name: %Rrc\n", rc);
     1021            break;
     1022        }
     1023
     1024        rc = com::VBoxLogRelCreate("Autostart",
     1025                                   szLogFile,
     1026                                     RTLOGFLAGS_PREFIX_THREAD
     1027                                   | RTLOGFLAGS_PREFIX_TIME_PROG,
     1028                                   "all",
     1029                                   "VBOXAUTOSTART_RELEASE_LOG",
     1030                                   RTLOGDEST_FILE,
     1031                                   UINT32_MAX /* cMaxEntriesPerGroup */,
     1032                                   g_cHistory,
     1033                                   g_uHistoryFileTime,
     1034                                   g_uHistoryFileSize,
     1035                                   NULL);
     1036        if (RT_FAILURE(rc))
     1037            autostartSvcLogError("Failed to create release log file: %Rrc\n", rc);
     1038    } while (0);
     1039
     1040
    9871041
    9881042    /*
     
    10151069                }
    10161070                break;
     1071
    10171072            default:
    1018                 return autostartSvcDisplayGetOptError("runit", ch, &Value);
     1073                /**
     1074                 * @todo autostartSvcLogGetOptError is useless as it
     1075                 * is, should be change after RTGetOptPrintError.
     1076                 */
     1077                return autostartSvcLogError("RTGetOpt: %Rrc\n", ch);
    10191078        }
    10201079    }
     
    10251084        return RTEXITCODE_FAILURE;
    10261085    }
     1086
     1087    LogRel(("Starting service %ls\n", g_bstrServiceName.raw()));
    10271088
    10281089    /*
Note: See TracChangeset for help on using the changeset viewer.

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