зеркало из https://github.com/mozilla/gecko-dev.git
Bug 794240: Disable timerthread + close sockets + cleanup tmp-files on shutdown + file permissions. r=jesup
This commit is contained in:
Родитель
e666579b92
Коммит
10c0782671
|
@ -582,6 +582,9 @@
|
|||
#
|
||||
|
||||
'defines' : [
|
||||
# CPR timers are needed by SIP, but are disabled for now
|
||||
# to avoid the extra timer thread and stale cleanup code
|
||||
# 'CPR_TIMERS_ENABLED',
|
||||
],
|
||||
|
||||
'cflags_mozilla': [
|
||||
|
|
|
@ -216,7 +216,7 @@ ccInit ()
|
|||
/*
|
||||
* below should move to cprPreInit. keep it here until then
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32) && defined(CPR_TIMERS_ENABLED)
|
||||
cprTimerSystemInit();
|
||||
#endif
|
||||
|
||||
|
|
|
@ -37,17 +37,16 @@
|
|||
|
||||
/* SIP Message queue waiting thread and the main thread IPC names */
|
||||
#ifdef __ANDROID__
|
||||
#define SIP_MSG_IPC_PATH "/data/data/com.cisco.telephony.provider/"
|
||||
#define SIP_IPC_TEMP_PATH "/data/data/com.cisco.telephony.provider/SIP-%d"
|
||||
#else
|
||||
#define SIP_MSG_IPC_PATH "/tmp/"
|
||||
#define SIP_IPC_TEMP_PATH "/tmp/SIP-%d"
|
||||
#endif
|
||||
#define SIP_MSG_SERV_NAME "SIP-Main-%d"
|
||||
#define SIP_MSG_CLNT_NAME "SIP-MsgQ-%d"
|
||||
#define SIP_MSG_SERV_NAME "Main"
|
||||
#define SIP_MSG_CLNT_NAME "MsgQ"
|
||||
|
||||
#define SIP_PAUSE_WAIT_IPC_LISTEN_READY_TIME 50 /* 50ms. */
|
||||
#define SIP_MAX_WAIT_FOR_IPC_LISTEN_READY 1200 /* 50 * 1200 = 1 minutes */
|
||||
|
||||
|
||||
/*---------------------------------------------------------
|
||||
*
|
||||
* Local Variables
|
||||
|
@ -74,9 +73,6 @@ typedef struct sip_int_msg_t_ {
|
|||
/* Internal message queue (array) */
|
||||
static sip_int_msg_t sip_int_msgq_buf[MAX_SIP_MESSAGES] = {{0,0},{0,0}};
|
||||
|
||||
/* Main thread and message queue waiting thread IPC names */
|
||||
static const char *sip_IPC_serv_name = SIP_MSG_IPC_PATH SIP_MSG_SERV_NAME;
|
||||
static const char *sip_IPC_clnt_name = SIP_MSG_IPC_PATH SIP_MSG_CLNT_NAME;
|
||||
static cpr_sockaddr_un_t sip_serv_sock_addr;
|
||||
static cpr_sockaddr_un_t sip_clnt_sock_addr;
|
||||
|
||||
|
@ -163,7 +159,7 @@ static cpr_socket_t sip_create_IPC_sock (const char *name)
|
|||
cpr_set_sockun_addr(&addr, name, getpid());
|
||||
|
||||
/* make sure file doesn't already exist */
|
||||
unlink( (char *)addr.sun_path);
|
||||
unlink(addr.sun_path);
|
||||
|
||||
/* do the bind */
|
||||
if (cprBind(sock, (cpr_sockaddr_t *)&addr,
|
||||
|
@ -240,20 +236,16 @@ void sip_platform_task_msgqwait (void *arg)
|
|||
/*
|
||||
* Adjust relative priority of SIP thread.
|
||||
*/
|
||||
#ifndef WIN32
|
||||
(void) cprAdjustRelativeThreadPriority(SIP_THREAD_RELATIVE_PRIORITY);
|
||||
#else
|
||||
/* Use default priority */
|
||||
(void) cprAdjustRelativeThreadPriority(0);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The main thread is ready. set global client socket address
|
||||
* so that the server can send back response.
|
||||
*/
|
||||
cpr_set_sockun_addr(&sip_clnt_sock_addr, sip_IPC_clnt_name, getpid());
|
||||
cpr_set_sockun_addr(&sip_clnt_sock_addr,
|
||||
SIP_IPC_TEMP_PATH "/" SIP_MSG_CLNT_NAME, getpid());
|
||||
|
||||
sip_ipc_clnt_socket = sip_create_IPC_sock(sip_IPC_clnt_name);
|
||||
sip_ipc_clnt_socket = sip_create_IPC_sock(sip_clnt_sock_addr.sun_path);
|
||||
|
||||
if (sip_ipc_clnt_socket == INVALID_SOCKET) {
|
||||
CCSIP_DEBUG_ERROR(SIP_F_PREFIX"sip_create_IPC_sock() failed,"
|
||||
|
@ -323,6 +315,8 @@ void sip_platform_task_msgqwait (void *arg)
|
|||
}
|
||||
}
|
||||
}
|
||||
cprCloseSocket(sip_ipc_clnt_socket);
|
||||
unlink(sip_clnt_sock_addr.sun_path); // removes tmp file
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -370,6 +364,21 @@ static void sip_process_int_msg (void)
|
|||
msg = int_msg->msg;
|
||||
syshdr = int_msg->syshdr;
|
||||
if (msg != NULL && syshdr != NULL) {
|
||||
if (syshdr->Cmd == THREAD_UNLOAD) {
|
||||
/*
|
||||
* Cleanup here, as SIPTaskProcessListEvent wont return.
|
||||
* - Remove last tmp file and tmp dir.
|
||||
*/
|
||||
cprCloseSocket(sip_ipc_serv_socket);
|
||||
unlink(sip_serv_sock_addr.sun_path);
|
||||
|
||||
char stmpdir[sizeof(sip_serv_sock_addr.sun_path)];
|
||||
PR_snprintf(stmpdir, sizeof(stmpdir), SIP_IPC_TEMP_PATH, getpid());
|
||||
if (rmdir(stmpdir) != 0) {
|
||||
CCSIP_DEBUG_ERROR(SIP_F_PREFIX"failed to remove temp dir\n",
|
||||
fname);
|
||||
}
|
||||
}
|
||||
SIPTaskProcessListEvent(syshdr->Cmd, msg, syshdr->Usr.UsrPtr,
|
||||
syshdr->Len);
|
||||
cprReleaseSysHeader(syshdr);
|
||||
|
@ -435,23 +444,28 @@ sip_platform_task_loop (void *arg)
|
|||
/*
|
||||
* Adjust relative priority of SIP thread.
|
||||
*/
|
||||
#ifndef WIN32
|
||||
(void) cprAdjustRelativeThreadPriority(SIP_THREAD_RELATIVE_PRIORITY);
|
||||
#else
|
||||
/* Use default priority */
|
||||
(void) cprAdjustRelativeThreadPriority(0);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Setup IPC socket addresses for main thread (server)
|
||||
*/
|
||||
cpr_set_sockun_addr(&sip_serv_sock_addr, sip_IPC_serv_name, getpid());
|
||||
{
|
||||
char stmpdir[sizeof(sip_serv_sock_addr.sun_path)];
|
||||
PR_snprintf(stmpdir, sizeof(stmpdir), SIP_IPC_TEMP_PATH, getpid());
|
||||
|
||||
if (mkdir(stmpdir, 0700) != 0) {
|
||||
CCSIP_DEBUG_ERROR(SIP_F_PREFIX"failed to create temp dir\n", fname);
|
||||
return;
|
||||
}
|
||||
}
|
||||
cpr_set_sockun_addr(&sip_serv_sock_addr,
|
||||
SIP_IPC_TEMP_PATH "/" SIP_MSG_SERV_NAME, getpid());
|
||||
|
||||
/*
|
||||
* Create IPC between the message queue thread and this main
|
||||
* thread.
|
||||
*/
|
||||
sip_ipc_serv_socket = sip_create_IPC_sock(sip_IPC_serv_name);
|
||||
sip_ipc_serv_socket = sip_create_IPC_sock(sip_serv_sock_addr.sun_path);
|
||||
|
||||
if (sip_ipc_serv_socket == INVALID_SOCKET) {
|
||||
CCSIP_DEBUG_ERROR(SIP_F_PREFIX"sip_create_IPC_sock() failed:"
|
||||
|
@ -480,6 +494,7 @@ sip_platform_task_loop (void *arg)
|
|||
|
||||
/*
|
||||
* Main Event Loop
|
||||
* - Forever-loop exits in sip_process_int_msg()::THREAD_UNLOAD
|
||||
*/
|
||||
while (TRUE) {
|
||||
/*
|
||||
|
|
|
@ -171,14 +171,13 @@ cprPreInit (void)
|
|||
CPR_ERROR("%s: MsgQueue Mutex init failure %d\n", fname, returnCode);
|
||||
return CPR_FAILURE;
|
||||
}
|
||||
|
||||
#ifdef CPR_TIMERS_ENABLED
|
||||
returnCode = cpr_timer_pre_init();
|
||||
if (returnCode != 0) {
|
||||
CPR_ERROR("%s: timer pre init failed %d\n", fname, returnCode);
|
||||
return CPR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
return CPR_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -765,7 +765,7 @@ cpr_inet_pton (int af, const char *src, void *dst)
|
|||
*
|
||||
* @param[in] addr - socket fd to bind with the IPC address.
|
||||
* @param[in] name - pointer to the name of socket to bind to.
|
||||
*
|
||||
* @param[in] pid - process id (only used if name contains %d)
|
||||
*
|
||||
* @pre (name != NULL)
|
||||
*/
|
||||
|
@ -774,7 +774,7 @@ void cpr_set_sockun_addr (cpr_sockaddr_un_t *addr, const char *name, pid_t pid)
|
|||
/* Bind to the local socket */
|
||||
memset(addr, 0, sizeof(cpr_sockaddr_un_t));
|
||||
addr->sun_family = AF_UNIX;
|
||||
snprintf((char *) addr->sun_path, sizeof(addr->sun_path), "%s_%d", name, pid);
|
||||
snprintf(addr->sun_path, sizeof(addr->sun_path), name, pid);
|
||||
}
|
||||
|
||||
/* int
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
*/
|
||||
|
||||
#include "cpr.h"
|
||||
#include "cpr_assert.h"
|
||||
#include "cpr_socket.h"
|
||||
#include "cpr_stdlib.h"
|
||||
#include "cpr_stdio.h"
|
||||
|
@ -226,14 +227,10 @@ cprSleep (uint32_t duration)
|
|||
static cprRC_t addTimerToList (cpr_timer_t *cprTimerPtr, uint32_t duration, void *data)
|
||||
{
|
||||
// TODO(ekr@rtfm.com): Put this back in when you figure out why it causes crashes
|
||||
return CPR_SUCCESS;
|
||||
|
||||
#if 0
|
||||
static const char fname[] = "addTimerToList";
|
||||
#ifdef CPR_TIMERS_ENABLED
|
||||
timer_ipc_t tmr_cmd = {0};
|
||||
timer_ipc_t tmr_rsp={0};
|
||||
|
||||
|
||||
API_ENTER();
|
||||
|
||||
CPR_INFO("%s: cprTimerptr=0x%x dur=%d user_data=%p\n",
|
||||
|
@ -254,7 +251,7 @@ static cprRC_t addTimerToList (cpr_timer_t *cprTimerPtr, uint32_t duration, void
|
|||
}
|
||||
|
||||
} else {
|
||||
CPR_ERROR("can not make IPC connection, client_sock is invalid %s\n", fname);
|
||||
CPR_ERROR("can not make IPC connection, client_sock is invalid %s\n", __FUNCTION__);
|
||||
API_RETURN(CPR_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -270,7 +267,11 @@ static cprRC_t addTimerToList (cpr_timer_t *cprTimerPtr, uint32_t duration, void
|
|||
//CPR_INFO("received response from the timer result=%d\n", tmr_rsp.u.result);
|
||||
API_RETURN(tmr_rsp.u.result);
|
||||
}
|
||||
#else
|
||||
cprAssert(FALSE, CPR_FAILURE);
|
||||
CPR_ERROR("CPR Timers are disabled! %s\n", __FUNCTION__);
|
||||
#endif
|
||||
return CPR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -175,14 +175,13 @@ cprPreInit (void)
|
|||
CPR_ERROR("%s: MsgQueue Mutex init failure %d\n", fname, returnCode);
|
||||
return CPR_FAILURE;
|
||||
}
|
||||
|
||||
#if CPR_TIMERS_ENABLED
|
||||
returnCode = cpr_timer_pre_init();
|
||||
if (returnCode != 0) {
|
||||
CPR_ERROR("%s: timer pre init failed %d\n", fname, returnCode);
|
||||
return CPR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
return CPR_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -740,7 +740,7 @@ cpr_inet_pton (int af, const char *src, void *dst)
|
|||
*
|
||||
* @param[in] addr - socket fd to bind with the IPC address.
|
||||
* @param[in] name - pointer to the name of socket to bind to.
|
||||
*
|
||||
* @param[in] pid - process id (only used if name contains %d)
|
||||
*
|
||||
* @pre (name != NULL)
|
||||
*/
|
||||
|
@ -749,7 +749,7 @@ void cpr_set_sockun_addr (cpr_sockaddr_un_t *addr, const char *name, pid_t pid)
|
|||
/* Bind to the local socket */
|
||||
memset(addr, 0, sizeof(cpr_sockaddr_un_t));
|
||||
addr->sun_family = AF_LOCAL;
|
||||
snprintf((char *) addr->sun_path, sizeof(addr->sun_path), "%s_%d", name, pid);
|
||||
snprintf(addr->sun_path, sizeof(addr->sun_path), name, pid);
|
||||
}
|
||||
|
||||
/* int
|
||||
|
|
|
@ -1084,5 +1084,5 @@ void cpr_set_sockun_addr(cpr_sockaddr_un_t *addr, const char *name, pid_t pid)
|
|||
/* Bind to the local socket */
|
||||
memset(addr, 0, sizeof(cpr_sockaddr_un_t));
|
||||
addr->sun_family = AF_INET;
|
||||
snprintf((char *) addr->sun_path, sizeof(addr->sun_path), "%s_%d", name, pid);
|
||||
snprintf(addr->sun_path, sizeof(addr->sun_path), name, pid);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче