Skip to content

Commit 94d440d

Browse files
avaginKAGA-KOKO
authored andcommitted
proc, time/namespace: Show clock symbolic names in /proc/pid/timens_offsets
Michael Kerrisk suggested to replace numeric clock IDs with symbolic names. Now the content of these files looks like this: $ cat /proc/774/timens_offsets monotonic 864000 0 boottime 1728000 0 For setting offsets, both representations of clocks (numeric and symbolic) can be used. As for compatibility, it is acceptable to change things as long as userspace doesn't care. The format of timens_offsets files is very new and there are no userspace tools yet which rely on this format. But three projects crun, util-linux and criu rely on the interface of setting time offsets and this is why it's required to continue supporting the numeric clock IDs on write. Fixes: 04a8682 ("fs/proc: Introduce /proc/pid/timens_offsets") Suggested-by: Michael Kerrisk <[email protected]> Signed-off-by: Andrei Vagin <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Michael Kerrisk <[email protected]> Acked-by: Michael Kerrisk <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Eric W. Biederman <[email protected]> Cc: Dmitry Safonov <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 8f3d9f3 commit 94d440d

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)