Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 2819bb5

Browse files
authored
Merge pull request #292 from gao-feng/ro
continue to start container if create file failed
2 parents 295dd43 + 7831235 commit 2819bb5

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/container.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,23 +424,31 @@ static int container_binding_file(char *src, char *dest)
424424

425425
if (stat(src, &st) < 0) {
426426
if (errno == ENOENT) {
427-
fprintf(stdout, "no dns configured\n");
427+
fprintf(stdout, "can not find %s\n", src);
428428
return 0;
429429
}
430430

431-
fprintf(stderr, "stat %s failed", src);
431+
fprintf(stderr, "stat %s failed: %s\n", src, strerror(errno));
432432
return -1;
433433
}
434434

435-
fd = open(dest, O_CREAT| O_WRONLY, 0644);
436-
if (fd < 0) {
437-
fprintf(stderr, "create %s failed", dest);
438-
return -1;
435+
if (stat(dest, &st) < 0) {
436+
if (errno != ENOENT) {
437+
fprintf(stderr, "stat %s failed: %s\n", dest, strerror(errno));
438+
return 0;
439+
}
440+
fprintf(stdout, "can not find %s\n", dest);
441+
fd = open(dest, O_CREAT| O_WRONLY, 0644);
442+
if (fd < 0) {
443+
// root filesystem may be read only, don't fail
444+
fprintf(stderr, "create %s failed: %s\n", dest, strerror(errno));
445+
return 0;
446+
}
447+
close(fd);
439448
}
440-
close(fd);
441449

442450
if (mount(src, dest, NULL, MS_BIND, NULL) < 0) {
443-
fprintf(stderr, "bind to %s failed", dest);
451+
fprintf(stderr, "bind to %s failed: %s\n", dest, strerror(errno));
444452
return -1;
445453
}
446454

0 commit comments

Comments
 (0)