This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v4] linux ttyname and ttyname_r: do not return wrong results


Appended to the mail you'll find a program that'll allow you to test the changes
to ttyname() and ttyname_r() on a patched glibc. Are we good about the patch as
it stands?

On Fri, Jan 27, 2017 at 03:59:58PM +0100, Christian Brauner wrote:
> Hi,
> 
> Last we've talked this patches was ready to merge. The only thing left to do was
> to sign an FSF agreement. I did and it is fully processed. If you need to see a
> PDF I can send it to a specific person privately per mail. I hope we're good to
> go now. :)
> 
> I've taken over this patch from Serge who has been informed and is CCed on this
> thread. There are no significant functional changes. As requested the following
> this have been changed:
> 
> - remove obsolete comment in ttyname_r.c
> - move is_pty() to common header file and mark as static inline
> 
> Christian
> 
> Christian Brauner (1):
>   linux ttyname and ttyname_r: do not return wrong results
> 
>  ChangeLog                           | 12 ++++++++++++
>  sysdeps/unix/sysv/linux/ttyname.c   | 16 ++++++++++++----
>  sysdeps/unix/sysv/linux/ttyname.h   | 35 +++++++++++++++++++++++++++++++++++
>  sysdeps/unix/sysv/linux/ttyname_r.c | 17 +++++++++++++----
>  4 files changed, 72 insertions(+), 8 deletions(-)
>  create mode 100644 sysdeps/unix/sysv/linux/ttyname.h
> 
> -- 
> 2.11.0
/*
 *
 * Copyright © 2017 Christian Brauner <christian.brauner@ubuntu.com>.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

/* Test whether ttyname() */
int main(int argc, char *argv[])
{
	int fd;
	char buf[4096];

	fd = open("/proc/self/fd/0", O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "Could not open \"/proc/self/fd/0\": %s.\n",
			strerror(errno));
		exit(EXIT_FAILURE);
	}

	if (!ttyname(fd)) {
		/* COMMENT(brauner): ENODEV will only be set by a patched
		 * glibc.
		 */
		if (errno == ENODEV) {
			printf("ttyname(): The pty device might exist in a "
			       "different "
			       "namespace: %s\n",
			       strerror(errno));
		} else {
			exit(EXIT_FAILURE);
		}
	}

	if (ttyname_r(fd, buf, sizeof(buf))) {
		/* COMMENT(brauner): ENODEV will only be set by a patched
		 * glibc.
		 */
		if (errno == ENODEV) {
			printf("ttyname_r(): The pty device might exist in a "
			       "different "
			       "namespace: %s\n",
			       strerror(errno));
		} else {
			exit(EXIT_FAILURE);
		}
	}

	exit(EXIT_SUCCESS);
}

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]