mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-30 10:38:55 +00:00
libc: improve diagnistics on initialization errors
This change helps to draw the connection between warnings during the initialization of file descriptors and the libc configuration.
This commit is contained in:
parent
901cbf0af3
commit
2a49eee50f
@ -72,6 +72,18 @@ void Libc::Kernel::_init_file_descriptors()
|
|||||||
{
|
{
|
||||||
typedef Genode::Token<Vfs::Scanner_policy_path_element> Path_element_token;
|
typedef Genode::Token<Vfs::Scanner_policy_path_element> Path_element_token;
|
||||||
|
|
||||||
|
/* guard used to print an offending libc config when leaving the scope */
|
||||||
|
struct Diag_guard
|
||||||
|
{
|
||||||
|
Kernel &kernel;
|
||||||
|
bool show = false;
|
||||||
|
|
||||||
|
Diag_guard(Kernel &kernel) : kernel(kernel) { }
|
||||||
|
|
||||||
|
~Diag_guard() { if (show) log(kernel._libc_env.libc_config()); }
|
||||||
|
|
||||||
|
} diag_guard { *this };
|
||||||
|
|
||||||
auto resolve_symlinks = [&] (Absolute_path next_iteration_working_path, Absolute_path &resolved_path)
|
auto resolve_symlinks = [&] (Absolute_path next_iteration_working_path, Absolute_path &resolved_path)
|
||||||
{
|
{
|
||||||
char path_element[PATH_MAX];
|
char path_element[PATH_MAX];
|
||||||
@ -183,6 +195,7 @@ void Libc::Kernel::_init_file_descriptors()
|
|||||||
struct stat out_stat { };
|
struct stat out_stat { };
|
||||||
if (_vfs.stat_from_kernel(path.string(), &out_stat) != 0) {
|
if (_vfs.stat_from_kernel(path.string(), &out_stat) != 0) {
|
||||||
warning("failed to call 'stat' on ", path);
|
warning("failed to call 'stat' on ", path);
|
||||||
|
diag_guard.show = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,6 +209,7 @@ void Libc::Kernel::_init_file_descriptors()
|
|||||||
error("could not allocate fd ",libc_fd," for ",path,", "
|
error("could not allocate fd ",libc_fd," for ",path,", "
|
||||||
"got fd ",fd->libc_fd);
|
"got fd ",fd->libc_fd);
|
||||||
_vfs.close_from_kernel(fd);
|
_vfs.close_from_kernel(fd);
|
||||||
|
diag_guard.show = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,6 +235,7 @@ void Libc::Kernel::_init_file_descriptors()
|
|||||||
|
|
||||||
} catch (Symlink_resolve_error) {
|
} catch (Symlink_resolve_error) {
|
||||||
warning("failed to resolve path for ", attr_value);
|
warning("failed to resolve path for ", attr_value);
|
||||||
|
diag_guard.show = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -229,7 +244,7 @@ void Libc::Kernel::_init_file_descriptors()
|
|||||||
|
|
||||||
Xml_node const node = _libc_env.libc_config();
|
Xml_node const node = _libc_env.libc_config();
|
||||||
|
|
||||||
typedef String<Vfs::MAX_PATH_LEN> Path;
|
using Path = String<Vfs::MAX_PATH_LEN>;
|
||||||
|
|
||||||
if (node.has_attribute("cwd"))
|
if (node.has_attribute("cwd"))
|
||||||
_cwd.import(node.attribute_value("cwd", Path()).string(), _cwd.base());
|
_cwd.import(node.attribute_value("cwd", Path()).string(), _cwd.base());
|
||||||
@ -248,8 +263,10 @@ void Libc::Kernel::_init_file_descriptors()
|
|||||||
unsigned const flags = rd ? (wr ? O_RDWR : O_RDONLY)
|
unsigned const flags = rd ? (wr ? O_RDWR : O_RDONLY)
|
||||||
: (wr ? O_WRONLY : 0);
|
: (wr ? O_WRONLY : 0);
|
||||||
|
|
||||||
if (!fd.has_attribute("path"))
|
if (!fd.has_attribute("path")) {
|
||||||
warning("Invalid <fd> node, 'path' attribute is missing");
|
warning("unknown path for file descriptor ", id);
|
||||||
|
diag_guard.show = true;
|
||||||
|
}
|
||||||
|
|
||||||
init_fd(fd, "path", id, flags);
|
init_fd(fd, "path", id, flags);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user