Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with product_family in docker on a Synology nas #293

Closed
PromoFaux opened this issue Dec 15, 2022 · 29 comments
Closed

Issue with product_family in docker on a Synology nas #293

PromoFaux opened this issue Dec 15, 2022 · 29 comments

Comments

@PromoFaux
Copy link
Member

The below line path does not appear to exist when I run on docker on my Synology NAS, however I do not see the same thing in docker on a raspberry Pi

PADD/padd.sh

Line 222 in 89853fa

product_family=$(tr -d '\0' < /sys/devices/virtual/dmi/id/product_family)

image

@rdwebdesign
Copy link
Member

How is this line executed?

Line 219 should be false:

PADD/padd.sh

Line 219 in 89853fa

if [ -f /sys/devices/virtual/dmi/id/product_name ] || [ -f /sys/devices/virtual/dmi/id/product_family ]; then

@rdwebdesign
Copy link
Member

rdwebdesign commented Dec 15, 2022

Actually it should be:

-  if [ -f /sys/devices/virtual/dmi/id/product_name ] || [ -f /sys/devices/virtual/dmi/id/product_family ]; then 
+  if [ -f /sys/devices/virtual/dmi/id/product_name ] && [ -f /sys/devices/virtual/dmi/id/product_family ]; then 

@PromoFaux
Copy link
Member Author

Because it's hitting the || condition.

product_name is populated:

admin@fappotron:~$ docker exec -it pihole cat /sys/devices/virtual/dmi/id/product_name
DS218+
admin@fappotron:~$ docker exec -it pihole cat /sys/devices/virtual/dmi/id/product_family
cat: /sys/devices/virtual/dmi/id/product_family: No such file or directory

@rdwebdesign
Copy link
Member

rdwebdesign commented Dec 15, 2022

So, we need a different test, to avoid the use of an absent file:

  if [ -f /sys/devices/virtual/dmi/id/product_name ]; then
    # Get model, remove possible null byte
    product_name=$(tr -d '\0' < /sys/devices/virtual/dmi/id/product_name)
    
    sys_model="$(echo "$product_name")"
    if [ -f /sys/devices/virtual/dmi/id/product_family ]; then
      product_family=$(tr -d '\0' < /sys/devices/virtual/dmi/id/product_family)
      sys_model="$(echo "$product_name" | grep "$product_family")"
    fi

    # If product_family is not contained in product_name, both are shown
    if [ -z "$sys_model" ]; then
      sys_model="${product_family} ${product_name}"
    fi
  elif [ -f /sys/firmware/devicetree/base/model ]; then

Edit:
I'm not sure if there is a case where there is no /sys/devices/virtual/dmi/id/product_name, but there is /sys/devices/virtual/dmi/id/product_family.
If this is possible, we need to change the code a little.

@rdwebdesign
Copy link
Member

@yubiuser

Promofaux found a case where product_name exists, but product_family does not exist.

In this case, the current code fails.
I suggested a new code that works if both files exist or only product_name exists.

