xdbe replaced with more generic pixmap based buffering but there are 3 major bugs:
[monky] / src / users.c
index 58cfb02..5ba7959 100644 (file)
@@ -10,7 +10,7 @@
  * 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.
  *
@@ -93,32 +93,22 @@ static void user_time(char *ptr)
                }
        }
 }
-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);
@@ -137,20 +127,19 @@ static void users_alloc(struct information *ptr)
        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);
@@ -166,7 +155,15 @@ void update_users(void)
                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);
@@ -224,4 +221,5 @@ void update_users(void)
                current_info->users.times = malloc(text_buffer_size);
                strncpy(current_info->users.times, "broken", text_buffer_size);
        }
+       return 0;
 }