Skip to content
Browse files

lib/tty: don't hardcode terminal fd in get_terminal_name()

Signed-off-by: Karel Zak <kzak@redhat.com>
  • Loading branch information...
1 parent 6608366 commit 507341f83296f0e7786d8bfbb5d77a4de1666f3f @karelzak committed May 13, 2013
Showing with 8 additions and 6 deletions.
  1. +2 −1 include/ttyutils.h
  2. +3 −2 lib/ttyutils.c
  3. +1 −1 login-utils/login.c
  4. +2 −2 login-utils/su-common.c
View
3 include/ttyutils.h
@@ -48,7 +48,8 @@ struct chardata {
} while (0)
extern int get_terminal_width(void);
-extern int get_terminal_name(const char **path, const char **name, const char **number);
+extern int get_terminal_name(int fd, const char **path, const char **name,
+ const char **number);
#define UL_TTY_KEEPCFLAGS (1 << 1)
#define UL_TTY_UTF8 (1 << 2)
View
5 lib/ttyutils.c
@@ -42,7 +42,8 @@ int get_terminal_width(void)
return 0;
}
-int get_terminal_name(const char **path,
+int get_terminal_name(int fd,
+ const char **path,
const char **name,
const char **number)
{
@@ -56,7 +57,7 @@ int get_terminal_name(const char **path,
if (number)
*number = NULL;
- tty = ttyname(STDERR_FILENO);
+ tty = ttyname(fd);
if (!tty)
return -1;
if (path)
View
2 login-utils/login.c
@@ -356,7 +356,7 @@ static void init_tty(struct login_context *cxt)
cxt->tty_mode = (mode_t) getlogindefs_num("TTYPERM", TTY_MODE);
- get_terminal_name(&cxt->tty_path, &cxt->tty_name, &cxt->tty_number);
+ get_terminal_name(0, &cxt->tty_path, &cxt->tty_name, &cxt->tty_number);
/*
* In case login is suid it was possible to use a hardlink as stdin
View
4 login-utils/su-common.c
@@ -158,7 +158,7 @@ log_syslog(struct passwd const *pw, bool successful)
old_user = pwd ? pwd->pw_name : "";
}
- if (get_terminal_name(NULL, &tty, NULL) == 0 && tty)
+ if (get_terminal_name(STDERR_FILENO, NULL, &tty, NULL) == 0 && tty)
tty = "none";
openlog (program_invocation_short_name, 0 , LOG_AUTH);
@@ -185,7 +185,7 @@ static void log_btmp(struct passwd const *pw)
pw && pw->pw_name ? pw->pw_name : "(unknown)",
sizeof(ut.ut_user));
- get_terminal_name(NULL, &tty_name, &tty_num);
+ get_terminal_name(STDERR_FILENO, NULL, &tty_name, &tty_num);
if (tty_num)
xstrncpy(ut.ut_id, tty_num, sizeof(ut.ut_id));
if (tty_name)

0 comments on commit 507341f

Please sign in to comment.
Something went wrong with that request. Please try again.