Are there cases where only product_family exists?
If the answer is positive (or it's not possible to predict), we need to change the code to guarantee we read the files only if they exist.

@yubiuser
Copy link
Member

Are there cases where only product_family exists?

Actually, I don't know - and worse: I don't know how to test this. We can't check all devices that exist out there. Therefore we should assume there are devices that have only a product_family set.

@PromoFaux
Copy link
Member Author

Do we even need it? It's only used in mega as far as I can see

PADD/padd.sh

Line 857 in 6676f56

moveXOffset; printf " %-10s%-39s${clear_line}\n" "Device:" "${sys_model}"

@rdwebdesign
Copy link
Member

Because mega is bigger and we can show more information, like this.

@PromoFaux
Copy link
Member Author

It just seems like a lot of code to possibly spit out Unknown in cases where the screen happens to be big enough

PADD/padd.sh

Lines 218 to 268 in 6676f56

# Device model
if [ -f /sys/devices/virtual/dmi/id/product_name ] || [ -f /sys/devices/virtual/dmi/id/product_family ]; then
# Get model, remove possible null byte
product_name=$(tr -d '\0' < /sys/devices/virtual/dmi/id/product_name)
product_family=$(tr -d '\0' < /sys/devices/virtual/dmi/id/product_family)
sys_model="$(echo "$product_name" | grep "$product_family")"
# If product_family is not contained in product_name, both are shown
if [ -z "$sys_model" ]; then
sys_model="${product_family} ${product_name}"
fi
elif [ -f /sys/firmware/devicetree/base/model ]; then
sys_model=$(tr -d '\0' < /sys/firmware/devicetree/base/model)
elif [ -f /sys/devices/virtual/dmi/id/board_vendor ] || [ -f /sys/devices/virtual/dmi/id/board_name ]; then
sys_model=$(tr -d '\0' < /sys/devices/virtual/dmi/id/board_vendor)
sys_model="$sys_model $(tr -d '\0' < /sys/devices/virtual/dmi/id/board_name)"
elif [ -f /tmp/sysinfo/model ]; then
sys_model=$(tr -d '\0' < /tmp/sysinfo/model)
fi
# Cleaning device model from useless OEM information
sys_model=${sys_model#"To be filled by O.E.M."}
sys_model=${sys_model%"To be filled by O.E.M."}
sys_model=${sys_model#"To Be Filled*"}
sys_model=${sys_model%"To Be Filled*"}
sys_model=${sys_model#"OEM*"}
sys_model=${sys_model%"OEM*"}
sys_model=${sys_model#"Not Applicable"}
sys_model=${sys_model%"Not Applicable"}
sys_model=${sys_model#"System Product Name"}
sys_model=${sys_model%"System Product Name"}
sys_model=${sys_model#"System Version"}
sys_model=${sys_model%"System Version"}
sys_model=${sys_model#"Undefined"}
sys_model=${sys_model%"Undefined"}
sys_model=${sys_model#"Default string"}
sys_model=${sys_model%"Default string"}
sys_model=${sys_model#"Not Specified"}
sys_model=${sys_model%"Not Specified"}
sys_model=${sys_model#"Type1ProductConfigId"}
sys_model=${sys_model%"Type1ProductConfigId"}
sys_model=${sys_model#"INVALID"}
sys_model=${sys_model%"INVALID"}
sys_model=${sys_model#"All Series"}
sys_model=${sys_model%"All Series"}
sys_model=${sys_model#""}
sys_model=${sys_model%""}
if [ -z "$sys_model" ]; then
sys_model="Unknown"
fi

Screenshot from a raspberry pi 4

image

@rdwebdesign
Copy link
Member

This is the PR, including the discussion:
#267

@PromoFaux
Copy link
Member Author

Hmmm, the code that was removed would work on an Rpi:

pi@dockerpi:~ $ cat /sys/firmware/devicetree/base/model
Raspberry Pi 4 Model B Rev 1.4

So was the PR to change it so that device name could only be derived on an x86 machine?

@yubiuser
Copy link
Member

No.

The check is still in there.

PADD/padd.sh

Line 229 in 6676f56

elif [ -f /sys/firmware/devicetree/base/model ]; then

@PromoFaux
Copy link
Member Author

My bad - I missed that entirely! OK, if I extract that I can see the model number when running directly on the pi:

pi@dockerpi:~ $ ./test.sh
Raspberry Pi 4 Model B Rev 1.4

But from within the container it does not work

pi@dockerpi:~ $ docker exec -it pihole cat /sys/firmware/devicetree/base/model
cat: /sys/firmware/devicetree/base/model: No such file or directory

No biggy I guess!

@rdwebdesign
Copy link
Member

Inside containers are very difficult to identify the hardware.

@yubiuser
Copy link
Member

yubiuser commented Dec 15, 2022

Figuring out the base device from within a script running in a docker container might be out-of-scope for PADD

@rdwebdesign
Copy link
Member

rdwebdesign commented Dec 15, 2022

I think it's possible (or at least easier) if the docker socket (/var/run/docker.sock) is mounted inside the container, but this is completely out of question, because it is very unsafe.

It could be possible using external software, but I think we don't want to add a new dependency just to be able to get this information.

@PromoFaux
Copy link
Member Author

I already think it's a lot of code just for outputting the device - imagine what I would think about adding in special cases for docker ;)

@yubiuser
Copy link
Member

Most is the code for cleaning unwanted stuff.

@rdwebdesign
Copy link
Member

Note:
tested only on Raspberry Pi.

The command cat /proc/cpuinfo | grep "Model" returns Model             : Raspberry Pi 4 Model B Rev 1.4, even inside a container.

@yubiuser
Copy link
Member

cat /proc/cpuinfo | grep "Model" does not return anything on my x86_64 laptop nor my RockPi 4b.

Do you think we should add it as an additional source?

@rdwebdesign
Copy link
Member

I don't think this will work... Inside a container is not possible to access all hardware info (this is intentional, for security reasons).

I added the code to show the Docker Tag inside containers.

@yubiuser yubiuser added the WIP label Dec 17, 2022
@DL6ER
Copy link
Member

DL6ER commented Dec 18, 2022

@yubiuser Just seen this and thought it'd be worthwhile to point out that the key is lowercase in the kernel (but you grepped for uppercase). Try grep -i "model" < /proc/cpuinfo probably even grep -i "model name" < /proc/cpuinfo

@yubiuser
Copy link
Member

Better, but not good ;-)

rockpi@rockpi-4b:~$ grep -i "model" < /proc/cpuinfo
rockpi@rockpi-4b:~$ grep -i "model name" < /proc/cpuinfo
chrko@ThinkPad-X230:~$ grep -i "model" < /proc/cpuinfo
model		: 58
model name	: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
model		: 58
model name	: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
model		: 58
model name	: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
model		: 58
model name	: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz

@DL6ER
Copy link
Member

DL6ER commented Dec 19, 2022

So ... this raises the question: What is the content of /proc/cpuinfo on rockpi-4b at all?

@DL6ER
Copy link
Member

DL6ER commented Dec 19, 2022

Some further ideas:

dmidecode --type processor

sudo dmidecode --type processor | sed -n "s/Version: \(.*\)/\1/p"
AMD Ryzen 7 4800H with Radeon Graphics

lshw -C CPU

$ sudo lshw -C CPU 2> /dev/null | sed -n "s/product: \(.*\)/\1/p"
AMD Ryzen 7 4800H with Radeon Graphics

lscpu

$ lscpu | sed -n "s/Model name:\W*\(.*\)/\1/p"
AMD Ryzen 7 4800H with Radeon Graphics

If they return empty for you, you should check what the commands return without sed

@rdwebdesign
Copy link
Member

rdwebdesign commented Dec 19, 2022

Are you sure this commands are available everywhere?

Note: none of the commands above are available inside our container.

Since we are going to add PADD on docker-pi-hole images, to I think we need to separate these tests:

  • if inside a docker container: show image tag;
  • else, use those other methods.

@yubiuser
Copy link
Member

What is the content of /proc/cpuinfo

rockpi@rockpi-4b:~$ cat /proc/cpuinfo 
processor	: 0
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 1
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 2
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 3
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd03
CPU revision	: 4

processor	: 4
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd08
CPU revision	: 2

processor	: 5
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0xd08
CPU revision	: 2

rockpi@rockpi-4b:~$ sudo dmidecode --type processor | sed -n "s/Version: \(.*\)/\1/p"
rockpi@rockpi-4b:~$ sudo lshw -C CPU 2> /dev/null | sed -n "s/product: \(.*\)/\1/p"
rockpi@rockpi-4b:~$ lscpu | sed -n "s/Model name:\W*\(.*\)/\1/p"
Cortex-A53

@rdwebdesign
Copy link
Member

dmidecode doesn't work on my 2 Raspberry Pi (running on Buster):

pi@pi4:~ $ sudo dmidecode
# dmidecode 3.2
Scanning /dev/mem for entry point.
# No SMBIOS nor DMI entry point found, sorry.

lshw is not installed by default.

lscpu | sed -n "s/Model name:\W*\(.*\)/\1/p" returns the same CPU model: Cortex-A53

@yubiuser
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants