Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Bad file descriptor on system() call

    I'm running a fairly simple program that lets users add an account onto my server so they can connect through ftp. The problem comes in in the following line (I left in the debug lines as well):

    Code:
    system("sudo /usr/sbin/useradd $username");
    print "exit status: $?<br>\n";
    print "errors: $!<br>\n";
    The exit status is always 256, errors is always a "Bad file descriptor". In some fairly last ditch efforts to get this thing working, I've put chmod 777 on useradd and put the following line in my sudoers:

    Code:
    ALL     ALL=(ALL)       NOPASSWD: /usr/sbin/useradd
    I'll fix these to be more secure after this thing gets sorted out. I've looked on google for a solution to this, but most people are having this problem with windows, and it's because they're actually opening files. I'm not opening any files, and running 'sudo /usr/sbin/useradd username' in a terminal works fine. Does anyone have any idea of what's wrong, or do I need to give more details?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Code:
    system("sudo /usr/sbin/useradd $username") == 0 or die "code $?";
    see perlfunc man pages for system, there is some code there to test the value of $?.

    best regards

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I placed the following after the system call, hopefully it's what you were talking about:
    Code:
        if ($? == -1) {
    	print "failed to execute: $!\n";
        }
        elsif ($? & 127) {
    	printf "child died with signal %d, %s coredump\n",
    	    ($? & 127),  ($? & 128) ? 'with' : 'without';
        }
        else {
    	printf "child exited with value %d\n", $? >> 8;
        }
    When I run it it outputs the following:
    child exited with value 1

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Dustfinger View Post
    When I run it it outputs the following:
    child exited with value 1
    from sudo man page:
    RETURN VALUES
    Upon successful execution of a program, the return value from sudo will simply be the return value of the program that was executed.

    Otherwise, sudo quits with an exit value of 1 if there is a configuration/permission problem or if sudo cannot execute the given command. In the
    latter case the error string is printed to stderr.
    If sudo cannot stat(2) one or more entries in the user's PATH an error is printed on stderr.
    (If the directory does not exist or if it is not really a directory, the entry is ignored and no error is printed.) This should not happen under
    normal circumstances. The most common reason for stat(2) to return "permission denied" is if you are running an automounter and one of the directo-
    ries in your PATH is on a machine that is currently unreachable.
    from useradd man page:
    EXIT VALUES
    The useradd command exits with the following values:

    0
    success

    1
    can't update password file
    I don't have enought experience with runing sudo and useradd from perl, I guess you must check both cases.
    If this don't fix the problem another thing with runing from perl is the difference of enviroment, commands work in a terminal shell but not in perl script. This can be checked runing env from both and see the difference.

    best regards

  • Users who have thanked oesxyl for this post:

    Dustfinger (11-06-2008)

  • #5
    New Coder
    Join Date
    Jun 2007
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Alright, I think I'm on the right track. I'm gonna take this problem to a different forum, since I don't think it's a problem with my perl script. Here's the new thread, if anyone wants to follow this there:

    http://www.linuxforums.org/forum/ser...tml#post640506

    Thanks oesxyl for your help, I really appreciate it.

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Dustfinger View Post
    Alright, I think I'm on the right track. I'm gonna take this problem to a different forum, since I don't think it's a problem with my perl script. Here's the new thread, if anyone wants to follow this there:

    http://www.linuxforums.org/forum/ser...tml#post640506

    Thanks oesxyl for your help, I really appreciate it.
    you are welcome. When you fix the problem please post a link or a comment here to help other who have same problem.

    good luck and best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •