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-2008 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/>.
34 static void user_name(char *ptr)
36 const struct utmp *usr = 0;
39 while ((usr = getutent()) != NULL) {
40 if (usr->ut_type == USER_PROCESS) {
41 strncat(ptr, usr->ut_name, 9);
45 static void user_num(int *ptr)
47 const struct utmp *usr;
51 while ((usr = getutent()) != NULL) {
52 if (usr->ut_type == USER_PROCESS) {
58 static void user_term(char *ptr)
60 const struct utmp *usr;
63 while ((usr = getutent()) != NULL) {
64 if (usr->ut_type == USER_PROCESS) {
65 strncat(ptr, usr->ut_line, 13);
69 static void user_time(char *ptr)
71 const struct utmp *usr;
72 time_t log_in, real, diff;
77 while ((usr = getutent()) != NULL) {
78 if (usr->ut_type == USER_PROCESS) {
79 log_in = usr->ut_time;
81 diff = difftime(real, log_in);
82 dtime = localtime(&diff);
83 dtime->tm_year = dtime->tm_year - 70;
84 dtime->tm_mon = dtime->tm_mon - 1;
85 dtime->tm_mday = dtime->tm_mday - 1;
86 if (dtime->tm_year > 0) {
87 strftime(buf, 512, "%yy %mm %dd %Hh %Mm", dtime);
88 } else if (dtime->tm_mon > 0) {
89 strftime(buf, 512, "%mm %dd %Hh %Mm", dtime);
90 } else if (dtime->tm_mday > 0) {
91 strftime(buf, 512, "%dd %Hh %Mm", dtime);
92 } else if (dtime->tm_hour > 0) {
93 strftime(buf, 512, "%Hh %Mm", dtime);
94 } else if (dtime->tm_min > 0) {
95 strftime(buf, 512, "%Mm", dtime);
97 strncat(ptr, buf, 512);
102 static void users_alloc(struct information *ptr)
104 if (ptr->users.names == NULL) {
105 ptr->users.names = malloc(text_buffer_size);
108 if (ptr->users.terms == NULL) {
109 ptr->users.terms = malloc(text_buffer_size);
111 if (ptr->users.times == NULL) {
112 ptr->users.times = malloc(text_buffer_size);
116 void update_users(void)
118 struct information *current_info = &info;
121 users_alloc(current_info);
124 if (current_info->users.names) {
125 free(current_info->users.names);
126 current_info->users.names = 0;
128 current_info->users.names = malloc(text_buffer_size);
129 strncpy(current_info->users.names, temp, text_buffer_size);
131 if (current_info->users.names) {
132 free(current_info->users.names);
133 current_info->users.names = 0;
135 current_info->users.names = malloc(text_buffer_size);
136 strncpy(current_info->users.names, "broken", text_buffer_size);
140 if (current_info->users.number) {
141 current_info->users.number = 0;
143 current_info->users.number = t;
145 current_info->users.number = 0;
150 if (current_info->users.terms) {
151 free(current_info->users.terms);
152 current_info->users.terms = 0;
154 current_info->users.terms = malloc(text_buffer_size);
155 strncpy(current_info->users.terms, temp, text_buffer_size);
157 if (current_info->users.terms) {
158 free(current_info->users.terms);
159 current_info->users.terms = 0;
161 current_info->users.terms = malloc(text_buffer_size);
162 strncpy(current_info->users.terms, "broken", text_buffer_size);
166 if (current_info->users.times) {
167 free(current_info->users.times);
168 current_info->users.times = 0;
170 current_info->users.times = malloc(text_buffer_size);
171 strncpy(current_info->users.times, temp, text_buffer_size);
173 if (current_info->users.times) {
174 free(current_info->users.times);
175 current_info->users.times = 0;
177 current_info->users.times = malloc(text_buffer_size);
178 strncpy(current_info->users.times, "broken", text_buffer_size);