~ubuntu-branches/ubuntu/saucy/mapserver/saucy-security

« back to all changes in this revision

Viewing changes to mapdebug.c

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-12-23 14:02:06 UTC
  • mfrom: (26.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111223140206-n3h9t2hsa8hyslmu
Tags: 6.0.1-2
Added missed stuff for libmapscript-perl.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: mapdebug.c 7923 2008-09-23 17:58:55Z dmorissette $
 
2
 * $Id: mapdebug.c 11503 2011-04-07 19:56:16Z dmorissette $
3
3
 *
4
4
 * Project:  MapServer
5
5
 * Purpose:  Implementation of debug/logging, msDebug() and related functions.
48
48
#include <windows.h> /* OutputDebugStringA() */
49
49
#endif
50
50
 
51
 
#if defined(_WIN32) && !defined(__CYGWIN__)
52
 
/* Need to use _vsnprintf() with VS2003 */
53
 
#define vsnprintf _vsnprintf
54
 
#endif 
55
 
 
56
 
MS_CVSID("$Id: mapdebug.c 7923 2008-09-23 17:58:55Z dmorissette $")
 
51
MS_CVSID("$Id: mapdebug.c 11503 2011-04-07 19:56:16Z dmorissette $")
57
52
 
58
53
 
59
54
#ifndef USE_THREAD
97
92
        debugInfoObj *new_link;
98
93
 
99
94
        new_link = (debugInfoObj *) malloc(sizeof(debugInfoObj));
100
 
        new_link->next = debuginfo_list;
101
 
        new_link->thread_id = thread_id;
102
 
        new_link->global_debug_level = MS_DEBUGLEVEL_ERRORSONLY;
103
 
        new_link->debug_mode = MS_DEBUGMODE_OFF;
104
 
        new_link->errorfile = NULL;
105
 
        new_link->fp = NULL;
 
95
        if (new_link != NULL) 
 
96
        {
 
97
            new_link->next = debuginfo_list;
 
98
            new_link->thread_id = thread_id;
 
99
            new_link->global_debug_level = MS_DEBUGLEVEL_ERRORSONLY;
 
100
            new_link->debug_mode = MS_DEBUGMODE_OFF;
 
101
            new_link->errorfile = NULL;
 
102
            new_link->fp = NULL;
 
103
        } else
 
104
            msSetError(MS_MEMERR, "Out of memory allocating %u bytes.\n", "msGetDebugInfoObj()", sizeof(debugInfoObj));
106
105
 
107
106
        debuginfo_list = new_link;
108
107
    }
130
129
**
131
130
** Set output target, ready to write to it, open file if necessary
132
131
**
 
132
** If pszRelToPath != NULL then we will try to make the value relative to 
 
133
** this path if it is not absolute already and it's not one of the special
 
134
** values (stderr, stdout, windowsdebug)
 
135
**
133
136
** Returns MS_SUCCESS/MS_FAILURE
134
137
*/
135
 
int msSetErrorFile(const char *pszErrorFile)
 
138
int msSetErrorFile(const char *pszErrorFile, const char *pszRelToPath)
136
139
{
 
140
    char extended_path[MS_MAXPATHLEN];
137
141
    debugInfoObj *debuginfo = msGetDebugInfoObj();
138
142
 
139
 
    if (debuginfo->errorfile && pszErrorFile &&
 
143
    if (strcmp(pszErrorFile, "stderr") != 0 &&
 
144
        strcmp(pszErrorFile, "stdout") != 0 &&
 
145
        strcmp(pszErrorFile, "windowsdebug") != 0)
 
146
    {
 
147
        /* Try to make the path relative */
 
148
        if(msBuildPath(extended_path, pszRelToPath, pszErrorFile) == NULL)
 
149
            return MS_FAILURE;
 
150
        pszErrorFile = extended_path;
 
151
    }
 
152
 
 
153
    if (debuginfo && debuginfo->errorfile && pszErrorFile &&
140
154
        strcmp(debuginfo->errorfile, pszErrorFile) == 0)
141
155
    {
142
156
        /* Nothing to do, already writing to the right place */
153
167
    if (strcmp(pszErrorFile, "stderr") == 0)
154
168
    {
155
169
        debuginfo->fp = stderr;
156
 
        debuginfo->errorfile = strdup(pszErrorFile);
 
170
        debuginfo->errorfile = msStrdup(pszErrorFile);
157
171
        debuginfo->debug_mode = MS_DEBUGMODE_STDERR;
158
172
#if defined(NEED_NONBLOCKING_STDERR) && !defined(USE_MAPIO) && !defined(_WIN32)
159
173
        fcntl(fileno(stderr), F_SETFL, O_NONBLOCK);
163
177
    else if (strcmp(pszErrorFile, "stdout") == 0)
164
178
    {
165
179
        debuginfo->fp = stdout;
166
 
        debuginfo->errorfile = strdup(pszErrorFile);
 
180
        debuginfo->errorfile = msStrdup(pszErrorFile);
167
181
        debuginfo->debug_mode = MS_DEBUGMODE_STDOUT;
168
182
    }
169
183
    else if (strcmp(pszErrorFile, "windowsdebug") == 0)
170
184
    {
171
185
#ifdef _WIN32
172
 
        debuginfo->errorfile = strdup(pszErrorFile);
 
186
        debuginfo->errorfile = msStrdup(pszErrorFile);
173
187
        debuginfo->fp = NULL;
174
188
        debuginfo->debug_mode = MS_DEBUGMODE_WINDOWSDEBUG;
175
189
#else
185
199
            msSetError(MS_MISCERR, "Failed to open MS_ERRORFILE %s", "msSetErrorFile()", pszErrorFile);
186
200
            return MS_FAILURE;
187
201
        }
188
 
        debuginfo->errorfile = strdup(pszErrorFile);
 
202
        debuginfo->errorfile = msStrdup(pszErrorFile);
189
203
        debuginfo->debug_mode = MS_DEBUGMODE_FILE;
190
204
    }
191
205
 
272
286
 
273
287
    if( (val=getenv( "MS_ERRORFILE" )) != NULL )
274
288
    {
275
 
        if ( msSetErrorFile(val) != MS_SUCCESS )
 
289
        if ( msSetErrorFile(val, NULL) != MS_SUCCESS )
276
290
            return MS_FAILURE;
277
291
    }
278
292