Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F108649336
D29320.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D29320.diff
View Options
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -2435,6 +2435,47 @@
return (retval);
}
+/**
+ * @brief Print the name of the device followed by a colon, a space
+ * and the result of calling log() with the value of @p fmt and
+ * the following arguments.
+ *
+ * @returns the number of characters printed
+ */
+int
+device_log(device_t dev, int pri, const char * fmt, ...)
+{
+ char buf[128];
+ struct sbuf sb;
+ const char *name;
+ va_list ap;
+ size_t retval;
+
+ retval = 0;
+
+ sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
+
+ name = device_get_name(dev);
+
+ if (name == NULL)
+ sbuf_cat(&sb, "unknown: ");
+ else
+ sbuf_printf(&sb, "%s%d: ", name, device_get_unit(dev));
+
+ va_start(ap, fmt);
+ sbuf_vprintf(&sb, fmt, ap);
+ va_end(ap);
+
+ sbuf_finish(&sb);
+
+ log(pri, "%.*s", (int) sbuf_len(&sb), sbuf_data(&sb));
+ retval = sbuf_len(&sb);
+
+ sbuf_delete(&sb);
+
+ return (retval);
+}
+
/**
* @internal
*/
diff --git a/sys/net/if.c b/sys/net/if.c
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -3968,15 +3968,35 @@
strlcpy(ifp->if_xname, name, IFNAMSIZ);
}
+static int
+if_vlog(struct ifnet *ifp, int pri, const char *fmt, va_list ap)
+{
+ char if_fmt[256];
+
+ snprintf(if_fmt, sizeof(if_fmt), "%s: %s", ifp->if_xname, fmt);
+ vlog(pri, if_fmt, ap);
+ return (0);
+}
+
+
int
if_printf(struct ifnet *ifp, const char *fmt, ...)
{
- char if_fmt[256];
va_list ap;
- snprintf(if_fmt, sizeof(if_fmt), "%s: %s", ifp->if_xname, fmt);
va_start(ap, fmt);
- vlog(LOG_INFO, if_fmt, ap);
+ if_vlog(ifp, LOG_INFO, fmt, ap);
+ va_end(ap);
+ return (0);
+}
+
+int
+if_log(struct ifnet *ifp, int pri, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ if_vlog(ifp, pri, fmt, ap);
va_end(ap);
return (0);
}
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -659,6 +659,7 @@
void if_initname(struct ifnet *, const char *, int);
void if_link_state_change(struct ifnet *, int);
int if_printf(struct ifnet *, const char *, ...) __printflike(2, 3);
+int if_log(struct ifnet *, int, const char *, ...) __printflike(3, 4);
void if_ref(struct ifnet *);
void if_rele(struct ifnet *);
bool if_try_ref(struct ifnet *);
diff --git a/sys/sys/bus.h b/sys/sys/bus.h
--- a/sys/sys/bus.h
+++ b/sys/sys/bus.h
@@ -607,6 +607,7 @@
device_t device_lookup_by_name(const char *name);
int device_print_prettyname(device_t dev);
int device_printf(device_t dev, const char *, ...) __printflike(2, 3);
+int device_log(device_t dev, int pri, const char *, ...) __printflike(3, 4);
int device_probe(device_t dev);
int device_probe_and_attach(device_t dev);
int device_probe_child(device_t bus, device_t dev);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 28, 2:03 AM (9 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16237500
Default Alt Text
D29320.diff (2 KB)
Attached To
Mode
D29320: Add log() style versions of device_printf() and if_printf()
Attached
Detach File
Event Timeline
Log In to Comment