Select Git revision
daemon_win32.cpp
daemon_win32.cpp 28.33 KiB
/*
* os_win32/daemon_win32.c
*
* Home page of code is: http://smartmontools.sourceforge.net
*
* Copyright (C) 2004 Christian Franke <smartmontools-support@lists.sourceforge.net>
*
* 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, or (at your option)
* any later version.
*
* You should have received a copy of the GNU General Public License
* (for example COPYING); if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <io.h>
#define WIN32_LEAN_AND_MEAN
// Need MB_SERVICE_NOTIFICATION (NT4/2000/XP), IsDebuggerPresent() (Win98/ME/NT4/2000/XP)
#define _WIN32_WINNT 0x0400
#include <windows.h>
#ifdef _DEBUG
#include <crtdbg.h>
#endif
#include "daemon_win32.h"
const char *daemon_win32_c_cvsid = "$Id: daemon_win32.cpp,v 1.5 2004/08/09 14:35:59 chrfranke Exp $"
DAEMON_WIN32_H_CVSID;
/////////////////////////////////////////////////////////////////////////////
#define ARGUSED(x) ((void)(x))
// Prevent spawning of child process if debugging
#ifdef _DEBUG
#define debugging() IsDebuggerPresent()
#else
#define debugging() FALSE
#endif
#define EVT_NAME_LEN 260
// Internal events (must be > SIGUSRn)
#define EVT_RUNNING 100 // Exists when running, signaled on creation
#define EVT_DETACHED 101 // Signaled when child detaches from console
#define EVT_RESTART 102 // Signaled when child should restart
static void make_name(char * name, int sig)
{
int i;
if (!GetModuleFileNameA(NULL, name, EVT_NAME_LEN-10))
strcpy(name, "DaemonEvent");
for (i = 0; name[i]; i++) {
char c = name[i];
if (!( ('0' <= c && c <= '9')
|| ('A' <= c && c <= 'Z')
|| ('a' <= c && c <= 'z')))
name[i] = '_';
}
sprintf(name+strlen(name), "-%d", sig);
}