/* ******************************************************************************* * Copyright (c) 1996 Martin Poole * ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * System : * Subsystem : * Module : * $Source: /home/cvs/cvsroot/onelan/onelan/src/mplib1/util/sh_grab.c,v $ * $Author: mpoole $ * $Date: 2002/10/07 09:37:30 $ * $Revision: 1.2 $ * ******************************************************************************* * * Change History * * $Log: sh_grab.c,v $ * Revision 1.2 2002/10/07 09:37:30 mpoole * Initial checkin of mplib1-3.1.0 * * Revision 1.1 2002/10/07 09:37:09 mpoole * Initial checkin of mplib1-3.1.0 * * ******************************************************************************* */ #ident "$Header: /home/cvs/cvsroot/onelan/onelan/src/mplib1/util/sh_grab.c,v 1.2 2002/10/07 09:37:30 mpoole Exp $" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #ifdef __linux__ #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include /* ------------------------------------------------------------------ defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ static void usage ( const char *progname, const char *errstr ) { if (errstr) fprintf( stderr, "Error: %s\n", errstr ); fprintf(stderr, "\nUsage: %s [ -f filename ] [ -s | -e | -d ] [ -v ]\n", progname ); exit(1); return; } static void * Attach_Raw_IPC( int shmid, size_t *szp ) { void *vp; struct shmid_ds myshm_ds; vp = shmat( shmid, NULL, 0 ); if (vp== (void *)-1) vp =NULL; if (vp) { /* it exists, so how big is it */ if (shmctl( shmid, IPC_STAT, &myshm_ds )==0) { if (szp) *szp = myshm_ds.shm_segsz; }else { shmdt( vp ); vp=NULL; } } return(vp); } int main (int argc, char *argv[] ) { int rv=0; int optc; char *fname=NULL,*cp; char *seg_name=NULL; size_t sz=0; char id=0; void *vp; int do_shm=0; int do_mmap=0; int do_rawipc=0,shmid; while ((optc = getopt(argc, argv, "c:n:f:m:i:r:s:")) != EOF) switch (optc) { case 'r' : /* raw shm */ shmid = atoi(optarg); do_rawipc=1; break; case 'n' : /* name of segment */ seg_name = optarg; break; case 'm' : /* shared memory use */ fname = optarg; do_shm = 1; break; case 'f' : /* shared file */ fname = optarg; do_mmap = 1; break; case 'i' : /* id */ id = atoi(optarg); break; case 's' : /* size */ sz = atoi(optarg); break; case 'c' : /* config name, read it I suppose */ read_config_file(optarg); break; default: usage( argv[0], "Invalid argument supplied" ); break; } if (do_rawipc) { fprintf( stderr, "Attach_Raw_IPC( %d )\n", shmid ); vp = Attach_Raw_IPC( shmid, &sz ); }else if (do_shm) { fprintf( stderr, "Create_SODB_shm( %s, %s, %d %d, 0, SODB_USE_SHALLOC )\n", (seg_name)?seg_name:"", fname, id, sz ); vp = Create_SODB_shm( seg_name, fname, id, sz, SODB_USE_SHALLOC ); }else if (do_mmap) { fprintf( stderr, "Create_SODB_mmap( %s, %s, %d, 0, SODB_USE_SHALLOC )\n", (seg_name)?seg_name:"", fname, sz ); vp = Create_SODB_mmap( seg_name, fname, sz, 0, SODB_USE_SHALLOC ); }else { cp = strdup( eval_config_default( "SHM_CONFIG", "$HOME/config/shm.cfg" ) ); vp = comms_shm_attach( cp, SODB_READ_CONFIG ); if (sz==0) { sz = get_private_int( cp, "COMMS_SIZE" ); if (sz<32768) sz=2000000; } } if(vp) { fprintf( stderr, "Attached at %p - dumping %d bytes\n", vp, sz ); /* Dump the segment to standard out */ write( 1, vp, sz ); }else { fprintf( stderr, "Unable to attach\n" ); } return(rv); } /* -- End of File -- */