I've been committing a sequence of patches for cygserver on the
cygwin_daemon branch over the last few days and I was thinking it was
about time to submit the current batch for consideration for the
mainline. I've attached a cumulative ChangeLog for the individual
patches and a bzip'ed patch file. (I've not appended the entire
ChangeLog here as it's rather long.) This patch is against the current
HEAD version, which I merged into the branch yesterday. Nicholas
Wourms has kindly downloaded the branch version and confirmed that it
works on a non-NT platform. I've also successfully run the ipctests
and has the server running continually while I've been developing. In
other words, I don't seem to have broken anything :-)

Which is all well and good, but what have I actually done? Summary:

* Conditionalize the security code so that cygserver works on non-NT
platforms.
* Refactor the client request classes for greater encapsulation and to
support variable length requests.
* Add new interfaces for the (eventual) implementation of ipcs(8).
* Add definitions of the strace XXX_printf macros to allow code to use
these whether it's compiled for the DLL or for the daemon.
* Several minor C++ related changes: for example, making some methods
pure virtual, and adding virtual destructors throughout as required.
* Add --version and --help options.
* Add checking for an existing instance of the daemon to avoid having
multiple copies running.
* Some more error checking throughout.

In other words, almost nothing shm related as it's not quite finished,
so I've not checked any of that into the branch as yet. This is all
just groundwork :-)

[One thing to note about this patch is that it includes a new file,
"woutsup.h". I only mention this in case anything special needs to be
done in cvs if/when the patch is committed.]

I hope this is all fine and that someone has a chance to look it over
sometime soon-ish.

Thanks.

// Conrad

2002-06-18  Conrad Scott  <[EMAIL PROTECTED]>

        * woutsup.h (cygserver_running): Add declaration.
        (api_fatal): Eliminate.
        * include/cygwin/cygserver.h
        (client_request_get_version::check_version): Change return type to
        bool.
        (check_cygserver_available): New function.
        (cygserver_init): Add check_version_too argument.
        * cygserver_client.cc (allow_daemon): Make a bool.
        (client_request_get_version::make_request): See errno on error.
        Remove special case for CYGSERVER_REQUEST_GET_VERSION; this is now
        handled in cygserver_init().
        (client_request_get_version::check_version): Use syscall_printf()
        instead of api_fatal(). Return true if cygserver version is
        compatible.
        (check_cygserver_available): New function; code moved here from
        cygserver_init().
        (cygserver_init): Move some code into check_cygserver_available().
        * cygserver.cc (__set_errno): Copy from debug.cc so that
        set_errno() can be used when __OUTSIDE_CYGWIN__.
        (main): Call cygserver_init() to set up cygserver_running and add
        checks against this to (try and) prevent multiple copies of
        cygserver running simultaneously.  Remember to delete all
        transport connections so that (one day) the transport classes can
        tidy up on cygserver shutdown.

