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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-17-2007, 01:50 AM
|
#1
|
Member
Registered: Aug 2007
Location: The Greate INDIA
Distribution: CentOS, RHEL, Fedora
Posts: 102
Rep:
|
pseudo terminal - scp problem
hy frnds,
I am having a problem regarding pseudo terminal and scp command.
Let me explain the prob in brief...
I am developing a program which copies files to client pcs one by one.
For example I have one server and 5 client nodes.
and I have one "xmms-1.4.i386.rpm" in server, which i have to copy in all the 5 nodes. (for copying i am using "scp") without user interaction.
So I have implemented the pseudo terminal idea in my program.
Client IP and password id stored in a simple text file so I can directly read it, and can supply it in pseudo terminal.
but the problem is tht after copying the file the control is not returning back.
To call the "makeSecureCopy()" function u just need to read IP and passwd from text file one by one and then call the function.
I am using RHEL 4, 5, Redhat 9 and FC6 distro.
here is the code...
Code:
int makeSecureCopy (char *ip, char *pass, char *sSrcRPM )
{
int ptm=0, i=0;
char pts[MAX]="", buf[MAX*10]="";
pid_t pid;
makeCommand (sSrcRPM, ip /*HostIP*/,pass /*HostPass*/);
fprintf(stderr," About to install in ip = %s \n",ip);
if (((pid = forkpty (&ptm, pts, NULL, NULL))) == 0) //child
{
execl ("/bin/bash", "/bin/bash", NULL);
exit (1);
}
else
{
sleep (1); //let the child run first
fcntl (ptm, F_SETFL, fcntl (ptm, F_GETFL) | O_NONBLOCK);
for (i = 0; i < TOT_CMD; ++i)
{
bzero (buf, sizeof (buf));
while (!(read (ptm, buf, sizeof (buf)) == -1 && errno == EAGAIN))
{
sleep (3);
fprintf (stderr, "%s\n", buf);
bzero (buf, sizeof (buf));
}
write (ptm, cmd[i], strlen (cmd[i]));
write (STDOUT_FILENO, cmd[i], strlen (cmd[i]));
sleep (3);
}
bzero (buf, sizeof (buf));
while (!(read (ptm, buf, sizeof (buf)) == -1 && errno == EAGAIN));
fprintf (stderr, "waiting...");
wait (0);
}
fprintf(stdout,"Copying completed on %s client\n",ip);
return SUCCESS;
}
void makeCommand (char *rpm, char *ip, char *pass)
{
strcpy(cmd[0],"");
strcpy(cmd[1],"");
strcpy(cmd[2],"");
sprintf (cmd[0], "scp %s%s root@%s:%s\n", SERVER_PATCH_PATH, rpm, ip, CLIENT_PATCH_PATH);
sprintf (cmd[1], "%s\n", pass);
sprintf (cmd[3], "exit\n");
return;
}
any kind of help will be appreciated.
plz help me.......
|
|
|
08-17-2007, 08:59 PM
|
#2
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
I can't answer your question, but why do you do it that
way to begin with?
Just set-up a system user account with a login that's
disabled for ordinary logins; give him a password-less
login on the target machines (via public keypairs) and
do the job in a bash script ... no need to store passwords
in a flat-file.
Code:
for i in host1 host2 host3 host4 host5
do
scp file $i:/path/to/target
done
Cheers,
Tink
|
|
|
08-18-2007, 04:20 AM
|
#3
|
Member
Registered: Aug 2007
Location: The Greate INDIA
Distribution: CentOS, RHEL, Fedora
Posts: 102
Original Poster
Rep:
|
thnx Tinkster
hi Tinkster
Thx 4 ur replay....and I am appreciate ur sudgetion, but I can not use shell scripting in my software so, If u have any other solution of my C program then plz replay me.
Thanking you once again.
|
|
|
08-19-2007, 10:51 AM
|
#4
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078
Rep: 
|
What control are you talking about? Do you mean control of the terminal or are you saying the function doesn't return? Are you wanting the terminal to go back to the session leader? If so, you can't block SIGTTIO/SIGTTOU in the session leader because it will fail. It's safe to leave them unblocked ONLY in the session leader since it can revoke the terminal from anyone else without blocking or stopping. If you aren't talking about this, please specify.
ta0kira
Last edited by ta0kira; 08-20-2007 at 08:18 AM.
|
|
|
08-19-2007, 08:13 PM
|
#5
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,429
|
Actually, using rsync would enable you to do no programming.
Also, remember that rsync can use the ssh protocol if you need on-the-fly encryption.
|
|
|
08-20-2007, 01:22 AM
|
#6
|
Member
Registered: Aug 2007
Location: The Greate INDIA
Distribution: CentOS, RHEL, Fedora
Posts: 102
Original Poster
Rep:
|
dear ta0kira,
Thnx 4 replay, Let me explain my prob in detail.
wen u fork a process, then in parent u can wait for the child using wait() or waitpid() syscall.
In my given code I am waiting for the forked child (the child part in which i m execl the pseudo terminal "/bin/bash") but the child is not returning back and we control encounters the wait() syscall, it pauses and waits for infinite times (in short my prog pauses at this line, and not returning back for the next iteration)
This is the actual problem i m currently facing....
and ya, control doesnt returning means child process does not returning back in parent process.
so i can not get the exit status of child. If I got the exit status of child the problem is solved form me...
plz replay me...
btw thnk u very much 4 replay..
Last edited by vdx; 08-20-2007 at 01:34 AM.
|
|
|
08-20-2007, 08:22 AM
|
#7
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078
Rep: 
|
When the child process execs, it leaves the process group of the parent. To open a new controlling terminal it needs to be in its own session, so the problem is likely that the child process is no longer a child of the parent, so the parent can't waitpid it.
ta0kira
|
|
|
08-20-2007, 09:17 AM
|
#8
|
Member
Registered: Aug 2007
Location: The Greate INDIA
Distribution: CentOS, RHEL, Fedora
Posts: 102
Original Poster
Rep:
|
thnx ta0kira
thnk u very much 4 ur replay.
I got ur point very clear. And also finding solution for the same.
thnk u very much once again.
|
|
|
08-22-2007, 12:13 AM
|
#9
|
Member
Registered: Aug 2007
Location: The Greate INDIA
Distribution: CentOS, RHEL, Fedora
Posts: 102
Original Poster
Rep:
|
dear ta0kira
u said tht, "When the child process execs, it leaves the process group of the parent".
Thts ok, but I think tht If an execl process is setting sid bit for it, only then it can leave process group id of parent.
isn't it ??
and if it is or not then wt can be the solution ???
|
|
|
08-22-2007, 03:37 AM
|
#10
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078
Rep: 
|
I think you are thinking of "session" in place of "group". For example, when you have a command line with piped output each part of the command line is a different process, but they are all in the same group. They can be put into and taken out of the foreground as a group. All of the processes the shell has control over are a session, which can consist of many groups. A process can't have a different session without using setsid (in one form or another,) but can be moved from group to group by its session leader. When a fork execs, it takes on its own group so that signals to the session leader don't go directly to it. The session leader can then link all of the piped commands together and give it a single process group so pausing/continuing/fg/etc. affect all of them at once.
ta0kira
Last edited by ta0kira; 08-22-2007 at 03:52 AM.
|
|
|
All times are GMT -5. The time now is 06:46 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|