Link to home
Start Free TrialLog in
Avatar of ekariel
ekariel

asked on

set "environment size" ksh aix

Hello out there,

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

Kind regards,

Ebe
Avatar of Gns
Gns

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
Avatar of ekariel

ASKER

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
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
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
Avatar of ekariel

ASKER

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

> How do I display set (increase) the environment SIZE for ksh under AIX?
Is ksh yet another C compiler ? A dialect ??
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
Avatar of ekariel

ASKER

NORKSEN is still there!

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

Ebe
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
Avatar of ekariel

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Gns
Gns

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
CC gheist, this question turned out to have little to do with ksh:-).

-- Glenn