Solved

set "environment size" ksh aix

Posted on 2004-04-12
15
5,268 Views
Last Modified: 2013-11-17
Hello out there,

How do I display set (increase) the environment SIZE for ksh under AIX?

Kind regards,

Ebe
0
Comment
Question by:ekariel
  • 6
  • 4
  • 3
15 Comments
 
LVL 20

Expert Comment

by:Gns
ID: 10814242
Eh, Is there such a limit? Surely not imposed be ksh at least.
The "passing of environment" from parent to child is handled by the exec family of syscalls (man exec), and one can see there that the environment is defined as a "pointer to pointer to char" thingy (a vector of strings), where the end of environment is "signaled" by a NULL string. Could be pretty hefty on a 64 bit machine:-).

From the man-page of the IEEE POSIX 1003 limits.h file one can further glean
------- Start snip
Run-Time Invariant Values (Possibly Indeterminate)

The second set of run-time invariant values required by POSIX specify values
that might vary, especially due to system load, but that can be attained on a
lightly loaded system.

Symbol Value Explanation

ARG_MAX 24,576> Maximum length (in bytes) of arguments for the exec subroutine,
including the environment
Note: The argument list and environment are allowed to consume all of the user
data segment.
------- End snip
So this leads one to believe that one could "increase" this by use of the ulimit shell builtin (realistic only for root), or by changing the limit in /etc/security/limits (a -1 value == inifinity).

Or are you asking how to set and export the environment variable SIZE? "export SIZE=value" ...:-)... Nah, probably not.

-- Glenn
0
 

Author Comment

by:ekariel
ID: 10814530
Thanks Glenn. The short answer is - upgrade to AIX 5.1!! Then you can do the following:

ncargs
Purpose:  Specifies the maximum allowable size of the ARG/ENV list (in 4KB blocks) when running exec() subroutines.  
Values:  Default: 6; Range: 6 to 128  
Display:  lsattr -E -l sys0 -a ncargs  
Change:  chdev -l sys0 -a ncargs=NewValue
Change takes effect immediately and is preserved over boot.  
Diagnosis:  Users cannot execute any additional processes because the argument list passed to the exec() system call is too long.  
Tuning:  This is a mechanism to prevent the exec() subroutines from failing if the argument list is too long. Please note that tuning to a higher ncargs value puts additional constraints on system memory resources.  

This is from:

http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IBMp690/IBM/usr/share/man/info/en_US/a_doc_lib/aixbman/prftungd/2365a82.htm#HDRI48026

Another question then - how do you DELETE an environment variable under Unix? Putenv under Windows allows a null value to be treated as "delete the variable".

Kind regards,

Ebe
0
 
LVL 20

Expert Comment

by:Gns
ID: 10821119
Ah, and the default value for ncargs is 6... which is to say the POSIX limit. Good info. Thanks.

Deleting...
As you've seen, if you have
export aa=somestring
env | grep aa
... will give
aa=somestring
... and a subsequent
aa=
... will still keep aa around with a null value. You need do
unset aa
for it to go away:-).

Happy trails!

-- Glenn
0
 
LVL 61

Expert Comment

by:gheist
ID: 10846084
Thanks ekariel, ksh is broken (linked against old libraries i guess)
you have option to configure in AIX 5.1 , but ksh does not catch up still...
This is not about env list, but about args, so use xargs to split the list, or bash2 for finer limit

for ksh
export VAR=value # makes VAR containing value
unset VAR=value # removes variable
readonly VAR # locks out both previous

/etc/security/profile
default .profile for new user
/etc/environment
file run first to set env variables by tsm (Terminal Security Manager, known as login or pam on other systems)
/etc/profile
shell script run before user's .profile, export, readonly and unset goes here
0
 

Author Comment

by:ekariel
ID: 10871644
Ok - sorry about the delay - had a system to fix! Maybe I didn't state the problem clearly enough. unset works in the shell. I need the name of the API to call to achieve the same effect in a C program. As mentioned before, putenv under Windows allows a null VALUE to be treated as "delete the environment variable". This doesn't appear to be the case under Unix/Linux/AIX. Any ideas?

