@@ -95,6 +95,13 @@ struct nlconfig_t {
95
95
/* Mount sources opened outside the container userns. */
96
96
char * mountsources ;
97
97
size_t mountsources_len ;
98
+
99
+ /* Time NS settings for boottime and monotonic */
100
+ char * monotonic ;
101
+ size_t monotonic_len ;
102
+
103
+ char * boottime ;
104
+ size_t boottime_len ;
98
105
};
99
106
100
107
/*
@@ -112,6 +119,8 @@ struct nlconfig_t {
112
119
#define UIDMAPPATH_ATTR 27288
113
120
#define GIDMAPPATH_ATTR 27289
114
121
#define MOUNT_SOURCES_ATTR 27290
122
+ #define BOOTTIME_NS_ATTR 27291
123
+ #define MONOTONIC_NS_ATTR 27292
115
124
116
125
/*
117
126
* Use the raw syscall for versions of glibc which don't include a function for
@@ -341,6 +350,8 @@ static int nsflag(char *name)
341
350
return CLONE_NEWUSER ;
342
351
else if (!strcmp (name , "uts" ))
343
352
return CLONE_NEWUTS ;
353
+ else if (!strcmp (name , "time" ))
354
+ return CLONE_NEWTIME ;
344
355
345
356
/* If we don't recognise a name, fallback to 0. */
346
357
return 0 ;
@@ -431,6 +442,14 @@ static void nl_parse(int fd, struct nlconfig_t *config)
431
442
config -> mountsources = current ;
432
443
config -> mountsources_len = payload_len ;
433
444
break ;
445
+ case BOOTTIME_NS_ATTR :
446
+ config -> boottime = current ;
447
+ config -> boottime_len = payload_len ;
448
+ break ;
449
+ case MONOTONIC_NS_ATTR :
450
+ config -> monotonic = current ;
451
+ config -> monotonic_len = payload_len ;
452
+ break ;
434
453
default :
435
454
bail ("unknown netlink message type %d" , nlattr -> nla_type );
436
455
}
@@ -641,6 +660,17 @@ void try_unshare(int flags, const char *msg)
641
660
bail ("failed to unshare %s" , msg );
642
661
}
643
662
663
+ static void update_timens (char * map , size_t map_len )
664
+ {
665
+ if (map == NULL || map_len == 0 )
666
+ return ;
667
+ write_log (DEBUG , "update /proc/self/timens_offsets to '%s'" , map );
668
+ if (write_file (map , map_len , "/proc/self/timens_offsets" ) < 0 ) {
669
+ if (errno != EPERM )
670
+ bail ("failed to update /proc/self/timens_offsets" );
671
+ }
672
+ }
673
+
644
674
void nsexec (void )
645
675
{
646
676
int pipenum ;
@@ -1053,6 +1083,14 @@ void nsexec(void)
1053
1083
bail ("failed to sync with parent: SYNC_MOUNTSOURCES_ACK: got %u" , s );
1054
1084
}
1055
1085
1086
+ /*
1087
+ * Update timens offsets
1088
+ * set boottime and monotonic offsets
1089
+ */
1090
+ write_log (DEBUG , "set timens offsets %s" , config .boottime );
1091
+ update_timens (config .boottime , config .boottime_len );
1092
+ update_timens (config .monotonic , config .monotonic_len );
1093
+
1056
1094
/*
1057
1095
* TODO: What about non-namespace clone flags that we're dropping here?
1058
1096
*
0 commit comments