diff -rNup bwbar-1.2/Makefile bwbar-shm-1.2/Makefile --- bwbar-1.2/Makefile 2001-05-06 00:51:48.000000000 +0200 +++ bwbar-shm-1.2/Makefile 2003-09-30 16:37:08.000000000 +0200 @@ -11,6 +11,12 @@ ## ## ----------------------------------------------------------------------- +## ----------------------------------------------------------------------- +## +## Applied patch for use Shared Memory in Bwbar +## +## ----------------------------------------------------------------------- + PROGS = bwbar CC = gcc @@ -29,5 +35,5 @@ distclean: clean bwbar: bwbar.c $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) - - +test_shm: test_shm.c + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) diff -rNup bwbar-1.2/bwbar.c bwbar-shm-1.2/bwbar.c --- bwbar-1.2/bwbar.c 2001-09-22 00:33:35.000000000 +0200 +++ bwbar-shm-1.2/bwbar.c 2003-09-30 16:34:46.000000000 +0200 @@ -19,6 +19,15 @@ * */ +/* + * Applied patch for store data in Shared Memory + * + * 2003 - Sergi Coll (sergi at sim00 net) + * + * http://www.sim00.net/ + * + */ + #define _GNU_SOURCE #include #include @@ -31,6 +40,16 @@ #include #include +/* start - Shared Memory patch */ + +#include +#include +#include +#include +#include + +/* end - Shared Memory patch */ + void skipline(FILE *f) { int ch; @@ -185,6 +204,15 @@ void usage(int err) int main(int argc, char *argv[]) { + /* start - Shared Memory patch */ + + int shmid; + unsigned int i; + char *shm, *s; + char texte_sortida[100]; + + /* end - Shared Memory patch */ + FILE *pnd; char *interface; struct ifinfo { @@ -214,6 +242,24 @@ int main(int argc, char *argv[]) program = argv[0]; + /* start - Shared Memory patch */ + + /* Create the segment. */ + + if ((shmid = shmget(5678, 100, IPC_CREAT | 0666)) < 0) { + perror("shmget"); + exit(1); + } + + /* Now we attach the segment to our data space. */ + + if ((shm = shmat(shmid, NULL, 0)) == (void *) -1) { + perror("shmat"); + exit(1); + } + + /* end - Shared Memory patch */ + while ( (opt = getopt_long(argc, argv, "iof:p:t:x:y:b:kMGh", longopts, NULL)) != -1 ) { switch ( opt ) { case 'i': @@ -319,6 +365,7 @@ int main(int argc, char *argv[]) /**** Begin code that generates output ****/ if ( !first ) { + FILE *ubar, *pngmaker; timedelta = (double)(t_now.tv_sec - t_last.tv_sec) + @@ -327,7 +374,7 @@ int main(int argc, char *argv[]) bwout = (bout-lbout)*8/timedelta; bwmeasure = measure_input ? bwin : bwout; - + ubar = fopen(t_tmp, "w"); pngmaker = fopen(g_tmp, "w"); if ( ubar ) { @@ -340,6 +387,24 @@ int main(int argc, char *argv[]) fclose(pngmaker); rename(g_tmp, graphics_file); } + + /* start - Shared Memory patch */ + + /* Now put some things into the memory for the other process to read. */ + + sprintf (texte_sortida, "Current bandwidth utilization %6.2f %s", bwmeasure/unit, unit_name); + + s = shm; + + for (i=0; i < strlen(texte_sortida); i++) { + sprintf(s,"%c",texte_sortida[i]); + *s++; + } + + s = NULL; + + /* end - Shared Memory patch */ + } else { first = 0; } diff -rNup bwbar-1.2/test_shm.c bwbar-shm-1.2/test_shm.c --- bwbar-1.2/test_shm.c 1970-01-01 01:00:00.000000000 +0100 +++ bwbar-shm-1.2/test_shm.c 2003-09-30 16:33:33.000000000 +0200 @@ -0,0 +1,47 @@ +/* + * shm-client - client program to demonstrate shared memory. + */ + +#include +#include +#include +#include +#define SHMSZ 100 +main() +{ + int shmid; + key_t key; + char *shm, *s; + /* + * We need to get the segment named + * "5678", created by the server. + */ + key = 5678; + /* + * Locate the segment. + */ + if ((shmid = shmget(key, SHMSZ, 0666)) < 0) { + perror("shmget"); + exit(1); + } + /* + * Now we attach the segment to our data space. + */ + if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { + perror("shmat"); + exit(1); + } + /* + * Now read what the server put in the memory. + */ + for (s = shm; *s != NULL; s++) + putchar(*s); + putchar('\n'); + /* + * Finally, change the first character of the + * segment to '*', indicating we have read + * the segment. + */ + /* *shm = '*'; */ + exit(0); +}