- own win32 resource file for gkrellmd

- request admin-rights for gkrellmd on win32 (done via manifest file)
- fix make dependencies on sysdeps folder
- new function gkrellmd_exit() to exit gkrellmd properly, gkrellm_sys_main_cleanup() was never called on exit
- make gkrellmd a console application on win32 (first step towards making it an nt-service)
This commit is contained in:
Stefan Gehn 2008-02-01 20:31:53 +00:00
parent 55b00bc848
commit 4e128bfa18
5 changed files with 110 additions and 73 deletions

View File

@ -154,8 +154,8 @@ endif
windows: libgkrellmd.a windows: libgkrellmd.a
$(MAKE) \ $(MAKE) \
CFLAGS="${CFLAGS} -D_WIN32_WINNT=0x0500 -DWINVER=0x0500" \ CFLAGS="${CFLAGS} -D_WIN32_WINNT=0x0500 -DWINVER=0x0500" \
LINK_FLAGS="${LINK_FLAGS} -mwindows" \ LINK_FLAGS="${LINK_FLAGS} -mconsole" \
EXTRAOBJS="resource.o win32-gui.o win32-plugin.o" \ EXTRAOBJS="win32-resource.o win32-plugin.o" \
SYS_LIBS=" -llargeint -lws2_32 -lpdh -lnetapi32 -liphlpapi -lntdll -lintl" \ SYS_LIBS=" -llargeint -lws2_32 -lpdh -lnetapi32 -liphlpapi -lntdll -lintl" \
gkrellmd gkrellmd
@ -207,9 +207,11 @@ clean:
libgkrellmd.a core libgkrellmd.a core
SYSDEPS = ../src/sysdeps/bsd-common.c ../src/sysdeps/bsd-net-open.c \ SYSDEPS = ../src/sysdeps/bsd-common.c ../src/sysdeps/bsd-net-open.c \
../src/sysdeps/darwin.c \
../src/sysdeps/freebsd.c ../src/sysdeps/gtop.c \ ../src/sysdeps/freebsd.c ../src/sysdeps/gtop.c \
../src/sysdeps/linux.c ../src/sysdeps/netbsd.c \ ../src/sysdeps/linux.c ../src/sysdeps/netbsd.c \
../src/sysdeps/openbsd.c ../src/sysdeps/solaris.c ../src/sysdeps/darwin.c ../src/sysdeps/openbsd.c ../src/sysdeps/sensors-common.c \
../src/sysdeps/solaris.c ../src/sysdeps/win32.c
main.o: main.c gkrellmd.h main.o: main.c gkrellmd.h
monitor.o: monitor.c gkrellmd.h monitor.o: monitor.c gkrellmd.h
@ -225,6 +227,5 @@ win32-libgkrellmd.o: win32-libgkrellmd.c win32-plugin.h gkrellmd.h
libgkrellmd.a: win32-libgkrellmd.o libgkrellmd.a: win32-libgkrellmd.o
ar -cr libgkrellmd.a win32-libgkrellmd.o ar -cr libgkrellmd.a win32-libgkrellmd.o
resource.o: ../resource.rc win32-resource.o: win32-resource.rc win32-resource.h
windres -I.. -o resource.o ../resource.rc windres -I.. -o win32-resource.o win32-resource.rc

View File

