public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: JAmes Coleman <james.coleman@s3group.com>
To: Gerald Villemure <GVillemure@ik.ca>
Cc: cygwin@cygwin.com
Subject: Re: Win98se and using SSHD as a TRUE service
Date: Sun, 11 Nov 2001 08:26:00 -0000	[thread overview]
Message-ID: <3BF3A48E.9537B5DD@s3group.com> (raw)
In-Reply-To: <00c901c16d7b$da23f880$0200000a@dyn.ik.ca>

Hi Gerald,

Gerald Villemure wrote:
> 
> 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

I had a go at compiling what you sent, obviously I can't compile it
properly
 but I can test the syntax anyway.
 I just had to remove #include "includes.h"
 For me, gcc version 2.9-cygwin-990830, I got similar errors to you and
others 
 which I got rid of by fixing includes ... (except for one).

daemon.c: In function `daemon':
daemon.c:82: parse error before `kerneldll'
daemon.c:83: `kerneldll' undeclared (first use in this function)
daemon.c:83: (Each undeclared identifier is reported only once
daemon.c:83: for each function it appears in.)
daemon.c:87: parse error before `('
daemon.c:88: `RegisterService' undeclared (first use in this function)
daemon.c:95: `RegisterService' used prior to declaration
daemon.c:95: warning: implicit declaration of function `RegisterService'
daemon.c:108: `_PATH_DEVNULL' undeclared (first use in this function)


(I add the following includes)
//#include <includes.h>
#include <sys/types.h>
     #include <unistd.h>
#include <sys/types.h>
     #include <sys/stat.h>
     #include <fcntl.h>
#define HAVE_CYGWIN


ANYWAY

Two things .... (possibly caused by command line options?)

  1. compiler doesn't like // comments

  2. compiler doesn't like declaration of variables except at start of
function

The following compiles okay for me (with only the one error I introduced
which you shouldn't have)

int
daemon(nochdir, noclose)
        int nochdir, noclose;
{
        int fd;
        HINSTANCE kerneldll;
        DWORD (*RegisterService)(DWORD, DWORD);

        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 */
                         kerneldll = LoadLibrary("KERNEL32.DLL");
                         if (kerneldll == NULL)
                                 break;
 
                         /* And find the RegisterServiceProcess function
*/
                         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);
}




> 
> The source is at the end of this email.
> 
> The problem may be easy to spot but its beyond me.

I can help a bit with C and a little with cygwin but I don't do all that
much
cygwin+windows programming.   Hopefully this is useful.

> 
> I am trying to fix the right file for this right?

:)

That's a very good question .... and I really don't know the answer to
it :-7

Last time I played with services was on msdos5.something!

> 
> Thanks for any help,
> Gérald
> 

Good Luck!

JAmes.

--
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/

  reply	other threads:[~2001-11-15 11:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-11  8:26 JAmes Coleman
2001-11-11  8:26 ` Gerald Villemure
2001-11-11  8:26   ` JAmes Coleman [this message]
2001-11-11  8:26     ` Gerald Villemure
2001-11-11  8:26   ` Corinna Vinschen
2001-11-11  8:26     ` Win98se and using SSHD as a TRUE service (solution) Gerald Villemure
  -- strict thread matches above, loose matches on Subject: below --
2001-11-11  8:26 Win98se and using SSHD as a TRUE service GregHolmes
2001-11-08 21:04 Gerald Villemure
2001-11-09  5:34 ` Max Bowsher
2001-11-09 10:26   ` Gerald Villemure

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3BF3A48E.9537B5DD@s3group.com \
    --to=james.coleman@s3group.com \
    --cc=GVillemure@ik.ca \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).