Files
glibc/termios/tcgetsid.c
T

65 lines
1.6 KiB
C
Raw Normal View History

1999-04-28 23:13:52 +00:00
/* Copyright (C) 1997, 1999 Free Software Foundation, Inc.
1997-10-26 20:13:00 +00:00
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
2001-07-06 04:58:11 +00:00
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
1997-10-26 20:13:00 +00:00
The GNU C Library 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
2001-07-06 04:58:11 +00:00
Lesser General Public License for more details.
1997-10-26 20:13:00 +00:00
2001-07-06 04:58:11 +00:00
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
1997-10-26 20:13:00 +00:00
#include <errno.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
/* Return the session ID of FD. */
pid_t
tcgetsid (fd)
int fd;
{
pid_t pgrp;
pid_t sid;
#ifdef TIOCGSID
1999-04-29 13:19:45 +00:00
static int tiocgsid_does_not_work;
1997-10-26 20:13:00 +00:00
1999-04-29 13:19:45 +00:00
if (! tiocgsid_does_not_work)
1997-10-26 20:13:00 +00:00
{
int serrno = errno;
int sid;
if (__ioctl (fd, TIOCGSID, &sid) < 0)
{
if (errno == EINVAL)
{
1999-04-29 13:19:45 +00:00
tiocgsid_does_not_work = 1;
1997-10-26 20:13:00 +00:00
__set_errno (serrno);
}
else
return (pid_t) -1;
}
else
return (pid_t) sid;
}
#endif
pgrp = tcgetpgrp (fd);
if (pgrp == -1)
return (pid_t) -1;
sid = getsid (pgrp);
if (sid == -1 && errno == ESRCH)
__set_errno (ENOTTY);
return sid;
}