1 | /* $Id: SUPLoggerCtl.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * SUPLoggerCtl - Support Driver Logger Control.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #include <VBox/sup.h>
|
---|
32 | #include <iprt/buildconfig.h>
|
---|
33 | #include <iprt/initterm.h>
|
---|
34 | #include <iprt/getopt.h>
|
---|
35 | #include <iprt/stream.h>
|
---|
36 | #include <iprt/string.h>
|
---|
37 | #include <iprt/ctype.h>
|
---|
38 | #include <iprt/errcore.h>
|
---|
39 |
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Prints the usage.
|
---|
43 | * @returns 1.
|
---|
44 | */
|
---|
45 | static int usage(void)
|
---|
46 | {
|
---|
47 | RTPrintf("usage: SUPLoggerCtl [-f|--flags <flags-settings>] \\\n"
|
---|
48 | " [-g|--groups <groups-settings>] \\\n"
|
---|
49 | " [-d|--dest <destination-specifiers>] \\\n"
|
---|
50 | " [-l|--which <release|debug>] \\\n"
|
---|
51 | " [-o|--what <set|create|destroy>]\n"
|
---|
52 | " or: SUPLoggerCtl <-h|--help>\n"
|
---|
53 | "\n"
|
---|
54 | );
|
---|
55 | return 1;
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | int main(int argc, char **argv)
|
---|
60 | {
|
---|
61 | RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_TRY_SUPLIB);
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * Options are mandatory.
|
---|
65 | */
|
---|
66 | if (argc <= 1)
|
---|
67 | return usage();
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * Parse the options.
|
---|
71 | */
|
---|
72 | static const RTGETOPTDEF s_aOptions[] =
|
---|
73 | {
|
---|
74 | { "--flags", 'f', RTGETOPT_REQ_STRING },
|
---|
75 | { "--groups", 'g', RTGETOPT_REQ_STRING },
|
---|
76 | { "--dest", 'd', RTGETOPT_REQ_STRING },
|
---|
77 | { "--what", 'o', RTGETOPT_REQ_STRING },
|
---|
78 | { "--which", 'l', RTGETOPT_REQ_STRING },
|
---|
79 | };
|
---|
80 |
|
---|
81 | const char *pszFlags = "";
|
---|
82 | const char *pszGroups = "";
|
---|
83 | const char *pszDest = "";
|
---|
84 | SUPLOGGER enmWhich = SUPLOGGER_DEBUG;
|
---|
85 | enum
|
---|
86 | {
|
---|
87 | kSupLoggerCtl_Set, kSupLoggerCtl_Create, kSupLoggerCtl_Destroy
|
---|
88 | } enmWhat = kSupLoggerCtl_Set;
|
---|
89 |
|
---|
90 | int ch;
|
---|
91 | RTGETOPTUNION Val;
|
---|
92 | RTGETOPTSTATE GetState;
|
---|
93 | RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
|
---|
94 | while ((ch = RTGetOpt(&GetState, &Val)))
|
---|
95 | {
|
---|
96 | switch (ch)
|
---|
97 | {
|
---|
98 | case 'f':
|
---|
99 | pszFlags = Val.psz;
|
---|
100 | break;
|
---|
101 |
|
---|
102 | case 'g':
|
---|
103 | pszGroups = Val.psz;
|
---|
104 | break;
|
---|
105 |
|
---|
106 | case 'd':
|
---|
107 | pszDest = Val.psz;
|
---|
108 | break;
|
---|
109 |
|
---|
110 | case 'o':
|
---|
111 | if (!strcmp(Val.psz, "set"))
|
---|
112 | enmWhat = kSupLoggerCtl_Set;
|
---|
113 | else if (!strcmp(Val.psz, "create"))
|
---|
114 | enmWhat = kSupLoggerCtl_Create;
|
---|
115 | else if (!strcmp(Val.psz, "destroy"))
|
---|
116 | enmWhat = kSupLoggerCtl_Destroy;
|
---|
117 | else
|
---|
118 | {
|
---|
119 | RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unknown operation '%s'.\n", Val.psz);
|
---|
120 | return 1;
|
---|
121 | }
|
---|
122 | break;
|
---|
123 |
|
---|
124 | case 'l':
|
---|
125 | if (!strcmp(Val.psz, "debug"))
|
---|
126 | enmWhich = SUPLOGGER_DEBUG;
|
---|
127 | else if (!strcmp(Val.psz, "release"))
|
---|
128 | enmWhich = SUPLOGGER_RELEASE;
|
---|
129 | else
|
---|
130 | {
|
---|
131 | RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unknown logger '%s'.\n", Val.psz);
|
---|
132 | return 1;
|
---|
133 | }
|
---|
134 | break;
|
---|
135 |
|
---|
136 | case 'h':
|
---|
137 | return usage();
|
---|
138 |
|
---|
139 | case 'V':
|
---|
140 | RTPrintf("%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr());
|
---|
141 | return 0;
|
---|
142 |
|
---|
143 | case VINF_GETOPT_NOT_OPTION:
|
---|
144 | RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unexpected argument '%s'.\n", Val.psz);
|
---|
145 | return 1;
|
---|
146 |
|
---|
147 | default:
|
---|
148 | return RTGetOptPrintError(ch, &Val);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | /*
|
---|
153 | * Make sure the support library is initialized.
|
---|
154 | */
|
---|
155 | int rc = SUPR3Init(NULL /*ppSession*/);
|
---|
156 | if (RT_SUCCESS(rc))
|
---|
157 | {
|
---|
158 | /*
|
---|
159 | * Do the requested job.
|
---|
160 | */
|
---|
161 | switch (enmWhat)
|
---|
162 | {
|
---|
163 | case kSupLoggerCtl_Set:
|
---|
164 | rc = SUPR3LoggerSettings(enmWhich, pszFlags, pszGroups, pszDest);
|
---|
165 | break;
|
---|
166 | case kSupLoggerCtl_Create:
|
---|
167 | rc = SUPR3LoggerCreate(enmWhich, pszFlags, pszGroups, pszDest);
|
---|
168 | break;
|
---|
169 | case kSupLoggerCtl_Destroy:
|
---|
170 | rc = SUPR3LoggerDestroy(enmWhich);
|
---|
171 | break;
|
---|
172 | default:
|
---|
173 | rc = VERR_INTERNAL_ERROR;
|
---|
174 | break;
|
---|
175 | }
|
---|
176 | if (RT_SUCCESS(rc))
|
---|
177 | RTPrintf("SUPLoggerCtl: Success\n");
|
---|
178 | else
|
---|
179 | RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: rc=%Rrc\n", rc);
|
---|
180 | }
|
---|
181 | else
|
---|
182 | RTStrmPrintf(g_pStdErr, "SUPR3Init: error: rc=%Rrc\n", rc);
|
---|
183 |
|
---|
184 | return RT_SUCCESS(rc) ? 0 : 1;
|
---|
185 | }
|
---|
186 |
|
---|