Skip to content

Commit

Permalink
Include major and minor number of tty in /proc/stat
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Nov 3, 2019
1 parent 32ae8bc commit 89e3b07
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/Terminal.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "DelayedUITask.h"
#import "UserPreferences.h"
#include "fs/tty.h"
#include "fs/devices.h"

@interface Terminal () <WKScriptMessageHandler>

Expand Down Expand Up @@ -300,4 +301,4 @@ static void ios_tty_cleanup(struct tty *tty) {
.write = ios_tty_write,
.cleanup = ios_tty_cleanup,
};
DEFINE_TTY_DRIVER(ios_tty_driver, &ios_tty_ops, 64);
DEFINE_TTY_DRIVER(ios_tty_driver, &ios_tty_ops, TTY_CONSOLE_MAJOR, 64);
5 changes: 3 additions & 2 deletions fs/proc/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ static ssize_t proc_pid_stat_show(struct proc_entry *entry, char *buf) {
n += sprintf(buf + n, "%d ", task->parent ? task->parent->pid : 0);
n += sprintf(buf + n, "%d ", task->group->pgid);
n += sprintf(buf + n, "%d ", task->group->sid);
n += sprintf(buf + n, "%d ", task->group->tty ? task->group->tty->num : 0);
n += sprintf(buf + n, "%d ", task->group->tty ? task->group->tty->fg_group : 0);
struct tty *tty = task->group->tty;
n += sprintf(buf + n, "%d ", tty ? dev_make(tty->driver->major, tty->num) : 0);
n += sprintf(buf + n, "%d ", tty ? tty->fg_group : 0);
n += sprintf(buf + n, "%u ", 0); // flags

// page faults (no data available)
Expand Down
4 changes: 2 additions & 2 deletions fs/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ const struct tty_driver_ops pty_master_ops = {
.ioctl = pty_master_ioctl,
.cleanup = pty_master_cleanup,
};
DEFINE_TTY_DRIVER(pty_master, &pty_master_ops, MAX_PTYS);
DEFINE_TTY_DRIVER(pty_master, &pty_master_ops, TTY_PSEUDO_MASTER_MAJOR, MAX_PTYS);

const struct tty_driver_ops pty_slave_ops = {
.init = pty_return_eio,
.open = pty_slave_open,
.write = pty_write,
};
DEFINE_TTY_DRIVER(pty_slave, &pty_slave_ops, MAX_PTYS);
DEFINE_TTY_DRIVER(pty_slave, &pty_slave_ops, TTY_PSEUDO_SLAVE_MAJOR, MAX_PTYS);

int ptmx_open(struct fd *fd) {
int pty_num;
Expand Down
3 changes: 2 additions & 1 deletion fs/tty-real.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "kernel/calls.h"
#include "fs/tty.h"
#include "fs/devices.h"

// Only /dev/tty1 will be connected, the rest will go to a black hole.
#define REAL_TTY_NUM 1
Expand Down Expand Up @@ -130,4 +131,4 @@ struct tty_driver_ops real_tty_ops = {
.write = real_tty_write,
.cleanup = real_tty_cleanup,
};
DEFINE_TTY_DRIVER(real_tty_driver, &real_tty_ops, 64);
DEFINE_TTY_DRIVER(real_tty_driver, &real_tty_ops, TTY_CONSOLE_MAJOR, 64);
5 changes: 3 additions & 2 deletions fs/tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ struct termios_ {

struct tty_driver {
const struct tty_driver_ops *ops;
int major;
struct tty **ttys;
unsigned limit;
};

#define DEFINE_TTY_DRIVER(name, driver_ops, size) \
#define DEFINE_TTY_DRIVER(name, driver_ops, _major, size) \
static struct tty *name##_ttys[size]; \
struct tty_driver name = {.ops = driver_ops, .ttys = name##_ttys, .limit = size}
struct tty_driver name = {.ops = driver_ops, .major = _major, .ttys = name##_ttys, .limit = size}

struct tty_driver_ops {
int (*init)(struct tty *tty);
Expand Down

0 comments on commit 89e3b07

Please sign in to comment.