@ -22,12 +22,6 @@
#include "gkrellmd.h" #include "gkrellmd.h"
#include "gkrellmd-private.h" #include "gkrellmd-private.h"
#ifdef WIN32
#include "win32-gui.h"
#endif
//#include "../src/inet.h"
// we do have addrinfo on win32 but do not have getaddrinfo(), doh // we do have addrinfo on win32 but do not have getaddrinfo(), doh
#if !defined(HAVE_GETADDRINFO) && !defined(WIN32) #if !defined(HAVE_GETADDRINFO) && !defined(WIN32)
struct addrinfo struct addrinfo
@ -94,11 +88,20 @@ remove_pidfile(void)
#endif #endif
} }
static void
gkrellmd_exit(gint exit_code)
{
if (_GK.debug_level & DEBUG_SYSDEP)
printf("GKrellM Daemon exiting.\n");
gkrellm_sys_main_cleanup();
remove_pidfile();
exit(exit_code);
}
static void static void
cb_sigterm(gint sig) cb_sigterm(gint sig)
{ {
remove_pidfile(); gkrellmd_exit(0);
exit(0);
} }
gint gint
@ -600,6 +603,7 @@ read_config(void)
gchar *path; gchar *path;
_GK.update_HZ = 3; _GK.update_HZ = 3;
_GK.debug_level = 0;
_GK.max_clients = 2; _GK.max_clients = 2;
_GK.server_port = GKRELLMD_SERVER_PORT; _GK.server_port = GKRELLMD_SERVER_PORT;
@ -865,7 +869,7 @@ detach_from_terminal(void)
#if !defined(WIN32) #if !defined(WIN32)
#if !defined(HAVE_DAEMON) #if !defined(HAVE_DAEMON)
gint i, fd; gint i, fd;
#endif #endif /* HAVE_DAEMON */
if (getppid() == 1) /* already a daemon */ if (getppid() == 1) /* already a daemon */
return; return;
@ -874,8 +878,7 @@ detach_from_terminal(void)
if (daemon(0, 0)) if (daemon(0, 0))
{ {
fprintf(stderr, "gkrellmd detach failed: %s\n", strerror(errno)); fprintf(stderr, "gkrellmd detach failed: %s\n", strerror(errno));
remove_pidfile(); gkrellmd_exit(1);
exit(1);
} }
#else #else
i = fork(); i = fork();
@ -885,8 +888,7 @@ detach_from_terminal(void)
if (i < 0 || setsid() == -1) /* new session process group */ if (i < 0 || setsid() == -1) /* new session process group */
{ {
fprintf(stderr, "gkrellmd detach failed: %s\n", strerror(errno)); fprintf(stderr, "gkrellmd detach failed: %s\n", strerror(errno));
remove_pidfile(); gkrellmd_exit(1);
exit(1);
} }
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1)
@ -898,7 +900,7 @@ detach_from_terminal(void)
close(fd); close(fd);
} }
chdir("/"); chdir("/");
#endif #endif /* HAVE_DAEMON */
// signal(SIGCHLD, SIG_IGN); // signal(SIGCHLD, SIG_IGN);
signal(SIGTSTP, SIG_IGN); signal(SIGTSTP, SIG_IGN);
@ -907,8 +909,8 @@ detach_from_terminal(void)
signal(SIGHUP, SIG_IGN); signal(SIGHUP, SIG_IGN);
#if !defined(MSG_NOSIGNAL) #if !defined(MSG_NOSIGNAL)
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
#endif #endif /* MSG_NOSIGNAL */
#endif #endif /* WIN32 */
} }
@ -928,19 +930,10 @@ drop_privileges(void)
} }
#if defined(WIN32)
int APIENTRY
WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nCmdShow)
{
int argc;
gchar **argv;
gchar *cmd;
#else
gint gint
main(gint argc, gchar **argv) main(gint argc, gchar **argv)
{ {
#endif // WIN32
#ifdef HAVE_GETADDRINFO #ifdef HAVE_GETADDRINFO
struct sockaddr_storage client_addr; struct sockaddr_storage client_addr;
#else #else
@ -952,7 +945,7 @@ main(gint argc, gchar **argv)
size_t addr_len; size_t addr_len;
gint fd, server_fd, client_fd, i; gint fd, server_fd, client_fd, i;
#if defined(WIN32) #if defined(WIN32)
gulong nbytes; gulong nbytes;
#else #else
gint nbytes; gint nbytes;
#endif // WIN32 #endif // WIN32
@ -960,18 +953,11 @@ main(gint argc, gchar **argv)
gint listen_fds = 0; gint listen_fds = 0;
gint interval, result; gint interval, result;
#if defined(WIN32)
createServerWindow(hInst);
// lpCmd does not contain the exe name, GetCommandLine() does :)
cmd = GetCommandLine();
g_shell_parse_argv(cmd, &argc, &argv, NULL);
#endif // WIN32
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
#ifdef LOCALEDIR #ifdef LOCALEDIR
bindtextdomain(PACKAGE_D, LOCALEDIR); bindtextdomain(PACKAGE_D, LOCALEDIR);
#endif #endif /* LOCALEDIR */
textdomain(PACKAGE_D); textdomain(PACKAGE_D);
bind_textdomain_codeset(PACKAGE_D, "UTF-8"); bind_textdomain_codeset(PACKAGE_D, "UTF-8");
#endif /* ENABLE_NLS */ #endif /* ENABLE_NLS */
@ -982,6 +968,11 @@ main(gint argc, gchar **argv)
if (_GK.verbose) if (_GK.verbose)
printf("update_HZ=%d\n", _GK.update_HZ); printf("update_HZ=%d\n", _GK.update_HZ);
#if defined(WIN32)
// can't detach, just listen to QUIT and TERM signals
signal(SIGTERM, cb_sigterm);
signal(SIGINT, cb_sigterm);
#else
if ( detach_flag if ( detach_flag
&& !_GK.log_plugins && !_GK.list_plugins && _GK.debug_level == 0 && !_GK.log_plugins && !_GK.list_plugins && _GK.debug_level == 0
) )
@ -989,15 +980,13 @@ main(gint argc, gchar **argv)
else else
{ {
signal(SIGTERM, cb_sigterm); signal(SIGTERM, cb_sigterm);
#if !defined(WIN32)
signal(SIGQUIT, cb_sigterm); signal(SIGQUIT, cb_sigterm);
signal(SIGTSTP, SIG_IGN); signal(SIGTSTP, SIG_IGN);
#endif
signal(SIGINT, cb_sigterm); signal(SIGINT, cb_sigterm);
} }
#endif
make_pidfile(); make_pidfile();
gkrellm_sys_main_init(); gkrellm_sys_main_init();
drop_privileges(); drop_privileges();
@ -1021,8 +1010,7 @@ main(gint argc, gchar **argv)
if (_GK.server_fd == NULL) if (_GK.server_fd == NULL)
{ {
fprintf(stderr, "gkrellmd socket() failed: %s\n", strerror(errno)); fprintf(stderr, "gkrellmd socket() failed: %s\n", strerror(errno));
remove_pidfile(); gkrellmd_exit(1);
exit(1);
} }
/* Listen on the socket so a client gkrellm can connect. /* Listen on the socket so a client gkrellm can connect.
@ -1043,43 +1031,34 @@ main(gint argc, gchar **argv)
if (listen_fds <= 0) if (listen_fds <= 0)
{ {
fprintf(stderr, "gkrellmd listen() failed: %s\n", strerror(errno)); fprintf(stderr, "gkrellmd listen() failed: %s\n", strerror(errno));
remove_pidfile(); gkrellmd_exit(1);
exit(1);
} }
interval = 1000000 / _GK.update_HZ; interval = 1000000 / _GK.update_HZ;
#if defined(WIN32) // main event loop
while (!done) while(1)
{
{
MSG msg;
while (PeekMessage(&msg, (HWND) NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#else
while(1)
{ {
#endif
test_fds = read_fds; test_fds = read_fds;
#ifdef HAVE_GETADDRINFO #ifdef HAVE_GETADDRINFO
addr_len = sizeof(struct sockaddr_storage); addr_len = sizeof(struct sockaddr_storage);
#else #else
addr_len = sizeof(struct sockaddr_in); addr_len = sizeof(struct sockaddr_in);
#endif #endif
tv.tv_usec = interval; tv.tv_usec = interval;
tv.tv_sec = 0; tv.tv_sec = 0;
if ((result = select(max_fd + 1, &test_fds, NULL, NULL, &tv) == -1))
result = select(max_fd + 1, &test_fds, NULL, NULL, &tv);
if (result == -1)
{ {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
fprintf(stderr, "gkrellmd select() failed: %s\n", strerror(errno)); fprintf(stderr, "gkrellmd select() failed: %s\n", strerror(errno));
remove_pidfile(); gkrellmd_exit(1);
exit(1);
} }
#if 0 /* BUG, result is 0 when test_fds has a set fd!! */ #if 0 /* BUG, result is 0 when test_fds has a set fd!! */
if (result == 0) if (result == 0)
{ {
@ -1087,17 +1066,20 @@ main(gint argc, gchar **argv)
continue; continue;
} }
#endif #endif
for (fd = 0; fd <= max_fd; ++fd) for (fd = 0; fd <= max_fd; ++fd)
{ {
if (!FD_ISSET(fd, &test_fds)) if (!FD_ISSET(fd, &test_fds))
continue; continue;
server_fd = -1; server_fd = -1;
for (i = 1; i <= _GK.server_fd[0]; ++i) for (i = 1; i <= _GK.server_fd[0]; ++i)
{
if (fd == _GK.server_fd[i]) if (fd == _GK.server_fd[i])
{ {
server_fd = fd; server_fd = fd;
break; break;
} }
}
if (server_fd >= 0) if (server_fd >= 0)
{ {
client_fd = accept(server_fd, client_fd = accept(server_fd,
@ -1107,8 +1089,7 @@ main(gint argc, gchar **argv)
{ {
fprintf(stderr, "gkrellmd accept() failed: %s\n", fprintf(stderr, "gkrellmd accept() failed: %s\n",
strerror(errno)); strerror(errno));
remove_pidfile(); gkrellmd_exit(1);
exit(1);
} }
if (client_fd > max_fd) if (client_fd > max_fd)
max_fd = client_fd; max_fd = client_fd;
@ -1122,9 +1103,11 @@ main(gint argc, gchar **argv)
FD_SET(client_fd, &read_fds); FD_SET(client_fd, &read_fds);
gkrellmd_serve_setup(client); gkrellmd_serve_setup(client);
if (_GK.verbose) if (_GK.verbose)
{
printf("gkrellmd accepted client: %s:%u\n", printf("gkrellmd accepted client: %s:%u\n",
client->hostname, client->hostname,
ntohs(((struct sockaddr_in *)&client_addr)->sin_port)); ntohs(((struct sockaddr_in *)&client_addr)->sin_port));
}
} }
else else
{ {
@ -1139,13 +1122,9 @@ main(gint argc, gchar **argv)
} }
} }
gkrellmd_update_monitors(); gkrellmd_update_monitors();
} } /* while(1) */
#ifdef WIN32
deleteServerWindow();
#endif
return 0; return 0;
} // main()/WinMain() } // main()
GkrellmdTicks * GkrellmdTicks *

12
server/win32-manifest.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="gkrellmd.exe" type="win32"/>
<description>GKrellM Daemon</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

5
server/win32-resource.h Normal file
View File

@ -0,0 +1,5 @@
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif
#define IDI_ICON3 105

40
server/win32-resource.rc Normal file
View File

@ -0,0 +1,40 @@
#include "win32-resource.h"
#include "windows.h"
//
// Icon resources
//
IDI_ICON3 ICON "gkrellm.ico"
//
// Version Information resources
//
1 VERSIONINFO
FILEVERSION 2,3,1,0
PRODUCTVERSION 0,0,0,0
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "FileDescription", "GKrellM Daemon"
VALUE "FileVersion", "2.3.1"
VALUE "InternalName", "gkrellmd"
VALUE "LegalCopyright", "Copyright (C) 1999-2007 Bill Wilson"
VALUE "OriginalFilename", "gkrellmd.exe"
VALUE "ProductName", "GKrellM"
VALUE "ProductVersion", "2.3.1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
//
// Manifest resources
//
1 RT_MANIFEST "win32-manifest.xml"