Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F164718437
D58238.id182294.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D58238.id182294.diff
View Options
diff --git a/lib/libc/gen/uexterr_format.c b/lib/libc/gen/uexterr_format.c
--- a/lib/libc/gen/uexterr_format.c
+++ b/lib/libc/gen/uexterr_format.c
@@ -11,20 +11,63 @@
#include <sys/param.h>
#include <sys/exterr_cat.h>
#include <sys/exterrvar.h>
+#include <sys/sysctl.h>
#include <exterr.h>
+#include <pthread.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include "libc_private.h"
+
static const char * const cat_to_filenames[] = {
#include "exterr_cat_filenames.h"
};
+_Thread_local char filename_buf[128];
+
+#define MIB_SIZE 4
+static int mib_template[MIB_SIZE];
+pthread_once_t mib_template_once_control = PTHREAD_ONCE_INIT;
+
+static void
+mib_template_init(void)
+{
+ size_t len;
+
+ len = nitems(mib_template);
+ (void)sysctlnametomib("kern.exterr.categories", mib_template, &len);
+ /* failure handled in kern_dynamic_cat_to_filename() */
+}
+
+static const char *
+kern_dynamic_cat_to_filename(int category)
+{
+ int mib[MIB_SIZE];
+ size_t len;
+
+ if (_once(&mib_template_once_control, mib_template_init) != 0)
+ return (NULL);
+ if (__predict_false(mib_template[0] != CTL_KERN)) {
+ filename_buf[0] = '\0';
+ return (filename_buf);
+ }
+
+ memcpy(mib, mib_template, MIB_SIZE);
+ mib[MIB_SIZE - 1] = category;
+ len = sizeof(filename_buf);
+ if (sysctl(mib, nitems(mib), filename_buf, &len, NULL, 0) != 0)
+ return (NULL);
+ return (filename_buf);
+}
+
static const char *
cat_to_filename(int category)
{
+ const char *path;
+
switch (EXTERR_CAT_SRC(category)) {
case EXTERR_CAT_SRC_KERN_STATIC:
if (category < 0 || category >= nitems(cat_to_filenames) ||
@@ -33,7 +76,10 @@
return (cat_to_filenames[category]);
case EXTERR_CAT_SRC_KERN_DYNAMIC:
- return ("unknown:kern");
+ path = kern_dynamic_cat_to_filename(EXTERR_CAT(category));
+ if (path == NULL)
+ return ("unknown:kern");
+ return (path);
case EXTERR_CAT_SRC_USER:
return ("unknown:user");
diff --git a/tests/sys/kern/exterr_test.c b/tests/sys/kern/exterr_test.c
--- a/tests/sys/kern/exterr_test.c
+++ b/tests/sys/kern/exterr_test.c
@@ -23,8 +23,10 @@
* SUCH DAMAGE.
*/
+#include <sys/param.h>
#include <sys/exterrvar.h>
#include <sys/mman.h>
+#include <sys/sysctl.h>
#include <atf-c.h>
#include <errno.h>
@@ -98,11 +100,37 @@
ATF_CHECK_STREQ(exterr, "");
}
+ATF_TC(exterr_dynamic_categories);
+ATF_TC_HEAD(exterr_dynamic_categories, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "directly check there is at least one registered category");
+}
+ATF_TC_BODY(exterr_dynamic_categories, tc)
+{
+ int mib[4];
+ size_t len;
+ char filename_buf[128];
+
+ len = nitems(mib);
+ ATF_REQUIRE_EQ(sysctlnametomib("kern.exterr.categories", mib, &len),
+ 0);
+ mib[3] = 1;
+ len = sizeof(filename_buf);
+ ATF_REQUIRE_EQ(sysctl(mib, nitems(mib), filename_buf, &len, NULL, 0),
+ 0);
+ printf("%s\n", filename_buf);
+ /* We can't know what it is, but make sure it's non-empty */
+ ATF_REQUIRE(strlen(filename_buf) > 1);
+}
+
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, gettext_extended);
ATF_TP_ADD_TC(tp, gettext_noextended);
ATF_TP_ADD_TC(tp, gettext_noextended_after_extended);
+ ATF_TP_ADD_TC(tp, exterr_dynamic_categories);
return (atf_no_error());
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Aug 4, 8:19 AM (19 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35908327
Default Alt Text
D58238.id182294.diff (3 KB)
Attached To
Mode
D58238: uexterr_gettext(3): support dynamic kernel categories
Attached
Detach File
Event Timeline
Log In to Comment