Accomodate moving cygserver header files from cygwin/include/cygwin

to here and cygwin dir.
	* Makefile.in (EXEEXT): Drop as unused.
	(EXEEXT_FOR_BUILD): Ditto.
	(all): Don't build libcygserver.a.
	* cygserver_process.h: Moved from cygwin/include/cygwin to here.
	* cygserver_transport.h: Ditto.
	* cygserver_transport_pipes.h: Ditto.
	* cygserver_transport_sockets.h: Ditto.
	* ipc.h: Moved to ../cygwin and renamed to cygserver_ipc.h.
	* shm.h: Moved to ../cygwin and renamed to cygserver_shm.h.
This commit is contained in:
Corinna Vinschen 2003-10-22 10:04:11 +00:00
parent 63a823f8f4
commit 567970786e
15 changed files with 334 additions and 252 deletions

View File

@ -1,3 +1,17 @@
2003-10-22 Corinna Vinschen <corinna@vinschen.de>
Accomodate moving cygserver header files from cygwin/include/cygwin
to here and cygwin dir.
* Makefile.in (EXEEXT): Drop as unused.
(EXEEXT_FOR_BUILD): Ditto.
(all): Don't build libcygserver.a.
* cygserver_process.h: Moved from cygwin/include/cygwin to here.
* cygserver_transport.h: Ditto.
* cygserver_transport_pipes.h: Ditto.
* cygserver_transport_sockets.h: Ditto.
* ipc.h: Moved to ../cygwin and renamed to cygserver_ipc.h.
* shm.h: Moved to ../cygwin and renamed to cygserver_shm.h.
2003-08-30 Christopher Faylor <cgf@redhat.com>
* msg.cc: New file.

View File

@ -22,9 +22,6 @@ INSTALL:=@INSTALL@
INSTALL_PROGRAM:=@INSTALL_PROGRAM@
INSTALL_DATA:=@INSTALL_DATA@
EXEEXT:=@EXEEXT@
EXEEXT_FOR_BUILD:=@EXEEXT_FOR_BUILD@
CC:=@CC@
CC_FOR_TARGET:=$(CC)
CXX:=@CXX@
@ -44,7 +41,7 @@ LIBOBJS:=${patsubst %.o,lib%.o,$(OBJS)}
CYGWIN_OBJS:=$(cygwin_build)/smallprint.o $(cygwin_build)/version.o \
$(cygwin_build)/wincap.o
all: cygserver.exe libcygserver.a
all: cygserver.exe
install: all

View File

@ -25,8 +25,8 @@ details. */
#include "cygserver_shm.h"
#include "safe_memory.h"
#include "cygwin/cygserver.h"
#include "cygwin/cygserver_transport.h"
#include "cygserver.h"
#include "cygserver_transport.h"
int cygserver_running = CYGSERVER_UNKNOWN; // Nb: inherited by children.

View File

@ -26,9 +26,9 @@ details. */
#include "cygerrno.h"
#include "cygwin_version.h"
#include "cygwin/cygserver.h"
#include "cygwin/cygserver_process.h"
#include "cygwin/cygserver_transport.h"
#include "cygserver.h"
#include "cygserver_process.h"
#include "cygserver_transport.h"
// Version string.
static const char version[] = "$Revision$";

View File

