summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2009-09-16 14:37:52 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2009-09-16 14:37:52 +0000
commitc7788533a2565593405e55b617d09425e08ef439 (patch)
tree3f5e079ea8633edfe8fd37ec9a6fe40a0a4f952f /sal
parent36fc972942594e186e6924bfc1568bfb0096733e (diff)
CWS-TOOLING: integrate CWS sb113
2009-09-01 sb #i76393# second attempt at properly #ifdef-ing previous HG commit d598efdbf012 2009-08-28 sb #i102469# change back <T extends XInterface> to just <T> on queryInterface, to avoid binary incompatibility (method changing its signature from (Ljava/lang/Class;Ljava/lang/Object;)Ljava/lang/Object; to (Ljava/lang/Class;Ljava/lang/Object;)Lcom/sun/star/uno/XInterface;) 2009-08-28 sb #i76393# properly #ifdef previous HG commit d598efdbf012 2009-08-27 sb #i94421# work around compiler error (based on a patch supplied by cloph) 2009-08-26 sb merged in DEV300_m56 2009-08-26 sb #i76393# on Linux, include dynamic section offset in crash report so as to be able to map "prelinked" callstacks back to original (patch by cmc) 2009-08-26 sb #i88162# remove unnecessary whitespace lines from per-locale xcu files (patch by tora) 2009-08-17 Juergen Schmidt #i104292# set context classloader after create new custom UNO loader 2009-08-17 Juergen Schmidt #i103749# integrate patch 2009-08-14 sb #i103269# cherry-picked ssh://hg@hg.services.openoffice.org/cws/sb111 -r 5124ebd5edd1 ("#i101955# changed encoding of XML file content from erroneous ISO-8859-1 to UTF-8") 2009-08-12 sb #i102469# fixed mis-applications of UnoRuntime.queryInterface (detected via the simplified UnoRuntime.queryInterface, the HG changeset 29de35fc9554) to use AnyConverter instead; changed qadevOOo's lib.MultiMethodTest.before to allow throwing arbitrary exceptions, to cater for IllegalArgumentException thrown by AnyConverter 2009-08-12 sb #i104178# drop extra libxml2-config script from libxmlsec 2009-08-10 sb #i101754# simplified osl_getProcessInfo for LINUX (patch by cmc) 2009-08-10 sb #i95018# avoid closing -1 fds (patch supplied by cmc) 2009-08-10 sb #i103585# removed (apparently unnecessary) zlib support from libxml2; in turn, removed zlib dependencies from libxmlsec, libxslt, and redland (assuming those were transitive dependencies brought in by direct dependencies on libxml2) 2009-08-10 sb #i102469# simplified UnoRuntime.queryInterface using Java 5 generics; adapted URE-related modules accordingly 2009-08-10 sb #i101213# adapted setsolar env (solenv/config/) to set PYTHONPATH (and not set PYTHONHOME) in accordance with configure env (set_soenv.in); fixed testtools/source/bridgetest/pyuno (which now should work everywhere out of the box, thanks to the fixed setsolar PYTHONPATH) 2009-08-10 sb cherry-picked ssh://hg@hg.services.openoffice.org/cws/sb111 -r ea8de6d9396b ("#i101955# work in progress for a .hgignore file, continued")
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/process.c173
-rw-r--r--sal/osl/unx/signal.c92
2 files changed, 164 insertions, 101 deletions
diff --git a/sal/osl/unx/process.c b/sal/osl/unx/process.c
index e5faf46548a6..a1f47cdf76a5 100644
--- a/sal/osl/unx/process.c
+++ b/sal/osl/unx/process.c
@@ -466,7 +466,7 @@ static void ChildStatusProc(void *pData)
if ((pid = fork()) == 0)
{
/* Child */
- 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())))
{
@@ -500,32 +500,32 @@ static void ChildStatusProc(void *pData)
/* Connect std IO to pipe ends */
/* Write end of stdInput not used in child process */
- close( stdInput[1] );
+ if (stdInput[1] != -1) close( stdInput[1] );
/* Read end of stdOutput not used in child process */
- close( stdOutput[0] );
+ if (stdOutput[0] != -1) close( stdOutput[0] );
/* Read end of stdError not used in child process */
- close( stdError[0] );
+ if (stdError[0] != -1) close( stdError[0] );
/* Redirect pipe ends to std IO */
if ( stdInput[0] != STDIN_FILENO )
{
dup2( stdInput[0], STDIN_FILENO );
- close( stdInput[0] );
+ if (stdInput[0] != -1) close( stdInput[0] );
}
if ( stdOutput[1] != STDOUT_FILENO )
{
dup2( stdOutput[1], STDOUT_FILENO );
- close( stdOutput[1] );
+ if (stdOutput[1] != -1) close( stdOutput[1] );
}
if ( stdError[1] != STDERR_FILENO )
{
dup2( stdError[1], STDERR_FILENO );
- close( stdError[1] );
+ if (stdError[1] != -1) close( stdError[1] );
}
pid=execv(data.m_pszArgs[0], (sal_Char **)data.m_pszArgs);
@@ -539,7 +539,7 @@ static void ChildStatusProc(void *pData)
/* if we reach here, something went wrong */
write(channel[1], &errno, sizeof(errno));
- close(channel[1]);
+ if (channel[1] != -1) close(channel[1]);
_exit(255);
}
@@ -547,12 +547,12 @@ static void ChildStatusProc(void *pData)
{ /* Parent */
int status;
- close(channel[1]);
+ if (channel[1] != -1) close(channel[1]);
/* Close unused pipe ends */
- close( stdInput[0] );
- close( stdOutput[1] );
- close( stdError[1] );
+ if (stdInput[0] != -1) close( stdInput[0] );
+ if (stdOutput[1] != -1) close( stdOutput[1] );
+ if (stdError[1] != -1) close( stdError[1] );
while (((i = read(channel[0], &status, sizeof(status))) < 0))
{
@@ -560,7 +560,7 @@ static void ChildStatusProc(void *pData)
break;
}
- close(channel[0]);
+ if (channel[0] != -1) close(channel[0]);
if ((pid > 0) && (i == 0))
@@ -646,9 +646,9 @@ static void ChildStatusProc(void *pData)
if ( pdata->m_pErrorRead )
*pdata->m_pErrorRead = NULL;
- close( stdInput[1] );
- close( stdOutput[0] );
- close( stdError[0] );
+ if (stdInput[1] != -1) close( stdInput[1] );
+ 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
@@ -1124,15 +1124,6 @@ struct osl_procStat
unsigned long nswap; /* ? */
unsigned long cnswap; /* ? */
- /* from 'statm' */
- long size; /* numbers of pages in memory */
- long resident; /* number of resident pages */
- long share; /* number of shared pages */
- long trs; /* text resident size */
- long lrs; /* library resident size */
- long drs; /* data resident size */
- long dt; /* ditry pages */
-
/* from 'status' */
int ruid; /* real uid */
int euid; /* effective uid */
@@ -1155,9 +1146,10 @@ struct osl_procStat
osl_getProcStat
*********************************************/
-void osl_getProcStat(pid_t pid, struct osl_procStat* procstat)
+sal_Bool osl_getProcStat(pid_t pid, struct osl_procStat* procstat)
{
int fd = 0;
+ sal_Bool bRet = sal_False;
char name[PATH_MAX + 1];
snprintf(name, sizeof(name), "/proc/%u/stat", pid);
@@ -1166,11 +1158,13 @@ void osl_getProcStat(pid_t pid, struct osl_procStat* procstat)
char* tmp=0;
char prstatbuf[512];
memset(prstatbuf,0,512);
- read(fd,prstatbuf,511);
+ bRet = read(fd,prstatbuf,511) == 511;
close(fd);
/*printf("%s\n\n",prstatbuf);*/
+ if (!bRet)
+ return sal_False;
tmp = strrchr(prstatbuf, ')');
*tmp = '\0';
@@ -1198,57 +1192,35 @@ void osl_getProcStat(pid_t pid, struct osl_procStat* procstat)
&procstat->wchan, &procstat->nswap, &procstat->cnswap
);
}
-}
-
-/**********************************************
- osl_getProcStatm
- *********************************************/
-
-void osl_getProcStatm(pid_t pid, struct osl_procStat* procstat)
-{
- int fd = 0;
- char name[PATH_MAX + 1];
- snprintf(name, sizeof(name), "/proc/%u/statm", pid);
-
- if ((fd = open(name,O_RDONLY)) >=0 )
- {
- char prstatmbuf[512];
- memset(prstatmbuf,0,512);
- read(fd,prstatmbuf,511);
-
- close(fd);
-
- /* printf("\n\n%s\n\n",prstatmbuf);*/
-
- sscanf(prstatmbuf,"%li %li %li %li %li %li %li",
- &procstat->size, &procstat->resident, &procstat->share,
- &procstat->trs, &procstat->lrs, &procstat->drs,
- &procstat->dt
- );
- }
+ return bRet;
}
/**********************************************
osl_getProcStatus
*********************************************/
-void osl_getProcStatus(pid_t pid, struct osl_procStat* procstat)
+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;
+
if ((fd = open(name,O_RDONLY)) >=0 )
{
char* tmp=0;
char prstatusbuf[512];
memset(prstatusbuf,0,512);
- read(fd,prstatusbuf,511);
+ bRet = read(fd,prstatusbuf,511) == 511;
close(fd);
/* printf("\n\n%s\n\n",prstatusbuf);*/
+ if (!bRet)
+ return sal_False;
+
tmp = strstr(prstatusbuf,"Uid:");
if(tmp)
{
@@ -1290,6 +1262,7 @@ void osl_getProcStatus(pid_t pid, struct osl_procStat* procstat)
);
}
}
+ return bRet;
}
#endif
@@ -1439,56 +1412,54 @@ oslProcessError SAL_CALL osl_getProcessInfo(oslProcess Process, oslProcessData F
#elif defined(LINUX)
-/* int fd = 0;*/
- struct osl_procStat procstat;
- memset(&procstat,0,sizeof(procstat));
+ if ( (Fields & osl_Process_CPUTIMES) || (Fields & osl_Process_HEAPUSAGE) )
+ {
+ struct osl_procStat procstat;
+ memset(&procstat,0,sizeof(procstat));
- osl_getProcStat(pid, &procstat);
- osl_getProcStatm(pid, &procstat);
- osl_getProcStatus(pid, &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;
- if ( Fields & osl_Process_CPUTIMES)
- {
- /*
- * 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;
- 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->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;
+ }
- 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;
- if (Fields & osl_Process_HEAPUSAGE)
- {
- /*
- * 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;
+ pInfo->Fields |= osl_Process_HEAPUSAGE;
+ }
}
return (pInfo->Fields == Fields) ? osl_Process_E_None : osl_Process_E_Unknown;
diff --git a/sal/osl/unx/signal.c b/sal/osl/unx/signal.c
index 77633dd81269..35884e11c9ba 100644
--- a/sal/osl/unx/signal.c
+++ b/sal/osl/unx/signal.c
@@ -46,6 +46,7 @@
#ifdef LINUX
#include <execinfo.h>
+#include <link.h>
#define INCLUDE_BACKTRACE
#define STACKTYPE "Linux"
#endif
@@ -392,6 +393,88 @@ static int fputs_xml( const char *string, FILE *stream )
#define REPORTENV_PARAM "-crashreportenv:"
+#if defined SAL_ENABLE_CRASH_REPORT && defined INCLUDE_BACKTRACE && \
+ defined LINUX
+
+typedef struct
+{
+ const char *name;
+ ElfW(Off) offset;
+} dynamic_entry;
+
+static int
+callback(struct dl_phdr_info *info, size_t size, void *data)
+{
+ const ElfW(Phdr) *pDynamic = NULL;
+
+ if (size == sizeof(struct dl_phdr_info))
+ {
+ int i;
+ for (i = 0; i < info->dlpi_phnum; ++i)
+ {
+ if (info->dlpi_phdr[i].p_type == PT_DYNAMIC)
+ {
+ pDynamic = &(info->dlpi_phdr[i]);
+ break;
+ }
+ }
+ }
+
+ if (pDynamic)
+ {
+ char buffer[100];
+ int len;
+ char exe[PATH_MAX];
+ const char *dsoname = info->dlpi_name;
+
+ dynamic_entry* entry = (dynamic_entry*)data;
+
+ if (strcmp(dsoname, "") == 0)
+ {
+ snprintf(buffer, sizeof(buffer), "/proc/%d/exe", getpid());
+ if ((len = readlink(buffer, exe, PATH_MAX)) != -1)
+ {
+ exe[len] = '\0';
+ dsoname = exe;
+ }
+ }
+
+ if (strcmp(dsoname, entry->name) == 0)
+ {
+ entry->offset = pDynamic->p_offset;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/* Get the location of the .dynamic section offset for the given elf file.
+ * i.e. same as the "Offset" value shown for DYNAMIC from readelf -l foo
+ *
+ * We want to know this value so that if the binaries have been modifed
+ * by prelink then we can still process the call stack on server side
+ * by comparing this value to that of an "un-prelinked but known to be
+ * otherwise equivalent" version of those binaries and adjust the call
+ * stack addresses by the differences between .dynamic addresses so as
+ * to be able to map the prelinked addresses back to the unprelinked
+ * addresses
+ *
+ * cmc@openoffice.org
+ */
+static ElfW(Off)
+dynamic_section_offset(const char *name)
+{
+ dynamic_entry entry;
+
+ entry.name = name;
+ entry.offset = 0;
+
+ dl_iterate_phdr(callback, &entry);
+
+ return entry.offset;
+}
+#endif
+
static int ReportCrash( int Signal )
{
#ifdef SAL_ENABLE_CRASH_REPORT
@@ -572,6 +655,11 @@ static int ReportCrash( int Signal )
if ( dl_info.dli_fbase && dl_info.dli_fname )
{
+#ifdef LINUX
+ ElfW(Off) dynamic_offset = dynamic_section_offset(dl_info.dli_fname);
+ fprintf( stackout, " 0x%" SAL_PRI_SIZET "x:", dynamic_offset);
+#endif
+
fprintf( stackout, " %s + 0x%" SAL_PRI_PTRDIFFT "x",
dl_info.dli_fname,
(char*)stackframes[iFrame] - (char*)dl_info.dli_fbase
@@ -583,6 +671,10 @@ static int ReportCrash( int Signal )
if ( dli_fdir )
fprintf( xmlout, " path=\"%s\"", dli_fdir );
+
+#ifdef LINUX
+ fprintf( xmlout, " dynamicoffset=\"0x%" SAL_PRI_SIZET "x\"", dynamic_offset );
+#endif
}
else
fprintf( stackout, " ????????" );