LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-31-2003, 08:14 AM   #1
GŠutama
Member
 
Registered: Jun 2003
Location: Tokyo
Distribution: Gentoo
Posts: 78

Rep: Reputation: 15
atexit and exit code


I have been using the on_exit function to register a clean up function that is executed when a program exits. However on_exit does not exist on Solaris machines, they only have an atexit function. The atexti function does roughly the same work but I can't figure out how to get the registered atexit function to get the exit code of the program.

The on_exit function gives this as an argument.

Have you any ideas on how to find the original programs exit code in the registered function?
 
Old 10-31-2003, 10:41 AM   #2
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
Unfortunately I don't think you can.
You can set a global variable that your exit
function uses though.
so you can do something like:
Code:
global_var = myexitcode;
exit(myexitcode);

void my_exit_func(void)
{
        switch(myexitcode) {
        ...
        }
}
 
Old 10-31-2003, 12:24 PM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
If you run library functions that set errno, it MAY be available to your exit routine, depending on what you do after errno gets set.
Your can can also deliberately set errno - if you're positive that no intervening call could set it to another value.

If you do that, be sure to use
Code:
#define EUSERVAL  somevalue
where somevalue is NOT one already used by errno.h for the standard defined Exxxx messages.
 
Old 11-01-2003, 03:15 AM   #4
GŠutama
Member
 
Registered: Jun 2003
Location: Tokyo
Distribution: Gentoo
Posts: 78

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by LogicG8

Code:
global_var = myexitcode;
exit(myexitcode);

void my_exit_func(void)
{
        switch(myexitcode) {
        ...
        }
}
This is the same solution I had. So I guess this is the way to go. Even-though it would be nice to use some solution that uses some library functions / features. I don't think I can use jims solution since I use a fair amount of functions that set errno.

hmm. I think I have to go for the global var solution even-though I hope there is something I haven't thought about.

If you come up with something else let me know.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exit Code: 7 dbzw Suse/Novell 0 12-21-2004 02:06 PM
exit code 2 -- pppd eduac Linux - Software 3 11-21-2003 06:19 AM
pppd exit code = 10 eduac Linux - Hardware 1 10-20-2003 03:57 AM
kppp - exit code 1 grim1234 Slackware 3 09-02-2003 10:01 AM
pppd exit code 16 ksgill Linux - Newbie 8 07-12-2003 11:20 PM


All times are GMT -5. The time now is 05:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration