@@ -104,6 +104,10 @@ struct nlconfig_t {
104
104
/* Idmap sources opened outside the container userns which will be id mapped. */
105
105
char * idmapsources ;
106
106
size_t idmapsources_len ;
107
+
108
+ /* Time NS offsets. */
109
+ char * timensoffset ;
110
+ size_t timensoffset_len ;
107
111
};
108
112
109
113
/*
@@ -122,6 +126,7 @@ struct nlconfig_t {
122
126
#define GIDMAPPATH_ATTR 27289
123
127
#define MOUNT_SOURCES_ATTR 27290
124
128
#define IDMAP_SOURCES_ATTR 27291
129
+ #define TIMENSOFFSET_ATTR 27292
125
130
126
131
/*
127
132
* Use the raw syscall for versions of glibc which don't include a function for
@@ -351,6 +356,8 @@ static int nsflag(char *name)
351
356
return CLONE_NEWUSER ;
352
357
else if (!strcmp (name , "uts" ))
353
358
return CLONE_NEWUTS ;
359
+ else if (!strcmp (name , "time" ))
360
+ return CLONE_NEWTIME ;
354
361
355
362
/* If we don't recognise a name, fallback to 0. */
356
363
return 0 ;
@@ -445,6 +452,10 @@ static void nl_parse(int fd, struct nlconfig_t *config)
445
452
config -> idmapsources = current ;
446
453
config -> idmapsources_len = payload_len ;
447
454
break ;
455
+ case TIMENSOFFSET_ATTR :
456
+ config -> timensoffset = current ;
457
+ config -> timensoffset_len = payload_len ;
458
+ break ;
448
459
default :
449
460
bail ("unknown netlink message type %d" , nlattr -> nla_type );
450
461
}
@@ -747,6 +758,17 @@ void receive_idmapsources(int sockfd)
747
758
receive_fd_sources (sockfd , "_LIBCONTAINER_IDMAP_FDS" );
748
759
}
749
760
761
+ static void update_timens (char * map , size_t map_len )
762
+ {
763
+ if (map == NULL || map_len == 0 )
764
+ return ;
765
+ write_log (DEBUG , "update /proc/self/timens_offsets to '%s'" , map );
766
+ if (write_file (map , map_len , "/proc/self/timens_offsets" ) < 0 ) {
767
+ if (errno != EPERM )
768
+ bail ("failed to update /proc/self/timens_offsets" );
769
+ }
770
+ }
771
+
750
772
void nsexec (void )
751
773
{
752
774
int pipenum ;
@@ -1185,6 +1207,11 @@ void nsexec(void)
1185
1207
bail ("failed to sync with parent: SYNC_MOUNT_IDMAP_ACK: got %u" , s );
1186
1208
}
1187
1209
1210
+ /*
1211
+ * set boottime and monotonic timens offsets.
1212
+ */
1213
+ update_timens (config .timensoffset , config .timensoffset_len );
1214
+
1188
1215
/*
1189
1216
* TODO: What about non-namespace clone flags that we're dropping here?
1190
1217
*
0 commit comments