Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Syntax using user define $>

by bigal_george (Acolyte)
on Jan 01, 2020 at 00:05 UTC ( [id://11110807]=perlquestion: print w/replies, xml ) Need Help??

bigal_george has asked for the wisdom of the Perl Monks concerning the following question:

Cant get my head around this works:
if($> && $> eq 0)
if ($>)
but this doesnt:
if($> eq 0) # sudo
if($> == 0) { # exec { "/path-to-wrapper-program" } # ( "/path-to-wrapper-program",$0,@ARGV); exec { "$0" } #<<<<<<<<<<<error if l +ast 2 ( "$0",$0,@ARGV); }

Seems like in above 2 $> is popped off a stack with null left.

Replies are listed 'Best First'.
Re: Syntax using user define $>
by jcb (Parson) on Jan 01, 2020 at 00:24 UTC

    What are you trying to accomplish?

    The expression $> && ($> == 0) should always be false and Deparse suggests that $> && $> eq 0 parses as that. Testing $> itself should be false iff you are running with EUID 0. Remember that UID values are numbers so you should compare them with the numeric comparisons rather than string comparisons in Perl; see perlop for more details.

      OK sorry if confusing.
      Testing $> itself should be false when sudo - yes.
      Goal is to allow sudo when needed by files permissions and user otherwise,
      Info I had said that when running administrator these should be called:
      use strict;
      use warnings FATAL=>"all";
      if($>)
      {
      exec { "/path-to-wrapper-program" }
      ( "/path-to-wrapper-program",$0,@ARGV);
      }
      My confusion was that Id assumed the exec call was for sudo but now seems pointless, as application runs fine without.

        Programs should not automatically reinvoke themselves using sudo, ever. If the program needs to be run with privileges and does not have them, simply report the "Permission Denied" error you get from the system to the user and let the user take the hint to retry with sudo.

Re: Syntax using user define $>
by LanX (Saint) on Jan 01, 2020 at 03:10 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11110807]
Approved by jcb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found