From: Nicolas Boichat Date: Sat, 17 Apr 2004 17:38:37 +0000 (+0000) Subject: mingw support. X-Git-Tag: Release-1.34.1~28 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=99f70507b341de86dfc895016de730cceb7f51ed;p=bacula%2Fbacula mingw support. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1225 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/findlib/winapi.h b/bacula/src/findlib/winapi.h index 4672fdd49f..102eda1809 100644 --- a/bacula/src/findlib/winapi.h +++ b/bacula/src/findlib/winapi.h @@ -1,6 +1,6 @@ /* * Windows APIs that are different for each system. - * We use pointers to the entry points so that a + * We use pointers to the entry points so that a * single binary will run on all Windows systems. * * Kern Sibbald MMIII @@ -28,7 +28,9 @@ #ifndef __WINAPI_H #define __WINAPI_H #if defined(HAVE_WIN32) +#if !defined(HAVE_MINGW) // native.h not present on mingw #include +#endif #include #endif #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) @@ -36,7 +38,7 @@ typedef BOOL (WINAPI * t_OpenProcessToken)(HANDLE, DWORD, PHANDLE); typedef BOOL (WINAPI * t_AdjustTokenPrivileges)(HANDLE, BOOL, - PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD); + PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD); typedef BOOL (WINAPI * t_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID); extern t_OpenProcessToken p_OpenProcessToken; @@ -45,15 +47,15 @@ extern t_LookupPrivilegeValue p_LookupPrivilegeValue; /* In KERNEL32.DLL */ typedef BOOL (WINAPI * t_GetFileAttributesEx)(LPCTSTR, GET_FILEEX_INFO_LEVELS, - LPVOID); + LPVOID); typedef BOOL (WINAPI * t_SetProcessShutdownParameters)(DWORD, DWORD); typedef BOOL (WINAPI * t_BackupRead)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*); typedef BOOL (WINAPI * t_BackupWrite)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*); extern t_GetFileAttributesEx p_GetFileAttributesEx; extern t_SetProcessShutdownParameters p_SetProcessShutdownParameters; -extern t_BackupRead p_BackupRead; -extern t_BackupWrite p_BackupWrite; +extern t_BackupRead p_BackupRead; +extern t_BackupWrite p_BackupWrite; #endif diff --git a/bacula/src/lib/Makefile.mingw b/bacula/src/lib/Makefile.mingw new file mode 100644 index 0000000000..dab73ebe0b --- /dev/null +++ b/bacula/src/lib/Makefile.mingw @@ -0,0 +1,232 @@ +# $Id$ + +# autoconf/Make.common.in -*- Makefile -*- +# release date (man), LSM date, version number/name, current maintainer +DATE="15 Apr 2004" +LSMDATE=15Apr04 +VERSION=1.35.0 +VERNAME=bacula-$(VERSION)# +MAINT=Kern Sibbald# +MAINTEMAIL=# +WEBMAINT=# +WEBMAINTEMAIL=# +WEBPAGE=# +FTPSITENAME=# +FTPSITEDIR=# +#------------------------------------------------------------------------- + +SHELL = /bin/sh + +# Installation target directories & other installation stuff +prefix = +exec_prefix = +binprefix = +manprefix = +sbindir = /sbin +sysconfdir = /etc/bacula +scriptdir = /etc/bacula +mandir = ${prefix}/man/man1 +manext = 1 + +# Tools & program stuff +CC = gcc +CPP = gcc -E +CXX = g++ +MV = /usr/bin/mv +RM = /usr/bin/rm +RMF = /usr/bin/rm -f +CP = /usr/bin/cp +SED = /usr/bin/sed +AWK = /usr/bin/awk +ECHO = /usr/bin/echo +CMP = /usr/bin/cmp +TBL = /usr/bin/tbl +AR = ar +RANLIB = ranlib +INSTALL = /usr/bin/install -c +# add the -s to the following in PRODUCTION mode +INSTALL_PROGRAM = /usr/bin/install -c -m 754 +INSTALL_DATA = /usr/bin/install -c -m 644 +INSTALL_SCRIPT = /usr/bin/install -c -m 754 +INSTALL_CONFIG = /usr/bin/install -c -m 640 + +# Flags & libs +CFLAGS = -g -O2 -Wall +CPPFLAGS = +LDFLAGS = -O +TTOOL_LDFLAGS = +DEFS = -DHAVE_WIN32 -DHAVE_MINGW +LIBS = -lpthread +DINCLUDE = +DLIB = +DB_LIBS = + +# Windows (cygwin) flags +WCFLAGS = -mwindows +WLDFLAGS = -mwindows + +# X Include directory +#XINC = @XPM_CFLAGS@ + +# extra libraries needed by X on some systems, X library location +#XLIB = @XPM_LIBS@ -lX11 + +# End of common section of the Makefile +#------------------------------------------------------------------------- + +CWEB = @CWEB@ +CTANGLE = $(CWEB)/ctangle +CWEAVE = $(CWEB)/cweave +TEXINPUTS = TEXINPUTS=.:$(CWEB): + +# FIXME -- These should be found by autoconf +TEX = tex +PDFTEX = pdftex +XDVI = xdvi +DVIPS = dvips + +srcdir = . +VPATH = . +.PATH: . + +# one up +basedir = .. +# top dir +topdir = ../.. +# this dir relative to top dir +thisdir = src/lib + + +DEBUG= + +GMP_INC=@GMP_INC@ + +first_rule: all +dummy: + +LIBSRCS = alloc.c attr.c base64.c bsys.c bget_msg.c \ + bnet.c bnet_server.c \ + bpipe.c bshm.c btime.c \ + cram-md5.c crc32.c daemon.c edit.c fnmatch.c \ + hmac.c idcache.c jcr.c lex.c alist.c dlist.c \ + md5.c message.c mem_pool.c parse_conf.c \ + queue.c rwlock.c scan.c serial.c sha1.c \ + semlock.c signal.c smartall.c tree.c \ + util.c var.c watchdog.c workq.c timers.c + + +LIBOBJS = alloc.o attr.o base64.o bsys.o bget_msg.o \ + bnet.o bnet_server.o \ + bpipe.o bshm.o btime.o \ + cram-md5.o crc32.o daemon.o edit.o fnmatch.o \ + hmac.o idcache.o jcr.o lex.o alist.o dlist.o \ + md5.o message.o mem_pool.o parse_conf.o \ + queue.o rwlock.o scan.o serial.o sha1.o \ + semlock.o signal.o smartall.o tree.o \ + util.o var.o watchdog.o workq.o timers.o + + + +EXTRAOBJS = + + +.SUFFIXES: .c .o .ch .dvi .pdf .tex .view .w .1 +.PHONY: +.DONTCARE: + +# inference rules +compat.o: ../win32/compat/compat.cpp + $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I../win32/compat \ + -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) -o compat.o ../win32/compat/compat.cpp + +.c.o: + $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I../win32/compat -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $< + +.cc.o: + $(CXX) $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I../win32/compat -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $< + +.w.c: + $(CTANGLE) $< + +.w.tex: + $(CWEAVE) $< + +.tex.dvi: + ( $(TEXINPUTS) ; export TEXINPUTS; $(TEX) $< ) + +.tex.pdf: + ( $(TEXINPUTS) ; export TEXINPUTS; $(PDFTEX) $< ) + +.dvi.view: + $(XDVI) -s 0 $< + +#------------------------------------------------------------------------- +all: Makefile libbac.a + @echo "==== Make of lib is good ====" + @echo " " + +libbac.a: $(LIBOBJS) compat.o + $(AR) rc $@ $(LIBOBJS) compat.o + $(RANLIB) $@ + + +Makefile: $(srcdir)/Makefile.in $(topdir)/config.status + cd $(topdir) \ + && CONFIG_FILES=$(thisdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + +rwlock_test: + rm -f rwlock.o + $(CXX) -DTEST_RWLOCK $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) rwlock.c + $(CXX) $(LDFLAGS) -L. -o $@ rwlock.o $(LIBS) $(DLIB) -lbac -lm + rm -f rwlock.o + $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) rwlock.c + +md5sum: + rm -f md5.o + $(CXX) -DMD5_SUM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) md5.c + $(CXX) $(LDFLAGS) -L. -o $@ md5.o $(LIBS) $(DLIB) -lbac -lm + rm -f md5.o + $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) md5.c + + +sha1sum: + rm -f sha1.o + $(CXX) -DSHA1_SUM $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) sha1.c + $(CXX) $(LDFLAGS) -L. -o $@ sha1.o $(LIBS) $(DLIB) -lbac -lm + rm -f sha1.o + $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) md5.c + +install: + +uninstall: + +clean: + $(RMF) *.a core a.out *.o *.bak *.tex *.pdf *~ *.intpro *.extpro 1 2 3 + $(RMF) rwlock_test md5sum sha1sum + +realclean: clean + $(RMF) tags + +distclean: realclean + if test $(srcdir) = .; then $(MAKE) realclean; fi + (cd $(srcdir); $(RMF) Makefile; $(RMF) -r CVS) + +# Semi-automatic generation of dependencies: +# Use gcc -MM because X11 `makedepend' doesn't work on all systems +# and it also includes system headers. +# `semi'-automatic since dependencies are generated at distribution time. + +depend: + @$(MV) Makefile Makefile.bak + @$(SED) "/^# DO NOT DELETE:/,$$ d" Makefile.bak > Makefile + @$(ECHO) "# DO NOT DELETE: nice dependency list follows" >> Makefile + @$(CXX) -S -M $(CPPFLAGS) $(XINC) -I$(srcdir) -I$(basedir) $(SQL_INC) *.c >> Makefile + @if test -f Makefile ; then \ + $(RMF) Makefile.bak; \ + else \ + $(MV) Makefile.bak Makefile; \ + echo -e "Something went wrong\n\a"; \ + fi + +# ----------------------------------------------------------------------- +# DO NOT DELETE: nice dependency list follows \ No newline at end of file diff --git a/bacula/src/win32/compat/compat.cpp b/bacula/src/win32/compat/compat.cpp index 016a3a29a4..90d20b784b 100644 --- a/bacula/src/win32/compat/compat.cpp +++ b/bacula/src/win32/compat/compat.cpp @@ -1,12 +1,12 @@ -// -*- Mode: C++ -*- +// -*- Mode: C++ -*- // compat.cpp -- compatibilty layer to make bacula-fd run // natively under windows // -// Copyright transferred from Raider Solutions, Inc to +// Copyright transferred from Raider Solutions, Inc to // Kern Sibbald and John Walker by express permission. // // Copyright (C) 2004 Kern Sibbald and John Walker -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of @@ -37,7 +37,11 @@ extern void d_msg(const char *file, int line, int level, const char *fmt,...); extern DWORD g_platform_id; // from CYGWIN (should be diff between Jan 1 1601 and Jan 1 1970 +#ifdef HAVE_MINGW +#define WIN32_FILETIME_ADJUST 0x19DB1DED53E8000UL //Not sure it works +#else #define WIN32_FILETIME_ADJUST 0x19DB1DED53E8000I64 +#endif #define WIN32_FILETIME_SCALE 10000000 // 100ns/second @@ -139,7 +143,11 @@ cvt_utime_to_ftime(const time_t &time, FILETIME &wintime) mstime *= WIN32_FILETIME_SCALE; mstime += WIN32_FILETIME_ADJUST; + #ifdef HAVE_MINGW + wintime.dwLowDateTime = (DWORD)(mstime & 0xffffffffUL); + #else wintime.dwLowDateTime = (DWORD)(mstime & 0xffffffffI64); + #endif wintime.dwHighDateTime = (DWORD) ((mstime>>32)& 0xffffffffUL); } @@ -174,6 +182,8 @@ errorString(void) return (const char *) lpMsgBuf; } +#ifndef HAVE_MINGW + static int statDir(const char *file, struct stat *sb) { @@ -240,8 +250,8 @@ stat2(const char *file, struct stat *sb) errno = GetLastError(); return -1; } - - if (attr & FILE_ATTRIBUTE_DIRECTORY) + + if (attr & FILE_ATTRIBUTE_DIRECTORY) return statDir(tmpbuf, sb); h = CreateFile(tmpbuf, GENERIC_READ, @@ -256,7 +266,7 @@ stat2(const char *file, struct stat *sb) errno = GetLastError(); goto error; } - + if (!GetFileInformationByHandle(h, &info)) { const char *err = errorString(); d_msg(__FILE__, __LINE__, 99, @@ -266,7 +276,7 @@ stat2(const char *file, struct stat *sb) errno = GetLastError(); goto error; } - + sb->st_dev = info.dwVolumeSerialNumber; sb->st_ino = info.nFileIndexHigh; sb->st_ino <<= 32; @@ -324,7 +334,7 @@ stat(const char *file, struct stat *sb) if (!GetFileAttributesEx(file, GetFileExInfoStandard, &data)) return stat2(file, sb); #endif - + sb->st_mode = 0777; /* start with everything */ if (data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) sb->st_mode &= ~(S_IRUSR|S_IRGRP|S_IROTH); @@ -360,7 +370,9 @@ void sleep(int sec) { Sleep(sec * 1000); -} +} + +#endif //HAVE_MINGW int geteuid(void) @@ -399,11 +411,12 @@ readlink(const char *, char *, int) } +#ifndef HAVE_MINGW int strcasecmp(const char *s1, const char *s2) { register int ch1, ch2; - + if (s1==s2) return 0; /* strings are equal if same object. */ else if (!s1) @@ -417,15 +430,16 @@ strcasecmp(const char *s1, const char *s2) s1++; s2++; } while (ch1 != 0 && tolower(ch1) == tolower(ch2)); - + return(ch1 - ch2); } +#endif //HAVE_MINGW int strncasecmp(const char *s1, const char *s2, int len) { register int ch1, ch2; - + if (s1==s2) return 0; /* strings are equal if same object. */ else if (!s1) @@ -439,7 +453,7 @@ strncasecmp(const char *s1, const char *s2, int len) s1++; s2++; } while (len-- && ch1 != 0 && tolower(ch1) == tolower(ch2)); - + return(ch1 - ch2); } @@ -457,11 +471,11 @@ gettimeofday(struct timeval *tv, struct timezone *) _100nsec <<= 32; _100nsec |= tmp.dwLowDateTime; _100nsec -= WIN32_FILETIME_ADJUST; - + tv->tv_sec =(long) (_100nsec / 10000000); tv->tv_usec = (long) ((_100nsec % 10000000)/10); return 0; - + } int @@ -482,7 +496,7 @@ getgrgid(uid_t) return NULL; } - +#ifndef HAVE_MINGW // implement opendir/readdir/closedir on top of window's API typedef struct _dir { @@ -499,12 +513,12 @@ opendir(const char *path) int max_len = strlen(path) + 16; _dir *rval = NULL; if (path == NULL) return NULL; - + rval = (_dir *)malloc(sizeof(_dir)); if (rval == NULL) return NULL; char *tspec = (char *)malloc(max_len); if (tspec == NULL) goto err1; - + if (g_platform_id != VER_PLATFORM_WIN32_WINDOWS) { // allow path to be 32767 bytes tspec[0] = '\\'; @@ -512,7 +526,7 @@ opendir(const char *path) tspec[2] = '?'; tspec[3] = '\\'; tspec[4] = 0; - cygwin_conv_to_win32_path(path, tspec+4); + cygwin_conv_to_win32_path(path, tspec+4); } else { cygwin_conv_to_win32_path(path, tspec); } @@ -537,7 +551,7 @@ err1: free(rval); return NULL; } - + int closedir(DIR *dirp) { @@ -595,7 +609,7 @@ readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) dp->valid = FindNextFile(dp->dirh, &dp->data); return 0; } - +#endif //HAVE_MINGW int inet_aton(const char *a, struct in_addr *inp) @@ -662,10 +676,10 @@ WSA_Init(void) { WORD wVersionRequested = MAKEWORD( 1, 1); WSADATA wsaData; - + int err = WSAStartup(wVersionRequested, &wsaData); - - + + if (err != 0) { printf("Can not start Windows Sockets\n"); @@ -695,7 +709,7 @@ win32_getcwd(char *buf, int maxlen) buf[n] = '\\'; buf[n+1] = 0; } - + return buf; } @@ -756,13 +770,13 @@ winver::winver(void) close_bpipe(b); #endif } - -BOOL CreateChildProcess(VOID); -VOID WriteToPipe(VOID); -VOID ReadFromPipe(VOID); -VOID ErrorExit(LPTSTR); -VOID ErrMsg(LPTSTR, BOOL); - + +BOOL CreateChildProcess(VOID); +VOID WriteToPipe(VOID); +VOID ReadFromPipe(VOID); +VOID ErrorExit(LPTSTR); +VOID ErrMsg(LPTSTR, BOOL); + const char * getArgv0(const char *cmdline) @@ -784,18 +798,18 @@ getArgv0(const char *cmdline) } HANDLE -CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err) -{ - PROCESS_INFORMATION piProcInfo; +CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err) +{ + PROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo; - BOOL bFuncRetn = FALSE; - - // Set up members of the PROCESS_INFORMATION structure. - + BOOL bFuncRetn = FALSE; + + // Set up members of the PROCESS_INFORMATION structure. + ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) ); - - // Set up members of the STARTUPINFO structure. - + + // Set up members of the STARTUPINFO structure. + ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) ); siStartInfo.cb = sizeof(STARTUPINFO); // setup new process to use supplied handles for stdin,stdout,stderr @@ -807,7 +821,7 @@ CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err) siStartInfo.hStdInput = in; else siStartInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); - + if (out != INVALID_HANDLE_VALUE) siStartInfo.hStdOutput = out; else @@ -816,19 +830,19 @@ CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err) siStartInfo.hStdError = err; else siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE); - // Create the child process. - + // Create the child process. + char cmdLine[1024]; char exeFile[1024]; // retrive the first compont of the command line which should be the - // executable + // executable const char *exeName = getArgv0(cmdline); // check to see if absolute path was passed to us already? if (exeName[1] != ':' || (strchr(cmdline, '/') == NULL && strchr(cmdline, '\\') == NULL)) { - // only command name so perform search of PATH to find + // only command name so perform search of PATH to find char *file; DWORD rval = SearchPath(NULL, exeName, @@ -842,7 +856,7 @@ CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err) return INVALID_HANDLE_VALUE; } - else + else strcpy(exeFile, exeName); // exeFile now has absolute path to program to execute. @@ -850,17 +864,17 @@ CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err) // copy original command line to pass to create process strcpy(cmdLine, cmdline); // try to execute program - bFuncRetn = CreateProcess(exeFile, - cmdLine, // command line - NULL, // process security attributes - NULL, // primary thread security attributes - TRUE, // handles are inherited - 0, // creation flags - NULL, // use parent's environment - NULL, // use parent's current directory - &siStartInfo, // STARTUPINFO pointer + bFuncRetn = CreateProcess(exeFile, + cmdLine, // command line + NULL, // process security attributes + NULL, // primary thread security attributes + TRUE, // handles are inherited + 0, // creation flags + NULL, // use parent's environment + NULL, // use parent's current directory + &siStartInfo, // STARTUPINFO pointer &piProcInfo); // receives PROCESS_INFORMATION - + if (bFuncRetn == 0) { ErrorExit("CreateProcess failed\n"); return INVALID_HANDLE_VALUE; @@ -868,17 +882,17 @@ CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err) // we don't need a handle on the process primary thread so we close // this now. CloseHandle(piProcInfo.hThread); - + return piProcInfo.hProcess; } - + void -ErrorExit (LPTSTR lpszMessage) -{ +ErrorExit (LPTSTR lpszMessage) +{ d_msg(__FILE__, __LINE__, 0, "%s", lpszMessage); -} - +} + /* typedef struct s_bpipe { @@ -898,44 +912,45 @@ CloseIfValid(HANDLE handle) CloseHandle(handle); } +#ifndef HAVE_MINGW BPIPE * open_bpipe(char *prog, int wait, const char *mode) { - HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup, - hChildStdoutRd, hChildStdoutWr, hChildStdoutRdDup, + HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup, + hChildStdoutRd, hChildStdoutWr, hChildStdoutRdDup, hInputFile; - - SECURITY_ATTRIBUTES saAttr; - BOOL fSuccess; + SECURITY_ATTRIBUTES saAttr; + + BOOL fSuccess; - hChildStdinRd = hChildStdinWr = hChildStdinWrDup = - hChildStdoutRd = hChildStdoutWr = hChildStdoutRdDup = + hChildStdinRd = hChildStdinWr = hChildStdinWrDup = + hChildStdoutRd = hChildStdoutWr = hChildStdoutRdDup = hInputFile = INVALID_HANDLE_VALUE; - + BPIPE *bpipe = (BPIPE *)malloc(sizeof(BPIPE)); memset((void *)bpipe, 0, sizeof(BPIPE)); int mode_read = (mode[0] == 'r'); int mode_write = (mode[0] == 'w' || mode[1] == 'w'); - - - // Set the bInheritHandle flag so pipe handles are inherited. - - saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); - saAttr.bInheritHandle = TRUE; - saAttr.lpSecurityDescriptor = NULL; - + + + // Set the bInheritHandle flag so pipe handles are inherited. + + saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); + saAttr.bInheritHandle = TRUE; + saAttr.lpSecurityDescriptor = NULL; + if (mode_read) { - - // Create a pipe for the child process's STDOUT. + + // Create a pipe for the child process's STDOUT. if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) { ErrorExit("Stdout pipe creation failed\n"); goto cleanup; } - // Create noninheritable read handle and close the inheritable read - // handle. - + // Create noninheritable read handle and close the inheritable read + // handle. + fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd, GetCurrentProcess(), &hChildStdoutRdDup , 0, FALSE, @@ -944,31 +959,31 @@ open_bpipe(char *prog, int wait, const char *mode) ErrorExit("DuplicateHandle failed"); goto cleanup; } - + CloseHandle(hChildStdoutRd); } - + if (mode_write) { - - // Create a pipe for the child process's STDIN. - + + // Create a pipe for the child process's STDIN. + if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0)) { ErrorExit("Stdin pipe creation failed\n"); goto cleanup; } - - // Duplicate the write handle to the pipe so it is not inherited. - fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr, + + // Duplicate the write handle to the pipe so it is not inherited. + fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr, GetCurrentProcess(), &hChildStdinWrDup, - 0, - FALSE, // not inherited - DUPLICATE_SAME_ACCESS); + 0, + FALSE, // not inherited + DUPLICATE_SAME_ACCESS); if (!fSuccess) { ErrorExit("DuplicateHandle failed"); goto cleanup; } - - CloseHandle(hChildStdinWr); + + CloseHandle(hChildStdinWr); } // spawn program with redirected handles as appropriate bpipe->worker_pid = (pid_t) @@ -976,13 +991,13 @@ open_bpipe(char *prog, int wait, const char *mode) hChildStdinRd, // stdin HANDLE hChildStdoutWr, // stdout HANDLE hChildStdoutWr);// stderr HANDLE - + if ((HANDLE) bpipe->worker_pid == INVALID_HANDLE_VALUE) goto cleanup; - + bpipe->wait = wait; bpipe->worker_stime = time(NULL); - + if (mode_read) { CloseHandle(hChildStdoutWr); // close our write side so when // process terminates we can @@ -998,25 +1013,27 @@ open_bpipe(char *prog, int wait, const char *mode) int wfd = _open_osfhandle((long)hChildStdinWrDup, O_WRONLY); bpipe->wfd = _fdopen(wfd, "w"); } - + if (wait > 0) { bpipe->timer_id = start_child_timer(bpipe->worker_pid, wait); } - + return bpipe; - + cleanup: - + CloseIfValid(hChildStdoutRd); CloseIfValid(hChildStdoutRdDup); CloseIfValid(hChildStdinWr); CloseIfValid(hChildStdinWrDup); - + free((void *) bpipe); - + return NULL; } +#endif //HAVE_MINGW + int kill(int pid, int signal) { @@ -1027,6 +1044,8 @@ kill(int pid, int signal) return rval; } +#ifndef HAVE_MINGW + int close_bpipe(BPIPE *bpipe) { @@ -1036,19 +1055,19 @@ close_bpipe(BPIPE *bpipe) if (bpipe->wait) { int remaining_wait = bpipe->wait; - do + do { DWORD exitCode; if (!GetExitCodeProcess((HANDLE)bpipe->worker_pid, &exitCode)) { const char *err = errorString(); rval = GetLastError(); - d_msg(__FILE__, __LINE__, 0, + d_msg(__FILE__, __LINE__, 0, "GetExitCode error %s\n", err); LocalFree((void *)err); break; } - + if (exitCode == STILL_ACTIVE) { bmicrosleep(1, 0); /* wait one second */ remaining_wait--; @@ -1056,11 +1075,11 @@ close_bpipe(BPIPE *bpipe) else break; } while(remaining_wait); } - + if (bpipe->timer_id) { stop_child_timer(bpipe->timer_id); } - free((void *)bpipe); + free((void *)bpipe); return rval; } @@ -1068,7 +1087,7 @@ int close_wpipe(BPIPE *bpipe) { int stat = 1; - + if (bpipe->wfd) { fflush(bpipe->wfd); if (fclose(bpipe->wfd) != 0) { @@ -1111,7 +1130,7 @@ utime(const char *fname, struct utimbuf *times) int rval = SetFileTime(h, NULL, &acc, &mod) ? 0 : -1; CloseHandle(h); - + return rval; } @@ -1167,21 +1186,21 @@ open(const char *file, int flags, int mode) if (flags & O_WRONLY) access = GENERIC_WRITE; else if (flags & O_RDWR) access = GENERIC_READ|GENERIC_WRITE; else access = GENERIC_READ; - + if (flags & O_CREAT) create = CREATE_NEW; else create = OPEN_EXISTING; - + if (flags & O_TRUNC) create = TRUNCATE_EXISTING; - + if (!(flags & O_EXCL)) shareMode = FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE; - + if (flags & O_APPEND) { printf("open...APPEND not implemented yet."); exit(-1); } - + foo = CreateFile(file, access, shareMode, NULL, create, msflags, NULL); if (INVALID_HANDLE_VALUE == foo) return(int) -1; @@ -1239,7 +1258,7 @@ lseek(int fd, off_t offset, int whence) default: return -1; } - + return SetFilePointer((HANDLE)fd, (DWORD)offset, NULL, method); } @@ -1251,3 +1270,10 @@ dup2(int, int) #endif + +#endif //HAVE_MINGW + +#ifdef HAVE_MINGW +/* syslog function, added by Nicolas Boichat */ +void closelog() {} +#endif //HAVE_MINGW diff --git a/bacula/src/win32/compat/compat.h b/bacula/src/win32/compat/compat.h index c0caa8af33..a75b9bad2b 100644 --- a/bacula/src/win32/compat/compat.h +++ b/bacula/src/win32/compat/compat.h @@ -1,11 +1,11 @@ -/* -*- Mode: C -*- - * compat.h -- +/* -*- Mode: C -*- + * compat.h -- */ -// Copyright transferred from Raider Solutions, Inc to +// Copyright transferred from Raider Solutions, Inc to // Kern Sibbald and John Walker by express permission. // // Copyright (C) 2004 Kern Sibbald and John Walker -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of @@ -20,12 +20,12 @@ // License along with this program; if not, write to the Free // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, // MA 02111-1307, USA. - * - * +/* + * * Author : Christopher S. Hull * Created On : Fri Jan 30 13:00:51 2004 - * Last Modified By: Christopher S. Hull - * Last Modified On: Tue Feb 24 11:13:32 2004 + * Last Modified By: Nicolas Boichat + * Last Modified On: Sat Apr 17 19:30:00 2004 * Update Count : 218 * $Id$ */ @@ -34,7 +34,9 @@ #ifndef __COMPAT_H_ #define __COMPAT_H_ +#ifndef HAVE_MINGW #define __STDC__ 1 +#endif #include #include @@ -63,14 +65,22 @@ #include #include +#if defined HAVE_MINGW +#include +#include +#endif #include "getopt.h" +#ifdef HAVE_MINGW +#define HAVE_WIN32 1 +#else #ifdef HAVE_CYGWIN #error should not be used under cygwin... #else #define HAVE_WIN32 1 -#endif +#endif //HAVE_CYGWIN +#endif //HAVE_MINGW typedef UINT64 u_int64_t; typedef UINT64 uint64_t; typedef INT64 int64_t; @@ -83,34 +93,43 @@ typedef unsigned short uint16_t; typedef signed short int16_t; typedef long time_t; #if __STDC__ +#ifndef HAVE_MINGW typedef _dev_t dev_t; typedef __int64 ino_t; typedef __int64 off_t; /* STDC=1 means we can define this */ +#endif #else typedef long _off_t; /* must be same as sys/types.h */ #endif typedef signed char int8_t; +#ifndef HAVE_MINGW typedef int BOOL; #define bool BOOL +#endif typedef double float64_t; typedef UINT32 u_int32_t; typedef unsigned char u_int8_t; typedef unsigned short u_int16_t; +#ifndef HAVE_MINGW #undef uint32_t +#endif void sleep(int); typedef UINT32 key_t; + +#ifdef HAVE_MINGW +#ifndef uid_t +typedef UINT32 uid_t; +typedef UINT32 gid_t; +#endif +#else typedef UINT32 uid_t; typedef UINT32 gid_t; typedef UINT32 mode_t; typedef INT64 ssize_t; - -typedef void DIR; - - struct dirent { uint64_t d_ino; uint32_t d_off; @@ -118,6 +137,10 @@ struct dirent { char d_name[256]; }; +#endif //HAVE_MINGW + +typedef void DIR; + #ifndef __cplusplus #ifndef true #define true 1 @@ -137,6 +160,7 @@ int gettimeofday(struct timeval *, struct timezone *); #define ETIMEDOUT 55 +#ifndef HAVE_MINGW struct stat { _dev_t st_dev; @@ -166,6 +190,7 @@ struct stat #define S_IRUSR S_IREAD #define S_IWUSR S_IWRITE #define S_IXUSR S_IEXEC +#endif //HAVE_MINGW #define S_IRGRP 000040 #define S_IWGRP 000020 @@ -181,12 +206,13 @@ struct stat #define S_ISGID 002000 #define S_ISVTX 001000 - +#ifndef HAVE_MINGW #define S_ISREG(x) (((x) & S_IFREG) == S_IFREG) #define S_ISDIR(x) (((x) & S_IFDIR) == S_IFDIR) #define S_ISCHR(x) 0 #define S_ISBLK(x) 0 #define S_ISFIFO(x) 0 +#endif //HAVE_MINGW #define S_ISSOCK(x) 0 #define S_ISLNK(x) 0 @@ -210,12 +236,14 @@ int umask(int); int lchown(const char *, uid_t uid, gid_t gid); int chown(const char *, uid_t uid, gid_t gid); int chmod(const char *, mode_t mode); +#ifndef HAVE_MINGW int utime(const char *filename, struct utimbuf *buf); int open(const char *, int, int); -off_t lseek(int, off_t, int); ssize_t read(int fd, void *, size_t nbytes); ssize_t write(int fd, const void *, size_t nbytes); int close(int fd); +#endif //HAVE_MINGW +off_t lseek(int, off_t, int); int inet_aton(const char *cp, struct in_addr *inp); int kill(int pid, int signo); int pipe(int []); @@ -231,7 +259,7 @@ int waitpid(int, int *, int); #define HAVE_OLD_SOCKOPT - +#ifndef HAVE_MINGW #define vsnprintf __vsnprintf int __vsnprintf(char *s, size_t count, const char *format, va_list args); @@ -243,7 +271,7 @@ int __snprintf(char *str, size_t count, const char *fmt, ...); #define sprintf __sprintf int __sprintf(char *str, const char *fmt, ...); - +#endif //HAVE_MINGW int readdir(unsigned int fd, struct dirent *dirp, unsigned int count); int nanosleep(const struct timespec*, struct timespec *); @@ -261,8 +289,11 @@ int readlink(const char *, char *, int); int geteuid(); + +#ifndef HAVE_MINGW DIR *opendir(const char *name); int closedir(DIR *dir); +#endif //HAVE_MINGW struct passwd { char *foo; @@ -275,9 +306,10 @@ struct group { struct passwd *getpwuid(uid_t); struct group *getgrgid(uid_t); +#ifndef HAVE_MINGW #define R_OK 04 #define W_OK 02 - +#endif //HAVE_MINGW struct sigaction { int sa_flags; @@ -289,17 +321,21 @@ struct sigaction { #define mkdir(p, m) _mkdir(p) #define chdir win32_chdir +#ifndef HAVE_MINGW int stat(const char *, struct stat *); +#endif //HAVE_MINGW int syslog(int, const char *, const char *); #define LOG_DAEMON 0 #define LOG_ERR 0 +#ifndef HAVE_MINGW #ifdef __cplusplus #define access _access extern "C" _CRTIMP int __cdecl _access(const char *, int); int execvp(const char *, char *[]); extern "C" void * __cdecl _alloca(size_t); #endif +#endif //HAVE_MINGW #define getpid _getpid @@ -315,4 +351,8 @@ int win32_chdir(const char *buf); int WSA_Init(void); +#ifdef HAVE_MINGW +void closelog(); +#endif //HAVE_MINGW + #endif /* __COMPAT_H_ */ diff --git a/bacula/src/win32/compat/winconfig.h b/bacula/src/win32/compat/winconfig.h index 79b784785c..cf67ce7f41 100644 --- a/bacula/src/win32/compat/winconfig.h +++ b/bacula/src/win32/compat/winconfig.h @@ -149,7 +149,7 @@ #define _PATH_BACULA_PIDDIR "/var/run" /* Define if you have zlib */ -#define HAVE_LIBZ 1 +#define HAVE_LIBZ 1 /* General libs */ /* #undef LIBS */ @@ -225,7 +225,9 @@ /* Define to 1 if you have `alloca', as a function or macro. */ #define HAVE_ALLOCA 1 +#ifndef HAVE_MINGW #define alloca _alloca +#endif /* Define to 1 if you have and it should be used (not on Ultrix). */ #define HAVE_ALLOCA_H 1 @@ -371,7 +373,7 @@ /*#define HAVE_SIGNAL 1 */ /* Define to 1 if you have the `snprintf' function. */ -#define HAVE_SNPRINTF 1 +#define HAVE_SNPRINTF 1 /* Define to 1 if you have the header file. */ /*#define HAVE_STDARG_H 1*/ diff --git a/bacula/src/wx-console/Makefile.mingw b/bacula/src/wx-console/Makefile.mingw new file mode 100644 index 0000000000..c3a1a2011c --- /dev/null +++ b/bacula/src/wx-console/Makefile.mingw @@ -0,0 +1,53 @@ +CPP = g++.exe -D__DEBUG__ -DHAVE_MINGW +CC = gcc.exe -D__DEBUG__ -DHAVE_MINGW +WINDRES = windres.exe +RES = wx-console_private.res +OBJ = main.o console_thread.o authenticate.o console_conf.o wxbrestorepanel.o wxbmainframe.o wxbtableparser.o wxbtreectrl.o wxblistctrl.o $(RES) +LINKOBJ = main.o console_thread.o authenticate.o console_conf.o wxbrestorepanel.o wxbmainframe.o wxbtableparser.o wxbtreectrl.o wxblistctrl.o $(RES) +LIBS = -L"../lib" -mwindows -Wl,--subsystem,windows -lbac `wx-config --libs` -g3 /MinGW/lib/libpthreadGC.a +INCS = -I".." -I"../lib" -I"../win32/compat/" +CXXINCS = -I".." -I"../lib" -I"../win32/compat/" +BIN = wx-console.exe +CXXFLAGS = $(CXXINCS) `wx-config --cppflags` -Wall -g3 +CFLAGS = $(INCS) -g3 + +.PHONY: all all-before all-after clean clean-custom + +all: all-before wx-console.exe all-after + + +clean: clean-custom + rm -f $(OBJ) $(BIN) + +$(BIN): $(OBJ) + $(CPP) $(LINKOBJ) -o "wx-console.exe" $(LIBS) + +main.o: main.cpp + $(CPP) -c main.cpp -o main.o $(CXXFLAGS) + +console_thread.o: console_thread.cpp + $(CPP) -c console_thread.cpp -o console_thread.o $(CXXFLAGS) + +authenticate.o: authenticate.c + $(CPP) -c authenticate.c -o authenticate.o $(CXXFLAGS) + +console_conf.o: console_conf.c + $(CPP) -c console_conf.c -o console_conf.o $(CXXFLAGS) + +wxbrestorepanel.o: wxbrestorepanel.cpp + $(CPP) -c wxbrestorepanel.cpp -o wxbrestorepanel.o $(CXXFLAGS) + +wxbmainframe.o: wxbmainframe.cpp + $(CPP) -c wxbmainframe.cpp -o wxbmainframe.o $(CXXFLAGS) + +wxbtableparser.o: wxbtableparser.cpp + $(CPP) -c wxbtableparser.cpp -o wxbtableparser.o $(CXXFLAGS) + +wxbtreectrl.o: wxbtreectrl.cpp + $(CPP) -c wxbtreectrl.cpp -o wxbtreectrl.o $(CXXFLAGS) + +wxblistctrl.o: wxblistctrl.cpp + $(CPP) -c wxblistctrl.cpp -o wxblistctrl.o $(CXXFLAGS) + +wx-console_private.res: wx-console_private.rc + $(WINDRES) -i wx-console_private.rc -I rc -o wx-console_private.res -O coff