- 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
$(MAKE) \
CFLAGS="${CFLAGS} -D_WIN32_WINNT=0x0500 -DWINVER=0x0500" \
LINK_FLAGS="${LINK_FLAGS} -mwindows" \
EXTRAOBJS="resource.o win32-gui.o win32-plugin.o" \
LINK_FLAGS="${LINK_FLAGS} -mconsole" \
EXTRAOBJS="win32-resource.o win32-plugin.o" \
SYS_LIBS=" -llargeint -lws2_32 -lpdh -lnetapi32 -liphlpapi -lntdll -lintl" \
gkrellmd
@ -207,9 +207,11 @@ clean:
libgkrellmd.a core
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/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
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
ar -cr libgkrellmd.a win32-libgkrellmd.o
resource.o: ../resource.rc
windres -I.. -o resource.o ../resource.rc
win32-resource.o: win32-resource.rc win32-resource.h
windres -I.. -o win32-resource.o win32-resource.rc

View File

@ -22,12 +22,6 @@
#include "gkrellmd.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
#if !defined(HAVE_GETADDRINFO) && !defined(WIN32)
struct addrinfo
@ -94,11 +88,20 @@ remove_pidfile(void)
#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
cb_sigterm(gint sig)
{
remove_pidfile();
exit(0);
gkrellmd_exit(0);
}
gint
@ -600,6 +603,7 @@ read_config(void)
gchar *path;
_GK.update_HZ = 3;
_GK.debug_level = 0;
_GK.max_clients = 2;
_GK.server_port = GKRELLMD_SERVER_PORT;
@ -865,7 +869,7 @@ detach_from_terminal(void)
#if !defined(WIN32)
#if !defined(HAVE_DAEMON)
gint i, fd;
#endif
#endif /* HAVE_DAEMON */
if (getppid() == 1) /* already a daemon */
return;
@ -874,8 +878,7 @@ detach_from_terminal(void)
if (daemon(0, 0))
{
fprintf(stderr, "gkrellmd detach failed: %s\n", strerror(errno));
remove_pidfile();
exit(1);
gkrellmd_exit(1);
}
#else
i = fork();
@ -885,8 +888,7 @@ detach_from_terminal(void)
if (i < 0 || setsid() == -1) /* new session process group */
{
fprintf(stderr, "gkrellmd detach failed: %s\n", strerror(errno));
remove_pidfile();
exit(1);
gkrellmd_exit(1);
}
if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1)
@ -898,7 +900,7 @@ detach_from_terminal(void)
close(fd);
}
chdir("/");
#endif
#endif /* HAVE_DAEMON */
// signal(SIGCHLD, SIG_IGN);
signal(SIGTSTP, SIG_IGN);
@ -907,8 +909,8 @@ detach_from_terminal(void)
signal(SIGHUP, SIG_IGN);
#if !defined(MSG_NOSIGNAL)
signal(SIGPIPE, SIG_IGN);
#endif
#endif
#endif /* MSG_NOSIGNAL */
#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
main(gint argc, gchar **argv)
{
#endif // WIN32
#ifdef HAVE_GETADDRINFO
struct sockaddr_storage client_addr;
#else
@ -952,7 +945,7 @@ main(gint argc, gchar **argv)
size_t addr_len;
gint fd, server_fd, client_fd, i;
#if defined(WIN32)
gulong nbytes;
gulong nbytes;
#else
gint nbytes;
#endif // WIN32
@ -960,18 +953,11 @@ main(gint argc, gchar **argv)
gint listen_fds = 0;
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 LOCALEDIR
bindtextdomain(PACKAGE_D, LOCALEDIR);
#endif
#endif /* LOCALEDIR */
textdomain(PACKAGE_D);
bind_textdomain_codeset(PACKAGE_D, "UTF-8");
#endif /* ENABLE_NLS */
@ -982,6 +968,11 @@ main(gint argc, gchar **argv)
if (_GK.verbose)
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
&& !_GK.log_plugins && !_GK.list_plugins && _GK.debug_level == 0
)
@ -989,15 +980,13 @@ main(gint argc, gchar **argv)
else
{
signal(SIGTERM, cb_sigterm);
#if !defined(WIN32)
signal(SIGQUIT, cb_sigterm);
signal(SIGTSTP, SIG_IGN);
#endif
signal(SIGINT, cb_sigterm);
}
#endif
make_pidfile();
gkrellm_sys_main_init();
drop_privileges();
@ -1021,8 +1010,7 @@ main(gint argc, gchar **argv)
if (_GK.server_fd == NULL)
{
fprintf(stderr, "gkrellmd socket() failed: %s\n", strerror(errno));
remove_pidfile();
exit(1);
gkrellmd_exit(1);
}
/* Listen on the socket so a client gkrellm can connect.
@ -1043,43 +1031,34 @@ main(gint argc, gchar **argv)
if (listen_fds <= 0)
{
fprintf(stderr, "gkrellmd listen() failed: %s\n", strerror(errno));
remove_pidfile();
exit(1);
gkrellmd_exit(1);
}
interval = 1000000 / _GK.update_HZ;
#if defined(WIN32)
while (!done)
{
{
MSG msg;
while (PeekMessage(&msg, (HWND) NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#else
while(1)
// main event loop
while(1)
{
#endif
test_fds = read_fds;
#ifdef HAVE_GETADDRINFO
addr_len = sizeof(struct sockaddr_storage);
#else
addr_len = sizeof(struct sockaddr_in);
#endif
tv.tv_usec = interval;
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)
continue;
fprintf(stderr, "gkrellmd select() failed: %s\n", strerror(errno));
remove_pidfile();
exit(1);
gkrellmd_exit(1);
}
#if 0 /* BUG, result is 0 when test_fds has a set fd!! */
if (result == 0)
{
@ -1087,17 +1066,20 @@ main(gint argc, gchar **argv)
continue;
}
#endif
for (fd = 0; fd <= max_fd; ++fd)
{
if (!FD_ISSET(fd, &test_fds))
continue;
server_fd = -1;
for (i = 1; i <= _GK.server_fd[0]; ++i)
{
if (fd == _GK.server_fd[i])
{
server_fd = fd;
break;
}
}
if (server_fd >= 0)
{
client_fd = accept(server_fd,
@ -1107,8 +1089,7 @@ main(gint argc, gchar **argv)
{
fprintf(stderr, "gkrellmd accept() failed: %s\n",
strerror(errno));
remove_pidfile();
exit(1);
gkrellmd_exit(1);
}
if (client_fd > max_fd)
max_fd = client_fd;
@ -1122,9 +1103,11 @@ main(gint argc, gchar **argv)
FD_SET(client_fd, &read_fds);
gkrellmd_serve_setup(client);
if (_GK.verbose)
{
printf("gkrellmd accepted client: %s:%u\n",
client->hostname,
ntohs(((struct sockaddr_in *)&client_addr)->sin_port));
}
}
else
{
@ -1139,13 +1122,9 @@ main(gint argc, gchar **argv)
}
}
gkrellmd_update_monitors();
}
#ifdef WIN32
deleteServerWindow();
#endif
} /* while(1) */
return 0;
} // main()/WinMain()
} // main()
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"