Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I followed this tutorial guide on "How to Create Linux Proc Files in C Program using LKM".

I've successfully made my module and loaded it in. Now I want to echo to my proc file to make sure the method gets called that's supposed to be called.

I have tried:

$ echo "hello" > /proc/procEntry123       # But it says permission is denied!
$ sudo echo "hello" > /proc/procEntry123  # Same error message.

How can I elevate privileges to echo to this file? I am the sole user and admin on this system.

share|improve this question
    
"but I'm sudo", no actually you're su the super user. It stands for something like "Take this action as the super user" since the second half is do as in "do this, do that" –  TheZ Sep 28 '12 at 23:58

1 Answer 1

up vote 6 down vote accepted

But it says permission is denied!

It probably says so because you set restrictive permissions when calling create_proc_entry(). (0644 translates to "u=rw,go=r", which only gives write permissions to the owner, which defaults to root.)

I put "sudo" in front of it - same message.

Redirections such as > or | are performed by the running shell, before it invokes sudo.

You have to either use sudo sh -c "echo blah > /proc/blah", or run a root shell with sudo -s.

I am the only user - this is my own personal machine!

This does not matter in Linux. File permissions will be enforced regardless of who uses the computer.

If you don't want that, either log in as root, or use pam_cap to give yourself the cap_dac_override capability – but either method will cause troubles sooner or later.

share|improve this answer
2  
No, don't suggest that the inexperienced log in as root. That's a recipe for disaster! –  Darth Android Sep 28 '12 at 22:24
    
@DarthAndroid: If they can write a kernel module, they should have enough common sense not to do that. –  grawity Sep 28 '12 at 22:25
2  
But the problem isn't that you're suggesting this to an experienced user, it's that everyone, their brother, and their dog who visits this post will see that you suggested just throwing caution to the wind and logging in as root. There are already 23 views on this question, so essentially 23 people now might think this is okay. :) Just a thought... With that said, a lot of people will log in as root no matter what we tell them, so I guess it doesn't really matter... –  jmort253 Sep 29 '12 at 9:03
    
Hi guys - I chmod 777'd the proc file and it was solved. This excercise was purely experimentation so it doesn't matter that the file is rw for all. Thanks for your help! –  Sam Sep 29 '12 at 17:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.