1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: generic Unix implementation of many wx functions
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
19 #include "wx/string.h"
26 #include "wx/process.h"
27 #include "wx/thread.h"
29 #include "wx/stream.h"
36 #include "wx/unix/execute.h"
39 // SGI signal.h defines signal handler arguments differently depending on
40 // whether _LANGUAGE_C_PLUS_PLUS is set or not - do set it
41 #if defined(__SGI__) && !defined(_LANGUAGE_C_PLUS_PLUS)
42 #define _LANGUAGE_C_PLUS_PLUS 1
49 #include <sys/types.h>
56 #include <fcntl.h> // for O_WRONLY and friends
57 #include <time.h> // nanosleep() and/or usleep()
58 #include <ctype.h> // isspace()
59 #include <sys/time.h> // needed for FD_SETSIZE
62 #include <sys/utsname.h> // for uname()
65 // ----------------------------------------------------------------------------
66 // conditional compilation
67 // ----------------------------------------------------------------------------
69 // many versions of Unices have this function, but it is not defined in system
70 // headers - please add your system here if it is the case for your OS.
71 // SunOS < 5.6 (i.e. Solaris < 2.6) and DG-UX are like this.
72 #if !defined(HAVE_USLEEP) && \
73 (defined(__SUN__) && !defined(__SunOs_5_6) && \
74 !defined(__SunOs_5_7) && !defined(__SUNPRO_CC)) || \
75 defined(__osf__) || defined(__EMX__)
79 int usleep(unsigned int usec
);
82 /* I copied this from the XFree86 diffs. AV. */
83 #define INCL_DOSPROCESS
85 inline void usleep(unsigned long delay
)
87 DosSleep(delay
? (delay
/1000l) : 1l);
90 void usleep(unsigned long usec
);
92 #endif // Sun/EMX/Something else
96 #endif // Unices without usleep()
98 // ============================================================================
100 // ============================================================================
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 void wxSleep(int nSecs
)
111 void wxUsleep(unsigned long milliseconds
)
113 #if defined(HAVE_NANOSLEEP)
115 tmReq
.tv_sec
= (time_t)(milliseconds
/ 1000);
116 tmReq
.tv_nsec
= (milliseconds
% 1000) * 1000 * 1000;
118 // we're not interested in remaining time nor in return value
119 (void)nanosleep(&tmReq
, (timespec
*)NULL
);
120 #elif defined(HAVE_USLEEP)
121 // uncomment this if you feel brave or if you are sure that your version
122 // of Solaris has a safe usleep() function but please notice that usleep()
123 // is known to lead to crashes in MT programs in Solaris 2.[67] and is not
124 // documented as MT-Safe
125 #if defined(__SUN__) && wxUSE_THREADS
126 #error "usleep() cannot be used in MT programs under Solaris."
129 usleep(milliseconds
* 1000); // usleep(3) wants microseconds
130 #elif defined(HAVE_SLEEP)
131 // under BeOS sleep() takes seconds (what about other platforms, if any?)
132 sleep(milliseconds
* 1000);
133 #else // !sleep function
134 #error "usleep() or nanosleep() function required for wxUsleep"
135 #endif // sleep function
138 // ----------------------------------------------------------------------------
139 // process management
140 // ----------------------------------------------------------------------------
142 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
)
144 int err
= kill((pid_t
)pid
, (int)sig
);
154 *rc
= wxKILL_BAD_SIGNAL
;
158 *rc
= wxKILL_ACCESS_DENIED
;
162 *rc
= wxKILL_NO_PROCESS
;
166 // this goes against Unix98 docs so log it
167 wxLogDebug(_T("unexpected kill(2) return value %d"), err
);
177 #define WXEXECUTE_NARGS 127
179 long wxExecute( const wxString
& command
, bool sync
, wxProcess
*process
)
181 wxCHECK_MSG( !command
.IsEmpty(), 0, wxT("can't exec empty command") );
184 wxChar
*argv
[WXEXECUTE_NARGS
];
186 const wxChar
*cptr
= command
.c_str();
187 wxChar quotechar
= wxT('\0'); // is arg quoted?
188 bool escaped
= FALSE
;
190 // split the command line in arguments
194 quotechar
= wxT('\0');
196 // eat leading whitespace:
197 while ( wxIsspace(*cptr
) )
200 if ( *cptr
== wxT('\'') || *cptr
== wxT('"') )
205 if ( *cptr
== wxT('\\') && ! escaped
)
212 // all other characters:
216 // have we reached the end of the argument?
217 if ( (*cptr
== quotechar
&& ! escaped
)
218 || (quotechar
== wxT('\0') && wxIsspace(*cptr
))
219 || *cptr
== wxT('\0') )
221 wxASSERT_MSG( argc
< WXEXECUTE_NARGS
,
222 wxT("too many arguments in wxExecute") );
224 argv
[argc
] = new wxChar
[argument
.length() + 1];
225 wxStrcpy(argv
[argc
], argument
.c_str());
228 // if not at end of buffer, swallow last character:
232 break; // done with this one, start over
238 // do execute the command
239 long lRc
= wxExecute(argv
, sync
, process
);
244 delete [] argv
[argc
++];
249 // ----------------------------------------------------------------------------
251 // ----------------------------------------------------------------------------
253 static wxString
wxMakeShellCommand(const wxString
& command
)
258 // just an interactive shell
263 // execute command in a shell
264 cmd
<< _T("/bin/sh -c '") << command
<< _T('\'');
270 bool wxShell(const wxString
& command
)
272 return wxExecute(wxMakeShellCommand(command
), TRUE
/* sync */) == 0;
275 bool wxShell(const wxString
& command
, wxArrayString
& output
)
277 wxCHECK_MSG( !!command
, FALSE
, _T("can't exec shell non interactively") );
279 return wxExecute(wxMakeShellCommand(command
), output
);
284 void wxHandleProcessTermination(wxEndProcessData
*proc_data
)
286 int pid
= (proc_data
->pid
> 0) ? proc_data
->pid
: -(proc_data
->pid
);
288 // waitpid is POSIX so should be available everywhere, however on older
289 // systems wait() might be used instead in a loop (until the right pid
294 // wait for child termination and if waitpid() was interrupted, try again
297 rc
= waitpid(pid
, &status
, 0);
299 while ( rc
== -1 && errno
== EINTR
);
302 if( rc
== -1 || ! (WIFEXITED(status
) || WIFSIGNALED(status
)) )
304 wxLogSysError(_("Waiting for subprocess termination failed"));
305 /* AFAIK, this can only happen if something went wrong within
306 wxGTK, i.e. due to a race condition or some serious bug.
307 After having fixed the order of statements in
308 GTK_EndProcessDetector(). (KB)
313 // notify user about termination if required
314 if (proc_data
->process
)
316 proc_data
->process
->OnTerminate(proc_data
->pid
,
317 WEXITSTATUS(status
));
320 if ( proc_data
->pid
> 0 )
326 // wxExecute() will know about it
327 proc_data
->exitcode
= status
;
336 // ----------------------------------------------------------------------------
337 // wxStream classes to support IO redirection in wxExecute
338 // ----------------------------------------------------------------------------
342 class wxProcessFileInputStream
: public wxInputStream
345 wxProcessFileInputStream(int fd
) { m_fd
= fd
; }
346 ~wxProcessFileInputStream() { close(m_fd
); }
348 virtual bool Eof() const;
351 size_t OnSysRead(void *buffer
, size_t bufsize
);
357 class wxProcessFileOutputStream
: public wxOutputStream
360 wxProcessFileOutputStream(int fd
) { m_fd
= fd
; }
361 ~wxProcessFileOutputStream() { close(m_fd
); }
364 size_t OnSysWrite(const void *buffer
, size_t bufsize
);
370 bool wxProcessFileInputStream::Eof() const
372 if ( m_lasterror
== wxSTREAM_EOF
)
375 // check if there is any input available
382 FD_SET(m_fd
, &readfds
);
383 switch ( select(m_fd
+ 1, &readfds
, NULL
, NULL
, &tv
) )
386 wxLogSysError(_("Impossible to get child process input"));
393 wxFAIL_MSG(_T("unexpected select() return value"));
394 // still fall through
397 // input available: check if there is any
398 return wxInputStream::Eof();
402 size_t wxProcessFileInputStream::OnSysRead(void *buffer
, size_t bufsize
)
404 int ret
= read(m_fd
, buffer
, bufsize
);
407 m_lasterror
= wxSTREAM_EOF
;
409 else if ( ret
== -1 )
411 m_lasterror
= wxSTREAM_READ_ERROR
;
416 m_lasterror
= wxSTREAM_NOERROR
;
422 size_t wxProcessFileOutputStream::OnSysWrite(const void *buffer
, size_t bufsize
)
424 int ret
= write(m_fd
, buffer
, bufsize
);
427 m_lasterror
= wxSTREAM_WRITE_ERROR
;
432 m_lasterror
= wxSTREAM_NOERROR
;
438 #endif // wxUSE_STREAMS
440 long wxExecute(wxChar
**argv
,
444 // for the sync execution, we return -1 to indicate failure, but for async
445 // case we return 0 which is never a valid PID
447 // we define this as a macro, not a variable, to avoid compiler warnings
448 // about "ERROR_RETURN_CODE value may be clobbered by fork()"
449 #define ERROR_RETURN_CODE ((sync) ? -1 : 0)
451 wxCHECK_MSG( *argv
, ERROR_RETURN_CODE
, wxT("can't exec empty command") );
455 char *mb_argv
[WXEXECUTE_NARGS
];
457 while (argv
[mb_argc
])
459 wxWX2MBbuf mb_arg
= wxConvertWX2MB(argv
[mb_argc
]);
460 mb_argv
[mb_argc
] = strdup(mb_arg
);
463 mb_argv
[mb_argc
] = (char *) NULL
;
465 // this macro will free memory we used above
466 #define ARGS_CLEANUP \
467 for ( mb_argc = 0; mb_argv[mb_argc]; mb_argc++ ) \
468 free(mb_argv[mb_argc])
470 // no need for cleanup
473 wxChar
**mb_argv
= argv
;
474 #endif // Unicode/ANSI
478 int end_proc_detect
[2];
479 if ( pipe(end_proc_detect
) == -1 )
481 wxLogSysError( _("Pipe creation failed") );
482 wxLogError( _("Failed to execute '%s'\n"), *argv
);
486 return ERROR_RETURN_CODE
;
490 // pipes for inter process communication
491 int pipeIn
[2], // stdin
492 pipeOut
[2], // stdout
493 pipeErr
[2]; // stderr
495 pipeIn
[0] = pipeIn
[1] =
496 pipeOut
[0] = pipeOut
[1] =
497 pipeErr
[0] = pipeErr
[1] = -1;
499 if ( process
&& process
->IsRedirected() )
501 if ( pipe(pipeIn
) == -1 || pipe(pipeOut
) == -1 || pipe(pipeErr
) == -1 )
504 // free previously allocated resources
505 close(end_proc_detect
[0]);
506 close(end_proc_detect
[1]);
509 wxLogSysError( _("Pipe creation failed") );
510 wxLogError( _("Failed to execute '%s'\n"), *argv
);
514 return ERROR_RETURN_CODE
;
525 if ( pid
== -1 ) // error?
528 close(end_proc_detect
[0]);
529 close(end_proc_detect
[1]);
538 wxLogSysError( _("Fork failed") );
542 return ERROR_RETURN_CODE
;
544 else if ( pid
== 0 ) // we're in child
547 close(end_proc_detect
[0]); // close reading side
550 // These lines close the open file descriptors to to avoid any
551 // input/output which might block the process or irritate the user. If
552 // one wants proper IO for the subprocess, the right thing to do is to
553 // start an xterm executing it.
556 for ( int fd
= 0; fd
< FD_SETSIZE
; fd
++ )
558 if ( fd
== pipeIn
[0] || fd
== pipeOut
[1] || fd
== pipeErr
[1]
560 || fd
== end_proc_detect
[1]
564 // don't close this one, we still need it
568 // leave stderr opened too, it won't do any hurm
569 if ( fd
!= STDERR_FILENO
)
574 // redirect stdio, stdout and stderr
575 if ( pipeIn
[0] != -1 )
577 if ( dup2(pipeIn
[0], STDIN_FILENO
) == -1 ||
578 dup2(pipeOut
[1], STDOUT_FILENO
) == -1 ||
579 dup2(pipeErr
[1], STDERR_FILENO
) == -1 )
581 wxLogSysError(_("Failed to redirect child process input/output"));
589 execvp (*mb_argv
, mb_argv
);
591 // there is no return after successful exec()
594 else // we're in parent
598 // pipe initialization: construction of the wxStreams
599 if ( process
&& process
->IsRedirected() )
602 // These two streams are relative to this process.
603 wxOutputStream
*outStream
= new wxProcessFileOutputStream(pipeIn
[1]);
604 wxInputStream
*inStream
= new wxProcessFileInputStream(pipeOut
[0]);
605 wxInputStream
*errStream
= new wxProcessFileInputStream(pipeErr
[0]);
607 process
->SetPipeStreams(inStream
, outStream
, errStream
);
608 #endif // wxUSE_STREAMS
610 close(pipeIn
[0]); // close reading side
611 close(pipeOut
[1]); // close writing side
612 close(pipeErr
[1]); // close writing side
615 #if wxUSE_GUI && !defined(__WXMICROWIN__)
616 wxEndProcessData
*data
= new wxEndProcessData
;
620 // we may have process for capturing the program output, but it's
621 // not used in wxEndProcessData in the case of sync execution
622 data
->process
= NULL
;
624 // sync execution: indicate it by negating the pid
626 data
->tag
= wxAddProcessCallback(data
, end_proc_detect
[0]);
628 close(end_proc_detect
[1]); // close writing side
633 // it will be set to 0 from GTK_EndProcessDetector
634 while (data
->pid
!= 0)
637 int exitcode
= data
->exitcode
;
643 else // async execution
645 // async execution, nothing special to do - caller will be
646 // notified about the process termination if process != NULL, data
647 // will be deleted in GTK_EndProcessDetector
648 data
->process
= process
;
650 data
->tag
= wxAddProcessCallback(data
, end_proc_detect
[0]);
652 close(end_proc_detect
[1]); // close writing side
657 wxASSERT_MSG( sync
, wxT("async execution not supported yet") );
660 if ( waitpid(pid
, &exitcode
, 0) == -1 || !WIFEXITED(exitcode
) )
662 wxLogSysError(_("Waiting for subprocess termination failed"));
669 // VMS does not recognise exit as a return and complains about
671 // I think VMS is wrong in this
677 #undef ERROR_RETURN_CODE
680 // ----------------------------------------------------------------------------
681 // file and directory functions
682 // ----------------------------------------------------------------------------
684 const wxChar
* wxGetHomeDir( wxString
*home
)
686 *home
= wxGetUserHome( wxString() );
688 if ( home
->IsEmpty() )
692 if ( tmp
.Last() != wxT(']'))
693 if ( tmp
.Last() != wxT('/')) *home
<< wxT('/');
695 return home
->c_str();
699 const wxMB2WXbuf
wxGetUserHome( const wxString
&user
)
700 #else // just for binary compatibility -- there is no 'const' here
701 char *wxGetUserHome( const wxString
&user
)
704 struct passwd
*who
= (struct passwd
*) NULL
;
710 if ((ptr
= wxGetenv(wxT("HOME"))) != NULL
)
714 if ((ptr
= wxGetenv(wxT("USER"))) != NULL
|| (ptr
= wxGetenv(wxT("LOGNAME"))) != NULL
)
716 who
= getpwnam(wxConvertWX2MB(ptr
));
719 // We now make sure the the user exists!
722 who
= getpwuid(getuid());
727 who
= getpwnam (user
.mb_str());
730 return wxConvertMB2WX(who
? who
->pw_dir
: 0);
733 // ----------------------------------------------------------------------------
734 // network and user id routines
735 // ----------------------------------------------------------------------------
737 // retrieve either the hostname or FQDN depending on platform (caller must
738 // check whether it's one or the other, this is why this function is for
740 static bool wxGetHostNameInternal(wxChar
*buf
, int sz
)
742 wxCHECK_MSG( buf
, FALSE
, wxT("NULL pointer in wxGetHostNameInternal") );
746 // we're using uname() which is POSIX instead of less standard sysinfo()
747 #if defined(HAVE_UNAME)
749 bool ok
= uname(&uts
) != -1;
752 wxStrncpy(buf
, wxConvertMB2WX(uts
.nodename
), sz
- 1);
755 #elif defined(HAVE_GETHOSTNAME)
756 bool ok
= gethostname(buf
, sz
) != -1;
757 #else // no uname, no gethostname
758 wxFAIL_MSG(wxT("don't know host name for this machine"));
761 #endif // uname/gethostname
765 wxLogSysError(_("Cannot get the hostname"));
771 bool wxGetHostName(wxChar
*buf
, int sz
)
773 bool ok
= wxGetHostNameInternal(buf
, sz
);
777 // BSD systems return the FQDN, we only want the hostname, so extract
778 // it (we consider that dots are domain separators)
779 wxChar
*dot
= wxStrchr(buf
, wxT('.'));
790 bool wxGetFullHostName(wxChar
*buf
, int sz
)
792 bool ok
= wxGetHostNameInternal(buf
, sz
);
796 if ( !wxStrchr(buf
, wxT('.')) )
798 struct hostent
*host
= gethostbyname(wxConvertWX2MB(buf
));
801 wxLogSysError(_("Cannot get the official hostname"));
807 // the canonical name
808 wxStrncpy(buf
, wxConvertMB2WX(host
->h_name
), sz
);
811 //else: it's already a FQDN (BSD behaves this way)
817 bool wxGetUserId(wxChar
*buf
, int sz
)
822 if ((who
= getpwuid(getuid ())) != NULL
)
824 wxStrncpy (buf
, wxConvertMB2WX(who
->pw_name
), sz
- 1);
831 bool wxGetUserName(wxChar
*buf
, int sz
)
836 if ((who
= getpwuid (getuid ())) != NULL
)
838 // pw_gecos field in struct passwd is not standard
840 char *comma
= strchr(who
->pw_gecos
, ',');
842 *comma
= '\0'; // cut off non-name comment fields
843 wxStrncpy (buf
, wxConvertMB2WX(who
->pw_gecos
), sz
- 1);
844 #else // !HAVE_PW_GECOS
845 wxStrncpy (buf
, wxConvertMB2WX(who
->pw_name
), sz
- 1);
846 #endif // HAVE_PW_GECOS/!HAVE_PW_GECOS
853 wxString
wxGetOsDescription()
855 #ifndef WXWIN_OS_DESCRIPTION
856 #error WXWIN_OS_DESCRIPTION should be defined in config.h by configure
858 return WXWIN_OS_DESCRIPTION
;
862 // this function returns the GUI toolkit version in GUI programs, but OS
863 // version in non-GUI ones
866 int wxGetOsVersion(int *majorVsn
, int *minorVsn
)
871 if ( sscanf(WXWIN_OS_DESCRIPTION
, "%s %d.%d", name
, &major
, &minor
) != 3 )
873 // unreckognized uname string format
887 long wxGetFreeMemory()
889 #if defined(__LINUX__)
890 // get it from /proc/meminfo
891 FILE *fp
= fopen("/proc/meminfo", "r");
897 if ( fgets(buf
, WXSIZEOF(buf
), fp
) && fgets(buf
, WXSIZEOF(buf
), fp
) )
899 long memTotal
, memUsed
;
900 sscanf(buf
, "Mem: %ld %ld %ld", &memTotal
, &memUsed
, &memFree
);
907 #elif defined(__SUN__) && defined(_SC_AVPHYS_PAGES)
908 return sysconf(_SC_AVPHYS_PAGES
)*sysconf(_SC_PAGESIZE
);
909 //#elif defined(__FREEBSD__) -- might use sysctl() to find it out, probably
916 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
921 if ( statfs(path
, &fs
) != 0 )
923 wxLogSysError("Failed to get file system statistics");
930 *pTotal
= wxLongLong(fs
.f_blocks
) * fs
.f_bsize
;
935 *pFree
= wxLongLong(fs
.f_bavail
) * fs
.f_bsize
;
939 #endif // HAVE_STATFS
944 // ----------------------------------------------------------------------------
946 // ----------------------------------------------------------------------------
948 bool wxGetEnv(const wxString
& var
, wxString
*value
)
950 // wxGetenv is defined as getenv()
951 wxChar
*p
= wxGetenv(var
);
963 bool wxSetEnv(const wxString
& variable
, const wxChar
*value
)
965 #if defined(HAVE_SETENV)
966 return setenv(variable
.mb_str(), value
? wxString(value
).mb_str().data()
967 : NULL
, 1 /* overwrite */) == 0;
968 #elif defined(HAVE_PUTENV)
969 wxString s
= variable
;
971 s
<< _T('=') << value
;
974 const char *p
= s
.mb_str();
976 // the string will be free()d by libc
977 char *buf
= (char *)malloc(strlen(p
) + 1);
980 return putenv(buf
) == 0;
981 #else // no way to set an env var
986 // ----------------------------------------------------------------------------
988 // ----------------------------------------------------------------------------
990 #if wxUSE_ON_FATAL_EXCEPTION
994 static void wxFatalSignalHandler(wxTYPE_SA_HANDLER
)
998 // give the user a chance to do something special about this
999 wxTheApp
->OnFatalException();
1005 bool wxHandleFatalExceptions(bool doit
)
1008 static bool s_savedHandlers
= FALSE
;
1009 static struct sigaction s_handlerFPE
,
1015 if ( doit
&& !s_savedHandlers
)
1017 // install the signal handler
1018 struct sigaction act
;
1020 // some systems extend it with non std fields, so zero everything
1021 memset(&act
, 0, sizeof(act
));
1023 act
.sa_handler
= wxFatalSignalHandler
;
1024 sigemptyset(&act
.sa_mask
);
1027 ok
&= sigaction(SIGFPE
, &act
, &s_handlerFPE
) == 0;
1028 ok
&= sigaction(SIGILL
, &act
, &s_handlerILL
) == 0;
1029 ok
&= sigaction(SIGBUS
, &act
, &s_handlerBUS
) == 0;
1030 ok
&= sigaction(SIGSEGV
, &act
, &s_handlerSEGV
) == 0;
1033 wxLogDebug(_T("Failed to install our signal handler."));
1036 s_savedHandlers
= TRUE
;
1038 else if ( s_savedHandlers
)
1040 // uninstall the signal handler
1041 ok
&= sigaction(SIGFPE
, &s_handlerFPE
, NULL
) == 0;
1042 ok
&= sigaction(SIGILL
, &s_handlerILL
, NULL
) == 0;
1043 ok
&= sigaction(SIGBUS
, &s_handlerBUS
, NULL
) == 0;
1044 ok
&= sigaction(SIGSEGV
, &s_handlerSEGV
, NULL
) == 0;
1047 wxLogDebug(_T("Failed to uninstall our signal handler."));
1050 s_savedHandlers
= FALSE
;
1052 //else: nothing to do
1057 #endif // wxUSE_ON_FATAL_EXCEPTION
1059 // ----------------------------------------------------------------------------
1060 // error and debug output routines (deprecated, use wxLog)
1061 // ----------------------------------------------------------------------------
1063 void wxDebugMsg( const char *format
, ... )
1066 va_start( ap
, format
);
1067 vfprintf( stderr
, format
, ap
);
1072 void wxError( const wxString
&msg
, const wxString
&title
)
1074 wxFprintf( stderr
, _("Error ") );
1075 if (!title
.IsNull()) wxFprintf( stderr
, wxT("%s "), WXSTRINGCAST(title
) );
1076 if (!msg
.IsNull()) wxFprintf( stderr
, wxT(": %s"), WXSTRINGCAST(msg
) );
1077 wxFprintf( stderr
, wxT(".\n") );
1080 void wxFatalError( const wxString
&msg
, const wxString
&title
)
1082 wxFprintf( stderr
, _("Error ") );
1083 if (!title
.IsNull()) wxFprintf( stderr
, wxT("%s "), WXSTRINGCAST(title
) );
1084 if (!msg
.IsNull()) wxFprintf( stderr
, wxT(": %s"), WXSTRINGCAST(msg
) );
1085 wxFprintf( stderr
, wxT(".\n") );
1086 exit(3); // the same exit code as for abort()