Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a python script that needs to run as a normal user, but do to the fact that it is accessing digital IO ports I need root access. I tried setting the SUID
Code:
chmod 4755 file
and then tried running it as a normal user, but I still get a need to root error. Is there anyway around this problem?
Depending on what you are doing, you could always change the individual permission for the block device that you are using; In this case, a digital IO port. What exactly are you working on anyway? Just curious so I can help out...
Depending on what you are doing, you could always change the individual permission for the block device that you are using; In this case, a digital IO port. What exactly are you working on anyway? Just curious so I can help out...
Cheers,
Josh
I am using the python portio library to toggle a shutdown line to an external device. The code below works, but like I said I need to be root to execute it and I eventually need to do it as a normal user as part of an application. Either that or I need to add a new group to the sudoer list. I did that for a startup script that I need to run but I read that I could set the SUID to allow a normal user to run a script, but I have been unsuccessful so far.
Code:
import sys, time, os
import portio
# check for root privileges
if os.getuid():
print 'You need to be root! Exiting.'
sys.exit()
# acquire permission for I/O on lp0
#status = portio.ioperm(0x480, 1, 1)
status = portio.iopl(3)
if status:
print 'iopl:',os.strerror(status)
sys.exit()
#init the chipset
RetVal = 0
RetVal = portio.inb(0x4B0)
RetVal=RetVal|0x02
portio.outb(RetVal,0x4B0)
RetVal = portio.inb(0x481)
RetVal=RetVal|0xF0
portio.outb(RetVal,0x481)
RetVal = portio.inb(0x480)
RetVal=RetVal|0xC0
portio.outb(RetVal,0x480)
RetVal = portio.inb(0x4B4)
RetVal=RetVal|0x01
portio.outb(RetVal,0x4B4)
RetVal = portio.inb(0x485)
RetVal=RetVal&0x0F
portio.outb(RetVal,0x485)
RetVal = portio.inb(0x485)
RetVal=RetVal|0x02
portio.outb(RetVal,0x485)
RetVal = portio.inb(0x484)
RetVal=RetVal|0xC0
portio.outb(RetVal,0x484)
#reset the output pins to zero
RetVal = portio.inb(0x48d)
RetVal=RetVal&0x0F
portio.outb(RetVal,0x48d)
for i in range(1,10):
print ("LED ON!, \n",i)
#Set all DO0 to 1
portio.outb(0x10,0x48d) #DO0 is bit 4
#DO1 is bit 5
#DO2 is bit 6
#DO3 is bit 7
time.sleep(1)
print ("LED OFF!, \n",i)
#Set all output to 0
portio.outb(0x00,0x48d)
time.sleep(1)
print ("Hello World!, \n")
#### END
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.