Re: [util-linux] [PATCH 00/13] Initial import of sulogin

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 12, 2012 at 04:07:57PM +0200, Dr. Werner Fink wrote:
> +static
> +#ifdef __GNUC__
> +__attribute__((__nonnull__,__hot__))
> +#endif
> +void consalloc(char * name)
> +{
> +	struct console *restrict tail;
> +
> +	if (posix_memalign((void*)&tail, sizeof(void*), alignof(typeof(struct console))) != 0)
> +		perror("memory allocation");

 why not malloc() ?

> +
> +	tail->next = (struct console*)0;
> +	tail->tty = name;
> +
> +	tail->file = (FILE*)0;
> +	tail->flags = 0;
> +	tail->fd = -1;
> +	tail->id = concount++;
> +	tail->pid = 0;
> +	memset(&tail->tio, 0, sizeof(tail->tio));
> +	memcpy(&tail->cp, &initcp, sizeof(struct chardata));
> +
> +	if (!consoles)
> +		consoles = tail;
> +	else
> +		consoles->next = tail;
> +}

 It does not look like a list. It always update the same pointer
 consoles->next but not "consoles", so the result is list with only
 two items (first and the last item).

 If you want to create a list you have to always update two pointers
 (the "->next" and pointer to the first/last item).

    Karel



-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux