2002-06-21 Conrad Scott * Merge of previous patches for submission to HEAD without the changes to and . * cygserver_shm.h: Include with #undef __INSIDE_CYGWIN__, if necessary, to avoid picking up the old internal class definitions. * cygserver_shm.cc: Remove explicit include of to allow the guarded include in "cygserver_shm.h" to be used. * shm.cc: Ditto. 2002-06-21 Conrad Scott * cygserver.cc: The tests for a duplicate server instance are now the responsibility of the transport layer. (request_loop): Use new `recoverable' flag in call to `cygserver_transport::accept ()' and shutdown on an unrecoverable error. (main): Never call `cygserver_init ()'. Fake `cygserver_running' just for sending a shutdown request. * cygserver_client.cc (client_request::send): Comment out message-size tracing statements as verbose. (client_request::handle): Ditto. (client_request_get_version::check_version): #ifdef as DLL-only. (check_cygserver_available): Ditto. (cygserver_init): Ditto. * include/cygwin/cygserver.h (client_request_get_version::check_version): #ifdef as DLL-only. (check_cygserver_available): Ditto. (cygserver_init): Ditto. * include/cygwin/cygserver_transport.h (transport_layer_base::impersonate_client): #ifdef as cygserver-only. (transport_layer_base::revert_to_self): Ditto. (transport_layer_base::listen): Ditto. (transport_layer_base::accept): Ditto. Add a `recoverable' out flag for error handling. * include/cygwin/cygserver_transport_sockets.h: Ditto. * include/cygwin/cygserver_transport_pipes.h: Ditto. (transport_layer_pipes): Change type of the `pipe_name' field. Remove the `inited' field, as unnecessary. Add new `is_accepted_endpoint' field. * include/cygwin/cygserver_transport.cc (transport_layer_base::impersonate_client): #ifdef as cygserver-only. (transport_layer_base::revert_to_self): Ditto. * include/cygwin/cygserver_transport_sockets.cc (transport_layer_sockets::listen): #ifdef as cygserver-only. (transport_layer_sockets::accept): #ifdef as cygserver-only. Analyse any errno from `accept ()' and set `recoverable' as appropriate. * cygserver_transport_pipes.cc: Add local #define of `FILE_FLAG_FIRST_PIPE_INSTANCE'. (pipe_instance_lock_once): New variable. (pipe_instance_lock): Ditto. (pipe_instance): Ditto. (initialise_pipe_instance_lock): New function. (transport_layer_pipes::transport_layer_pipes): Change initialization of `pipe_name'. Initialize `is_accepted_endpoint' as appropriate. Remove use of `inited'. (transport_layer_pipes::impersonate_client): #ifdef as cygserver-only. (transport_layer_pipes::revert_to_self): Ditto. (transport_layer_pipes::listen): Ditto. (transport_layer_pipes::accept): Ditto. Keep track of how often many named pipes have been created, in the `pipe_instance' variable, and pass the `FILE_FLAG_FIRST_PIPE_INSTANCE' flag on the open of the first instance. Analyse the error code from `CreateNamedPipe ()' and set the `recoverable' flag as appropriate. (transport_layer_pipes::close): Update the `pipe_instance' count. 2002-06-18 Conrad Scott * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * cygserver_shm.cc: Remove #define __INSIDE_CYGWIN__ from around as it no longer contains any internal code. 2002-06-16 Conrad Scott * cygserver_shm.h: Remove obsolete #if 0 ... #endif block. (class shm_cleanup): Remove unused class. (struct _shmattach): Internal type copied from . (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 * 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 * 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 * 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.