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-2009 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/>.
26 * vim: ts=4 sw=4 noet ai cindent syntax=c
27 * -*- c-basic-offset: 4; tab-width: 4 -*-
36 static void user_name(char *ptr)
38 const struct utmp *usr = 0;
41 while ((usr = getutent()) != NULL) {
42 if (usr->ut_type == USER_PROCESS) {
43 if (strlen(ptr) + strlen(usr->ut_name) + 1 <= BUFLEN) {
44 strncat(ptr, usr->ut_name, UT_NAMESIZE);
49 static void user_num(int *ptr)
51 const struct utmp *usr;
55 while ((usr = getutent()) != NULL) {
56 if (usr->ut_type == USER_PROCESS) {
62 static void user_term(char *ptr)
64 const struct utmp *usr;
67 while ((usr = getutent()) != NULL) {
68 if (usr->ut_type == USER_PROCESS) {
69 if (strlen(ptr) + strlen(usr->ut_line) + 1 <= BUFLEN) {
70 strncat(ptr, usr->ut_line, UT_LINESIZE);
75 static void user_time(char *ptr)
77 const struct utmp *usr;
78 time_t log_in, real, diff;
79 char buf[BUFLEN] = "";
82 while ((usr = getutent()) != NULL) {
83 if (usr->ut_type == USER_PROCESS) {
84 log_in = usr->ut_time;
86 diff = difftime(real, log_in);
87 format_seconds(buf, BUFLEN, diff);
88 if (strlen(ptr) + strlen(buf) + 1 <= BUFLEN) {
89 strncat(ptr, buf, BUFLEN-strlen(ptr)-1);
95 static void users_alloc(struct information *ptr)
97 if (ptr->users.names == NULL) {
98 ptr->users.names = malloc(text_buffer_size);
101 if (ptr->users.terms == NULL) {
102 ptr->users.terms = malloc(text_buffer_size);
104 if (ptr->users.times == NULL) {
105 ptr->users.times = malloc(text_buffer_size);
109 void update_users(void)
111 struct information *current_info = &info;
112 char temp[BUFLEN] = "";
114 users_alloc(current_info);
117 if (current_info->users.names) {
118 free(current_info->users.names);
119 current_info->users.names = 0;
121 current_info->users.names = malloc(text_buffer_size);
122 strncpy(current_info->users.names, temp, text_buffer_size);
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, "broken", text_buffer_size);
133 if (current_info->users.number) {
134 current_info->users.number = 0;
136 current_info->users.number = t;
138 current_info->users.number = 0;
143 if (current_info->users.terms) {
144 free(current_info->users.terms);
145 current_info->users.terms = 0;
147 current_info->users.terms = malloc(text_buffer_size);
148 strncpy(current_info->users.terms, temp, text_buffer_size);
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, "broken", text_buffer_size);
159 if (current_info->users.times) {
160 free(current_info->users.times);
161 current_info->users.times = 0;
163 current_info->users.times = malloc(text_buffer_size);
164 strncpy(current_info->users.times, temp, 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, "broken", text_buffer_size);