~n-muench/ubuntu/precise/open-vm-tools/open-vm-tools.raring-precise.backport

« back to all changes in this revision

Viewing changes to lib/misc/msgList.c

  • Committer: Package Import Robot
  • Author(s): Nate Muench
  • Date: 2012-01-23 16:09:45 UTC
  • mfrom: (1.4.6) (2.4.26 sid)
  • Revision ID: package-import@ubuntu.com-20120123160945-b6s0r1vkcovucpf3
Tags: 2011.12.20-562307-0ubuntu1
* Merge latest upstream git tag. Fixes building on Precise
  (LP: #898289, LP: #905612)

* Items merged from Debian unstable:
  - debian/control:
    + open-vm-tools recommends open-vm-dkms. (LP: #598933)
    + open-vm-tools now suggests open-vm-toolbox. (LP: #604998)
  (From 2011.08.21-471295-1 release)
  - Updating maintainer and uploaders fields.
  - Removing vcs fields.
  - Removing references to Daniel's old email address.
  - Updating years in copyright file.
  - Updating to standards version 3.9.2.
  - Updating to debhelper version 8.
  - Switching to source format 3.0 (quilt).
  - Removing manual chrpath setting.
  - Removing exclusion from plugins from debhelper shlibs.
  - Rediffing kvers.patch.
  (From 2011.09.23-491607-1 release)
  - Marking binary architecture-dependend packages as linux and kfreebsd
  only.
  - Removing liburiparser-dev from build-depends as upstream dropped
  unity support.
  - Building with libproc-dev on amd64 again.
  - Dropping disabling of dnet support.
  (From 2011.09.23-491607-2 release)
  - Adding doxygen to build-depends for api documentation.
  - Adding libcunit1-dev to build-depends for test suites.
  - Minimizing rules file.
  - Adding open-vm-tools-dev package, containing only the api
    documentation for now.
  (From 2011.09.23-491607-3 release)
  - Sorting overrides in rules alphabetically.
  - Compacting copyright file.
  - Adding udev rule to set timeout for vmware scsi devices
  (From 2011.12.20-562307-1 release)
  - Adding patch to correct typo in upstreams dkms configuration

* Remaining Changes:
  - Remove Stable part of version numbering.
  - debian folder:
    + Re-added open-vm-dkms.postinst & open-vm-dkms.prerm.
      * Allows dkms modules to compile upon installation.
  - debian/control:
    + Re-add open-vm-source and make into a transitional package
      for open-vm-toolbox.
    + Return dependancies that were moved to open-vm-tools back to
      open-vm-toolbox.
  - debian/rules and debian/open-vm-toolbox.lintian-overrides:
    + Make vmware-user-suid-wrapper suid-root
  - debian/rules:
    + Added CFLAGS field with -Wno-deprecated-declarations
      * Will suppress issues with glib 2.31 or later.
    + Add line to copy vmware-xdg-detect-de into place.
    + Install vmware-user.desktop through toolbox package.
  - debian/open-vm-tools.init:
    + Re-add 'modprobe [-r] vmblock'.
    + Add 'modprobe [-r] vmxnet'.
      * Incase it's not loaded during boot.
    + Remove and re-add pcnet32 module
      * Will be done before (remove) and after (readd) vmxnet module
        is added.
      * If vmxnet doesn't exist (aka modules fail to build), pcnet32 can be
        still used for network connectivity.
      * Workaround until a better fix can be done.
  - Re-add gnome-session to debian/local/xautostart.conf
  - Manpages removed (from debian/manpages):
    + vmmemctl.9
    + vmxnet3.9
    + Remove references to manpages that have been removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 2009-2011 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
 * msgList.c --
 
21
 *
 
22
 *   Utilities to manipulate (stateless) lists of messages.
 
23
 *   See also msg.h.
 
24
 */
 
25
 
 
26
 
 
27
#include <stdarg.h>
 
28
#include <stdlib.h>
 
29
#include <string.h>
 
30
 
 
31
#include "vmware.h"
 
32
#include "util.h"
 
33
#include "str.h"
 
34
#include "err.h"
 
35
#include "msgList.h"
 
36
#include "dynbuf.h"
 
37
 
 
38
#define LOGLEVEL_MODULE main
 
39
#include "loglevel_user.h"
 
40
 
 
41
 
 
42
/*
 
43
 *-----------------------------------------------------------------------------
 
44
 *
 
45
 * MsgId2MsgList --
 
46
 *
 
47
 *      Create a MsgList item from the input message. Does not handle arguments;
 
48
 *      the caller must handle those.
 
49
 *
 
50
 *      Performs any needed sanity checks as well.
 
51
 *
 
52
 * Results:
 
53
 *      A newly-allocated MsgList.
 
54
 *
 
55
 * Side effects:
 
56
 *      None.
 
57
 *
 
58
 *-----------------------------------------------------------------------------
 
59
 */
 
60
 
 
61
static MsgList *
 
62
MsgId2MsgList(const char *idFmt)  // IN message ID and English message
 
63
{
 
64
   MsgList *m;
 
65
   const char *idp, *strp;
 
66
 
 
67
   /* All message strings must be prefixed by the message ID. */
 
68
   ASSERT(Msg_HasMsgID(idFmt));
 
69
 
 
70
   /*
 
71
    * Find the beginning of the ID (idp) and the string (strp).
 
72
    * The string should have the correct MSG_MAGIC(...)... form.
 
73
    */
 
74
 
 
75
   idp = idFmt + MSG_MAGIC_LEN + 1;
 
76
   strp = strchr(idp, ')') + 1;
 
77
 
 
78
   m = Util_SafeMalloc(sizeof *m);
 
79
   m->format = Util_SafeStrdup(strp);
 
80
   m->next = NULL;
 
81
   m->args = NULL;
 
82
   m->numArgs = 0;
 
83
 
 
84
   if (vmx86_debug) {
 
85
      uint32 i;
 
86
      static const char *prfx[] = {
 
87
         "msg.",    // bora/lib, VMX, ...
 
88
         "vob.",    // Vmkernel OBservation
 
89
         "vpxa.",   // VirtualCenter host agent
 
90
         "vpxd.",   // VirtualCenter server
 
91
         "hostd.",  // Host agent
 
92
                    // Additional prefixes go here, but do not add "button."
 
93
      };
 
94
 
 
95
      for (i = 0; i < ARRAYSIZE(prfx); i++) {
 
96
         if (!Str_Strncasecmp(idp, prfx[i], strlen(prfx[i]))) {
 
97
            break;
 
98
         }
 
99
      }
 
100
      if (i >= ARRAYSIZE(prfx)) {
 
101
         Panic("%s error: Invalid msg prefix in <%s>\n", __FUNCTION__, idp);
 
102
      }
 
103
   }
 
104
 
 
105
   m->id = Util_SafeStrndup(idp, strp - idp - 1 /* ')' character */);
 
106
 
 
107
   return m;
 
108
}
 
109
 
 
110
 
 
111
/*
 
112
 *-----------------------------------------------------------------------------
 
113
 *
 
114
 * MsgList_AppendStr --
 
115
 *
 
116
 *      Create a MsgList item from the input message. The input message MUST
 
117
 *      have no arguments. Do not pass in formatted messages; use MsgList_Append
 
118
 *      for that. This variant is only for MSGIDs that have no format arguments.
 
119
 *
 
120
 *      If the incoming list pointer reference is NULL, operate in 'silent'
 
121
 *      mode: skip all work (except preconditions).  Note that in silent +
 
122
 *      vmx86_debug mode, this code does all work and throws away the result,
 
123
 *      to make sure all messages are parseable.
 
124
 *
 
125
 * Results:
 
126
 *      New item is attached to 'list' (and '*list' is updated).
 
127
 *
 
128
 * Side effects:
 
129
 *      Callers are responsible to free the returned MsgList.
 
130
 *
 
131
 *-----------------------------------------------------------------------------
 
132
 */
 
133
 
 
134
void
 
135
MsgList_AppendStr(MsgList **list,  // IN reference to existing list
 
136
                  const char *id)  // IN message ID and English message
 
137
{
 
138
   ASSERT(id != NULL);
 
139
 
 
140
   /* Silently upgrade system errors to real MSGIDs. */
 
141
   if (!Msg_HasMsgID(id) && Err_String2Errno(id) != ERR_INVALID) {
 
142
      MsgList_Append(list, MSGID(systemerror) "%s", id);
 
143
      return;
 
144
   }
 
145
 
 
146
   /*
 
147
    * The MsgList_AppendStr variant does not accept format strings. This
 
148
    * check disallows some legitimate strings, but it's probably easier
 
149
    * on the msgconv parser to just disallow all format-string-like things.
 
150
    */
 
151
   ASSERT(strchr(id, '%') == NULL);
 
152
 
 
153
   /*
 
154
    * In silent mode, skip processing in release builds. Debug
 
155
    * builds can afford the speed cost to verify message is constructable.
 
156
    */
 
157
   if (list != NULL || vmx86_debug) {
 
158
      MsgList *m = MsgId2MsgList(id);
 
159
 
 
160
      if (list != NULL) {
 
161
         m->next = *list;
 
162
         *list = m;
 
163
      } else {
 
164
         /* Silent mode, but constructed as a sanity test. Clean up. */
 
165
         ASSERT(vmx86_debug);
 
166
         MsgList_Free(m);
 
167
      }
 
168
   }
 
169
}
 
170
 
 
171
 
 
172
/*
 
173
 *-----------------------------------------------------------------------------
 
174
 *
 
175
 * MsgList_VAppend --
 
176
 *
 
177
 *      Create a MsgList item from the message with va_list,
 
178
 *      and attach it to the incoming list.
 
179
 *
 
180
 *      If the incoming list pointer reference is NULL, operate in 'silent'
 
181
 *      mode: skip all work (except preconditions).  Note that in silent +
 
182
 *      vmx86_debug mode, this code does all work and throws away the result,
 
183
 *      to make sure all messages are parseable.
 
184
 *
 
185
 * Results:
 
186
 *      New item is attached to 'list' (and '*list' is updated).
 
187
 *
 
188
 * Side effects:
 
189
 *      Callers are responsible to free the returned MsgList.
 
190
 *
 
191
 *-----------------------------------------------------------------------------
 
192
 */
 
193
 
 
194
void
 
195
MsgList_VAppend(MsgList **list,     // IN reference to existing list
 
196
                const char *idFmt,  // IN message ID and English message
 
197
                va_list args)       // IN args
 
198
{
 
199
   ASSERT(idFmt != NULL);
 
200
 
 
201
   /* Silently upgrade system errors to real MSGIDs. */
 
202
   if (!Msg_HasMsgID(idFmt) && Err_String2Errno(idFmt) != ERR_INVALID) {
 
203
      MsgList_Append(list, MSGID(systemerror) "%s", idFmt);
 
204
      return;
 
205
   }
 
206
 
 
207
   /*
 
208
    * In silent mode, skip processing in release builds. Debug
 
209
    * builds can afford the speed cost to verify message is constructable.
 
210
    */
 
211
   if (list != NULL || vmx86_debug) {
 
212
      MsgList *m = MsgId2MsgList(idFmt);
 
213
      Bool status;
 
214
      char *error;
 
215
 
 
216
      status = MsgFmt_GetArgs(m->format, args, &m->args, &m->numArgs, &error);
 
217
      if (!status) {
 
218
         Log("%s error: %s\nformat <%s>\n", __FUNCTION__, error, m->format);
 
219
         PANIC();
 
220
      }
 
221
 
 
222
      if (list != NULL) {
 
223
         m->next = *list;
 
224
         *list = m;
 
225
      } else {
 
226
         /* Silent mode, but constructed as a sanity test. Clean up. */
 
227
         ASSERT(vmx86_debug);
 
228
         MsgList_Free(m);
 
229
      }
 
230
   }
 
231
}
 
232
 
 
233
 
 
234
/*
 
235
 *-----------------------------------------------------------------------------
 
236
 *
 
237
 * MsgList_Append --
 
238
 *
 
239
 *      Create the MsgList item from the message with va_list.
 
240
 *
 
241
 * Results:
 
242
 *      New item is prepended to 'list' (and '*list' is new item).
 
243
 *
 
244
 * Side effects:
 
245
 *      Callers are responsible to free the returned MsgList.
 
246
 *
 
247
 *-----------------------------------------------------------------------------
 
248
 */
 
249
 
 
250
void
 
251
MsgList_Append(MsgList **list,     // IN reference to existing list
 
252
               const char *idFmt,  // IN message ID and English message
 
253
               ...)                // IN args
 
254
{
 
255
   va_list args;
 
256
 
 
257
   va_start(args, idFmt);
 
258
   MsgList_VAppend(list, idFmt, args);
 
259
   va_end(args);
 
260
}
 
261
 
 
262
 
 
263
/*
 
264
 *-----------------------------------------------------------------------------
 
265
 *
 
266
 * MsgList_VCreate --
 
267
 *
 
268
 *     Create the MsgList item from the message.
 
269
 *
 
270
 * Results:
 
271
 *      New MsgList structure.
 
272
 *
 
273
 * Side effects:
 
274
 *      Callers are responsible to free the returned MsgList.
 
275
 *
 
276
 *-----------------------------------------------------------------------------
 
277
 */
 
278
 
 
279
MsgList *
 
280
MsgList_VCreate(const char *idFmt,  // IN message ID and English message
 
281
                va_list args)       // IN args
 
282
{
 
283
   MsgList *ml = NULL;
 
284
 
 
285
   MsgList_VAppend(&ml, idFmt, args);
 
286
 
 
287
   return ml;
 
288
}
 
289
 
 
290
 
 
291
/*
 
292
 *-----------------------------------------------------------------------------
 
293
 *
 
294
 * MsgList_Create --
 
295
 *
 
296
 *     Create the MsgList item from the message with va_list.
 
297
 *
 
298
 * Results:
 
299
 *      New MsgList structure.
 
300
 *
 
301
 * Side effects:
 
302
 *      Callers are responsible to free the returned MsgList.
 
303
 *
 
304
 *-----------------------------------------------------------------------------
 
305
 */
 
306
 
 
307
MsgList *
 
308
MsgList_Create(const char *idFmt,  // IN message ID and English message
 
309
               ...)                // IN args
 
310
{
 
311
   MsgList *ml = NULL;
 
312
   va_list args;
 
313
 
 
314
   va_start(args, idFmt);
 
315
   MsgList_VAppend(&ml, idFmt, args);
 
316
   va_end(args);
 
317
 
 
318
   return ml;
 
319
}
 
320
 
 
321
 
 
322
/*
 
323
 *-----------------------------------------------------------------------------
 
324
 *
 
325
 * MsgList_CreateStr --
 
326
 *
 
327
 *     Create the MsgList item from the message with no format arguments.
 
328
 *
 
329
 * Results:
 
330
 *      New MsgList structure.
 
331
 *
 
332
 * Side effects:
 
333
 *      Callers are responsible to free the returned MsgList.
 
334
 *
 
335
 *-----------------------------------------------------------------------------
 
336
 */
 
337
 
 
338
MsgList *
 
339
MsgList_CreateStr(const char *idFmt)  // IN message ID and English message
 
340
{
 
341
   MsgList *ml = NULL;
 
342
 
 
343
   MsgList_AppendStr(&ml, idFmt);
 
344
 
 
345
   return ml;
 
346
}
 
347
 
 
348
 
 
349
/*
 
350
 *----------------------------------------------------------------------
 
351
 *
 
352
 * MsgList_Copy --
 
353
 *
 
354
 *      Makes a deep copy of the MsgList.
 
355
 *
 
356
 * Results:
 
357
 *      Newly allocated MsgList.  Use MsgList_Free() to free.
 
358
 *
 
359
 * Side effects:
 
360
 *      None.
 
361
 *
 
362
 *----------------------------------------------------------------------
 
363
 */
 
364
 
 
365
MsgList *
 
366
MsgList_Copy(const MsgList *src)  // IN:
 
367
{
 
368
   MsgList *result = NULL;
 
369
   MsgList **pdst = &result;
 
370
 
 
371
   while (src != NULL) {
 
372
      MsgList *dst = Util_SafeMalloc(sizeof *dst);
 
373
 
 
374
      dst->id = Util_SafeStrdup(src->id);
 
375
      dst->format = Util_SafeStrdup(src->format);
 
376
      dst->args = MsgFmt_CopyArgs(src->args, src->numArgs);
 
377
      dst->numArgs = src->numArgs;
 
378
      dst->next = NULL;
 
379
      src = src->next;
 
380
      *pdst = dst;
 
381
      pdst = &dst->next;
 
382
   }
 
383
 
 
384
   return result;
 
385
}
 
386
 
 
387
 
 
388
/*
 
389
 *----------------------------------------------------------------------
 
390
 *
 
391
 * MsgList_Free --
 
392
 *
 
393
 *      Frees the full MsgList chain.
 
394
 *
 
395
 * Results:
 
396
 *      None.
 
397
 *
 
398
 * Side effects:
 
399
 *      None.
 
400
 *
 
401
 *----------------------------------------------------------------------
 
402
 */
 
403
 
 
404
void
 
405
MsgList_Free(MsgList *messages)  // IN:
 
406
{
 
407
   MsgList *m;
 
408
   MsgList *next;
 
409
 
 
410
   for (m = messages; m != NULL; m = next) {
 
411
      free(m->format);
 
412
      free(m->id);
 
413
      MsgFmt_FreeArgs(m->args, m->numArgs);
 
414
      next = m->next;
 
415
      free(m);
 
416
   }
 
417
}
 
418
 
 
419
/*
 
420
 *----------------------------------------------------------------------
 
421
 *
 
422
 * MsgList_GetMsgID --
 
423
 *
 
424
 *      Returns the "main" MSGID for the message stack.
 
425
 *
 
426
 *      This is useful for Msg_Post, Msg_Hint, and Msg_Question,
 
427
 *      all of which have the semantic that the generalized MSGID
 
428
 *      is the MSGID of the last message in the stack.
 
429
 *
 
430
 * Results:
 
431
 *      Returns pointer to something within the MsgList, or
 
432
 *      NULL if the MsgList doesn't exist.
 
433
 *
 
434
 * Side effects:
 
435
 *      None.
 
436
 *
 
437
 *----------------------------------------------------------------------
 
438
 */
 
439
 
 
440
const char *
 
441
MsgList_GetMsgID(const MsgList *messages)  // IN:
 
442
{
 
443
   if (messages == NULL) {
 
444
      return NULL;
 
445
   }
 
446
   while (messages->next != NULL) {
 
447
      messages = messages->next;
 
448
   }
 
449
 
 
450
   return messages->id;
 
451
}
 
452
 
 
453
 
 
454
/*
 
455
 *----------------------------------------------------------------------
 
456
 *
 
457
 * MsgList_ToString --
 
458
 *
 
459
 *      Returns the English representation of a MsgList chain.  Does NOT
 
460
 *      localize.
 
461
 *
 
462
 * Results:
 
463
 *      Allocated memory containing message.  Successive messages
 
464
 *      are separated by newlines.
 
465
 *
 
466
 * Side effects:
 
467
 *      None.
 
468
 *
 
469
 *----------------------------------------------------------------------
 
470
 */
 
471
 
 
472
char *
 
473
MsgList_ToString(const MsgList *messages)  // IN:
 
474
{
 
475
   char *result = NULL;
 
476
 
 
477
   if (messages != NULL) {
 
478
      size_t len = 0;
 
479
      char *formatted = MsgFmt_Asprintf(&len, messages->format, messages->args,
 
480
                                        messages->numArgs);
 
481
      const char *eol = (len > 0 && formatted != NULL &&
 
482
                         formatted[len - 1] == '\n') ? "" : "\n";
 
483
      char *tail;
 
484
 
 
485
      if (messages->next != NULL) {
 
486
         tail = MsgList_ToString(messages->next);
 
487
      } else {
 
488
         tail = Util_SafeStrdup("");
 
489
      }
 
490
      result = Str_SafeAsprintf(NULL, "%s%s%s", formatted, eol, tail);
 
491
      free(formatted);
 
492
      free(tail);
 
493
   }
 
494
 
 
495
   return result;
 
496
}
 
497
 
 
498
 
 
499
/*
 
500
 *----------------------------------------------------------------------
 
501
 *
 
502
 * MsgList_Log --
 
503
 *
 
504
 *      Emits the English representation of a MsgList chain to Log().
 
505
 *
 
506
 * Results:
 
507
 *      None.
 
508
 *
 
509
 * Side effects:
 
510
 *      None.
 
511
 *
 
512
 *----------------------------------------------------------------------
 
513
 */
 
514
 
 
515
void
 
516
MsgList_Log(const MsgList *messages)  // IN:
 
517
{
 
518
   const MsgList *m;
 
519
 
 
520
   for (m = messages; m != NULL; m = m->next) {
 
521
      size_t len = 0;
 
522
      char *formatted = MsgFmt_Asprintf(&len, m->format, m->args, m->numArgs);
 
523
 
 
524
      Log("[%s] %s%s",
 
525
          m->id, formatted,
 
526
          (len > 0 && formatted != NULL && formatted[len - 1] == '\n') ? ""
 
527
                                                                       : "\n");
 
528
      free(formatted);
 
529
   }
 
530
}