VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/testcase/SUPLoggerCtl.cpp

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use