วันนี้ลงโปรแกรมที่ต้องใช้ serial port
ตอนลงติดตั้งโปรแกรม พบว่าไม่มีปัญหา สามารถติดต่อกับ serial port และ hard lock ได้
อืม ก็โอเคดีนี่ เลยรีสตาร์ทเครื่อง หลังลงเสร็จ
จากนั้นเข้า user ปรกติ คือ user ของเราเอง
เอาล่ะซี่ โปรแกรมไม่ทำงาน เอ๊ะ อะไรหว่า
ตรวจสอบ log file ... อืม ทำไมติดต่อ serial port ไม่ได้ล่า
เลยไปเช็คจาก /dev/ttyS0 สำหรับ COM1 และ /dev/ttyS1 สำหรับ COM2
ปรากฎว่าเป็น
c r w - r w - - - -
อ่อ มิน่าล่า มันไม่ไห้ user ทั่วไป connect (read) จาก serial port เลยนี่เอง
ด้วยความรวดเร็ว เลยล่อคำสั่ง
chmod 777 /dev/ttyS*
เปิดหมด ไม่เหลือ reboot เพื่อความแน่ใจอีกรอบด้วย
หลังเปิดเครื่อง เราก็เปิดโปรแกรมใหม่
อ่าว ไม่ได้อีกแฮะ เลยกลับไปดู permission ของ serial port ใหม่
เพราะคิดว่าใส่ผิด
ปรากฎว่าเป็น
c r w - r w - - - -
อ่าว เฮ่ย ไม่ได้เปลี่ยนเลย ใส่ผิดยังงัยก็ไม่น่ากลับมาเป็นตัวเดิม
ลองอีกรอบ ก็เหมือนเดิม
สรุปว่า ถ้ารีสตาร์ทเครื่องเมื่อไหร่ ไอ้ที่เซ็ตไว้ จะหายเกลี้ยง
สรุปว่า security ล่ะสิ
เช็คกูเกิ้ลตั้งนาน จนเจอ http://www.weather-watch.com/wiki/index.php/Linux_Weather_Display_Manual
- NOTE: If you are running OpenSUSE, or any other Linux distro which utilizes "udev" (udev is included in almost every 2.6 kernel based Linux distribution), then in order to permanently change permissions of your ttyS0 port (or any ttyS* port), you must edit the "/etc/udev/rules.d/50-udev-default.rules" file. Here are the changes you must make in order for the permissions to stick after rebooting your computer (you must be root to make the changes):
- Open the "/etc/udev/rules.d/50-udev-default.rules" file in your favorite text editor (as root). Find the line in the file that begins with KERNEL=="tty[A-Z]". That's the line you will need to edit. Notice the default settings will look something like this:
- KERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp"
- Add [, MODE="777"] to the end of the above line in your 50-udev-default.rules file (without the brackets but don't forget to add the preceding coma). It should look something like this:
- KERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp", MODE="777"
- After changing this file and saving, reboot your computer. The ttyS* ports will grant rwx permission to any user.
- Important: If you have a udev enabled Linux distribution and you do not make the above noted changes to your 50-udev-default.rules file, then every time you reboot your computer, the permissions on the ttyS* ports will revert back to root only access. This is because udev dynamically updates the /dev directory upon booting. All permissions granted during your previous session will be lost and Weather Display will not function properly. This solution is known to work properly with OpenSUSE 10.2.
เนื่องจาก openSuSe หรือ Linux distro ใหม่ๆที่ใช้ kernel 2.6 ขึ้นไป ซึ่งจะมีการใช้งาน udev (อะไรฟระ เกิดมาเพิ่งเคยได้ยิน เฮ้อ) มันจะมี rule file อยู่ ถ้าต้องการทำให้การเปลี่ยน permission เป็นไปอย่างถาวร สิ่งที่ต้องทำคือการแก้ไข rule file
rule file ที่เกี่ยวข้องกับ serial port (ttyS*) ก็คืิอ /etc/udev/rules.d/50-udev-default.rules
เปิดด้วย user root (super user) แล้วมองหา
KERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp"
หรืออะไรที่คล้ายกัน แล้วเพิ่ม MODE="777" ลงไป
ERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp", MODE="777"
เท่านั้นเอง
จากนั้น เปลี่ยน permission ของ /dev/ttyS* อีกรอบ แล้วก็ restart
คราวนี้ได้แล้วฮะ :)