1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 static void user_name(char *ptr)
39 const struct utmp *usr = 0;
42 while ((usr = getutent()) != NULL) {
43 if (usr->ut_type == USER_PROCESS) {
44 strncat(ptr, usr->ut_name, 9);
48 static void user_num(int *ptr)
50 const struct utmp *usr;
54 while ((usr = getutent()) != NULL) {
55 if (usr->ut_type == USER_PROCESS) {
61 static void user_term(char *ptr)
63 const struct utmp *usr;
66 while ((usr = getutent()) != NULL) {
67 if (usr->ut_type == USER_PROCESS) {
68 strncat(ptr, usr->ut_line, 13);
72 static void user_time(char *ptr)
74 const struct utmp *usr;
75 time_t log_in, real, diff;
80 while ((usr = getutent()) != NULL) {
81 if (usr->ut_type == USER_PROCESS) {
82 log_in = usr->ut_time;
84 diff = difftime(real, log_in);
85 dtime = localtime(&diff);
86 dtime->tm_year = dtime->tm_year - 70;
87 dtime->tm_mon = dtime->tm_mon - 1;
88 dtime->tm_mday = dtime->tm_mday - 1;
89 if (dtime->tm_year > 0) {
90 strftime(buf, 512, "%yy %mm %dd %Hh %Mm", dtime);
91 } else if (dtime->tm_mon > 0) {
92 strftime(buf, 512, "%mm %dd %Hh %Mm", dtime);
93 } else if (dtime->tm_mday > 0) {
94 strftime(buf, 512, "%dd %Hh %Mm", dtime);
95 } else if (dtime->tm_hour > 0) {
96 strftime(buf, 512, "%Hh %Mm", dtime);
97 } else if (dtime->tm_min > 0) {
98 strftime(buf, 512, "%Mm", dtime);
100 strncat(ptr, buf, 512);
105 static void users_alloc(struct information *ptr)
107 if (ptr->users.names == NULL) {
108 ptr->users.names = malloc(text_buffer_size);
111 if (ptr->users.terms == NULL) {
112 ptr->users.terms = malloc(text_buffer_size);
114 if (ptr->users.times == NULL) {
115 ptr->users.times = malloc(text_buffer_size);
119 void update_users(void)
121 struct information *current_info = &info;
124 users_alloc(current_info);
127 if (current_info->users.names) {
128 free(current_info->users.names);
129 current_info->users.names = 0;
131 current_info->users.names = malloc(text_buffer_size);
132 strncpy(current_info->users.names, temp, text_buffer_size);
134 if (current_info->users.names) {
135 free(current_info->users.names);
136 current_info->users.names = 0;
138 current_info->users.names = malloc(text_buffer_size);
139 strncpy(current_info->users.names, "broken", text_buffer_size);
143 if (current_info->users.number) {
144 current_info->users.number = 0;
146 current_info->users.number = t;
148 current_info->users.number = 0;
153 if (current_info->users.terms) {
154 free(current_info->users.terms);
155 current_info->users.terms = 0;
157 current_info->users.terms = malloc(text_buffer_size);
158 strncpy(current_info->users.terms, temp, text_buffer_size);
160 if (current_info->users.terms) {
161 free(current_info->users.terms);
162 current_info->users.terms = 0;
164 current_info->users.terms = malloc(text_buffer_size);
165 strncpy(current_info->users.terms, "broken", text_buffer_size);
169 if (current_info->users.times) {
170 free(current_info->users.times);
171 current_info->users.times = 0;
173 current_info->users.times = malloc(text_buffer_size);
174 strncpy(current_info->users.times, temp, text_buffer_size);
176 if (current_info->users.times) {
177 free(current_info->users.times);
178 current_info->users.times = 0;
180 current_info->users.times = malloc(text_buffer_size);
181 strncpy(current_info->users.times, "broken", text_buffer_size);