1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*********************************************************
* Copyright (C) 2010-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/**
* @file reload.c
*
* Code to respond to SIGUSR2 and restart the vmtoolsd instance.
*/
#include "desktopEventsInt.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static GSource *gReloadSrc;
/*
******************************************************************************
* ReloadSelf -- */ /**
*
* Signal handler for SIGUSR2. Stops the RPC channel and reloads the vmusr
* instance.
*
* @param[in] info Unused.
* @param[in] data The application context.
*
* @return FALSE.
*
******************************************************************************
*/
static gboolean
ReloadSelf(const siginfo_t *info,
gpointer data)
{
ToolsAppCtx *ctx = data;
if (ctx->rpc != NULL) {
RpcChannel_Stop(ctx->rpc);
}
Reload_Do();
return FALSE;
}
/*
******************************************************************************
* Reload_Do -- */ /**
*
* Re-launch vmware-user by attempting to execute VMUSER_TITLE ('vmware-user'),
* relying on the user's search path.
*
* On success, vmware-user is relaunched in our stead. On failure, we exit with
* EXIT_FAILURE.
*
******************************************************************************
*/
void
Reload_Do(void)
{
g_debug("Reloading the vmusr instance.");
execlp(VMUSER_TITLE, VMUSER_TITLE, NULL);
_exit(EXIT_FAILURE);
}
/*
******************************************************************************
* Reload_Init -- */ /**
*
* Registers a signal handler for SIGUSR2 that reloads the container.
*
* @param[in] ctx Application context.
* @param[in] pdata Registration data.
*
* @return TRUE.
*
******************************************************************************
*/
gboolean
Reload_Init(ToolsAppCtx *ctx,
ToolsPluginData *pdata)
{
gReloadSrc = VMTools_NewSignalSource(SIGUSR2);
VMTOOLSAPP_ATTACH_SOURCE(ctx, gReloadSrc, ReloadSelf, ctx, NULL);
return TRUE;
}
/*
******************************************************************************
* Reload_Shutdown -- */ /**
*
* Unregisters the SIGUSR2 signal handler.
*
* @param[in] ctx Application context.
* @param[in] pdata Plugin data (unused).
*
******************************************************************************
*/
void
Reload_Shutdown(ToolsAppCtx *ctx,
ToolsPluginData *pdata)
{
g_source_destroy(gReloadSrc);
g_source_unref(gReloadSrc);
gReloadSrc = NULL;
}
|