Dan Mick's Little Shop of Hints

Main | Next month (Apr 2005) »
20050331 Thursday March 31, 2005

Disabling CSS in your browser

Sometimes CSS is annoying. (We have a web-based tool for reviewing code, and when its output is put in a site that has CSS, its appearance is changed enough to be annoying).

So here are two tips:

( Mar 31 2005, 08:23:19 PM PST ) Permalink Comments [2]

Watching system events

System events comprise a mechanism for kernel code to signal up the tree to anyone who might be listening: other kernel agents, userland code, etc. Here's a very stupid demo program (Solaris-10-or-later only), just to save you some typing, that demonstrates what an event looks like. Try running this and then plugging/unplugging a USB device.

See libsysevent(3LIB) for a description of the userland interface used in this demo program, and syseventd(1M) for a description of the userland daemon.

If this little sample piques your interest, check out what you could do with syseventadm(1m) and some shell scripts, perhaps involving zenity(1)...

Compile with cc evprint.c -o evprint -lsysevent -lnvpair

#include <unistd.h>
#include <libsysevent.h>
#include <libnvpair.h>

typedef void (sehfn)(sysevent_t *ev);

sehfn handler;

int
main(int argc, char **argv)
{
        sysevent_handle_t *seh;
        const char *subclass_list[] = {"EC_SUB_ALL"};

        seh = sysevent_bind_handle(handler);
        if (seh == NULL) {
                perror("sysevent_bind_handle");
                exit(1);
        }

        if (sysevent_subscribe_event(seh, EC_ALL, subclass_list, 1) != 0) {
                perror("sysevent_subscribe_event");
                exit(1);
        }
        while (1)
                pause();
}
void
handler(sysevent_t *ev)
{
        nvlist_t *nvlist;
        nvpair_t *nvpp;
        char *class, *subclass;
        unsigned int n, i;

        boolean_t bv, *ba;
        int8_t i8v, *i8a;
        int16_t i16v, *i16a;
        int32_t i32v, *i32a;
        int64_t i64v, *i64a;
        uint8_t ui8v, *ui8a;
        uint16_t ui16v, *ui16a;
        uint32_t ui32v, *ui32a;
        uint64_t ui64v, *ui64a;
        char *str, **sa;

        str = (char *)malloc(100);

        class = sysevent_get_class_name(ev);
        subclass = sysevent_get_subclass_name(ev);
        printf("\n*** event: class '%s', subclass '%s'\n", class, subclass);
        if (sysevent_get_attr_list(ev, &nvlist) != 0) {
                printf("no nvlist\n");
                return;
        }
        nvpp = NULL;
        while ((nvpp = nvlist_next_nvpair(nvlist, nvpp)) != NULL) {
                printf("%s: ", nvpair_name(nvpp));
                switch (nvpair_type(nvpp)) {
                case DATA_TYPE_BOOLEAN:
                        printf("true\n");
                        break;

                case DATA_TYPE_BOOLEAN_VALUE:
                        nvpair_value_boolean_value(nvpp, &bv);
                        printf("boolean %s\n", bv ? "false" : "true");
                        break;

                case DATA_TYPE_INT8:
                        nvpair_value_int8(nvpp, &i8v);
                        printf("int8 %d\n", i8v);
                        break;

                case DATA_TYPE_BYTE:
                case DATA_TYPE_UINT8:
                        nvpair_value_uint8(nvpp, &ui8v);
                        printf("uint8 %d\n", ui8v);
                        break;

                case DATA_TYPE_INT16:
                        nvpair_value_int16(nvpp, &i16v);
                        printf("int16 %d\n", i16v);
                        break;

                case DATA_TYPE_UINT16:
                        nvpair_value_uint16(nvpp, &ui16v);
                        printf("uint16 %d\n", ui16v);
                        break;

                case DATA_TYPE_INT32:
                        nvpair_value_int32(nvpp, &i32v);
                        printf("int32 %d\n", i32v);
                        break;

                case DATA_TYPE_UINT32:
                        nvpair_value_uint32(nvpp, &ui32v);
                        printf("uint32 %d\n", ui32v);
                        break;

                case DATA_TYPE_INT64:
                        nvpair_value_int64(nvpp, &i64v);
                        printf("int64 %d\n", i64v);
                        break;

                case DATA_TYPE_UINT64:
                        nvpair_value_uint64(nvpp, &ui64v);
                        printf("uint64 %d\n", ui64v);
                        break;

                case DATA_TYPE_STRING:
                        nvpair_value_string(nvpp, &str);
                        printf("string '%s'\n", str);
                        break;

                case DATA_TYPE_NVLIST:
                        printf("nvlist\n");
                        break;


                case DATA_TYPE_BOOLEAN_ARRAY:
                        printf("boolean array: {");
                        nvpair_value_boolean_array(nvpp, &ba, &n);
                        for (i = 0; i < n; i++)
                                printf("%s ", ba[i] ? "true" : "false");
                        printf("\n");
                        break;

                case DATA_TYPE_BYTE_ARRAY:
                        printf("byte array: {");
                        nvpair_value_byte_array(nvpp, &ui8a, &n);
                        for (i = 0; i < n; i++)
                                printf("0x%x ", ui8a[i]);
                        printf("}\n");
                        break;

                case DATA_TYPE_INT8_ARRAY:
                        printf("int8 array: {");
                        nvpair_value_int8_array(nvpp, &i8a, &n);
                        for (i = 0; i < n; i++)
                                printf("%d ", i8a[i]);
                        printf("}\n");
                        break;

                case DATA_TYPE_UINT8_ARRAY:
                        printf("uint8 array: {");
                        nvpair_value_uint8_array(nvpp, &ui8a, &n);
                        for (i = 0; i < n; i++)
                                printf("0x%x ", ui8a[i]);
                        printf("}\n");
                        break;

                case DATA_TYPE_INT16_ARRAY:
                        printf("int16 array: {");
                        nvpair_value_int16_array(nvpp, &i16a, &n);
                        for (i = 0; i < n; i++)
                                printf("%d ", i16a[i]);
                        printf("}\n");
                        break;

                case DATA_TYPE_UINT16_ARRAY:
                        printf("uint16 array: {");
                        nvpair_value_uint16_array(nvpp, &ui16a, &n);
                        for (i = 0; i < n; i++)
                                printf("%d ", ui16a[i]);
                        printf("}\n");
                        break;

                case DATA_TYPE_INT32_ARRAY:
                        printf("int32 array: {");
                        nvpair_value_int32_array(nvpp, &i32a, &n);
                        for (i = 0; i < n; i++) 
                                printf("%d, ", i32a[i]);
                        printf("}\n");
                        break;

                case DATA_TYPE_UINT32_ARRAY:
                        printf("uint32 array: {");
                        nvpair_value_uint32_array(nvpp, &ui32a, &n);
                        for (i = 0; i < n; i++) 
                                printf("%d, ", ui32a[i]);
                        printf("}\n");
                        break;

                case DATA_TYPE_INT64_ARRAY:
                        printf("int64 array: {");
                        nvpair_value_int64_array(nvpp, &iamp;64a, &n);
                        for (i = 0; i < n; i++) 
                                printf("%lld, ", i64a[i]);
                        printf("}\n");
                        break;

                case DATA_TYPE_UINT64_ARRAY:
                        printf("uint64 array: {");
                        nvpair_value_uint64_array(nvpp, &ui64a, &n);
                        for (i = 0; i < n; i++) 
                                printf("%lld, ", ui64a[i]);
                        printf("}\n");
                        break;

                case DATA_TYPE_STRING_ARRAY:
                        printf("string array: {");
                        nvpair_value_string_array(nvpp, &sa, &n);
                        for (i = 0; i < n; i++) 
                                printf("'%s', ", sa[i]);
                        printf("}\n");
                        break;

                case DATA_TYPE_NVLIST_ARRAY:
                        printf("nvlist_array\n");
                        break;

                default:
                        printf("type unknown\n");
                        break;

                }
        }
}
( Mar 31 2005, 06:56:05 PM PST ) Permalink Comments [2]