@ -0,0 +1,164 @@
/* cygserver_process.h
Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com>
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef _CYGSERVER_PROCESS_
#define _CYGSERVER_PROCESS_
#include <assert.h>
#include "threaded_queue.h"
class process_cleanup : public queue_request
{
public:
process_cleanup (class process *const theprocess)
: _process (theprocess)
{
assert (_process);
}
virtual ~process_cleanup ();
virtual void process ();
private:
class process *const _process;
};
class process;
class cleanup_routine
{
friend class process;
public:
cleanup_routine (void *const key)
: _key (key),
_next (NULL)
{}
virtual ~cleanup_routine ();
bool operator== (const cleanup_routine &rhs) const
{
return _key == rhs._key;
}
void *key () const { return _key; }
/* MUST BE SYNCHRONOUS */
virtual void cleanup (class process *) = 0;
private:
void *const _key;
cleanup_routine *_next;
};
class process_cache;
class process
{
friend class process_cache;
friend class process_cleanup;
public:
process (pid_t cygpid, DWORD winpid);
~process ();
pid_t cygpid () const { return _cygpid; }
DWORD winpid () const { return _winpid; }
HANDLE handle () const { return _hProcess; }
bool is_active () const { return _exit_status == STILL_ACTIVE; }
void hold () { EnterCriticalSection (&_access); }
void release () { LeaveCriticalSection (&_access); }
bool add (cleanup_routine *);
bool remove (const cleanup_routine *);
private:
const pid_t _cygpid;
const DWORD _winpid;
HANDLE _hProcess;
long _cleaning_up;
DWORD _exit_status; // Set in the constructor and in exit_code ().
cleanup_routine *_routines_head;
/* used to prevent races-on-delete */
CRITICAL_SECTION _access;
class process *_next;
DWORD check_exit_code ();
void cleanup ();
};
class process_cache
{
// Number of special (i.e., non-process) handles in _wait_array.
// See wait_for_processes () and sync_wait_array () for details.
enum {
SPECIALS_COUNT = 2
};
class submission_loop : public queue_submission_loop
{
public:
submission_loop (process_cache *const cache, threaded_queue *const queue)
: queue_submission_loop (queue, true),
_cache (cache)
{
assert (_cache);
}
private:
process_cache *const _cache;
virtual void request_loop ();
};
friend class submission_loop;
public:
process_cache (unsigned int initial_workers);
~process_cache ();
class process *process (pid_t cygpid, DWORD winpid);
bool running () const { return _queue.running (); }
bool start () { return _queue.start (); }
bool stop () { return _queue.stop (); }
private:
threaded_queue _queue;
submission_loop _submitter;
size_t _processes_count;
class process *_processes_head; // A list sorted by winpid.
// Access to the _wait_array and related fields is not thread-safe,
// since they are used solely by wait_for_processes () and its callees.
HANDLE _wait_array[MAXIMUM_WAIT_OBJECTS];
class process *_process_array[MAXIMUM_WAIT_OBJECTS];
HANDLE _cache_add_trigger; // Actually both add and remove.
CRITICAL_SECTION _cache_write_access; // Actually both read and write access.
void wait_for_processes (HANDLE interrupt);
size_t sync_wait_array (HANDLE interrupt);
void check_and_remove_process (const size_t index);
class process *find (DWORD winpid, class process **previous = NULL);
};
#endif /* _CYGSERVER_PROCESS_ */

View File

@ -0,0 +1,39 @@
/* cygserver_transport.h
Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com>
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef _CYGSERVER_TRANSPORT_
#define _CYGSERVER_TRANSPORT_
class transport_layer_base *create_server_transport ();
class transport_layer_base
{
public:
#ifndef __INSIDE_CYGWIN__
virtual int listen () = 0;
virtual class transport_layer_base *accept (bool *recoverable) = 0;
#endif
virtual void close () = 0;
virtual ssize_t read (void *buf, size_t len) = 0;
virtual ssize_t write (void *buf, size_t len) = 0;
virtual int connect () = 0;
#ifndef __INSIDE_CYGWIN__
virtual void impersonate_client ();
virtual void revert_to_self ();
#endif
virtual ~transport_layer_base ();
};
#endif /* _CYGSERVER_TRANSPORT_ */

View File

@ -0,0 +1,53 @@
/* cygserver_transport_pipes.h
Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com>
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef _CYGSERVER_TRANSPORT_PIPES_
#define _CYGSERVER_TRANSPORT_PIPES_
/* Named pipes based transport, for security on NT */
class transport_layer_pipes : public transport_layer_base
{
public:
#ifndef __INSIDE_CYGWIN__
virtual int listen ();
virtual class transport_layer_pipes *accept (bool *recoverable);
#endif
virtual void close ();
virtual ssize_t read (void *buf, size_t len);
virtual ssize_t write (void *buf, size_t len);
virtual int connect ();
#ifndef __INSIDE_CYGWIN__
virtual void impersonate_client ();
virtual void revert_to_self ();
#endif
transport_layer_pipes ();
virtual ~transport_layer_pipes ();
private:
/* for pipe based communications */
void init_security ();
//FIXME: allow inited, sd, all_nih_.. to be static members
SECURITY_DESCRIPTOR _sd;
SECURITY_ATTRIBUTES _sec_all_nih;
const char *const _pipe_name;
HANDLE _hPipe;
const bool _is_accepted_endpoint;
bool _is_listening_endpoint;
transport_layer_pipes (HANDLE hPipe);
};
#endif /* _CYGSERVER_TRANSPORT_PIPES_ */

