Go Back   openSUSE Forums > Programming/Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read


Programming/Scripting Questions about programming, bash scripts, perl, php, cron jobs, ruby, python, etc.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 25-Sep-2009, 15:27
Puzzled Penguin
 
Join Date: Mar 2009
Posts: 28
pwright2 hasn't been rated much yet
Default Daemon Idea

I am trying to write a daemon in perl that "watches" a directory (using perl-linux-Inotify2).

I have written the script and am satisfied with it. I would like this to automatically start at boot and cleanly be started and stopped with an rc like command. I was able to put something together using Cool Solutions: Creating Custom init Scripts.

However, I would like this script to run under an unprivileged daemon account (as many other daemons do). I don't know many options here. If I use sudo within the script, it spawns a new process and this is not cleaned up by the rc scripts. The setuid bit won't work because it is a script instead of a binary file, so this won't run as my unprivileged user.

Any ideas? Should I just write this program in C, compile it, and use the setuid bit?
Reply With Quote
  #2 (permalink)  
Old 25-Sep-2009, 15:44
Explorer Penguin
 
Join Date: Apr 2009
Posts: 686
ab@novell.com hasn't been rated much yet
Default Re: Daemon Idea

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Assuming you are using the CS exactly you are using startproc and
killproc, presumably. Thankfully, those are good commands.

man startproc

-u user
Sets the user ID of the process to user.

There ya go.

Good luck.






pwright2 wrote:
> I am trying to write a daemon in perl that "watches" a directory (using
> perl-linux-Inotify2).
>
> I have written the script and am satisfied with it. I would like this
> to automatically start at boot and cleanly be started and stopped with
> an rc like command. I was able to put something together using 'Cool
> Solutions: Creating Custom init Scripts'
> (http://www.novell.com/coolsolutions/feature/15380.html).
>
> However, I would like this script to run under an unprivileged daemon
> account (as many other daemons do). I don't know many options here. If I
> use sudo within the script, it spawns a new process and this is not
> cleaned up by the rc scripts. The setuid bit won't work because it is a
> script instead of a binary file, so this won't run as my unprivileged
> user.
>
> Any ideas? Should I just write this program in C, compile it, and use
> the setuid bit?
>
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJKvSuhAAoJEF+XTK08PnB55fkQAJUwPqE/so+MqWqUSMawKB1y
LrpMpnBgg7BmITrZfEtf6Fp9BekkF89cjIMJ/UJ20aJL5J0LoEBAy98ywgw265CZ
G0TeHpH002u1ely1xWAMzkPYTiEr5QAzrsN8QyAzpEdf7LHJU0 Ph+rvBC94lx7UL
8B3tDao6cMFRoFc9LB8lVviJCqzVtSeVUwGr03kmqzsmqs9fn1 C9hSQDYedgLv30
M0i2CrWkqM/7GbPbcY7FeH7+Z/VGzspzbA5dJEBKBFACfQEaKQ2owVPBcCyf93Qo
zrTyJBz5dmLxU96os23Cbfd6sfAKM5ri6u8TvM7kaJa0HBgUvM YSE7g1CVMpOYbn
/On6xPr2YxHEEjrIu6vxOdHoVcP1kfP9esgdiUS1CiRyszQJMBr yoOB3cJLH7/Pd
732ALZXHc+LU//SYFyfgzkronkZGwHxV4/Ga40pO2jGQuytNz+N8z8rx9D88qN4w
qADEzEdtOrmWd2dA3lNeMGTs51kKxEDcF0Q8txWGL1abq9Ba6d rD6rNbI+4pSSNl
E5yYHqlDd2JCg7qKqCvKpUCM9Vcs/97dlvw5Q71Icfv9VOqOzXNx+aLHZWaOClWH
L/Tgk5S0O284lgkWrA/gGvpwvp21l5OnL8KwVLyuZiwEDBE3UQgsTd5z3J9dqXQ8
5dC82iPJR5Z2fG5LJpDt
=iMqU
-----END PGP SIGNATURE-----
Reply With Quote
  #3 (permalink)  
Old 30-Sep-2009, 22:59
Puzzled Penguin
 
Join Date: Sep 2009
Posts: 8
craverii hasn't been rated much yet
Default Re: Daemon Idea

Write a C wrapper to start (and stop) the process. There's an example of a small C wrapper for a Perl script in the camel book. The compiled C wrapper may, of course, have the setuid bit set.
Reply With Quote
Reply

Bookmarks

Tags
daemon, unprivileged accout


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2