From: Karel Zak Date: Fri, 9 Nov 2012 08:52:35 +0000 (+0100) Subject: lib/consolas: remove global variable concount, fix linked list X-Git-Tag: v2.23-rc1~550 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c7c1eaf2a3372347852aeeb00f95907b0e1a4ba;p=thirdparty%2Futil-linux.git lib/consolas: remove global variable concount, fix linked list Signed-off-by: Karel Zak --- diff --git a/lib/consoles.c b/lib/consoles.c index bc7c039bdd..b304e37a9c 100644 --- a/lib/consoles.c +++ b/lib/consoles.c @@ -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; } /*