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

« back to all changes in this revision

Viewing changes to services/vmtoolsd/serviceObj.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:
27
27
#include "svcSignals.h"
28
28
 
29
29
 
 
30
typedef struct ServiceProperty {
 
31
   guint       id;
 
32
   gchar      *name;
 
33
   gpointer    value;
 
34
} ServiceProperty;
 
35
 
 
36
static gpointer gToolsCoreServiceParentClass;
 
37
 
30
38
/**
31
39
 * Accumulator function for the "set option" signal. If a handler returns
32
40
 * TRUE, sets the result of the signal propagation to TRUE.
148
156
#endif
149
157
 
150
158
 
 
159
/*
 
160
 *******************************************************************************
 
161
 * ToolsCoreServiceGetProperty --                                         */ /**
 
162
 *
 
163
 * Gets the value of a property in the object.
 
164
 *
 
165
 * @param[in]  object   The instance.
 
166
 * @param[in]  id       Property ID.
 
167
 * @param[out] value    Where to set the value.
 
168
 * @param[in]  pspec    Unused.
 
169
 *
 
170
 *******************************************************************************
 
171
 */
 
172
 
 
173
static void
 
174
ToolsCoreServiceGetProperty(GObject *object,
 
175
                            guint id,
 
176
                            GValue *value,
 
177
                            GParamSpec *pspec)
 
178
{
 
179
   ToolsCoreService *self = (ToolsCoreService *) object;
 
180
 
 
181
   id -= 1;
 
182
 
 
183
   g_mutex_lock(self->lock);
 
184
 
 
185
   if (id < self->props->len) {
 
186
      ServiceProperty *p = &g_array_index(self->props, ServiceProperty, id);
 
187
      g_value_set_pointer(value, p->value);
 
188
   }
 
189
 
 
190
   g_mutex_unlock(self->lock);
 
191
}
 
192
 
 
193
 
 
194
/*
 
195
 *******************************************************************************
 
196
 * ToolsCoreServiceSetProperty --                                         */ /**
 
197
 *
 
198
 * Sets a property in the given object. If the property is found, a "notify"
 
199
 * signal is sent so that interested listeners can act on the change.
 
200
 *
 
201
 * @param[in] object The instance.
 
202
 * @param[in] id     Property ID.
 
203
 * @param[in] value  Value to set.
 
204
 * @param[in] pspec  Unused.
 
205
 *
 
206
 *******************************************************************************
 
207
 */
 
208
 
 
209
static void
 
210
ToolsCoreServiceSetProperty(GObject *object,
 
211
                            guint id,
 
212
                            const GValue *value,
 
213
                            GParamSpec *pspec)
 
214
{
 
215
   ServiceProperty *p = NULL;
 
216
   ToolsCoreService *self = (ToolsCoreService *) object;
 
217
 
 
218
   id -= 1;
 
219
 
 
220
   g_mutex_lock(self->lock);
 
221
 
 
222
   if (id < self->props->len) {
 
223
      p = &g_array_index(self->props, ServiceProperty, id);
 
224
      p->value = g_value_get_pointer(value);
 
225
   }
 
226
 
 
227
   g_mutex_unlock(self->lock);
 
228
 
 
229
   if (p != NULL) {
 
230
      g_object_notify(object, p->name);
 
231
   }
 
232
}
 
233
 
 
234
 
 
235
/*
 
236
 *******************************************************************************
 
237
 * ToolsCoreServiceCtor --                                                */ /**
 
238
 *
 
239
 * Object constructor. Initialize internal state.
 
240
 *
 
241
 * @param[in] type      Object type.
 
242
 * @param[in] nparams   Param count.
 
243
 * @param[in] params    Construction parameters.
 
244
 *
 
245
 * @return A new instance.
 
246
 *
 
247
 *******************************************************************************
 
248
 */
 
249
 
 
250
static GObject *
 
251
ToolsCoreServiceCtor(GType type,
 
252
                     guint nparams,
 
253
                     GObjectConstructParam *params)
 
254
{
 
255
   GObject *object;
 
256
   ToolsCoreService *self;
 
257
 
 
258
   object = G_OBJECT_CLASS(gToolsCoreServiceParentClass)->constructor(type,
 
259
                                                                      nparams,
 
260
                                                                      params);
 
261
 
 
262
   self = TOOLSCORE_SERVICE(object);
 
263
   self->lock = g_mutex_new();
 
264
   self->props = g_array_new(FALSE, FALSE, sizeof (ServiceProperty));
 
265
 
 
266
   return object;
 
267
}
 
