sedna 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → CHANGES.rdoc} +9 -0
- data/{README → README.rdoc} +23 -25
- data/Rakefile +32 -9
- data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
- data/ext/{sedna.c → sedna/sedna.c} +48 -40
- data/test/sedna_test.rb +9 -9
- data/vendor/sedna/AUTHORS +18 -0
- data/vendor/sedna/COPYRIGHT +90 -0
- data/vendor/sedna/LICENSE +202 -0
- data/vendor/sedna/Makefile.include +423 -0
- data/vendor/sedna/Makefile.platform +31 -0
- data/vendor/sedna/depend.sed +48 -0
- data/vendor/sedna/driver/c/Makefile +98 -0
- data/vendor/sedna/driver/c/libsedna.c +1998 -0
- data/vendor/sedna/driver/c/libsedna.h +199 -0
- data/vendor/sedna/driver/c/sednamt.def +21 -0
- data/vendor/sedna/driver/c/sp_defs.h +186 -0
- data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
- data/vendor/sedna/kernel/common/IntHash.h +314 -0
- data/vendor/sedna/kernel/common/IntList.h +224 -0
- data/vendor/sedna/kernel/common/Makefile +30 -0
- data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
- data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
- data/vendor/sedna/kernel/common/XptrHash.h +435 -0
- data/vendor/sedna/kernel/common/argtable.c +972 -0
- data/vendor/sedna/kernel/common/argtable.h +896 -0
- data/vendor/sedna/kernel/common/base.cpp +339 -0
- data/vendor/sedna/kernel/common/base.h +226 -0
- data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
- data/vendor/sedna/kernel/common/bit_set.h +55 -0
- data/vendor/sedna/kernel/common/commutil.h +67 -0
- data/vendor/sedna/kernel/common/config.h +62 -0
- data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
- data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
- data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
- data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
- data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
- data/vendor/sedna/kernel/common/gmm.cpp +192 -0
- data/vendor/sedna/kernel/common/gmm.h +29 -0
- data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
- data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
- data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
- data/vendor/sedna/kernel/common/lm_base.h +90 -0
- data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
- data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
- data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
- data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
- data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
- data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
- data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
- data/vendor/sedna/kernel/common/pping.cpp +672 -0
- data/vendor/sedna/kernel/common/pping.h +119 -0
- data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
- data/vendor/sedna/kernel/common/rcv_test.h +19 -0
- data/vendor/sedna/kernel/common/sedna.c +128 -0
- data/vendor/sedna/kernel/common/sedna.h +49 -0
- data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
- data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
- data/vendor/sedna/kernel/common/sp.c +93 -0
- data/vendor/sedna/kernel/common/sp.h +36 -0
- data/vendor/sedna/kernel/common/st/Makefile +20 -0
- data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
- data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
- data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
- data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
- data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
- data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
- data/vendor/sedna/kernel/common/tr_debug.h +22 -0
- data/vendor/sedna/kernel/common/u/Makefile +14 -0
- data/vendor/sedna/kernel/common/u/u.c +268 -0
- data/vendor/sedna/kernel/common/u/u.h +715 -0
- data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
- data/vendor/sedna/kernel/common/u/udl.h +31 -0
- data/vendor/sedna/kernel/common/u/uevent.c +406 -0
- data/vendor/sedna/kernel/common/u/uevent.h +71 -0
- data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
- data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
- data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
- data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
- data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
- data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
- data/vendor/sedna/kernel/common/u/ummap.h +60 -0
- data/vendor/sedna/kernel/common/u/umutex.c +145 -0
- data/vendor/sedna/kernel/common/u/umutex.h +65 -0
- data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
- data/vendor/sedna/kernel/common/u/upipe.h +74 -0
- data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
- data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
- data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
- data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
- data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
- data/vendor/sedna/kernel/common/u/usem.c +891 -0
- data/vendor/sedna/kernel/common/u/usem.h +83 -0
- data/vendor/sedna/kernel/common/u/ushm.c +222 -0
- data/vendor/sedna/kernel/common/u/ushm.h +46 -0
- data/vendor/sedna/kernel/common/u/usocket.c +541 -0
- data/vendor/sedna/kernel/common/u/usocket.h +118 -0
- data/vendor/sedna/kernel/common/u/usystem.c +57 -0
- data/vendor/sedna/kernel/common/u/usystem.h +46 -0
- data/vendor/sedna/kernel/common/u/uthread.c +259 -0
- data/vendor/sedna/kernel/common/u/uthread.h +95 -0
- data/vendor/sedna/kernel/common/u/utime.c +65 -0
- data/vendor/sedna/kernel/common/u/utime.h +40 -0
- data/vendor/sedna/kernel/common/u/uutils.c +142 -0
- data/vendor/sedna/kernel/common/u/uutils.h +65 -0
- data/vendor/sedna/kernel/common/ugc.cpp +156 -0
- data/vendor/sedna/kernel/common/ugc.h +15 -0
- data/vendor/sedna/kernel/common/utils.cpp +156 -0
- data/vendor/sedna/kernel/common/utils.h +133 -0
- data/vendor/sedna/kernel/common/version.c +16 -0
- data/vendor/sedna/kernel/common/version.h +21 -0
- data/vendor/sedna/kernel/common/wustructures.h +18 -0
- data/vendor/sedna/kernel/common/wutypes.h +34 -0
- data/vendor/sedna/kernel/common/xptr.cpp +17 -0
- data/vendor/sedna/kernel/common/xptr.h +211 -0
- data/vendor/sedna/ver +1 -0
- metadata +142 -14
@@ -0,0 +1,64 @@
|
|
1
|
+
#include <string.h>
|
2
|
+
#include <assert.h>
|
3
|
+
#include "stacktrace.h"
|
4
|
+
|
5
|
+
static const char *GetFileNameFromFilepath(const char *filepath);
|
6
|
+
|
7
|
+
int PrintStackFrameInfo(SnprintfLikeProc proc,
|
8
|
+
char *buf,
|
9
|
+
size_t count,
|
10
|
+
int frame,
|
11
|
+
const StackFrameInfo *frameInfo,
|
12
|
+
int reserved)
|
13
|
+
{
|
14
|
+
static const char
|
15
|
+
*fullFmt = "#%-3d %s -- %s -- %s:%d\n",/* #0 function -- module.exe -- file.cpp:10 */
|
16
|
+
*nomodFmt = "#%-3d %s -- %s:%d\n", /* #1 procedur -- file.cpp:10 */
|
17
|
+
*nolnFmt = "#%-3d %s -- %s\n", /* #2 foofunct -- module.exe */
|
18
|
+
*nosrcFmt = "#%-3d %08p -- %s\n", /* #3 4000E7BC -- module.exe */
|
19
|
+
*minFmt = "#%-3d %08p\n"; /* #4 4000E7A0 */
|
20
|
+
|
21
|
+
int result = -1;
|
22
|
+
const char *module = NULL, *file = NULL, *function=NULL;
|
23
|
+
|
24
|
+
assert(frameInfo && proc);
|
25
|
+
function = frameInfo->function;
|
26
|
+
module = GetFileNameFromFilepath(frameInfo->module);
|
27
|
+
file = GetFileNameFromFilepath(frameInfo->file);
|
28
|
+
|
29
|
+
if (module && file && function)
|
30
|
+
{
|
31
|
+
result = proc(buf, count, fullFmt, frame, function, module, file, frameInfo->line);
|
32
|
+
}
|
33
|
+
else if (file && function)
|
34
|
+
{
|
35
|
+
result = proc(buf, count, nomodFmt, frame, function, file, frameInfo->line);
|
36
|
+
}
|
37
|
+
else if (module && function)
|
38
|
+
{
|
39
|
+
result = proc(buf, count, nolnFmt, frame, function, module);
|
40
|
+
}
|
41
|
+
else if (module)
|
42
|
+
{
|
43
|
+
result = proc(buf, count, nosrcFmt, frame, frameInfo->addr, module);
|
44
|
+
}
|
45
|
+
else
|
46
|
+
{
|
47
|
+
result = proc(buf, count, minFmt, frame, frameInfo->addr);
|
48
|
+
}
|
49
|
+
|
50
|
+
return result;
|
51
|
+
}
|
52
|
+
|
53
|
+
static const char *GetFileNameFromFilepath(const char *filepath)
|
54
|
+
{
|
55
|
+
const char *result = NULL, *temp = filepath;
|
56
|
+
|
57
|
+
while (filepath && temp)
|
58
|
+
{
|
59
|
+
result = temp;
|
60
|
+
temp = strpbrk(temp,"/\\");
|
61
|
+
if (temp) ++temp;
|
62
|
+
}
|
63
|
+
return result;
|
64
|
+
}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
/*
|
2
|
+
* File: tr_debug.cpp
|
3
|
+
* Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
#include <string>
|
7
|
+
|
8
|
+
#include "common/sedna.h"
|
9
|
+
|
10
|
+
#include "common/u/uhdd.h"
|
11
|
+
#include "common/base.h"
|
12
|
+
#include "common/u/usem.h"
|
13
|
+
|
14
|
+
using namespace std;
|
15
|
+
|
16
|
+
UFile debug_f;
|
17
|
+
string debug_file_path;
|
18
|
+
USemaphore debug_sem;
|
19
|
+
|
20
|
+
//#define DEBUG_TR_ON
|
21
|
+
|
22
|
+
void INIT_DEBUG_LOG(const char* db_name)
|
23
|
+
{
|
24
|
+
#ifdef DEBUG_TR_ON
|
25
|
+
|
26
|
+
debug_file_path = string(SEDNA_DATA) + "\\data\\" + string(db_name) + "_files\\" + string(db_name) + ".dlog";
|
27
|
+
debug_f = uOpenFile(debug_file_path.c_str(), U_SHARE_READ | U_SHARE_WRITE, U_READ_WRITE, U_WRITE_THROUGH);
|
28
|
+
|
29
|
+
if (debug_f == U_INVALID_FD)
|
30
|
+
throw USER_EXCEPTION2(SE4042, debug_file_path.c_str());
|
31
|
+
|
32
|
+
if (uSetFilePointer(debug_f, 0, NULL, U_FILE_END) == 0)
|
33
|
+
throw USER_EXCEPTION2(SE4046, debug_file_path.c_str());
|
34
|
+
|
35
|
+
if ( 0 != USemaphoreCreate(&debug_sem, 1, 1, CHARISMA_TRANSACTIONS_DEBUG_LOG_PROTECTION))
|
36
|
+
throw USER_EXCEPTION2(SE4010, "CHARISMA_TRANSACTIONS_DEBUG_LOG_PROTECTION");
|
37
|
+
#endif
|
38
|
+
}
|
39
|
+
|
40
|
+
void INIT_DEBUG_LOG2(const char* db_name)
|
41
|
+
{
|
42
|
+
#ifdef DEBUG_TR_ON
|
43
|
+
|
44
|
+
debug_file_path = string(SEDNA_DATA) + "\\data\\" + string(db_name) + "_files\\" + string(db_name) + ".dlog";
|
45
|
+
debug_f = uOpenFile(debug_file_path.c_str(), U_SHARE_READ | U_SHARE_WRITE, U_READ_WRITE, U_WRITE_THROUGH);
|
46
|
+
|
47
|
+
if (debug_f == U_INVALID_FD)
|
48
|
+
throw USER_EXCEPTION2(SE4042, debug_file_path.c_str());
|
49
|
+
|
50
|
+
if (uSetFilePointer(debug_f, 0, NULL, U_FILE_END) == 0)
|
51
|
+
throw USER_EXCEPTION2(SE4046, debug_file_path.c_str());
|
52
|
+
|
53
|
+
if ( 0 != USemaphoreOpen(&debug_sem, CHARISMA_TRANSACTIONS_DEBUG_LOG_PROTECTION))
|
54
|
+
throw USER_EXCEPTION2(SE4012, "CHARISMA_TRANSACTIONS_DEBUG_LOG_PROTECTION");
|
55
|
+
#endif
|
56
|
+
}
|
57
|
+
|
58
|
+
void CREATE_DEBUG_LOG(const char* db_name)
|
59
|
+
{
|
60
|
+
#ifdef DEBUG_TR_ON
|
61
|
+
debug_file_path = string(SEDNA_DATA) + "\\data\\" + string(db_name) + "_files\\" + string(db_name) + ".dlog";
|
62
|
+
debug_f = uCreateFile(debug_file_path.c_str(), U_SHARE_READ | U_SHARE_WRITE, U_READ_WRITE, U_WRITE_THROUGH);
|
63
|
+
if (debug_f == U_INVALID_FD)
|
64
|
+
throw USER_EXCEPTION2(SE4040, debug_file_path.c_str());
|
65
|
+
|
66
|
+
if ( 0 != USemaphoreCreate(&debug_sem, 1, 1, CHARISMA_TRANSACTIONS_DEBUG_LOG_PROTECTION))
|
67
|
+
throw USER_EXCEPTION2(SE4010, "CHARISMA_TRANSACTIONS_DEBUG_LOG_PROTECTION");
|
68
|
+
|
69
|
+
#endif
|
70
|
+
}
|
71
|
+
|
72
|
+
void RELEASE_DEBUG_LOG()
|
73
|
+
{
|
74
|
+
#ifdef DEBUG_TR_ON
|
75
|
+
if (uCloseFile(debug_f) == 0)
|
76
|
+
throw USER_EXCEPTION2(SE4043, debug_file_path.c_str());
|
77
|
+
|
78
|
+
if (USemaphoreRelease(debug_sem) != 0)
|
79
|
+
throw USER_EXCEPTION2(SE4011, "CHARISMA_TRANSACTIONS_DEBUG_LOG_PROTECTION");
|
80
|
+
#endif
|
81
|
+
}
|
82
|
+
|
83
|
+
void RELEASE_DEBUG_LOG2()
|
84
|
+
{
|
85
|
+
#ifdef DEBUG_TR_ON
|
86
|
+
if (uCloseFile(debug_f) == 0)
|
87
|
+
throw USER_EXCEPTION2(SE4043, debug_file_path.c_str());
|
88
|
+
|
89
|
+
if (USemaphoreClose(debug_sem) != 0)
|
90
|
+
throw USER_EXCEPTION2(SE4013, "CHARISMA_TRANSACTIONS_DEBUG_LOG_PROTECTION");
|
91
|
+
#endif
|
92
|
+
}
|
93
|
+
|
94
|
+
void WRITE_DEBUG_LOG(const char* msg)
|
95
|
+
{
|
96
|
+
#ifdef DEBUG_TR_ON
|
97
|
+
int res;
|
98
|
+
int written;
|
99
|
+
if ( 0 != USemaphoreDown(debug_sem))
|
100
|
+
throw USER_EXCEPTION2(SE4015, "CHARISMA_TRANSACTIONS_DEBUG_LOG_PROTECTION");
|
101
|
+
|
102
|
+
res = uWriteFile(debug_f, msg, strlen(msg), &written);
|
103
|
+
|
104
|
+
if ( 0 != USemaphoreUp(debug_sem))
|
105
|
+
throw USER_EXCEPTION2(SE4014, "CHARISMA_TRANSACTIONS_DEBUG_LOG_PROTECTION");
|
106
|
+
|
107
|
+
if (res == 0 || written != strlen(msg))
|
108
|
+
throw USER_EXCEPTION2(SE4045, debug_file_path.c_str());
|
109
|
+
#endif
|
110
|
+
}
|
111
|
+
|
112
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
* File: tr_debug.h
|
3
|
+
* Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifndef _TR_DEBUG_H_
|
7
|
+
#define _TR_DEBUG_H_
|
8
|
+
|
9
|
+
void INIT_DEBUG_LOG(const char* db_name);
|
10
|
+
|
11
|
+
void INIT_DEBUG_LOG2(const char* db_name);
|
12
|
+
|
13
|
+
void CREATE_DEBUG_LOG(const char* db_name);
|
14
|
+
|
15
|
+
void RELEASE_DEBUG_LOG();
|
16
|
+
|
17
|
+
void RELEASE_DEBUG_LOG2();
|
18
|
+
|
19
|
+
void WRITE_DEBUG_LOG(const char* msg);
|
20
|
+
|
21
|
+
#endif
|
22
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#
|
2
|
+
# Makefile for u (GNU make)
|
3
|
+
#
|
4
|
+
|
5
|
+
PP = ../../..
|
6
|
+
|
7
|
+
include $(PP)/Makefile.include
|
8
|
+
|
9
|
+
OBJS = u$(OBJ_EXT) uhdd$(OBJ_EXT) ummap$(OBJ_EXT) umutex$(OBJ_EXT) \
|
10
|
+
upipe$(OBJ_EXT) uprocess$(OBJ_EXT) usecurity$(OBJ_EXT) usem$(OBJ_EXT) \
|
11
|
+
ushm$(OBJ_EXT) usocket$(OBJ_EXT) usystem$(OBJ_EXT) uthread$(OBJ_EXT) \
|
12
|
+
utime$(OBJ_EXT) uutils$(OBJ_EXT) uevent$(OBJ_EXT) ugnames$(OBJ_EXT)
|
13
|
+
|
14
|
+
include $(PP)/Makefile.pseudolib
|
@@ -0,0 +1,268 @@
|
|
1
|
+
/*
|
2
|
+
* File: u.c
|
3
|
+
* Copyright (C) 2005 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
#include "common/u/u.h"
|
7
|
+
#include "common/errdbg/d_printf.h"
|
8
|
+
|
9
|
+
#if !(defined(SE_NO_EVENT_LOG))
|
10
|
+
#include "common/errdbg/event_log.h"
|
11
|
+
#endif
|
12
|
+
|
13
|
+
|
14
|
+
static char ustrerror_buf[256];
|
15
|
+
|
16
|
+
|
17
|
+
void uSleep(unsigned int secs, sys_call_error_fun fun)
|
18
|
+
{
|
19
|
+
#ifdef _WIN32
|
20
|
+
Sleep(secs * 1000);
|
21
|
+
#else
|
22
|
+
sleep(secs);
|
23
|
+
#endif
|
24
|
+
}
|
25
|
+
|
26
|
+
#if defined(DARWIN)
|
27
|
+
int u_is_nan(double d)
|
28
|
+
{
|
29
|
+
return isnan(d);
|
30
|
+
}
|
31
|
+
|
32
|
+
bool u_is_neg_inf(double d)
|
33
|
+
{
|
34
|
+
return (isinf(d) && (d) < 0.0);
|
35
|
+
}
|
36
|
+
|
37
|
+
bool u_is_pos_inf(double d)
|
38
|
+
{
|
39
|
+
return (isinf(d) && (d) > 0.0);
|
40
|
+
}
|
41
|
+
#endif
|
42
|
+
|
43
|
+
/* ustrerror is not thread safe */
|
44
|
+
char* ustrerror(int errnum)
|
45
|
+
{
|
46
|
+
#ifdef _WIN32
|
47
|
+
DWORD res = 0;
|
48
|
+
|
49
|
+
res = FormatMessage(
|
50
|
+
FORMAT_MESSAGE_FROM_SYSTEM |
|
51
|
+
FORMAT_MESSAGE_IGNORE_INSERTS,
|
52
|
+
NULL,
|
53
|
+
errnum,
|
54
|
+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
55
|
+
(LPTSTR)ustrerror_buf,
|
56
|
+
255,
|
57
|
+
NULL);
|
58
|
+
|
59
|
+
if (!res)
|
60
|
+
sprintf(ustrerror_buf, "unrecognized error code (%d)", errnum);
|
61
|
+
|
62
|
+
return ustrerror_buf;
|
63
|
+
#else
|
64
|
+
return strerror(errnum);
|
65
|
+
#endif
|
66
|
+
}
|
67
|
+
|
68
|
+
int ustrerror_r(int errnum, char *buf, size_t n)
|
69
|
+
{
|
70
|
+
#ifdef _WIN32
|
71
|
+
DWORD res = 0;
|
72
|
+
|
73
|
+
memset(buf, '\0', n);
|
74
|
+
res = FormatMessage(
|
75
|
+
FORMAT_MESSAGE_FROM_SYSTEM |
|
76
|
+
FORMAT_MESSAGE_IGNORE_INSERTS,
|
77
|
+
NULL,
|
78
|
+
errnum,
|
79
|
+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
80
|
+
(LPTSTR)buf,
|
81
|
+
n - 1,
|
82
|
+
NULL);
|
83
|
+
|
84
|
+
if (!res)
|
85
|
+
sprintf(buf, "unrecognized error code (%d)", errnum);
|
86
|
+
else
|
87
|
+
{
|
88
|
+
if ((res > 1) && (buf[res - 1] == (char)10) && (buf[res - 2] == (char)13))
|
89
|
+
buf[res - 1] = buf[res - 2] = '\0';
|
90
|
+
}
|
91
|
+
|
92
|
+
return 0;
|
93
|
+
#else
|
94
|
+
/* There is actually 2 incompatible strerror_r functions -
|
95
|
+
cannot safely rely on return value which is either integer
|
96
|
+
(nonzero indicates failure) or char pointer (NULL indicates
|
97
|
+
failure).
|
98
|
+
*/
|
99
|
+
memset(buf, '\0', n);
|
100
|
+
strncpy(buf, "Failed to obtain error message", n - 1);
|
101
|
+
strerror_r(errnum, buf, n);
|
102
|
+
return 0;
|
103
|
+
#endif
|
104
|
+
}
|
105
|
+
|
106
|
+
int uerrno(const char *funcname, const void* arg)
|
107
|
+
{
|
108
|
+
#ifdef _WIN32
|
109
|
+
#if 0
|
110
|
+
if (strcmp(funcname, "WSAStartup") == 0)
|
111
|
+
{
|
112
|
+
return (arg ? *(int*)arg : 0);
|
113
|
+
}
|
114
|
+
else if ( strcmp(funcname, "WSACleanup") == 0
|
115
|
+
|| strcmp(funcname, "socket") == 0
|
116
|
+
|| strcmp(funcname, "gethostbyname") == 0
|
117
|
+
|| strcmp(funcname, "bind") == 0
|
118
|
+
|| strcmp(funcname, "connect") == 0
|
119
|
+
|| strcmp(funcname, "setsockopt") == 0
|
120
|
+
|| strcmp(funcname, "getsockopt") == 0
|
121
|
+
|| strcmp(funcname, "listen") == 0
|
122
|
+
|| strcmp(funcname, "accept") == 0
|
123
|
+
|| strcmp(funcname, "recv") == 0
|
124
|
+
|| strcmp(funcname, "send") == 0
|
125
|
+
|| strcmp(funcname, "closesocket") == 0
|
126
|
+
|| strcmp(funcname, "shutdown") == 0
|
127
|
+
|| strcmp(funcname, "select") == 0)
|
128
|
+
{
|
129
|
+
return WSAGetLastError();
|
130
|
+
}
|
131
|
+
else
|
132
|
+
{
|
133
|
+
return GetLastError();
|
134
|
+
}
|
135
|
+
#endif
|
136
|
+
/* WSAGetLastError() is an alias for GetLastError() */
|
137
|
+
return GetLastError();
|
138
|
+
#else
|
139
|
+
return errno;
|
140
|
+
#endif
|
141
|
+
}
|
142
|
+
|
143
|
+
void uperror(const char *s)
|
144
|
+
{
|
145
|
+
#ifdef _WIN32
|
146
|
+
char buf[256];
|
147
|
+
ustrerror_r(uerrno(s, NULL), buf, 256);
|
148
|
+
fprintf(stderr, "%s: %s\n", s, buf);
|
149
|
+
#else
|
150
|
+
perror(s);
|
151
|
+
#endif
|
152
|
+
}
|
153
|
+
|
154
|
+
void __sys_call_error(const char *filename, int lineno, const char *funcname, const char *sys_call, const void* arg)
|
155
|
+
{
|
156
|
+
#if !(defined(SE_NO_EVENT_LOG))
|
157
|
+
char buf[256];
|
158
|
+
int code = uerrno(funcname, arg);
|
159
|
+
#endif
|
160
|
+
|
161
|
+
d_perror(sys_call);
|
162
|
+
|
163
|
+
#if !(defined(SE_NO_EVENT_LOG))
|
164
|
+
ustrerror_r(code, buf, 256);
|
165
|
+
event_log_short_msg(EL_SYS,
|
166
|
+
filename,
|
167
|
+
lineno,
|
168
|
+
funcname,
|
169
|
+
"%s (code = %d): %s",
|
170
|
+
sys_call,
|
171
|
+
code,
|
172
|
+
buf);
|
173
|
+
#endif
|
174
|
+
}
|
175
|
+
|
176
|
+
void __sys_call_error_nop(const char *filename, int lineno, const char *funcname, const char *sys_call, const void* arg)
|
177
|
+
{
|
178
|
+
}
|
179
|
+
|
180
|
+
|
181
|
+
/* Simply writes message to the event log
|
182
|
+
* Intended to be used inside u-functions to
|
183
|
+
* write additional error condition information.
|
184
|
+
*/
|
185
|
+
void
|
186
|
+
__u_call_error(const char *filename,
|
187
|
+
int lineno,
|
188
|
+
const char *funcname,
|
189
|
+
const char *message)
|
190
|
+
{
|
191
|
+
#if !(defined(SE_NO_EVENT_LOG))
|
192
|
+
event_log_short_msg(EL_ERROR,
|
193
|
+
filename,
|
194
|
+
lineno,
|
195
|
+
funcname,
|
196
|
+
message);
|
197
|
+
#endif /* !SE_NO_EVENT_LOG */
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
int uNotInheritDescriptor(UHANDLE h, sys_call_error_fun fun)
|
203
|
+
{
|
204
|
+
#ifdef _WIN32
|
205
|
+
if (SetHandleInformation(h, HANDLE_FLAG_INHERIT, 0) == 0)
|
206
|
+
{
|
207
|
+
sys_call_error("SetHandleInformation");
|
208
|
+
return -1;
|
209
|
+
}
|
210
|
+
else
|
211
|
+
return 0;
|
212
|
+
#else
|
213
|
+
|
214
|
+
if (fcntl(h, F_SETFD, FD_CLOEXEC) == -1)
|
215
|
+
{
|
216
|
+
sys_call_error("fcntl");
|
217
|
+
return -1;
|
218
|
+
}
|
219
|
+
else
|
220
|
+
return 0;
|
221
|
+
#endif
|
222
|
+
}
|
223
|
+
|
224
|
+
|
225
|
+
int uMakeLowLevelDescriptorNonInheritable(FILE* f, sys_call_error_fun fun)
|
226
|
+
{
|
227
|
+
int fd;
|
228
|
+
|
229
|
+
#ifdef _WIN32
|
230
|
+
HANDLE hnd;
|
231
|
+
|
232
|
+
fd = _fileno(f);
|
233
|
+
if(fd == -1)
|
234
|
+
{
|
235
|
+
sys_call_error("_fileno");
|
236
|
+
return -1;
|
237
|
+
}
|
238
|
+
|
239
|
+
hnd = (HANDLE)_get_osfhandle(fd);
|
240
|
+
if(hnd == INVALID_HANDLE_VALUE)
|
241
|
+
{
|
242
|
+
sys_call_error("_get_osfhandle");
|
243
|
+
return -1;
|
244
|
+
}
|
245
|
+
|
246
|
+
if(SetHandleInformation(hnd, HANDLE_FLAG_INHERIT, 0) == 0)
|
247
|
+
{
|
248
|
+
sys_call_error("SetHandleInformation");
|
249
|
+
return -1;
|
250
|
+
}
|
251
|
+
return 0;
|
252
|
+
#else
|
253
|
+
fd = fileno(f);
|
254
|
+
if(fd == -1)
|
255
|
+
{
|
256
|
+
sys_call_error("fileno");
|
257
|
+
return -1;
|
258
|
+
}
|
259
|
+
|
260
|
+
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
|
261
|
+
{
|
262
|
+
sys_call_error("fcntl");
|
263
|
+
return -1;
|
264
|
+
}
|
265
|
+
return 0;
|
266
|
+
#endif
|
267
|
+
}
|
268
|
+
|