File: 10_misc.patch

package info (click to toggle)
gmemusage 0.2-11
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, jessie, jessie-kfreebsd, squeeze, stretch, wheezy
  • size: 148 kB
  • ctags: 121
  • sloc: ansic: 1,321; perl: 67; makefile: 33
file content (105 lines) | stat: -rw-r--r-- 3,089 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
--- gmemusage-0.2.orig/gmemusage.c
+++ gmemusage-0.2/gmemusage.c
@@ -40,6 +40,9 @@
 
 #define TOO_SMALL	0
 #define	BIG_ENOUGH	1
+
+#define name_length 64
+
 /*
  * I hate these file-wide variables, but since draw_window is going to be
  * called from a signal, we can't pass it any args.
@@ -108,9 +111,10 @@
       border_width = 4 ,
       display_width ,
       display_height ;
-   char
-      *window_name = "gmemusage" ,
-      *icon_name = "gmemusage" ;
+   char 
+     window_name [name_length];
+   char 
+     * window_name_list [1];
    Pixmap
       icon_pixmap ;
    XSizeHints
@@ -141,6 +145,11 @@
    {
       strcpy ( progname , argv [0] ) ;
    }
+
+   strcpy(window_name, "gmemusage: ");
+   gethostname (&window_name[11], name_length - 11); 
+   window_name_list[0] = window_name;
+
 /*
  * Allocate necessaru X structures for later use. Apparently this needs to
  * be done before any other X stuff.
@@ -228,13 +237,14 @@
    size_hints -> flags = PPosition | PSize | PMinSize ;
    size_hints -> min_width = default_width ;
    size_hints -> min_height = default_height ;
-   if ( XStringListToTextProperty (&window_name , 1 , &windowName ) == 0 )
+   
+   if ( XStringListToTextProperty ( window_name_list , 1 , &windowName ) == 0 )
    {
       fprintf ( stderr , "%s: struct allocation for windowName failed\n" ,
 		progname ) ;
       exit ( 1 ) ;
    }
-   if ( XStringListToTextProperty ( &icon_name , 1 , &iconName ) == 0 )
+   if ( XStringListToTextProperty ( window_name_list , 1 , &iconName ) == 0 )
    {
       fprintf ( stderr , "%s: struct allocation for iconName failed\n" ,
 		progname ) ;
@@ -752,7 +762,7 @@
    valuemask |= GCPlaneMask;
    values.plane_mask = AllPlanes;
    blackGC = XCreateGC ( display , win , valuemask , &values ) ;
-   XSetForeground ( display , blackGC , BlackPixel ( display , screen_num ) ) ;
+   XSetForeground ( display , blackGC , Background . pixel ) ;
    return ;
 }
 #if 0
--- gmemusage-0.2.orig/proc.c
+++ gmemusage-0.2/proc.c
@@ -23,6 +23,9 @@
 /*
  * Set values for various memory usages
  */
+#define MemTotalLine   "MemTotal:"
+#define        MemFreeLine     "MemFree:"
+#define        BuffersLine     "Buffers:"
 static void
 SetMemInfo ( void )
 {
@@ -63,12 +66,28 @@
    {
       if ( !strncmp ( buf , MemLine , MemLineLen ) )
       {
+	 /* Linux 2.4 (and earlier?) */
 	 /* Mem: total used free shared buffers cached */
 	 sscanf ( buf , "%*s %d %*d %d %*d %d" , &totalmem , &freemem ,
 		  &buffermem ) ;
 	 break ;
+	 
+       /* Linux 2.6 (and later?) */
+       } else if (!strncmp(buf, MemTotalLine, strlen(MemTotalLine))) {
+	      sscanf(buf, "%*s %d", &totalmem);
+       } else if (!strncmp(buf, MemFreeLine, strlen(MemFreeLine))) {
+	      sscanf(buf, "%*s %d", &freemem);
+       } else if (!strncmp(buf, BuffersLine, strlen(BuffersLine))) {
+	      sscanf(buf, "%*s %d", &buffermem);
       }
    }
+   
+   if (!totalmem) {
+	 fprintf(stderr, "Fatal error reading /proc/meminfo\n");
+	 exit(1);
+   }
+   
+   sysmem /= 1024 ;
    sysmem /= 1024 ;
    totalmem /= 1024 ;
    freemem /= 1024 ;