Skip to content
Snippets Groups Projects
Select Git revision
  • e97cabc18ba8811a74272385a13d160441ff5ca9
  • master default
  • trunk
  • RELEASE_6_5_DRIVEDB
  • RELEASE_6_6_DRIVEDB
  • RELEASE_7_0_DRIVEDB
  • RELEASE_7_2_DRIVEDB
  • RELEASE_7_3_DRIVEDB
  • RELEASE_6_0_DRIVEDB
  • RELEASE_6_1_DRIVEDB
  • RELEASE_6_2_DRIVEDB
  • RELEASE_6_3_DRIVEDB
  • RELEASE_6_4_DRIVEDB
  • tags/RELEASE_7_4
  • tags/RELEASE_7_3
  • RELEASE_5_41_DRIVEDB
  • RELEASE_5_42_DRIVEDB
  • RELEASE_5_43_DRIVEDB
  • tags/RELEASE_7_2
  • tags/RELEASE_7_1
  • tags/RELEASE_7_0
  • RELEASE_5_40_DRIVEDB
22 results

daemon_win32.cpp

Blame
  • 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);
    }