~ubuntu-branches/ubuntu/precise/open-vm-tools/precise

« back to all changes in this revision

Viewing changes to lib/xdg/xdg.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
 * xdg.c --
 
21
 *
 
22
 *      vmware-xdg-* script wrapper library.
 
23
 */
 
24
 
 
25
#include <sys/types.h>
 
26
#include <sys/wait.h>
 
27
 
 
28
#include <stdio.h>
 
29
#include <stdlib.h>
 
30
 
 
31
#include "vmware.h"
 
32
#include "vmstdio.h"
 
33
#include "xdg.h"
 
34
 
 
35
 
 
36
/*
 
37
 * Local data
 
38
 */
 
39
 
 
40
 
 
41
/* Name of helper script used by Xdg_DetectDesktopEnv. */
 
42
static const char xdgDetectDEExec[] = "vmware-xdg-detect-de";
 
43
 
 
44
 
 
45
/*
 
46
 * Global functions
 
47
 */
 
48
 
 
49
 
 
50
/*
 
51
 *-----------------------------------------------------------------------------
 
52
 *
 
53
 * Xdg_DetectDesktopEnv --
 
54
 *
 
55
 *      Captures output from external vmware-xdg-detect-de script to determine
 
56
 *      which desktop environment we're running under.
 
57
 *
 
58
 * Results:
 
59
 *      Returns a pointer to a string specifying the desktop environment on
 
60
 *      success or NULL on failure.
 
61
 *
 
62
 *      This function only guarantees that the returned string matches the
 
63
 *      pattern ^[A-Z]*$.
 
64
 *
 
65
 * Side effects:
 
66
 *      Allocates memory for outbuf on first call for duration of program.
 
67
 *      Uses popen(), relying on $PATH, to find and execute xdgDetectDeExec.
 
68
 *      Caller must not modify returned string.
 
69
 *
 
70
 *-----------------------------------------------------------------------------
 
71
 */
 
72
 
 
73
const char *
 
74
Xdg_DetectDesktopEnv(void)
 
75
{
 
76
   static char *outbuf = NULL;
 
77
 
 
78
   if (outbuf == NULL) {
 
79
      FILE *cmdPipe = popen(xdgDetectDEExec, "r");
 
80
 
 
81
      if (cmdPipe) {
 
82
         static const size_t maxSize = sizeof "TEHLONGISTDESKTOPENVEVAR";
 
83
         size_t outLen;         // Doesn't include NUL.
 
84
         int status;
 
85
 
 
86
         if (StdIO_ReadNextLine(cmdPipe, &outbuf, maxSize, &outLen)
 
87
             == StdIO_Success) {
 
88
            char *i;
 
89
 
 
90
            for (i = outbuf; i < &outbuf[outLen]; i++) {
 
91
               /* We expect a string in all capitals. */
 
92
               if (*i < 'A' || *i > 'Z') {
 
93
                  free(outbuf);
 
94
                  outbuf = NULL;
 
95
                  break;
 
96
               }
 
97
            }
 
98
         }
 
99
 
 
100
         status = pclose(cmdPipe);
 
101
         if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
 
102
            free(outbuf);
 
103
            outbuf = NULL;
 
104
         }
 
105
      }
 
106
   }
 
107
 
 
108
   return outbuf;
 
109
}