Ubuntu v4l2loopbackのdkmsがビルドエラー

ある日突然エラーが出たので対処法をメモする。
一時的で、あまりよくない対処方法だと思うのでご参考までに。

# エラー内容
この記事とエラーは同じです。

https://qiita.com/m-m-n/items/e406a82f6db1869f6edd

```shell
ユーザー名@パソコン:~$ sudo apt upgrade
[sudo] password for パソコン: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  apport-symptoms libbsd0:i386 libdrm2:i386 libexpat1:i386 libffi8:i386 libgbm1:i386 libmd0:i386 libnvidia-cfg1-560 libnvidia-common-560
  libnvidia-compute-560:i386 libnvidia-decode-560:i386 libnvidia-encode-560 libnvidia-encode-560:i386 libnvidia-extra-560 libnvidia-fbc1-560
  libnvidia-fbc1-560:i386 libnvidia-gl-560 libnvidia-gl-560:i386 libwayland-server0:i386 libx11-6:i386 libxau6:i386 libxcb-randr0:i386 libxcb1:i386
  libxdmcp6:i386 libxext6:i386 nvidia-compute-utils-560 nvidia-firmware-560-560.35.05 nvidia-modprobe nvidia-prime nvidia-settings nvidia-utils-560
  python3-systemd screen-resolution-extra xserver-xorg-video-nvidia-560
Use 'sudo apt autoremove' to remove them.
Get more security updates through Ubuntu Pro with 'esm-apps' enabled:
  libpostproc-dev libde265-dev python3-tornado libheif1 libjs-jquery-ui
  libpathplan4 libopenexr-dev graphviz libavdevice58 libgvpr2 libgvc6 ffmpeg
  libopenexr25 python3-scipy libpostproc55 libcgraph6 libswscale-dev libcdt5
  libavdevice-dev libavcodec58 libavutil56 libswscale5 libheif-dev
  libavutil-dev liblab-gamut1 libswresample3 libavfilter-dev libavformat58
  libpmix-dev libavformat-dev libavcodec-dev libde265-0 libpmix2
  libswresample-dev libavfilter7
Learn more about Ubuntu Pro at https://ubuntu.com/pro
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up v4l2loopback-dkms (0.12.7-2ubuntu2~22.04.1) ...
Removing old v4l2loopback-0.12.7 DKMS files...
Deleting module v4l2loopback-0.12.7 completely from the DKMS tree.
Loading new v4l2loopback-0.12.7 DKMS files...
Building for 6.8.0-50-generic
Building initial module for 6.8.0-50-generic
Error! Bad return status for module build on kernel: 6.8.0-50-generic (x86_64)
Consult /var/lib/dkms/v4l2loopback/0.12.7/build/make.log for more information.
dpkg: error processing package v4l2loopback-dkms (--configure):
 installed v4l2loopback-dkms package post-installation script subprocess returned error exit status 10
Errors were encountered while processing:
 v4l2loopback-dkms
E: Sub-process /usr/bin/dpkg returned an error code (1)
ユーザー名@パソコン:~$ sudo dkms build -m v4l2lo
```
# エラー原因

この状態で、`sudo dkms build -m v4l2loopback -v 0.12.7`を実行すると

```shell
ユーザー名@パソコン:~$ sudo dkms build -m v4l2loopback -v 0.12.7

Kernel preparation unnecessary for this kernel. Skipping...

Building module:
cleaning build area...
make -j12 KERNELRELEASE=6.8.0-50-generic KERNEL_DIR=/lib/modules/6.8.0-50-generic/build all...(bad exit status: 2)
Error! Bad return status for module build on kernel: 6.8.0-50-generic (x86_64)
Consult /var/lib/dkms/v4l2loopback/0.12.7/build/make.log for more information.
```

`/var/lib/dkms/v4l2loopback/0.12.7/build/make.log`に情報があるよとあるので、
`code /var/lib/dkms/v4l2loopback/0.12.7/build/make.log`でbuild時のエラーを確認します。

```/var/lib/dkms/v4l2loopback/0.12.7/build/make.log
DKMS make.log for v4l2loopback-0.12.7 for kernel 6.8.0-50-generic (x86_64)
Thu Jan  2 03:24:14 PM JST 2025
Building v4l2-loopback driver...
make -C /lib/modules/6.8.0-50-generic/build M=/var/lib/dkms/v4l2loopback/0.12.7/build modules CC=x86_64-linux-gnu-gcc-12
make[1]: Entering directory '/usr/src/linux-headers-6.8.0-50-generic'
  CC [M]  /var/lib/dkms/v4l2loopback/0.12.7/build/v4l2loopback.o
/var/lib/dkms/v4l2loopback/0.12.7/build/v4l2loopback.c: In function ‘vidioc_querycap’:
/var/lib/dkms/v4l2loopback/0.12.7/build/v4l2loopback.c:727:9: error: implicit declaration of function ‘strlcpy’; did you mean ‘strscpy’? [-Werror=implicit-function-declaration]
  727 |         strlcpy(cap->driver, "v4l2 loopback", sizeof(cap->driver));
      |         ^~~~~~~
      |         strscpy
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:243: /var/lib/dkms/v4l2loopback/0.12.7/build/v4l2loopback.o] Error 1
make[2]: *** [/usr/src/linux-headers-6.8.0-50-generic/Makefile:1925: /var/lib/dkms/v4l2loopback/0.12.7/build] Error 2
make[1]: *** [Makefile:240: __sub-make] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.8.0-50-generic'
make: *** [Makefile:43: v4l2loopback.ko] Error 2
```
このログからわかるように、`strscpy`でなく`strlcpy`を使ったことによるエラーみたいです。

参考の記事には次のように記載されていました。
> Linux Kernel 6.8で strlcpy() 関数がなくなった
> v4l2loopback.cで該当の関数を利用している

# エラー対処
VScodeの置換機能で`/var/lib/dkms/v4l2loopback/0.12.7/build/v4l2loopback.c`の`strlcpy`を`strscpy`に置換します。
buildファイルの中のやつを変更してるから絶対にbuild元だと考えられる`/usr/src/v4l2loopback-0.12.7/v4l2loopback.c`を変更したほうが、いい気がする。

置換後に
`sudo dkms build -m v4l2loopback -v 0.12.7`
`sudo dkms install -m v4l2loopback -v 0.12.7`
を実行したら成功！
```shell
ユーザー名@パソコン:/usr/src/v4l2loopback-0.12.7$ sudo dkms build -m v4l2loopback -v 0.12.7

Kernel preparation unnecessary for this kernel. Skipping...

Building module:
cleaning build area...
make -j12 KERNELRELEASE=6.8.0-50-generic KERNEL_DIR=/lib/modules/6.8.0-50-generic/build all...
Signing module:
 - /var/lib/dkms/v4l2loopback/0.12.7/6.8.0-50-generic/x86_64/module/v4l2loopback.ko
Secure Boot not enabled on this system.
cleaning build area...
ユーザー名@パソコン:/usr/src/v4l2loopback-0.12.7$ sudo dkms install -m v4l2loopback -v 0.12.7

v4l2loopback.ko:
Running module version sanity check.
 - Original module
 - Installation
   - Installing to /lib/modules/6.8.0-50-generic/updates/dkms/

depmod...

```

この後に`sudo apt upgrade`しても成功しました！