diff options
-rw-r--r-- | drivers/char/tty_io.c | 28 | ||||
-rw-r--r-- | fs/proc/array.c | 4 | ||||
-rw-r--r-- | include/linux/tty.h | 1 |
3 files changed, 31 insertions, 2 deletions
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index c8aa318eaa18..2460c4c76161 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c | |||
@@ -3174,6 +3174,27 @@ unlock: | |||
3174 | } | 3174 | } |
3175 | 3175 | ||
3176 | /** | 3176 | /** |
3177 | * tty_get_pgrp - return a ref counted pgrp pid | ||
3178 | * @tty: tty to read | ||
3179 | * | ||
3180 | * Returns a refcounted instance of the pid struct for the process | ||
3181 | * group controlling the tty. | ||
3182 | */ | ||
3183 | |||
3184 | struct pid *tty_get_pgrp(struct tty_struct *tty) | ||
3185 | { | ||
3186 | unsigned long flags; | ||
3187 | struct pid *pgrp; | ||
3188 | |||
3189 | spin_lock_irqsave(&tty->ctrl_lock, flags); | ||
3190 | pgrp = get_pid(tty->pgrp); | ||
3191 | spin_unlock_irqrestore(&tty->ctrl_lock, flags); | ||
3192 | |||
3193 | return pgrp; | ||
3194 | } | ||
3195 | EXPORT_SYMBOL_GPL(tty_get_pgrp); | ||
3196 | |||
3197 | /** | ||
3177 | * tiocgpgrp - get process group | 3198 | * tiocgpgrp - get process group |
3178 | * @tty: tty passed by user | 3199 | * @tty: tty passed by user |
3179 | * @real_tty: tty side of the tty pased by the user if a pty else the tty | 3200 | * @real_tty: tty side of the tty pased by the user if a pty else the tty |
@@ -3187,13 +3208,18 @@ unlock: | |||
3187 | 3208 | ||
3188 | static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) | 3209 | static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) |
3189 | { | 3210 | { |
3211 | struct pid *pid; | ||
3212 | int ret; | ||
3190 | /* | 3213 | /* |
3191 | * (tty == real_tty) is a cheap way of | 3214 | * (tty == real_tty) is a cheap way of |
3192 | * testing if the tty is NOT a master pty. | 3215 | * testing if the tty is NOT a master pty. |
3193 | */ | 3216 | */ |
3194 | if (tty == real_tty && current->signal->tty != real_tty) | 3217 | if (tty == real_tty && current->signal->tty != real_tty) |
3195 | return -ENOTTY; | 3218 | return -ENOTTY; |
3196 | return put_user(pid_vnr(real_tty->pgrp), p); | 3219 | pid = tty_get_pgrp(real_tty); |
3220 | ret = put_user(pid_vnr(pid), p); | ||
3221 | put_pid(pid); | ||
3222 | return ret; | ||
3197 | } | 3223 | } |
3198 | 3224 | ||
3199 | /** | 3225 | /** |
diff --git a/fs/proc/array.c b/fs/proc/array.c index b07a71002f2f..c135cbdd9127 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c | |||
@@ -429,7 +429,9 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, | |||
429 | struct signal_struct *sig = task->signal; | 429 | struct signal_struct *sig = task->signal; |
430 | 430 | ||
431 | if (sig->tty) { | 431 | if (sig->tty) { |
432 | tty_pgrp = pid_nr_ns(sig->tty->pgrp, ns); | 432 | struct pid *pgrp = tty_get_pgrp(sig->tty); |
433 | tty_pgrp = pid_nr_ns(pgrp, ns); | ||
434 | put_pid(pgrp); | ||
433 | tty_nr = new_encode_dev(tty_devnum(sig->tty)); | 435 | tty_nr = new_encode_dev(tty_devnum(sig->tty)); |
434 | } | 436 | } |
435 | 437 | ||
diff --git a/include/linux/tty.h b/include/linux/tty.h index 381085e45cca..2699298b00ef 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h | |||
@@ -297,6 +297,7 @@ extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp, | |||
297 | extern void tty_write_message(struct tty_struct *tty, char *msg); | 297 | extern void tty_write_message(struct tty_struct *tty, char *msg); |
298 | 298 | ||
299 | extern int is_current_pgrp_orphaned(void); | 299 | extern int is_current_pgrp_orphaned(void); |
300 | extern struct pid *tty_get_pgrp(struct tty_struct *tty); | ||
300 | extern int is_ignored(int sig); | 301 | extern int is_ignored(int sig); |
301 | extern int tty_signal(int sig, struct tty_struct *tty); | 302 | extern int tty_signal(int sig, struct tty_struct *tty); |
302 | extern void tty_hangup(struct tty_struct * tty); | 303 | extern void tty_hangup(struct tty_struct * tty); |