268
 
 
269
 
 
270
/*
 
271
 *******************************************************************************
 
272
 * ToolsCoreServiceDtor --                                                */ /**
 
273
 *
 
274
 * Object destructor. Frees memory associated with the object. Goes through the
 
275
 * list of properties to make sure all of them have been cleaned up before the
 
276
 * service exits, printing a warning otherwise.
 
277
 *
 
278
 * @param[in]  object   The object being destructed.
 
279
 *
 
280
 *******************************************************************************
 
281
 */
 
282
 
 
283
static void
 
284
ToolsCoreServiceDtor(GObject *object)
 
285
{
 
286
   ToolsCoreService *self = (ToolsCoreService *) object;
 
287
   guint i;
 
288
 
 
289
   for (i = 0; i < self->props->len; i++) {
 
290
      ServiceProperty *p = &g_array_index(self->props, ServiceProperty, i);
 
291
      if (p->value != NULL) {
 
292
         g_warning("Property '%s' was not cleaned up before shut down.",
 
293
                   p->name);
 
294
      }
 
295
      g_free(p->name);
 
296
   }
 
297
 
 
298
   g_array_free(self->props, TRUE);
 
299
   g_mutex_free(self->lock);
 
300
}
 
301
 
 
302
 
151
303
/**
152
304
 * Initializes the ToolsCoreService class. Sets up the signals that are sent
153
305
 * by the vmtoolsd service.
160
312
                             gpointer klassData)
161
313
{
162
314
   ToolsCoreServiceClass *klass = _klass;
 
315
 
 
316
   gToolsCoreServiceParentClass = g_type_class_peek_parent(_klass);
 
317
 
163
318
   g_signal_new(TOOLS_CORE_SIG_CAPABILITIES,
164
319
                G_OBJECT_CLASS_TYPE(klass),
165
320
                G_SIGNAL_RUN_LAST,
239
394
                G_TYPE_UINT,
240
395
                G_TYPE_POINTER);
241
396
#endif
 
397
 
 
398
   G_OBJECT_CLASS(klass)->constructor = ToolsCoreServiceCtor;
 
399
   G_OBJECT_CLASS(klass)->finalize = ToolsCoreServiceDtor;
 
400
   G_OBJECT_CLASS(klass)->set_property = ToolsCoreServiceSetProperty;
 
401
   G_OBJECT_CLASS(klass)->get_property = ToolsCoreServiceGetProperty;
242
402
}
243
403
 
244
404
 
273
433
   return type;
274
434
}
275
435
 
 
436
 
 
437
/*
 
438
 *******************************************************************************
 
439
 * ToolsCoreService_RegisterProperty --                                   */ /**
 
440
 *
 
441
 * Installs a new property in the service object.
 
442
 *
 
443
 * @param[in] obj    Service object.
 
444
 * @param[in] prop   Property to install.
 
445
 *
 
446
 *******************************************************************************
 
447
 */
 
448
 
 
449
void
 
450
ToolsCoreService_RegisterProperty(ToolsCoreService *obj,
 
451
                                  ToolsServiceProperty *prop)
 
452
{
 
453
   static guint PROP_ID_SEQ = 0;
 
454
 
 
455
   ServiceProperty sprop;
 
456
   ToolsCoreServiceClass *klass = TOOLSCORESERVICE_GET_CLASS(obj);
 
457
   GParamSpec *pspec = g_param_spec_pointer(prop->name,
 
458
                                            prop->name,
 
459
                                            prop->name,
 
460
                                            G_PARAM_READWRITE);
 
461
 
 
462
   g_mutex_lock(obj->lock);
 
463
 
 
464
   sprop.id = ++PROP_ID_SEQ;
 
465
   sprop.name = g_strdup(prop->name);
 
466
   sprop.value = NULL;
 
467
   g_array_append_val(obj->props, sprop);
 
468
   g_object_class_install_property(G_OBJECT_CLASS(klass), sprop.id, pspec);
 
469
 
 
470
   g_mutex_unlock(obj->lock);
 
471
}
 
472