~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201210021442

« back to all changes in this revision

Viewing changes to services/plugins/desktopEvents/xioError.c

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-03-31 14:20:05 UTC
  • mfrom: (1.4.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110331142005-3n9red91p7ogkweo
Tags: 2011.03.28-387002-0ubuntu1
* Merge latest upstream git tag.  This has the unlocked_ioctl change
  needed to fix dkms build failures (LP: #727342)
* Changes in debian/rules:
  - work around a bug in toolbox/Makefile, where install-exec-hook is
    not happening.  This needs to get fixed the right way.
  - don't install 'vmware-user' which seems to no longer exist
  - move /etc/xdg into open-vm-toolbox (which should be done using .install)
* debian/open-vm-tools.init: add 'modprobe [-r] vmblock'. (LP: #332323)
* debian/rules and debian/open-vm-toolbox.lintian-overrides:
  - Make vmware-user-suid-wrapper suid-root (LP: #332323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 2010 VMware, Inc. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License as published
 
6
 * by the Free Software Foundation version 2.1 and no later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
10
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 
11
 * License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 
15
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 
16
 *
 
17
 *********************************************************/
 
18
 
 
19
/**
 
20
 * @file xioError.c
 
21
 *
 
22
 * Handles responding to X11 I/O errors.
 
23
 */
 
24
 
 
25
#include "desktopEventsInt.h"
 
26
#include <stdlib.h>
 
27
#include <sys/types.h>
 
28
#include <unistd.h>
 
29
#include <X11/Xlib.h>
 
30
 
 
31
 
 
32
static int gParentPid;
 
33
static ToolsAppCtx *gCtx;
 
34
static XIOErrorHandler gOrigHandler;
 
35
 
 
36
/*
 
37
 ******************************************************************************
 
38
 * DEXIOErrorHandler --                                                 */ /**
 
39
 *
 
40
 * Handler for all X I/O errors. Xlib documentation says we should not
 
41
 * return when handling I/O errors.
 
42
 *
 
43
 * @param[in] dpy    Unused.
 
44
 *
 
45
 * @return 1 (but doesn't really return).
 
46
 *
 
47
 ******************************************************************************
 
48
 */
 
49
 
 
50
static int
 
51
DEXIOErrorHandler(Display *dpy)
 
52
{
 
53
   pid_t my_pid = getpid();
 
54
 
 
55
   /*
 
56
    * ProcMgr_ExecAsync() needs to fork off a child to handle watching the
 
57
    * process being run.  When it dies, it will come through here, so we don't
 
58
    * want to let it shut down the RPC channel.
 
59
    */
 
60
   if (my_pid == gParentPid) {
 
61
      g_debug("%s", __func__);
 
62
 
 
63
      /*
 
64
       * XXX: the really correct thing to do here would be to properly stop all
 
65
       * plugins so that capabilities are unset and all other "clean shutdown"
 
66
       * tasks are performed. Unfortunately two things currently prevent that:
 
67
       *
 
68
       * . we can't rely on g_main_loop_quit() because we can't return from this
 
69
       *   function (well, we can, but Xlib will exit() before vmtoolsd is able
 
70
       *   to clean up things), so the main loop will never regain control off
 
71
       *   the app.
 
72
       *
 
73
       * . we can't access the internal vmtoolsd functions that cleanly shuts
 
74
       *   down plugins.
 
75
       *
 
76
       * So, right now, let's stick with just stopping the RPC channel so that
 
77
       * the host is notified the application is gone. This may cause temporary
 
78
       * issues with clients that only look at capabilities and not at the
 
79
       * status of vmusr.
 
80
       */
 
81
      if (gCtx->rpc != NULL) {
 
82
         RpcChannel_Stop(gCtx->rpc);
 
83
      }
 
84
      Reload_Do();
 
85
      exit(EXIT_FAILURE);
 
86
   } else {
 
87
      /*
 
88
       * _exit is used here so that any atexit() registered routines don't
 
89
       * interfere with any resources shared with the parent.
 
90
       */
 
91
      g_debug("%s hit from forked() child", __func__);
 
92
      _exit(EXIT_FAILURE);
 
93
   }
 
94
 
 
95
   return 1;
 
96
}
 
97
 
 
98
 
 
99
/*
 
100
 ******************************************************************************
 
101
 * XIOError_Init --                                                     */ /**
 
102
 *
 
103
 * Sets up an X11 I/O error callback that stops the daemon.
 
104
 *
 
105
 * @param[in] ctx       Application context.
 
106
 * @param[in] pdata     Registration data.
 
107
 *
 
108
 * @return TRUE.
 
109
 *
 
110
 ******************************************************************************
 
111
 */
 
112
 
 
113
gboolean
 
114
XIOError_Init(ToolsAppCtx *ctx,
 
115
              ToolsPluginData *pdata)
 
116
{
 
117
   gCtx = ctx;
 
118
   gParentPid = getpid();
 
119
   gOrigHandler = XSetIOErrorHandler(DEXIOErrorHandler);
 
120
   return TRUE;
 
121
}
 
122
 
 
123
 
 
124
/*
 
125
 ******************************************************************************
 
126
 * XIOError_Shutdown --                                                 */ /**
 
127
 *
 
128
 * Shutdown function, restores the original X I/O error handler.
 
129
 *
 
130
 * @param[in] ctx   Application context.
 
131
 * @param[in] pdata Plugin data (unused).
 
132
 *
 
133
 ******************************************************************************
 
134
 */
 
135
 
 
136
void
 
137
XIOError_Shutdown(ToolsAppCtx *ctx,
 
138
                  ToolsPluginData *pdata)
 
139
{
 
140
   XSetIOErrorHandler(gOrigHandler);
 
141
   gCtx = NULL;
 
142
   gOrigHandler = NULL;
 
143
}
 
144