Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5311
  • Last Modified:

set "environment size" ksh aix

Hello out there,

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

Kind regards,

Ebe
0
ekariel
Asked:
ekariel
  • 6
  • 4
  • 3
1 Solution
 
GnsCommented:
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
 
ekarielAuthor Commented:
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
 
GnsCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gheistCommented:
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
 
ekarielAuthor Commented:
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
 
gheistCommented:
> How do I display set (increase) the environment SIZE for ksh under AIX?
Is ksh yet another C compiler ? A dialect ??
0
 
GnsCommented:
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
 
ekarielAuthor Commented:
NORKSEN is still there!

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

Ebe
0
 
GnsCommented:
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
 
ekarielAuthor Commented:
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
 
GnsCommented:
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
 
gheistCommented:
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
 
GnsCommented:
CC gheist, this question turned out to have little to do with ksh:-).

-- Glenn
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now