This is an automated email from the ASF dual-hosted git repository.
mseidel pushed a commit to branch AOO42X
in repository https://gitbox.apache.org/repos/asf/openoffice.git
The following commit(s) were added to refs/heads/AOO42X by this push:
new 18a2cb5 Fixed mixed style (space/tabs) in indentation
18a2cb5 is described below
commit 18a2cb5f54f836dd660fa779fff998dca47fd4f5
Author: mseidel <[email protected]>
AuthorDate: Wed Aug 25 19:39:38 2021 +0200
Fixed mixed style (space/tabs) in indentation
(cherry picked from commit 6e2e4a188da9cb15953b6ac809239c8d1048848e)
---
main/sal/osl/unx/diagnose.c | 72 ++--
main/sal/osl/unx/process.c | 901 ++++++++++++++++++++++----------------------
main/sal/osl/unx/thread.c | 347 +++++++++--------
main/sal/osl/unx/time.c | 151 ++++----
4 files changed, 734 insertions(+), 737 deletions(-)
diff --git a/main/sal/osl/unx/diagnose.c b/main/sal/osl/unx/diagnose.c
index 45c3b90..0ccd1f2 100644
--- a/main/sal/osl/unx/diagnose.c
+++ b/main/sal/osl/unx/diagnose.c
@@ -1,5 +1,5 @@
/**************************************************************
- *
+ *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -7,16 +7,16 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
+ *
*************************************************************/
@@ -28,19 +28,19 @@
#if defined(LINUX) || defined(SOLARIS) || defined(FREEBSD)
#define HAVE_DLFCN_H
-#endif /* LINUX || SOLARIS || FREEBSD */
+#endif /* LINUX || SOLARIS || FREEBSD */
-#endif /* HAVE_DLFCN_H */
+#endif /* HAVE_DLFCN_H */
-#ifdef HAVE_DLFCN_H
+#ifdef HAVE_DLFCN_H
#ifndef INCLUDED_DLFCN_H
#include <dlfcn.h>
#define INCLUDED_DLFCN_H
#endif
-#endif /* HAVE_DLFCN_H */
+#endif /* HAVE_DLFCN_H */
#include "osl/thread.h"
#ifndef INCLUDED_PTHREAD_H
@@ -112,7 +112,7 @@ static void osl_diagnose_frame_Impl (
sname ? sname : "???",
offset);
- OSL_DIAGNOSE_OUTPUTMESSAGE(f, szMessage);
+ OSL_DIAGNOSE_OUTPUTMESSAGE(f, szMessage);
}
#endif
@@ -232,7 +232,7 @@ static void osl_diagnose_backtrace_Impl
(oslDebugMessageFunc f)
}
}
-#else /* (LINUX || SOLARIS || FREEBSD) */
+#else /* (LINUX || SOLARIS || FREEBSD) */
static void osl_diagnose_backtrace_Impl (oslDebugMessageFunc f)
{
@@ -250,23 +250,23 @@ sal_Bool SAL_CALL osl_assertFailedLine (
const sal_Char* pszMessage)
{
oslDebugMessageFunc f = g_pDebugMessageFunc;
- char szMessage[1024];
+ char szMessage[1024];
- // after reporting the assertion, abort if told so by SAL_DIAGNOSE_ABORT,
but *not* if
- // assertions are routed to some external instance
- char const * env = getenv( "SAL_DIAGNOSE_ABORT" );
- sal_Bool const doAbort = ( ( env != NULL ) && ( *env != '\0' ) && ( f ==
NULL ) );
+ // after reporting the assertion, abort if told so by
SAL_DIAGNOSE_ABORT, but *not* if
+ // assertions are routed to some external instance
+ char const * env = getenv( "SAL_DIAGNOSE_ABORT" );
+ sal_Bool const doAbort = ( ( env != NULL ) && ( *env != '\0' ) && ( f
== NULL ) );
- /* If there's a callback for detailed messages, use it */
- if ( g_pDetailedDebugMessageFunc != NULL )
- {
- g_pDetailedDebugMessageFunc( pszFileName, nLine, pszMessage );
- return sal_False;
- }
+ /* If there's a callback for detailed messages, use it */
+ if ( g_pDetailedDebugMessageFunc != NULL )
+ {
+ g_pDetailedDebugMessageFunc( pszFileName, nLine, pszMessage );
+ return sal_False;
+ }
- /* if SAL assertions are disabled in general, stop here */
- if ( getenv("DISABLE_SAL_DBGBOX") )
- return doAbort;
+ /* if SAL assertions are disabled in general, stop here */
+ if ( getenv("DISABLE_SAL_DBGBOX") )
+ return doAbort;
/* format message into buffer */
if (pszMessage != NULL)
@@ -286,7 +286,7 @@ sal_Bool SAL_CALL osl_assertFailedLine (
pthread_mutex_lock(&g_mutex);
/* output message buffer */
- OSL_DIAGNOSE_OUTPUTMESSAGE(f, szMessage);
+ OSL_DIAGNOSE_OUTPUTMESSAGE(f, szMessage);
/* output backtrace */
osl_diagnose_backtrace_Impl(f);
@@ -294,7 +294,7 @@ sal_Bool SAL_CALL osl_assertFailedLine (
/* release lock and leave */
pthread_mutex_unlock(&g_mutex);
- return doAbort;
+ return doAbort;
}
/************************************************************************/
@@ -309,10 +309,10 @@ void SAL_CALL osl_breakDebug()
/* osl_reportError */
/************************************************************************/
sal_Int32 SAL_CALL osl_reportError (
- sal_uInt32 nType,
+ sal_uInt32 nType,
const sal_Char* pszMessage)
{
- (void) nType; /* unused */
+ (void) nType; /* unused */
fputs(pszMessage, stderr);
return 0;
}
@@ -332,19 +332,19 @@ oslDebugMessageFunc SAL_CALL osl_setDebugMessageFunc (
/* osl_setDetailedDebugMessageFunc */
/************************************************************************/
pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc (
- pfunc_osl_printDetailedDebugMessage pNewFunc)
+ pfunc_osl_printDetailedDebugMessage pNewFunc)
{
- oslDetailedDebugMessageFunc pOldFunc = g_pDetailedDebugMessageFunc;
- g_pDetailedDebugMessageFunc = pNewFunc;
- return pOldFunc;
+ oslDetailedDebugMessageFunc pOldFunc = g_pDetailedDebugMessageFunc;
+ g_pDetailedDebugMessageFunc = pNewFunc;
+ return pOldFunc;
}
/************************************************************************/
/* osl_trace */
/************************************************************************/
void osl_trace(char const * pszFormat, ...) {
- va_list args;
- va_start(args, pszFormat);
- printTrace((unsigned long) getpid(), pszFormat, args);
- va_end(args);
+ va_list args;
+ va_start(args, pszFormat);
+ printTrace((unsigned long) getpid(), pszFormat, args);
+ va_end(args);
}
diff --git a/main/sal/osl/unx/process.c b/main/sal/osl/unx/process.c
index be3b80e..01f8657 100644
--- a/main/sal/osl/unx/process.c
+++ b/main/sal/osl/unx/process.c
@@ -1,5 +1,5 @@
/**************************************************************
- *
+ *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -7,21 +7,20 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
+ *
*************************************************************/
-
/*
* ToDo:
* - cleanup of process status things
@@ -30,8 +29,8 @@
*/
#if defined(SOLARIS)
- // The procfs may only be used without LFS in 32bits.
-# ifdef _FILE_OFFSET_BITS
+// The procfs may only be used without LFS in 32bits.
+# ifdef _FILE_OFFSET_BITS
# undef _FILE_OFFSET_BITS
# endif
#endif
@@ -76,7 +75,7 @@ extern oslFileHandle osl_createFileHandleFromFD( int fd );
/******************************************************************************
*
- * Data Type Definition
+ * Data Type Definition
*
******************************************************************************/
@@ -102,34 +101,34 @@ typedef struct {
} ProcessData;
typedef struct _oslPipeImpl {
- int m_Socket;
- sal_Char m_Name[PATH_MAX + 1];
+ int m_Socket;
+ sal_Char m_Name[PATH_MAX + 1];
} oslPipeImpl;
/******************************************************************************
*
- * Function Declarations
+ * Function Declarations
*
*****************************************************************************/
oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char *pszImageName,
- sal_Char *pszArguments[],
- oslProcessOption Options,
- oslSecurity Security,
- sal_Char *pszDirectory,
- sal_Char *pszEnvironments[],
- oslProcess *pProcess,
+
sal_Char *pszArguments[],
+
oslProcessOption Options,
+
oslSecurity Security,
+
sal_Char *pszDirectory,
+
sal_Char *pszEnvironments[],
+
oslProcess *pProcess,
oslFileHandle *pInputWrite,
oslFileHandle *pOutputRead,
oslFileHandle *pErrorRead );
-
+
oslProcessError SAL_CALL osl_searchPath_impl(
- const sal_Char* pszName,
- const sal_Char* pszPath,
- sal_Char Separator,
- sal_Char *pszBuffer,
+ const sal_Char* pszName,
+ const sal_Char* pszPath,
+ sal_Char Separator,
+ sal_Char *pszBuffer,
sal_uInt32 Max);
@@ -151,8 +150,8 @@ oslProcessError SAL_CALL osl_searchPath_impl(const
sal_Char* pszName, const sal_
sal_Char path[PATH_MAX + 1];
sal_Char *pchr;
- path[0] = '\0';
-
+ path[0] = '\0';
+
OSL_ASSERT(pszName != NULL);
if ( pszName == NULL )
@@ -187,8 +186,8 @@ oslProcessError SAL_CALL osl_searchPath_impl(const
sal_Char* pszName, const sal_
if (access(path, 0) == 0)
{
- char szRealPathBuf[PATH_MAX] = "";
-
+ char szRealPathBuf[PATH_MAX] = "";
+
if( NULL == realpath(path, szRealPathBuf) ||
(strlen(szRealPathBuf) >= (sal_uInt32)Max))
return osl_Process_E_Unknown;
@@ -207,7 +206,7 @@ oslProcessError SAL_CALL osl_searchPath_impl(const
sal_Char* pszName, const sal_
/******************************************************************************
*
- * New io resource transfer functions
+ * New io resource transfer functions
*
*****************************************************************************/
@@ -215,210 +214,210 @@ oslProcessError SAL_CALL osl_searchPath_impl(const
sal_Char* pszName, const sal_
/**********************************************
sendFdPipe
*********************************************/
-
+
static sal_Bool sendFdPipe(int PipeFD, int SocketFD)
{
- sal_Bool bRet = sal_False;
-
- struct iovec iov[1];
- struct msghdr msg;
- char buf[2]; /* send_fd()/recv_fd() 2-byte protocol
*/
- int nSend;
- int RetCode=0;
-
+ sal_Bool bRet = sal_False;
+
+ struct iovec iov[1];
+ struct msghdr msg;
+ char buf[2]; /* send_fd()/recv_fd() 2-byte protocol
*/
+ int nSend;
+ int RetCode=0;
+
#if defined(IOCHANNEL_TRANSFER_BSD)
- OSL_TRACE("IOCHANNEL_TRANSFER_BSD send");
-/* OSL_TRACE("sending fd %i\n",SocketFD); */
-
- iov[0].iov_base = buf;
- iov[0].iov_len = sizeof(buf);
- msg.msg_iov = iov;
- msg.msg_iovlen = 1;
- msg.msg_name = NULL;
- msg.msg_namelen = 0;
-
- msg.msg_accrights = (caddr_t) &SocketFD; /* addr of descriptor */
- msg.msg_accrightslen = sizeof(int); /* pass 1 descriptor */
- buf[1] = 0;
/* zero status means OK */
- buf[0] = 0;
/* null byte flag to recv_fd() */
-
+ OSL_TRACE("IOCHANNEL_TRANSFER_BSD send");
+/* OSL_TRACE("sending fd %i\n",SocketFD); */
+
+ iov[0].iov_base = buf;
+ iov[0].iov_len = sizeof(buf);
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+
+ msg.msg_accrights = (caddr_t) &SocketFD; /* addr of descriptor */
+ msg.msg_accrightslen = sizeof(int); /* pass 1 descriptor */
+ buf[1] = 0;
/* zero status means OK */
+ buf[0] = 0;
/* null byte flag to recv_fd() */
+
#else
-
- struct cmsghdr* cmptr = (struct cmsghdr*)malloc(CONTROLLEN);
-
- OSL_TRACE("!!!!!! IOCHANNEL_TRANSFER_BSD_RENO send");
-/* OSL_TRACE("sending fd %i\n",SocketFD); */
-
- iov[0].iov_base = buf;
- iov[0].iov_len = sizeof(buf);
- msg.msg_iov = iov;
- msg.msg_iovlen = 1;
- msg.msg_name = NULL;
- msg.msg_namelen = 0;
- msg.msg_control = (caddr_t) cmptr;
- msg.msg_controllen = CONTROLLEN;
-
- cmptr->cmsg_level = SOL_SOCKET;
- cmptr->cmsg_type = SCM_RIGHTS;
- cmptr->cmsg_len = CONTROLLEN;
- memcpy(CMSG_DATA(cmptr), &SocketFD, sizeof(int));
+
+ struct cmsghdr* cmptr = (struct cmsghdr*)malloc(CONTROLLEN);
+
+ OSL_TRACE("!!!!!! IOCHANNEL_TRANSFER_BSD_RENO send");
+/* OSL_TRACE("sending fd %i\n",SocketFD); */
+
+ iov[0].iov_base = buf;
+ iov[0].iov_len = sizeof(buf);
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_control = (caddr_t) cmptr;
+ msg.msg_controllen = CONTROLLEN;
+
+ cmptr->cmsg_level = SOL_SOCKET;
+ cmptr->cmsg_type = SCM_RIGHTS;
+ cmptr->cmsg_len = CONTROLLEN;
+ memcpy(CMSG_DATA(cmptr), &SocketFD, sizeof(int));
#endif
-
- if ( ( nSend = sendmsg(PipeFD, &msg, 0) ) > 0 )
- {
- bRet = sal_True;
- OSL_TRACE("sendFdPipe : send '%i' bytes\n",nSend);
-
- }
- else
- {
- OSL_TRACE("sendFdPipe : sending failed (%s)",strerror(errno));
- }
-
- nSend=read(PipeFD,&RetCode,sizeof(RetCode));
-
- if ( nSend > 0 && RetCode == 1 )
- {
- OSL_TRACE("sendFdPipe : resource was received\n");
- }
- else
- {
- OSL_TRACE("sendFdPipe : resource wasn't received\n");
- }
-
+
+ if ( ( nSend = sendmsg(PipeFD, &msg, 0) ) > 0 )
+ {
+ bRet = sal_True;
+ OSL_TRACE("sendFdPipe : send '%i' bytes\n",nSend);
+
+ }
+ else
+ {
+ OSL_TRACE("sendFdPipe : sending failed (%s)",strerror(errno));
+ }
+
+ nSend=read(PipeFD,&RetCode,sizeof(RetCode));
+
+ if ( nSend > 0 && RetCode == 1 )
+ {
+ OSL_TRACE("sendFdPipe : resource was received\n");
+ }
+ else
+ {
+ OSL_TRACE("sendFdPipe : resource wasn't received\n");
+ }
+
#if defined(IOCHANNEL_TRANSFER_BSD_RENO)
- free(cmptr);
+ free(cmptr);
#endif
- return bRet;
+ return bRet;
}
/**********************************************
receiveFdPipe
*********************************************/
-
+
static oslSocket receiveFdPipe(int PipeFD)
{
- oslSocket pSocket = 0;
- struct msghdr msghdr;
- struct iovec iov[1];
- char buffer[2];
- sal_Int32 nRead;
- int newfd=-1;
- int nRetCode=0;
-/* char *ptr; */
+ oslSocket pSocket = 0;
+ struct msghdr msghdr;
+ struct iovec iov[1];
+ char buffer[2];
+ sal_Int32 nRead;
+ int newfd=-1;
+ int nRetCode=0;
+/* char *ptr; */
#if defined(IOCHANNEL_TRANSFER_BSD)
-
- OSL_TRACE("IOCHANNEL_TRANSFER_BSD receive\n");
-
- iov[0].iov_base = buffer;
- iov[0].iov_len = sizeof(buffer);
- msghdr.msg_name = NULL;
- msghdr.msg_namelen = 0;
- msghdr.msg_iov = iov;
- msghdr.msg_iovlen = 1;
- msghdr.msg_accrights = (caddr_t) &newfd; /* addr of descriptor */
- msghdr.msg_accrightslen = sizeof(int); /* receive 1 descriptor */
-
+
+ OSL_TRACE("IOCHANNEL_TRANSFER_BSD receive\n");
+
+ iov[0].iov_base = buffer;
+ iov[0].iov_len = sizeof(buffer);
+ msghdr.msg_name = NULL;
+ msghdr.msg_namelen = 0;
+ msghdr.msg_iov = iov;
+ msghdr.msg_iovlen = 1;
+ msghdr.msg_accrights = (caddr_t) &newfd; /* addr of descriptor */
+ msghdr.msg_accrightslen = sizeof(int); /* receive 1 descriptor */
+
#else
- struct cmsghdr* cmptr = (struct cmsghdr*)malloc(CONTROLLEN);
+ struct cmsghdr* cmptr = (struct cmsghdr*)malloc(CONTROLLEN);
+
+ OSL_TRACE(" !!!! IOCHANNEL_TRANSFER_BSD_RENO receive");
- OSL_TRACE(" !!!! IOCHANNEL_TRANSFER_BSD_RENO receive");
-
- iov[0].iov_base = buffer;
- iov[0].iov_len = sizeof(buffer);
- msghdr.msg_name = NULL;
- msghdr.msg_namelen = 0;
- msghdr.msg_iov = iov;
- msghdr.msg_iovlen = 1;
+ iov[0].iov_base = buffer;
+ iov[0].iov_len = sizeof(buffer);
+ msghdr.msg_name = NULL;
+ msghdr.msg_namelen = 0;
+ msghdr.msg_iov = iov;
+ msghdr.msg_iovlen = 1;
- msghdr.msg_control = (caddr_t) cmptr;
- msghdr.msg_controllen = CONTROLLEN;
+ msghdr.msg_control = (caddr_t) cmptr;
+ msghdr.msg_controllen = CONTROLLEN;
#endif
-
+
#if defined(IOCHANNEL_TRANSFER_BSD)
-
- if ( ( nRead = recvmsg(PipeFD, &msghdr, 0) ) > 0 )
- {
- OSL_TRACE("receiveFdPipe : received '%i' bytes\n",nRead);
- }
+
+ if ( ( nRead = recvmsg(PipeFD, &msghdr, 0) ) > 0 )
+ {
+ OSL_TRACE("receiveFdPipe : received '%i' bytes\n",nRead);
+ }
#else
- if ( ( ( nRead = recvmsg(PipeFD, &msghdr, 0) ) > 0 ) &&
- ( msghdr.msg_controllen == CONTROLLEN ) )
- {
- OSL_TRACE("receiveFdPipe : received '%i' bytes\n",nRead);
- memcpy(&newfd, CMSG_DATA(cmptr), sizeof(int));
- }
+ if ( ( ( nRead = recvmsg(PipeFD, &msghdr, 0) ) > 0 ) &&
+ ( msghdr.msg_controllen == CONTROLLEN ) )
+ {
+ OSL_TRACE("receiveFdPipe : received '%i' bytes\n",nRead);
+ memcpy(&newfd, CMSG_DATA(cmptr), sizeof(int));
+ }
#endif
- else
- {
- OSL_TRACE("receiveFdPipe : receiving failed (%s)",strerror(errno));
- }
-
- if ( newfd >= 0 )
- {
- pSocket = __osl_createSocketImpl(newfd);
- nRetCode=1;
- OSL_TRACE("received fd %i\n",newfd);
- }
-
- OSL_TRACE("receiveFdPipe : writing back %i",nRetCode);
- nRead=write(PipeFD,&nRetCode,sizeof(nRetCode));
+ else
+ {
+ OSL_TRACE("receiveFdPipe : receiving failed
(%s)",strerror(errno));
+ }
+
+ if ( newfd >= 0 )
+ {
+ pSocket = __osl_createSocketImpl(newfd);
+ nRetCode=1;
+ OSL_TRACE("received fd %i\n",newfd);
+ }
+
+ OSL_TRACE("receiveFdPipe : writing back %i",nRetCode);
+ nRead=write(PipeFD,&nRetCode,sizeof(nRetCode));
#if defined(IOCHANNEL_TRANSFER_BSD_RENO)
- free(cmptr);
+ free(cmptr);
#endif
- return pSocket;
+ return pSocket;
}
/**********************************************
osl_sendResourcePipe
*********************************************/
-
+
sal_Bool osl_sendResourcePipe(oslPipe pPipe, oslSocket pSocket)
{
- sal_Bool bRet = sal_False;
+ sal_Bool bRet = sal_False;
- if ( pSocket == 0 || pPipe == 0 )
- {
- return sal_False;
- }
+ if ( pSocket == 0 || pPipe == 0 )
+ {
+ return sal_False;
+ }
- bRet = sendFdPipe(pPipe->m_Socket,pSocket->m_Socket);
+ bRet = sendFdPipe(pPipe->m_Socket,pSocket->m_Socket);
- return bRet;
+ return bRet;
}
/**********************************************
osl_receiveResourcePipe
*********************************************/
-
+
oslSocket osl_receiveResourcePipe(oslPipe pPipe)
{
- oslSocket pSocket=0;
+ oslSocket pSocket=0;
- if ( pPipe == 0 )
- {
- return 0;
- }
+ if ( pPipe == 0 )
+ {
+ return 0;
+ }
- pSocket = receiveFdPipe(pPipe->m_Socket);
+ pSocket = receiveFdPipe(pPipe->m_Socket);
- return (oslSocket) pSocket;
+ return (oslSocket) pSocket;
}
/******************************************************************************
*
- * Functions for starting a process
+ * Functions for starting a process
*
*****************************************************************************/
@@ -438,32 +437,32 @@ static void ChildStatusProc(void *pData)
in our child process */
memcpy(&data, pData, sizeof(data));
- if (socketpair(AF_UNIX, SOCK_STREAM, 0, channel) == -1)
- status = errno;
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, channel) == -1)
+ status = errno;
- fcntl(channel[0], F_SETFD, FD_CLOEXEC);
- fcntl(channel[1], F_SETFD, FD_CLOEXEC);
+ fcntl(channel[0], F_SETFD, FD_CLOEXEC);
+ fcntl(channel[1], F_SETFD, FD_CLOEXEC);
/* Create redirected IO pipes */
if ( status == 0 && data.m_pInputWrite )
if (pipe( stdInput ) == -1)
- status = errno;
+ status = errno;
if ( status == 0 && data.m_pOutputRead )
if (pipe( stdOutput ) == -1)
- status = errno;
+ status = errno;
if ( status == 0 && data.m_pErrorRead )
if (pipe( stdError ) == -1)
- status = errno;
+ status = errno;
- if ( (status == 0) && ((pid = fork()) == 0) )
- {
+ if ( (status == 0) && ((pid = fork()) == 0) )
+ {
/* Child */
- int chstatus = 0;
- sal_Int32 nWrote;
+ int chstatus = 0;
+ sal_Int32 nWrote;
- if (channel[0] != -1) close(channel[0]);
+ if (channel[0] != -1) close(channel[0]);
if ((data.m_uid != (uid_t)-1) && ((data.m_uid != getuid()) ||
(data.m_gid != getgid())))
{
@@ -478,26 +477,26 @@ static void ChildStatusProc(void *pData)
#endif
}
- if (data.m_pszDir)
- chstatus = chdir(data.m_pszDir);
+ if (data.m_pszDir)
+ chstatus = chdir(data.m_pszDir);
- if (chstatus == 0 && ((data.m_uid == (uid_t)-1) || ((data.m_uid ==
getuid()) && (data.m_gid == getgid()))))
+ if (chstatus == 0 && ((data.m_uid == (uid_t)-1) || ((data.m_uid
== getuid()) && (data.m_gid == getgid()))))
{
- int i;
+ int i;
for (i = 0; data.m_pszEnv[i] != NULL; i++)
- {
- if (strchr(data.m_pszEnv[i], '=') == NULL)
- {
- unsetenv(data.m_pszEnv[i]); /*TODO: check error return*/
- }
- else
- {
- putenv(data.m_pszEnv[i]); /*TODO: check error return*/
- }
- }
-
- OSL_TRACE("ChildStatusProc : starting '%s'",data.m_pszArgs[0]);
-
+ {
+ if (strchr(data.m_pszEnv[i], '=') == NULL)
+ {
+ unsetenv(data.m_pszEnv[i]); /*TODO:
check error return*/
+ }
+ else
+ {
+ putenv(data.m_pszEnv[i]); /*TODO: check
error return*/
+ }
+ }
+
+ OSL_TRACE("ChildStatusProc : starting
'%s'",data.m_pszArgs[0]);
+
/* Connect std IO to pipe ends */
/* Write end of stdInput not used in child process */
@@ -529,26 +528,26 @@ static void ChildStatusProc(void *pData)
if (stdError[1] != -1) close( stdError[1] );
}
- pid=execv(data.m_pszArgs[0], (sal_Char **)data.m_pszArgs);
+ pid=execv(data.m_pszArgs[0], (sal_Char
**)data.m_pszArgs);
}
- OSL_TRACE("Failed to exec, errno=%d (%s)\n", errno, strerror(errno));
+ OSL_TRACE("Failed to exec, errno=%d (%s)\n", errno,
strerror(errno));
+
+ OSL_TRACE("ChildStatusProc : starting '%s'
failed",data.m_pszArgs[0]);
- OSL_TRACE("ChildStatusProc : starting '%s' failed",data.m_pszArgs[0]);
-
/* if we reach here, something went wrong */
- nWrote = write(channel[1], &errno, sizeof(errno));
+ nWrote = write(channel[1], &errno, sizeof(errno));
if (nWrote != sizeof(errno))
- OSL_TRACE("sendFdPipe : sending failed (%s)",strerror(errno));
+ OSL_TRACE("sendFdPipe : sending failed
(%s)",strerror(errno));
- if (channel[1] != -1) close(channel[1]);
+ if (channel[1] != -1) close(channel[1]);
_exit(255);
- }
- else
- { /* Parent */
- int i = -1;
+ }
+ else
+ { /* Parent */
+ int i = -1;
if (channel[1] != -1) close(channel[1]);
/* Close unused pipe ends */
@@ -580,17 +579,17 @@ static void ChildStatusProc(void *pData)
if ( pdata->m_pInputWrite )
*(pdata->m_pInputWrite) =
osl_createFileHandleFromFD( stdInput[1] );
-
+
if ( pdata->m_pOutputRead )
*(pdata->m_pOutputRead) =
osl_createFileHandleFromFD( stdOutput[0] );
-
+
if ( pdata->m_pErrorRead )
*(pdata->m_pErrorRead) =
osl_createFileHandleFromFD( stdError[0] );
osl_releaseMutex(ChildListMutex);
osl_setCondition(pdata->m_started);
-
+
do
{
child_pid = waitpid(pid, &status, 0);
@@ -600,14 +599,14 @@ static void ChildStatusProc(void *pData)
{
OSL_TRACE("Failed to wait for child process,
errno=%d (%s)\n", errno, strerror(errno));
- /*
+ /*
We got an other error than EINTR. Anyway we
have to wake up the
waiting thread under any circumstances */
child_pid = pid;
}
-
+
if ( child_pid > 0 )
{
oslProcessImpl* pChild;
@@ -637,7 +636,7 @@ static void ChildStatusProc(void *pData)
}
else
{
- OSL_TRACE("ChildStatusProc : starting '%s'
failed",data.m_pszArgs[0]);
+ OSL_TRACE("ChildStatusProc : starting '%s'
failed",data.m_pszArgs[0]);
OSL_TRACE("Failed to launch child process, child
reports errno=%d (%s)\n", status, strerror(status));
/* Close pipe ends */
@@ -654,17 +653,17 @@ static void ChildStatusProc(void *pData)
if (stdOutput[0] != -1) close( stdOutput[0] );
if (stdError[0] != -1) close( stdError[0] );
- //if pid > 0 then a process was created, even if it later failed
- //e.g. bash searching for a command to execute, and we still
- //need to clean it up to avoid "defunct" processes
- if (pid > 0)
- {
- pid_t child_pid;
- do
- {
- child_pid = waitpid(pid, &status, 0);
- } while ( 0 > child_pid && EINTR == errno );
- }
+ //if pid > 0 then a process was created, even if it
later failed
+ //e.g. bash searching for a command to execute, and we
still
+ //need to clean it up to avoid "defunct" processes
+ if (pid > 0)
+ {
+ pid_t child_pid;
+ do
+ {
+ child_pid = waitpid(pid, &status, 0);
+ } while ( 0 > child_pid && EINTR == errno );
+ }
/* notify (and unblock) parent thread */
osl_setCondition(pdata->m_started);
@@ -675,16 +674,16 @@ static void ChildStatusProc(void *pData)
/**********************************************
osl_executeProcess_WithRedirectedIO
*********************************************/
-
+
oslProcessError SAL_CALL osl_executeProcess_WithRedirectedIO(
rtl_uString *ustrImageName,
rtl_uString *ustrArguments[],
- sal_uInt32 nArguments,
+
sal_uInt32 nArguments,
oslProcessOption Options,
oslSecurity Security,
rtl_uString *ustrWorkDir,
rtl_uString *ustrEnvironment[],
- sal_uInt32 nEnvironmentVars,
+
sal_uInt32 nEnvironmentVars,
oslProcess *pProcess,
oslFileHandle *pInputWrite,
oslFileHandle *pOutputRead,
@@ -692,121 +691,121 @@ oslProcessError SAL_CALL
osl_executeProcess_WithRedirectedIO(
)
{
- oslProcessError Error;
- sal_Char* pszWorkDir=NULL;
- sal_Char** pArguments=NULL;
- sal_Char** pEnvironment=NULL;
- unsigned int idx;
-
- char szImagePath[PATH_MAX] = "";
- char szWorkDir[PATH_MAX] = "";
-
- if ( ustrImageName && ustrImageName->length )
- {
- FileURLToPath( szImagePath, PATH_MAX, ustrImageName );
- }
-
- if ( ustrWorkDir != NULL && ustrWorkDir->length )
- {
- FileURLToPath( szWorkDir, PATH_MAX, ustrWorkDir );
- pszWorkDir = szWorkDir;
- }
-
- if ( pArguments == NULL && nArguments > 0 )
- {
- pArguments = (sal_Char**) malloc( ( nArguments + 2 ) *
sizeof(sal_Char*) );
- }
-
-
- for ( idx = 0 ; idx < nArguments ; ++idx )
- {
- rtl_String* strArg =NULL;
-
-
- rtl_uString2String( &strArg,
- rtl_uString_getStr(ustrArguments[idx]),
- rtl_uString_getLength(ustrArguments[idx]),
- osl_getThreadTextEncoding(),
- OUSTRING_TO_OSTRING_CVTFLAGS );
-
- pArguments[idx]=strdup(rtl_string_getStr(strArg));
- rtl_string_release(strArg);
+ oslProcessError Error;
+ sal_Char* pszWorkDir=NULL;
+ sal_Char** pArguments=NULL;
+ sal_Char** pEnvironment=NULL;
+ unsigned int idx;
+
+ char szImagePath[PATH_MAX] = "";
+ char szWorkDir[PATH_MAX] = "";
+
+ if ( ustrImageName && ustrImageName->length )
+ {
+ FileURLToPath( szImagePath, PATH_MAX, ustrImageName );
+ }
+
+ if ( ustrWorkDir != NULL && ustrWorkDir->length )
+ {
+ FileURLToPath( szWorkDir, PATH_MAX, ustrWorkDir );
+ pszWorkDir = szWorkDir;
+ }
+
+ if ( pArguments == NULL && nArguments > 0 )
+ {
+ pArguments = (sal_Char**) malloc( ( nArguments + 2 ) *
sizeof(sal_Char*) );
+ }
+
+
+ for ( idx = 0 ; idx < nArguments ; ++idx )
+ {
+ rtl_String* strArg =NULL;
+
+
+ rtl_uString2String( &strArg,
+
rtl_uString_getStr(ustrArguments[idx]),
+
rtl_uString_getLength(ustrArguments[idx]),
+
osl_getThreadTextEncoding(),
+
OUSTRING_TO_OSTRING_CVTFLAGS );
+
+ pArguments[idx]=strdup(rtl_string_getStr(strArg));
+ rtl_string_release(strArg);
pArguments[idx+1]=NULL;
- }
-
- for ( idx = 0 ; idx < nEnvironmentVars ; ++idx )
- {
- rtl_String* strEnv=NULL;
-
- if ( pEnvironment == NULL )
- {
- pEnvironment = (sal_Char**) malloc( ( nEnvironmentVars + 2 ) *
sizeof(sal_Char*) );
- }
-
- rtl_uString2String( &strEnv,
- rtl_uString_getStr(ustrEnvironment[idx]),
- rtl_uString_getLength(ustrEnvironment[idx]),
- osl_getThreadTextEncoding(),
- OUSTRING_TO_OSTRING_CVTFLAGS );
-
- pEnvironment[idx]=strdup(rtl_string_getStr(strEnv));
- rtl_string_release(strEnv);
- pEnvironment[idx+1]=NULL;
- }
-
-
- Error = osl_psz_executeProcess(szImagePath,
- pArguments,
- Options,
- Security,
- pszWorkDir,
- pEnvironment,
- pProcess,
+ }
+
+ for ( idx = 0 ; idx < nEnvironmentVars ; ++idx )
+ {
+ rtl_String* strEnv=NULL;
+
+ if ( pEnvironment == NULL )
+ {
+ pEnvironment = (sal_Char**) malloc( ( nEnvironmentVars
+ 2 ) * sizeof(sal_Char*) );
+ }
+
+ rtl_uString2String( &strEnv,
+
rtl_uString_getStr(ustrEnvironment[idx]),
+
rtl_uString_getLength(ustrEnvironment[idx]),
+
osl_getThreadTextEncoding(),
+
OUSTRING_TO_OSTRING_CVTFLAGS );
+
+ pEnvironment[idx]=strdup(rtl_string_getStr(strEnv));
+ rtl_string_release(strEnv);
+ pEnvironment[idx+1]=NULL;
+ }
+
+
+ Error = osl_psz_executeProcess(szImagePath,
+ pArguments,
+ Options,
+ Security,
+ pszWorkDir,
+ pEnvironment,
+ pProcess,
pInputWrite,
pOutputRead,
pErrorRead
);
- if ( pArguments != NULL )
- {
- for ( idx = 0 ; idx < nArguments ; ++idx )
- {
- if ( pArguments[idx] != NULL )
- {
- free(pArguments[idx]);
- }
- }
- free(pArguments);
- }
-
- if ( pEnvironment != NULL )
- {
- for ( idx = 0 ; idx < nEnvironmentVars ; ++idx )
- {
- if ( pEnvironment[idx] != NULL )
- {
- free(pEnvironment[idx]);
- }
- }
- free(pEnvironment);
- }
-
- return Error;
+ if ( pArguments != NULL )
+ {
+ for ( idx = 0 ; idx < nArguments ; ++idx )
+ {
+ if ( pArguments[idx] != NULL )
+ {
+ free(pArguments[idx]);
+ }
+ }
+ free(pArguments);
+ }
+
+ if ( pEnvironment != NULL )
+ {
+ for ( idx = 0 ; idx < nEnvironmentVars ; ++idx )
+ {
+ if ( pEnvironment[idx] != NULL )
+ {
+ free(pEnvironment[idx]);
+ }
+ }
+ free(pEnvironment);
+ }
+
+ return Error;
}
/**********************************************
osl_executeProcess
*********************************************/
-
+
oslProcessError SAL_CALL osl_executeProcess(
rtl_uString *ustrImageName,
rtl_uString *ustrArguments[],
- sal_uInt32 nArguments,
+
sal_uInt32 nArguments,
oslProcessOption Options,
oslSecurity Security,
rtl_uString *ustrWorkDir,
rtl_uString *ustrEnvironment[],
- sal_uInt32 nEnvironmentVars,
+
sal_uInt32 nEnvironmentVars,
oslProcess *pProcess
)
{
@@ -829,27 +828,27 @@ oslProcessError SAL_CALL osl_executeProcess(
/**********************************************
osl_psz_executeProcess
*********************************************/
-
+
oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char *pszImageName,
- sal_Char *pszArguments[],
- oslProcessOption Options,
- oslSecurity Security,
- sal_Char *pszDirectory,
- sal_Char *pszEnvironments[],
- oslProcess *pProcess,
+
sal_Char *pszArguments[],
+
oslProcessOption Options,
+
oslSecurity Security,
+
sal_Char *pszDirectory,
+
sal_Char *pszEnvironments[],
+
oslProcess *pProcess,
oslFileHandle *pInputWrite,
oslFileHandle *pOutputRead,
oslFileHandle *pErrorRead
)
{
- int i;
+ int i;
sal_Char path[PATH_MAX + 1];
ProcessData Data;
oslThread hThread;
- path[0] = '\0';
-
- memset(&Data,0,sizeof(ProcessData));
+ path[0] = '\0';
+
+ memset(&Data,0,sizeof(ProcessData));
Data.m_pInputWrite = pInputWrite;
Data.m_pOutputRead = pOutputRead;
Data.m_pErrorRead = pErrorRead;
@@ -871,19 +870,19 @@ oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char
*pszImageName,
Data.m_pszArgs[0] = strdup(pszImageName);
Data.m_pszArgs[1] = NULL;
- if ( pszArguments != 0 )
- {
- for (i = 0; ((i + 2) < MAX_ARGS) && (pszArguments[i] != NULL); i++)
- Data.m_pszArgs[i+1] = strdup(pszArguments[i]);
- Data.m_pszArgs[i+2] = NULL;
- }
+ if ( pszArguments != 0 )
+ {
+ for (i = 0; ((i + 2) < MAX_ARGS) && (pszArguments[i] != NULL);
i++)
+ Data.m_pszArgs[i+1] = strdup(pszArguments[i]);
+ Data.m_pszArgs[i+2] = NULL;
+ }
Data.m_options = Options;
Data.m_pszDir = (pszDirectory != NULL) ? strdup(pszDirectory) : NULL;
if (pszEnvironments != NULL)
{
- for (i = 0; ((i + 1) < MAX_ENVS) && (pszEnvironments[i] !=
NULL); i++)
+ for (i = 0; ((i + 1) < MAX_ENVS) && (pszEnvironments[i] !=
NULL); i++)
Data.m_pszEnv[i] = strdup(pszEnvironments[i]);
Data.m_pszEnv[i+1] = NULL;
}
@@ -892,8 +891,8 @@ oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char
*pszImageName,
if (Security != NULL)
{
- Data.m_uid = ((oslSecurityImpl*)Security)->m_pPasswd.pw_uid;
- Data.m_gid = ((oslSecurityImpl*)Security)->m_pPasswd.pw_gid;
+ Data.m_uid = ((oslSecurityImpl*)Security)->m_pPasswd.pw_uid;
+ Data.m_gid = ((oslSecurityImpl*)Security)->m_pPasswd.pw_gid;
Data.m_name = ((oslSecurityImpl*)Security)->m_pPasswd.pw_name;
}
else
@@ -912,18 +911,18 @@ oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char
*pszImageName,
hThread = osl_createThread(ChildStatusProc, &Data);
osl_waitCondition(Data.m_started, NULL);
- osl_destroyCondition(Data.m_started);
+ osl_destroyCondition(Data.m_started);
- for (i = 0; Data.m_pszArgs[i] != NULL; i++)
+ for (i = 0; Data.m_pszArgs[i] != NULL; i++)
free((void *)Data.m_pszArgs[i]);
- for (i = 0; Data.m_pszEnv[i] != NULL; i++)
+ for (i = 0; Data.m_pszEnv[i] != NULL; i++)
free((void *)Data.m_pszEnv[i]);
- if ( Data.m_pszDir != NULL )
- {
+ if ( Data.m_pszDir != NULL )
+ {
free((void *)Data.m_pszDir);
- }
+ }
osl_destroyThread(hThread);
@@ -935,7 +934,7 @@ oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char
*pszImageName,
osl_joinProcess(*pProcess);
return osl_Process_E_None;
- }
+ }
osl_destroyCondition(Data.m_pProcImpl->m_terminated);
free(Data.m_pProcImpl);
@@ -946,7 +945,7 @@ oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char
*pszImageName,
/******************************************************************************
*
- * Functions for processes
+ * Functions for processes
*
*****************************************************************************/
@@ -954,11 +953,11 @@ oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char
*pszImageName,
/**********************************************
osl_terminateProcess
*********************************************/
-
+
oslProcessError SAL_CALL osl_terminateProcess(oslProcess Process)
{
- if (Process == NULL)
- return osl_Process_E_Unknown;
+ if (Process == NULL)
+ return osl_Process_E_Unknown;
if (kill(((oslProcessImpl*)Process)->m_pid, SIGKILL) != 0)
{
@@ -968,10 +967,10 @@ oslProcessError SAL_CALL osl_terminateProcess(oslProcess
Process)
return osl_Process_E_NoPermission;
case ESRCH:
- return osl_Process_E_NotFound;
+ return osl_Process_E_NotFound;
default:
- return osl_Process_E_Unknown;
+ return osl_Process_E_Unknown;
}
}
@@ -981,7 +980,7 @@ oslProcessError SAL_CALL osl_terminateProcess(oslProcess
Process)
/**********************************************
osl_getProcess
*********************************************/
-
+
oslProcess SAL_CALL osl_getProcess(oslProcessIdentifier Ident)
{
oslProcessImpl *pProcImpl;
@@ -1035,10 +1034,10 @@ oslProcess SAL_CALL osl_getProcess(oslProcessIdentifier
Ident)
/**********************************************
osl_freeProcessHandle
*********************************************/
-
+
void SAL_CALL osl_freeProcessHandle(oslProcess Process)
{
- if (Process != NULL)
+ if (Process != NULL)
{
oslProcessImpl *pChild, *pPrev = NULL;
@@ -1081,7 +1080,7 @@ void SAL_CALL osl_freeProcessHandle(oslProcess Process)
#if defined(LINUX)
struct osl_procStat
{
- /* from 'stat' */
+ /* from 'stat' */
pid_t pid; /* pid */
char command[16]; /* 'argv[0]' */ /* mfe: it all right char
comm[16] in kernel! */
char state; /* state (running, stopped, ...) */
@@ -1107,7 +1106,7 @@ struct osl_procStat
unsigned long vsize; /* virtual memory size (in bytes) */
long rss; /* resident set size (in pages) */
unsigned long rss_rlim; /* rss limit (in bytes) */
- unsigned long startcode; /* address above program text can run */
+ unsigned long startcode; /* address above program text can run */
unsigned long endcode; /* address below program text can run */
unsigned long startstack; /* address of start of stack */
unsigned long kstkesp; /* current value of 'esp' (stack pointer) */
@@ -1149,7 +1148,7 @@ struct osl_procStat
/**********************************************
osl_getProcStat
*********************************************/
-
+
sal_Bool osl_getProcStat(pid_t pid, struct osl_procStat* procstat)
{
int fd = 0;
@@ -1168,7 +1167,7 @@ sal_Bool osl_getProcStat(pid_t pid, struct osl_procStat*
procstat)
/*printf("%s\n\n",prstatbuf);*/
if (!bRet)
- return sal_False;
+ return sal_False;
tmp = strrchr(prstatbuf, ')');
*tmp = '\0';
@@ -1196,20 +1195,20 @@ sal_Bool osl_getProcStat(pid_t pid, struct
osl_procStat* procstat)
&procstat->wchan, &procstat->nswap,
&procstat->cnswap
);
}
- return bRet;
+ return bRet;
}
/**********************************************
osl_getProcStatus
*********************************************/
-
+
sal_Bool osl_getProcStatus(pid_t pid, struct osl_procStat* procstat)
{
int fd = 0;
char name[PATH_MAX + 1];
snprintf(name, sizeof(name), "/proc/%u/status", pid);
- sal_Bool bRet = sal_False;
+ sal_Bool bRet = sal_False;
if ((fd = open(name,O_RDONLY)) >=0 )
{
@@ -1223,7 +1222,7 @@ sal_Bool osl_getProcStatus(pid_t pid, struct
osl_procStat* procstat)
/* printf("\n\n%s\n\n",prstatusbuf);*/
if (!bRet)
- return sal_False;
+ return sal_False;
tmp = strstr(prstatusbuf,"Uid:");
if(tmp)
@@ -1274,12 +1273,12 @@ sal_Bool osl_getProcStatus(pid_t pid, struct
osl_procStat* procstat)
/**********************************************
osl_getProcessInfo
*********************************************/
-
+
oslProcessError SAL_CALL osl_getProcessInfo(oslProcess Process, oslProcessData
Fields, oslProcessInfo* pInfo)
{
pid_t pid;
- if (Process == NULL)
+ if (Process == NULL)
pid = getpid();
else
pid = ((oslProcessImpl*)Process)->m_pid;
@@ -1376,53 +1375,53 @@ oslProcessError SAL_CALL osl_getProcessInfo(oslProcess
Process, oslProcessData F
if ( (Fields & osl_Process_CPUTIMES) || (Fields &
osl_Process_HEAPUSAGE) )
{
- struct osl_procStat procstat;
- memset(&procstat,0,sizeof(procstat));
-
- if ( (Fields & osl_Process_CPUTIMES) && osl_getProcStat(pid,
&procstat) )
- {
- /*
- * mfe:
- * We calculate only time of the process proper.
- * Threads are processes, we do not consider their
time here!
- * (For this, cutime and cstime should be used, it
seems not
- * to work in 2.0.36)
- */
-
- long clktck;
- unsigned long hz;
- unsigned long userseconds;
- unsigned long systemseconds;
-
- clktck = sysconf(_SC_CLK_TCK);
- if (clktck < 0) {
- return osl_Process_E_Unknown;
- }
- hz = (unsigned long) clktck;
-
- userseconds = procstat.utime/hz;
- systemseconds = procstat.stime/hz;
-
- pInfo->UserTime.Seconds = userseconds;
- pInfo->UserTime.Nanosec = procstat.utime -
(userseconds * hz);
- pInfo->SystemTime.Seconds = systemseconds;
- pInfo->SystemTime.Nanosec = procstat.stime -
(systemseconds * hz);
-
- pInfo->Fields |= osl_Process_CPUTIMES;
- }
-
- if ( (Fields & osl_Process_HEAPUSAGE) && osl_getProcStatus(pid,
&procstat) )
- {
- /*
- * mfe:
- * vm_data (found in status) shows the size of the
data segment
- * it a rough approximation of the core heap size
- */
- pInfo->HeapUsage = procstat.vm_data*1024;
-
- pInfo->Fields |= osl_Process_HEAPUSAGE;
- }
- }
+ struct osl_procStat procstat;
+ memset(&procstat,0,sizeof(procstat));
+
+ if ( (Fields & osl_Process_CPUTIMES) &&
osl_getProcStat(pid, &procstat) )
+ {
+ /*
+ * mfe:
+ * We calculate only time of the process
proper.
+ * Threads are processes, we do not consider
their time here!
+ * (For this, cutime and cstime should be
used, it seems not
+ * to work in 2.0.36)
+ */
+
+ long clktck;
+ unsigned long hz;
+ unsigned long userseconds;
+ unsigned long systemseconds;
+
+ clktck = sysconf(_SC_CLK_TCK);
+ if (clktck < 0) {
+ return osl_Process_E_Unknown;
+ }
+ hz = (unsigned long) clktck;
+
+ userseconds = procstat.utime/hz;
+ systemseconds = procstat.stime/hz;
+
+ pInfo->UserTime.Seconds = userseconds;
+ pInfo->UserTime.Nanosec = procstat.utime -
(userseconds * hz);
+ pInfo->SystemTime.Seconds = systemseconds;
+ pInfo->SystemTime.Nanosec = procstat.stime -
(systemseconds * hz);
+
+ pInfo->Fields |= osl_Process_CPUTIMES;
+ }
+
+ if ( (Fields & osl_Process_HEAPUSAGE) &&
osl_getProcStatus(pid, &procstat) )
+ {
+ /*
+ * mfe:
+ * vm_data (found in status) shows the size of
the data segment
+ * it a rough approximation of the core heap
size
+ */
+ pInfo->HeapUsage = procstat.vm_data*1024;
+
+ pInfo->Fields |= osl_Process_HEAPUSAGE;
+ }
+ }
return (pInfo->Fields == Fields) ? osl_Process_E_None :
osl_Process_E_Unknown;
#endif
@@ -1440,39 +1439,39 @@ oslProcessError SAL_CALL osl_getProcessInfo(oslProcess
Process, oslProcessData F
static int is_timeout(const struct timeval* tend)
{
struct timeval tcurrent;
- gettimeofday(&tcurrent, NULL);
+ gettimeofday(&tcurrent, NULL);
return (tcurrent.tv_sec >= tend->tv_sec);
}
/**********************************************
- kill(pid, 0) is useful for checking if a
- process is still alive, but remember that
+ kill(pid, 0) is useful for checking if a
+ process is still alive, but remember that
kill even returns 0 if the process is already
a zombie.
*********************************************/
-
+
static int is_process_dead(pid_t pid)
-{
+{
return ((-1 == kill(pid, 0)) && (ESRCH == errno));
}
/**********************************************
osl_joinProcessWithTimeout
*********************************************/
-
+
oslProcessError SAL_CALL osl_joinProcessWithTimeout(oslProcess Process, const
TimeValue* pTimeout)
{
oslProcessImpl* pChild = ChildList;
oslProcessError osl_error = osl_Process_E_None;
-
- OSL_PRECOND(Process, "osl_joinProcess: Invalid parameter");
- OSL_ASSERT(ChildListMutex);
-
- if (NULL == Process || 0 == ChildListMutex)
- return osl_Process_E_Unknown;
-
+
+ OSL_PRECOND(Process, "osl_joinProcess: Invalid parameter");
+ OSL_ASSERT(ChildListMutex);
+
+ if (NULL == Process || 0 == ChildListMutex)
+ return osl_Process_E_Unknown;
+
osl_acquireMutex(ChildListMutex);
-
+
/* check if process is a child of ours */
while (pChild != NULL)
{
@@ -1483,33 +1482,33 @@ oslProcessError SAL_CALL
osl_joinProcessWithTimeout(oslProcess Process, const Ti
}
osl_releaseMutex(ChildListMutex);
-
+
if (pChild != NULL)
{
oslConditionResult cond_res =
osl_waitCondition(pChild->m_terminated, pTimeout);
-
+
if (osl_cond_result_timeout == cond_res)
osl_error = osl_Process_E_TimedOut;
else if (osl_cond_result_ok != cond_res)
- osl_error = osl_Process_E_Unknown;
+ osl_error = osl_Process_E_Unknown;
}
else /* alien process; StatusThread will not be able
- to set the condition terminated */
+ to set the condition terminated */
{
pid_t pid = ((oslProcessImpl*)Process)->m_pid;
-
+
if (pTimeout)
{
int timeout = 0;
- struct timeval tend;
-
- gettimeofday(&tend, NULL);
-
- tend.tv_sec += pTimeout->Seconds;
-
+ struct timeval tend;
+
+ gettimeofday(&tend, NULL);
+
+ tend.tv_sec += pTimeout->Seconds;
+
while (!is_process_dead(pid) && ((timeout =
is_timeout(&tend)) == 0))
sleep(1);
-
+
if (timeout)
osl_error = osl_Process_E_TimedOut;
}
@@ -1517,9 +1516,9 @@ oslProcessError SAL_CALL
osl_joinProcessWithTimeout(oslProcess Process, const Ti
{
while (!is_process_dead(pid))
sleep(1);
- }
+ }
}
- return osl_error;
+ return osl_error;
}
/**********************************************
@@ -1528,5 +1527,5 @@ oslProcessError SAL_CALL
osl_joinProcessWithTimeout(oslProcess Process, const Ti
oslProcessError SAL_CALL osl_joinProcess(oslProcess Process)
{
- return osl_joinProcessWithTimeout(Process, NULL);
+ return osl_joinProcessWithTimeout(Process, NULL);
}
diff --git a/main/sal/osl/unx/thread.c b/main/sal/osl/unx/thread.c
index 605a9f5..df42bd7 100644
--- a/main/sal/osl/unx/thread.c
+++ b/main/sal/osl/unx/thread.c
@@ -1,5 +1,5 @@
/**************************************************************
- *
+ *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -7,16 +7,16 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
+ *
*************************************************************/
@@ -70,8 +70,8 @@ typedef struct osl_thread_impl_st
{
pthread_t m_hThread;
sal_uInt16 m_Ident; /* @@@ see TODO @@@ */
- short m_Flags;
- oslWorkerFunction m_WorkerFunction;
+ short m_Flags;
+ oslWorkerFunction m_WorkerFunction;
void* m_pData;
pthread_mutex_t m_Lock;
pthread_cond_t m_Cond;
@@ -195,30 +195,30 @@ static void osl_thread_destruct_Impl (Thread_Impl **
ppImpl)
/*****************************************************************************/
static void osl_thread_cleanup_Impl (void* pData)
{
- pthread_t thread;
- int attached;
- int destroyed;
+ pthread_t thread;
+ int attached;
+ int destroyed;
Thread_Impl* pImpl= (Thread_Impl*)pData;
pthread_mutex_lock (&(pImpl->m_Lock));
- thread = pImpl->m_hThread;
- attached = (pImpl->m_Flags & THREADIMPL_FLAGS_ATTACHED) != 0;
- destroyed = (pImpl->m_Flags & THREADIMPL_FLAGS_DESTROYED) != 0;
- pImpl->m_Flags &= ~(THREADIMPL_FLAGS_ACTIVE | THREADIMPL_FLAGS_ATTACHED);
+ thread = pImpl->m_hThread;
+ attached = (pImpl->m_Flags & THREADIMPL_FLAGS_ATTACHED) != 0;
+ destroyed = (pImpl->m_Flags & THREADIMPL_FLAGS_DESTROYED) != 0;
+ pImpl->m_Flags &= ~(THREADIMPL_FLAGS_ACTIVE |
THREADIMPL_FLAGS_ATTACHED);
pthread_mutex_unlock (&(pImpl->m_Lock));
- /* release oslThreadIdentifier @@@ see TODO @@@ */
- removeThreadId (thread);
+ /* release oslThreadIdentifier @@@ see TODO @@@ */
+ removeThreadId (thread);
- if (attached)
- {
- pthread_detach (thread);
- }
+ if (attached)
+ {
+ pthread_detach (thread);
+ }
- if (destroyed)
- {
+ if (destroyed)
+ {
osl_thread_destruct_Impl (&pImpl);
}
}
@@ -233,10 +233,10 @@ static void* osl_thread_start_Impl (void* pData)
OSL_ASSERT(pImpl);
- pthread_mutex_lock (&(pImpl->m_Lock));
+ pthread_mutex_lock (&(pImpl->m_Lock));
/* install cleanup handler */
- pthread_cleanup_push (osl_thread_cleanup_Impl, pData);
+ pthread_cleanup_push (osl_thread_cleanup_Impl, pData);
/* request oslThreadIdentifier @@@ see TODO @@@ */
pImpl->m_Ident = insertThreadId (pImpl->m_hThread);
@@ -244,21 +244,21 @@ static void* osl_thread_start_Impl (void* pData)
/* signal change from STARTUP to ACTIVE state */
pImpl->m_Flags &= ~THREADIMPL_FLAGS_STARTUP;
pImpl->m_Flags |= THREADIMPL_FLAGS_ACTIVE;
- pthread_cond_signal (&(pImpl->m_Cond));
+ pthread_cond_signal (&(pImpl->m_Cond));
/* Check if thread is started in SUSPENDED state */
- while (pImpl->m_Flags & THREADIMPL_FLAGS_SUSPENDED)
- {
- /* wait until SUSPENDED flag is cleared */
+ while (pImpl->m_Flags & THREADIMPL_FLAGS_SUSPENDED)
+ {
+ /* wait until SUSPENDED flag is cleared */
pthread_cleanup_push (osl_thread_wait_cleanup_Impl,
&(pImpl->m_Lock));
pthread_cond_wait (&(pImpl->m_Cond), &(pImpl->m_Lock));
pthread_cleanup_pop (0);
- }
+ }
/* check for SUSPENDED to TERMINATE state change */
terminate = ((pImpl->m_Flags & THREADIMPL_FLAGS_TERMINATE) > 0);
- pthread_mutex_unlock (&(pImpl->m_Lock));
+ pthread_mutex_unlock (&(pImpl->m_Lock));
if (!terminate)
{
@@ -280,17 +280,17 @@ static oslThread osl_thread_create_Impl (
short nFlags)
{
Thread_Impl* pImpl;
- int nRet=0;
+ int nRet=0;
pImpl = osl_thread_construct_Impl();
- if (!pImpl)
- return (0); /* ENOMEM */
+ if (!pImpl)
+ return (0); /* ENOMEM */
pImpl->m_WorkerFunction = pWorker;
pImpl->m_pData = pThreadData;
pImpl->m_Flags = nFlags | THREADIMPL_FLAGS_STARTUP;
- pthread_mutex_lock (&(pImpl->m_Lock));
+ pthread_mutex_lock (&(pImpl->m_Lock));
if ((nRet = pthread_create (
&(pImpl->m_hThread),
@@ -298,8 +298,7 @@ static oslThread osl_thread_create_Impl (
osl_thread_start_Impl,
(void*)(pImpl))) != 0)
{
- OSL_TRACE("osl_thread_create_Impl(): errno: %d, %s\n",
- nRet, strerror(nRet));
+ OSL_TRACE("osl_thread_create_Impl(): errno: %d, %s\n", nRet,
strerror(nRet));
pthread_mutex_unlock (&(pImpl->m_Lock));
osl_thread_destruct_Impl (&pImpl);
@@ -312,11 +311,11 @@ static oslThread osl_thread_create_Impl (
{
/* wait until STARTUP flag is cleared */
pthread_cleanup_push (osl_thread_wait_cleanup_Impl,
&(pImpl->m_Lock));
- pthread_cond_wait (&(pImpl->m_Cond), &(pImpl->m_Lock));
+ pthread_cond_wait (&(pImpl->m_Cond), &(pImpl->m_Lock));
pthread_cleanup_pop (0);
- }
+ }
- pthread_mutex_unlock (&(pImpl->m_Lock));
+ pthread_mutex_unlock (&(pImpl->m_Lock));
return ((oslThread)(pImpl));
}
@@ -328,7 +327,7 @@ oslThread osl_createThread (
oslWorkerFunction pWorker,
void * pThreadData)
{
- return osl_thread_create_Impl (
+ return osl_thread_create_Impl (
pWorker,
pThreadData,
THREADIMPL_FLAGS_ATTACHED);
@@ -341,7 +340,7 @@ oslThread osl_createSuspendedThread (
oslWorkerFunction pWorker,
void * pThreadData)
{
- return osl_thread_create_Impl (
+ return osl_thread_create_Impl (
pWorker,
pThreadData,
THREADIMPL_FLAGS_ATTACHED |
@@ -353,17 +352,17 @@ oslThread osl_createSuspendedThread (
/*****************************************************************************/
void SAL_CALL osl_destroyThread(oslThread Thread)
{
- if (Thread != NULL) {
- Thread_Impl * impl = (Thread_Impl *) Thread;
- int active;
- pthread_mutex_lock(&impl->m_Lock);
- active = (impl->m_Flags & THREADIMPL_FLAGS_ACTIVE) != 0;
- impl->m_Flags |= THREADIMPL_FLAGS_DESTROYED;
- pthread_mutex_unlock(&impl->m_Lock);
- if (!active) {
- osl_thread_destruct_Impl(&impl);
- }
- }
+ if (Thread != NULL) {
+ Thread_Impl * impl = (Thread_Impl *) Thread;
+ int active;
+ pthread_mutex_lock(&impl->m_Lock);
+ active = (impl->m_Flags & THREADIMPL_FLAGS_ACTIVE) != 0;
+ impl->m_Flags |= THREADIMPL_FLAGS_DESTROYED;
+ pthread_mutex_unlock(&impl->m_Lock);
+ if (!active) {
+ osl_thread_destruct_Impl(&impl);
+ }
+ }
}
/*****************************************************************************/
@@ -380,11 +379,11 @@ void SAL_CALL osl_resumeThread(oslThread Thread)
pthread_mutex_lock (&(pImpl->m_Lock));
if (pImpl->m_Flags & THREADIMPL_FLAGS_SUSPENDED)
- {
+ {
/* clear SUSPENDED flag */
pImpl->m_Flags &= ~THREADIMPL_FLAGS_SUSPENDED;
pthread_cond_signal (&(pImpl->m_Cond));
- }
+ }
pthread_mutex_unlock (&(pImpl->m_Lock));
}
@@ -394,7 +393,7 @@ void SAL_CALL osl_resumeThread(oslThread Thread)
/*****************************************************************************/
void SAL_CALL osl_suspendThread(oslThread Thread)
{
- Thread_Impl* pImpl= (Thread_Impl*)Thread;
+ Thread_Impl* pImpl= (Thread_Impl*)Thread;
OSL_ASSERT(pImpl);
if (!pImpl)
@@ -405,16 +404,16 @@ void SAL_CALL osl_suspendThread(oslThread Thread)
pImpl->m_Flags |= THREADIMPL_FLAGS_SUSPENDED;
if (pthread_equal (pthread_self(), pImpl->m_hThread))
- {
+ {
/* self suspend */
- while (pImpl->m_Flags & THREADIMPL_FLAGS_SUSPENDED)
- {
- /* wait until SUSPENDED flag is cleared */
+ while (pImpl->m_Flags & THREADIMPL_FLAGS_SUSPENDED)
+ {
+ /* wait until SUSPENDED flag is cleared */
pthread_cleanup_push (osl_thread_wait_cleanup_Impl,
&(pImpl->m_Lock));
pthread_cond_wait (&(pImpl->m_Cond), &(pImpl->m_Lock));
pthread_cleanup_pop (0);
- }
- }
+ }
+ }
pthread_mutex_unlock (&(pImpl->m_Lock));
}
@@ -442,7 +441,7 @@ sal_Bool SAL_CALL osl_isThreadRunning(const oslThread
Thread)
/*****************************************************************************/
void SAL_CALL osl_joinWithThread(oslThread Thread)
{
- pthread_t thread;
+ pthread_t thread;
int attached;
Thread_Impl* pImpl= (Thread_Impl*)Thread;
@@ -458,7 +457,7 @@ void SAL_CALL osl_joinWithThread(oslThread Thread)
return; /* EDEADLK */
}
- thread = pImpl->m_hThread;
+ thread = pImpl->m_hThread;
attached = ((pImpl->m_Flags & THREADIMPL_FLAGS_ATTACHED) > 0);
pImpl->m_Flags &= ~THREADIMPL_FLAGS_ATTACHED;
@@ -492,11 +491,11 @@ void SAL_CALL osl_terminateThread(oslThread Thread)
pthread_mutex_lock (&(pImpl->m_Lock));
if (pImpl->m_Flags & THREADIMPL_FLAGS_SUSPENDED)
- {
+ {
/* clear SUSPENDED flag */
pImpl->m_Flags &= ~THREADIMPL_FLAGS_SUSPENDED;
pthread_cond_signal (&(pImpl->m_Cond));
- }
+ }
pImpl->m_Flags |= THREADIMPL_FLAGS_TERMINATE;
@@ -523,12 +522,12 @@ sal_Bool SAL_CALL osl_scheduleThread(oslThread Thread)
pthread_mutex_lock (&(pImpl->m_Lock));
while (pImpl->m_Flags & THREADIMPL_FLAGS_SUSPENDED)
- {
+ {
/* wait until SUSPENDED flag is cleared */
pthread_cleanup_push (osl_thread_wait_cleanup_Impl,
&(pImpl->m_Lock));
pthread_cond_wait (&(pImpl->m_Cond), &(pImpl->m_Lock));
pthread_cleanup_pop (0);
- }
+ }
terminate = ((pImpl->m_Flags & THREADIMPL_FLAGS_TERMINATE) > 0);
@@ -558,23 +557,23 @@ void SAL_CALL osl_waitThread(const TimeValue* pDelay)
/*
Note that POSIX scheduling _really_ requires threads to call this
functions, since a thread only reschedules to other thread, when
- it blocks (sleep, blocking I/O) OR calls sched_yield().
+ it blocks (sleep, blocking I/O) OR calls sched_yield().
*/
/*****************************************************************************/
void SAL_CALL osl_yieldThread()
{
- sched_yield();
+ sched_yield();
}
void SAL_CALL osl_setThreadName(char const * name) {
#if defined LINUX
- if (prctl(PR_SET_NAME, (unsigned long) name, 0, 0, 0) != 0) {
- OSL_TRACE(
- "%s prctl(PR_SET_NAME) failed with errno %d", OSL_LOG_PREFIX,
- errno);
- }
+ if (prctl(PR_SET_NAME, (unsigned long) name, 0, 0, 0) != 0) {
+ OSL_TRACE(
+ "%s prctl(PR_SET_NAME) failed with errno %d",
OSL_LOG_PREFIX,
+ errno);
+ }
#else
- (void) name;
+ (void) name;
#endif
}
@@ -645,10 +644,10 @@ static sal_uInt16 insertThreadId (pthread_t hThread)
++ LastIdent;
- if ( LastIdent == 0 )
- LastIdent = 1;
+ if ( LastIdent == 0 )
+ LastIdent = 1;
- pEntry->Ident = LastIdent;
+ pEntry->Ident = LastIdent;
if (pInsert)
pInsert->Next = pEntry;
@@ -712,82 +711,82 @@ oslThreadIdentifier SAL_CALL
osl_getThreadIdentifier(oslThread Thread)
}
/*****************************************************************************
- @@@ see TODO @@@
+ @@@ see TODO @@@
osl_thread_priority_init_Impl
set the base-priority of the main-thread to
oslThreadPriorityNormal (64) since 0 (lowest) is
the system default. This behaviour collides with
our enum-priority definition (highest..normal..lowest).
- A normaluser will expect the main-thread of an app.
+ A normal user will expect the main-thread of an app.
to have the "normal" priority.
*****************************************************************************/
static void osl_thread_priority_init_Impl (void)
{
#ifndef NO_PTHREAD_PRIORITY
- struct sched_param param;
- int policy=0;
- int nRet=0;
+ struct sched_param param;
+ int policy=0;
+ int nRet=0;
/* @@@ see TODO: calling thread may not be main thread @@@ */
- if ((nRet = pthread_getschedparam(pthread_self(), &policy, ¶m)) != 0)
- {
- OSL_TRACE("failed to get priority of thread [%s]\n",strerror(nRet));
- return;
- }
+ if ((nRet = pthread_getschedparam(pthread_self(), &policy, ¶m)) !=
0)
+ {
+ OSL_TRACE("failed to get priority of thread
[%s]\n",strerror(nRet));
+ return;
+ }
#if defined (SOLARIS)
- if ( policy >= _SCHED_NEXT)
- {
- /* mfe: pthread_getschedparam on Solaris has a possible Bug */
- /* one gets 959917873 as the policy */
- /* so set the policy to a default one */
- policy=SCHED_OTHER;
- }
+ if ( policy >= _SCHED_NEXT)
+ {
+ /* mfe: pthread_getschedparam on Solaris has a possible Bug */
+ /* one gets 959917873 as the policy */
+ /* so set the policy to a default one */
+ policy=SCHED_OTHER;
+ }
#endif /* SOLARIS */
- if ((nRet = sched_get_priority_min(policy) ) != -1)
- {
- OSL_TRACE("Min Prioriy for policy '%i' == '%i'\n",policy,nRet);
- g_thread.m_priority.m_Lowest=nRet;
- }
+ if ((nRet = sched_get_priority_min(policy) ) != -1)
+ {
+ OSL_TRACE("Min Prioriy for policy '%i' == '%i'\n",policy,nRet);
+ g_thread.m_priority.m_Lowest=nRet;
+ }
#if OSL_DEBUG_LEVEL > 1
- else
- {
- fprintf(stderr,"failed to get min sched param [%s]\n",strerror(errno));
- }
+ else
+ {
+ fprintf(stderr,"failed to get min sched param
[%s]\n",strerror(errno));
+ }
#endif /* OSL_DEBUG_LEVEL */
- if ((nRet = sched_get_priority_max(policy) ) != -1)
- {
- OSL_TRACE("Max Prioriy for policy '%i' == '%i'\n",policy,nRet);
- g_thread.m_priority.m_Highest=nRet;
- }
+ if ((nRet = sched_get_priority_max(policy) ) != -1)
+ {
+ OSL_TRACE("Max Prioriy for policy '%i' == '%i'\n",policy,nRet);
+ g_thread.m_priority.m_Highest=nRet;
+ }
#if OSL_DEBUG_LEVEL > 1
- else
- {
- fprintf(stderr,"failed to get max sched param [%s]\n",strerror(errno));
- }
+ else
+ {
+ fprintf(stderr,"failed to get max sched param
[%s]\n",strerror(errno));
+ }
#endif /* OSL_DEBUG_LEVEL */
- g_thread.m_priority.m_Normal =
+ g_thread.m_priority.m_Normal =
(g_thread.m_priority.m_Lowest + g_thread.m_priority.m_Highest)
/ 2;
- g_thread.m_priority.m_Below_Normal =
- (g_thread.m_priority.m_Lowest + g_thread.m_priority.m_Normal)
/ 2;
- g_thread.m_priority.m_Above_Normal =
+ g_thread.m_priority.m_Below_Normal =
+ (g_thread.m_priority.m_Lowest + g_thread.m_priority.m_Normal) /
2;
+ g_thread.m_priority.m_Above_Normal =
(g_thread.m_priority.m_Normal + g_thread.m_priority.m_Highest)
/ 2;
/* @@@ set prio of calling (not main) thread (?) @@@ */
- param.sched_priority= g_thread.m_priority.m_Normal;
+ param.sched_priority= g_thread.m_priority.m_Normal;
- if ((nRet = pthread_setschedparam(pthread_self(), policy, ¶m)) != 0)
- {
- OSL_TRACE("failed to change base priority of thread
[%s]\n",strerror(nRet));
- OSL_TRACE("Thread ID '%i', Policy '%i', Priority
'%i'\n",pthread_self(),policy,param.sched_priority);
- }
+ if ((nRet = pthread_setschedparam(pthread_self(), policy, ¶m)) != 0)
+ {
+ OSL_TRACE("failed to change base priority of thread
[%s]\n",strerror(nRet));
+ OSL_TRACE("Thread ID '%i', Policy '%i', Priority
'%i'\n",pthread_self(),policy,param.sched_priority);
+ }
#endif /* NO_PTHREAD_PRIORITY */
}
@@ -808,7 +807,7 @@ void SAL_CALL osl_setThreadPriority (
struct sched_param Param;
int policy;
- int nRet;
+ int nRet;
#endif /* NO_PTHREAD_PRIORITY */
@@ -819,64 +818,64 @@ void SAL_CALL osl_setThreadPriority (
return; /* EINVAL */
#ifdef NO_PTHREAD_PRIORITY
- (void) Priority; /* unused */
+ (void) Priority; /* unused */
#else /* NO_PTHREAD_PRIORITY */
- if (pthread_getschedparam(pImpl->m_hThread, &policy, &Param) != 0)
+ if (pthread_getschedparam(pImpl->m_hThread, &policy, &Param) != 0)
return; /* ESRCH */
#if defined (SOLARIS)
- if ( policy >= _SCHED_NEXT)
- {
- /* mfe: pthread_getschedparam on Solaris has a possible Bug */
- /* one gets 959917873 as the policy */
- /* so set the policy to a default one */
- policy=SCHED_OTHER;
- }
+ if ( policy >= _SCHED_NEXT)
+ {
+ /* mfe: pthread_getschedparam on Solaris has a possible Bug */
+ /* one gets 959917873 as the policy */
+ /* so set the policy to a default one */
+ policy=SCHED_OTHER;
+ }
#endif /* SOLARIS */
pthread_once (&(g_thread.m_once), osl_thread_init_Impl);
- switch(Priority)
- {
- case osl_Thread_PriorityHighest:
- Param.sched_priority= g_thread.m_priority.m_Highest;
- break;
+ switch(Priority)
+ {
+ case osl_Thread_PriorityHighest:
+ Param.sched_priority= g_thread.m_priority.m_Highest;
+ break;
- case osl_Thread_PriorityAboveNormal:
- Param.sched_priority= g_thread.m_priority.m_Above_Normal;
- break;
+ case osl_Thread_PriorityAboveNormal:
+ Param.sched_priority=
g_thread.m_priority.m_Above_Normal;
+ break;
- case osl_Thread_PriorityNormal:
- Param.sched_priority= g_thread.m_priority.m_Normal;
- break;
+ case osl_Thread_PriorityNormal:
+ Param.sched_priority= g_thread.m_priority.m_Normal;
+ break;
- case osl_Thread_PriorityBelowNormal:
- Param.sched_priority= g_thread.m_priority.m_Below_Normal;
- break;
+ case osl_Thread_PriorityBelowNormal:
+ Param.sched_priority=
g_thread.m_priority.m_Below_Normal;
+ break;
- case osl_Thread_PriorityLowest:
- Param.sched_priority= g_thread.m_priority.m_Lowest;
- break;
+ case osl_Thread_PriorityLowest:
+ Param.sched_priority= g_thread.m_priority.m_Lowest;
+ break;
- case osl_Thread_PriorityUnknown:
- OSL_ASSERT(sal_False); /* only fools try this...*/
+ case osl_Thread_PriorityUnknown:
+ OSL_ASSERT(sal_False); /* only fools try
this...*/
- /* let release-version behave friendly */
- return;
+ /* let release-version behave friendly */
+ return;
- default:
- /* enum expanded, but forgotten here...*/
- OSL_ENSURE(sal_False,"osl_setThreadPriority : unknown priority\n");
+ default:
+ /* enum expanded, but forgotten here...*/
+ OSL_ENSURE(sal_False,"osl_setThreadPriority : unknown
priority\n");
- /* let release-version behave friendly */
- return;
- }
+ /* let release-version behave friendly */
+ return;
+ }
- if ((nRet = pthread_setschedparam(pImpl->m_hThread, policy, &Param)) != 0)
- {
- OSL_TRACE("failed to change thread priority [%s]\n",strerror(nRet));
- }
+ if ((nRet = pthread_setschedparam(pImpl->m_hThread, policy, &Param)) !=
0)
+ {
+ OSL_TRACE("failed to change thread priority
[%s]\n",strerror(nRet));
+ }
#endif /* NO_PTHREAD_PRIORITY */
}
@@ -1017,18 +1016,18 @@ static void osl_thread_textencoding_init_Impl (void)
/*****************************************************************************/
rtl_TextEncoding SAL_CALL osl_getThreadTextEncoding()
{
- rtl_TextEncoding threadEncoding;
+ rtl_TextEncoding threadEncoding;
pthread_once (&(g_thread.m_once), osl_thread_init_Impl);
- /* check for thread specific encoding, use default if not set */
+ /* check for thread specific encoding, use default if not set */
threadEncoding = SAL_INT_CAST(
- rtl_TextEncoding,
- (sal_uIntPtr) pthread_getspecific(g_thread.m_textencoding.m_key));
+ rtl_TextEncoding,
+ (sal_uIntPtr)
pthread_getspecific(g_thread.m_textencoding.m_key));
if (0 == threadEncoding)
threadEncoding = g_thread.m_textencoding.m_default;
- return threadEncoding;
+ return threadEncoding;
}
/*****************************************************************************/
@@ -1036,12 +1035,12 @@ rtl_TextEncoding SAL_CALL osl_getThreadTextEncoding()
/*****************************************************************************/
rtl_TextEncoding osl_setThreadTextEncoding(rtl_TextEncoding Encoding)
{
- rtl_TextEncoding oldThreadEncoding = osl_getThreadTextEncoding();
+ rtl_TextEncoding oldThreadEncoding = osl_getThreadTextEncoding();
- /* save encoding in thread local storage */
- pthread_setspecific (
- g_thread.m_textencoding.m_key,
- (void*) SAL_INT_CAST(sal_uIntPtr, Encoding));
+ /* save encoding in thread local storage */
+ pthread_setspecific (
+ g_thread.m_textencoding.m_key,
+ (void*) SAL_INT_CAST(sal_uIntPtr, Encoding));
- return oldThreadEncoding;
+ return oldThreadEncoding;
}
diff --git a/main/sal/osl/unx/time.c b/main/sal/osl/unx/time.c
index 4898569..8361b0d 100644
--- a/main/sal/osl/unx/time.c
+++ b/main/sal/osl/unx/time.c
@@ -1,5 +1,5 @@
/**************************************************************
- *
+ *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -7,21 +7,20 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- *
+ *
*************************************************************/
-
#include "system.h"
#include <osl/diagnose.h>
@@ -43,7 +42,7 @@ sal_Bool SAL_CALL osl_getSystemTime(TimeValue* TimeValue)
{
struct timeval tp;
- /* FIXME: use higher resolution */
+ /* FIXME: use higher resolution */
gettimeofday(&tp, NULL);
TimeValue->Seconds = tp.tv_sec;
@@ -60,11 +59,11 @@ sal_Bool SAL_CALL osl_getSystemTime(TimeValue* TimeValue)
sal_Bool SAL_CALL osl_getDateTimeFromTimeValue( TimeValue* pTimeVal,
oslDateTime* pDateTime )
{
struct tm *pSystemTime;
- struct tm tmBuf;
+ struct tm tmBuf;
time_t atime;
atime = (time_t)pTimeVal->Seconds;
-
+
/* Convert time from type time_t to struct tm */
pSystemTime = gmtime_r( &atime, &tmBuf );
@@ -79,7 +78,7 @@ sal_Bool SAL_CALL osl_getDateTimeFromTimeValue( TimeValue*
pTimeVal, oslDateTime
pDateTime->Day = pSystemTime->tm_mday;
pDateTime->DayOfWeek = pSystemTime->tm_wday;
pDateTime->Month = pSystemTime->tm_mon + 1;
- pDateTime->Year = pSystemTime->tm_year +
1900;
+ pDateTime->Year = pSystemTime->tm_year +
1900;
return sal_True;
}
@@ -105,51 +104,51 @@ sal_Bool SAL_CALL osl_getTimeValueFromDateTime(
oslDateTime* pDateTime, TimeValu
if ( pDateTime->Month > 0 )
aTime.tm_mon = pDateTime->Month - 1;
- else
+ else
return sal_False;
if ( pDateTime->Year >= 1900 )
aTime.tm_year = pDateTime->Year - 1900;
- else
+ else
return sal_False;
- aTime.tm_isdst = -1;
+ aTime.tm_isdst = -1;
aTime.tm_wday = 0;
aTime.tm_yday = 0;
/* Convert time to calendar value */
nSeconds = mktime( &aTime );
- /*
- * mktime expects the struct tm to be in local timezone, so we have to
adjust
- * the returned value to be timezone neutral.
- */
-
+ /*
+ * mktime expects the struct tm to be in local timezone, so we have to
adjust
+ * the returned value to be timezone neutral.
+ */
+
if ( nSeconds != (time_t) -1 )
{
- time_t bias;
-
+ time_t bias;
+
/* timezone corrections */
tzset();
#if defined(STRUCT_TM_HAS_GMTOFF)
- /* members of struct tm are corrected by mktime */
- bias = 0 - aTime.tm_gmtoff;
+ /* members of struct tm are corrected by mktime */
+ bias = 0 - aTime.tm_gmtoff;
#elif defined(HAS_ALTZONE)
- /* check if daylight saving time is in effect */
- bias = aTime.tm_isdst > 0 ? altzone : timezone;
+ /* check if daylight saving time is in effect */
+ bias = aTime.tm_isdst > 0 ? altzone : timezone;
#else
- /* exspect daylight saving time to be one hour */
- bias = aTime.tm_isdst > 0 ? timezone - 3600 : timezone;
+ /* expect daylight saving time to be one hour */
+ bias = aTime.tm_isdst > 0 ? timezone - 3600 : timezone;
#endif
-
- pTimeVal->Seconds = nSeconds;
+
+ pTimeVal->Seconds = nSeconds;
pTimeVal->Nanosec = pDateTime->NanoSeconds;
- if ( nSeconds > bias )
- pTimeVal->Seconds -= bias;
-
+ if ( nSeconds > bias )
+ pTimeVal->Seconds -= bias;
+
return sal_True;
}
@@ -162,25 +161,25 @@ sal_Bool SAL_CALL osl_getTimeValueFromDateTime(
oslDateTime* pDateTime, TimeValu
*--------------------------------------------------*/
sal_Bool SAL_CALL osl_getLocalTimeFromSystemTime( TimeValue* pSystemTimeVal,
TimeValue* pLocalTimeVal )
-{
- struct tm *pLocalTime;
- struct tm tmBuf;
- time_t bias;
+{
+ struct tm *pLocalTime;
+ struct tm tmBuf;
+ time_t bias;
time_t atime;
- atime = (time_t) pSystemTimeVal->Seconds;
- pLocalTime = localtime_r( &atime, &tmBuf );
+ atime = (time_t) pSystemTimeVal->Seconds;
+ pLocalTime = localtime_r( &atime, &tmBuf );
#if defined(STRUCT_TM_HAS_GMTOFF)
- /* members of struct tm are corrected by mktime */
- bias = 0 - pLocalTime->tm_gmtoff;
-
+ /* members of struct tm are corrected by mktime */
+ bias = 0 - pLocalTime->tm_gmtoff;
+
#elif defined(HAS_ALTZONE)
- /* check if daylight saving time is in effect */
- bias = pLocalTime->tm_isdst > 0 ? altzone : timezone;
+ /* check if daylight saving time is in effect */
+ bias = pLocalTime->tm_isdst > 0 ? altzone : timezone;
#else
- /* exspect daylight saving time to be one hour */
- bias = pLocalTime->tm_isdst > 0 ? timezone - 3600 : timezone;
+ /* expect daylight saving time to be one hour */
+ bias = pLocalTime->tm_isdst > 0 ? timezone - 3600 : timezone;
#endif
if ( (sal_Int64) pSystemTimeVal->Seconds > bias )
@@ -201,32 +200,32 @@ sal_Bool SAL_CALL osl_getLocalTimeFromSystemTime(
TimeValue* pSystemTimeVal, Tim
sal_Bool SAL_CALL osl_getSystemTimeFromLocalTime( TimeValue* pLocalTimeVal,
TimeValue* pSystemTimeVal )
{
struct tm *pLocalTime;
- struct tm tmBuf;
+ struct tm tmBuf;
time_t bias;
time_t atime;
- atime = (time_t) pLocalTimeVal->Seconds;
+ atime = (time_t) pLocalTimeVal->Seconds;
- /* Convert atime, which is a local time, to it's GMT equivalent. Then, get
- * the timezone offset for the local time for the GMT equivalent time. Note
- * that we cannot directly use local time to determine the timezone offset
- * because GMT is the only reliable time that we can determine timezone
- * offset from.
- */
+ /* Convert atime, which is a local time, to its GMT equivalent. Then,
get
+ * the timezone offset for the local time for the GMT equivalent time.
Note
+ * that we cannot directly use local time to determine the timezone
offset
+ * because GMT is the only reliable time that we can determine timezone
+ * offset from.
+ */
- atime = mktime( gmtime_r( &atime, &tmBuf ) );
- pLocalTime = localtime_r( &atime, &tmBuf );
+ atime = mktime( gmtime_r( &atime, &tmBuf ) );
+ pLocalTime = localtime_r( &atime, &tmBuf );
#if defined(STRUCT_TM_HAS_GMTOFF)
- /* members of struct tm are corrected by mktime */
- bias = 0 - pLocalTime->tm_gmtoff;
-
+ /* members of struct tm are corrected by mktime */
+ bias = 0 - pLocalTime->tm_gmtoff;
+
#elif defined(HAS_ALTZONE)
- /* check if daylight saving time is in effect */
- bias = pLocalTime->tm_isdst > 0 ? altzone : timezone;
+ /* check if daylight saving time is in effect */
+ bias = pLocalTime->tm_isdst > 0 ? altzone : timezone;
#else
- /* exspect daylight saving time to be one hour */
- bias = pLocalTime->tm_isdst > 0 ? timezone - 3600 : timezone;
+ /* expect daylight saving time to be one hour */
+ bias = pLocalTime->tm_isdst > 0 ? timezone - 3600 : timezone;
#endif
if ( (sal_Int64) pLocalTimeVal->Seconds + bias > 0 )
@@ -237,7 +236,7 @@ sal_Bool SAL_CALL osl_getSystemTimeFromLocalTime(
TimeValue* pLocalTimeVal, Time
return sal_True;
}
- return sal_False;
+ return sal_False;
}
@@ -247,19 +246,19 @@ static sal_Bool bGlobalTimer = sal_False;
sal_uInt32 SAL_CALL osl_getGlobalTimer()
{
- struct timeval currentTime;
- sal_uInt32 nSeconds;
-
- // FIXME: not thread safe !!
- if ( bGlobalTimer == sal_False )
- {
- gettimeofday( &startTime, NULL );
- bGlobalTimer=sal_True;
- }
-
- gettimeofday( ¤tTime, NULL );
-
- nSeconds = (sal_uInt32)( currentTime.tv_sec - startTime.tv_sec );
-
- return ( nSeconds * 1000 ) + (long) (( currentTime.tv_usec -
startTime.tv_usec) / 1000 );
+ struct timeval currentTime;
+ sal_uInt32 nSeconds;
+
+ // FIXME: not thread safe !!
+ if ( bGlobalTimer == sal_False )
+ {
+ gettimeofday( &startTime, NULL );
+ bGlobalTimer=sal_True;
+ }
+
+ gettimeofday( ¤tTime, NULL );
+
+ nSeconds = (sal_uInt32)( currentTime.tv_sec - startTime.tv_sec );
+
+ return ( nSeconds * 1000 ) + (long) (( currentTime.tv_usec -
startTime.tv_usec) / 1000 );
}