Skip to content

Commit

Permalink
Merge tag 'timers-urgent-2020-04-19' of git://git.kernel.org/pub/scm/…
Browse files Browse the repository at this point in the history
…linux/kernel/git/tip/tip

Pull time namespace fix from Thomas Gleixner:
 "An update for the proc interface of time namespaces: Use symbolic
  names instead of clockid numbers. The usability nuisance of numbers
  was noticed by Michael when polishing the man page"

* tag 'timers-urgent-2020-04-19' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  proc, time/namespace: Show clock symbolic names in /proc/pid/timens_offsets
  • Loading branch information
torvalds committed Apr 19, 2020
2 parents b737458 + 94d440d commit 3e0dea5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 13 additions & 1 deletion fs/proc/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ static ssize_t timens_offsets_write(struct file *file, const char __user *buf,
noffsets = 0;
for (pos = kbuf; pos; pos = next_line) {
struct proc_timens_offset *off = &offsets[noffsets];
char clock[10];
int err;

/* Find the end of line and ensure we don't look past it */
Expand All @@ -1584,10 +1585,21 @@ static ssize_t timens_offsets_write(struct file *file, const char __user *buf,
next_line = NULL;
}

err = sscanf(pos, "%u %lld %lu", &off->clockid,
err = sscanf(pos, "%9s %lld %lu", clock,
&off->val.tv_sec, &off->val.tv_nsec);
if (err != 3 || off->val.tv_nsec >= NSEC_PER_SEC)
goto out;

clock[sizeof(clock) - 1] = 0;
if (strcmp(clock, "monotonic") == 0 ||
strcmp(clock, __stringify(CLOCK_MONOTONIC)) == 0)
off->clockid = CLOCK_MONOTONIC;
else if (strcmp(clock, "boottime") == 0 ||
strcmp(clock, __stringify(CLOCK_BOOTTIME)) == 0)
off->clockid = CLOCK_BOOTTIME;
else
goto out;

noffsets++;
if (noffsets == ARRAY_SIZE(offsets)) {
if (next_line)
Expand Down
15 changes: 14 additions & 1 deletion kernel/time/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,20 @@ static struct user_namespace *timens_owner(struct ns_common *ns)

static void show_offset(struct seq_file *m, int clockid, struct timespec64 *ts)
{
seq_printf(m, "%d %lld %ld\n", clockid, ts->tv_sec, ts->tv_nsec);
char *clock;

switch (clockid) {
case CLOCK_BOOTTIME:
clock = "boottime";
break;
case CLOCK_MONOTONIC:
clock = "monotonic";
break;
default:
clock = "unknown";
break;
}
seq_printf(m, "%-10s %10lld %9ld\n", clock, ts->tv_sec, ts->tv_nsec);
}

void proc_timens_show_offsets(struct task_struct *p, struct seq_file *m)
Expand Down

0 comments on commit 3e0dea5

Please sign in to comment.