~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_init.c

  • Committer: Stewart Smith
  • Date: 2008-07-13 06:56:15 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713065615-vzok75kgnnviokl9
Move MD5() into a UDF

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include "config.h"
17
 
 
18
 
#include "drizzled/internal/my_sys.h"
 
16
#include "mysys_priv.h"
19
17
#include "my_static.h"
20
 
#include "drizzled/error.h"
21
 
#include "drizzled/internal/m_string.h"
22
 
#include "drizzled/charset_info.h"
23
 
#include "drizzled/charset.h"
24
 
#include <cstdio>
25
 
#include <cstdlib>
26
 
 
27
 
namespace drizzled
28
 
{
29
 
namespace internal
30
 
{
31
 
 
32
 
bool my_init_done= 0;
 
18
#include "mysys_err.h"
 
19
#include <m_string.h>
 
20
#include <m_ctype.h>
 
21
#include <signal.h>
 
22
 
 
23
my_bool my_init_done= 0;
33
24
uint    mysys_usage_id= 0;              /* Incremented for each my_init() */
 
25
ulong   my_thread_stack_size= 65536;
34
26
 
35
 
static uint32_t atoi_octal(const char *str)
 
27
static ulong atoi_octal(const char *str)
36
28
{
37
29
  long int tmp;
38
 
  while (*str && my_isspace(&my_charset_utf8_general_ci, *str))
 
30
  while (*str && my_isspace(&my_charset_latin1, *str))
39
31
    str++;
40
 
  tmp= strtol(str, NULL, (*str == '0' ? 8 : 10));
41
 
  return (uint32_t) tmp;
 
32
  str2int(str,
 
33
          (*str == '0' ? 8 : 10),       /* Octalt or decimalt */
 
34
          0, INT_MAX, &tmp);
 
35
  return (ulong) tmp;
42
36
}
43
37
 
44
38
 
53
47
    1  Couldn't initialize environment
54
48
*/
55
49
 
56
 
bool my_init(void)
 
50
my_bool my_init(void)
57
51
{
58
52
  char * str;
59
53
  if (my_init_done)
62
56
  mysys_usage_id++;
63
57
  my_umask= 0660;                       /* Default umask for new files */
64
58
  my_umask_dir= 0700;                   /* Default umask for new directories */
 
59
  init_glob_errs();
 
60
#if defined(SAFE_MUTEX)
 
61
  safe_mutex_global_init();             /* Must be called early */
 
62
#endif
 
63
#if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
 
64
  fastmutex_global_init();              /* Must be called early */
 
65
#endif
65
66
#if defined(HAVE_PTHREAD_INIT)
66
 
  pthread_init();
 
67
  pthread_init();                       /* Must be called before DBUG_ENTER */
67
68
#endif
68
69
  if (my_thread_global_init())
69
70
    return 1;
70
71
  sigfillset(&my_signals);              /* signals blocked by mf_brkhant */
71
72
  {
 
73
    DBUG_ENTER("my_init");
 
74
    DBUG_PROCESS((char*) (my_progname ? my_progname : "unknown"));
72
75
    if (!home_dir)
73
76
    {                                   /* Don't initialize twice */
74
77
      if ((home_dir=getenv("HOME")) != 0)
79
82
        /* Default creation of new dir's */
80
83
      if ((str=getenv("UMASK_DIR")) != 0)
81
84
        my_umask_dir=(int) (atoi_octal(str) | 0700);
 
85
      DBUG_PRINT("exit",("home: '%s'",home_dir));
82
86
    }
83
 
    return(0);
 
87
    DBUG_RETURN(0);
84
88
  }
85
89
} /* my_init */
86
90
 
87
91
 
88
92
        /* End my_sys */
89
93
 
90
 
void my_end()
 
94
void my_end(int infoflag)
91
95
{
 
96
  /*
 
97
    this code is suboptimal to workaround a bug in
 
98
    Sun CC: Sun C++ 5.6 2004/06/02 for x86, and should not be
 
99
    optimized until this compiler is not in use anymore
 
100
  */
 
101
  FILE *info_file= DBUG_FILE;
 
102
  my_bool print_info= (info_file != stderr);
 
103
  /*
 
104
    We do not use DBUG_ENTER here, as after cleanup DBUG is no longer
 
105
    operational, so we cannot use DBUG_RETURN.
 
106
  */
 
107
  DBUG_PRINT("info",("Shutting down: infoflag: %d  print_info: %d",
 
108
                     infoflag, print_info));
 
109
  if (!info_file)
 
110
  {
 
111
    info_file= stderr;
 
112
    print_info= 0;
 
113
  }
 
114
 
 
115
  if ((infoflag & MY_CHECK_ERROR) || print_info)
 
116
 
 
117
  {                                     /* Test if some file is left open */
 
118
    if (my_file_opened | my_stream_opened)
 
119
    {
 
120
      sprintf(errbuff[0],EE(EE_OPEN_WARNING),my_file_opened,my_stream_opened);
 
121
      (void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL);
 
122
      DBUG_PRINT("error",("%s",errbuff[0]));
 
123
      my_print_open_files();
 
124
    }
 
125
  }
92
126
  free_charsets();
93
 
 
 
127
  my_error_unregister_all();
 
128
  my_once_free();
 
129
 
 
130
  if ((infoflag & MY_GIVE_INFO) || print_info)
 
131
  {
 
132
#ifdef HAVE_GETRUSAGE
 
133
    struct rusage rus;
 
134
#ifdef HAVE_purify
 
135
    /* Purify assumes that rus is uninitialized after getrusage call */
 
136
    bzero((char*) &rus, sizeof(rus));
 
137
#endif
 
138
    if (!getrusage(RUSAGE_SELF, &rus))
 
139
      fprintf(info_file,"\n\
 
140
User time %.2f, System time %.2f\n\
 
141
Maximum resident set size %ld, Integral resident set size %ld\n\
 
142
Non-physical pagefaults %ld, Physical pagefaults %ld, Swaps %ld\n\
 
143
Blocks in %ld out %ld, Messages in %ld out %ld, Signals %ld\n\
 
144
Voluntary context switches %ld, Involuntary context switches %ld\n",
 
145
              (rus.ru_utime.tv_sec * SCALE_SEC +
 
146
               rus.ru_utime.tv_usec / SCALE_USEC) / 100.0,
 
147
              (rus.ru_stime.tv_sec * SCALE_SEC +
 
148
               rus.ru_stime.tv_usec / SCALE_USEC) / 100.0,
 
149
              rus.ru_maxrss, rus.ru_idrss,
 
150
              rus.ru_minflt, rus.ru_majflt,
 
151
              rus.ru_nswap, rus.ru_inblock, rus.ru_oublock,
 
152
              rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals,
 
153
              rus.ru_nvcsw, rus.ru_nivcsw);
 
154
#endif
 
155
  }
 
156
  else if (infoflag & MY_CHECK_ERROR)
 
157
  {
 
158
    TERMINATE(stderr, 0);               /* Print memory leaks on screen */
 
159
  }
 
160
 
 
161
  if (!(infoflag & MY_DONT_FREE_DBUG))
 
162
  {
 
163
    DBUG_END();                /* Must be done before my_thread_end */
 
164
  }
94
165
  my_thread_end();
95
166
  my_thread_global_end();
 
167
#if defined(SAFE_MUTEX)
 
168
  /*
 
169
    Check on destroying of mutexes. A few may be left that will get cleaned
 
170
    up by C++ destructors
 
171
  */
 
172
  safe_mutex_end((infoflag & (MY_GIVE_INFO | MY_CHECK_ERROR)) ? stderr :
 
173
                 (FILE *) 0);
 
174
#endif /* defined(SAFE_MUTEX) */
96
175
 
97
176
  my_init_done=0;
98
177
} /* my_end */
99
 
 
100
 
} /* namespace internal */
101
 
} /* namespace drizzled */