in reply to RE: onlyone
in thread onlyone
Thanks for taking the time to reply :)
- open (FROMKID, "-|") or exec ("who", "-m") or system_log ("Can't run who: $!");
You probably want to die here, otherwise both processes (open here does an implicit fork) would continue to run in the event your exec fails.
Ah, so the die in the open ... or exec ... or die construct actually applies to the child, not the entire script? I was trying to make sure that any runtime errors get logged to the system logger, so I can diagnose problems after the event, hence the exit 1 on the following line. Is there a better way of trying to achive this?
-
Regular expressions like /tty(.*?)\s/ are probably a little more efficient written like /tty(\S+)/.
I'm slowly starting to get to grips with regexp, however I do find it confusing when perl, tcl, and sed seem to do things slightly differently!
- $killresult = kill 15, $1;
Your code will be a bit more readable if you were to use, say, 'TERM' instead of 15.
That would be better, I hadn't realised I could do that - is that a product of the English module, or built in?
- ... or system_log ("Can't run ps: $!");
While I don't see any immediate problem, since $! probably won't be touched by the user, you don't generally want to call syslog with only a single (well, this second) argument, because it leaves you open to format-based attacks.
Thanks for the heads up - I shall adjust my calls to the system_log subroutine accordingly.
- my $hit_enter = <STDIN>;
If you're just discarding the input anyway, just call <STDIN> in a void context:
<STDIN>;I keep getting confused over when I can do that, and when I can't - guess it's also because my other main programming language is a varient on Basic!
-
I'm curious what you're using the English module for..? You don't seem to be using the "long" versions of any system variables.
Ah, that's left over from when I was creating a load of code to make the child safe in open's, but then changed my mind and decided to make the entire script safe instead.
Kudos for using strict, but I'd be most impressed if your script ran warning-free with the -wT options (even if you don't need to use them in your end product).
I must get into the habit of doing that!
Hope this helps!
Immensely, thanks very much :)