From d43bb8058f42e40aecd243696820672cf659dc78 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 21 Jan 2011 09:00:49 +0000 Subject: [PATCH] 2011-01-21 09:59 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + contrib/hbposix/tests/testdmn.prg * contrib/hbposix/hbposix.hbp + contrib/hbposix/daemon.c + Added HB_POSIX_DAEMON( lNoChdir, lNoClose ) --> lResult * contrib/hbmxml/hbmxmlp.prg * contrib/hbmagic/hbmagis.prg * contrib/hbmagic/tests/hbmagit.prg * contrib/hbmagic/hbmagic.c ! Minor fix to copyright line. ; Patch from Tamas. Thank you! * contrib/hbposix/tests/testdmn.prg * contrib/hbposix/daemon.c * Renamed POSIX_DAEMON() to HB_POSIX_DAEMON() to reflect fact that it implement higher level posix functionality (as opposed to being a direct wrapper to posix function names 'deamon()') --- harbour/ChangeLog | 21 ++++++ harbour/contrib/hbmagic/hbmagic.c | 2 +- harbour/contrib/hbmagic/hbmagis.prg | 2 +- harbour/contrib/hbmagic/tests/hbmagit.prg | 2 +- harbour/contrib/hbmxml/hbmxmlp.prg | 2 +- harbour/contrib/hbposix/daemon.c | 79 +++++++++++++++++++++++ harbour/contrib/hbposix/hbposix.hbp | 1 + harbour/contrib/hbposix/tests/testdmn.prg | 42 ++++++++++++ 8 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 harbour/contrib/hbposix/daemon.c create mode 100644 harbour/contrib/hbposix/tests/testdmn.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e12da9f9f7..5e237eaa32 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,27 @@ The license applies to all entries newer than 2009-04-28. */ +2011-01-21 09:59 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + + contrib/hbposix/tests/testdmn.prg + * contrib/hbposix/hbposix.hbp + + contrib/hbposix/daemon.c + + Added HB_POSIX_DAEMON( lNoChdir, lNoClose ) --> lResult + + * contrib/hbmxml/hbmxmlp.prg + * contrib/hbmagic/hbmagis.prg + * contrib/hbmagic/tests/hbmagit.prg + * contrib/hbmagic/hbmagic.c + ! Minor fix to copyright line. + + ; Patch from Tamas. Thank you! + + * contrib/hbposix/tests/testdmn.prg + * contrib/hbposix/daemon.c + * Renamed POSIX_DAEMON() to HB_POSIX_DAEMON() to reflect + fact that it implement higher level posix functionality + (as opposed to being a direct wrapper to posix function + names 'deamon()') + 2011-01-21 07:04 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/hbmxml/hbmxml.c % optimization - moved hb_itemNew()/hb_itemRelease() outside for() diff --git a/harbour/contrib/hbmagic/hbmagic.c b/harbour/contrib/hbmagic/hbmagic.c index 4dffe738eb..4cb378c330 100644 --- a/harbour/contrib/hbmagic/hbmagic.c +++ b/harbour/contrib/hbmagic/hbmagic.c @@ -6,7 +6,7 @@ * Harbour Project source code: * libmagic wrapper functions * - * Copyright 2010. Tamas TEVESZ + * Copyright 2010 Tamas TEVESZ * www - http://harbour-project.org * * This program is free software; you can redistribute it and/or modify diff --git a/harbour/contrib/hbmagic/hbmagis.prg b/harbour/contrib/hbmagic/hbmagis.prg index 58e0c428be..5bf9077f77 100644 --- a/harbour/contrib/hbmagic/hbmagis.prg +++ b/harbour/contrib/hbmagic/hbmagis.prg @@ -6,7 +6,7 @@ * Harbour Project source code: * libmagic convenience functions * - * Copyright 2010. Tamas TEVESZ + * Copyright 2010 Tamas TEVESZ * www - http://harbour-project.org * * This program is free software; you can redistribute it and/or modify diff --git a/harbour/contrib/hbmagic/tests/hbmagit.prg b/harbour/contrib/hbmagic/tests/hbmagit.prg index c7ef80928a..651936eeeb 100644 --- a/harbour/contrib/hbmagic/tests/hbmagit.prg +++ b/harbour/contrib/hbmagic/tests/hbmagit.prg @@ -6,7 +6,7 @@ * Harbour Project source code: * hbmagic test suite * - * Copyright 2010. Tamas TEVESZ + * Copyright 2010 Tamas TEVESZ * www - http://harbour-project.org * * This program is free software; you can redistribute it and/or modify diff --git a/harbour/contrib/hbmxml/hbmxmlp.prg b/harbour/contrib/hbmxml/hbmxmlp.prg index 9f03de1a8e..046541bb9b 100644 --- a/harbour/contrib/hbmxml/hbmxmlp.prg +++ b/harbour/contrib/hbmxml/hbmxmlp.prg @@ -6,7 +6,7 @@ * Harbour Project source code: * MINIXML functions wrapper * - * Copyright 2010. Tamas TEVESZ + * Copyright 2010 Tamas TEVESZ * www - http://harbour-project.org * * This program is free software; you can redistribute it and/or modify diff --git a/harbour/contrib/hbposix/daemon.c b/harbour/contrib/hbposix/daemon.c new file mode 100644 index 0000000000..b6bb64fb0a --- /dev/null +++ b/harbour/contrib/hbposix/daemon.c @@ -0,0 +1,79 @@ +/* + * $Id$ + */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * Copyright (c) 2011 Tamas TEVESZ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "hbapi.h" +#include "hbvm.h" + +#include +#include + +/* + * hb_posix_daemon( lNoChdir, lNoClose ) --> lResult + */ +HB_FUNC( HB_POSIX_DAEMON ) +{ + int fd; + + switch( fork() ) + { + case -1: + hb_retl( HB_FALSE ); + return; + case 0: + break; + default: + hb_vmRequestQuit(); + exit( 0 ); + } + + if( setsid() == -1 ) + { + hb_retl( HB_FALSE ); + return; + } + + if( ! hb_parl( 1 ) ) + ( void ) chdir( "/" ); + + if( ! hb_parl( 2 ) && ( fd = open( "/dev/null", O_RDWR ) ) != -1 ) + { + ( void ) dup2( fd, STDIN_FILENO ); + ( void ) dup2( fd, STDOUT_FILENO ); + ( void ) dup2( fd, STDERR_FILENO ); + if( fd > 2 ) + ( void ) close( fd ); + } + + hb_retl( HB_TRUE ); +} diff --git a/harbour/contrib/hbposix/hbposix.hbp b/harbour/contrib/hbposix/hbposix.hbp index 15d633361a..d354c9951f 100644 --- a/harbour/contrib/hbposix/hbposix.hbp +++ b/harbour/contrib/hbposix/hbposix.hbp @@ -12,3 +12,4 @@ -stop{!unix} hbposix.c +daemon.c diff --git a/harbour/contrib/hbposix/tests/testdmn.prg b/harbour/contrib/hbposix/tests/testdmn.prg new file mode 100644 index 0000000000..46b8699064 --- /dev/null +++ b/harbour/contrib/hbposix/tests/testdmn.prg @@ -0,0 +1,42 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * + * Copyright 2011 Tamas TEVESZ + * www - http://harbour-project.org + * + */ + +REQUEST HB_GT_CGI_DEFAULT + +PROCEDURE Main() + + LOCAL cLogFile, cLogText + + cLogFile := hb_ps() + CurDir() + hb_ps() + "testdmn.txt" + + OutStd( hb_strFormat( "Parent(%d) launching child... ", posix_getpid() ) + hb_eol() ) + + IF ! hb_posix_daemon( .F., .F. ) + OutStd( "failed." + hb_eol() ) + ErrorLevel( 1 ) + QUIT + ENDIF + + IF File( cLogFile ) + FErase( cLogFile ) + ENDIF + + OutStd( "***" + hb_eol() + "* If you see this, something is b0rked" + hb_eol() + "***" + hb_eol() ) + + cLogText := hb_strFormat( "Hello, this is the daemon child(%d) writing.", posix_getpid() ) + hb_eol() + cLogText += hb_strFormat( "I am currenty residing in %s and ", hb_ps() + CurDir() ) + hb_eol() + cLogText += hb_strFormat( "am writing this message to %s", cLogFile ) + hb_eol() + cLogText += "Good bye now." + hb_eol() + + hb_MemoWrit( cLogFile, cLogText ) + + RETURN