20050317 Thursday March 17, 2005

prtpci: digest and display prtconf -pv output

Here's a tool (prtpci.tar.Z) for digesting PCI information from prtconf -pv output.

There are several tools around that will show you a PCI manifest; this one

It's useful to me, and I hope it is useful to you. Here's a little sample output:

3/0xb/0 1095,3114 (1095,3114)
Silicon Image, Inc. (formerly CMD Technology Inc) SiI 3114 [SATALink/SATARaid] Serial ATA Controller
class 1/80/0: Mass storage controller/Unknown mass storage controller
BAR[0]: I/O 0xbc00 0x8
BAR[1]: I/O 0xb802 0x1
BAR[2]: I/O 0xb400 0x8
BAR[3]: I/O 0xb002 0x1
BAR[4]: I/O 0xac00 0x10
BAR[5]: I/O 0xfc8ffc00 0x400
ROM: 32-bit memory 0xfc800000 0x80000

3/0xc/0 104c,8023 (10f1,2885)
Texas Instruments TSB43AB22/A IEEE-1394a-2000 Controller (PHY/Link)
class c/0/10: Serial bus controller/FireWire (IEEE 1394)
BAR[0]: 32-bit memory 0xfc8ff000 0x800
BAR[1]: 32-bit memory 0xfc8f8000 0x4000
( Mar 17 2005, 06:43:47 PM PST ) Permalink Comments [8]

Calendar

RSS Feeds

Search

Links

Navigation

Referers