* Please see COPYING for details
*
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
* (see AUTHORS)
* All rights reserved.
*
}
}
}
-static void conky_user_time(char *ptr)
+static void tty_user_time(char *ptr, char *tty)
{
- time_t real, diff;
- static time_t log_in = 0;
+ time_t real, diff, log_in;
char buf[BUFLEN] = "";
- if (log_in == 0) {
- struct utmp *usr, line;
- char *real_tty_path = NULL;
+ struct utmp *usr, line;
- real_tty_path = ttyname(0);
- if (real_tty_path == NULL ) {
- return;
- }
+ setutent();
+ strcpy(line.ut_line, tty);
+ usr = getutline(&line);
+ if (usr == NULL ) {
+ return;
+ }
- real_tty_path += 5; /* Remove "/dev/". */
+ log_in = usr->ut_time;
- setutent();
- strcpy(line.ut_line, real_tty_path);
- usr = getutline(&line);
- if (usr == NULL ) {
- return;
- }
-
- log_in = usr->ut_time;
- }
time(&real);
diff = difftime(real, log_in);
format_seconds(buf, BUFLEN, diff);
if (ptr->users.times == NULL) {
ptr->users.times = malloc(text_buffer_size);
}
- if (ptr->users.ctime == NULL) {
- ptr->users.ctime = malloc(text_buffer_size);
- }
}
-void update_users(void)
+void update_user_time(char *tty)
{
struct information *current_info = &info;
char temp[BUFLEN] = "";
- int t;
- users_alloc(current_info);
- user_name(temp);
- temp[0] = 0;
- conky_user_time(temp);
+
+ if (current_info->users.ctime == NULL) {
+ current_info->users.ctime = malloc(text_buffer_size);
+ }
+
+ tty_user_time(temp, tty);
+
if (temp != NULL) {
if (current_info->users.ctime) {
free(current_info->users.ctime);
current_info->users.ctime = malloc(text_buffer_size);
strncpy(current_info->users.ctime, "broken", text_buffer_size);
}
- temp[0] = 0;
+}
+
+int update_users(void)
+{
+ struct information *current_info = &info;
+ char temp[BUFLEN] = "";
+ int t;
+ users_alloc(current_info);
+ user_name(temp);
if (temp != NULL) {
if (current_info->users.names) {
free(current_info->users.names);
current_info->users.times = malloc(text_buffer_size);
strncpy(current_info->users.times, "broken", text_buffer_size);
}
+ return 0;
}