Re: [PATCH 07/12] write: add control structure to clarify what is going on

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

 



On Mon, May 09, 2016 at 10:27:23PM +0100, Sami Kerola wrote:
> @@ -339,39 +347,42 @@ int main(int argc, char **argv)
>  		 * term_chk() will put "/dev/" in front, so remove that
>  		 * part.
>  		 */
> -		if (!strncmp(mytty, "/dev/", 5))
> -			mytty += 5;
> -		if (term_chk(mytty, &msgsok, NULL, 1))
> +		if (!strncmp(ctl.src_tty, "/dev/", 5))
> +			memmove(ctl.src_tty, ctl.src_tty + 5, strlen(ctl.src_tty + 5) + 1);
> +		if (term_chk(ctl.src_tty, &msgsok, NULL, 1))

The patch promises that it replaces variables with control struct, but
here it does something more. Don't do that. There is no memmove() in
the original code. 

Please, if you want to optimize the code than do it in another patch.

and btw: we have lib/ttyutils.c: get_terminal_name(), it seems usable
for this use-case, but...

> -		if (!strncmp(argv[2], "/dev/", 5))
> -			argv[2] += 5;
> -		if (utmp_chk(argv[1], argv[2]))
> +		ctl.dst_login = argv[1];
> +		xstrncpy(ctl.dst_tty, argv[2], sizeof(ctl.dst_tty));
> +		if (!strncmp(ctl.dst_tty, "/dev/", 5))
> +			memmove(ctl.dst_tty, ctl.dst_tty + 5, strlen(ctl.dst_tty + 5) + 1);

... maybe we need xttyname() to return a name (no path) and in
allocated string for programs where we call ttyname() more times.

    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