| 6 |
details. |
details. |
| 7 |
|
|
| 8 |
Mixmaster initialization, configuration |
Mixmaster initialization, configuration |
| 9 |
$Id: mix.c,v 1.2 2001/11/06 23:41:58 rabbi Exp $ */ |
$Id: mix.c,v 1.3 2001/12/11 20:59:26 rabbi Exp $ */ |
| 10 |
|
|
| 11 |
|
|
| 12 |
#include "mix3.h" |
#include "mix3.h" |
| 625 |
return (0); |
return (0); |
| 626 |
} |
} |
| 627 |
|
|
| 628 |
|
|
| 629 |
|
#ifdef WIN32 |
| 630 |
|
|
| 631 |
|
int is_nt_service(void) |
| 632 |
|
{ // Try to detect if we are the service or not... seems there is no easy reliable way :-( |
| 633 |
|
static int issvc = -1; |
| 634 |
|
#ifdef WIN32SERVICE |
| 635 |
|
STARTUPINFO StartupInfo; |
| 636 |
|
OSVERSIONINFO VersionInfo; |
| 637 |
|
DWORD dwsize; |
| 638 |
|
|
| 639 |
|
if (issvc != -1) //do it only once |
| 640 |
|
return issvc; |
| 641 |
|
|
| 642 |
|
VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo); |
| 643 |
|
if (GetVersionEx(&VersionInfo)) |
| 644 |
|
if (VersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT) |
| 645 |
|
return issvc = 0; // not NT - not the service |
| 646 |
|
|
| 647 |
|
if (!GetConsoleTitle(&VersionInfo,sizeof(VersionInfo))) // reuse VersionInfo to save memory |
| 648 |
|
return issvc = 1; // have no console - we are the service probably... |
| 649 |
|
|
| 650 |
|
dwsize = sizeof(VersionInfo); |
| 651 |
|
if (GetUserName(&VersionInfo,&dwsize)) // reuse VersionInfo again |
| 652 |
|
if (!strcmp(&VersionInfo, "SYSTEM")) |
| 653 |
|
return issvc = 1; // SYSTEM user - we are the service probably... |
| 654 |
|
|
| 655 |
|
GetStartupInfo(&StartupInfo); |
| 656 |
|
if (StartupInfo.lpDesktop[0] == 0) |
| 657 |
|
return issvc = 1; // have no desktop - we are the service probably... |
| 658 |
|
|
| 659 |
|
if (_fileno(stdin) == -1 && _fileno(stdout) == -1 && _fileno(stderr) == -1) |
| 660 |
|
return issvc = 1; // have no stdin,stderr,stdout - we are the service probably... |
| 661 |
|
#endif // WIN32SERVICE |
| 662 |
|
|
| 663 |
|
return issvc = 0; // assume not the service |
| 664 |
|
} // is_nt_service |
| 665 |
|
|
| 666 |
|
HANDLE hMustTerminate = NULL; |
| 667 |
|
void set_nt_exit_event(HANDLE h_svc_exit_event) |
| 668 |
|
{ |
| 669 |
|
hMustTerminate = h_svc_exit_event; |
| 670 |
|
} // set_nt_exit_event |
| 671 |
|
|
| 672 |
|
#endif // WIN32 |
| 673 |
|
|
| 674 |
int mix_daemon(void) |
int mix_daemon(void) |
| 675 |
{ |
{ |
| 676 |
long t; |
long t; |
|
#ifdef WIN32SERVICE |
|
|
long t1; |
|
|
HANDLE hMustTerminate = OpenEvent(EVENT_ALL_ACCESS, FALSE, "mixmaster-stop"); |
|
|
#endif |
|
| 677 |
t = SENDPOOLTIME; |
t = SENDPOOLTIME; |
| 678 |
#ifdef USE_SOCK |
#ifdef USE_SOCK |
| 679 |
if (POP3TIME < t) |
if (POP3TIME < t) |
| 684 |
mix_regular(0); |
mix_regular(0); |
| 685 |
#ifdef WIN32 |
#ifdef WIN32 |
| 686 |
#ifdef WIN32SERVICE |
#ifdef WIN32SERVICE |
| 687 |
t1 = t*2; |
if (hMustTerminate) { |
| 688 |
while (t1) { |
if (WaitForSingleObject(hMustTerminate, t * 1000) == WAIT_OBJECT_0) { |
| 689 |
if (hMustTerminate) |
CloseHandle(hMustTerminate); |
| 690 |
if (WaitForSingleObject(hMustTerminate, 500) == WAIT_OBJECT_0) { |
return 0; |
| 691 |
CloseHandle(hMustTerminate); |
} |
| 692 |
return 0; |
} else |
|
} |
|
|
t1--; |
|
|
} |
|
|
#else |
|
|
Sleep(t * 1000); |
|
| 693 |
#endif |
#endif |
| 694 |
|
Sleep(t * 1000); |
| 695 |
#else |
#else |
| 696 |
sleep(t); |
sleep(t); |
| 697 |
#endif |
#endif |