Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Tarassov2013-11-14 04:36:00 -0500
committerEugene Tarassov2013-11-14 04:36:00 -0500
commit44363245703cedf17e9a034fed41588cfae59fe9 (patch)
tree4ff655bff15930fd391f69695a7ba3904a6e33af
parente87340bfc756b971652a365a131d876f3846e8be (diff)
downloadorg.eclipse.tcf.agent-44363245703cedf17e9a034fed41588cfae59fe9.tar.gz
org.eclipse.tcf.agent-44363245703cedf17e9a034fed41588cfae59fe9.tar.xz
org.eclipse.tcf.agent-44363245703cedf17e9a034fed41588cfae59fe9.zip
TCF Agent: fixed Cygwin build - _WIN32 no longer set on Cygwin
-rw-r--r--agent/machine/x86_64/tcf/cpudefs-mdep.c4
-rw-r--r--agent/system/GNU/Linux/tcf/context-linux.c10
-rw-r--r--agent/system/Windows/tcf/context-win32.c10
-rw-r--r--agent/system/Windows/tcf/pthreads-win32.c2
-rw-r--r--agent/system/Windows/tcf/windbgcache.h79
-rw-r--r--agent/tcf/config.h2
-rw-r--r--agent/tcf/framework/asyncreq.c4
-rw-r--r--agent/tcf/framework/asyncreq.h4
-rw-r--r--agent/tcf/framework/channel_pipe.c2
-rw-r--r--agent/tcf/framework/channel_tcp.c20
-rw-r--r--agent/tcf/framework/errors.c8
-rw-r--r--agent/tcf/framework/errors.h4
-rw-r--r--agent/tcf/framework/events.c2
-rw-r--r--agent/tcf/framework/inputbuf.c2
-rw-r--r--agent/tcf/framework/ip_ifc.c2
-rw-r--r--agent/tcf/framework/mdep-inet.h7
-rw-r--r--agent/tcf/framework/mdep.c16
-rw-r--r--agent/tcf/framework/mdep.h6
-rw-r--r--agent/tcf/framework/plugins.c2
-rw-r--r--agent/tcf/framework/proxy.c6
-rw-r--r--agent/tcf/framework/signames.c2
-rw-r--r--agent/tcf/framework/trace.c6
-rw-r--r--agent/tcf/framework/trace.h2
-rw-r--r--agent/tcf/framework/waitpid.c2
-rw-r--r--agent/tcf/main/main.c8
-rw-r--r--agent/tcf/main/main_lua.c2
-rw-r--r--agent/tcf/main/test.c8
-rw-r--r--agent/tcf/services/discovery_udp.c2
-rw-r--r--agent/tcf/services/filesystem.c36
-rw-r--r--agent/tcf/services/linenumbers_mux.c2
-rw-r--r--agent/tcf/services/processes.c38
-rw-r--r--agent/tcf/services/runctrl.c2
-rw-r--r--agent/tcf/services/sysmon.c2
-rw-r--r--agent/tcf/services/tcf_elf.c8
-rw-r--r--agent/tcf/services/tcf_elf.h4
-rw-r--r--agent/tcf/services/terminals.c8
36 files changed, 174 insertions, 150 deletions
diff --git a/agent/machine/x86_64/tcf/cpudefs-mdep.c b/agent/machine/x86_64/tcf/cpudefs-mdep.c
index e6fb24fa..79f07368 100644
--- a/agent/machine/x86_64/tcf/cpudefs-mdep.c
+++ b/agent/machine/x86_64/tcf/cpudefs-mdep.c
@@ -39,7 +39,7 @@
#define REG_OFFSET(name) offsetof(REG_SET, name)
static RegisterDefinition regs_def[] = {
-#if defined(_WIN32) && defined(__i386__)
+#if (defined(_WIN32) || defined(__CYGWIN__)) && defined(__i386__)
# define REG_SP Esp
# define REG_BP Ebp
# define REG_IP Eip
@@ -108,7 +108,7 @@ static RegisterDefinition regs_def[] = {
{ "dr6", REG_OFFSET(Dr6), 4, -1, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, regs_def + 46 },
{ "dr7", REG_OFFSET(Dr7), 4, -1, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, regs_def + 46 },
-#elif defined(_WIN32) && defined(__x86_64__)
+#elif (defined(_WIN32) || defined(__CYGWIN__)) && defined(__x86_64__)
# define REG_SP Rsp
# define REG_BP Rbp
# define REG_IP Rip
diff --git a/agent/system/GNU/Linux/tcf/context-linux.c b/agent/system/GNU/Linux/tcf/context-linux.c
index fb168aef..cf8bc157 100644
--- a/agent/system/GNU/Linux/tcf/context-linux.c
+++ b/agent/system/GNU/Linux/tcf/context-linux.c
@@ -434,6 +434,7 @@ static void send_process_exited_event(Context * prs) {
send_context_exited_event(prs);
}
+#if ENABLE_Trace
static const char * get_ptrace_cmd_name(int cmd) {
switch (cmd) {
case PTRACE_CONT: return "PTRACE_CONT";
@@ -443,6 +444,7 @@ static const char * get_ptrace_cmd_name(int cmd) {
}
return "?";
}
+#endif
static int do_single_step(Context * ctx) {
uint32_t is_cont;
@@ -1274,9 +1276,8 @@ static void event_pid_stopped(pid_t pid, int signal, int event, int syscall) {
if (ext->ptrace_flags == 0) {
if (ptrace((enum __ptrace_request)PTRACE_SETOPTIONS, ext->pid, 0, PTRACE_FLAGS) < 0) {
- int err = errno;
- trace(LOG_ALWAYS, "error: ptrace(PTRACE_SETOPTIONS) failed: pid %d, error %d %s",
- ext->pid, err, errno_to_str(err));
+ trace(LOG_ALWAYS, "error: ptrace(PTRACE_SETOPTIONS) failed: pid %d, error %s",
+ ext->pid, errno_to_str(errno));
}
else {
ext->ptrace_flags = PTRACE_FLAGS;
@@ -1550,8 +1551,7 @@ static void eventpoint_at_loader(Context * ctx, void * args) {
default: assert(0);
}
if (elf_read_memory_word(ctx, file, addr, &state) < 0) {
- int error = errno;
- trace(LOG_ALWAYS, "Can't read loader state flag: %d %s", error, errno_to_str(error));
+ trace(LOG_ALWAYS, "Can't read loader state flag: %s", errno_to_str(errno));
ctx->pending_intercept = 1;
ext->loader_state = 0;
return;
diff --git a/agent/system/Windows/tcf/context-win32.c b/agent/system/Windows/tcf/context-win32.c
index ad135eac..e00791fc 100644
--- a/agent/system/Windows/tcf/context-win32.c
+++ b/agent/system/Windows/tcf/context-win32.c
@@ -19,7 +19,7 @@
#include <tcf/config.h>
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#if ENABLE_DebugContext && !ENABLE_ContextProxy
@@ -39,7 +39,11 @@
#include <tcf/services/memorymap.h>
#include <tcf/services/runctrl.h>
#include <system/Windows/tcf/context-win32.h>
-#include <system/Windows/tcf/regset.h>
+#if defined(__CYGWIN__)
+# include <system/Cygwin/tcf/regset.h>
+#else
+# include <system/Windows/tcf/regset.h>
+#endif
#include <system/Windows/tcf/windbgcache.h>
#define BREAK_TIMEOUT 100000
@@ -1485,4 +1489,4 @@ void init_contexts_sys_dep(void) {
}
#endif /* if ENABLE_DebugContext */
-#endif /* _WIN32 */
+#endif /* defined(_WIN32) || defined(__CYGWIN__) */
diff --git a/agent/system/Windows/tcf/pthreads-win32.c b/agent/system/Windows/tcf/pthreads-win32.c
index 4f7f887d..3d383e97 100644
--- a/agent/system/Windows/tcf/pthreads-win32.c
+++ b/agent/system/Windows/tcf/pthreads-win32.c
@@ -15,7 +15,7 @@
#include <tcf/config.h>
-#if defined(_WIN32) && !defined(DISABLE_PTHREADS_WIN32)
+#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(DISABLE_PTHREADS_WIN32)
#include <assert.h>
#include <tcf/framework/myalloc.h>
diff --git a/agent/system/Windows/tcf/windbgcache.h b/agent/system/Windows/tcf/windbgcache.h
index bcfb8a4e..6eeac1af 100644
--- a/agent/system/Windows/tcf/windbgcache.h
+++ b/agent/system/Windows/tcf/windbgcache.h
@@ -22,7 +22,7 @@
#include <tcf/config.h>
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(__GNUC__)
# include <imagehlp.h>
@@ -37,6 +37,9 @@ extern "C" {
#endif
#if defined(__GNUC__)
+
+#if !defined(API_VERSION_NUMBER) || API_VERSION_NUMBER < 11
+
typedef enum _IMAGEHLP_SYMBOL_TYPE_INFO {
TI_GET_SYMTAG,
TI_GET_SYMNAME,
@@ -79,41 +82,6 @@ typedef struct _TI_FINDCHILDREN_PARAMS {
ULONG ChildId[1];
} TI_FINDCHILDREN_PARAMS;
-enum SymTagEnum {
- SymTagNull,
- SymTagExe,
- SymTagCompiland,
- SymTagCompilandDetails,
- SymTagCompilandEnv,
- SymTagFunction,
- SymTagBlock,
- SymTagData,
- SymTagAnnotation,
- SymTagLabel,
- SymTagPublicSymbol,
- SymTagUDT,
- SymTagEnum,
- SymTagFunctionType,
- SymTagPointerType,
- SymTagArrayType,
- SymTagBaseType,
- SymTagTypedef,
- SymTagBaseClass,
- SymTagFriend,
- SymTagFunctionArgType,
- SymTagFuncDebugStart,
- SymTagFuncDebugEnd,
- SymTagUsingNamespace,
- SymTagVTableShape,
- SymTagVTable,
- SymTagCustom,
- SymTagThunk,
- SymTagCustomType,
- SymTagManagedType,
- SymTagDimension,
- SymTagMax
-};
-
#define SYMFLAG_VALUEPRESENT 0x00000001
#define SYMFLAG_REGISTER 0x00000008
#define SYMFLAG_REGREL 0x00000010
@@ -194,6 +162,43 @@ typedef VOID IMAGEHLP_CONTEXT, *PIMAGEHLP_CONTEXT;
typedef BOOL (CALLBACK *PSYM_ENUMERATESYMBOLS_CALLBACK)(PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext);
typedef BOOL (CALLBACK *PENUMLOADED_MODULES_CALLBACKW64)(PCWSTR ModuleName, DWORD64 ModuleBase, ULONG ModuleSize, PVOID UserContext);
+#endif
+
+enum SymTagEnum {
+ SymTagNull,
+ SymTagExe,
+ SymTagCompiland,
+ SymTagCompilandDetails,
+ SymTagCompilandEnv,
+ SymTagFunction,
+ SymTagBlock,
+ SymTagData,
+ SymTagAnnotation,
+ SymTagLabel,
+ SymTagPublicSymbol,
+ SymTagUDT,
+ SymTagEnum,
+ SymTagFunctionType,
+ SymTagPointerType,
+ SymTagArrayType,
+ SymTagBaseType,
+ SymTagTypedef,
+ SymTagBaseClass,
+ SymTagFriend,
+ SymTagFunctionArgType,
+ SymTagFuncDebugStart,
+ SymTagFuncDebugEnd,
+ SymTagUsingNamespace,
+ SymTagVTableShape,
+ SymTagVTable,
+ SymTagCustom,
+ SymTagThunk,
+ SymTagCustomType,
+ SymTagManagedType,
+ SymTagDimension,
+ SymTagMax
+};
+
#endif /* defined(__GNUC__) */
enum BasicType {
@@ -276,5 +281,5 @@ extern BOOL LocEnumerateLoadedModulesW64(HANDLE hProcess, PENUMLOADED_MODULES_CA
}
#endif
-#endif /* defined(_WIN32) */
+#endif /* defined(_WIN32) || defined(__CYGWIN__) */
#endif /* D_windbgcache */
diff --git a/agent/tcf/config.h b/agent/tcf/config.h
index 7bff1c67..a4d223c2 100644
--- a/agent/tcf/config.h
+++ b/agent/tcf/config.h
@@ -23,7 +23,7 @@
#include <tcf/framework/mdep.h>
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
# define TARGET_WINDOWS 1
# define TARGET_VXWORKS 0
# define TARGET_UNIX 0
diff --git a/agent/tcf/framework/asyncreq.c b/agent/tcf/framework/asyncreq.c
index 117ae7e9..87da96a5 100644
--- a/agent/tcf/framework/asyncreq.c
+++ b/agent/tcf/framework/asyncreq.c
@@ -24,7 +24,7 @@
#include <fcntl.h>
#include <sys/stat.h>
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#elif defined(_WRS_KERNEL)
#else
# include <sys/wait.h>
@@ -180,7 +180,7 @@ static void * worker_thread_handler(void * x) {
break;
/* Platform dependant IO methods */
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
case AsyncReqConnectPipe:
req->u.cnp.rval = ConnectNamedPipe(req->u.cnp.pipe, NULL);
if (!req->u.cnp.rval) {
diff --git a/agent/tcf/framework/asyncreq.h b/agent/tcf/framework/asyncreq.h
index 73fcb87e..3a3bad87 100644
--- a/agent/tcf/framework/asyncreq.h
+++ b/agent/tcf/framework/asyncreq.h
@@ -70,7 +70,7 @@ struct AsyncReqInfo {
int permission;
char * file_name;
struct stat statbuf;
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
DWORD win32_attrs;
#endif
/* Out */
@@ -119,7 +119,7 @@ struct AsyncReqInfo {
/* Out */
int rval;
} con;
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
struct {
/* In */
HANDLE pipe;
diff --git a/agent/tcf/framework/channel_pipe.c b/agent/tcf/framework/channel_pipe.c
index b9ce6c6f..dad5bf8d 100644
--- a/agent/tcf/framework/channel_pipe.c
+++ b/agent/tcf/framework/channel_pipe.c
@@ -19,7 +19,7 @@
#include <tcf/config.h>
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#include <fcntl.h>
#include <errno.h>
diff --git a/agent/tcf/framework/channel_tcp.c b/agent/tcf/framework/channel_tcp.c
index f4060abe..c89c025d 100644
--- a/agent/tcf/framework/channel_tcp.c
+++ b/agent/tcf/framework/channel_tcp.c
@@ -38,7 +38,7 @@
# include <openssl/ssl.h>
# include <openssl/rand.h>
# include <openssl/err.h>
-# ifdef _WIN32
+# if defined(_WIN32) || defined(__CYGWIN__)
# include <ShlObj.h>
# endif
#else
@@ -67,7 +67,7 @@
#define MSG_MORE 0
#endif
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
# define FD_SETX(a,b) FD_SET((unsigned)a, b)
# define MKDIR_MODE_TCF 0
# define MKDIR_MODE_SSL 0
@@ -87,7 +87,7 @@
#define MAX_IFC 10
#if !defined(ENABLE_OutputQueue)
-# if ENABLE_SSL || ENABLE_ContextProxy || defined(_WIN32) || defined(__linux__)
+# if ENABLE_SSL || ENABLE_ContextProxy || defined(_WIN32) || defined(__CYGWIN__) || defined(__linux__)
# define ENABLE_OutputQueue 1
# else
# define ENABLE_OutputQueue 0
@@ -173,7 +173,7 @@ static void ini_ssl(void) {
RAND_add(&ts.tv_nsec, sizeof(ts.tv_nsec), 0.1);
}
inited = 1;
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
{
WCHAR fnm[MAX_PATH];
char buf[MAX_PATH];
@@ -880,7 +880,7 @@ static ChannelTCP * create_channel(int sock, int en_ssl, int server, int unix_do
}
}
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
{
unsigned long opts = 1;
if (ioctlsocket((SOCKET)sock, FIONBIO, &opts) != 0) {
@@ -1206,7 +1206,7 @@ ChannelServer * channel_unix_server(PeerServer * ps) {
if (error) {
if (sock >= 0) closesocket(sock);
trace(LOG_ALWAYS, "Socket %s error on %s: %s", reason, localhost.sun_path, errno_to_str(error));
- errno = error;
+ set_fmt_errno(error, "Socket %s error", reason);
return NULL;
}
@@ -1263,7 +1263,7 @@ ChannelServer * channel_tcp_server(PeerServer * ps) {
reason = "create";
continue;
}
-#if !defined(_WIN32)
+#if !(defined(_WIN32) || defined(__CYGWIN__))
{
const int i = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&i, sizeof(i)) < 0) {
@@ -1312,7 +1312,7 @@ ChannelServer * channel_tcp_server(PeerServer * ps) {
loc_freeaddrinfo(reslist);
if (sock < 0) {
trace(LOG_ALWAYS, "Socket %s error: %s", reason, errno_to_str(error));
- errno = error;
+ set_fmt_errno(error, "Socket %s error", reason);
return NULL;
}
@@ -1509,14 +1509,14 @@ void generate_ssl_certificate(void) {
if (!err && (fp = fopen(fnm, "w")) == NULL) err = errno;
if (!err && !PEM_write_PKCS8PrivateKey(fp, rsa_key, NULL, NULL, 0, NULL, NULL)) err = set_ssl_errno();
if (!err && fclose(fp) != 0) err = errno;
-#ifndef _WIN32
+#if !(defined(_WIN32) || defined(__CYGWIN__))
if (!err && chmod(fnm, S_IRUSR|S_IWUSR) != 0) err = errno;
#endif
snprintf(fnm, sizeof(fnm), "%s/ssl/local.cert", tcf_dir);
if (!err && (fp = fopen(fnm, "w")) == NULL) err = errno;
if (!err && !PEM_write_X509(fp, cert)) err = set_ssl_errno();
if (!err && fclose(fp) != 0) err = errno;
-#ifndef _WIN32
+#if !(defined(_WIN32) || defined(__CYGWIN__))
if (!err && chmod(fnm, S_IRUSR|S_IWUSR) != 0) err = errno;
#endif
if (err) {
diff --git a/agent/tcf/framework/errors.c b/agent/tcf/framework/errors.c
index 4cae58d2..a96b85e0 100644
--- a/agent/tcf/framework/errors.c
+++ b/agent/tcf/framework/errors.c
@@ -42,7 +42,7 @@
#define MESSAGE_CNT (ERR_MESSAGE_MAX - ERR_MESSAGE_MIN + 1)
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
# define ERR_WINDOWS_MIN (STD_ERR_BASE + 0x10000)
# define ERR_WINDOWS_MAX (ERR_WINDOWS_MIN + 0xffff)
# define ERR_WINDOWS_CNT (ERR_WINDOWS_MAX - ERR_WINDOWS_MIN + 1)
@@ -116,7 +116,7 @@ static ErrorMessage * alloc_msg(int source) {
return m;
}
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
static char * system_strerror(DWORD error_code, HMODULE module) {
WCHAR * buf = NULL;
@@ -371,7 +371,7 @@ const char * errno_to_str(int err) {
return "Cannot get error message text: errno_to_str() must be called from the main thread";
}
}
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
if (err >= ERR_WINDOWS_MIN && err <= ERR_WINDOWS_MAX) {
if (is_dispatch_thread()) {
return system_strerror(err - ERR_WINDOWS_MIN, NULL);
@@ -521,7 +521,7 @@ ErrorReport * get_error_report(int err) {
report->pub.format = loc_strdup(errno_to_str(err));
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
if (err >= ERR_WINDOWS_MIN && err <= ERR_WINDOWS_MAX) {
add_report_prop_int(report, "AltCode", err - ERR_WINDOWS_MIN);
add_report_prop_str(report, "AltOrg", "_WIN32");
diff --git a/agent/tcf/framework/errors.h b/agent/tcf/framework/errors.h
index e39545ff..702c69c9 100644
--- a/agent/tcf/framework/errors.h
+++ b/agent/tcf/framework/errors.h
@@ -104,9 +104,9 @@ extern int set_fmt_errno(int no, const char * fmt, ...);
*/
extern int set_gai_errno(int gai_error_code);
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
/*
- * Set errno to indicate _WIN32 error code.
+ * Set errno to indicate WIN32 error code.
* This function is thread-safe - can be called from background threads.
* Return new value of errno.
*/
diff --git a/agent/tcf/framework/events.c b/agent/tcf/framework/events.c
index 5e9438a6..44cc7558 100644
--- a/agent/tcf/framework/events.c
+++ b/agent/tcf/framework/events.c
@@ -49,7 +49,7 @@ struct event_node {
void * arg;
};
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
static DWORD event_thread;
# define current_thread GetCurrentThreadId()
# define is_event_thread (event_thread == current_thread)
diff --git a/agent/tcf/framework/inputbuf.c b/agent/tcf/framework/inputbuf.c
index 2bb7463d..7ca96de1 100644
--- a/agent/tcf/framework/inputbuf.c
+++ b/agent/tcf/framework/inputbuf.c
@@ -28,7 +28,7 @@
#include <tcf/framework/inputbuf.h>
#if !defined(ENABLE_InputQueue)
-# if ENABLE_SSL || ENABLE_ContextProxy || defined(_WIN32) || defined(__linux__)
+# if ENABLE_SSL || ENABLE_ContextProxy || defined(_WIN32) || defined(__CYGWIN__) || defined(__linux__)
# define ENABLE_InputQueue 1
# else
# define ENABLE_InputQueue 0
diff --git a/agent/tcf/framework/ip_ifc.c b/agent/tcf/framework/ip_ifc.c
index 14b6e079..b339ee52 100644
--- a/agent/tcf/framework/ip_ifc.c
+++ b/agent/tcf/framework/ip_ifc.c
@@ -36,7 +36,7 @@
#endif
int build_ifclist(int sock, int max, ip_ifc_info * list) {
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
int i;
int ind;
MIB_IPADDRTABLE * info;
diff --git a/agent/tcf/framework/mdep-inet.h b/agent/tcf/framework/mdep-inet.h
index bc611221..446fcc1d 100644
--- a/agent/tcf/framework/mdep-inet.h
+++ b/agent/tcf/framework/mdep-inet.h
@@ -28,9 +28,14 @@
#if defined(__CYGWIN__)
+#include <cygwin/version.h>
+
+#if CYGWIN_VERSION_CYGWIN_CONV < 157
+
extern void __stdcall freeaddrinfo(struct addrinfo *);
extern int __stdcall getaddrinfo(const char *, const char *,
const struct addrinfo *, struct addrinfo **);
+#endif
#endif
@@ -70,7 +75,7 @@ extern int wsa_sendto(int socket, const void * buf, size_t size, int flags,
const struct sockaddr * dest_addr, socklen_t dest_size);
extern int wsa_setsockopt(int socket, int level, int opt, const char * value, int size);
extern int wsa_getsockname(int socket, struct sockaddr * name, int * size);
-extern int wsa_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout);
+extern int wsa_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);
#ifndef SHUT_WR
#define SHUT_WR SD_SEND
diff --git a/agent/tcf/framework/mdep.c b/agent/tcf/framework/mdep.c
index f23f54dc..c604836b 100644
--- a/agent/tcf/framework/mdep.c
+++ b/agent/tcf/framework/mdep.c
@@ -37,7 +37,7 @@
pthread_attr_t pthread_create_attr;
int utf8_locale = 0;
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#ifndef SIO_UDP_CONNRESET
#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12)
@@ -189,7 +189,7 @@ int wsa_select(int nfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds
int res = 0;
SetLastError(0);
WSASetLastError(0);
- res = select(nfds, readfds, writefds, exceptfds, timeout);
+ res = select(nfds, readfds, writefds, exceptfds, (PTIMEVAL)timeout);
if (res < 0) {
set_win32_errno(WSAGetLastError());
return -1;
@@ -230,7 +230,7 @@ int inet_pton(int af, const char * src, void * dst) {
return 1;
}
-#endif /* _WIN32 */
+#endif /* defined(_WIN32) || defined(__CYGWIN__)*/
#if defined(_WIN32) && !defined(__CYGWIN__)
@@ -564,7 +564,7 @@ void swap_bytes(void * buf, size_t size) {
}
}
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#include <locale.h>
#include <shlobj.h>
@@ -890,7 +890,7 @@ void ini_mdep(void) {
/** canonicalize_file_name ****************************************************/
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
char * canonicalize_file_name(const char * name) {
DWORD len;
@@ -1172,7 +1172,7 @@ const char * loc_gai_strerror(int ecode) {
return buf;
}
-#elif defined(_WIN32)
+#elif defined(_WIN32) || defined(__CYGWIN__)
const char * loc_gai_strerror(int ecode) {
WCHAR * buf = NULL;
@@ -1206,7 +1206,7 @@ const char * loc_gai_strerror(int ecode) {
#endif
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
# include <tlhelp32.h>
# ifdef _MSC_VER
# pragma warning(disable:4201) /* nonstandard extension used : nameless struct/union (in winternl.h) */
@@ -1569,7 +1569,7 @@ double str_to_double(const char * buf, char ** end) {
double res;
int n;
- while (isspace(*buf)) buf++;
+ while (isspace((unsigned char)*buf)) buf++;
if (*buf == '-') sign_val = 1;
if (sign_val || *buf == '+') buf++;
while (*buf >= '0' && *buf <= '9') {
diff --git a/agent/tcf/framework/mdep.h b/agent/tcf/framework/mdep.h
index 818dbea8..c4937a9e 100644
--- a/agent/tcf/framework/mdep.h
+++ b/agent/tcf/framework/mdep.h
@@ -28,7 +28,7 @@
#define __STDC_FORMAT_MACROS 1
#if defined(_WIN32) || defined(__CYGWIN__)
-/* MS Windows NT/XP */
+/* MS Windows */
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0501
@@ -36,6 +36,7 @@
#if defined(__CYGWIN__)
# define _WIN32_IE 0x0501
+# define __USE_W32_SOCKETS
#elif defined(__MINGW32__)
# define _WIN32_IE 0x0501
#elif defined(_MSC_VER)
@@ -99,6 +100,7 @@ typedef int socklen_t;
#if defined(__CYGWIN__)
+#include <sys/ioctl.h>
#include <sys/unistd.h>
#else /* not __CYGWIN__ */
@@ -346,7 +348,7 @@ extern const char * get_user_name(void);
extern const char * create_uuid(void);
/* Switch to running in the background, rather than under the direct control of a user */
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
extern void become_daemon(char ** argv);
#else
extern void become_daemon(void);
diff --git a/agent/tcf/framework/plugins.c b/agent/tcf/framework/plugins.c
index 785a51ad..98d7e1a2 100644
--- a/agent/tcf/framework/plugins.c
+++ b/agent/tcf/framework/plugins.c
@@ -43,7 +43,7 @@
#define _QUOTEME(x) #x
#define QUOTE(x) _QUOTEME(x)
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#define PLUGINS_DEF_EXT "dll" /* Default plugins' extension */
#else
#define PLUGINS_DEF_EXT "so" /* Default plugins' extension */
diff --git a/agent/tcf/framework/proxy.c b/agent/tcf/framework/proxy.c
index 826af62d..80cf5289 100644
--- a/agent/tcf/framework/proxy.c
+++ b/agent/tcf/framework/proxy.c
@@ -250,9 +250,9 @@ static void log_flush(Proxy * proxy) {
#else
-#define log_start(a, b, c) 0
-#define log_byte(a) 0
-#define log_flush(a) 0
+#define log_start(a, b, c) do {} while(0)
+#define log_byte(a) do {} while(0)
+#define log_flush(a) do {} while(0)
#endif
diff --git a/agent/tcf/framework/signames.c b/agent/tcf/framework/signames.c
index b894046e..cf91036e 100644
--- a/agent/tcf/framework/signames.c
+++ b/agent/tcf/framework/signames.c
@@ -24,7 +24,7 @@
#include <tcf/framework/sigsets.h>
#include <tcf/framework/signames.h>
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
typedef struct ExceptionName {
DWORD code;
diff --git a/agent/tcf/framework/trace.c b/agent/tcf/framework/trace.c
index c7674591..0631c778 100644
--- a/agent/tcf/framework/trace.c
+++ b/agent/tcf/framework/trace.c
@@ -27,7 +27,7 @@ int log_mode = LOG_EVENTS | LOG_CHILD | LOG_WAITPID | LOG_CONTEXT | LOG_PROTOCOL
#include <string.h>
#include <tcf/framework/mdep-threads.h>
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#elif defined(_WRS_KERNEL)
#elif defined(__SYMBIAN32__)
#else
@@ -70,7 +70,7 @@ int print_trace(int mode, const char * fmt, ...) {
va_start(ap, fmt);
if (use_syslog) {
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#elif defined(_WRS_KERNEL)
#elif defined(__SYMBIAN32__)
#else
@@ -178,7 +178,7 @@ void open_log_file(const char * log_name) {
else if (strcmp(log_name, LOG_NAME_STDERR) == 0) {
log_file = stderr;
if (is_daemon()) {
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#elif defined(_WRS_KERNEL)
#elif defined(__SYMBIAN32__)
#else
diff --git a/agent/tcf/framework/trace.h b/agent/tcf/framework/trace.h
index e79de6f5..d6a4942b 100644
--- a/agent/tcf/framework/trace.h
+++ b/agent/tcf/framework/trace.h
@@ -60,7 +60,7 @@ extern FILE * log_file;
#else /* not ENABLE_Trace */
-#if _MSC_VER >= 1400 || __GNUC__
+#if (defined(_MSC_VER) && _MSC_VER >= 1400) || __GNUC__
# define trace(...) ((void)0)
#else
# define trace 0 &&
diff --git a/agent/tcf/framework/waitpid.c b/agent/tcf/framework/waitpid.c
index 6d8b6dca..f47d1907 100644
--- a/agent/tcf/framework/waitpid.c
+++ b/agent/tcf/framework/waitpid.c
@@ -50,7 +50,7 @@ void add_waitpid_listener(WaitPIDListener * listener, void * args) {
listener_cnt++;
}
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#define MAX_HANDLES 64
diff --git a/agent/tcf/main/main.c b/agent/tcf/main/main.c
index a3b3a2d8..4b6aceed 100644
--- a/agent/tcf/main/main.c
+++ b/agent/tcf/main/main.c
@@ -128,7 +128,7 @@ static void signal_handler(int sig) {
}
}
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
static LONG NTAPI VectoredExceptionHandler(PEXCEPTION_POINTERS x) {
if (is_dispatch_thread()) {
DWORD exception_code = x->ExceptionRecord->ExceptionCode;
@@ -260,7 +260,7 @@ int main(int argc, char ** argv) {
break;
case 'd':
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
/* For Windows the only way to detach a process is to
* create a new process, so we patch the -d option to
* -D for the second time we get invoked so we don't
@@ -343,7 +343,7 @@ int main(int argc, char ** argv) {
POST_OPTION_HOOK;
if (daemon) {
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
become_daemon(daemon > 1 ? argv : NULL);
#else
become_daemon();
@@ -403,7 +403,7 @@ int main(int argc, char ** argv) {
signal(SIGILL, signal_handler);
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE);
AddVectoredExceptionHandler(1, VectoredExceptionHandler);
#endif
diff --git a/agent/tcf/main/main_lua.c b/agent/tcf/main/main_lua.c
index f7c20e3d..f6638bf8 100644
--- a/agent/tcf/main/main_lua.c
+++ b/agent/tcf/main/main_lua.c
@@ -1473,7 +1473,7 @@ int main(int argc, char ** argv) {
log_mode = 0;
-#ifndef _WIN32
+#if !(defined(_WIN32) || defined(__CYGWIN__))
signal(SIGPIPE, SIG_IGN);
#endif
ini_mdep();
diff --git a/agent/tcf/main/test.c b/agent/tcf/main/test.c
index cd4dba82..293e5806 100644
--- a/agent/tcf/main/test.c
+++ b/agent/tcf/main/test.c
@@ -35,7 +35,7 @@
#include <tcf/framework/errors.h>
#include <tcf/services/diagnostics.h>
#include <tcf/main/test.h>
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
# include <system/Windows/tcf/context-win32.h>
#endif
@@ -269,7 +269,7 @@ int find_test_symbol(Context * ctx, const char * name, void ** addr, int * sym_c
return -1;
}
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
typedef struct ContextAttachArgs {
ContextAttachCallBack * done;
void * data;
@@ -285,10 +285,10 @@ static void done_context_attach(int error, Context * ctx, void * data) {
CloseHandle(args->process);
loc_free(args);
}
-#endif /* defined(_WIN32) */
+#endif /* defined(_WIN32) || defined(__CYGWIN__) */
int run_test_process(ContextAttachCallBack * done, void * data) {
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
char fnm[FILE_PATH_SIZE];
char cmd[FILE_PATH_SIZE];
int res = 0;
diff --git a/agent/tcf/services/discovery_udp.c b/agent/tcf/services/discovery_udp.c
index 6e4b0067..690bec6d 100644
--- a/agent/tcf/services/discovery_udp.c
+++ b/agent/tcf/services/discovery_udp.c
@@ -265,7 +265,7 @@ static int create_server_socket(void) {
}
trace(LOG_ALWAYS, "Discovery service socket %s error: %s",
reason, errno_to_str(error));
- return error;
+ return set_fmt_errno(error, "Socket %s error", reason);
}
if (udp_server_socket >= 0) closesocket(udp_server_socket);
diff --git a/agent/tcf/services/filesystem.c b/agent/tcf/services/filesystem.c
index c6b6505a..9ac2f5a1 100644
--- a/agent/tcf/services/filesystem.c
+++ b/agent/tcf/services/filesystem.c
@@ -38,7 +38,7 @@
#if !defined(_WIN32) || defined(__CYGWIN__)
# include <utime.h>
#endif
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
# include <Windows.h>
#endif
#if defined(_WRS_KERNEL)
@@ -88,7 +88,7 @@ struct FileAttrs {
int permissions;
uint64_t atime;
uint64_t mtime;
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
DWORD win32_attrs;
#endif
};
@@ -288,7 +288,7 @@ static void read_file_attrs(InputStream * inp, const char * nm, void * arg) {
attrs->mtime = json_read_uint64(inp);
attrs->flags |= ATTR_ACMODTIME;
}
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
else if (strcmp(nm, "Win32Attrs") == 0) {
attrs->win32_attrs = json_read_ulong(inp);
}
@@ -340,12 +340,12 @@ static void write_file_attrs(OutputStream * out, FileAttrs * attrs) {
json_write_string(out, "MTime");
write_stream(out, ':');
json_write_uint64(out, attrs->mtime);
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
cnt++;
#endif
}
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
if (attrs->win32_attrs != INVALID_FILE_ATTRIBUTES) {
if (cnt) write_stream(out, ',');
json_write_string(out, "Win32Attrs");
@@ -440,7 +440,7 @@ static void command_open(char * token, Channel * c) {
flags = (unsigned int) json_read_ulong(&c->inp);
json_test_char(&c->inp, MARKER_EOA);
memset(&attrs, 0, sizeof(FileAttrs));
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
attrs.win32_attrs = INVALID_FILE_ATTRIBUTES;
#endif
json_read_struct(&c->inp, read_file_attrs, &attrs);
@@ -457,7 +457,7 @@ static void command_open(char * token, Channel * c) {
req->info.u.fio.permission = attrs.permissions;
req->info.u.fio.flags = to_local_open_flags(flags);
req->info.u.fio.file_name = loc_strdup(path);
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
req->info.u.fio.win32_attrs = attrs.win32_attrs;
#endif
post_io_request(handle);
@@ -494,7 +494,7 @@ static void reply_stat(char * token, OutputStream * out, int err, struct stat *
if (err == 0) fill_attrs(&attrs, buf);
else memset(&attrs, 0, sizeof(attrs));
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
attrs.win32_attrs = err ? INVALID_FILE_ATTRIBUTES : GetFileAttributes(path);
#endif
@@ -608,7 +608,7 @@ static void done_io_request(void * arg) {
break;
case REQ_OPEN:
err = req->info.error;
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
if (err == 0) {
if (req->info.u.fio.win32_attrs != INVALID_FILE_ATTRIBUTES) {
if (SetFileAttributes(req->info.u.fio.file_name, req->info.u.fio.win32_attrs) == 0)
@@ -661,11 +661,11 @@ static void post_io_request(OpenFileInfo * handle) {
if (attrs.flags & ATTR_SIZE) {
if (ftruncate(handle->file, attrs.size) < 0) err = errno;
}
-#if defined(_WIN32) || defined(_WRS_KERNEL)
+#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WRS_KERNEL)
if (attrs.flags & ATTR_PERMISSIONS) {
if (chmod(handle->path, attrs.permissions) < 0) err = errno;
}
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
if (attrs.win32_attrs != INVALID_FILE_ATTRIBUTES) {
if (SetFileAttributes(handle->path, attrs.win32_attrs) == 0)
err = set_win32_errno(GetLastError());
@@ -885,7 +885,7 @@ static void command_setstat(char * token, Channel * c) {
read_path(&c->inp, path, sizeof(path));
json_test_char(&c->inp, MARKER_EOA);
memset(&attrs, 0, sizeof(FileAttrs));
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
attrs.win32_attrs = INVALID_FILE_ATTRIBUTES;
#endif
json_read_struct(&c->inp, read_file_attrs, &attrs);
@@ -909,7 +909,7 @@ static void command_setstat(char * token, Channel * c) {
buf.modtime = (time_t)(attrs.mtime / 1000);
if (utime(path, &buf) < 0) err = errno;
}
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
if (attrs.win32_attrs != INVALID_FILE_ATTRIBUTES) {
if (SetFileAttributes(path, attrs.win32_attrs) == 0)
err = set_win32_errno(GetLastError());
@@ -927,7 +927,7 @@ static void command_fsetstat(char * token, Channel * c) {
json_read_string(&c->inp, id, sizeof(id));
json_test_char(&c->inp, MARKER_EOA);
memset(&attrs, 0, sizeof(FileAttrs));
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
attrs.win32_attrs = INVALID_FILE_ATTRIBUTES;
#endif
json_read_struct(&c->inp, read_file_attrs, &attrs);
@@ -1014,7 +1014,7 @@ static void command_readdir(char * token, Channel * c) {
snprintf(path, sizeof(path), "%s/%s", h->path, e->d_name);
if (stat(path, &st) == 0) {
fill_attrs(&attrs, &st);
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
attrs.win32_attrs = GetFileAttributes(path);
#endif
write_stream(&c->out, ',');
@@ -1079,7 +1079,7 @@ static void command_mkdir(char * token, Channel * c) {
read_path(&c->inp, path, sizeof(path));
json_test_char(&c->inp, MARKER_EOA);
memset(&attrs, 0, sizeof(FileAttrs));
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
attrs.win32_attrs = INVALID_FILE_ATTRIBUTES;
#endif
json_read_struct(&c->inp, read_file_attrs, &attrs);
@@ -1092,7 +1092,7 @@ static void command_mkdir(char * token, Channel * c) {
mode = (attrs.flags & ATTR_PERMISSIONS) ? attrs.permissions : 0777;
if (mkdir(path, mode) < 0) err = errno;
#endif
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
if (attrs.win32_attrs != INVALID_FILE_ATTRIBUTES) {
if (SetFileAttributes(path, attrs.win32_attrs) == 0)
err = set_win32_errno(GetLastError());
@@ -1296,7 +1296,7 @@ static void command_roots(char * token, Channel * c) {
write_stringz(&c->out, token);
write_stream(&c->out, '[');
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
{
int cnt = 0;
int disk = 0;
diff --git a/agent/tcf/services/linenumbers_mux.c b/agent/tcf/services/linenumbers_mux.c
index 7e7ad462..229d79ce 100644
--- a/agent/tcf/services/linenumbers_mux.c
+++ b/agent/tcf/services/linenumbers_mux.c
@@ -38,7 +38,7 @@ static unsigned max_reader_count = 0;
#if ENABLE_ELF
extern void elf_ini_line_numbers_lib(void);
#endif
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
extern void win32_ini_line_numbers_lib(void);
#endif
diff --git a/agent/tcf/services/processes.c b/agent/tcf/services/processes.c
index 3a9cb88d..3be7ab9e 100644
--- a/agent/tcf/services/processes.c
+++ b/agent/tcf/services/processes.c
@@ -57,7 +57,7 @@
static const char * PROCESSES[2] = { "Processes", "ProcessesV1" };
#endif
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
# include <tlhelp32.h>
# ifdef _MSC_VER
# pragma warning(disable:4201) /* nonstandard extension used : nameless struct/union (in winternl.h) */
@@ -318,7 +318,7 @@ static void command_get_context(char * token, Channel * c) {
write_stringz(&c->out, token);
if (pid != 0 && parent == 0) {
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#elif defined(_WRS_KERNEL)
if (TASK_ID_VERIFY(pid) == ERROR) err = ERR_INV_CONTEXT;
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
@@ -362,7 +362,7 @@ static void command_get_children(char * token, Channel * c) {
write_stringz(&c->out, "null");
}
else {
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
DWORD err = 0;
HANDLE snapshot;
PROCESSENTRY32 pe32;
@@ -687,7 +687,7 @@ static void command_terminate(char * token, Channel * c) {
err = ERR_INV_CONTEXT;
}
else {
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
HANDLE h = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
if (h == NULL) {
err = set_win32_errno(GetLastError());
@@ -721,7 +721,7 @@ static void command_signal(char * token, Channel * c) {
write_stringz(&c->out, "R");
write_stringz(&c->out, token);
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
if (parent != 0) {
err = ERR_INV_CONTEXT;
}
@@ -897,8 +897,7 @@ static void write_process_input_done(void * x) {
int wr = inp->req.u.fio.rval;
if (wr < 0) {
- int err = inp->req.error;
- trace(LOG_ALWAYS, "Can't write process input stream: %d %s", err, errno_to_str(err));
+ trace(LOG_ALWAYS, "Can't write process input stream: %s", errno_to_str(inp->req.error));
inp->buf_pos = inp->buf_len = 0;
}
else {
@@ -1012,7 +1011,15 @@ static ProcessOutput * read_process_output(ChildProcess * prs, int fd) {
# define context_attach_self() (errno = ERR_UNSUPPORTED, -1)
#endif
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
+
+#if defined(_MSC_VER)
+static int setenv(const char * name, const char * val, int overwrite) {
+ assert(overwrite);
+ _putenv_s(name, val);
+ return 0;
+}
+#endif
static int start_process_imp(Channel * c, char ** envp, const char * dir, const char * exe, char ** args,
ProcessStartParams * params, int * selfattach, ChildProcess ** prs) {
@@ -1093,7 +1100,7 @@ static int start_process_imp(Channel * c, char ** envp, const char * dir, const
const char * fnm = exe;
char * cmd = NULL;
char * env = NULL;
- char * env_path = NULL;
+ const char * env_path = NULL;
SetHandleInformation(hpipes[0][0], HANDLE_FLAG_INHERIT, TRUE);
SetHandleInformation(hpipes[1][1], HANDLE_FLAG_INHERIT, TRUE);
SetHandleInformation(hpipes[2][1], HANDLE_FLAG_INHERIT, TRUE);
@@ -1137,14 +1144,13 @@ static int start_process_imp(Channel * c, char ** envp, const char * dir, const
char ** p = envp;
size_t env_size = 1;
char * s = NULL;
- char * path = getenv("PATH");
- if (path == NULL) env_path = "PATH=";
- else env_path = tmp_strdup2("PATH=", path);
+ env_path = getenv("PATH");
+ if (env_path == NULL) env_path = "";
while (*p != NULL) env_size += strlen(*p++) + 1;
s = env = (char *)tmp_alloc(env_size);
for (p = envp; *p != NULL; p++) {
size_t l = strlen(*p) + 1;
- if (strncmp(*p, "PATH=", 5) == 0) putenv(*p);
+ if (strncmp(*p, "PATH=", 5) == 0) setenv("PATH", *p + 5, 1);
memcpy(s, *p, l);
s += l;
}
@@ -1165,7 +1171,7 @@ static int start_process_imp(Channel * c, char ** envp, const char * dir, const
if (!CloseHandle(prs_info.hThread)) err = set_win32_errno(GetLastError());
if (!CloseHandle(prs_info.hProcess)) err = set_win32_errno(GetLastError());
}
- if (env_path != NULL) putenv(env_path);
+ if (env_path != NULL) setenv("PATH", env_path, 1);
}
if (fpipes[0][0] >= 0 && close(fpipes[0][0]) < 0 && !err) err = errno;
if (fpipes[1][1] >= 0 && close(fpipes[1][1]) < 0 && !err) err = errno;
@@ -1482,7 +1488,7 @@ int start_process(Channel * c, ProcessStartParams * params, int * selfattach, Ch
(*prs)->exit_cb = params->exit_cb;
}
if (!err) {
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#elif defined(_WRS_KERNEL)
#else
if ((*prs)->tty >= 0) {
@@ -1542,7 +1548,7 @@ int get_process_tty_win_size(ChildProcess * prs, unsigned * ws_col, unsigned * w
int set_process_tty_win_size(ChildProcess * prs, unsigned ws_col, unsigned ws_row, int * changed) {
if (changed) *changed = 0;
if (prs->ws_col != ws_col || prs->ws_row != ws_row) {
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#elif defined(_WRS_KERNEL)
#else
struct winsize size;
diff --git a/agent/tcf/services/runctrl.c b/agent/tcf/services/runctrl.c
index ff217ea3..e82dd336 100644
--- a/agent/tcf/services/runctrl.c
+++ b/agent/tcf/services/runctrl.c
@@ -2035,10 +2035,12 @@ static void run_safe_events(void * arg) {
ext->cannot_stop = 1;
}
else {
+#if ENABLE_Trace
if (stop_all_timer_cnt == STOP_ALL_MAX_CNT / 2) {
const char * msg = ext->safe_single_step ? "finish single step" : "stop";
trace(LOG_ALWAYS, "warning: waiting too long for context %s to %s", ctx->id, msg);
}
+#endif
if (!ext->safe_single_step || stop_all_timer_cnt >= STOP_ALL_MAX_CNT / 2) {
if (context_stop(ctx) < 0) {
trace(LOG_ALWAYS, "can't stop %s: %s", ctx->id, errno_to_str(errno));
diff --git a/agent/tcf/services/sysmon.c b/agent/tcf/services/sysmon.c
index 036e8f06..538340a4 100644
--- a/agent/tcf/services/sysmon.c
+++ b/agent/tcf/services/sysmon.c
@@ -409,7 +409,7 @@ static void command_get_environment(char * token, Channel * c) {
write_stream(&c->out, MARKER_EOM);
}
-#elif defined(_WIN32)
+#elif defined(_WIN32) || defined(__CYGWIN__)
#include <windows.h>
#include <wchar.h>
diff --git a/agent/tcf/services/tcf_elf.c b/agent/tcf/services/tcf_elf.c
index f22a7db5..a5432a89 100644
--- a/agent/tcf/services/tcf_elf.c
+++ b/agent/tcf/services/tcf_elf.c
@@ -49,7 +49,7 @@
#elif defined(_MSC_VER)
/* Memoy mapped files appear broken on Windows 8 */
# define USE_MMAP 0
-#elif defined(_WIN32)
+#elif defined(_WIN32) || defined(__CYGWIN__)
# define USE_MMAP 0
#else
# include <sys/mman.h>
@@ -111,7 +111,7 @@ static void elf_dispose(ELF_File * file) {
ELF_Section * s = file->sections + n;
#if !USE_MMAP
loc_free(s->data);
-#elif defined(_WIN32)
+#elif defined(_WIN32) || defined(__CYGWIN__)
if (s->mmap_addr == NULL) loc_free(s->data);
else UnmapViewOfFile(s->mmap_addr);
#else
@@ -125,7 +125,7 @@ static void elf_dispose(ELF_File * file) {
}
loc_free(file->sections);
}
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
if (file->mmap_handle != NULL) CloseHandle(file->mmap_handle);
#endif
for (n = 0; n < file->names_cnt; n++) {
@@ -896,7 +896,7 @@ int elf_load(ELF_Section * s) {
}
#if USE_MMAP
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
if (s->size >= 0x100000) {
ELF_File * file = s->file;
if (file->mmap_handle == NULL) {
diff --git a/agent/tcf/services/tcf_elf.h b/agent/tcf/services/tcf_elf.h
index e9ab0f47..d7f9bcf4 100644
--- a/agent/tcf/services/tcf_elf.h
+++ b/agent/tcf/services/tcf_elf.h
@@ -23,7 +23,7 @@
#if ENABLE_ELF
-#if !ENABLE_ContextProxy && !defined(_WIN32) && !defined(__APPLE__)
+#if !ENABLE_ContextProxy && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__APPLE__)
# define INCLUDE_NATIVE_ELF_H 1
# include <elf.h>
#endif
@@ -412,7 +412,7 @@ struct ELF_File {
unsigned names_cnt;
unsigned names_max;
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
HANDLE mmap_handle;
#endif
diff --git a/agent/tcf/services/terminals.c b/agent/tcf/services/terminals.c
index c59da316..8e41b2b5 100644
--- a/agent/tcf/services/terminals.c
+++ b/agent/tcf/services/terminals.c
@@ -49,7 +49,7 @@
static const char * TERMINALS = "Terminals";
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
# define TERM_LAUNCH_EXEC "cmd"
# define TERM_LAUNCH_ARGS {TERM_LAUNCH_EXEC, NULL}
#else
@@ -231,7 +231,7 @@ static int kill_term(Terminal * term) {
int err = 0;
int pid = get_process_pid(term->prs);
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
HANDLE h = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
if (h == NULL) {
err = set_win32_errno(GetLastError());
@@ -290,7 +290,7 @@ static void terminal_exited(void * args) {
loc_free(term);
}
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(__CYGWIN__)
/*
* Set the environment variable "name" to the value "value". If the variable
* exists already, override it or just skip.
@@ -412,7 +412,7 @@ static void command_launch(char * token, Channel * c) {
prms.envp = read_env(&c->inp);
json_test_char(&c->inp, MARKER_EOM);
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(__CYGWIN__)
{
struct stat st;
if (err == 0 && stat(exec, &st) != 0) {

Back to the top