Mail Archives: cygwin/2001/11/14/21:16:19
The idea here is to have SSHD start as a true service in Win9x such that it
will NOT dies when a user logs out. To do this the process must make the
system call "RegisterServiceProcess" which only exist in Win95, Win98 and
WinMe.
James Coleman: I tryied adding the #include "windows.h" line but I still
have compile errors:
$ make
gcc -g -O2 -Wall -Wpointer-arith -Wno-uninitialized -I. -I.. -I. -I./.. -DH
AVE_CONFIG_H -c daemon.c
daemon.c: In function `daemon':
daemon.c:67: parse error before `kerneldll'
daemon.c:68: `kerneldll' undeclared (first use in this function)
daemon.c:68: (Each undeclared identifier is reported only once
daemon.c:68: for each function it appears in.)
daemon.c:72: parse error before `('
daemon.c:73: `RegisterService' undeclared (first use in this function)
daemon.c:79: `RegisterService' used prior to declaration
daemon.c:79: warning: implicit declaration of function `RegisterService'
make: *** [daemon.o] Error 1
The source is at the end of this email.
The problem may be easy to spot but its beyond me.
I am trying to fix the right file for this right?
Thanks for any help,
Gérald
----- Original Message -----
From: "JAmes Coleman" <james DOT coleman AT s3group DOT com>
To: <cygwin AT cygwin DOT com>; <GVillemure AT ik DOT ca>
Sent: Wednesday, November 14, 2001 2:41 PM
Subject: Re: Win98se and using SSHD as a TRUE service
>
> What are your compile errors?
> The whole point of cygnus is (kindof) mixing windows & unix code.
> Perhaps adding #include <windows.h> would solve your problems?
---- souce file --------
$ cat daemon.c
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. 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 "includes.h"
#include "windows.h"
#ifndef HAVE_DAEMON
#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: daemon.c,v 1.2 1996/08/19 08:22:13 tholo
Exp $";
#endif /* LIBC_SCCS and not lint */
int
daemon(nochdir, noclose)
int nochdir, noclose;
{
int fd;
switch (fork()) {
case -1:
return (-1);
case 0:
break;
default:
#ifdef HAVE_CYGWIN
/*
* This sleep avoids a race condition which kills the
* child process if parent is started by a NT/W2K service.
*/
sleep(1);
/*
* This is the code that I took from WinVNC
* The best solution would be to enclose this in a IF Win9x
clause
* that is if I knew propers C syntax I could do this
*/
// Obtain a handle to the kernel library
HINSTANCE kerneldll = LoadLibrary("KERNEL32.DLL");
if (kerneldll == NULL)
break;
// And find the RegisterServiceProcess function
DWORD (*RegisterService)(DWORD, DWORD);
RegisterService = (DWORD (*)(DWORD, DWORD))
GetProcAddress(kerneldll,
"RegisterServiceProcess");
if (RegisterService == NULL)
break;
// Register this process with the OS as a service!
RegisterService(NULL, 1);
#endif
_exit(0);
}
if (setsid() == -1)
return (-1);
if (!nochdir)
(void)chdir("/");
if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
(void)dup2(fd, STDIN_FILENO);
(void)dup2(fd, STDOUT_FILENO);
(void)dup2(fd, STDERR_FILENO);
if (fd > 2)
(void)close (fd);
}
return (0);
}
#endif /* !HAVE_DAEMON */
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -