More bugs and fixes in userlist version 1.4.3


Subject: More bugs and fixes in userlist version 1.4.3
From: Livio Baldini Soares (livio@linux.ime.usp.br)
Date: Tue Jul 25 2000 - 07:54:39 CEST


Hello,

  I've sent in a patch (about two days ago), but nobody answered.. Was
the patch so bad? BTW, is anyone ON this list? I haven't gotten any
mail from here.

Anyway, I've found more "bugs" in `userlist` in cfingerd (1.4.3).
If what I've explained below is too complicated (I can't express
myself in English too well), then I can send in a diff, just ask.

1) Problems with idle time:

  I've found two problems with idle time (idle.c).
  a) In `calc_idle(char *tty)`, if tty is a X entry, for like XDM or
     KDM, then there is no idle for stat information, and it would
     show bizarre values, like a thousand days.
     To fix this, just at this to the function, at the beginning below
     memset of idledisp (line +- 30):

    if (tty[0] == ':')
        return idledisp;

  b) Another problem is that the idle time would sometimes appear
     smaller than it really is. To fix this I've changed the field to
     get time information, from buf.st_mtime to buf.st_atime. So now
     diff_time looks like this:

     diff_time = (long) cur_time - (long) buf.st_atime;

2) Problems with size of `Remote console` and `tty`:

  a) The `Remote console location` field was being truncated too
     early, so I thought of a way to make it more "flexible".
     I changed things in two places userlist/initialize.c and
     userlist/display.c.
      initialize.c:
     First, instead of malloc on a fixed size (ULIST_LOCALE+1) (we can
     even throw away the #define ULIST_LOCALE, 'cause it won't be used
     in my implementation), what I did was, wait until it's time to
     initiate tty_list[times_on].locale and THEN malloc it.
     First, I commented out:
/* if (*cp == ':')
                    cp++; */ I think it's nice to have this ':' to
     see if user is in the X enviroment.
     then,

     tty_list[times_on].locale = malloc(strlen(cp)+1); /* alocating, just what we need */
     memset (tty_list[times_on].locale, 0, strlen(cp)+1);
     strncpy(tty_list[times_on].locale, cp, strlen(cp)+1); /* copying */

     and finally, commented out:
 /* if (strlen ((char *) ut->ut_host) > ULIST_LINE)
       if ((cp = strrchr(tty_list[times_on].locale, '.')) != NULL)
         *cp = '\0'; */ Don't want to truncate `locale` anymore.

    Ok, now display.c:
     Now we have variable sized `tty_list[i].locale`, so the variable
     `console` in function `process_display` can't be fixed
     anymore. So I've changed `console` declaration to :
     char *console;

   And it's initialization to:

 console = malloc(strlen(tty_list[i].locale)+3);

 if (strlen((char *) tty_list[i].locale) == 0){
   console = realloc(console, strlen(our_host)+3);
   snprintf(console, strlen(our_host)+3, "(%s)", our_host);
 }
 else
   snprintf(console, strlen(tty_list[i].locale)+3, "(%s)", tty_list[i].locale);

  Ok, now `console` is correct, we just have to print it. Since it's
  the last field we can change the %-30.30s to plain out %-s.

  OF COURSE, we can't forget to free(console) after we've used
  it. (after the fflush(stdout); line).

  b) Now let's look at TTY. Tty will only print out 2 chars, but in my
  Linux 2.2 with Unix/pts terminals, it's too short, so I've changed
  that also, in a analogous way to the `locale` field.
  In initialize.c:
  Here we also don't malloc tty_list[times_on].tty with (ULIST_TTY+1)
  (throw away this #define too...), instead wait until we would
  initialize it, (after we strip ^tty from ut->ut_line), do:

  tty_list[times_on].tty = malloc(strlen(cp)+1);
  memset (tty_list[times_on].tty, 0, strlen(cp)+1);
  strncpy(tty_list[times_on].tty, cp, strlen(cp));

  Ok, now display.c:

   Just change the print out from:
   printf("%3.3s %-25.25s\n", (char *) tty_list[i].tty, console);
to:
   printf("%-*s %-s\n", 5, (char *) tty_list[i].tty, console);
(Well, yes, that "5" is kind of ugly, but I'm thinking of changing it
latter).

 So now, it's all more "flexible".

TODO: To make it really flexible we should change the width of tty
printout from 5 to something like `maxttysize`, and calculate this in
initiaze.c, when checking all user stuff. I can do this and send in
the patch... If someone will read it...

  hope I wasn't too confusing, bye,

        Livio <livio@linux.ime.usp.br>



This archive was generated by hypermail 2b25 : Tue Jul 25 2000 - 07:52:01 CEST