mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-19 15:43:56 +00:00
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch cleans up a few base headers, i.e., it removes unused includes from root/component.h, specifically base/heap.h and ram_session/ram_session.h. Hence, components that relied on the implicit inclusion of those headers have to manually include those headers now. While adjusting the log messages, I repeatedly stumbled over the problem that printing char * arguments is ambiguous. It is unclear whether to print the argument as pointer or null-terminated string. To overcome this problem, the patch introduces a new type 'Cstring' that allows the caller to express that the argument should be handled as null-terminated string. As a nice side effect, with this type in place, the optional len argument of the 'String' class could be removed. Instead of supplying a pair of (char const *, size_t), the constructor accepts a 'Cstring'. This, in turn, clears the way let the 'String' constructor use the new output mechanism to assemble a string from multiple arguments (and thereby getting rid of snprintf within Genode in the near future). To enforce the explicit resolution of the char * ambiguity, the 'char *' overload of the 'print' function is marked as deleted. Issue #1987
This commit is contained in:
committed by
Christian Helmuth
parent
a5d3aa8373
commit
17c79a9e23
@ -13,7 +13,7 @@
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#include <base/printf.h>
|
||||
#include <base/log.h>
|
||||
#include <base/snprintf.h>
|
||||
#include <os/config.h>
|
||||
#include <util/string.h>
|
||||
@ -48,31 +48,33 @@ void __attribute__((constructor)) init_libc_lxip(void)
|
||||
(Genode::strlen(netmask_str) != 0) ||
|
||||
(Genode::strlen(gateway_str) != 0)) {
|
||||
if (Genode::strlen(ip_addr_str) == 0) {
|
||||
PERR("Missing \"ip_addr\" attribute. Ignoring network interface config.");
|
||||
Genode::error("missing \"ip_addr\" attribute. Ignoring network interface config.");
|
||||
throw Genode::Xml_node::Nonexistent_attribute();
|
||||
} else if (Genode::strlen(netmask_str) == 0) {
|
||||
PERR("Missing \"netmask\" attribute. Ignoring network interface config.");
|
||||
Genode::error("missing \"netmask\" attribute. Ignoring network interface config.");
|
||||
throw Genode::Xml_node::Nonexistent_attribute();
|
||||
} else if (Genode::strlen(gateway_str) == 0) {
|
||||
PERR("Missing \"gateway\" attribute. Ignoring network interface config.");
|
||||
Genode::error("missing \"gateway\" attribute. Ignoring network interface config.");
|
||||
throw Genode::Xml_node::Nonexistent_attribute();
|
||||
}
|
||||
} else
|
||||
throw -1;
|
||||
|
||||
PDBG("static network interface: ip_addr=%s netmask=%s gateway=%s ",
|
||||
ip_addr_str, netmask_str, gateway_str);
|
||||
Genode::log("static network interface: ",
|
||||
"ip_addr=", Genode::Cstring(ip_addr_str), " "
|
||||
"netmask=", Genode::Cstring(netmask_str), " "
|
||||
"gateway=", Genode::Cstring(gateway_str));
|
||||
|
||||
Genode::snprintf(address_buf, sizeof(address_buf), "%s::%s:%s:::off",
|
||||
ip_addr_str, gateway_str, netmask_str);
|
||||
address_config = address_buf;
|
||||
}
|
||||
catch (...) {
|
||||
PINF("Using DHCP for interface configuration.");
|
||||
Genode::log("Using DHCP for interface configuration.");
|
||||
address_config = "dhcp";
|
||||
}
|
||||
|
||||
PDBG("init_libc_lxip() address config=%s\n", address_config);
|
||||
Genode::log("init_libc_lxip() address config=", address_config);
|
||||
|
||||
create_lxip_plugin(address_config);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/env.h>
|
||||
#include <base/printf.h>
|
||||
#include <base/log.h>
|
||||
|
||||
/* Libc plugin includes */
|
||||
#include <libc-plugin/fd_alloc.h>
|
||||
@ -140,7 +140,7 @@ struct Plugin : Libc::Plugin
|
||||
|
||||
Plugin::Plugin(char const *address_config) : socketcall(Lxip::init(address_config))
|
||||
{
|
||||
PDBG("using the lxip libc plugin");
|
||||
Genode::log("using the lxip libc plugin");
|
||||
}
|
||||
|
||||
|
||||
@ -260,7 +260,7 @@ int Plugin::fcntl(Libc::File_descriptor *sockfdo, int cmd, long val)
|
||||
|
||||
default:
|
||||
|
||||
PERR("unsupported fcntl() request: %d", cmd);
|
||||
Genode::error("unsupported fcntl() request: ", cmd);
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
@ -308,8 +308,7 @@ int Plugin::getsockopt(Libc::File_descriptor *sockfdo, int level,
|
||||
int optname, void *optval, socklen_t *optlen)
|
||||
{
|
||||
if (level != SOL_SOCKET) {
|
||||
PERR("%s: Unsupported level %d, we only support SOL_SOCKET for now",
|
||||
__func__, level);
|
||||
Genode::error(__func__, ": Unsupported level ", level, ", we only support SOL_SOCKET for now");
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
@ -342,7 +341,7 @@ int Plugin::ioctl(Libc::File_descriptor *sockfdo, int request, char *argp)
|
||||
|
||||
default:
|
||||
|
||||
PERR("unsupported ioctl() request");
|
||||
Genode::error("unsupported ioctl() request");
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
@ -497,8 +496,7 @@ int Plugin::setsockopt(Libc::File_descriptor *sockfdo, int level,
|
||||
socklen_t optlen)
|
||||
{
|
||||
if (level != SOL_SOCKET) {
|
||||
PERR("%s: Unsupported level %d, we only support SOL_SOCKET for now",
|
||||
__func__, level);
|
||||
Genode::error(__func__, ": Unsupported level ", level, ", we only support SOL_SOCKET for now");
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
@ -546,7 +544,7 @@ int Plugin::linux_family(const struct sockaddr *addr, socklen_t addrlen)
|
||||
|
||||
default:
|
||||
|
||||
PERR("Unsupported socket BSD-protocol %u\n", addr->sa_family);
|
||||
Genode::error("unsupported socket BSD protocol ", addr->sa_family);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -569,7 +567,7 @@ int Plugin::bsd_family(struct sockaddr *addr)
|
||||
|
||||
default:
|
||||
|
||||
PERR("Unsupported socket Linux-protocol %u\n", addr->sa_family);
|
||||
Genode::error("unsupported socket Linux protocol ", addr->sa_family);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -580,19 +578,19 @@ int Plugin::translate_msg_flags(int bsd_flags)
|
||||
using namespace Lxip;
|
||||
int f = 0;
|
||||
|
||||
if (bsd_flags & MSG_OOB) f |= LINUX_MSG_OOB;
|
||||
if (bsd_flags & MSG_PEEK) f |= LINUX_MSG_PEEK;
|
||||
if (bsd_flags & MSG_DONTROUTE) f |= LINUX_MSG_DONTROUTE;
|
||||
if (bsd_flags & MSG_EOR) f |= LINUX_MSG_EOR;
|
||||
if (bsd_flags & MSG_TRUNC) f |= LINUX_MSG_TRUNC;
|
||||
if (bsd_flags & MSG_CTRUNC) f |= LINUX_MSG_CTRUNC;
|
||||
if (bsd_flags & MSG_WAITALL) f |= LINUX_MSG_WAITALL;
|
||||
if (bsd_flags & MSG_NOTIFICATION) PWRN("MSG_NOTIFICATION ignored");
|
||||
if (bsd_flags & MSG_DONTWAIT) f |= LINUX_MSG_DONTWAIT;
|
||||
if (bsd_flags & MSG_EOF) f |= LINUX_MSG_EOF;
|
||||
if (bsd_flags & MSG_NBIO) PWRN("MSG_NBIO ignored");
|
||||
if (bsd_flags & MSG_NOSIGNAL) f |= LINUX_MSG_NOSIGNAL;
|
||||
if (bsd_flags & MSG_COMPAT) f |= LINUX_MSG_COMPAT;
|
||||
if (bsd_flags & MSG_OOB) f |= LINUX_MSG_OOB;
|
||||
if (bsd_flags & MSG_PEEK) f |= LINUX_MSG_PEEK;
|
||||
if (bsd_flags & MSG_DONTROUTE) f |= LINUX_MSG_DONTROUTE;
|
||||
if (bsd_flags & MSG_EOR) f |= LINUX_MSG_EOR;
|
||||
if (bsd_flags & MSG_TRUNC) f |= LINUX_MSG_TRUNC;
|
||||
if (bsd_flags & MSG_CTRUNC) f |= LINUX_MSG_CTRUNC;
|
||||
if (bsd_flags & MSG_WAITALL) f |= LINUX_MSG_WAITALL;
|
||||
if (bsd_flags & MSG_NOTIFICATION) Genode::warning("MSG_NOTIFICATION ignored");
|
||||
if (bsd_flags & MSG_DONTWAIT) f |= LINUX_MSG_DONTWAIT;
|
||||
if (bsd_flags & MSG_EOF) f |= LINUX_MSG_EOF;
|
||||
if (bsd_flags & MSG_NBIO) Genode::warning("MSG_NBIO ignored");
|
||||
if (bsd_flags & MSG_NOSIGNAL) f |= LINUX_MSG_NOSIGNAL;
|
||||
if (bsd_flags & MSG_COMPAT) f |= LINUX_MSG_COMPAT;
|
||||
|
||||
return f;
|
||||
}
|
||||
@ -642,7 +640,7 @@ int Plugin::translate_ops_linux(int optname)
|
||||
if (sockopts[i] == optname)
|
||||
return i;
|
||||
|
||||
PERR("Unsupported sockopt %d\n", optname);
|
||||
Genode::error("unsupported sockopt ", optname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user