View File

@ -0,0 +1,46 @@
/* cygserver_transport_sockets.h
Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com>
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef _CYGSERVER_TRANSPORT_SOCKETS_
#define _CYGSERVER_TRANSPORT_SOCKETS_
#include <sys/socket.h>
#include <sys/un.h>
class transport_layer_sockets : public transport_layer_base
{
public:
#ifndef __INSIDE_CYGWIN__
virtual int listen ();
virtual class transport_layer_sockets *accept (bool *recoverable);
#endif
virtual void close ();
virtual ssize_t read (void *buf, size_t len);
virtual ssize_t write (void *buf, size_t len);
virtual int connect ();
transport_layer_sockets ();
virtual ~transport_layer_sockets ();
private:
/* for socket based communications */
int _fd;
struct sockaddr_un _addr;
socklen_t _addr_len;
const bool _is_accepted_endpoint;
bool _is_listening_endpoint;
transport_layer_sockets (int fd);
};
#endif /* _CYGSERVER_TRANSPORT_SOCKETS_ */

View File

@ -1,84 +0,0 @@
/* cygserver_ipc.h
Copyright 2002 Red Hat, Inc.
Originally written by Conrad Scott <conrad.scott@dsl.pipex.com>
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef __CYGSERVER_IPC_H__
#define __CYGSERVER_IPC_H__
#include <assert.h>
#include <limits.h> /* For OPEN_MAX. */
/*
* The sysv ipc id's (msgid, semid, shmid) are integers arranged such
* that they no subsystem will generate the same id as some other
* subsystem; nor do these ids overlap file descriptors (the other
* common integer ids). Since Cygwin can allocate more than OPEN_MAX
* file descriptors, it can't be guaranteed not to overlap, but it
* should help catch some errors.
*
* msgid's: OPEN_MAX, OPEN_MAX + 3, OPEN_MAX + 6, . . .
* semid's: OPEN_MAX + 1, OPEN_MAX + 4, OPEN_MAX + 7, . . .
* shmid's: OPEN_MAX + 2, OPEN_MAX + 5, OPEN_MAX + 8, . . .
*
* To further ensure that ids are unique, if ipc objects are created
* and destroyed and then re-created, they are given new ids by
* munging the basic id (as above) with a sequence number.
*
* Internal ipc id's, which are 0, 1, ... within each subsystem (and
* not munged with a sequence number), are used solely by the ipcs(8)
* interface.
*/
enum ipc_subsys_t
{
IPC_MSGOP = 0,
IPC_SEMOP = 1,
IPC_SHMOP = 2,
IPC_SUBSYS_COUNT
};
/*
* IPCMNI - The absolute maximum number of simultaneous ipc ids for
* any one subsystem.
*/
enum
{
IPCMNI = 0x10000 // Must be a power of two.
};
inline int
ipc_int2ext (const int intid, const ipc_subsys_t subsys, long & sequence)
{
assert (0 <= intid && intid < IPCMNI);
const long tmp = InterlockedIncrement (&sequence);
return (((tmp & 0x7fff) << 16)
| (OPEN_MAX + (intid * IPC_SUBSYS_COUNT) + subsys));
}
inline int
ipc_ext2int_subsys (const int extid)
{
return ((extid & (IPCMNI - 1)) - OPEN_MAX) % IPC_SUBSYS_COUNT;
}
inline int
ipc_ext2int (const int extid, const ipc_subsys_t subsys)
{
if (ipc_ext2int_subsys (extid) != subsys)
return -1;
else
return ((extid & (IPCMNI - 1)) - OPEN_MAX) / IPC_SUBSYS_COUNT;
}
#endif /* __CYGSERVER_IPC_H__ */

View File

@ -19,7 +19,7 @@ details. */
#include "cygerrno.h"
#include "cygwin/cygserver_process.h"
#include "cygserver_process.h"
/*****************************************************************************/

View File

