~ubuntu-branches/ubuntu/maverick/krb5/maverick

« back to all changes in this revision

Viewing changes to src/util/pty/open_ctty.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman, Russ Allbery, Sam Hartman
  • Date: 2008-08-21 10:41:41 UTC
  • mfrom: (11.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080821104141-a0f9c4o4cpo8xd0o
Tags: 1.6.dfsg.4~beta1-4
[ Russ Allbery ]
* Translation updates:
  - Swedish, thanks Martin Bagge.  (Closes: #487669, #491774)
  - Italian, thanks Luca Monducci.  (Closes: #493962)

[ Sam Hartman ]
* Translation Updates:
    - Dutch, Thanks Vincent Zweije, Closes: #495733

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * pty_open_ctty: Open and establish controlling terminal.
3
 
 *
4
 
 * Copyright 1995, 1996 by the Massachusetts Institute of Technology.
5
 
 *
6
 
 * Permission to use, copy, modify, and distribute this software and
7
 
 * its documentation for any purpose and without fee is hereby
8
 
 * granted, provided that the above copyright notice appear in all
9
 
 * copies and that both that copyright notice and this permission
10
 
 * notice appear in supporting documentation, and that the name of
11
 
 * M.I.T. not be used in advertising or publicity pertaining to
12
 
 * distribution of the software without specific, written prior
13
 
 * permission.  Furthermore if you modify this software you must label
14
 
 * your software as modified software and not distribute it in such a
15
 
 * fashion that it might be confused with the original M.I.T. software.
16
 
 * M.I.T. makes no representations about the suitability
17
 
 * of this software for any purpose.  It is provided "as is" without
18
 
 * express or implied warranty.
19
 
 * 
20
 
 */
21
 
 
22
 
#include "com_err.h"
23
 
#include "libpty.h"
24
 
#include "pty-int.h"
25
 
 
26
 
/* 
27
 
 * This function will be called twice.  The first time it will acquire
28
 
 * a controlling terminal from which to vhangup() or revoke() (see
29
 
 * comments in open_slave.c); the second time, it will be to open the
30
 
 * actual slave device for use by the application.  We no longer call
31
 
 * ptyint_void_association(), as that will be called in
32
 
 * pty_open_slave() to avoid spurious calls to setsid(), etc.
33
 
 *
34
 
 * It is assumed that systems where vhangup() exists and does break
35
 
 * the ctty association will allow the slave to be re-acquired as the
36
 
 * ctty.  Also, if revoke() or vhangup() doesn't break the ctty
37
 
 * association, we assume that we can successfully reopen the slave.
38
 
 *
39
 
 * This function doesn't check whether we actually acquired the ctty;
40
 
 * we assume that the caller will check that, or that it doesn't
41
 
 * matter in the particular case.
42
 
 */
43
 
long
44
 
pty_open_ctty(const char *slave, int *fd)
45
 
{
46
 
 
47
 
#ifdef ultrix
48
 
    /*
49
 
     * The Ultrix (and other BSD tty drivers) require the process
50
 
     * group to be zero, in order to acquire the new tty as a
51
 
     * controlling tty.  This may actually belong in
52
 
     * ptyint_void_association().
53
 
     */
54
 
    (void) setpgrp(0, 0);
55
 
#endif
56
 
    *fd = open(slave, O_RDWR);
57
 
    if (*fd < 0)
58
 
        return PTY_OPEN_SLAVE_OPENFAIL;
59
 
#ifdef ultrix
60
 
    setpgrp(0, getpid());
61
 
#endif
62
 
 
63
 
#ifdef TIOCSCTTY
64
 
    ioctl(*fd, TIOCSCTTY, 0); /* Don't check return.*/
65
 
#endif /* TIOCSTTY */
66
 
    return 0;
67
 
}