~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_udf.cc

  • Committer: Brian Aker
  • Date: 2008-07-07 21:24:00 UTC
  • Revision ID: brian@tangent.org-20080707212400-l438faws7z0th2aj
Remove bootstrap error on udf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
    delete new_thd;
128
128
    DBUG_VOID_RETURN;
129
129
  }
 
130
 
130
131
  initialized = 1;
131
 
  new_thd->thread_stack= (char*) &new_thd;
132
 
  new_thd->store_globals();
133
 
  lex_start(new_thd);
134
 
  new_thd->set_db(db, sizeof(db)-1);
135
 
 
136
 
  bzero((uchar*) &tables,sizeof(tables));
137
 
  tables.alias= tables.table_name= (char*) "func";
138
 
  tables.lock_type = TL_READ;
139
 
  tables.db= db;
140
 
 
141
 
  if (simple_open_n_lock_tables(new_thd, &tables))
142
 
  {
143
 
    DBUG_PRINT("error",("Can't open udf table"));
144
 
    sql_print_error("Can't open the mysql.func table. Please "
145
 
                    "run mysql_upgrade to create it.");
146
 
    goto end;
147
 
  }
148
 
 
149
 
  table= tables.table;
150
 
  init_read_record(&read_record_info, new_thd, table, NULL,1,0);
151
 
  table->use_all_columns();
152
 
  while (!(error= read_record_info.read_record(&read_record_info)))
153
 
  {
154
 
    DBUG_PRINT("info",("init udf record"));
155
 
    LEX_STRING name;
156
 
    name.str=get_field(&mem, table->field[0]);
157
 
    name.length = strlen(name.str);
158
 
    char *dl_name= get_field(&mem, table->field[2]);
159
 
    bool new_dl=0;
160
 
    Item_udftype udftype=UDFTYPE_FUNCTION;
161
 
    if (table->s->fields >= 4)                  // New func table
162
 
      udftype=(Item_udftype) table->field[3]->val_int();
163
 
 
164
 
    /*
165
 
      Ensure that the .dll doesn't have a path
166
 
      This is done to ensure that only approved dll from the system
167
 
      directories are used (to make this even remotely secure).
168
 
 
169
 
      On windows we must check both FN_LIBCHAR and '/'.
170
 
    */
171
 
    if (my_strchr(files_charset_info, dl_name,
172
 
                  dl_name + strlen(dl_name), FN_LIBCHAR) ||
173
 
        IF_WIN(my_strchr(files_charset_info, dl_name,
174
 
                         dl_name + strlen(dl_name), '/'), 0) ||
175
 
        check_identifier_name(&name))
176
 
    {
177
 
      sql_print_error("Invalid row in mysql.func table for function '%.64s'",
178
 
                      name.str);
179
 
      continue;
180
 
    }
181
 
 
182
 
    if (!(tmp= add_udf(&name,(Item_result) table->field[1]->val_int(),
183
 
                       dl_name, udftype)))
184
 
    {
185
 
      sql_print_error("Can't alloc memory for udf function: '%.64s'", name.str);
186
 
      continue;
187
 
    }
188
 
 
189
 
    void *dl = find_udf_dl(tmp->dl);
190
 
    if (dl == NULL)
191
 
    {
192
 
      char dlpath[FN_REFLEN];
193
 
      strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", tmp->dl,
194
 
               NullS);
195
 
      if (!(dl= dlopen(dlpath, RTLD_NOW)))
196
 
      {
197
 
        /* Print warning to log */
198
 
        sql_print_error(ER(ER_CANT_OPEN_LIBRARY), tmp->dl, errno, dlerror());
199
 
        /* Keep the udf in the hash so that we can remove it later */
200
 
        continue;
201
 
      }
202
 
      new_dl=1;
203
 
    }
204
 
    tmp->dlhandle = dl;
205
 
    {
206
 
      char buf[NAME_LEN+16], *missing;
207
 
      if ((missing= init_syms(tmp, buf)))
208
 
      {
209
 
        sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), missing);
210
 
        del_udf(tmp);
211
 
        if (new_dl)
212
 
          dlclose(dl);
213
 
      }
214
 
    }
215
 
  }
216
 
  if (error > 0)
217
 
    sql_print_error("Got unknown error: %d", my_errno);
218
 
  end_read_record(&read_record_info);
219
 
  new_thd->version--;                           // Force close to free memory
220
 
 
221
 
end:
 
132
 
222
133
  close_thread_tables(new_thd);
223
134
  delete new_thd;
224
135
  /* Remember that we don't have a THD */