Skip to content

Commit 3e0dea5

Browse files
committed
Merge tag 'timers-urgent-2020-04-19' of git://git.kernel.org/pub/scm/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
2 parents b737458 + 94d440d commit 3e0dea5

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

fs/proc/base.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,7 @@ static ssize_t timens_offsets_write(struct file *file, const char __user *buf,
15731573
noffsets = 0;
15741574
for (pos = kbuf; pos; pos = next_line) {
15751575
struct proc_timens_offset *off = &offsets[noffsets];
1576+
char clock[10];
15761577
int err;
15771578

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

1587-
err = sscanf(pos, "%u %lld %lu", &off->clockid,
1588+
err = sscanf(pos, "%9s %lld %lu", clock,
15881589
&off->val.tv_sec, &off->val.tv_nsec);
15891590
if (err != 3 || off->val.tv_nsec >= NSEC_PER_SEC)
15901591
goto out;
1592+
1593+
clock[sizeof(clock) - 1] = 0;
1594+
if (strcmp(clock, "monotonic") == 0 ||
1595+
strcmp(clock, __stringify(CLOCK_MONOTONIC)) == 0)
1596+
off->clockid = CLOCK_MONOTONIC;
1597+
else if (strcmp(clock, "boottime") == 0 ||
1598+
strcmp(clock, __stringify(CLOCK_BOOTTIME)) == 0)
1599+
off->clockid = CLOCK_BOOTTIME;
1600+
else
1601+
goto out;
1602+
15911603
noffsets++;
15921604
if (noffsets == ARRAY_SIZE(offsets)) {
15931605
if (next_line)

kernel/time/namespace.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,20 @@ static struct user_namespace *timens_owner(struct ns_common *ns)
338338

339339
static void show_offset(struct seq_file *m, int clockid, struct timespec64 *ts)
340340
{
341-
seq_printf(m, "%d %lld %ld\n", clockid, ts->tv_sec, ts->tv_nsec);
341+
char *clock;
342+
343+
switch (clockid) {
344+
case CLOCK_BOOTTIME:
345+
clock = "boottime";
346+
break;
347+
case CLOCK_MONOTONIC:
348+
clock = "monotonic";
349+
break;
350+
default:
351+
clock = "unknown";
352+
break;
353+
}
354+
seq_printf(m, "%-10s %10lld %9ld\n", clock, ts->tv_sec, ts->tv_nsec);
342355
}
343356

344357
void proc_timens_show_offsets(struct task_struct *p, struct seq_file *m)

0 commit comments

Comments
 (0)