리눅스 ttyslot() 함수에 대한 질문입니다.

anaud2의 이미지

안녕하세요

다른 사람의 telnet 소스를 고쳐서 저희 회사에 필요한 부분으로 바꾸기 위해 열심히 소스 분석을 하고 있는 직장신입니다.ㅠ
개인적으로 소스 분석은 너무 싫으네요 배우는 부분도 적고 시간에 쫓기구...
ttyslot()라는 부분이 소스중에 있는데요 man페이지는 있지만 해석이 좀 부족해서..인터넷을 찾아봐도 영문서 밖에 없네요

짧게 해석한 부분이라곤 /etc/ttys 라는 파일을 사용한다고 하는데 제 리눅스에는 그부분이 없거든요 그래서 실행이 안되서 오류값을 뱉는지...저부분이 막혀서 소스를 가동을 시켜봐도 안되네요 일단 소스가 어케 돌아가는지 알아야 좀 소스분석에 좋을꺼같은데...
간략하게나마 사용법을 아시는분은 답변을 좀 부탁드리겠습니다.
영어공부에 매진하겠습니다.ㅠ 개발자는 영어가 필수네요.ㅠ

NAME
ttyslot - find the slot of the current user's terminal in some file

SYNOPSIS
#include /* on BSD-like systems */
#include /* on SYSV-like systems */

int ttyslot(void);

DESCRIPTION
The legacy function ttyslot() returns the index of the current user's entry in some file.

Now "What file?" you ask. Well, let's first look at some history.

Ancient History
There used to be a file /etc/ttys in Unix V6, that was read by the init(8) program to find out what to do with each termi-
nal line. Each line consisted of three characters. The first character was either '0' or '1', where '0' meant "ignore".
The second character denoted the terminal: '8' stood for "/dev/tty8". The third character was an argument to getty(8)
indicating the sequence of line speeds to try ('-' was: start trying 110 baud). Thus a typical line was "18-". A hang on
some line was solved by changing the '1' to a '0', signalling init, changing back again, and signalling init again.

In Unix V7 the format was changed: here the second character was the argument to getty(8) indicating the sequence of line
speeds to try ('0' was: cycle through 300-1200-150-110 baud; '4' was for the on-line console DECwriter) while the rest of
the line contained the name of the tty. Thus a typical line was "14console".

Later systems have more elaborate syntax. SYSV-like systems have /etc/inittab instead.

Ancient History (2)
On the other hand, there is the file /etc/utmp listing the people currently logged in. It is maintained by login(8). It
has a fixed size, and the appropriate index in the file was determined by login(8) using the ttyslot() call to find the
number of the line in /etc/ttys (counting from 1).

The semantics of ttyslot
Thus, the function ttyslot() returns the index of the controlling terminal of the current process in the file /etc/ttys,
and that is (usually) the same as the index of the entry for the current user in the file /etc/utmp. BSD still has the
/etc/ttys file, but SYSV-like systems do not, and hence cannot refer to it. Thus, on such systems the documentation says
that ttyslot() returns the current user's index in the user accounting data base.

RETURN VALUE
If successful, this function returns the slot number. On error (e.g., if none of the file descriptors 0, 1 or 2 is asso-
ciated with a terminal that occurs in this data base) it returns 0 on Unix V6 and V7 and BSD-like systems, but -1 on SYSV-
like systems.

NOTES
The utmp file is found various places on various systems, such as /etc/utmp, /var/adm/utmp, /var/run/utmp.

The glibc2 implementation of this function reads the file _PATH_TTYS, defined in as "/etc/ttys". It returns 0
on error. Since Linux systems do not usually have "/etc/ttys", it will always return 0.

Minix also has fttyslot(fd).

HISTORY
ttyslot() appeared in Unix V7.

CONFORMS TO
XPG2. Legacy in SUSv2. Deleted in SUSv3. SUSv2 requires -1 on error.

SEE ALSO
getttyent(3), ttyname(3), utmp(5)

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.