Commit 08b94f41 authored by unknown's avatar unknown

added mysqlmanager-pwgen

added set_exec_stdout and set_exec_stderr to mysqlmanager to be able 
to redirect stdout and stderr
added support for MY_FULL_IO to my_read, so we can tell it to read
a number of bytes in as many chunks as it takes instead of one try


BitKeeper/etc/ignore:
  Added client/mysqlmanager-pwgen to the ignore list
client/Makefile.am:
  mysqlmanager-pwgen
client/mysqlmanagerc.c:
  clean-up
include/my_sys.h:
  added MY_FULL_IO
mysql-test/mysql-test-run.sh:
  started on changes to use mysqlmanager
mysys/my_read.c:
  added support for MY_FULL_IO
tools/managertest1.nc:
  updated test case
tools/mysqlmanager.c:
  added set_exec_stdout and set_exec_stderr
parent 8057a797
...@@ -413,3 +413,4 @@ vio/test-ssl ...@@ -413,3 +413,4 @@ vio/test-ssl
vio/test-sslclient vio/test-sslclient
vio/test-sslserver vio/test-sslserver
vio/viotest-ssl vio/viotest-ssl
client/mysqlmanager-pwgen
...@@ -23,7 +23,7 @@ noinst_HEADERS = client_priv.h ...@@ -23,7 +23,7 @@ noinst_HEADERS = client_priv.h
LIBS = @CLIENT_LIBS@ LIBS = @CLIENT_LIBS@
LDADD = @CLIENT_EXTRA_LDFLAGS@ ../libmysql/libmysqlclient.la LDADD = @CLIENT_EXTRA_LDFLAGS@ ../libmysql/libmysqlclient.la
bin_PROGRAMS = mysql mysqladmin mysqlcheck mysqlshow \ bin_PROGRAMS = mysql mysqladmin mysqlcheck mysqlshow \
mysqldump mysqlimport mysqltest mysqlbinlog mysqlmanagerc mysqldump mysqlimport mysqltest mysqlbinlog mysqlmanagerc mysqlmanager-pwgen
noinst_PROGRAMS = insert_test select_test thread_test noinst_PROGRAMS = insert_test select_test thread_test
noinst_HEADERS = sql_string.h completion_hash.h my_readline.h noinst_HEADERS = sql_string.h completion_hash.h my_readline.h
mysql_SOURCES = mysql.cc readline.cc sql_string.cc completion_hash.cc mysql_SOURCES = mysql.cc readline.cc sql_string.cc completion_hash.cc
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#define MANAGER_PWGEN_VERSION "1.0"
#include <my_global.h>
#include <m_ctype.h>
#include <my_sys.h>
#include <m_string.h>
#include <mysql_version.h>
#include <errno.h>
#include <getopt.h>
#include <md5.h>
const char* outfile=0,*user="root";
struct option long_options[] =
{
{"output-file",required_argument,0,'o'},
{"user",required_argument,0,'u'},
{"help",no_argument,0,'?'},
{"version",no_argument,0,'V'},
{0,0,0,0}
};
static void die(const char* fmt, ...)
{
va_list args;
DBUG_ENTER("die");
va_start(args, fmt);
if (fmt)
{
fprintf(stderr, "%s: ", my_progname);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
fflush(stderr);
}
va_end(args);
exit(1);
}
static void print_version(void)
{
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,
MANAGER_PWGEN_VERSION,
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
}
void usage()
{
print_version();
printf("MySQL AB, by Sasha\n");
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Generates a password file to be used by mysqltest.\n\n");
printf("Usage: %s [OPTIONS]\n", my_progname);
printf("-?,--help Display this message and exit\n\
-V,--version Display version info\n\
-u,--user= Put given user in the password file\n\
-o,--output-file= Write the output to the file with the given name\n");
}
int parse_args(int argc, char** argv)
{
int c,option_index=0;
while ((c=getopt_long(argc,argv,"?Vu:o:",long_options,&option_index))
!= EOF)
{
switch (c)
{
case 'o':
outfile=optarg;
break;
case 'u':
user=optarg;
break;
case '?':
usage();
exit(0);
case 'V':
print_version();
exit(0);
default:
usage();
exit(1);
}
}
return 0;
}
void get_pass(char* pw, int len)
{
FILE* fp;
char* pw_end=pw+len;
/* /dev/random is more secure than rand() because the seed is easy to
predict, so we resort to rand() only if /dev/random is not available */
if ((fp=fopen("/dev/random","r")))
{
fread(pw,len,1,fp);
fclose(fp);
while (pw<pw_end)
{
*pw++='a'+((uint)*pw % 26);
}
}
else
{
srand(time(NULL));
while (pw<pw_end)
*pw++='a'+((uint)rand() % 26);
}
*pw_end=0;
}
int main(int argc, char** argv)
{
FILE* fp;
my_MD5_CTX context;
uchar digest[16];
char pw[17];
uint i;
MY_INIT(argv[0]);
parse_args(argc,argv);
if (!outfile)
die("Missing --output-file");
if (!(fp=fopen(outfile,"w")))
die("Could not open '%s'(errno=%d)",outfile,errno);
get_pass(pw,sizeof(pw)-1);
my_MD5Init(&context);
my_MD5Update(&context,pw,sizeof(pw)-1);
my_MD5Final(digest,&context);
fprintf(fp,"%s:",user);
for (i=0;i<sizeof(digest);i++)
fprintf(fp,"%02x",digest[i]);
fprintf(fp,"\n");
fclose(fp);
printf("%s\n",pw);
return 0;
}
...@@ -92,9 +92,9 @@ static void print_version(void) ...@@ -92,9 +92,9 @@ static void print_version(void)
void usage() void usage()
{ {
print_version(); print_version();
printf("MySQL AB, by Sasha, Matt & Monty\n"); printf("MySQL AB, by Sasha\n");
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Runs a test against the mysql server and compares output with a results file.\n\n"); printf("Command-line client for MySQL manager daemon.\n\n");
printf("Usage: %s [OPTIONS] < command_file\n", my_progname); printf("Usage: %s [OPTIONS] < command_file\n", my_progname);
printf("\n\ printf("\n\
-?, --help Display this help and exit.\n"); -?, --help Display this help and exit.\n");
...@@ -148,7 +148,7 @@ int parse_args(int argc, char **argv) ...@@ -148,7 +148,7 @@ int parse_args(int argc, char **argv)
exit(0); exit(0);
case '?': case '?':
usage(); usage();
exit(1); /* Unknown option */ exit(0);
default: default:
usage(); usage();
exit(1); exit(1);
......
...@@ -59,6 +59,9 @@ extern int NEAR my_errno; /* Last error in mysys */ ...@@ -59,6 +59,9 @@ extern int NEAR my_errno; /* Last error in mysys */
#define MY_WME 16 /* Write message on error */ #define MY_WME 16 /* Write message on error */
#define MY_WAIT_IF_FULL 32 /* Wait and try again if disk full error */ #define MY_WAIT_IF_FULL 32 /* Wait and try again if disk full error */
#define MY_RAID 64 /* Support for RAID (not the "Johnson&Johnson"-s one ;) */ #define MY_RAID 64 /* Support for RAID (not the "Johnson&Johnson"-s one ;) */
#define MY_FULL_IO 128 /* For my_read - loop intil I/O
is complete
*/
#define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */ #define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */
#define MY_LINK_WARNING 32 /* my_redel() gives warning if links */ #define MY_LINK_WARNING 32 /* my_redel() gives warning if links */
#define MY_COPYTIME 64 /* my_redel() copys time */ #define MY_COPYTIME 64 /* my_redel() copys time */
......
...@@ -118,6 +118,7 @@ MASTER_RUNNING=0 ...@@ -118,6 +118,7 @@ MASTER_RUNNING=0
MASTER_MYPORT=9306 MASTER_MYPORT=9306
SLAVE_RUNNING=0 SLAVE_RUNNING=0
SLAVE_MYPORT=9307 SLAVE_MYPORT=9307
MYSQL_MANAGER_PORT=23546
NO_SLAVE=0 NO_SLAVE=0
EXTRA_MASTER_OPT="" EXTRA_MASTER_OPT=""
...@@ -276,6 +277,9 @@ if [ x$SOURCE_DIST = x1 ] ; then ...@@ -276,6 +277,9 @@ if [ x$SOURCE_DIST = x1 ] ; then
MYSQL_TEST="$BASEDIR/client/mysqltest" MYSQL_TEST="$BASEDIR/client/mysqltest"
fi fi
MYSQLADMIN="$BASEDIR/client/mysqladmin" MYSQLADMIN="$BASEDIR/client/mysqladmin"
MYSQL_MANAGER_CLIENT="$BASEDIR/client/mysqlmanagerc"
MYSQL_MANAGER="$BASEDIR/tools/mysqlmanager"
MYSQL_MANAGER_PWGEN="$BASEDIR/client/mysqlmanager-pwgen"
MYSQL="$BASEDIR/client/mysql" MYSQL="$BASEDIR/client/mysql"
LANGUAGE="$BASEDIR/sql/share/english/" LANGUAGE="$BASEDIR/sql/share/english/"
CHARSETSDIR="$BASEDIR/sql/share/charsets" CHARSETSDIR="$BASEDIR/sql/share/charsets"
...@@ -284,6 +288,9 @@ else ...@@ -284,6 +288,9 @@ else
MYSQLD="$BASEDIR/bin/mysqld" MYSQLD="$BASEDIR/bin/mysqld"
MYSQL_TEST="$BASEDIR/bin/mysqltest" MYSQL_TEST="$BASEDIR/bin/mysqltest"
MYSQLADMIN="$BASEDIR/bin/mysqladmin" MYSQLADMIN="$BASEDIR/bin/mysqladmin"
MYSQL_MANAGER="$BASEDIR/bin/mysqlmanager"
MYSQL_MANAGER_CLIENT="$BASEDIR/bin/mysqlmanagerc"
MYSQL_MANAGER_PWGEN="$BASEDIR/bin/mysqlmanager-pwgen"
MYSQL="$BASEDIR/bin/mysql" MYSQL="$BASEDIR/bin/mysql"
INSTALL_DB="./install_test_db -bin" INSTALL_DB="./install_test_db -bin"
if test -d "$BASEDIR/share/mysql/english" if test -d "$BASEDIR/share/mysql/english"
...@@ -487,6 +494,30 @@ gcov_collect () { ...@@ -487,6 +494,30 @@ gcov_collect () {
$ECHO "gcov info in $GCOV_MSG, errors in $GCOV_ERR" $ECHO "gcov info in $GCOV_MSG, errors in $GCOV_ERR"
} }
abort_if_failed()
{
if [ ! $? = 0 ] ; then
echo $1
exit 1
fi
}
start_manager()
{
MYSQL_MANAGER_PW=`$MYSQL_MANAGER_PWGEN -o $MYSQL_MANAGER_PW_FILE`
$MYSQL_MANAGER --log=$MYSQL_MANAGER_LOG --port=$MYSQL_MANAGER_PORT \
--password-file=$MYSQL_MANAGER_PW_FILE
abort_if_failed "Could not start MySQL manager"
}
manager_cmd()
{
$MYSQL_MANAGER_CLIENT --user=$MYSQL_MANAGER_USER \
--password=$MYSQL_MANAGER_PW --port=$MYSQL_MANAGER_PORT <<EOF
$@
EOF
abort_if_failed "Could not execute manager command"
}
start_master() start_master()
{ {
......
...@@ -28,10 +28,11 @@ uint my_read(File Filedes, byte *Buffer, uint Count, myf MyFlags) ...@@ -28,10 +28,11 @@ uint my_read(File Filedes, byte *Buffer, uint Count, myf MyFlags)
/* Max number of bytes returnd */ /* Max number of bytes returnd */
/* Flags on what to do on error */ /* Flags on what to do on error */
{ {
uint readbytes; uint readbytes,save_count;
DBUG_ENTER("my_read"); DBUG_ENTER("my_read");
DBUG_PRINT("my",("Fd: %d Buffer: %lx Count: %u MyFlags: %d", DBUG_PRINT("my",("Fd: %d Buffer: %lx Count: %u MyFlags: %d",
Filedes, Buffer, Count, MyFlags)); Filedes, Buffer, Count, MyFlags));
save_count=Count;
for (;;) for (;;)
{ {
...@@ -54,12 +55,21 @@ uint my_read(File Filedes, byte *Buffer, uint Count, myf MyFlags) ...@@ -54,12 +55,21 @@ uint my_read(File Filedes, byte *Buffer, uint Count, myf MyFlags)
my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG),
my_filename(Filedes),my_errno); my_filename(Filedes),my_errno);
} }
if ((int) readbytes == -1 || (MyFlags & (MY_FNABP | MY_NABP))) if ((int) readbytes == -1 ||
((MyFlags & (MY_FNABP | MY_NABP)) && !(MyFlags & MY_FULL_IO)))
DBUG_RETURN(MY_FILE_ERROR); /* Return with error */ DBUG_RETURN(MY_FILE_ERROR); /* Return with error */
if (readbytes > 0 && (MyFlags & MY_FULL_IO))
{
Buffer+=readbytes;
Count-=readbytes;
continue;
}
} }
if (MyFlags & (MY_NABP | MY_FNABP)) if (MyFlags & (MY_NABP | MY_FNABP))
readbytes=0; /* Ok on read */ readbytes=0; /* Ok on read */
else if (MyFlags & MY_FULL_IO)
readbytes=save_count;
break; break;
} }
DBUG_RETURN(readbytes); DBUG_RETURN(readbytes);
......
def_exec server /usr/sbin/mysqld --socket=/tmp/temp.sock --skip-grant --skip-net --datadir=/tmp def_exec server /usr/sbin/mysqld --socket=/tmp/temp.sock --skip-grant --skip-net --datadir=/tmp
set_exec_con server root localhost /tmp/temp.sock set_exec_con server root localhost /tmp/temp.sock
set_exec_stdout server /tmp/mysqld.err
set_exec_stderr server /tmp/mysqld.err
start_exec server 3 start_exec server 3
show_exec show_exec
stop_exec server 3 stop_exec server 3
......
...@@ -117,6 +117,8 @@ uint manager_max_cmd_len = MANAGER_MAX_CMD_LEN; ...@@ -117,6 +117,8 @@ uint manager_max_cmd_len = MANAGER_MAX_CMD_LEN;
const char* manager_pw_file=MANAGER_PW_FILE; const char* manager_pw_file=MANAGER_PW_FILE;
int one_thread = 0; /* for debugging */ int one_thread = 0; /* for debugging */
typedef enum {PARAM_STDOUT,PARAM_STDERR} PARAM_TYPE;
/* messages */ /* messages */
#define MAX_CLIENT_MSG_LEN 256 #define MAX_CLIENT_MSG_LEN 256
...@@ -170,6 +172,7 @@ static byte* get_user_key(const byte* u, uint* len, ...@@ -170,6 +172,7 @@ static byte* get_user_key(const byte* u, uint* len,
static uint tokenize_args(char* arg_start,char** arg_end); static uint tokenize_args(char* arg_start,char** arg_end);
static void init_arg_array(char* arg_str,char** args,uint arg_count); static void init_arg_array(char* arg_str,char** args,uint arg_count);
static int hex_val(char c); static int hex_val(char c);
static int open_and_dup(int fd,char* path);
typedef int (*manager_cmd_handler)(struct manager_thd*,char*,char*); typedef int (*manager_cmd_handler)(struct manager_thd*,char*,char*);
...@@ -211,12 +214,18 @@ struct manager_exec ...@@ -211,12 +214,18 @@ struct manager_exec
pthread_t th; pthread_t th;
char con_sock[FN_REFLEN]; char con_sock[FN_REFLEN];
char con_host[MAX_HOST]; char con_host[MAX_HOST];
char stderr_path[FN_REFLEN];
char stdout_path[FN_REFLEN];
MYSQL mysql; MYSQL mysql;
char* data_buf; char* data_buf;
int req_len; int req_len;
int stderr_path_size,stdout_path_size,data_buf_size;
int num_args; int num_args;
}; };
static int set_exec_param(struct manager_thd* thd, char* args_start,
char* args_end, PARAM_TYPE param_type);
#define HANDLE_DECL(com) static int handle_ ## com (struct manager_thd* thd,\ #define HANDLE_DECL(com) static int handle_ ## com (struct manager_thd* thd,\
char* args_start,char* args_end) char* args_start,char* args_end)
...@@ -233,6 +242,8 @@ HANDLE_DECL(def_exec); ...@@ -233,6 +242,8 @@ HANDLE_DECL(def_exec);
HANDLE_DECL(start_exec); HANDLE_DECL(start_exec);
HANDLE_DECL(stop_exec); HANDLE_DECL(stop_exec);
HANDLE_DECL(set_exec_con); HANDLE_DECL(set_exec_con);
HANDLE_DECL(set_exec_stdout);
HANDLE_DECL(set_exec_stderr);
HANDLE_NOARG_DECL(show_exec); HANDLE_NOARG_DECL(show_exec);
struct manager_cmd commands[] = struct manager_cmd commands[] =
...@@ -247,6 +258,10 @@ struct manager_cmd commands[] = ...@@ -247,6 +258,10 @@ struct manager_cmd commands[] =
handle_stop_exec,9}, handle_stop_exec,9},
{"set_exec_con", "Set connection parameters for executable entry", {"set_exec_con", "Set connection parameters for executable entry",
handle_set_exec_con,12}, handle_set_exec_con,12},
{"set_exec_stdout", "Set stdout path for executable entry",
handle_set_exec_stdout,15},
{"set_exec_stderr", "Set stderr path for executable entry",
handle_set_exec_stderr,15},
{"show_exec","Show defined executable entries",handle_show_exec,9}, {"show_exec","Show defined executable entries",handle_show_exec,9},
{"help", "Print this message", handle_help,4}, {"help", "Print this message", handle_help,4},
{0,0,0,0} {0,0,0,0}
...@@ -460,6 +475,68 @@ err: ...@@ -460,6 +475,68 @@ err:
return 1; return 1;
} }
HANDLE_DECL(set_exec_stdout)
{
return set_exec_param(thd,args_start,args_end,PARAM_STDOUT);
}
HANDLE_DECL(set_exec_stderr)
{
return set_exec_param(thd,args_start,args_end,PARAM_STDERR);
}
static int set_exec_param(struct manager_thd* thd, char* args_start,
char* args_end, PARAM_TYPE param_type)
{
int num_args;
const char* error=0;
struct manager_exec* e;
char* arg_p;
char* param;
int param_size;
if ((num_args=tokenize_args(args_start,&args_end))<2)
{
error="Too few arguments";
goto err;
}
arg_p=args_start;
pthread_mutex_lock(&lock_exec_hash);
if (!(e=(struct manager_exec*)hash_search(&exec_hash,arg_p,
strlen(arg_p))))
{
pthread_mutex_unlock(&lock_exec_hash);
error="Exec definition entry does not exist";
goto err;
}
arg_p+=strlen(arg_p)+1;
param_size=strlen(arg_p)+1;
switch (param_type)
{
case PARAM_STDOUT:
param=e->stdout_path;
e->req_len+=(param_size-e->stdout_path_size);
e->stdout_path_size=param_size;
break;
case PARAM_STDERR:
param=e->stderr_path;
e->req_len+=(param_size-e->stderr_path_size);
e->stderr_path_size=param_size;
break;
default:
error="Internal error";
goto err;
}
strnmov(param,arg_p,FN_REFLEN);
pthread_mutex_unlock(&lock_exec_hash);
client_msg(thd->vio,MANAGER_OK,"Entry updated");
return 0;
err:
client_msg(thd->vio,MANAGER_CLIENT_ERR,error);
return 1;
}
HANDLE_DECL(start_exec) HANDLE_DECL(start_exec)
{ {
int num_args; int num_args;
...@@ -488,6 +565,7 @@ HANDLE_DECL(start_exec) ...@@ -488,6 +565,7 @@ HANDLE_DECL(start_exec)
pthread_mutex_lock(&e->lock); pthread_mutex_lock(&e->lock);
t.tv_sec=time(0)+atoi(args_start+ident_len+1); t.tv_sec=time(0)+atoi(args_start+ident_len+1);
t.tv_nsec=0; t.tv_nsec=0;
if (!e->pid)
pthread_cond_timedwait(&e->cond,&e->lock,&t); pthread_cond_timedwait(&e->cond,&e->lock,&t);
if (!e->pid) if (!e->pid)
{ {
...@@ -548,6 +626,7 @@ HANDLE_DECL(stop_exec) ...@@ -548,6 +626,7 @@ HANDLE_DECL(stop_exec)
error="Could not send shutdown command"; error="Could not send shutdown command";
goto err; goto err;
} }
if (e->pid)
pthread_cond_timedwait(&e->cond,&e->lock,&abstime); pthread_cond_timedwait(&e->cond,&e->lock,&abstime);
if (e->pid) if (e->pid)
error="Process failed to terminate within alotted time"; error="Process failed to terminate within alotted time";
...@@ -600,7 +679,7 @@ HANDLE_NOARG_DECL(show_exec) ...@@ -600,7 +679,7 @@ HANDLE_NOARG_DECL(show_exec)
{ {
uint i; uint i;
client_msg_pre(thd->vio,MANAGER_INFO,"Exec_def\tPid\tExit_status\tCon_info\ client_msg_pre(thd->vio,MANAGER_INFO,"Exec_def\tPid\tExit_status\tCon_info\
\tArguments"); \tStdout\tStderr\tArguments");
pthread_mutex_lock(&lock_exec_hash); pthread_mutex_lock(&lock_exec_hash);
for (i=0;i<exec_hash.records;i++) for (i=0;i<exec_hash.records;i++)
{ {
...@@ -668,9 +747,16 @@ static int manager_exec_launch(struct manager_exec* e) ...@@ -668,9 +747,16 @@ static int manager_exec_launch(struct manager_exec* e)
} }
else else
{ {
if (write(to_launcher_pipe[1],&e->req_len,sizeof(int))!=sizeof(int) || if (my_write(to_launcher_pipe[1],(byte*)&e->req_len,
write(to_launcher_pipe[1],&e->num_args,sizeof(int))!=sizeof(int) || sizeof(int),MYF(MY_NABP))||
write(to_launcher_pipe[1],e->data_buf,e->req_len)!=e->req_len) my_write(to_launcher_pipe[1],(byte*)&e->num_args,
sizeof(int),MYF(MY_NABP)) ||
my_write(to_launcher_pipe[1],e->stdout_path,e->stdout_path_size,
MYF(MY_NABP)) ||
my_write(to_launcher_pipe[1],e->stderr_path,e->stderr_path_size,
MYF(MY_NABP)) ||
my_write(to_launcher_pipe[1],e->data_buf,e->data_buf_size,
MYF(MY_NABP)))
{ {
e->error="Failed write request to launcher"; e->error="Failed write request to launcher";
return 1; return 1;
...@@ -724,6 +810,14 @@ static void manager_exec_print(Vio* vio,struct manager_exec* e) ...@@ -724,6 +810,14 @@ static void manager_exec_print(Vio* vio,struct manager_exec* e)
p=int10_to_str(e->con_port,p,10); p=int10_to_str(e->con_port,p,10);
} }
*p++='\t'; *p++='\t';
p=arg_strmov(p,e->stdout_path,(int)(buf_end-p)-1);
if (p==buf_end-1)
goto end;
*p++='\t';
p=arg_strmov(p,e->stderr_path,(int)(buf_end-p)-1);
if (p==buf_end-1)
goto end;
*p++='\t';
for(;p<buf_end && *args;args++) for(;p<buf_end && *args;args++)
{ {
...@@ -1341,7 +1435,8 @@ static struct manager_exec* manager_exec_new(char* arg_start,char* arg_end) ...@@ -1341,7 +1435,8 @@ static struct manager_exec* manager_exec_new(char* arg_start,char* arg_end)
num_args=tokenize_args(arg_start,&arg_end); num_args=tokenize_args(arg_start,&arg_end);
arg_len=(uint)(arg_end-arg_start)+1; /* include \0 terminator*/ arg_len=(uint)(arg_end-arg_start)+1; /* include \0 terminator*/
if (!(tmp=(struct manager_exec*)my_malloc(sizeof(*tmp)+arg_len+ if (!(tmp=(struct manager_exec*)my_malloc(sizeof(*tmp)+arg_len+
sizeof(char*)*num_args,MYF(0)))) sizeof(char*)*num_args,
MYF(MY_ZEROFILL))))
return 0; return 0;
if (num_args<2) if (num_args<2)
{ {
...@@ -1350,7 +1445,7 @@ static struct manager_exec* manager_exec_new(char* arg_start,char* arg_end) ...@@ -1350,7 +1445,7 @@ static struct manager_exec* manager_exec_new(char* arg_start,char* arg_end)
} }
tmp->data_buf=(char*)tmp+sizeof(*tmp); tmp->data_buf=(char*)tmp+sizeof(*tmp);
memcpy(tmp->data_buf,arg_start,arg_len); memcpy(tmp->data_buf,arg_start,arg_len);
tmp->req_len=arg_len; tmp->data_buf_size=arg_len;
tmp->args=(char**)(tmp->data_buf+arg_len); tmp->args=(char**)(tmp->data_buf+arg_len);
tmp->num_args=num_args; tmp->num_args=num_args;
tmp->ident=tmp->data_buf; tmp->ident=tmp->data_buf;
...@@ -1358,18 +1453,14 @@ static struct manager_exec* manager_exec_new(char* arg_start,char* arg_end) ...@@ -1358,18 +1453,14 @@ static struct manager_exec* manager_exec_new(char* arg_start,char* arg_end)
first_arg=tmp->ident+tmp->ident_len+1; first_arg=tmp->ident+tmp->ident_len+1;
init_arg_array(first_arg,tmp->args,num_args-1); init_arg_array(first_arg,tmp->args,num_args-1);
strmov(tmp->con_user,"root"); strmov(tmp->con_user,"root");
tmp->con_pass[0]=0;
tmp->con_sock[0]=0;
tmp->con_port=MYSQL_PORT; tmp->con_port=MYSQL_PORT;
memcpy(tmp->con_host,"localhost",10); memcpy(tmp->con_host,"localhost",10);
tmp->bin_path=tmp->args[0]; tmp->bin_path=tmp->args[0];
tmp->pid=0; tmp->stdout_path_size=tmp->stderr_path_size=1;
tmp->exit_code=0; tmp->req_len=tmp->data_buf_size+2;
tmp->th=0;
pthread_mutex_init(&tmp->lock,0); pthread_mutex_init(&tmp->lock,0);
pthread_cond_init(&tmp->cond,0); pthread_cond_init(&tmp->cond,0);
mysql_init(&tmp->mysql); mysql_init(&tmp->mysql);
tmp->error=0;
return tmp; return tmp;
} }
...@@ -1480,6 +1571,23 @@ static void init_globals() ...@@ -1480,6 +1571,23 @@ static void init_globals()
signal(SIGPIPE,handle_sigpipe); signal(SIGPIPE,handle_sigpipe);
} }
static int open_and_dup(int fd,char* path)
{
int old_fd;
if ((old_fd=my_open(path,O_WRONLY|O_APPEND|O_CREAT,MYF(0)))<0)
{
log_err("Could not open '%s' for append, errno=%d",path,errno);
return 1;
}
if (dup2(old_fd,fd)<0)
{
log_err("Failed in dup2(), errno=%d",errno);
return 1;
}
my_close(old_fd,MYF(0));
return 0;
}
static void run_launcher_loop() static void run_launcher_loop()
{ {
for (;;) for (;;)
...@@ -1487,14 +1595,17 @@ static void run_launcher_loop() ...@@ -1487,14 +1595,17 @@ static void run_launcher_loop()
int req_len,ident_len,num_args; int req_len,ident_len,num_args;
char* request_buf=0; char* request_buf=0;
pid_t pid; pid_t pid;
char* exec_path,*ident; char* exec_path,*ident,*stdout_path,*stderr_path;
char** args=0; char** args=0;
if (read(to_launcher_pipe[0],&req_len,sizeof(int))!=sizeof(int) || if (my_read(to_launcher_pipe[0],(byte*)&req_len,
read(to_launcher_pipe[0],&num_args,sizeof(int))!=sizeof(int) || sizeof(int),MYF(MY_NABP|MY_FULL_IO)) ||
my_read(to_launcher_pipe[0],(byte*)&num_args,
sizeof(int),MYF(MY_NABP|MY_FULL_IO)) ||
!(request_buf=(char*)my_malloc(req_len+sizeof(pid)+2,MYF(0))) || !(request_buf=(char*)my_malloc(req_len+sizeof(pid)+2,MYF(0))) ||
!(args=(char**)my_malloc(num_args*sizeof(char*),MYF(0))) || !(args=(char**)my_malloc(num_args*sizeof(char*),MYF(0))) ||
read(to_launcher_pipe[0],request_buf+1,req_len)!=req_len) my_read(to_launcher_pipe[0],request_buf,req_len,
MYF(MY_NABP|MY_FULL_IO)))
{ {
log_err("launcher: Error reading request"); log_err("launcher: Error reading request");
my_free((gptr)request_buf,MYF(MY_ALLOW_ZERO_PTR)); my_free((gptr)request_buf,MYF(MY_ALLOW_ZERO_PTR));
...@@ -1502,12 +1613,16 @@ static void run_launcher_loop() ...@@ -1502,12 +1613,16 @@ static void run_launcher_loop()
sleep(1); sleep(1);
continue; continue;
} }
stdout_path=request_buf;
stderr_path=stdout_path+strlen(stdout_path)+1;
request_buf=stderr_path+strlen(stderr_path); /* black magic */
ident=request_buf+1; ident=request_buf+1;
ident_len=strlen(ident); ident_len=strlen(ident);
exec_path=ident+ident_len+1; exec_path=ident+ident_len+1;
log_debug("num_args=%d,req_len=%d,ident=%s,ident_len=%d,exec_path=%s", log_debug("num_args=%d,req_len=%d,ident=%s,ident_len=%d,exec_path=%s,\
stdout_path=%s,stderr_path=%s",
num_args, num_args,
req_len,ident,ident_len,exec_path); req_len,ident,ident_len,exec_path,stdout_path,stderr_path);
init_arg_array(exec_path,args,num_args-1); init_arg_array(exec_path,args,num_args-1);
switch ((pid=fork())) switch ((pid=fork()))
...@@ -1517,6 +1632,8 @@ static void run_launcher_loop() ...@@ -1517,6 +1632,8 @@ static void run_launcher_loop()
sleep(1); sleep(1);
break; break;
case 0: case 0:
if (open_and_dup(1,stdout_path) || open_and_dup(2,stderr_path))
exit(1);
if (execv(exec_path,args)) if (execv(exec_path,args))
log_err("launcher: cannot exec %s",exec_path); log_err("launcher: cannot exec %s",exec_path);
exit(1); exit(1);
...@@ -1527,7 +1644,7 @@ static void run_launcher_loop() ...@@ -1527,7 +1644,7 @@ static void run_launcher_loop()
log_err("launcher: error sending launch status report"); log_err("launcher: error sending launch status report");
break; break;
} }
my_free((gptr)request_buf,MYF(0)); my_free((gptr)(stdout_path),MYF(0));
my_free((gptr)args,MYF(0)); my_free((gptr)args,MYF(0));
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment