Skip to content
This repository
Browse code

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

Signed-off-by: Karel Zak <kzak@redhat.com>
  • Loading branch information...
commit 507341f83296f0e7786d8bfbb5d77a4de1666f3f 1 parent 6608366
Karel Zak authored
3  include/ttyutils.h
@@ -48,7 +48,8 @@ struct chardata {
48 48 } while (0)
49 49
50 50 extern int get_terminal_width(void);
51   -extern int get_terminal_name(const char **path, const char **name, const char **number);
  51 +extern int get_terminal_name(int fd, const char **path, const char **name,
  52 + const char **number);
52 53
53 54 #define UL_TTY_KEEPCFLAGS (1 << 1)
54 55 #define UL_TTY_UTF8 (1 << 2)
5 lib/ttyutils.c
@@ -42,7 +42,8 @@ int get_terminal_width(void)
42 42 return 0;
43 43 }
44 44
45   -int get_terminal_name(const char **path,
  45 +int get_terminal_name(int fd,
  46 + const char **path,
46 47 const char **name,
47 48 const char **number)
48 49 {
@@ -56,7 +57,7 @@ int get_terminal_name(const char **path,
56 57 if (number)
57 58 *number = NULL;
58 59
59   - tty = ttyname(STDERR_FILENO);
  60 + tty = ttyname(fd);
60 61 if (!tty)
61 62 return -1;
62 63 if (path)
2  login-utils/login.c
@@ -356,7 +356,7 @@ static void init_tty(struct login_context *cxt)
356 356
357 357 cxt->tty_mode = (mode_t) getlogindefs_num("TTYPERM", TTY_MODE);
358 358
359   - get_terminal_name(&cxt->tty_path, &cxt->tty_name, &cxt->tty_number);
  359 + get_terminal_name(0, &cxt->tty_path, &cxt->tty_name, &cxt->tty_number);
360 360
361 361 /*
362 362 * In case login is suid it was possible to use a hardlink as stdin
4 login-utils/su-common.c
@@ -158,7 +158,7 @@ log_syslog(struct passwd const *pw, bool successful)
158 158 old_user = pwd ? pwd->pw_name : "";
159 159 }
160 160
161   - if (get_terminal_name(NULL, &tty, NULL) == 0 && tty)
  161 + if (get_terminal_name(STDERR_FILENO, NULL, &tty, NULL) == 0 && tty)
162 162 tty = "none";
163 163
164 164 openlog (program_invocation_short_name, 0 , LOG_AUTH);
@@ -185,7 +185,7 @@ static void log_btmp(struct passwd const *pw)
185 185 pw && pw->pw_name ? pw->pw_name : "(unknown)",
186 186 sizeof(ut.ut_user));
187 187
188   - get_terminal_name(NULL, &tty_name, &tty_num);
  188 + get_terminal_name(STDERR_FILENO, NULL, &tty_name, &tty_num);
189 189 if (tty_num)
190 190 xstrncpy(ut.ut_id, tty_num, sizeof(ut.ut_id));
191 191 if (tty_name)

0 comments on commit 507341f

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