]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/consolas: remove global variable concount, fix linked list
authorKarel Zak <kzak@redhat.com>
Fri, 9 Nov 2012 08:52:35 +0000 (09:52 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 9 Nov 2012 08:52:35 +0000 (09:52 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/consoles.c

index bc7c039bdd5afad33ec7779710e7bea0e1c019ac..b304e37a9c6ce6aac5e3f51d79c86f6e671a2e33 100644 (file)
@@ -176,9 +176,6 @@ char* scandev(DIR *dir, dev_t comparedev)
  * initialize its default values, and append it to
  * the global linked list.
  */
-
-static int concount;           /* Counter for console IDs */
-
 static
 #ifdef __GNUC__
 __attribute__((__nonnull__,__hot__))
@@ -192,26 +189,28 @@ void consalloc(char * name)
                .parity = 0
        };
        struct console *restrict tail;
-
+       struct console *last;
 
        if (posix_memalign((void*)&tail, sizeof(void*), alignof(typeof(struct console))) != 0)
                perror("memory allocation");
 
+       for (last = consoles; last && last->next; last = last->next);
+
        tail->next = NULL;
        tail->tty = name;
 
        tail->file = (FILE*)0;
        tail->flags = 0;
        tail->fd = -1;
-       tail->id = concount++;
+       tail->id = last ? last->id + 1 : 0;
        tail->pid = 0;
        memset(&tail->tio, 0, sizeof(tail->tio));
        memcpy(&tail->cp, &initcp, sizeof(struct chardata));
 
-       if (!consoles)
+       if (!last)
                consoles = tail;
        else
-               consoles->next = tail;
+               last->next = tail;
 }
 
 /*