FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > RPM Package Manager

 
 
LinkBack Thread Tools
 
Old 08-11-2008, 07:46 AM
"Erez Zilber"
 
Default env variable is not defined when running rpmbuild --rebuild

Hi,

I have a problem with an env variable while running rpmbuild --rebuild
/usr/src/redhat/SRPMS/mypackage-0-0.1.src.rpm:

before running rpmbuild, I run the following commands:

[erez.zilber@klab002:~/work/]$ sudo bash -c 'export MY_ENV_VAR=some_val'
[erez.zilber@klab002:~/work/]$ sudo echo $MY_ENV_VAR
some_val

In the spec file, I print this env var:

%build
echo "MY_ENV_VAR = $MY_ENV_VAR"

but when I run rpmbuild --rebuild
/usr/src/redhat/SRPMS/mypackage-0-0.1.src.rpm, I get:

+ LANG=C
+ export LANG
+ unset DISPLAY
+ echo 'MY_ENV_VAR = '
MY_ENV_VAR =

I guess that it opens another shell in which the env var is not
defined. How can I solve that (without adding the env var to .bashrc
which is not a possible solution for me).

Thanks,
Erez

_______________________________________________
Rpm-list mailing list
Rpm-list@redhat.com
https://www.redhat.com/mailman/listinfo/rpm-list
 
Old 08-11-2008, 05:17 PM
Bob Proulx
 
Default env variable is not defined when running rpmbuild --rebuild

Erez Zilber wrote:
> before running rpmbuild, I run the following commands:
> [erez.zilber@klab002:~/work/]$ sudo bash -c 'export MY_ENV_VAR=some_val'

This has no effect because in Unix and Unix-like systems every process
starts with a copy of the current environment and at the termination
of the program the copied environment for that program is reclaimed by
the system.

In the above you are spawning a new environment for the 'sudo'
command. That is spawning a new environment for the 'bash' command.
In the bash process the environment variable is being set. That is
the entirety of the bash script and the bash process terminates at
that point. The system frees and reclaims all of the process memory
associated with the bash process including all environment memory
space. The sudo command has been waiting for the bash process to
exit. It observes the program exit code and then the sudo process
itself exits. When the sudo process exits the process memory
including all environment memory is freed and reclaimed by the
system.

> [erez.zilber@klab002:~/work/]$ sudo echo $MY_ENV_VAR
> some_val

This is because you have already set MY_ENV_VAR in the parent
environment. The $MY_ENV_VAR is expanded by the shell before it
invokes the sudo. The sudo then invokes echo with the some_val
argument. Try this for comparison:

$ echo debug: sudo echo $MY_ENV_VAR
debug: sudo echo some_val

The $MY_ENV_VAR will already have been expanded by the original
invoking command line shell.

> In the spec file, I print this env var:
>
> %build
> echo "MY_ENV_VAR = $MY_ENV_VAR"
> but when I run rpmbuild --rebuild
> /usr/src/redhat/SRPMS/mypackage-0-0.1.src.rpm, I get:
>
> + LANG=C
> + export LANG
> + unset DISPLAY
> + echo 'MY_ENV_VAR = '
> MY_ENV_VAR =
>
> I guess that it opens another shell in which the env var is not
> defined. How can I solve that (without adding the env var to .bashrc
> which is not a possible solution for me).

Export the variable in the parent environment. It will then be
inhereted by the child environments.

Either for the specific command:

$ MY_ENV_VAR=some_val rpmbuild --rebuild mypackage-0-0.1.src.rpm

Or:

$ export MY_ENV_VAR=some_val
$ rpmbuild --rebuild mypackage-0-0.1.src.rpm

Note that it is dangerous to use sudo to build rpm packages. This
causes the build to run as root. You don't want to do that. The
wisdom of thet 'net is that this should be avoided. Package building
should be done as a non-privileged user.

Bob

_______________________________________________
Rpm-list mailing list
Rpm-list@redhat.com
https://www.redhat.com/mailman/listinfo/rpm-list
 
Old 08-12-2008, 07:05 AM
"Erez Zilber"
 
Default env variable is not defined when running rpmbuild --rebuild

On Mon, Aug 11, 2008 at 8:17 PM, Bob Proulx <bob@proulx.com> wrote:
> Erez Zilber wrote:
>> before running rpmbuild, I run the following commands:
>> [erez.zilber@klab002:~/work/]$ sudo bash -c 'export MY_ENV_VAR=some_val'
>
> This has no effect because in Unix and Unix-like systems every process
> starts with a copy of the current environment and at the termination
> of the program the copied environment for that program is reclaimed by
> the system.
>
> In the above you are spawning a new environment for the 'sudo'
> command. That is spawning a new environment for the 'bash' command.
> In the bash process the environment variable is being set. That is
> the entirety of the bash script and the bash process terminates at
> that point. The system frees and reclaims all of the process memory
> associated with the bash process including all environment memory
> space. The sudo command has been waiting for the bash process to
> exit. It observes the program exit code and then the sudo process
> itself exits. When the sudo process exits the process memory
> including all environment memory is freed and reclaimed by the
> system.
>
>> [erez.zilber@klab002:~/work/]$ sudo echo $MY_ENV_VAR
>> some_val
>
> This is because you have already set MY_ENV_VAR in the parent
> environment. The $MY_ENV_VAR is expanded by the shell before it
> invokes the sudo. The sudo then invokes echo with the some_val
> argument. Try this for comparison:
>
> $ echo debug: sudo echo $MY_ENV_VAR
> debug: sudo echo some_val
>
> The $MY_ENV_VAR will already have been expanded by the original
> invoking command line shell.
>
>> In the spec file, I print this env var:
>>
>> %build
>> echo "MY_ENV_VAR = $MY_ENV_VAR"
>> but when I run rpmbuild --rebuild
>> /usr/src/redhat/SRPMS/mypackage-0-0.1.src.rpm, I get:
>>
>> + LANG=C
>> + export LANG
>> + unset DISPLAY
>> + echo 'MY_ENV_VAR = '
>> MY_ENV_VAR =
>>
>> I guess that it opens another shell in which the env var is not
>> defined. How can I solve that (without adding the env var to .bashrc
>> which is not a possible solution for me).
>
> Export the variable in the parent environment. It will then be
> inhereted by the child environments.
>
> Either for the specific command:
>
> $ MY_ENV_VAR=some_val rpmbuild --rebuild mypackage-0-0.1.src.rpm
>
> Or:
>
> $ export MY_ENV_VAR=some_val
> $ rpmbuild --rebuild mypackage-0-0.1.src.rpm
>
> Note that it is dangerous to use sudo to build rpm packages. This
> causes the build to run as root. You don't want to do that. The
> wisdom of thet 'net is that this should be avoided. Package building
> should be done as a non-privileged user.
>
> Bob
>

Thanks! That was very helpful.

Erez

_______________________________________________
Rpm-list mailing list
Rpm-list@redhat.com
https://www.redhat.com/mailman/listinfo/rpm-list
 

Thread Tools




All times are GMT. The time now is 02:52 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org