VirtualBox

source: vbox/trunk/src/VBox/Runtime/tools/RTShutdown.cpp@ 69434

Last change on this file since 69434 was 69434, checked in by vboxsync, 7 years ago

Runtime: scm updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/* $Id: RTShutdown.cpp 69434 2017-10-27 15:48:25Z vboxsync $ */
2/** @file
3 * IPRT Testcase - System Shutdown.
4 */
5
6/*
7 * Copyright (C) 2012-2017 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 <iprt/system.h>
32
33#include <iprt/buildconfig.h>
34#include <iprt/err.h>
35#include <iprt/getopt.h>
36#include <iprt/initterm.h>
37#include <iprt/message.h>
38#include <iprt/stream.h>
39#include <iprt/string.h>
40
41
42int main(int argc, char **argv)
43{
44 int rc = RTR3InitExe(argc, &argv, 0);
45 if (RT_FAILURE(rc))
46 return RTMsgInitFailure(rc);
47
48 /*
49 * Parse the command line.
50 */
51 static const RTGETOPTDEF s_aOptions[] =
52 {
53 { "--halt", 'H', RTGETOPT_REQ_NOTHING },
54 { "--poweroff", 'p', RTGETOPT_REQ_NOTHING },
55 { "--reboot", 'r', RTGETOPT_REQ_NOTHING },
56 { "--force", 'f', RTGETOPT_REQ_NOTHING },
57 { "--delay", 'd', RTGETOPT_REQ_UINT32 },
58 { "--message", 'm', RTGETOPT_REQ_STRING }
59 };
60
61 const char *pszMsg = "RTShutdown";
62 RTMSINTERVAL cMsDelay = 0;
63 uint32_t fFlags = RTSYSTEM_SHUTDOWN_POWER_OFF | RTSYSTEM_SHUTDOWN_PLANNED;
64
65 RTGETOPTSTATE GetState;
66 rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1,
67 RTGETOPTINIT_FLAGS_OPTS_FIRST);
68 for (;;)
69 {
70 RTGETOPTUNION ValueUnion;
71 rc = RTGetOpt(&GetState, &ValueUnion);
72 if (rc == 0)
73 break;
74 switch (rc)
75 {
76 case 'H': fFlags = (fFlags & ~RTSYSTEM_SHUTDOWN_ACTION_MASK) | RTSYSTEM_SHUTDOWN_HALT; break;
77 case 'p': fFlags = (fFlags & ~RTSYSTEM_SHUTDOWN_ACTION_MASK) | RTSYSTEM_SHUTDOWN_POWER_OFF_HALT; break;
78 case 'r': fFlags = (fFlags & ~RTSYSTEM_SHUTDOWN_ACTION_MASK) | RTSYSTEM_SHUTDOWN_REBOOT; break;
79 case 'f': fFlags |= RTSYSTEM_SHUTDOWN_FORCE; break;
80 case 'd': cMsDelay = ValueUnion.u32; break;
81 case 'm': pszMsg = ValueUnion.psz; break;
82
83 case 'h':
84 RTPrintf("Usage: RTShutdown [-H|-p|-r] [-f] [-d <milliseconds>] [-m <msg>]\n");
85 return RTEXITCODE_SUCCESS;
86
87 case 'V':
88 RTPrintf("%sr%d\n", RTBldCfgVersion(), RTBldCfgRevision());
89 return RTEXITCODE_SUCCESS;
90
91 default:
92 return RTGetOptPrintError(rc, &ValueUnion);
93 }
94 }
95
96 /*
97 * Do the deed.
98 */
99 rc = RTSystemShutdown(cMsDelay, fFlags, pszMsg);
100 if (RT_FAILURE(rc))
101 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTSystemShutdown(%u, %#x, \"%s\") returned %Rrc\n", cMsDelay, fFlags, pszMsg, rc);
102 return RTEXITCODE_SUCCESS;
103}
104
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