1
/* Copyright (C) 2000-2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
17
#include "my_static.h"
18
#include "mysys_err.h"
23
my_bool my_init_done= 0;
24
uint mysys_usage_id= 0; /* Incremented for each my_init() */
25
ulong my_thread_stack_size= 65536;
27
static ulong atoi_octal(const char *str)
30
while (*str && my_isspace(&my_charset_latin1, *str))
33
(*str == '0' ? 8 : 10), /* Octalt or decimalt */
40
Init my_sys functions and my_sys variabels
47
1 Couldn't initialize environment
57
my_umask= 0660; /* Default umask for new files */
58
my_umask_dir= 0700; /* Default umask for new directories */
60
#if defined(THREAD) && defined(SAFE_MUTEX)
61
safe_mutex_global_init(); /* Must be called early */
63
#if defined(THREAD) && defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
64
fastmutex_global_init(); /* Must be called early */
67
#if defined(HAVE_PTHREAD_INIT)
68
pthread_init(); /* Must be called before DBUG_ENTER */
70
if (my_thread_global_init())
72
sigfillset(&my_signals); /* signals blocked by mf_brkhant */
75
DBUG_ENTER("my_init");
76
DBUG_PROCESS((char*) (my_progname ? my_progname : "unknown"));
78
{ /* Don't initialize twice */
79
if ((home_dir=getenv("HOME")) != 0)
80
home_dir=intern_filename(home_dir_buff,home_dir);
81
/* Default creation of new files */
82
if ((str=getenv("UMASK")) != 0)
83
my_umask=(int) (atoi_octal(str) | 0600);
84
/* Default creation of new dir's */
85
if ((str=getenv("UMASK_DIR")) != 0)
86
my_umask_dir=(int) (atoi_octal(str) | 0700);
87
DBUG_PRINT("exit",("home: '%s'",home_dir));
96
void my_end(int infoflag)
99
this code is suboptimal to workaround a bug in
100
Sun CC: Sun C++ 5.6 2004/06/02 for x86, and should not be
101
optimized until this compiler is not in use anymore
103
FILE *info_file= DBUG_FILE;
104
my_bool print_info= (info_file != stderr);
106
We do not use DBUG_ENTER here, as after cleanup DBUG is no longer
107
operational, so we cannot use DBUG_RETURN.
109
DBUG_PRINT("info",("Shutting down: infoflag: %d print_info: %d",
110
infoflag, print_info));
117
if ((infoflag & MY_CHECK_ERROR) || print_info)
119
{ /* Test if some file is left open */
120
if (my_file_opened | my_stream_opened)
122
sprintf(errbuff[0],EE(EE_OPEN_WARNING),my_file_opened,my_stream_opened);
123
(void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL);
124
DBUG_PRINT("error",("%s",errbuff[0]));
125
my_print_open_files();
129
my_error_unregister_all();
132
if ((infoflag & MY_GIVE_INFO) || print_info)
134
#ifdef HAVE_GETRUSAGE
137
/* Purify assumes that rus is uninitialized after getrusage call */
138
bzero((char*) &rus, sizeof(rus));
140
if (!getrusage(RUSAGE_SELF, &rus))
141
fprintf(info_file,"\n\
142
User time %.2f, System time %.2f\n\
143
Maximum resident set size %ld, Integral resident set size %ld\n\
144
Non-physical pagefaults %ld, Physical pagefaults %ld, Swaps %ld\n\
145
Blocks in %ld out %ld, Messages in %ld out %ld, Signals %ld\n\
146
Voluntary context switches %ld, Involuntary context switches %ld\n",
147
(rus.ru_utime.tv_sec * SCALE_SEC +
148
rus.ru_utime.tv_usec / SCALE_USEC) / 100.0,
149
(rus.ru_stime.tv_sec * SCALE_SEC +
150
rus.ru_stime.tv_usec / SCALE_USEC) / 100.0,
151
rus.ru_maxrss, rus.ru_idrss,
152
rus.ru_minflt, rus.ru_majflt,
153
rus.ru_nswap, rus.ru_inblock, rus.ru_oublock,
154
rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals,
155
rus.ru_nvcsw, rus.ru_nivcsw);
158
else if (infoflag & MY_CHECK_ERROR)
160
TERMINATE(stderr, 0); /* Print memory leaks on screen */
163
if (!(infoflag & MY_DONT_FREE_DBUG))
165
DBUG_END(); /* Must be done before my_thread_end */
169
my_thread_global_end();
170
#if defined(SAFE_MUTEX)
172
Check on destroying of mutexes. A few may be left that will get cleaned
173
up by C++ destructors
175
safe_mutex_end((infoflag & (MY_GIVE_INFO | MY_CHECK_ERROR)) ? stderr :
177
#endif /* defined(SAFE_MUTEX) */