@ -23,9 +23,9 @@ details. */
#include "cygserver_shm.h"
#include "security.h"
#include "cygwin/cygserver.h"
#include "cygwin/cygserver_process.h"
#include "cygwin/cygserver_transport.h"
#include "cygserver.h"
#include "cygserver_process.h"
#include "cygserver_transport.h"
/*---------------------------------------------------------------------------*
* class server_shmmgr

View File

@ -1,147 +0,0 @@
/* cygserver_shm.h: Single unix specification IPC interface for Cygwin.
Copyright 2002 Red Hat, Inc.
Written by Conrad Scott <conrad.scott@dsl.pipex.com>.
Based on code by Robert Collins <robert.collins@hotmail.com>.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef __CYGSERVER_SHM_H__
#define __CYGSERVER_SHM_H__
#include <sys/types.h>
#include <cygwin/shm.h>
#include <assert.h>
#include <limits.h>
#include "cygserver_ipc.h"
#include "cygwin/cygserver.h"
/*---------------------------------------------------------------------------*
* Values for the shminfo entries.
*
* Nb. The values are segregated between two enums so that the `small'
* values aren't promoted to `unsigned long' equivalents.
*---------------------------------------------------------------------------*/
enum
{
SHMMAX = ULONG_MAX,
SHMSEG = ULONG_MAX,
SHMALL = ULONG_MAX
};
enum
{
SHMMIN = 1,
SHMMNI = IPCMNI // Must be <= IPCMNI.
};
/*---------------------------------------------------------------------------*
* class client_request_shm
*---------------------------------------------------------------------------*/
#ifndef __INSIDE_CYGWIN__
class transport_layer_base;
class process_cache;
#endif
class client_request_shm : public client_request
{
friend class client_request;
public:
enum shmop_t
{
SHMOP_shmat,
SHMOP_shmctl,
SHMOP_shmdt,
SHMOP_shmget
};
#ifdef __INSIDE_CYGWIN__
client_request_shm (int shmid, int shmflg); // shmat
client_request_shm (int shmid, int cmd, const struct shmid_ds *); // shmctl
client_request_shm (int shmid); // shmdt
client_request_shm (key_t, size_t, int shmflg); // shmget
#endif
// Accessors for out parameters.
int shmid () const
{
assert (!error_code ());
return _parameters.out.shmid;
}
HANDLE hFileMap () const
{
assert (!error_code ());
return _parameters.out.hFileMap;
}
const struct shmid_ds & ds () const
{
assert (!error_code ());
return _parameters.out.ds;
}
const struct shminfo & shminfo () const
{
assert (!error_code ());
return _parameters.out.shminfo;
}
const struct shm_info & shm_info () const
{
assert (!error_code ());
return _parameters.out.shm_info;
}
private:
union
{
struct
{
shmop_t shmop;
key_t key;
size_t size;
int shmflg;
int shmid;
int cmd;
pid_t cygpid;
DWORD winpid;
__uid32_t uid;
__gid32_t gid;
struct shmid_ds ds;
} in;
struct {
int shmid;
union
{
HANDLE hFileMap;
struct shmid_ds ds;
struct shminfo shminfo;
struct shm_info shm_info;
};
} out;
} _parameters;
#ifndef __INSIDE_CYGWIN__
client_request_shm ();
#endif
#ifndef __INSIDE_CYGWIN__
virtual void serve (transport_layer_base *, process_cache *);
#endif
};
#endif /* __CYGSERVER_SHM_H__ */

View File

@ -21,9 +21,9 @@ details. */
#include "safe_memory.h"
#include "cygwin/cygserver_transport.h"
#include "cygwin/cygserver_transport_pipes.h"
#include "cygwin/cygserver_transport_sockets.h"
#include "cygserver_transport.h"
#include "cygserver_transport_pipes.h"
#include "cygserver_transport_sockets.h"
/* The factory */
transport_layer_base *

View File

@ -25,11 +25,11 @@ details. */
#include <unistd.h>
#include "cygerrno.h"
#include "cygwin/cygserver_transport.h"
#include "cygwin/cygserver_transport_pipes.h"
#include "cygserver_transport.h"
#include "cygserver_transport_pipes.h"
#ifndef __INSIDE_CYGWIN__
#include "cygwin/cygserver.h"
#include "cygserver.h"
#endif
enum

View File

@ -26,8 +26,8 @@ details. */
#include <stdio.h>
#include <unistd.h>
#include "cygwin/cygserver_transport.h"
#include "cygwin/cygserver_transport_sockets.h"
#include "cygserver_transport.h"
#include "cygserver_transport_sockets.h"
/* to allow this to link into cygwin and the .dll, a little magic is needed. */
#ifndef __OUTSIDE_CYGWIN__