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) {
38 const struct utmp *usr;
42 while((usr=getutent())!=NULL) {
43 if (usr->ut_type==USER_PROCESS) {
44 strncat(buf, usr->ut_name, 9); strcat(buf, "\n");
49 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) {
62 const struct utmp *usr;
66 while((usr=getutent())!=NULL) {
67 if (usr->ut_type==USER_PROCESS) {
68 strncat(buf, usr->ut_line, 13); strncat(buf, "\n", 3);
73 static void user_time(char **ptr) {
74 const struct utmp *usr;
75 time_t login, real, diff;
78 char output[512] = "";
81 while ((usr=getutent())!=NULL) {
82 if (usr->ut_type==USER_PROCESS) {
85 diff = difftime(real, login);
86 dtime = localtime(&diff);
87 dtime->tm_year = dtime->tm_year-70;
88 dtime->tm_mon = dtime->tm_mon-1;
89 dtime->tm_mday = dtime->tm_mday-1;
90 if(dtime->tm_year>0){strftime(buf,512,"%yy %mm %dd %Hh %Mm\n", dtime); goto end;}
91 else if(dtime->tm_mon>0){strftime(buf,512,"%mm %dd %Hh %Mm\n", dtime); goto end;}
92 else if(dtime->tm_mday>0){strftime(buf,512,"%dd %Hh %Mm\n", dtime); goto end;}
93 else if(dtime->tm_hour>0){strftime(buf,512,"%Hh %Mm\n", dtime); goto end;}
94 else if(dtime->tm_min>0){strftime(buf,512,"%Mm\n", dtime); goto end;}
96 strncat(output, buf, 512);
102 static void users_alloc(struct information *ptr) {
103 if (ptr->users.names == NULL) {
104 ptr->users.names = malloc(TEXT_BUFFER_SIZE);
107 if (ptr->users.terms == NULL) {
108 ptr->users.terms = malloc(TEXT_BUFFER_SIZE);
110 if (ptr->users.times == NULL) {
111 ptr->users.times = malloc(TEXT_BUFFER_SIZE);
115 void update_users() {
116 struct information * current_info = &info;
119 users_alloc(current_info);
122 if (current_info->users.names) {
123 free(current_info->users.names); current_info->users.names = 0;
125 current_info->users.names = malloc(TEXT_BUFFER_SIZE);
126 strncpy(current_info->users.names, temp, TEXT_BUFFER_SIZE);
128 if (current_info->users.names) {
129 free(current_info->users.names); current_info->users.names = 0;
131 current_info->users.names = malloc(TEXT_BUFFER_SIZE);
132 strncpy(current_info->users.names, "broken", TEXT_BUFFER_SIZE);
136 if (current_info->users.number) {
137 current_info->users.number = 0;
139 current_info->users.number = t;
141 current_info->users.number = 0;
146 if (current_info->users.terms) {
147 free(current_info->users.terms); current_info->users.terms = 0;
149 current_info->users.terms = malloc(TEXT_BUFFER_SIZE);
150 strncpy(current_info->users.terms, temp, TEXT_BUFFER_SIZE);
152 if (current_info->users.terms) {
153 free(current_info->users.terms); current_info->users.terms = 0;
155 current_info->users.terms = malloc(TEXT_BUFFER_SIZE);
156 strncpy(current_info->users.terms, "broken", TEXT_BUFFER_SIZE);
160 if (current_info->users.times) {
161 free(current_info->users.times); 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); current_info->users.times = 0;
169 current_info->users.times = malloc(TEXT_BUFFER_SIZE);
170 strncpy(current_info->users.times, "broken", TEXT_BUFFER_SIZE);