LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-02-2005, 05:04 PM   #1
walwali
LQ Newbie
 
Registered: Jun 2005
Posts: 7

Rep: Reputation: 0
Passing groupadd to execv() returned error msg: "file already locked."


I am writing a program in linux to add group. The program calls execv("/usr/sbin/groupadd", "newGroupName"); This program failed returning the following error message: "Cannot lock group file: already locked." When I ran the "/usr/sbin/groupadd" command with "newGroupName" argument from the shell it worked and the newGroupName was created. I ran the new program with root privilages. Any idea why my program failed and which "group file" the error message is referring to?

Last edited by walwali; 06-02-2005 at 05:18 PM.
 
Old 06-02-2005, 05:09 PM   #2
walwali
LQ Newbie
 
Registered: Jun 2005
Posts: 7

Original Poster
Rep: Reputation: 0
Unhappy

hmmm

Last edited by walwali; 06-02-2005 at 05:20 PM.
 
Old 06-02-2005, 05:25 PM   #3
anandt4u
LQ Newbie
 
Registered: Jun 2005
Location: Montreal
Distribution: Fedora Core 3
Posts: 29

Rep: Reputation: 15
Re: Passing groupadd to execv() returned error msg: "file already locked."

Quote:
Originally posted by walwali
I am writing a program in linux to add group. The program calls execv("/usr/sbin/groupadd", "newGroupName"); This program failed returning the following error message: "Cannot lock group file: already locked." When I ran the "/usr/sbin/groupadd" command with "newGroupName" argument from the shell it worked and the newGroupName was created. I ran the new program with root privilages. Any idea why my program failed and which "group file" the error message is referring to?
was the program run as root??
 
Old 06-02-2005, 05:32 PM   #4
walwali
LQ Newbie
 
Registered: Jun 2005
Posts: 7

Original Poster
Rep: Reputation: 0
Yes!
 
Old 06-02-2005, 06:06 PM   #5
anandt4u
LQ Newbie
 
Registered: Jun 2005
Location: Montreal
Distribution: Fedora Core 3
Posts: 29

Rep: Reputation: 15
well i tried but it worked without errors but did not add any new group
 
Old 06-02-2005, 07:52 PM   #6
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
You're using execv() incorrectly. Check out the man page:
Quote:
int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);

The execv and execvp functions provide an array of point_
ers to null-terminated strings that represent the argument
list available to the new program. The first argument, by
convention, should point to the file name associated with
the file being executed. The array of pointers must be
terminated by a NULL pointer.
You're just passing in a string for the argv parameter. It doesn't work that way. Why don't you just use system() instead?
 
Old 06-02-2005, 11:12 PM   #7
walwali
LQ Newbie
 
Registered: Jun 2005
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by anandt4u
well i tried but it worked without errors but did not add any new group
Thanks anandt4u for following on with me. Actually the error message is embedded inside a CommandResult object and indicated by the global variable errno. To view it I had to have a logger that sends it messages to /var/log/messages. If the group isn't added then apparently your program isn't working either, you just can't see where it is failing.
 
Old 06-02-2005, 11:20 PM   #8
walwali
LQ Newbie
 
Registered: Jun 2005
Posts: 7

Original Poster
Rep: Reputation: 0
Hi itsme86. Actually I have used execv() correctly, I just did not list the whole thing in my post for simplicity.
I did create a const char* path variable and a const char* argv[2] whose first element contains the new group name and the second was NULL, then passed them to execv().
Add to that the error message the program returned was kind of showing that the problem was not the way execv() invoked, rather it seems like a file access conflict.
I've tried system() and it did not work either. It did not create the new group and returned a non zero value (I don't remember the returned value for sure now maybe 1280 or something, I can reproduce it if it make a difference, however it seems to me that it would have the same indication of the file lock conflict.)

Last edited by walwali; 06-03-2005 at 08:10 AM.
 
Old 06-03-2005, 10:59 AM   #9
anandt4u
LQ Newbie
 
Registered: Jun 2005
Location: Montreal
Distribution: Fedora Core 3
Posts: 29

Rep: Reputation: 15
After some googling and referring the man pages for execv, i tried this and it actually worked. There needs to be a null characted in the last. But i wonder why we should be repeating the groupadd command two times



Code:
#include<unistd.h>

int main(int args, char *argv[])
{
 char *cmd[]={"groupadd","newgroup",(char *)0};
 int a=execv("/usr/sbin/groupadd",cmd);
 printf("\n%d\n",a);
}
 
Old 11-22-2010, 06:36 AM   #10
jeename
LQ Newbie
 
Registered: Nov 2010
Posts: 1

Rep: Reputation: 0
My experience

I had the same problem,i tried everything manually but nothing worked,i am using a tool for all such type of errors which is available at pathtoodeep.com which will solve your problem in a click
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP! Error msg "Authentication Failure" legacyboy Linux - General 2 11-27-2005 03:36 PM
JBuilder install cancels - "No message error returned" bpatters Linux - Software 0 04-02-2004 01:57 PM
Synaptic error: "sub-process /usr/bin/dpkg returned an error code (2)" firefly2442 Linux - Software 3 02-04-2004 06:41 PM
Error: "mysqld dead but subsys locked" mikeshn Linux - Software 1 01-01-2004 05:18 PM
How can i add the "groupadd" command? kain Linux - General 3 11-14-2003 04:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration