Operating System - HP-UX
1830227 Members
2689 Online
109999 Solutions
New Discussion

Re: question abt system command and exec command

 
yonjon
Occasional Contributor

question abt system command and exec command

Hi Everyone,

exec command kicking two copies of script file .startup during initial login. Here is the setup of my login in the /etc/passwd file.

============================================================
userid:*:59190:501:rp*C,RP,XX,xXX:/home/user:/home/user/prog1
===========================================================
prog1 looks like following.
main()
{
execlp("./.startup",getlogin(), 0);
}
===============================================
/home/userid/.startup looks like following
settting some of the environments variables and kicking off prog2 binary.
/home/userid/prog2
==============================================
prog2 looks like following:
main()
{
system("/home/userid/prog3");
}
==============================================

The problem is prog2 is kicking off another copy of .startup file from prog1. I know system command is kickin off execl command. Is there any other c or system funciton i can use in prog2 so that it does not kick the .startup script again. Any answer would be appreciated. Thanks.
4 REPLIES 4
RAC_1
Honored Contributor

Re: question abt system command and exec command

Does the startup script do only variable siignment?? Then in the script itself, check if varibale is set or not and if not then set it.

Anil
There is no substitute to HARDWORK
yonjon
Occasional Contributor

Re: question abt system command and exec command

Anil,

Due to some constraints, I need to do all this within the C program. Thanks.

Biren
Biswajit Tripathy
Honored Contributor

Re: question abt system command and exec command

May be I don't understand the problem you are
trying to solve, but it looks like you are making it
more complicated that it is. For ex:

> /home/userid/.startup looks like following
> settting some of the environments variables and
> kicking off prog2 binary.
> /home/userid/prog2
>
>prog2 looks like following:
>main()
> {
>system("/home/userid/prog3");
>}

1) Since prog2 just forks a shell and executes
prog3, why can't you change .startup to call prog3
instead of prog2 ?

2) Even better than #1 is, why can't you decide
what the value of env variables in prog1.c itself and
call system() or exec() to run prog3 with these env
variables. That way, all your code with be one C
program.

- Biswajit

:-)
yonjon
Occasional Contributor

Re: question abt system command and exec command

sorry for confusion.

Ok prog2 needs to be root with sticky bit for setgid command to run successful. I can not give prog1 root ownership coz of security violation. That is why i am calling prog3 from prog2. Thanks.

Biren