Kind regards,

Ebe

0
 
LVL 61

Expert Comment

by:gheist
ID: 10872090
> How do I display set (increase) the environment SIZE for ksh under AIX?
Is ksh yet another C compiler ? A dialect ??
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 20

Expert Comment

by:Gns
ID: 10876944
Ok... Well, the following "silly test.c"
main() {
        char tst[1200];

        strcpy(tst,"NORKSEN=BLARUTIG");
        system("env");
        putenv(tst);
        system("env");
        tst[8]='\0';
        system("env");
       
        tst[0]='\0';
        putenv(tst);
        system("env");
}
gives the following result (I'm using gcc 3.0.1 ... from bullfreeware):
$ gcc aa.c        
$ ./a.out|grep NOR
NORKSEN=BLARUTIG
NORKSEN=
$  

.... so, what was it that didn't work?

-- Glenn
0
 

Author Comment

by:ekariel
ID: 10877024
NORKSEN is still there!

cf with unset which deletes the name (NORKSEN) AND the value

Ebe
0
 
LVL 20

Expert Comment

by:Gns
ID: 10877077
No, NORKSEN goes away... at least in my example.
Count the systems... One afters setting NORKSEN=BLARUTIG, one after setting NORKSEN=\0 and finally one after unsetting it.

Or do you mean that in your compile environment the silly thing doesn't produce this output?

-- Glenn
0
 

Author Comment

by:ekariel
ID: 10877268
This doesn't make sense. As I read it:

        strcpy(tst,"NORKSEN=BLARUTIG");            /* value of tst is: NORKSEN=BLARUTIG
        system("env");
        putenv(tst);
        system("env");
        tst[8]='\0';                                                /* value of tst is: NORKSEN=
        system("env");
       
        tst[0]='\0';                                                /* value of tst is:
        putenv(tst);
        system("env");

So what are you putting/deleting? And why don't you get an error? Or am I just being obtuse here???

Ebe
0
 
LVL 20

Accepted Solution

by:
Gns earned 500 total points
ID: 10878480
The first putenv makes tst semimagical... It is now more like a reference into the environment vector. The second putenv is not necessary, apologies for that. Keep in mind that environment always propagate downwards... You cannot from a program (like a shell) run a program that will unset environment in the parent... Thus the shell builtin unset...:-).

To manipulate already set values, you can work with a char*, but this will be to the "value" part of the key-value pair... So you cannot use that to unset a value... Example:
#include <stdio.h>
#include <unistd.h>
main() {
        char tst[1200];
        char *tst2;

// This is to "illustrate" that you operate on the _value_ of TESTOLLE
        system("env");
        tst2=(char *)getenv("TESTOLLE");
        printf("TESTOLLE->%s\n",tst2);fflush(stdout);
        strcpy(tst2,NULL);
        printf("TESTOLLE->%s\n",tst2);fflush(stdout);
        system("env");
        putenv(tst2);

// This will remove TESTOLLE ... eventually:-) First get the value
        tst2=(char *)getenv("TESTOLLE");
// "Create" a new string...
        tst[0]='\0';
        sprintf(tst,"TESTOLLE=%s",tst2);
// ... and let it "take over" ...
        putenv(tst);
// ... and "kill TESTOLLE" ...
        tst[0]='\0';
        system("env");
        printf("No more TESTOLLE\n");
}

$ export TESTOLLE=ARGH
$ gcc aa.c
$ ./a.out|egrep "OLLE"
TESTOLLE=ARGH
TESTOLLE->ARGH
TESTOLLE->
TESTOLLE=
No more TESTOLLE
$

Clearer?

-- Glenn
0
 
LVL 61

Expert Comment

by:gheist
ID: 11077826
I am sure proposed answer in no way relates to question given, but I will agree with you, since it did much at educating the asker.
0
 
LVL 20

Expert Comment

by:Gns
ID: 11089038
CC gheist, this question turned out to have little to do with ksh:-).

-- Glenn
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now