VirtualBox

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

Last change on this file since 78297 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1/* $Id: SUPLoggerCtl.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * SUPLoggerCtl - Support Driver Logger Control.
4 */
5
6/*
7 * Copyright (C) 2009-2019 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 */
45static 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
59int main(int argc, char **argv)
60{
61 RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_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 * Do the requested job.
154 */
155 int rc;
156 switch (enmWhat)
157 {
158 case kSupLoggerCtl_Set:
159 rc = SUPR3LoggerSettings(enmWhich, pszFlags, pszGroups, pszDest);
160 break;
161 case kSupLoggerCtl_Create:
162 rc = SUPR3LoggerCreate(enmWhich, pszFlags, pszGroups, pszDest);
163 break;
164 case kSupLoggerCtl_Destroy:
165 rc = SUPR3LoggerDestroy(enmWhich);
166 break;
167 default:
168 rc = VERR_INTERNAL_ERROR;
169 break;
170 }
171 if (RT_SUCCESS(rc))
172 RTPrintf("SUPLoggerCtl: Success\n");
173 else
174 RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: rc=%Rrc\n", rc);
175
176 return RT_SUCCESS(rc) ? 0 : 1;
177}
178
Note: See TracBrowser for help on using the repository browser.

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