~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2003 MySQL AB
2
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.
6
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.
11
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 */
15
16
#include "mysys_priv.h"
17
#include "my_static.h"
202.3.6 by Monty Taylor
First pass at gettexizing the error messages.
18
#include <mysys/mysys_err.h>
212.5.18 by Monty Taylor
Moved m_ctype, m_string and my_bitmap. Removed t_ctype.
19
#include <mystrings/m_string.h>
20
#include <mystrings/m_ctype.h>
612.2.6 by Monty Taylor
OpenSolaris builds.
21
#include <stdio.h>
629.1.1 by Monty Taylor
More solaris fixes.
22
#include <stdlib.h>
1 by brian
clean slate
23
146 by Brian Aker
my_bool cleanup.
24
bool my_init_done= 0;
1 by brian
clean slate
25
uint	mysys_usage_id= 0;              /* Incremented for each my_init() */
26
298 by Brian Aker
ulong conversion.
27
static uint32_t atoi_octal(const char *str)
1 by brian
clean slate
28
{
29
  long int tmp;
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
30
  while (*str && my_isspace(&my_charset_utf8_general_ci, *str))
1 by brian
clean slate
31
    str++;
32
  str2int(str,
33
	  (*str == '0' ? 8 : 10),       /* Octalt or decimalt */
34
	  0, INT_MAX, &tmp);
298 by Brian Aker
ulong conversion.
35
  return (uint32_t) tmp;
1 by brian
clean slate
36
}
37
38
39
/*
40
  Init my_sys functions and my_sys variabels
41
42
  SYNOPSIS
43
    my_init()
44
45
  RETURN
46
    0  ok
47
    1  Couldn't initialize environment
48
*/
49
146 by Brian Aker
my_bool cleanup.
50
bool my_init(void)
1 by brian
clean slate
51
{
52
  char * str;
53
  if (my_init_done)
54
    return 0;
55
  my_init_done=1;
56
  mysys_usage_id++;
57
  my_umask= 0660;                       /* Default umask for new files */
58
  my_umask_dir= 0700;                   /* Default umask for new directories */
59
  init_glob_errs();
28.1.35 by Monty Taylor
Removed all references to THREAD.
60
#if defined(SAFE_MUTEX)
1 by brian
clean slate
61
  safe_mutex_global_init();		/* Must be called early */
62
#endif
28.1.35 by Monty Taylor
Removed all references to THREAD.
63
#if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
1 by brian
clean slate
64
  fastmutex_global_init();              /* Must be called early */
65
#endif
66
#if defined(HAVE_PTHREAD_INIT)
51.3.17 by Jay Pipes
Phase 4 - Remove DBUG from mysys
67
  pthread_init();
1 by brian
clean slate
68
#endif
69
  if (my_thread_global_init())
70
    return 1;
71
  sigfillset(&my_signals);		/* signals blocked by mf_brkhant */
72
  {
73
    if (!home_dir)
74
    {					/* Don't initialize twice */
75
      if ((home_dir=getenv("HOME")) != 0)
76
	home_dir=intern_filename(home_dir_buff,home_dir);
77
      /* Default creation of new files */
78
      if ((str=getenv("UMASK")) != 0)
79
	my_umask=(int) (atoi_octal(str) | 0600);
80
	/* Default creation of new dir's */
81
      if ((str=getenv("UMASK_DIR")) != 0)
82
	my_umask_dir=(int) (atoi_octal(str) | 0700);
83
    }
51.3.17 by Jay Pipes
Phase 4 - Remove DBUG from mysys
84
    return(0);
1 by brian
clean slate
85
  }
86
} /* my_init */
87
88
89
	/* End my_sys */
90
91
void my_end(int infoflag)
92
{
93
  /*
94
    this code is suboptimal to workaround a bug in
95
    Sun CC: Sun C++ 5.6 2004/06/02 for x86, and should not be
96
    optimized until this compiler is not in use anymore
97
  */
51.3.22 by Jay Pipes
Final round of removal of DBUG in mysys/, including Makefile
98
  FILE *info_file= stderr;
99
  bool print_info= 0;
1 by brian
clean slate
100
101
  if ((infoflag & MY_CHECK_ERROR) || print_info)
102
103
  {					/* Test if some file is left open */
104
    if (my_file_opened | my_stream_opened)
105
    {
106
      sprintf(errbuff[0],EE(EE_OPEN_WARNING),my_file_opened,my_stream_opened);
779.1.19 by Monty Taylor
Removed stuff that gcov showed we weren't using.
107
      /* TODO: Mark... look at replacement here
108
       * (void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL);
109
       */
110
      (void) fflush(stdout);
111
      
1 by brian
clean slate
112
      my_print_open_files();
113
    }
114
  }
115
  free_charsets();
116
  my_error_unregister_all();
117
118
  if ((infoflag & MY_GIVE_INFO) || print_info)
119
  {
120
#ifdef HAVE_GETRUSAGE
121
    struct rusage rus;
122
#ifdef HAVE_purify
123
    /* Purify assumes that rus is uninitialized after getrusage call */
212.6.14 by Mats Kindahl
Removing redundant use of casts in mysys for memcmp(), memcpy(), memset(), and memmove().
124
    memset(&rus, 0, sizeof(rus));
1 by brian
clean slate
125
#endif
126
    if (!getrusage(RUSAGE_SELF, &rus))
127
      fprintf(info_file,"\n\
128
User time %.2f, System time %.2f\n\
129
Maximum resident set size %ld, Integral resident set size %ld\n\
130
Non-physical pagefaults %ld, Physical pagefaults %ld, Swaps %ld\n\
131
Blocks in %ld out %ld, Messages in %ld out %ld, Signals %ld\n\
132
Voluntary context switches %ld, Involuntary context switches %ld\n",
133
	      (rus.ru_utime.tv_sec * SCALE_SEC +
134
	       rus.ru_utime.tv_usec / SCALE_USEC) / 100.0,
135
	      (rus.ru_stime.tv_sec * SCALE_SEC +
136
	       rus.ru_stime.tv_usec / SCALE_USEC) / 100.0,
137
	      rus.ru_maxrss, rus.ru_idrss,
138
	      rus.ru_minflt, rus.ru_majflt,
139
	      rus.ru_nswap, rus.ru_inblock, rus.ru_oublock,
140
	      rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals,
141
	      rus.ru_nvcsw, rus.ru_nivcsw);
142
#endif
143
  }
144
  else if (infoflag & MY_CHECK_ERROR)
145
  {
146
    TERMINATE(stderr, 0);		/* Print memory leaks on screen */
147
  }
148
149
  my_thread_end();
150
  my_thread_global_end();
151
#if defined(SAFE_MUTEX)
152
  /*
153
    Check on destroying of mutexes. A few may be left that will get cleaned
154
    up by C++ destructors
155
  */
549 by Monty Taylor
Took gettext.h out of header files.
156
  safe_mutex_end();
157
1 by brian
clean slate
158
#endif /* defined(SAFE_MUTEX) */
159
160
  my_init_done=0;
161
} /* my_end */