@@ -173,35 +173,25 @@ static int chroot_luks()
173
173
}
174
174
#endif
175
175
176
- static int create_dirs ()
176
+ static int mount_filesystems ()
177
177
{
178
- char * const DIRS [] = {"/proc" , "/sys" , "/sys/fs" , "/sys/fs/cgroup" , "/dev/pts" , "/dev/shm" };
178
+ char * const DIRS_LEVEL1 [] = {"/dev" , "/proc" , "/sys" };
179
+ char * const DIRS_LEVEL2 [] = {"/dev/pts" , "/dev/shm" };
179
180
int i ;
180
181
181
- if (access ("/dev" , F_OK ) != 0 ) {
182
- if (mkdir ("/dev" , 0755 ) < 0 && errno != EEXIST ) {
183
- printf ("Error creating directory /dev\n" );
184
- return -1 ;
185
- }
186
- if (mount ("devtmpfs" , "/dev" , "devtmpfs" ,
187
- MS_RELATIME , NULL ) < 0 ) {
188
- perror ("mount(/dev)" );
182
+ for (i = 0 ; i < 3 ; ++ i ) {
183
+ if (mkdir (DIRS_LEVEL1 [i ], 0755 ) < 0 && errno != EEXIST ) {
184
+ printf ("Error creating directory (%s)\n" , DIRS_LEVEL1 [i ]);
189
185
return -1 ;
190
186
}
191
187
}
192
188
193
- for (i = 0 ; i < 6 ; ++ i ) {
194
- if (mkdir (DIRS [i ], 0755 ) < 0 && errno != EEXIST ) {
195
- printf ("Error creating directory (%s)\n" , DIRS [i ]);
196
- return -1 ;
197
- }
189
+ if (mount ("devtmpfs" , "/dev" , "devtmpfs" ,
190
+ MS_RELATIME , NULL ) < 0 && errno != EBUSY ) {
191
+ perror ("mount(/dev)" );
192
+ return -1 ;
198
193
}
199
194
200
- return 0 ;
201
- }
202
-
203
- static int mount_filesystems ()
204
- {
205
195
if (mount ("proc" , "/proc" , "proc" ,
206
196
MS_NODEV | MS_NOEXEC | MS_NOSUID | MS_RELATIME , NULL ) < 0 ) {
207
197
perror ("mount(/proc)" );
@@ -220,6 +210,13 @@ static int mount_filesystems()
220
210
return -1 ;
221
211
}
222
212
213
+ for (i = 0 ; i < 2 ; ++ i ) {
214
+ if (mkdir (DIRS_LEVEL2 [i ], 0755 ) < 0 && errno != EEXIST ) {
215
+ printf ("Error creating directory (%s)\n" , DIRS_LEVEL2 [i ]);
216
+ return -1 ;
217
+ }
218
+ }
219
+
223
220
if (mount ("devpts" , "/dev/pts" , "devpts" ,
224
221
MS_NOEXEC | MS_NOSUID | MS_RELATIME , NULL ) < 0 ) {
225
222
perror ("mount(/dev/pts)" );
@@ -260,7 +257,12 @@ static void config_parse_env(char *data, jsmntok_t *token)
260
257
* env_val = '\0' ;
261
258
env_val ++ ;
262
259
263
- setenv (env , env_val , 0 );
260
+ if ((strcmp (env , "HOME" ) == 0 ) ||
261
+ (strcmp (env , "TERM" ) == 0 )) {
262
+ setenv (env , env_val , 1 );
263
+ } else {
264
+ setenv (env , env_val , 0 );
265
+ }
264
266
}
265
267
}
266
268
@@ -454,6 +456,8 @@ int main(int argc, char **argv)
454
456
int sockfd ;
455
457
char localhost [] = "localhost\0" ;
456
458
char * hostname ;
459
+ char * krun_home ;
460
+ char * krun_term ;
457
461
char * krun_init ;
458
462
char * config_workdir , * env_workdir ;
459
463
char * rlimits ;
@@ -465,15 +469,9 @@ int main(int argc, char **argv)
465
469
exit (-1 );
466
470
}
467
471
#endif
468
-
469
- if (create_dirs () < 0 ) {
470
- printf ("Couldn't create support directories, bailing out\n" );
471
- exit (-2 );
472
- }
473
-
474
472
if (mount_filesystems () < 0 ) {
475
473
printf ("Couldn't mount filesystems, bailing out\n" );
476
- exit (-3 );
474
+ exit (-2 );
477
475
}
478
476
479
477
setsid ();
@@ -493,6 +491,16 @@ int main(int argc, char **argv)
493
491
494
492
config_parse_file (& config_argv , & config_workdir );
495
493
494
+ krun_home = getenv ("KRUN_HOME" );
495
+ if (krun_home ) {
496
+ setenv ("HOME" , krun_home , 1 );
497
+ }
498
+
499
+ krun_term = getenv ("KRUN_TERM" );
500
+ if (krun_term ) {
501
+ setenv ("TERM" , krun_term , 1 );
502
+ }
503
+
496
504
hostname = getenv ("HOSTNAME" );
497
505
if (hostname ) {
498
506
sethostname (hostname , strlen (hostname ));
0 commit comments