1 | @node White Paper, Reference Manual, About, Top |
---|
2 | @chapter LibGTop White Paper |
---|
3 | |
---|
4 | @menu |
---|
5 | * Introduction:: Introduction |
---|
6 | * Overview:: Overview |
---|
7 | @end menu |
---|
8 | |
---|
9 | @node Introduction, Overview, White Paper, White Paper |
---|
10 | @section Introduction |
---|
11 | |
---|
12 | Many modern UNIX systems like Solaris, BSD or Digitial Unix only allow |
---|
13 | priviledged processes to read information like CPU and Memory Usage or |
---|
14 | information about running processes. |
---|
15 | |
---|
16 | @itemize @bullet |
---|
17 | @item |
---|
18 | BSD, for instance, doesn't have any other way to get those data than reading |
---|
19 | directly from @file{/dev/kmem} and you need to be in the @code{kmem} group to |
---|
20 | be able to read this. |
---|
21 | |
---|
22 | @item |
---|
23 | Other systems, like Digital Unix, allow all users to get things like CPU and |
---|
24 | Memory statistics, but only root may read information about any process other |
---|
25 | than the current one (you may not even get information about your own processes |
---|
26 | if you're not root). |
---|
27 | |
---|
28 | @item |
---|
29 | Linux has a very nice @file{/proc} filesystem, but reading and parsing |
---|
30 | @file{/proc} is very slow and inefficient. |
---|
31 | |
---|
32 | @item |
---|
33 | Solaris is a bit better, but you still need to be in the @code{sys} group or |
---|
34 | even root to get some data. |
---|
35 | @end itemize |
---|
36 | |
---|
37 | Because of this system utilities like @code{ps}, @code{uptime} or @code{top} |
---|
38 | often are setgid kmem or setuid root. Usually, they're also very specific to |
---|
39 | the system they're written for and not easily portable to other systems without |
---|
40 | a lot of work. |
---|
41 | |
---|
42 | This, of cause, becomes a problem for graphical tools like @code{gtop} - making |
---|
43 | a GTK+ program setgid or even setuid would be a security hole as big as you can |
---|
44 | drive the entire X11 source code through. For the GNOME project, we also needed |
---|
45 | some kind of library which provides all the required information in a portable |
---|
46 | since there's more than just one single program that wants to use them - for |
---|
47 | instance @code{gtop} and the @code{multiload}, @code{cpumemusage} and |
---|
48 | @code{netload} panel applets. |
---|
49 | |
---|
50 | @node Overview, , Introduction, White Paper |
---|
51 | @section Overview |
---|
52 | |
---|
53 | This section should give you a short overview on how LibGTop was developed, which |
---|
54 | things needed to be considered and how it works. |
---|
55 | |
---|
56 | @menu |
---|
57 | * Interface Design:: Things that need to be considered |
---|
58 | * Server Implementation:: The LibGTop "server" |
---|
59 | @end menu |
---|
60 | |
---|
61 | @node Interface Design, Server Implementation, Overview, Overview |
---|
62 | @subsection Interface Design |
---|
63 | |
---|
64 | At the very beginning, it was necessary to collect all the data the library part |
---|
65 | should provide and put them into some C structures. This was not that easiy as it |
---|
66 | might sound since LibGTop should be portable to any modern UNIX system with a common |
---|
67 | library part on all those systems, but the data that should be returned vary from |
---|
68 | system to system. For instance some systems support shared memory, but some others |
---|
69 | may not. |
---|
70 | |
---|
71 | The header files where we define these C structures (which are system-independent) are |
---|
72 | shared between client and server. This way we can call the system dependent code |
---|
73 | directly where we do not need any special privileges to do so. |
---|
74 | |
---|
75 | All of those structures contain a @code{flags} member which is interpreted as a bit |
---|
76 | mask and tells the caller of the library functions which of the fields in the returned |
---|
77 | structure are valid and which are not. |
---|
78 | |
---|
79 | @node Server Implementation, , Interface Design, Overview |
---|
80 | @subsection Server Implementation |
---|
81 | |
---|
82 | The LibGTop @dfn{server} is a setgid/setuid binary which contains all the system |
---|
83 | dependent code which needs special privileges. It is only build if it's required |
---|
84 | on the current system (for instance, the Linux kernel provides all the required |
---|
85 | data via its @file{/proc} filesystem so we do not need the server at all) and it |
---|
86 | only contains the @dfn{features} which need privileges. |
---|
87 | |
---|
88 | Whenever we do not need any privileges to get all the data for some of the requested |
---|
89 | structures (here called @dfn{features}) the library calls the sysdeps code directly |
---|
90 | rather than using the server. |
---|