[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash configure.ac utilities/dumpshm.cpp
From: |
Rob Savoye |
Subject: |
[Gnash-commit] gnash configure.ac utilities/dumpshm.cpp |
Date: |
Sun, 30 Dec 2007 05:23:38 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Rob Savoye <rsavoye> 07/12/30 05:23:38
Modified files:
. : configure.ac
utilities : dumpshm.cpp
Log message:
* utilities/dumpshm.cpp: Add support to search through all sysv
style shared memory segments and look for the LocalConnection
one so the user doesn't have to know anything to find it.
* configure.ac: Add test for the key field of ipc_perm data
structure used by shmctl() to get the key.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/configure.ac?cvsroot=gnash&r1=1.463&r2=1.464
http://cvs.savannah.gnu.org/viewcvs/gnash/utilities/dumpshm.cpp?cvsroot=gnash&r1=1.16&r2=1.17
Patches:
Index: configure.ac
===================================================================
RCS file: /sources/gnash/gnash/configure.ac,v
retrieving revision 1.463
retrieving revision 1.464
diff -u -b -r1.463 -r1.464
--- configure.ac 26 Dec 2007 01:11:07 -0000 1.463
+++ configure.ac 30 Dec 2007 05:23:37 -0000 1.464
@@ -15,7 +15,7 @@
dnl Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
dnl
-dnl $Id: configure.ac,v 1.463 2007/12/26 01:11:07 rsavoye Exp $
+dnl $Id: configure.ac,v 1.464 2007/12/30 05:23:37 rsavoye Exp $
AC_PREREQ(2.50)
AC_INIT(gnash, cvs)
@@ -1095,6 +1095,29 @@
AC_DEFINE(HAVE_STRINGCASECMP, [1], [Has strcasecmp])
)
+dnl See if ipc_perm structure has the ipc_perm.key field, and if so,
+dnl which variant of the name is used.
+ipc_key=no
+AC_TRY_COMPILE([
+ #include <sys/ipc.h>
+ #include <sys/shm.h>], [
+ struct shmid_ds shmseg;
+ key_t x = shmseg.shm_perm.key;],
+ ipc_key=yes
+ AC_DEFINE(IPC_PERM_KEY, [key], [Has the key field in ipc_perm])
+)
+
+if test x$ipc_key = xno; then
+ AC_TRY_COMPILE([
+ #include <sys/ipc.h>
+ #include <sys/shm.h>], [
+ struct shmid_ds shmseg;
+ key_t x = shmseg.shm_perm.__key;],
+ AC_DEFINE(IPC_PERM_KEY, [__key], [Has the key field in ipc_perm])
+ ipc_key=yes
+ )
+fi
+
dnl AC_CHECK_FUNCS(strcasecmp stricmp)
AC_CHECK_FUNCS(vsnprintf)
dnl AC_CHECK_FUNCS(finite isfinite)
Index: utilities/dumpshm.cpp
===================================================================
RCS file: /sources/gnash/gnash/utilities/dumpshm.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- utilities/dumpshm.cpp 22 Dec 2007 23:26:56 -0000 1.16
+++ utilities/dumpshm.cpp 30 Dec 2007 05:23:38 -0000 1.17
@@ -23,7 +23,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
-
+#include <cerrno>
extern "C"{
#include <unistd.h>
@@ -67,6 +67,8 @@
#include "rc.h"
#include "shm.h"
#include "gnash.h"
+#include "amf.h"
+#include "lcshm.h"
using namespace std;
using namespace gnash;
@@ -74,12 +76,25 @@
static void usage (void);
void dump_ctrl(void *ptr);
void dump_shm(bool convert);
+key_t list_lcs();
const int PIDSTART = 20000;
const int PIDEND = 23000;
const int LINELEN = 80;
const unsigned int LOOPCNT = 5;
-const int DEFAULT_SHM_SIZE = 65535;
+const int DEFAULT_SHM_SIZE = 64528;
+
+#ifndef SHM_STAT
+const int SHM_STAT = 13;
+const int SHM_INFO = 14;
+#endif
+
+int verbosity = 0;
+
+namespace {
+gnash::LogFile& dbglogfile = gnash::LogFile::getDefaultInstance();
+gnash::RcInitFile& rcfile = gnash::RcInitFile::getDefaultInstance();
+}
int
main(int argc, char *argv[])
@@ -109,8 +124,7 @@
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif
- /* This initializes the DBG_MSG macros */
- while ((c = getopt (argc, argv, "hdnl:ifrc")) != -1) {
+ while ((c = getopt (argc, argv, "hdnl:ifrcv")) != -1) {
switch (c) {
case 'h':
usage ();
@@ -131,6 +145,7 @@
break;
case 'i':
+ sysv = true;
listfiles = true;
break;
@@ -142,6 +157,11 @@
nuke = true;
break;
+ case 'v':
+ dbglogfile.setVerbosity();
+ verbosity++;
+ break;
+
case 'l':
size = atoi(optarg);
break;
@@ -160,6 +180,16 @@
exit(0);
}
+ // Just list the shared memory segments
+ if (listfiles && sysv) {
+ list_lcs();
+ exit(0);
+ }
+
+ if (sysv) {
+ dump_shm(convert);
+ exit(0);
+ }
if (size == 0) {
size = DEFAULT_SHM_SIZE;
@@ -172,11 +202,6 @@
<< endl;
}
- if (sysv) {
- dump_shm(convert);
- exit(0);
- }
-
DIR *library_dir = NULL;
// Solaris stores shared memory segments in /var/tmp/.SHMD and
@@ -214,23 +239,6 @@
exit(0);
}
- // Just list the shared memory segments
- if (listfiles) {
- if (library_dir != NULL)
- {
- for (i=0; entry>0; i++) {
- entry = readdir(library_dir);
- if (entry != NULL) {
- cout << "Found segment: " << entry->d_name << endl;
- }
- }
- } else {
- cout << _("Sorry, we can only list the files on systems with"
- " disk based shared memory") << endl;
- }
- exit(0);
- }
-
//Destroy shared memory segments
if (nuke) {
if (filespec.size() == 0) {
@@ -314,22 +322,54 @@
dump_shm(bool convert)
{
// These are here for debugging purposes. It
-// key_t key1 = 0x0056a4d5; // size is 488
-// key_t key2 = 0x0056a4d6; // size is 131072
-// int size1 = 488;
-// int size2 = 131072;
int id;
char *shmaddr;
- key_t key = 0xdd3adabd; // size is 64528
+
+ key_t key = rcfile.getLCShmKey();
+
+ if (key == 0) {
+ cerr << "No LcShmKey set in ~/.gnashrc, trying to find it ourselves" <<
endl;
+ key = list_lcs();
+ }
+
+ if (key == 0) {
+ cerr << "No shared memory segments found!" << endl;
+ return;
+ }
+ log_msg("SHM Key 0x%x", key);
+
int size = 64528; // 1007 bytes less than unsigned
int flags = 0660 | IPC_CREAT;
+ int total = 0;
id = shmget(key, size, flags);
+ if (id < 0) {
+ cerr << "shmget() failed!: " << strerror(errno) << endl;
+ return;
+ }
shmaddr = (char *)shmat (id, 0, SHM_RDONLY); // attach segment for reading
- if (shmaddr == (char *) -1)
- perror ("shmat");
+ if (shmaddr == (char *)-1) {
+ cerr << "shmat() failed!: " << strerror(errno) << endl;
+ return;
+ }
+ Listener list(shmaddr);
+ vector<string>::const_iterator it;
+ vector<string> *listeners = list.listListeners();
+ if (listeners->size() == 0) {
+ cout << "Nobody is listening" << endl;
+ } else {
+ for (it=listeners->begin(); it!=listeners->end(); it++) {
+ string str = *it;
+ if ((str[0] != ':') || (verbosity > 0)) {
+ cout << " Listeners: " << str << endl;
+ total++;
+ }
+ }
+ }
+
+ cout << "There are " << total << " Listeners listening" << endl;
// If the -c convert options was specified, dump the memory segment to
disk.
// This makes it easy to store them as well as to examine them in great
detail.
if (convert) {
@@ -346,6 +386,65 @@
exit (0); // quit leaving resource allocated
}
+key_t
+list_lcs()
+{
+ int maxid, shmid, id;
+ struct shmid_ds shmseg;
+ struct shm_info shm_info;
+ struct shminfo shminfo;
+
+#ifdef USE_POSIX_SHM
+ if (library_dir != NULL) {
+ for (i=0; entry>0; i++) {
+ entry = readdir(library_dir);
+ if (entry != NULL) {
+ cout << "Found segment: " << entry->d_name << endl;
+ }
+ }
+ } else {
+ cout << _("Sorry, we can only list the files on systems with"
+ " disk based shared memory") << endl;
+ }
+#else
+ // If we're using SYSV shared memory, we can get a list of shared memory
segments.
+ // By examing the size of each one, we can make a reasonable guess if it's
one
+ // used for flash. As permissions apply, this will only list the segments
created
+ // by the user running dumpshm.
+#ifdef USE_SYSV_SHM
+ maxid = shmctl(0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info);
+ if (maxid < 0) {
+ cerr << "kernel not configured for shared memory";
+ return 0;
+ }
+
+ if ((shmctl(0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0) {
+ return 0;
+ }
+
+ for (id = 0; id <= maxid; id++) {
+ shmid = shmctl(id, SHM_STAT, &shmseg);
+ if (shmid < 0) {
+ continue;
+ }
+ if (shmseg.shm_segsz == 64528) {
+ cout << "Found it! \"set LCShmKey 0x"
+ << hex << shmseg.shm_perm.IPC_PERM_KEY
+ << "\" in your ~/.gnashrc" << endl;
+ cout << "Last changed on: " << ctime(&shmseg.shm_ctime);
+ cout << "Last attached on: " << ctime(&shmseg.shm_atime);
+ cout << "Last detached on: " << ctime(&shmseg.shm_dtime);
+ return shmseg.shm_perm.__key;
+ }
+ }
+#else
+#error "No supported shared memory type for this platform"
+#endif
+#endif
+ // Didn't find any segments of the right size
+ return 0;
+}
+
/// \brief Display the command line arguments
static void
usage (void)
@@ -360,6 +459,7 @@
cerr << _("-i\tList segments") << endl;
cerr << _("-r\tDump SYSV segments") << endl;
cerr << _("-c\tDump SYSV segments to disk") << endl;
+ cerr << _("-v\tVerbose output") << endl;
cerr << _("-f\tForce to use builtin names for nuke") << endl;
exit (-1);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash configure.ac utilities/dumpshm.cpp,
Rob Savoye <=