Solved

set "environment size" ksh aix

Posted on 2004-04-12
15
5,272 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to backup and restore the DHCP configuration on Solaris 9 7 41
Unix / Linux grid computing 5 148
IBM flash storage 840 15 58
add some character at the end of line in vi 7 63
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

920 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

16 Experts available now in Live!

Get 1:1 Help Now