2 * wmmisc - WindowMaker Dockapp for monitoring misc. information.
3 * Copyright (C) 2003-2006 Jesse S. (luxorfalls@sbcglobal.net)
5 * wmmisc is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * wmmisc is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with wmmisc; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <bits/types/time_t.h>
27 #include "dockapp_utils.h"
29 static dockapp_proc_t dockapp_proc
;
32 dockapp_utils_get_proc( void )
40 float p_uptime
= 0.00;
42 dockapp_utils_get_users();
44 pla_buf
= fopen( "/proc/loadavg", "r" );
46 if ( NULL
!= pla_buf
)
48 count
= fscanf( pla_buf
,
49 "%d.%d %*s %*s %d/%d %*s",
57 dockapp_proc
.total
= p_total
;
58 dockapp_proc
.running
= p_run
;
59 dockapp_proc
.load
[0] = p_load
[0];
60 dockapp_proc
.load
[1] = p_load
[1];
62 dockapp_proc
.total
= 0;
63 dockapp_proc
.running
= 0;
64 dockapp_proc
.load
[0] = 0;
65 dockapp_proc
.load
[1] = 0;
70 dockapp_proc
.total
= 0;
71 dockapp_proc
.running
= 0;
72 dockapp_proc
.load
[0] = 0;
73 dockapp_proc
.load
[1] = 0;
76 put_buf
= fopen( "/proc/uptime", "r" );
78 if ( NULL
!= put_buf
)
80 count
= fscanf( put_buf
, "%f %*s", &p_uptime
);
84 dockapp_proc
.jiffies
= p_uptime
;
85 dockapp_proc
.seconds
= GET_SECS( p_uptime
);
86 dockapp_proc
.minutes
= GET_MINS( p_uptime
);
87 dockapp_proc
.hours
= GET_HRS( p_uptime
);
88 dockapp_proc
.days
= GET_DAYS( p_uptime
);
89 dockapp_proc
.weeks
= GET_WEEKS( p_uptime
);
91 dockapp_proc
.jiffies
= 0.00;
92 dockapp_proc
.seconds
= 0;
93 dockapp_proc
.minutes
= 0;
94 dockapp_proc
.hours
= 0;
95 dockapp_proc
.days
= 0;
96 dockapp_proc
.weeks
= 0;
100 printf( "Uptime: %.2d:%.2d:%.2d, %d day%c, %.3d week%c\n",
102 dockapp_proc
.minutes
,
103 dockapp_proc
.seconds
,
105 ( ( dockapp_proc
.days
> 1 || !dockapp_proc
.days
) ? 's' : '\0' ),
107 ( ( dockapp_proc
.weeks
> 1 || !dockapp_proc
.weeks
) ? 's' : '\0' ) );
112 dockapp_proc
.jiffies
= 0.00;
113 dockapp_proc
.seconds
= 0;
114 dockapp_proc
.minutes
= 0;
115 dockapp_proc
.hours
= 0;
116 dockapp_proc
.days
= 0;
117 dockapp_proc
.weeks
= 0;
124 * Get the number of users logged onto the system.
126 * This code was taken from gkrellm and modified for
131 dockapp_utils_get_users( void )
135 static time_t utmp_mtime
;
138 if ( 0 == stat( _PATH_UTMP
, &stt
) && stt
.st_mtime
!= utmp_mtime
)
146 if ( USER_PROCESS
== ut
->ut_type
&& '\0' != ut
->ut_name
[0] )
156 utmp_mtime
= stt
.st_mtime
;
157 dockapp_proc
.users
= p_users
;
162 dockapp_utils_get_char( char d_char
)
352 n_char
= 26; /* Blank. */