Showing posts with label systemctl. Show all posts
Showing posts with label systemctl. Show all posts

Sunday, November 21, 2021

udev events, making an udev rule and debugging rules.



udev is a device manager for the linux kernel.

when you connect some device (pendrive, camera, microphone) on a linux machine, you have a daemon listen to events that are fired when the kernel register a new device. All devices are mapped to a file on /dev so you could check some info about the device with this command:

udevadm info -a -n  /dev/DEVICE_NAME

i.e.: udevadm info -a -n  /dev/ttyUSB2

udevadm info -a -n  /dev/ttyUSB2 | grep '{devpath}' | head -n 1
udevadm info -a -n  /dev/ttyUSB2 | grep '{idVendor}' | head -n 1
udevadm info -a -n  /dev/ttyUSB2 | grep '{idProduct}' | head -n 1
udevadm info -a -n  /dev/ttyUSB2 | grep '{serial}' | head -n 1


knowing the device info we could make a rule based in the information and execute a new action: make a file, make a symlink or execute a script. For example I want to create a rule that match with the attributes devpath, idVendor, idProduct, serial and generate a new symlink.

we need to create a file into:

/etc/udev/rules.d/99-some-rule.rules

- in this file we need to use "" in the values.
- each line is a rule.
- each line has many or one attribute and one action. When the attributes matched  the action is executed, that's all.
- if you edit or create a new rule, you need to load and trigger all rules again.

udevadm control --reload-rules && udevadm trigger


- so sometimes is tricky check why some rule is not executed. For debug you have:

    - udevadm test /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0/tty/ttyUSB0

      the devices path you could obtain with the comand udevadm info.

    - udevadm monitor

      show the events that are fired.
    
    - udevadm control --log-priority=debug

      set the environment on debug mode.

    - udevadm test $(udevadm info --query=path --name=ttyUSB0)
      
      test all rules associated to the device name ttyUSB0

- when you have an syntax error on some rules file, this will appear in the logs:
    - journalctl -f

- restart service:
    - systemctl restart systemd-udevd
 

- kernel messages
    - dmesg

- example: file called 99-new-rule.rules:

SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ATTRS{devpath}=="1.2", ATTRS{bcdDevice}=="0264", SYMLINK+="FANCY_NAME"

The 99 number indicated the priority for execution. in this case would be the last one to execute.

It's important to put double quotes instead single quote.

Sunday, April 19, 2015

Ordenando mi vieja instalacion de linux.




Hace un tiempo hice la instalación de mi maquina, y solo descargue mi config de github y anduvo lo mas esencial, pero hay aplicaciones que instalé pero no configure por tener urgencia de instalar y configurar lo mas necesario para la maestría.
Una de estas aplicaciones es tor, y privoxy.

JA, lo tenía instalado y ejecutándose y sin configurar por mucho tiempo.. me llevo 10minutos configurarlo siendo exagerada. así que a dejar la vagancia y anoto aca los pasos que eventualmente cambiaran entre las versiones, ahora es mucho más fácil la config. 

Igual la gente de Tor te comenta que si realmente quieres usar algo anónimo uses tor-browser que es más facil aún. pero es un browser propio basado en firefox.

Esto da la sensación que es más lento el internet, pero es otro tema..

Paquetes a instalar de archlinux.

pacman -S tor privoxy (estaban instalados...)

Archivo de configuración de tor.

/etc/tor/torrc

solo edite dos cosas:
descomente esta linea:

SocksPolicy reject *
Log notice syslog

Ver puertos utilizados.

netstat -punta 


Listar si se encuentra el servicio disponible

pacman -Qql tor | grep -Fe .service -e .socket

para otros paquetes:

pacman -Qql package | grep -Fe .service -e .socket

Luego repase un poco de systemctl.

systemctl is-enabled tor

systemctl status tor

Listar todos los servicios que tengo en mi maquina.
systemctl 


Listar los targets o lo que me recuerda a los niveles de ejecucion. o runlevels

systemctl list-units --type=target --all


Listar todos los servicios.
systemctl list-unit-files
 


Revisar el log de systemd.

journalctl -b
dmesg
journalctl -k

Revisando si tengo privoxy instalado y configurado basicamente.
http://www.privoxy.org/user-manual/startup.html


Hello tor!

Referencia:

https://wiki.archlinux.org/index.php/Systemd#Using_units

https://wiki.archlinux.org/index.php/Tor#Running_a_Tor_server
http://www.privoxy.org/user-manual/startup.html
http://www.privoxy.org/faq/misc.html#TOR