mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- Updated the new __obtain_daemon_message() function to call a
bsdsocket.library API function to determine if what appears to be a valid daemon startup message is sound. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15052 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@ -35,6 +35,10 @@
|
||||
- Moved the code which rebinds the standard I/O streams to the server
|
||||
socket into a separate function which can be overridden by user code.
|
||||
|
||||
- Updated the new __obtain_daemon_message() function to call a
|
||||
bsdsocket.library API function to determine if what appears to be
|
||||
a valid daemon startup message is sound.
|
||||
|
||||
|
||||
c.lib 1.196 (11.10.2005)
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: socket_headers.h,v 1.11 2005-10-20 07:19:15 obarthel Exp $
|
||||
* $Id: socket_headers.h,v 1.12 2005-10-23 09:53:39 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -76,6 +76,36 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* Code value. */
|
||||
#define SBTB_CODE 1
|
||||
#define SBTS_CODE 0x3FFF
|
||||
|
||||
/* Argument passed by reference or by value. */
|
||||
#define SBTF_VAL 0x0000
|
||||
#define SBTF_REF 0x8000
|
||||
|
||||
/* Get/Set (read/write) selection. */
|
||||
#define SBTF_GET 0
|
||||
#define SBTF_SET 1
|
||||
|
||||
/* Set a parameter, passing it by value. */
|
||||
#define SBTM_SETVAL(code) (TAG_USER | SBTF_VAL | (((code) & SBTS_CODE) << SBTB_CODE) | SBTF_SET)
|
||||
|
||||
/* Get a parameter, passing it by reference. */
|
||||
#define SBTM_GETREF(code) (TAG_USER | SBTF_REF | (((code) & SBTS_CODE) << SBTB_CODE) | SBTF_GET)
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#define SBTC_BREAKMASK 1 /* Interrupt signal mask */
|
||||
#define SBTC_LOGTAGPTR 11 /* Under which name log entries are filed */
|
||||
#define SBTC_ERRNOLONGPTR 24 /* Pointer to errno, length == sizeof(errno) */
|
||||
#define SBTC_HERRNOLONGPTR 25 /* 'h_errno' pointer (with sizeof(h_errno) == sizeof(long)) */
|
||||
#define SBTC_CAN_SHARE_LIBRARY_BASES 51 /* Enable library base sharing among Processes */
|
||||
#define SBTC_HAVE_SERVER_API 63 /* Whether or not the server API is supported. */
|
||||
#define SBTC_ERROR_HOOK 68 /* Error hook pointer */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern struct Library * NOCOMMON __SocketBase;
|
||||
|
||||
/****************************************************************************/
|
||||
@ -154,6 +184,7 @@ extern BOOL __obtain_daemon_message(VOID);
|
||||
#define __gethostid() __ISocket->gethostid()
|
||||
#define __SocketBaseTagList(tags) __ISocket->SocketBaseTagList(tags)
|
||||
#define __SocketBaseTags(tag1...) __ISocket->SocketBaseTags(## tag1)
|
||||
#define __ProcessIsServer(pr) __ISocket->ProcessIsServer(pr)
|
||||
|
||||
#else
|
||||
|
||||
@ -993,6 +1024,22 @@ extern BOOL __obtain_daemon_message(VOID);
|
||||
_SocketBaseTagList__re; \
|
||||
})
|
||||
|
||||
#define __ProcessIsServer(pr) ({ \
|
||||
struct Process * _ProcessIsServer_pr = (pr); \
|
||||
BOOL _ProcessIsServer__re = \
|
||||
({ \
|
||||
register struct Library * const __ProcessIsServer__bn __asm("a6") = (struct Library *) (__SocketBase);\
|
||||
register BOOL __ProcessIsServer__re __asm("d0"); \
|
||||
register struct Process * __ProcessIsServer_pr __asm("a0") = (_ProcessIsServer_pr); \
|
||||
__asm volatile ("jsr a6@(-690:W)" \
|
||||
: "=r"(__ProcessIsServer__re) \
|
||||
: "r"(__ProcessIsServer__bn), "r"(__ProcessIsServer_pr) \
|
||||
: "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \
|
||||
__ProcessIsServer__re; \
|
||||
}); \
|
||||
_ProcessIsServer__re; \
|
||||
})
|
||||
|
||||
#endif /* __amigaos4__ */
|
||||
|
||||
#endif /* __GNUC__ */
|
||||
@ -1046,6 +1093,7 @@ LONG __recvmsg(LONG sock,struct msghdr *msg,LONG flags);
|
||||
LONG __gethostname(STRPTR name,LONG namelen);
|
||||
ULONG __gethostid(VOID);
|
||||
LONG __SocketBaseTagList(struct TagItem *tags);
|
||||
BOOL __ProcessIsServer( struct Process *pr );
|
||||
|
||||
#pragma libcall __SocketBase __socket 01e 21003
|
||||
#pragma libcall __SocketBase __bind 024 18003
|
||||
@ -1092,6 +1140,7 @@ LONG __SocketBaseTagList(struct TagItem *tags);
|
||||
#pragma libcall __SocketBase __gethostname 11a 0802
|
||||
#pragma libcall __SocketBase __gethostid 120 00
|
||||
#pragma libcall __SocketBase __SocketBaseTagList 126 801
|
||||
#pragma libcall __SocketBase __ProcessIsServer 2b2 801
|
||||
|
||||
#endif /* __SASC */
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: socket_init_exit.c,v 1.23 2005-10-20 07:19:15 obarthel Exp $
|
||||
* $Id: socket_init_exit.c,v 1.24 2005-10-23 09:53:39 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -51,55 +51,6 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* Code value. */
|
||||
#define SBTB_CODE 1
|
||||
#define SBTS_CODE 0x3FFF
|
||||
|
||||
/* Set a parameter, passing it by value. */
|
||||
#ifndef SBTM_SETVAL
|
||||
#define SBTM_SETVAL(code) (TAG_USER | (((code) & SBTS_CODE) << SBTB_CODE) | 1)
|
||||
#endif /* SBTM_SETVAL */
|
||||
|
||||
#define SBTC_BREAKMASK 1 /* Interrupt signal mask */
|
||||
#define SBTC_LOGTAGPTR 11 /* Under which name log entries are filed */
|
||||
#define SBTC_ERRNOLONGPTR 24 /* Pointer to errno, length == sizeof(errno) */
|
||||
#define SBTC_HERRNOLONGPTR 25 /* 'h_errno' pointer (with sizeof(h_errno) == sizeof(long)) */
|
||||
#define SBTC_CAN_SHARE_LIBRARY_BASES 51 /* Enable library base sharing among Processes */
|
||||
#define SBTC_ERROR_HOOK 68 /* Error hook pointer */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* Call-back hook for use with SBTC_ERROR_HOOK */
|
||||
struct ErrorHookMsg
|
||||
{
|
||||
ULONG ehm_Size; /* Size of this data structure; this
|
||||
must be >= 12 */
|
||||
ULONG ehm_Action; /* See below for a list of definitions */
|
||||
|
||||
LONG ehm_Code; /* The error code to use */
|
||||
};
|
||||
|
||||
/* Which action the hook is to perform */
|
||||
#define EHMA_Set_errno 1 /* Set the local 'errno' to what is
|
||||
found in ehm_Code */
|
||||
#define EHMA_Set_h_errno 2 /* Set the local 'h_errno' to what is
|
||||
found in ehm_Code */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct DaemonMessage
|
||||
{
|
||||
struct Message dm_Message;
|
||||
ULONG dm_Pad1;
|
||||
ULONG dm_Pad2;
|
||||
LONG dm_ID;
|
||||
ULONG dm_Pad3;
|
||||
UBYTE dm_Family;
|
||||
UBYTE dm_Type;
|
||||
};
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct Library * NOCOMMON __SocketBase;
|
||||
|
||||
/****************************************************************************/
|
||||
@ -118,16 +69,40 @@ int NOCOMMON h_errno;
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* Call-back hook for use with SBTC_ERROR_HOOK */
|
||||
struct _ErrorHookMsg
|
||||
{
|
||||
ULONG ehm_Size; /* Size of this data structure; this
|
||||
must be >= 12 */
|
||||
ULONG ehm_Action; /* See below for a list of definitions */
|
||||
|
||||
LONG ehm_Code; /* The error code to use */
|
||||
};
|
||||
|
||||
/* Which action the hook is to perform */
|
||||
#define EHMA_Set_errno 1 /* Set the local 'errno' to what is
|
||||
found in ehm_Code */
|
||||
#define EHMA_Set_h_errno 2 /* Set the local 'h_errno' to what is
|
||||
found in ehm_Code */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
BOOL NOCOMMON __can_share_socket_library_base;
|
||||
BOOL NOCOMMON __thread_safe_errno_h_errno;
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* This hook function is called whenever either the errno or h_errno
|
||||
variable is to be changed by the bsdsocket.library code. It is invoked
|
||||
on the context of the caller, which means that the Process which called
|
||||
the library will also be the one will eventually call the hook function.
|
||||
You can key off this in your own __set_errno() or __set_h_errno()
|
||||
functions, setting a Process-specific set of variables. */
|
||||
STATIC LONG ASM
|
||||
error_hook_function(
|
||||
REG(a0, struct Hook * unused_hook),
|
||||
REG(a2, APTR unused_reserved),
|
||||
REG(a1, struct ErrorHookMsg * ehm))
|
||||
REG(a1, struct _ErrorHookMsg * ehm))
|
||||
{
|
||||
if(ehm != NULL && ehm->ehm_Size >= 12)
|
||||
{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: socket_obtain_daemon.c,v 1.1 2005-10-20 07:19:16 obarthel Exp $
|
||||
* $Id: socket_obtain_daemon.c,v 1.2 2005-10-23 09:53:39 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -41,7 +41,9 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct DaemonMessage
|
||||
/* This data structure is attached to the server's Process->pr_ExitData field
|
||||
if the server was launched by the inetd Internet super-server. */
|
||||
struct _DaemonMessage
|
||||
{
|
||||
struct Message dm_Message;
|
||||
ULONG dm_Pad1;
|
||||
@ -67,23 +69,49 @@ __obtain_daemon_message(VOID)
|
||||
|
||||
if(Cli() != NULL && NOT __detach && __check_daemon_startup)
|
||||
{
|
||||
struct DaemonMessage * dm;
|
||||
struct _DaemonMessage * dm;
|
||||
|
||||
/* The socket the superserver may have launched this program
|
||||
with is attached to the exit data entry of the process. */
|
||||
#if defined(__amigaos4__)
|
||||
{
|
||||
dm = (struct DaemonMessage *)GetExitData();
|
||||
dm = (struct _DaemonMessage *)GetExitData();
|
||||
}
|
||||
#else
|
||||
{
|
||||
struct Process * this_process = (struct Process *)FindTask(NULL);
|
||||
|
||||
dm = (struct DaemonMessage *)this_process->pr_ExitData;
|
||||
dm = (struct _DaemonMessage *)this_process->pr_ExitData;
|
||||
}
|
||||
#endif /* __amigaos4__ */
|
||||
|
||||
if(TypeOfMem(dm) != 0 && TypeOfMem(((char *)dm) + sizeof(*dm)-1) != 0)
|
||||
/* For extra safety, ask if what could be a "struct DaemonMessage"
|
||||
pointer was really placed there by the Internet super-server. */
|
||||
if(__SocketBase->lib_Version >= 4)
|
||||
{
|
||||
LONG have_server_api = FALSE;
|
||||
struct TagItem tags[2];
|
||||
|
||||
/* Check if it is safe to call the IsServerProcess() function. */
|
||||
tags[0].ti_Tag = SBTM_GETREF(SBTC_BREAKMASK);
|
||||
tags[0].ti_Data = (ULONG)&have_server_api;
|
||||
tags[1].ti_Tag = TAG_END;
|
||||
|
||||
PROFILE_OFF();
|
||||
|
||||
if(__SocketBaseTagList(tags) != 0)
|
||||
have_server_api = FALSE;
|
||||
|
||||
PROFILE_ON();
|
||||
|
||||
/* If it's safe to call IsServerProcess(), ask if the
|
||||
"struct DaemonMessage" pointer is valid. If it's not,
|
||||
set the message pointer to NULL, ignoring it altogether. */
|
||||
if(have_server_api && NOT IsServerProcess())
|
||||
dm = NULL;
|
||||
}
|
||||
|
||||
if(dm != NULL && TypeOfMem(dm) != 0 && TypeOfMem(((char *)dm) + sizeof(*dm)-1) != 0)
|
||||
{
|
||||
struct SignalSemaphore * lock;
|
||||
int daemon_socket;
|
||||
|
||||
Reference in New Issue
Block a user