nsenter: return an error if a process with specified pid is a zombie

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2014-12-25 18:16:43 +03:00 committed by Andrew Vagin
parent b6a1b88985
commit 0f8f0601ae
1 changed files with 10 additions and 2 deletions

View File

@ -176,11 +176,19 @@ void nsenter()
const int num = sizeof(namespaces) / sizeof(char *);
int i;
for (i = 0; i < num; i++) {
int fd = openat(ns_dir_fd, namespaces[i], O_RDONLY);
if (fd == -1) {
// A zombie process has links on namespaces, but they can't be opened
struct stat st;
if (fstatat(ns_dir_fd, namespaces[i], &st, AT_SYMLINK_NOFOLLOW) == -1) {
if (errno == ENOENT)
continue;
fprintf(stderr,
"nsenter: Failed to stat ns file \"%s\" for ns \"%s\" with error: \"%s\"\n",
ns_dir, namespaces[i], strerror(errno));
exit(1);
}
int fd = openat(ns_dir_fd, namespaces[i], O_RDONLY);
if (fd == -1) {
fprintf(stderr,
"nsenter: Failed to open ns file \"%s\" for ns \"%s\" with error: \"%s\"\n",
ns_dir, namespaces[i], strerror(errno));