1

Whenever I unsuspend my laptop, the tmux window I have open (running dmesg -w) lights up:

image of tmux status line, with one window highlighted

From the tmux man page, this means that the application running in the window has rung the terminal bell.

I have another machine with essentially the same setup (same operating system, same tmux config), and this doesn't happen there – only on this specific laptop. Why is dmesg ringing the terminal bell on unsuspend on this machine?

Software versions:

$ uname -a
Linux localhost 3.10.18 #1 SMP Mon Jan 8 23:08:08 PST 2018 armv7l armv7l armv7l GNU/Linux
$ lsb_release -cr
Release:        16.04
Codename:       xenial
$ tmux -V
tmux 2.6
$ dmesg --version
dmesg from util-linux 2.27.1
3

If you examine dmesg's output, you can see exactly when it's ringing the bell, by grepping for the ASCII BEL character \a:

$ dmesg | grep -C1 $'\a'
[    5.706427] usb 1-2: Manufacturer: HD WebCam
[    5.706434] usb 1-2: SerialNumber: NC2141103Q533020AALM03
[    5.798439] Unsafe core_pattern used with suid_dumpable=2. Pipe handler or fully qualified core dump path required.
--
[13843.531106] usb 1-2: Manufacturer: HD WebCam
[13843.531115] usb 1-2: SerialNumber: NC2141103Q533020AALM03
[13843.546586] uvcvideo: Found UVC 1.00 device HD WebCam (0bda:57cf)

Interestingly, the bell-ringing appears to be happening halfway through initialising the webcam. We can check exactly where in the line the BEL is being printed by piping through od:

$ dmesg | grep $'\a' | head -n 1 | od -c
0000000   [                   5   .   7   0   6   4   3   4   ]       u
0000020   s   b       1   -   2   :       S   e   r   i   a   l   N   u
0000040   m   b   e   r   :      \a   N   C   2   1   4   1   1   0   3
0000060   Q   5   3   3   0   2   0   A   A   L   M   0   3  \n
0000076

The BEL is represented here as \a, and it's being printed just before the serial number (SerialNumber: ␇NC214...). It seems unlikely that dmesg would insert a BEL halfway through a line, so maybe it's the kernel that's logging it.

Let's check the source code. Maybe the USB driver is printing a bell when it logs the serial number. We can use livegrep to quickly search the Linux 4.12 source, and find that the relevant file is likely to be drivers/usb/core/hub.c. Then, we can go back to the Linux 3.10.18 source by using Elixir, and find the relevant function:

static void announce_device(struct usb_device *udev)
{
    dev_info(&udev->dev, "New USB device found, idVendor=%04x, idProduct=%04x\n",
        le16_to_cpu(udev->descriptor.idVendor),
        le16_to_cpu(udev->descriptor.idProduct));
    dev_info(&udev->dev,
        "New USB device strings: Mfr=%d, Product=%d, SerialNumber=%d\n",
        udev->descriptor.iManufacturer,
        udev->descriptor.iProduct,
        udev->descriptor.iSerialNumber);
    show_string(udev, "Product", udev->product);
    show_string(udev, "Manufacturer", udev->manufacturer);
    show_string(udev, "SerialNumber", udev->serial);
}

show_string is a very simple function, defined just above announce_device, that pretty much just prints its arguments separated by a colon and a space:

static void show_string(struct usb_device *udev, char *id, char *string)
{
    if (!string)
        return;
    dev_info(&udev->dev, "%s: %s\n", id, string);
}

So it's not the kernel that's adding the bell either.

What's the USB device's serial number?

We can check with lsusb:

$ lsusb -vd 0bda:57cf | grep iSerial
  iSerial                 2 NC2141103Q533020AALM03

OK, now let's pipe it through od:

$ lsusb -vd 0bda:57cf | grep iSerial | od -c
0000000           i   S   e   r   i   a   l
0000020                                           2      \a   N   C   2
0000040   1   4   1   1   0   3   Q   5   3   3   0   2   0   A   A   L
0000060   M   0   3  \n
0000064

which suggests that, in fact, the webcam's serial number contains an ASCII BEL.

  • 2
    To which the next obvious question is: why does the serial number contain BEL? One would expect such an identifier to be either numeric or composed entirely of printable characters – Fox Jan 22 '18 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.