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

« back to all changes in this revision

Viewing changes to lib/glibUtils/sysLogger.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) 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 sysLogger.c
 
21
 *
 
22
 * Logger that writes to syslog(3). Since there's only one "syslog connection"
 
23
 * for the whole application, this code does reference counting to allow
 
24
 * different domains to be configured with a "syslog" handler, and still be
 
25
 * able to call closelog(3) when appropriate.
 
26
 */
 
27
 
 
28
#include "glibUtils.h"
 
29
#include <stdio.h>
 
30
#include <string.h>
 
31
#include <syslog.h>
 
32
 
 
33
typedef struct SysLogger {
 
34
   GlibLogger  handler;
 
35
   gchar      *domain;
 
36
   gint        refcount;
 
37
} SysLogger;
 
38
 
 
39
 
 
40
static SysLogger *gSysLogger;
 
41
static GStaticMutex gSysLoggerLock = G_STATIC_MUTEX_INIT;
 
42
 
 
43
 
 
44
/*
 
45
 *******************************************************************************
 
46
 * SysLoggerLog --                                                        */ /**
 
47
 *
 
48
 * @brief Sends the given log message to syslog.
 
49
 *
 
50
 * @param[in] domain     Unused.
 
51
 * @param[in] level      Log level.
 
52
 * @param[in] message    Message to log.
 
53
 * @param[in] data       Unused.
 
54
 *
 
55
 ******************************************************************************
 
56
 */
 
57
 
 
58
static void
 
59
SysLoggerLog(const gchar *domain,
 
60
             GLogLevelFlags level,
 
61
             const gchar *message,
 
62
             gpointer data)
 
63
{
 
64
   gchar *local;
 
65
   int priority;
 
66
 
 
67
   /* glib and syslog disagree about critical / error. */
 
68
   if (level & G_LOG_LEVEL_ERROR) {
 
69
      priority = LOG_CRIT;
 
70
   } else if (level & G_LOG_LEVEL_CRITICAL) {
 
71
      priority = LOG_ERR;
 
72
   } else if (level & G_LOG_LEVEL_WARNING) {
 
73
      priority = LOG_WARNING;
 
74
   } else if (level & G_LOG_LEVEL_MESSAGE) {
 
75
      priority = LOG_NOTICE;
 
76
   } else if (level & G_LOG_LEVEL_INFO) {
 
77
      priority = LOG_INFO;
 
78
   } else {
 
79
      priority = LOG_DEBUG;
 
80
   }
 
81
 
 
82
   local = g_locale_from_utf8(message, -1, NULL, NULL, NULL);
 
83
   if (local != NULL) {
 
84
      syslog(priority, "%s", local);
 
85
      g_free(local);
 
86
   } else {
 
87
      syslog(priority, "%s", message);
 
88
   }
 
89
}
 
90
 
 
91
 
 
92
/*
 
93
 *******************************************************************************
 
94
 * SysLoggerUnref --                                                      */ /**
 
95
 *
 
96
 * @brief Decreases the ref count and closes syslog if it reaches 0.
 
97
 *
 
98
 * @param[in] data   Unused.
 
99
 *
 
100
 *******************************************************************************
 
101
 */
 
102
 
 
103
static void
 
104
SysLoggerUnref(gpointer data)
 
105
{
 
106
   g_return_if_fail(data == gSysLogger);
 
107
   g_return_if_fail(gSysLogger->refcount > 0);
 
108
   g_static_mutex_lock(&gSysLoggerLock);
 
109
   gSysLogger->refcount -= 1;
 
110
   if (gSysLogger->refcount == 0) {
 
111
      closelog();
 
112
      g_free(gSysLogger->domain);
 
113
      g_free(gSysLogger);
 
114
      gSysLogger = NULL;
 
115
   }
 
116
   g_static_mutex_unlock(&gSysLoggerLock);
 
117
}
 
118
 
 
119
 
 
120
/*
 
121
 *******************************************************************************
 
122
 * GlibUtils_CreateSysLogger --                                           */ /**
 
123
 *
 
124
 * @brief Initializes syslog if it hasn't been done yet.
 
125
 *
 
126
 * Since syslog is shared, it's not recommended to change the default domain
 
127
 * during the lifetime of the application, since that may not reflect on the
 
128
 * syslogs (and, when it does, it might be confusing).
 
129
 *
 
130
 * @param[in] domain    Application name, used as the syslog identity.
 
131
 * @param[in] facility  Facility to use. One of: "daemon", "local[0-7]",
 
132
                        "user" (default).
 
133
 *
 
134
 * @return Syslog logger data.
 
135
 *
 
136
 *******************************************************************************
 
137
 */
 
138
 
 
139
GlibLogger *
 
140
GlibUtils_CreateSysLogger(const char *domain,
 
141
                          const char *facility)
 
142
{
 
143
   g_static_mutex_lock(&gSysLoggerLock);
 
144
   if (gSysLogger == NULL) {
 
145
      int facid = LOG_USER;
 
146
 
 
147
      if (facility != NULL) {
 
148
         int idx;
 
149
         if (strcmp(facility, "daemon") == 0) {
 
150
            facid = LOG_DAEMON;
 
151
         } else if (sscanf(facility, "local%d", &idx) == 1) {
 
152
            switch (idx) {
 
153
            case 0:
 
154
               facid = LOG_LOCAL0;
 
155
               break;
 
156
 
 
157
            case 1:
 
158
               facid = LOG_LOCAL1;
 
159
               break;
 
160
 
 
161
            case 2:
 
162
               facid = LOG_LOCAL2;
 
163
               break;
 
164
 
 
165
            case 3:
 
166
               facid = LOG_LOCAL3;
 
167
               break;
 
168
 
 
169
            case 4:
 
170
               facid = LOG_LOCAL4;
 
171
               break;
 
172
 
 
173
            case 5:
 
174
               facid = LOG_LOCAL5;
 
175
               break;
 
176
 
 
177
            case 6:
 
178
               facid = LOG_LOCAL6;
 
179
               break;
 
180
 
 
181
            case 7:
 
182
               facid = LOG_LOCAL7;
 
183
               break;
 
184
 
 
185
            default:
 
186
               g_message("Invalid local facility for %s: %s\n", domain, facility);
 
187
               break;
 
188
            }
 
189
         } else if (strcmp(facility, "user") != 0) {
 
190
            g_message("Invalid syslog facility for %s: %s\n", domain, facility);
 
191
         }
 
192
      }
 
193
 
 
194
      gSysLogger = g_new0(SysLogger, 1);
 
195
      gSysLogger->handler.addsTimestamp = TRUE;
 
196
      gSysLogger->handler.shared = FALSE;
 
197
      gSysLogger->handler.logfn = SysLoggerLog;
 
198
      gSysLogger->handler.dtor = SysLoggerUnref;
 
199
 
 
200
      gSysLogger->domain = g_strdup(domain);
 
201
      gSysLogger->refcount = 1;
 
202
      openlog(gSysLogger->domain, LOG_CONS | LOG_PID, facid);
 
203
   } else {
 
204
      gSysLogger->refcount += 1;
 
205
   }
 
206
   g_static_mutex_unlock(&gSysLoggerLock);
 
207
   return &gSysLogger->handler;
 
208
}
 
209