2002-06-17  Conrad Scott  <[EMAIL PROTECTED]>

        * cygserver.cc (main): Adjust tracing output for a cleaner display
        when compiled without --enable-debugging.
        * threaded_queue.cc (threaded_queue::cleanup): Ditto.
        (queue_process_param::stop): Ditto.
        * include/cygwin/cygserver.h
        (client_request::make_request): Make non-virtual.
        (client_request::send): Make virtual and protected, not private.
        (client_request_attach_tty::send): New virtual method.
        * cygserver_client.cc: Use the `msglen()' accessor rather than
        `_header.msglen' throughout.
        (client_request_attach_tty::send): New method.
        (client_request::make_request): Remove the explicit close of
        `transport' as it is closed on deletion.

2002-06-17  Conrad Scott  <[EMAIL PROTECTED]>

        * include/cygwin/cygserver.h: Change the client_request classes to
        give greater encapsulation and to allow variable length requests
        and replies.
        (enum cygserver_request_code): Now client_request::request_code_t.
        (class request_header): Now client_request::header_t.  Make a
        union of the request_code and the error_code.  The `cb' field,
        which was the buffer length, is now the `size_t msglen' field.
        (struct request_get_version): Now
        client_request_get_version::request_get_version.
        (struct request_shutdown): Remove unused type.
        (struct request_attach_tty): Now
        client_request_attach_tty::request_attach_tty.
        (client_request::_buf): Make field const.
        (client_request::_buflen): New const private field.
        (client_request::request_code): New accessor.
        (client_request::error_code): Ditto.
        (client_request::msglen): Ditto.
        (client_request::handle_request): New static method.
        (client_request::make_request): New virtual method.
        (client_request::handle): New method.
        (client_request::send): Make private.
        (client_request_get_version::check_version): New method.
        (client_request_get_version::serve): Make private.
        (client_request_get_version::version): Ditto.
        (client_request_shutdown::serve): Ditto.
        (client_request_attach_tty::req): Ditto.
        (client_request_attach_tty::serve): Ditto.
        (client_request_attach_tty::from_master): Make method const.
        (client_request_attach_tty::from_master): Ditto.
        * cygserver_client.cc
        (client_request_get_version::client_request_get_version): Track
        changes to the client_request classes.
        (client_request_attach_tty::client_request_attach_tty): Ditto.
        (client_request_get_version::check_version): New method to
        encapsulate code from cygserver_init().
        (client_request_shutdown::client_request_shutdown): Move into
        "cygserver.cc".
        (client_request::send): Track changes to the client_request
        classes.  Add more error checking.
        (client_request::handle_request): New static method containing the
        first half of the old server_request::process() code.
        (client_request::make_request): New method to replace the old
        cygserver_request() function.
        (client_request::handle): New method containing the second half of
        the old server_request::process() code.
        (cygserver_init): Track changes to the client_request classes.  In
        particular, some code moved into the
        client_request_get_version::check_version() method.
        * cygserver.cc (client_request_attach_tty::serve): Track changes
        to the client_request classes.  In particular, only return a reply
        body if some handles are successfully duplicated for the client.
        And remove goto's.
        (client_request_get_version::serve): Track changes to the
        client_request classes.
        (client_request_shutdown::serve): Ditto.
        (class client_request_invalid): Dead, and so young too.
        (server_request::request_buffer): Remove unnecessary field.
        (client_request_shutdown::client_request_shutdown): Moved here
        from "cygserver_client.cc".
        (server_request::process): Implementation moved into the new
        client_request::handle_request() and client_request::handle()
        methods.
        * cygserver_shm.h (class client_request_shm): Put client- and
        server-specific interfaces inside #ifdef/#ifndef __INSIDE_CYGWIN__
        guards.
        (client_request_shm::serve): Make private.
        * cygserver_shm.cc
        (client_request_shm::client_request_shm): Track changes to the
        client_request classes.
        (client_request_shm::serve): Ditto
        * shm.cc (client_request_shm::client_request_shm): Ditto.  Use
        alloc_sd() rather than set_security_attribute() to get access to
        the SECURITY_DESCRIPTOR length, so that we can use it to set the
        request body length.
        (shmat): Track changes to the client_request classes. In
        particular, allocate client_request objects on the stack rather
        than on the heap, and use the client_request::make_request()
        method rather than the old cygserver_request() function.
        (shmdt): Ditto.
        (shmctl): Ditto.
        (shmget): Ditto.
        * fhandler_tty.cc (fhandler_tty_slave::cygserver_attach_tty): Ditto.

2002-06-17  Conrad Scott  <[EMAIL PROTECTED]>

        * include/cygwin/cygserver_transport.h
        (cygserver_transport::read): Change buffer type to void *.
        (cygserver_transport::write): Ditto.
        * include/cygwin/cygserver_transport_sockets.h
        (cygserver_transport_sockets::read): Ditto.
        (cygserver_transport_sockets::write): Ditto.
        * include/cygwin/cygserver_transport_pipes.h
        (cygserver_transport_pipes::read): Ditto.
        (cygserver_transport_pipes::write): Ditto.
        * cygserver_transport_sockets.cc
        (cygserver_transport_sockets::read): Ditto.
        (cygserver_transport_sockets::write): Ditto.
        * cygserver_transport_pipes.cc
        (cygserver_transport_pipes::read): Ditto. Set errno on error, to
        match behaviour of cygserver_transport_sockets class.
        (cygserver_transport_pipes::write): Ditto.

2002-06-16  Conrad Scott  <[EMAIL PROTECTED]>

        * cygserver.cc (version): New static variable.
        (server_request_queue::add_connection): Remove my gratuitous use
        of studly caps.
        (setup_privileges): Declare static.
        (handle_signal): Ditto.
        (longopts): Make a local variable of main().
        (opts): Ditto.
        (print_usage): New function.
        (print_version): Ditto (tip of the hat to Joshua Daniel Franklin
        for inspiration here).
        (main): More argument checking.  Add --help and --version options.

2002-06-16  Conrad Scott  <[EMAIL PROTECTED]>

        * include/cygwin/cygserver.h (client_request::serve): Make pure
        virtual.
        * cygserver.cc (client_request::serve): Remove definition of pure
        virtual method.
        (class client_request_invalid): New class.
        (server_request::process): Use new client_request_invalid
        class. And remove goto's.

2002-06-16  Conrad Scott  <[EMAIL PROTECTED]>

        * cygserver.cc (class server_request): Add virtual destructor.
        (server_request_queue::addConnection): New method to replace bad
        virtual add() method.
        (request_loop): Replace call to queue->add() with call to
        queue->addConnection().
        (server_request::server_request): Use field initialization.
        (server_request::~server_request): New virtual destructor.
        (server_request::process): Remove close and delete of
        transport_layer_base object. It is deleted by the server_request's
        own destructor and closed by its own destructor.
        * include/cygwin/cygserver.h
        (client_request::operator request_header): Remove unused method.
        * cygserver_client.cc: Ditto.
        * include/cygwin/cygserver_process.h
        (class cleanup_routine): Add virtual destructor.
        (cleanup_routine::cleanup): Make pure virtual.
        (class process_cache): Make destructor non-virtual.
        (process_cache::add): Ditto.
        * cygserver_process.cc
        (cleanup_routine::~cleanup_routine): New virtual destructor.
        * include/cygwin/cygserver_transport.h
        (class transport_layer_base): Add virtual destructor.
        * cygserver_transport.cc
        (transport_layer_base::~transport_layer_base): New virtual
        destructor.
        * include/cygwin/cygserver_transport_pipes.h
        (class transport_layer_pipes): Add virtual destructor.
        * cygserver_transport_pipes.cc
        (transport_layer_pipes::~transport_layer_pipes): New virtual
        destructor.
        (transport_layer_pipes::close): Null out handle after closing.
        * include/cygwin/cygserver_transport_sockets.h
        (class transport_layer_sockets): Add virtual destructor.
        * cygserver_transport_sockets.cc
        (transport_layer_sockets::~transport_layer_sockets): New virtual
        destructor.
        (transport_layer_sockets::close): Null out fd after closing.
        * threaded_queue.h (class queue_request): Add virtual destructor.
        (queue_request::process): Make pure virtual.
        * threaded_queue.cc (~queue_request): New virtual destructor.
        (queue_request::process): Remove definition of pure virtual
        method.

2002-06-16  Conrad Scott  <[EMAIL PROTECTED]>

        * include/cygwin/cygserver.h (client_request::send): Make
        non-virtual.
        (class client_request_attach_tty): Put client- and server-specific
        interfaces inside #ifdef/#ifndef __INSIDE_CYGWIN__ guards.
        * cygserver_client.cc: Ditto.
        (cygserver_init): Fix error handling.

2002-06-16  Conrad Scott  <[EMAIL PROTECTED]>

        * cygserver.cc: Throughout the code, check and correct level of
        the XXX_printf() functions used. Comment out several of the
        debug_printf() calls with "// verbose:".  Reformat and correct
        typos of some of the XXX_printf() formats.
        * cygserver_process.cc: Ditto.
        * cygserver_shm.cc: Ditto.
        * cygserver_transport_pipes.cc: Ditto.
        * cygserver_transport_sockets.cc: Ditto.
        * shm.cc (hi_ulong): New function to allow printing of a 64-bit
        key with current small_printf implementation.
        (lo_ulong): Ditto.
        (client_request_shm::client_request_shm): Use hi_ulong() and
        lo_ulong() in call to debug_printf().

2002-06-16  Conrad Scott  <[EMAIL PROTECTED]>

        * cygserver_shm.cc: Remove #define __INSIDE_CYGWIN__ from around
        <sys/shm.h> as it no longer contains any internal code.

2002-06-16  Conrad Scott  <[EMAIL PROTECTED]>

        * include/sys/ipc.h (IPC_PRIVATE): Add cast to key_t.
        (IPC_INFO): New flag for ipcs(8).
        (IPC_RMID IPC_SET IPC_STAT): Renumber.
        * include/sys/shm.h (SHM_RDONLY SHM_RND): Renumber with distinct
        values [sic].
        (class _shmattach): Internal type moved to "cygserver_shm.h".
        (class shmnode): Ditto.
        (class shmid_ds): Ditto.
        (struct shmid_ds): Add spare fields.
        (struct shminfo): New type for IPC_INFO interface.
        * cygserver_shm.h: Remove obsolete #if 0 ... #endif block.
        (class shm_cleanup): Remove unused class.
        (struct _shmattach): Internal type moved from <sys/shm.h>.
        (struct shmnode): Ditto.
        (struct int_shmid_ds): Ditto. Renamed to avoid name clash with
        public interface struct shmid_ds. Use the shmid_bs structure as a
        field.
        * cygserver_shm.cc: Remove obsolete #if 0 ... #endif block.
        (client_request_shm::serve): Update for redefinition of
        int_shmid_ds structure.
        * shm.cc (build_inprocess_shmds): Ditto.
        (fixup_shms_after_fork): Ditto.
        (shmctl): Ditto.
        (shmget): Ditto. Remove obsolete #if 0 ... #endif code.

2002-06-16  Conrad Scott  <[EMAIL PROTECTED]>

        * include/cygwin/cygserver_transport.h
        (transport_layer_base::transport_layer_base): Remove since it is
        now redundant.
        (transport_layer_base::listen): Make a pure virtual method.
        (transport_layer_base::accept): Ditto.
        (transport_layer_base::close): Ditto.
        (transport_layer_base::read): Ditto.
        (transport_layer_base::write): Ditto.
        (transport_layer_base::connect): Ditto.
        * cygserver_transport.cc
        (transport_layer_base::transport_layer_base): Remove since it is
        now redundant.
        (transport_layer_base::listen): Remove since it is now a pure
        virtual method.
        (transport_layer_base::accept): Ditto.
        (transport_layer_base::close): Ditto.
        (transport_layer_base::read): Ditto.
        (transport_layer_base::write): Ditto.
        (transport_layer_base::connect): Ditto.

2002-06-16  Conrad Scott  <[EMAIL PROTECTED]>

        * cygserver.cc (check_and_dup_handle): Only use security code if
        running on NT, i.e. if wincap.has_security().
        (client_request_attach_tty::serve): Add check for has_security().
        * cygserver_process.cc (process_cache::process): Use DWORD winpid
        throughout to avoid win32 vs. cygwin pid confusion.
        (process::process): Ditto.
        * cygserver_shm.cc (client_request_shm::serve): Only use security
        code if running on NT, i.e. if wincap.has_security().
        * cygserver_shm.h (client_request_shm::parameters.in): Replace the
        ambiguous pid field with cygpid and winpid fields.
        (client_request_shm::client_request_shm): Reduce to only two
        client-side constructors: one for SHM_CREATE, another for all the
        other requests.
        * shm.cc (client_request_shm::client_request_shm):
        Ditto. Initialize cygpid and winpid fields here. On NT initialize
        sd_buf here using set_security_attribute() to make use of the euid
        and egid.
        (shmat): Use new client_request_shm constructor.
        (shmdt): Ditto.
        (shmctl): Ditto.
        (shmget): Ditto. Remove security code, now performed in the
        relevant client_request_shm constructor.
        * include/cygwin/cygserver_process.h: (class cleanup_routine):
        Change winpid type to DWORD.
        (class process): Ditto.

2002-06-15  Conrad Scott  <[EMAIL PROTECTED]>

        * woutsup.h: New file.
        * cygserver.cc: Use "woutsup.h" and new XXX_printf macros.
        (getfunc): New function, copied verbatim from "strace.cc".
        (__cygserver__printf): New function.
        * cygserver_client.cc: Use "woutsup.h" and new XXX_printf macros.
        * cygserver_process.cc: Ditto.
        * cygserver_shm.cc: Ditto.
        * cygserver_transport.cc: Ditto.
        * cygserver_transport_pipes.cc: Ditto.
        * cygserver_transport_sockets.cc: Ditto.
        * threaded_queue.cc: Ditto.
        * shm.cc: Remove trailing \n from XXX_printf format strings.
        * Makefile.in: Remove special __OUTSIDE_CYGWIN__ case for
        cygserver_shm.cc.

Attachment: cygserver.patch.bz2
Description: Binary data

Reply via email to