summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRüdiger Timm <rt@openoffice.org>2004-10-28 15:25:13 +0000
committerRüdiger Timm <rt@openoffice.org>2004-10-28 15:25:13 +0000
commit5a76578ad8bcc7a457181135c14c3b66ba745e6b (patch)
tree1731b82759e6efe16c0d489a9ec2d750393d3b51
parentf6c285bb55b79dd187222c6e3c568210177d127a (diff)
INTEGRATION: CWS valgrind02 (1.34.70); FILE MERGED
2004/10/08 15:53:24 mhu 1.34.70.1: #i35209# Added function 'osl_setCommandArgs()', adapted 'osl_getExecutableFile()' and 'osl_getCommandArg[Count]()', cleaned up previous 'getCmdLine()' mess, removed unused / obsolete code.
-rw-r--r--sal/osl/unx/process.c627
1 files changed, 5 insertions, 622 deletions
diff --git a/sal/osl/unx/process.c b/sal/osl/unx/process.c
index 594c1f21bbd8..ac909086e0c2 100644
--- a/sal/osl/unx/process.c
+++ b/sal/osl/unx/process.c
@@ -2,9 +2,9 @@
*
* $RCSfile: process.c,v $
*
- * $Revision: 1.34 $
+ * $Revision: 1.35 $
*
- * last change: $Author: rt $ $Date: 2004-03-30 16:29:19 $
+ * last change: $Author: rt $ $Date: 2004-10-28 16:25:13 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -63,7 +63,6 @@
/*
* ToDo:
* - cleanup of process status things
- * - cleanup/reimplementation of argument stuff
* - cleanup of process spawning
* - cleanup of resource transfer
*/
@@ -125,10 +124,6 @@
extern oslFileError FileURLToPath( char *, size_t, rtl_uString* );
extern oslFileHandle osl_createFileHandleFromFD( int fd );
-
-extern void _imp_getProcessLocale( rtl_Locale ** );
-extern int _imp_setProcessLocale( rtl_Locale * );
-
/******************************************************************************
*
* Data Type Definition
@@ -168,8 +163,6 @@ typedef struct _oslPipeImpl {
*
*****************************************************************************/
-extern sal_Char *getCmdLine();
-
oslProcessError SAL_CALL osl_psz_executeProcess(sal_Char *pszImageName,
sal_Char *pszArguments[],
oslProcessOption Options,
@@ -190,354 +183,16 @@ oslProcessError SAL_CALL osl_searchPath_impl(
sal_uInt32 Max);
-oslProcessError SAL_CALL osl_psz_getExecutableFile(sal_Char* pszBuffer, sal_uInt32 Max);
sal_Bool osl_getFullPath(const sal_Char* pszFilename, sal_Char* pszPath, sal_uInt32 MaxLen);
-oslProcessError SAL_CALL osl_psz_getEnvironment(const sal_Char* pszName, sal_Char *pszBuffer, sal_uInt32 Max);
-oslProcessError SAL_CALL osl_getCommandArgs(sal_Char* pszBuffer, sal_uInt32 Max);
-
static oslProcessImpl* ChildList;
static oslMutex ChildListMutex;
-static sal_Char CmdLine[CMD_ARG_MAX + 1] = "";
-static int nArgCount = -1;
-
-
-/******************************************************************************
- *
- * Functions for command args
- *
- *****************************************************************************/
-
-#if defined(MACOSX)
-/* Can't access environ and __progname directly when linking two-level. */
-sal_Char *getCmdLine()
-{
- int i;
- int len = 0;
- sal_Char *result;
- int the_argc = *_NSGetArgc();
- char **the_argv = *_NSGetArgv();
-
- for (i = 0; i < the_argc; i++) {
- len += 1 + strlen(the_argv[i]);
- }
-
- result = calloc(len + 1, sizeof(sal_Char));
- if (result) {
- sal_Char *dst = result;
- for (i = 0; i < the_argc; i++) {
- strcpy(dst, the_argv[i]);
- dst += 1 + strlen(the_argv[i]);
- }
- *dst = '\0';
- return result;
- }
-
- return NULL;
-}
-
-#endif
-
-#if defined(CMD_ARG_PRG) && defined(CMD_ARG_ENV)
-/*
- * mfe: used by FreeBSD, NetBSD, HP-UX, IRIX
- * (and which other Unix flavours?)
- */
-sal_Char *getCmdLine()
-{
- /* Memory layout of CMD_ARG_PRG:
- progname\0arg1\0...argn[\0]\0environ\0env2\0...envn\0[\0] */
-
-#if !defined(NETBSD) && !defined(FREEBSD)
- extern sal_Char* CMD_ARG_PRG;
-#endif
- extern sal_Char** CMD_ARG_ENV;
-
- int n = *(CMD_ARG_ENV) - (CMD_ARG_PRG);
- sal_Char *pchr;
-
- if (pchr = calloc(n + 1, sizeof(sal_Char)))
- {
- memcpy(pchr,(CMD_ARG_PRG), n);
- pchr[n] = '\0';
- return pchr;
- }
-
- return NULL;
-}
-#endif
-
-#if !defined (CMD_ARG_PRG) && defined (CMD_ARG_ENV)
-/*
- * mfe: not used ???
- */
-extern sal_Char** CMD_ARG_ENV;
-static sal_Char* pEnviron;
-
-/* The environment pointer has to be saved away early because
- * any putenv() may change it. The next line works for GCC on any
- * ELF platform.
- */
-
-static void saveEnviron(void) __attribute__((constructor));
-
-static void saveEnviron(void)
-{
- pEnviron = CMD_ARG_ENV;
-}
-
-sal_Char *getCmdLine()
-{
- sal_Char **pArgs = pEnviron;
- sal_Char *pChr;
- size_t n;
-
- pArgs--;
- while(*(--pArgs));
- pArgs += 2; /* skip NULL and pointer to number of args */
-
- n = *(CMD_ARG_ENV) - *(pArgs);
-
- if (pChr = calloc(n + 1, sizeof(sal_Char))) {
- memcpy(pChr,*pArgs, n);
- pChr[n] = '\0';
- return pChr;
- }
- return (NULL);
-}
-#endif
-
-#ifdef CMD_ARG_PROC_STREAM
-/*
- * mfe: this is for Linux
- * (and which other Unix flavours?)
- */
-sal_Char *getCmdLine()
-{
- FILE *fp;
- sal_Char name[PATH_MAX + 1];
-
- name[0] = '\0';
-
- snprintf(name, sizeof(name), CMD_ARG_PROC_NAME, getpid());
-
- if ( (fp = fopen(name, "r")) != 0 )
- {
- int c;
- int i = 0, n = 32;
- sal_Char *pchr = (sal_Char*) calloc(n, sizeof(sal_Char));
-
- while ((c = getc(fp)) != EOF)
- {
- if (i >= (n - 2))
- pchr = (sal_Char*) realloc(pchr, (n += 32) * sizeof(sal_Char));
-
- pchr[i++] = c;
- }
-
- pchr[i] = pchr[i + 1] = '\0';
-
- fclose(fp);
-
- return (pchr);
- }
-
- return (NULL);
-}
-#endif
-
-#ifdef CMD_ARG_PROC_IOCTL
-/*
- * mfe: this is for Solaris
- * (and which other Unix flavours?)
- */
-
-sal_Char *getCmdLine()
-{
- int fd;
- sal_Char name[PATH_MAX + 1];
- sal_Char *pchr=0;
-
- name[0] = '\0';
-
- snprintf(name, sizeof(name), CMD_ARG_PROC_NAME, getpid());
-
- if ((fd = open(name, O_RDONLY)) >= 0)
- {
- CMD_ARG_PROC_TYPE psinfo;
-
- if (ioctl(fd, CMD_ARG_PROC_IOCTL, &psinfo) >= 0)
- {
- int j, i = 0, n = 32;
- pchr = (sal_Char*) calloc(n, sizeof(sal_Char));
-
- if (CMD_ARG_PROC_ARGC(psinfo) > 0)
- for (j = 0; j < CMD_ARG_PROC_ARGC(psinfo) , CMD_ARG_PROC_ARGV(psinfo)[j] != 0 ; j++)
- {
- int l = strlen(CMD_ARG_PROC_ARGV(psinfo)[j]);
-
- if (i + l >= (n - 2))
- pchr = (sal_Char*) realloc(pchr, (n += l + 32) * sizeof(sal_Char));
-
- strcpy(&pchr[i], CMD_ARG_PROC_ARGV(psinfo)[j]);
-
- i += l;
- pchr[i++] = '\0';
- }
- else
- pchr[i++] = '\0';
-
- pchr[i] = '\0';
- }
-
- close(fd);
- }
-
- return (pchr);
-}
-#endif
-
-#ifdef CMD_ARG_PS
-/*
- * mfe : this is for AIX
- * (and which other Unix flavours?)
- */
-
-sal_Char *getCmdLine()
-{
- FILE *fp;
- sal_Char cmd[CMD_ARG_MAX + 1];
- int i;
-
- cmd[0] = '\0';
-
- snprintf(cmd, sizeof(cmd), CMD_ARG_PS, getpid());
-
- if (fp = popen(cmd, "r"))
- {
- int c;
- int i = 0, n = 32;
- sal_Bool sep = sal_True;
- sal_Char *pchr = calloc(n, sizeof(sal_Char));
-
- while ((c = getc(fp)) != EOF)
- {
- if (i >= (n - 2))
- pchr = realloc(pchr, (n += 32) * sizeof(sal_Char));
-
- if (! isspace(c))
- {
- pchr[i++] = c;
- sep = sal_False;
- }
- else
- if (! sep)
- {
- pchr[i++] = '\0';
- sep = sal_True;
- }
- }
-
- pchr[i] = pchr[i + 1] = '\0';
-
- fclose(fp);
-
- return (pchr);
- }
-
- return (NULL);
-}
-#endif
-
-/*******************************************************************
- !!! Working on byte strings is dangerous because of MBCS see
- #104563.
- Don't fix this function because it is only used in profile.c and
- profiles are deprecated
- ******************************************************************/
-
-oslProcessError SAL_CALL osl_psz_getExecutableFile(sal_Char* pszBuffer, sal_uInt32 Max)
-{
- const char * pszCmdLine = getCmdLine();
- const char * pszRealPathSrc = pszCmdLine;
- char szAbsolutePath[PATH_MAX] = "";
- char szRealPathBuf[PATH_MAX] = "";
-
- if( pszCmdLine == NULL ) {
- return osl_Process_E_None;
- }
-
- /* if the command line argument #0 starts with a '/', this program has been */
- /* invoked using a full qualified path */
- if( '/' != pszCmdLine[0] )
- {
- oslProcessError ret = osl_Process_E_None;
-
- /* if the command line argument #0 contains a '/' somewhere else, it has */
- /* been probably invoked relatively to the current working directory */
- if( strchr(pszCmdLine, '/') )
- {
- if( NULL != getcwd(szAbsolutePath, sizeof(szAbsolutePath)) )
- {
- size_t n = PATH_MAX - strlen(szAbsolutePath);
- size_t n2 = strlen(pszCmdLine);
-
- /* check remaining size and append '/' and argument #0 is possible */
- if( n + n2 + 1 < PATH_MAX )
- {
- szAbsolutePath[n] = '/';
- strncpy(szAbsolutePath+n+1, pszCmdLine, n2+1);
-
- /* replace the original pszRealPathSrc pointer */
- pszRealPathSrc = szAbsolutePath;
- }
- }
- }
- /* this program must be in the PATH variable */
- else
- {
- ret = osl_searchPath_impl(pszCmdLine, NULL, '\0', szAbsolutePath, sizeof(szAbsolutePath));
- if( osl_Process_E_None == ret )
- {
- /* replace the original pszRealPathSrc pointer */
- pszRealPathSrc = szAbsolutePath;
- }
- }
-
- /* if szAbsolutePath has not been filled, return with an error */
- if( '\0' == szAbsolutePath[0] )
- {
- ret = osl_Process_E_Unknown;
- }
-
- if( osl_Process_E_None != ret )
- {
- free((void *) pszCmdLine);
- return ret;
- }
- }
-
- /* get the realpath of the resulting file and convert it to a file URL */
- if( NULL != realpath(pszRealPathSrc, szRealPathBuf) && strlen(szRealPathBuf) < Max )
- {
- strcpy(pszBuffer, szRealPathBuf);
- }
- else
- {
- free((void *)pszCmdLine);
- return osl_Process_E_Unknown;
- }
-
- free((void *) pszCmdLine);
- return osl_Process_E_None;
-}
-
/******************************************************************************
Deprecated
- Old and buggy implementation of osl_searchPath used only by the deprected
- osl_psz_getExecutableName.
- A new implemenation is in process_impl.cxx
+ Old and buggy implementation of osl_searchPath used only by
+ osl_psz_executeProcess.
+ A new implemenation is in file_path_helper.cxx
*****************************************************************************/
oslProcessError SAL_CALL osl_searchPath_impl(const sal_Char* pszName, const sal_Char* pszPath,
@@ -600,146 +255,6 @@ oslProcessError SAL_CALL osl_searchPath_impl(const sal_Char* pszName, const sal_
return osl_Process_E_NotFound;
}
-/**********************************************
- osl_getCommandArgCount
- *********************************************/
-
-sal_uInt32 SAL_CALL osl_getCommandArgCount()
-{
- sal_Char pszBuffer[CMD_ARG_MAX+1];
-
- oslProcessError tErr = osl_Process_E_Unknown;
-
- pszBuffer[0] = '\0';
-
- if ( nArgCount == -1 )
- {
- tErr = osl_getCommandArgs(pszBuffer, sizeof(pszBuffer));
-
- if ( tErr != osl_Process_E_None)
- {
- return 0;
- }
- }
-
- /* fprintf(stderr,"osl_getCommandArgCount : ArgCount = '%i'\n",nArgCount);*/
-
- return nArgCount;
-}
-
-/**********************************************
- osl_getCommandArg
- *********************************************/
-
-oslProcessError SAL_CALL osl_getCommandArg( sal_uInt32 nArg, rtl_uString **strCommandArg)
-{
- oslProcessError tErr = osl_Process_E_Unknown;
- sal_Char* pChr=0;
-
- if ( nArgCount == -1 )
- {
- sal_Char pBuffer[CMD_ARG_MAX+1];
- pBuffer[0] = '\0';
-
- tErr = osl_getCommandArgs(pBuffer, CMD_ARG_MAX+1);
- if ( tErr == osl_Process_E_None )
- {
- return tErr;
- }
- }
-
-/* fprintf(stderr,"osl_getCommandArg : getting Arg No. '%i'\n",nArg); */
-
-/* nArg++;*/
-
- if ( nArg >= 0 && nArg < nArgCount )
- {
- int nIndex=0;
- int nLen;
-
- pChr=CmdLine;
-
- while ( nArg != nIndex && nIndex < nArgCount )
- {
-/* fprintf(stderr,"Having arg '%i' '%s'\n",nIndex,pChr); */
- nLen = strlen(pChr);
- pChr+=nLen+1;
- ++nIndex;
- }
-/* fprintf(stderr,"osl_getCommandArg : Arg '%i' = '%s'\n",nIndex,pChr); */
-
- rtl_string2UString(
- strCommandArg,
- pChr,
- rtl_str_getLength( pChr ),
- osl_getThreadTextEncoding(),
- OUSTRING_TO_OSTRING_CVTFLAGS );
- OSL_ASSERT(*strCommandArg != NULL);
-
- tErr=osl_Process_E_None;
- }
-
- return tErr;
-}
-
-/**********************************************
- osl_getCommandArgs
- *********************************************/
-
-oslProcessError SAL_CALL osl_getCommandArgs(sal_Char* pszBuffer, sal_uInt32 Max)
-{
- static int CmdLen = -1;
-
- if (CmdLen < 0)
- {
- sal_Char *pszCmdLine = getCmdLine();
- sal_Char *pStr = pszCmdLine;
- sal_Char *pBuffer = CmdLine;
-
- OSL_ASSERT(pszCmdLine != NULL);
-
- if ( pszCmdLine == 0 )
- {
- return osl_Process_E_Unknown;
- }
-
- nArgCount=0;
-
- /* skip program name */
- pStr += strlen(pStr) + 1;
-
- while ((*pStr != '\0') &&
- ((pBuffer + strlen(pszCmdLine)) < (CmdLine + sizeof(CmdLine) - 2)))
- {
- strcpy(pBuffer, pStr);
- pBuffer += strlen(pStr) + 1;
- pStr += strlen(pStr) + 1;
- ++nArgCount;
- }
-
- *pBuffer++ = '\0';
-
- CmdLen = pBuffer - CmdLine;
- free(pszCmdLine);
- }
-
- OSL_ASSERT(pszBuffer);
-
- if ( pszBuffer == 0 )
- {
- return osl_Process_E_Unknown;
- }
-
- if (Max < (sal_uInt32)CmdLen)
- return osl_Process_E_Unknown;
-
-/* fprintf(stderr,"osl_getCommandArgs : ArgCount is '%i'\n",nArgCount); */
-
- memcpy(pszBuffer, CmdLine, CmdLen);
-
- return osl_Process_E_None;
-}
-
/******************************************************************************
*
* New io resource transfer functions
@@ -2086,135 +1601,3 @@ oslProcessError SAL_CALL osl_joinProcess(oslProcess Process)
{
return osl_joinProcessWithTimeout(Process, NULL);
}
-
-
-/******************************************************************************
- *
- * Functions for the environment
- *
- *****************************************************************************/
-
-oslProcessError SAL_CALL osl_getEnvironment(rtl_uString* pustrEnvVar, rtl_uString** ppustrValue)
-{
- rtl_String* pstr_env_var = 0;
- char* p_env_var;
- oslProcessError osl_error = osl_Process_E_NotFound;
-
- OSL_PRECOND(pustrEnvVar, "osl_getEnvironment: Invalid parameter");
- OSL_PRECOND(ppustrValue, "osl_getEnvironment: Invalid parameter");
-
- rtl_uString2String(
- &pstr_env_var,
- rtl_uString_getStr(pustrEnvVar),
- rtl_uString_getLength(pustrEnvVar),
- osl_getThreadTextEncoding(),
- OUSTRING_TO_OSTRING_CVTFLAGS);
-
- if ((p_env_var = getenv(rtl_string_getStr(pstr_env_var))))
- {
- rtl_string2UString(
- ppustrValue,
- p_env_var,
- strlen(p_env_var),
- osl_getThreadTextEncoding(),
- OSTRING_TO_OUSTRING_CVTFLAGS);
- OSL_ASSERT(*ppustrValue != NULL);
-
- osl_error = osl_Process_E_None;
- }
-
- rtl_string_release(pstr_env_var);
-
- return osl_error;
-}
-
-
-/******************************************************************************
- *
- * new function to return the process working dir
- *
- *****************************************************************************/
-
-oslProcessError SAL_CALL osl_getProcessWorkingDir(rtl_uString **ppustrWorkingDir)
-{
- oslProcessError osl_error = osl_Process_E_Unknown;
- char buffer[PATH_MAX];
-
- OSL_PRECOND(ppustrWorkingDir, "osl_getProcessWorkingDir: invalid parameter");
-
- if (getcwd(buffer, PATH_MAX))
- {
- rtl_uString* ustrTmp = NULL;
-
- rtl_string2UString(
- &ustrTmp,
- buffer,
- strlen(buffer),
- osl_getThreadTextEncoding(),
- OSTRING_TO_OUSTRING_CVTFLAGS);
- OSL_ASSERT(ustrTmp != NULL);
-
- if (osl_getFileURLFromSystemPath(ustrTmp, ppustrWorkingDir) == osl_File_E_None)
- osl_error = osl_Process_E_None;
-
- rtl_uString_release(ustrTmp);
- }
- return osl_error;
-}
-
-/******************************************************************************
- *
- * new functions to set/return the current process locale
- *
- *****************************************************************************/
-
-static rtl_Locale * theProcessLocale = NULL;
-static pthread_mutex_t aLocalMutex = PTHREAD_MUTEX_INITIALIZER;
-
-/**********************************************
- osl_getProcessLocale
- *********************************************/
-
-oslProcessError SAL_CALL osl_getProcessLocale( rtl_Locale ** ppLocale )
-{
- OSL_ASSERT( ppLocale );
-
- /* basic thread safeness */
- pthread_mutex_lock( &aLocalMutex );
-
- if( NULL == theProcessLocale )
- _imp_getProcessLocale( &theProcessLocale );
-
- *ppLocale = theProcessLocale;
-
- pthread_mutex_unlock( &aLocalMutex );
-
- return osl_Process_E_None;
-}
-
-/**********************************************
- osl_setProcessLocale
- *********************************************/
-
-oslProcessError SAL_CALL osl_setProcessLocale( rtl_Locale * pLocale )
-{
- oslProcessError ret = osl_Process_E_Unknown;
-
- OSL_ASSERT( pLocale );
-
- /* basic thread safeness */
- pthread_mutex_lock( &aLocalMutex );
-
- /* try to set the new locale */
- if( 0 == _imp_setProcessLocale( pLocale ) )
- {
- theProcessLocale = pLocale;
- ret = osl_Process_E_None;
- }
-
- pthread_mutex_unlock( &aLocalMutex );
-
- return ret;
-}
-
-