bug-gnulib
[Top][All Lists]
Advanced

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

new module 'login_tty'


From: Bruno Haible
Subject: new module 'login_tty'
Date: Mon, 22 Mar 2010 02:13:01 +0100
User-agent: KMail/1.9.9

Here I'm adding a replacement for login_tty. Tested on Solaris.


2010-03-21  Bruno Haible  <address@hidden>

        New module 'login_tty'.
        * lib/login_tty.c: New file.
        * m4/pty.m4 (gl_FUNC_LOGIN_TTY): New macro.
        * modules/login_tty: New file.
        * doc/glibc-functions/login_tty.texi: Mention the new module.

=============================== lib/login_tty.c ===============================
/* Assign a given terminal as controlling terminal and as standard input,
   standard output, standard error of the current process.
   Copyright (C) 2010 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   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, see <http://www.gnu.org/licenses/>.  */

#include <config.h>

/* Currently no specification header.  */

#include <fcntl.h>
#include <unistd.h>

int
login_tty (int slave_fd)
{
  int i;

  /* Create a new session.  */
  setsid ();

  /* Make fd the controlling terminal for the current process.
     On Solaris: A terminal becomes the controlling terminal of a session
     if it is being open()ed, at a moment when
       1. it is not already the controlling terminal of some session, and
       2. the process that open()s it is a session leader that does not have
          a controlling terminal.
     We assume condition 1, try to ensure condition 2, and then open() it.  */
  for (i = 0; i < 3; i++)
    if (i != slave_fd)
      close (i);
  {
    char *slave_name;
    int dummy_fd;

    slave_name = ttyname (slave_fd);
    if (slave_name == NULL)
      return -1;
    dummy_fd = open (slave_name, O_RDWR);
    if (dummy_fd < 0)
      return -1;
    close (dummy_fd);
  }

  /* Assign fd to the standard input, standard output, and standardd error of
     the current process.  */
  for (i = 0; i < 3; i++)
    if (slave_fd != i)
      if (dup2 (slave_fd, i) < 0)
        return -1;
  if (slave_fd >= 3)
    close (slave_fd);

  return 0;
}
============================== modules/login_tty ==============================
Description:
login_tty() function: Assign a given terminal as controlling terminal and as
standard input, standard output, standard error of the current process.

Files:
lib/login_tty.c
m4/pty.m4

Depends-on:

configure.ac:
gl_FUNC_LOGIN_TTY
gl_PTY_MODULE_INDICATOR([login_tty])

Makefile.am:

Include:
extern int login_tty (int);

Link:
$(PTY_LIB)

License:
LGPL

Maintainer:
Bruno Haible
===============================================================================
--- m4/pty.m4.orig      Mon Mar 22 02:11:10 2010
+++ m4/pty.m4   Mon Mar 22 02:07:10 2010
@@ -1,4 +1,4 @@
-# pty.m4 serial 3
+# pty.m4 serial 4
 dnl Copyright (C) 2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -120,3 +120,13 @@
     AC_CHECK_FUNCS([_getpty posix_openpt])
   fi
 ])
+
+AC_DEFUN([gl_FUNC_LOGIN_TTY],
+[
+  AC_REQUIRE([gl_PTY_LIB])
+
+  AC_CHECK_FUNCS_ONCE([login_tty])
+  if test $ac_cv_func_login_tty = no; then
+    AC_LIBOBJ([login_tty])
+  fi
+])
--- doc/glibc-functions/login_tty.texi.orig     Mon Mar 22 02:11:10 2010
+++ doc/glibc-functions/login_tty.texi  Mon Mar 22 02:11:03 2010
@@ -2,14 +2,10 @@
 @subsection @code{login_tty}
 @findex login_tty
 
-Gnulib module: ---
+Gnulib module: login_tty
 
 Portability problems fixed by Gnulib:
 @itemize
address@hidden itemize
-
-Portability problems not fixed by Gnulib:
address@hidden
 @item
 This function is missing on some platforms:
 AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, mingw.
@@ -18,6 +14,10 @@
 glibc 2.3.6, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8.
 It is available without link options on other platforms:
 MacOS X 10.3, OSF/1 5.1, Cygwin, Interix 3.5.
address@hidden itemize
+
+Portability problems not fixed by Gnulib:
address@hidden
 @item
 This function is declared in @code{<utmp.h>} on glibc, Cygwin,
 in @code{<util.h>} on MacOS X 10.3, NetBSD 3.0, OpenBSD 3.8,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]