Merge lp:~sergei.glushchenko/percona-server/5.5-BT34246-ps-blueprint-into-outfile-pipe-and-socket into lp:percona-server/5.5
- 5.5-BT34246-ps-blueprint-into-outfile-pipe-and-socket
- Merge into 5.5
Status: | Merged |
---|---|
Approved by: | Alexey Kopytov |
Approved revision: | no longer in the source branch. |
Merged at revision: | 572 |
Proposed branch: | lp:~sergei.glushchenko/percona-server/5.5-BT34246-ps-blueprint-into-outfile-pipe-and-socket |
Merge into: | lp:percona-server/5.5 |
Diff against target: |
392 lines (+239/-14) 11 files modified
Percona-Server/include/my_dir.h (+2/-0) Percona-Server/include/my_sys.h (+3/-0) Percona-Server/include/mysql/psi/mysql_file.h (+44/-0) Percona-Server/include/mysys_err.h (+4/-1) Percona-Server/mysql-test/include/outfile_fifosocket.inc (+68/-0) Percona-Server/mysql-test/r/percona_outfile_fifosocket.result (+12/-0) Percona-Server/mysql-test/t/percona_outfile_fifosocket-master.opt (+1/-0) Percona-Server/mysql-test/t/percona_outfile_fifosocket.test (+12/-0) Percona-Server/mysys/errors.c (+7/-1) Percona-Server/mysys/my_open.c (+53/-0) Percona-Server/sql/sql_class.cc (+33/-12) |
To merge this branch: | bzr merge lp:~sergei.glushchenko/percona-server/5.5-BT34246-ps-blueprint-into-outfile-pipe-and-socket |
Related bugs: | |
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexey Kopytov (community) | Approve | ||
George Ormond Lorch III (community) | g2 | Approve | |
Review via email: mp+181115@code.launchpad.net |
Commit message
Description of the change
This patch allows OUTFILE to write to fifo and unix socket.
fifo/socket should already be created in filesystem.
If file specified as OUTFILE exists server will check it's type.
If file is fifo, my_open will be used instead of my_create.
If file is socket, socket+conect will be used to connect to socket.
Both fifo and socken then will be worked with like an regular file.
If existing file is regular file, error will be thrown as it was before.
Sergei Glushchenko (sergei.glushchenko) wrote : | # |
George Ormond Lorch III (gl-az) : | # |
Alexey Kopytov (akopytov) wrote : | # |
Sergeim
- the patch also allows using FIFOs/sockets with SELECT INTO
DUMPFILE, rather than just SELECT INTO OUTFILE, but it’s not
present anywhere in tests/MP/blueprint
- please copy the MP description into the BP
- Unix domain sockets are not supported on Windows, so all
sockets-
- the test should also include inc/not_windows.inc
- call to mysql_file_open() in create_file() does not need O_EXCL (it
only makes sense together with O_CREAT which is not being passed)
- if either mysql_file_open() or mysql_unix_
-1, create_file() assumes the file was neither a FIFO nor a socket
and raises the ER_FILE_
any errors (because it was already raised by one of those
functions) and return -1.
- if connect() fails in my_unix_
closing the socket.
- instead of doing:
—
if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
if (MyFlags & (MY_FAE | MY_WME))
my_
DBUG_
}
DBUG_
—
you could do:
—
if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
close(sd);
sd= -1;
}
DBUG_
—
- in the test case, the following Perl snippet creates a FIFO named
‘outfile’, but then the further code expects it to be named
‘fifo’:
—
perl;
use POSIX qw(mkfifo);
my $fn = "$ENV{'
unlink($fn);
mkfifo($fn, 0666) or die("mkfifo: $!");
EOF
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
--send_eval SELECT 1,2,3 INTO OUTFILE '$MYSQL_
perl;
my $fn = "$ENV{'
open(FILE, $fn);
print(<FILE>);
close(FILE);
unlink($fn);
EOF
—
The above only works because the second Perl snippet opens the file
for reading and writing (i.e. creates a regular file named ‘fifo’)
before SELECT INTO OUTFILE opens it. So we are testing SELECT INTO
OUTFILE with a regular file here. Also, the second snippet is
equivalent to:
--cat_file $MYSQL_TMP_DIR/fifo
- the Unix domain socket test uses SLEEP() for synchronization. I
understand it is tricky to avoid it in this case. But the following
should work:
1) create a procedure that would poll a certain file and execute
SELECT INTO OUTFILE only when it is created:
CREATE PROCEDURE p1() BEGIN WHILE ISNULL(
2) In Perl create that file before the listen() call:
open(FILE, '>', "$ENV{'
close(FILE);
Sergei Glushchenko (sergei.glushchenko) wrote : | # |
Hi Alexey,
> Sergeim
>
> - the patch also allows using FIFOs/sockets with SELECT INTO
> DUMPFILE, rather than just SELECT INTO OUTFILE, but it’s not
> present anywhere in tests/MP/blueprint
>
I've mentioned it in both comments/MP and modified the test case to verify this behaviour. I think it's a feature rather than bug.
> - please copy the MP description into the BP
>
done.
> - Unix domain sockets are not supported on Windows, so all
> sockets-related code should be wrapped into #ifndef __WIN__
>
done.
> - the test should also include inc/not_windows.inc
>
done.
> - call to mysql_file_open() in create_file() does not need O_EXCL (it
> only makes sense together with O_CREAT which is not being passed)
>
right, it doesn't make sense. removed.
> - if either mysql_file_open() or mysql_unix_
> -1, create_file() assumes the file was neither a FIFO nor a socket
> and raises the ER_FILE_
> any errors (because it was already raised by one of those
> functions) and return -1.
>
We need to raise ER_FILE_
> - if connect() fails in my_unix_
> closing the socket.
>
> - instead of doing:
>
> —
> if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
> if (MyFlags & (MY_FAE | MY_WME))
> my_error(
> DBUG_RETURN(-1);
> }
>
> DBUG_RETURN(
> EE_FILENOTFOUND, MyFlags));
> —
>
> you could do:
>
> —
> if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
> close(sd);
> sd= -1;
> }
>
> DBUG_RETURN(
> EE_CONNECT, MyFlags));
> —
>
Done.
> - in the test case, the following Perl snippet creates a FIFO named
> ‘outfile’, but then the further code expects it to be named
> ‘fifo’:
>
> —
> perl;
> use POSIX qw(mkfifo);
> my $fn = "$ENV{'
> unlink($fn);
> mkfifo($fn, 0666) or die("mkfifo: $!");
> EOF
>
> --replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
> --send_eval SELECT 1,2,3 INTO OUTFILE '$MYSQL_
>
> perl;
> my $fn = "$ENV{'
> open(FILE, $fn);
> print(<FILE>);
> close(FILE);
> unlink($fn);
> EOF
> —
>
> The above only works because the second Perl snippet opens the file
> for reading and writing (i.e. creates a regular file named ‘fifo’)
> before SELECT INTO OUTFILE opens it. So we are testing SELECT INTO
> OUTFILE with a regular file here.
Fixed.
> Also, the second snippet is
> equivalent to:
>
> --cat_file $MYSQL_TMP_DIR/fifo
>
Replaced perl with cat_file.
> - the Unix domain socket test uses SLEEP() for synchronization. I
> understand it is tricky to avoid it in this case. But the following
> should work:
>
> 1) create a procedure that would poll a certain file and execute
> SELECT INTO OUTFILE only when i...
Sergei Glushchenko (sergei.glushchenko) wrote : | # |
Alexey Kopytov (akopytov) wrote : | # |
MY_S_IFSOCK and MY_S_ISSOCK should also be inside #ifndef __WIN__ (Windows simply doesn't define S_IFSOCK). No need for another jenkins build.
Alexey Kopytov (akopytov) wrote : | # |
It somehow didn't occur to me late in the evening that the constant will not be used anywhere. So please ignore the last comment.
Preview Diff
1 | === modified file 'Percona-Server/include/my_dir.h' | |||
2 | --- Percona-Server/include/my_dir.h 2013-03-19 12:36:34 +0000 | |||
3 | +++ Percona-Server/include/my_dir.h 2013-09-19 16:14:11 +0000 | |||
4 | @@ -32,6 +32,7 @@ | |||
5 | 32 | #define MY_S_IFBLK S_IFBLK /* block special */ | 32 | #define MY_S_IFBLK S_IFBLK /* block special */ |
6 | 33 | #define MY_S_IFREG S_IFREG /* regular */ | 33 | #define MY_S_IFREG S_IFREG /* regular */ |
7 | 34 | #define MY_S_IFIFO S_IFIFO /* fifo */ | 34 | #define MY_S_IFIFO S_IFIFO /* fifo */ |
8 | 35 | #define MY_S_IFSOCK S_IFSOCK /* socket */ | ||
9 | 35 | #define MY_S_ISUID S_ISUID /* set user id on execution */ | 36 | #define MY_S_ISUID S_ISUID /* set user id on execution */ |
10 | 36 | #define MY_S_ISGID S_ISGID /* set group id on execution */ | 37 | #define MY_S_ISGID S_ISGID /* set group id on execution */ |
11 | 37 | #define MY_S_ISVTX S_ISVTX /* save swapped text even after use */ | 38 | #define MY_S_ISVTX S_ISVTX /* save swapped text even after use */ |
12 | @@ -44,6 +45,7 @@ | |||
13 | 44 | #define MY_S_ISBLK(m) (((m) & MY_S_IFMT) == MY_S_IFBLK) | 45 | #define MY_S_ISBLK(m) (((m) & MY_S_IFMT) == MY_S_IFBLK) |
14 | 45 | #define MY_S_ISREG(m) (((m) & MY_S_IFMT) == MY_S_IFREG) | 46 | #define MY_S_ISREG(m) (((m) & MY_S_IFMT) == MY_S_IFREG) |
15 | 46 | #define MY_S_ISFIFO(m) (((m) & MY_S_IFMT) == MY_S_IFIFO) | 47 | #define MY_S_ISFIFO(m) (((m) & MY_S_IFMT) == MY_S_IFIFO) |
16 | 48 | #define MY_S_ISSOCK(m) (((m) & MY_S_IFMT) == MY_S_IFSOCK) | ||
17 | 47 | 49 | ||
18 | 48 | #define MY_DONT_SORT 512 /* my_lib; Don't sort files */ | 50 | #define MY_DONT_SORT 512 /* my_lib; Don't sort files */ |
19 | 49 | #define MY_WANT_STAT 1024 /* my_lib; stat files */ | 51 | #define MY_WANT_STAT 1024 /* my_lib; stat files */ |
20 | 50 | 52 | ||
21 | === modified file 'Percona-Server/include/my_sys.h' | |||
22 | --- Percona-Server/include/my_sys.h 2013-06-27 15:35:20 +0000 | |||
23 | +++ Percona-Server/include/my_sys.h 2013-09-19 16:14:11 +0000 | |||
24 | @@ -562,6 +562,9 @@ | |||
25 | 562 | extern char *my_once_strdup(const char *src,myf myflags); | 562 | extern char *my_once_strdup(const char *src,myf myflags); |
26 | 563 | extern void *my_once_memdup(const void *src, size_t len, myf myflags); | 563 | extern void *my_once_memdup(const void *src, size_t len, myf myflags); |
27 | 564 | extern File my_open(const char *FileName,int Flags,myf MyFlags); | 564 | extern File my_open(const char *FileName,int Flags,myf MyFlags); |
28 | 565 | #ifndef __WIN__ | ||
29 | 566 | extern File my_unix_socket_connect(const char *FileName,myf MyFlags); | ||
30 | 567 | #endif | ||
31 | 565 | extern File my_register_filename(File fd, const char *FileName, | 568 | extern File my_register_filename(File fd, const char *FileName, |
32 | 566 | enum file_type type_of_file, | 569 | enum file_type type_of_file, |
33 | 567 | uint error_message_number, myf MyFlags); | 570 | uint error_message_number, myf MyFlags); |
34 | 568 | 571 | ||
35 | === modified file 'Percona-Server/include/mysql/psi/mysql_file.h' | |||
36 | --- Percona-Server/include/mysql/psi/mysql_file.h 2010-12-21 12:00:26 +0000 | |||
37 | +++ Percona-Server/include/mysql/psi/mysql_file.h 2013-09-19 16:14:11 +0000 | |||
38 | @@ -303,6 +303,21 @@ | |||
39 | 303 | #endif | 303 | #endif |
40 | 304 | 304 | ||
41 | 305 | /** | 305 | /** |
42 | 306 | @def mysql_unix_socket_connect(K, N, F) | ||
43 | 307 | Instrumented open. | ||
44 | 308 | @c mysql_unix_socket_connect connects to the unix domain socket. | ||
45 | 309 | */ | ||
46 | 310 | #ifndef __WIN__ | ||
47 | 311 | #ifdef HAVE_PSI_INTERFACE | ||
48 | 312 | #define mysql_unix_socket_connect(K, N, F) \ | ||
49 | 313 | inline_mysql_unix_socket_connect(K, __FILE__, __LINE__, N, F) | ||
50 | 314 | #else | ||
51 | 315 | #define mysql_unix_socket_connect(K, N, F) \ | ||
52 | 316 | inline_mysql_unix_socket_connect(N, F) | ||
53 | 317 | #endif | ||
54 | 318 | #endif | ||
55 | 319 | |||
56 | 320 | /** | ||
57 | 306 | @def mysql_file_close(FD, F) | 321 | @def mysql_file_close(FD, F) |
58 | 307 | Instrumented close. | 322 | Instrumented close. |
59 | 308 | @c mysql_file_close is a replacement for @c my_close. | 323 | @c mysql_file_close is a replacement for @c my_close. |
60 | @@ -1051,6 +1066,35 @@ | |||
61 | 1051 | return file; | 1066 | return file; |
62 | 1052 | } | 1067 | } |
63 | 1053 | 1068 | ||
64 | 1069 | #ifndef __WIN__ | ||
65 | 1070 | static inline File | ||
66 | 1071 | inline_mysql_unix_socket_connect( | ||
67 | 1072 | #ifdef HAVE_PSI_INTERFACE | ||
68 | 1073 | PSI_file_key key, const char *src_file, uint src_line, | ||
69 | 1074 | #endif | ||
70 | 1075 | const char *filename, myf myFlags) | ||
71 | 1076 | { | ||
72 | 1077 | File file; | ||
73 | 1078 | #ifdef HAVE_PSI_INTERFACE | ||
74 | 1079 | struct PSI_file_locker *locker= NULL; | ||
75 | 1080 | PSI_file_locker_state state; | ||
76 | 1081 | if (likely(PSI_server != NULL)) | ||
77 | 1082 | { | ||
78 | 1083 | locker= PSI_server->get_thread_file_name_locker(&state, key, PSI_FILE_OPEN, | ||
79 | 1084 | filename, &locker); | ||
80 | 1085 | if (likely(locker != NULL)) | ||
81 | 1086 | PSI_server->start_file_open_wait(locker, src_file, src_line); | ||
82 | 1087 | } | ||
83 | 1088 | #endif | ||
84 | 1089 | file = my_unix_socket_connect(filename, myFlags); | ||
85 | 1090 | #ifdef HAVE_PSI_INTERFACE | ||
86 | 1091 | if (likely(locker != NULL)) | ||
87 | 1092 | PSI_server->end_file_open_wait_and_bind_to_descriptor(locker, file); | ||
88 | 1093 | #endif | ||
89 | 1094 | return file; | ||
90 | 1095 | } | ||
91 | 1096 | #endif | ||
92 | 1097 | |||
93 | 1054 | static inline int | 1098 | static inline int |
94 | 1055 | inline_mysql_file_close( | 1099 | inline_mysql_file_close( |
95 | 1056 | #ifdef HAVE_PSI_INTERFACE | 1100 | #ifdef HAVE_PSI_INTERFACE |
96 | 1057 | 1101 | ||
97 | === modified file 'Percona-Server/include/mysys_err.h' | |||
98 | --- Percona-Server/include/mysys_err.h 2011-06-30 15:46:53 +0000 | |||
99 | +++ Percona-Server/include/mysys_err.h 2013-09-19 16:14:11 +0000 | |||
100 | @@ -66,7 +66,10 @@ | |||
101 | 66 | #define EE_CHANGE_OWNERSHIP 31 | 66 | #define EE_CHANGE_OWNERSHIP 31 |
102 | 67 | #define EE_CHANGE_PERMISSIONS 32 | 67 | #define EE_CHANGE_PERMISSIONS 32 |
103 | 68 | #define EE_CANT_SEEK 33 | 68 | #define EE_CANT_SEEK 33 |
105 | 69 | #define EE_ERROR_LAST 33 /* Copy last error nr */ | 69 | #define EE_SOCKET 34 |
106 | 70 | #define EE_CONNECT 35 | ||
107 | 71 | #define EE_TOOLONGFILENAME 36 | ||
108 | 72 | #define EE_ERROR_LAST 36 /* Copy last error nr */ | ||
109 | 70 | /* Add error numbers before EE_ERROR_LAST and change it accordingly. */ | 73 | /* Add error numbers before EE_ERROR_LAST and change it accordingly. */ |
110 | 71 | 74 | ||
111 | 72 | /* exit codes for all MySQL programs */ | 75 | /* exit codes for all MySQL programs */ |
112 | 73 | 76 | ||
113 | === added file 'Percona-Server/mysql-test/include/outfile_fifosocket.inc' | |||
114 | --- Percona-Server/mysql-test/include/outfile_fifosocket.inc 1970-01-01 00:00:00 +0000 | |||
115 | +++ Percona-Server/mysql-test/include/outfile_fifosocket.inc 2013-09-19 16:14:11 +0000 | |||
116 | @@ -0,0 +1,68 @@ | |||
117 | 1 | # | ||
118 | 2 | # Test SELECT INTO OUTFILE/DUMPFILE with fifo and unix socket as destination | ||
119 | 3 | # | ||
120 | 4 | |||
121 | 5 | perl; | ||
122 | 6 | my $fn = "$ENV{'MYSQL_TMP_DIR'}/regular"; | ||
123 | 7 | unlink($fn); | ||
124 | 8 | open(FILE, ">$fn"); | ||
125 | 9 | print(FILE "1\n"); | ||
126 | 10 | close(FILE); | ||
127 | 11 | EOF | ||
128 | 12 | |||
129 | 13 | --replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR | ||
130 | 14 | --error 1086 | ||
131 | 15 | --eval SELECT 1,2,3 INTO $select_into '$MYSQL_TMP_DIR/regular' | ||
132 | 16 | |||
133 | 17 | perl; | ||
134 | 18 | use POSIX qw(mkfifo); | ||
135 | 19 | my $fn = "$ENV{'MYSQL_TMP_DIR'}/fifo"; | ||
136 | 20 | unlink($fn); | ||
137 | 21 | mkfifo($fn, 0666) or die("mkfifo: $!"); | ||
138 | 22 | EOF | ||
139 | 23 | |||
140 | 24 | --replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR | ||
141 | 25 | --send_eval SELECT 1,2,3 INTO $select_into '$MYSQL_TMP_DIR/fifo' | ||
142 | 26 | |||
143 | 27 | --cat_file $MYSQL_TMP_DIR/fifo | ||
144 | 28 | |||
145 | 29 | --reap | ||
146 | 30 | |||
147 | 31 | DELIMITER //; | ||
148 | 32 | # procedure spin waiting when file 'trigger' appears | ||
149 | 33 | --replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR | ||
150 | 34 | --eval CREATE PROCEDURE p1() BEGIN WHILE ISNULL(LOAD_FILE('$MYSQL_TMP_DIR/trigger')) DO SELECT SLEEP(1); END WHILE; SELECT 1,2,3 INTO $select_into '$MYSQL_TMP_DIR/socket'; END | ||
151 | 35 | DELIMITER ;// | ||
152 | 36 | |||
153 | 37 | --send CALL p1() | ||
154 | 38 | |||
155 | 39 | perl; | ||
156 | 40 | use Socket; | ||
157 | 41 | use IO::Handle; | ||
158 | 42 | |||
159 | 43 | my $fn = "$ENV{'MYSQL_TMP_DIR'}/socket"; | ||
160 | 44 | my $trigger = "$ENV{'MYSQL_TMP_DIR'}/trigger"; | ||
161 | 45 | |||
162 | 46 | unlink($fn); | ||
163 | 47 | socket(SERV, PF_UNIX, SOCK_STREAM, 0) or die("socket: $!"); | ||
164 | 48 | bind(SERV, sockaddr_un($fn)) or die("bind $fn: $!"); | ||
165 | 49 | |||
166 | 50 | # tell the p1 that we created the socket | ||
167 | 51 | open(FILE, ">$trigger"); | ||
168 | 52 | close(FILE); | ||
169 | 53 | |||
170 | 54 | listen(SERV, 1) or die("listen: $!"); | ||
171 | 55 | |||
172 | 56 | accept(CLIENT, SERV); | ||
173 | 57 | $content = <CLIENT>; | ||
174 | 58 | close(CLIENT); | ||
175 | 59 | close(SERV); | ||
176 | 60 | unlink($fn); | ||
177 | 61 | unlink($trigger); | ||
178 | 62 | |||
179 | 63 | EOF | ||
180 | 64 | |||
181 | 65 | --disable_result_log | ||
182 | 66 | --reap | ||
183 | 67 | |||
184 | 68 | DROP PROCEDURE p1; | ||
185 | 0 | 69 | ||
186 | === added file 'Percona-Server/mysql-test/r/percona_outfile_fifosocket.result' | |||
187 | --- Percona-Server/mysql-test/r/percona_outfile_fifosocket.result 1970-01-01 00:00:00 +0000 | |||
188 | +++ Percona-Server/mysql-test/r/percona_outfile_fifosocket.result 2013-09-19 16:14:11 +0000 | |||
189 | @@ -0,0 +1,12 @@ | |||
190 | 1 | SELECT 1,2,3 INTO OUTFILE 'MYSQL_TMP_DIR/regular'; | ||
191 | 2 | ERROR HY000: File 'MYSQL_TMP_DIR/regular' already exists | ||
192 | 3 | SELECT 1,2,3 INTO OUTFILE 'MYSQL_TMP_DIR/fifo'; | ||
193 | 4 | 1 2 3 | ||
194 | 5 | CREATE PROCEDURE p1() BEGIN WHILE ISNULL(LOAD_FILE('MYSQL_TMP_DIR/trigger')) DO SELECT SLEEP(1); END WHILE; SELECT 1,2,3 INTO OUTFILE 'MYSQL_TMP_DIR/socket'; END// | ||
195 | 6 | CALL p1(); | ||
196 | 7 | DROP PROCEDURE p1; | ||
197 | 8 | SELECT 1,2,3 INTO DUMPFILE 'MYSQL_TMP_DIR/regular'; | ||
198 | 9 | SELECT 1,2,3 INTO DUMPFILE 'MYSQL_TMP_DIR/fifo'; | ||
199 | 10 | 123CREATE PROCEDURE p1() BEGIN WHILE ISNULL(LOAD_FILE('MYSQL_TMP_DIR/trigger')) DO SELECT SLEEP(1); END WHILE; SELECT 1,2,3 INTO DUMPFILE 'MYSQL_TMP_DIR/socket'; END// | ||
200 | 11 | CALL p1(); | ||
201 | 12 | DROP PROCEDURE p1; | ||
202 | 0 | 13 | ||
203 | === added file 'Percona-Server/mysql-test/t/percona_outfile_fifosocket-master.opt' | |||
204 | --- Percona-Server/mysql-test/t/percona_outfile_fifosocket-master.opt 1970-01-01 00:00:00 +0000 | |||
205 | +++ Percona-Server/mysql-test/t/percona_outfile_fifosocket-master.opt 2013-09-19 16:14:11 +0000 | |||
206 | @@ -0,0 +1,1 @@ | |||
207 | 1 | --secure_file_priv=$MYSQL_TMP_DIR | ||
208 | 0 | 2 | ||
209 | === added file 'Percona-Server/mysql-test/t/percona_outfile_fifosocket.test' | |||
210 | --- Percona-Server/mysql-test/t/percona_outfile_fifosocket.test 1970-01-01 00:00:00 +0000 | |||
211 | +++ Percona-Server/mysql-test/t/percona_outfile_fifosocket.test 2013-09-19 16:14:11 +0000 | |||
212 | @@ -0,0 +1,12 @@ | |||
213 | 1 | # | ||
214 | 2 | # Test that it is possible to specify fifos and unix sockets as | ||
215 | 3 | # an outfile | ||
216 | 4 | # | ||
217 | 5 | |||
218 | 6 | --source include/not_windows.inc | ||
219 | 7 | |||
220 | 8 | --let $select_into=OUTFILE | ||
221 | 9 | --source include/outfile_fifosocket.inc | ||
222 | 10 | |||
223 | 11 | --let $select_into=DUMPFILE | ||
224 | 12 | --source include/outfile_fifosocket.inc | ||
225 | 0 | 13 | ||
226 | === modified file 'Percona-Server/mysys/errors.c' | |||
227 | --- Percona-Server/mysys/errors.c 2013-03-01 09:31:32 +0000 | |||
228 | +++ Percona-Server/mysys/errors.c 2013-09-19 16:14:11 +0000 | |||
229 | @@ -52,7 +52,10 @@ | |||
230 | 52 | "File '%s' (fileno: %d) was not closed", | 52 | "File '%s' (fileno: %d) was not closed", |
231 | 53 | "Can't change ownership of the file '%s' (Errcode: %d)", | 53 | "Can't change ownership of the file '%s' (Errcode: %d)", |
232 | 54 | "Can't change permissions of the file '%s' (Errcode: %d)", | 54 | "Can't change permissions of the file '%s' (Errcode: %d)", |
234 | 55 | "Can't seek in file '%s' (Errcode: %d)" | 55 | "Can't seek in file '%s' (Errcode: %d)", |
235 | 56 | "Can't create socket '%s' (Errcode: %d)", | ||
236 | 57 | "Can't connect to '%s' (Errcode: %d)", | ||
237 | 58 | "File name '%s' is too long (max: %d)" | ||
238 | 56 | }; | 59 | }; |
239 | 57 | 60 | ||
240 | 58 | void init_glob_errs(void) | 61 | void init_glob_errs(void) |
241 | @@ -96,6 +99,9 @@ | |||
242 | 96 | EE(EE_CHANGE_OWNERSHIP) = "Can't change ownership of the file '%s' (Errcode: %d)"; | 99 | EE(EE_CHANGE_OWNERSHIP) = "Can't change ownership of the file '%s' (Errcode: %d)"; |
243 | 97 | EE(EE_CHANGE_PERMISSIONS) = "Can't change permissions of the file '%s' (Errcode: %d)"; | 100 | EE(EE_CHANGE_PERMISSIONS) = "Can't change permissions of the file '%s' (Errcode: %d)"; |
244 | 98 | EE(EE_CANT_SEEK) = "Can't seek in file '%s' (Errcode: %d)"; | 101 | EE(EE_CANT_SEEK) = "Can't seek in file '%s' (Errcode: %d)"; |
245 | 102 | EE(EE_SOCKET) = "Can't create socket '%s' (Errcode: %d)"; | ||
246 | 103 | EE(EE_CONNECT) = "Can't connect to '%s' (Errcode: %d)"; | ||
247 | 104 | EE(EE_TOOLONGFILENAME) = "File name '%s' is too long (max: %d)"; | ||
248 | 99 | } | 105 | } |
249 | 100 | #endif | 106 | #endif |
250 | 101 | 107 | ||
251 | 102 | 108 | ||
252 | === modified file 'Percona-Server/mysys/my_open.c' | |||
253 | --- Percona-Server/mysys/my_open.c 2013-03-19 12:36:34 +0000 | |||
254 | +++ Percona-Server/mysys/my_open.c 2013-09-19 16:14:11 +0000 | |||
255 | @@ -17,6 +17,9 @@ | |||
256 | 17 | #include "mysys_err.h" | 17 | #include "mysys_err.h" |
257 | 18 | #include <my_dir.h> | 18 | #include <my_dir.h> |
258 | 19 | #include <errno.h> | 19 | #include <errno.h> |
259 | 20 | #ifdef HAVE_SYS_UN_H | ||
260 | 21 | #include <sys/un.h> | ||
261 | 22 | #endif | ||
262 | 20 | 23 | ||
263 | 21 | 24 | ||
264 | 22 | /* | 25 | /* |
265 | @@ -55,6 +58,56 @@ | |||
266 | 55 | 58 | ||
267 | 56 | 59 | ||
268 | 57 | /* | 60 | /* |
269 | 61 | Connect to unix domain socket | ||
270 | 62 | |||
271 | 63 | SYNOPSIS | ||
272 | 64 | my_unix_socket_connect() | ||
273 | 65 | FileName Fully qualified file name | ||
274 | 66 | MyFlags Special flags | ||
275 | 67 | |||
276 | 68 | RETURN VALUE | ||
277 | 69 | File descriptor | ||
278 | 70 | */ | ||
279 | 71 | |||
280 | 72 | #ifndef __WIN__ | ||
281 | 73 | File my_unix_socket_connect(const char *FileName, myf MyFlags) | ||
282 | 74 | /* Path-name of file */ | ||
283 | 75 | /* Read | write .. */ | ||
284 | 76 | /* Special flags */ | ||
285 | 77 | { | ||
286 | 78 | my_socket sd; | ||
287 | 79 | struct sockaddr_un addr; | ||
288 | 80 | DBUG_ENTER("my_unix_socket_connect"); | ||
289 | 81 | DBUG_PRINT("my",("Name: '%s' MyFlags: %d", | ||
290 | 82 | FileName, MyFlags)); | ||
291 | 83 | |||
292 | 84 | if (strlen(FileName) > (sizeof(addr.sun_path) - 1)) | ||
293 | 85 | { | ||
294 | 86 | if (MyFlags & (MY_FAE | MY_WME)) | ||
295 | 87 | my_error(EE_TOOLONGFILENAME, MYF(0), FileName, sizeof(addr.sun_path) - 1); | ||
296 | 88 | DBUG_RETURN(-1); | ||
297 | 89 | } | ||
298 | 90 | if ((sd= socket(AF_UNIX, SOCK_STREAM, 0)) < 0) | ||
299 | 91 | { | ||
300 | 92 | if (MyFlags & (MY_FAE | MY_WME)) | ||
301 | 93 | my_error(EE_SOCKET, MYF(0), FileName, errno); | ||
302 | 94 | DBUG_RETURN(-1); | ||
303 | 95 | } | ||
304 | 96 | memset(&addr, 0, sizeof(addr)); | ||
305 | 97 | addr.sun_family = AF_UNIX; | ||
306 | 98 | strcpy(addr.sun_path, FileName); | ||
307 | 99 | if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { | ||
308 | 100 | close(sd); | ||
309 | 101 | sd= -1; | ||
310 | 102 | } | ||
311 | 103 | |||
312 | 104 | DBUG_RETURN(my_register_filename((File) sd, FileName, FILE_BY_OPEN, | ||
313 | 105 | EE_FILENOTFOUND, MyFlags)); | ||
314 | 106 | } /* my_unix_socket_connect */ | ||
315 | 107 | #endif | ||
316 | 108 | |||
317 | 109 | |||
318 | 110 | /* | ||
319 | 58 | Close a file | 111 | Close a file |
320 | 59 | 112 | ||
321 | 60 | SYNOPSIS | 113 | SYNOPSIS |
322 | 61 | 114 | ||
323 | === modified file 'Percona-Server/sql/sql_class.cc' | |||
324 | --- Percona-Server/sql/sql_class.cc 2013-08-02 09:40:55 +0000 | |||
325 | +++ Percona-Server/sql/sql_class.cc 2013-09-19 16:14:11 +0000 | |||
326 | @@ -2490,7 +2490,10 @@ | |||
327 | 2490 | static File create_file(THD *thd, char *path, sql_exchange *exchange, | 2490 | static File create_file(THD *thd, char *path, sql_exchange *exchange, |
328 | 2491 | IO_CACHE *cache) | 2491 | IO_CACHE *cache) |
329 | 2492 | { | 2492 | { |
331 | 2493 | File file; | 2493 | File file= -1; |
332 | 2494 | bool new_file_created= false; | ||
333 | 2495 | MY_STAT stat_arg; | ||
334 | 2496 | |||
335 | 2494 | uint option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH; | 2497 | uint option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH; |
336 | 2495 | 2498 | ||
337 | 2496 | #ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS | 2499 | #ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS |
338 | @@ -2513,25 +2516,43 @@ | |||
339 | 2513 | return -1; | 2516 | return -1; |
340 | 2514 | } | 2517 | } |
341 | 2515 | 2518 | ||
343 | 2516 | if (!access(path, F_OK)) | 2519 | if (my_stat(path, &stat_arg, MYF(0))) |
344 | 2517 | { | 2520 | { |
347 | 2518 | my_error(ER_FILE_EXISTS_ERROR, MYF(0), exchange->file_name); | 2521 | /* Check if file is named pipe or unix socket */ |
348 | 2519 | return -1; | 2522 | if (MY_S_ISFIFO(stat_arg.st_mode)) |
349 | 2523 | file= mysql_file_open(key_select_to_file, | ||
350 | 2524 | path, O_WRONLY, MYF(MY_WME)); | ||
351 | 2525 | #ifndef __WIN__ | ||
352 | 2526 | if (MY_S_ISSOCK(stat_arg.st_mode)) | ||
353 | 2527 | file= mysql_unix_socket_connect(key_select_to_file, | ||
354 | 2528 | path, MYF(MY_WME)); | ||
355 | 2529 | #endif | ||
356 | 2530 | if (file < 0) | ||
357 | 2531 | { | ||
358 | 2532 | if (!(MY_S_ISFIFO(stat_arg.st_mode) || MY_S_ISSOCK(stat_arg.st_mode))) | ||
359 | 2533 | my_error(ER_FILE_EXISTS_ERROR, MYF(0), exchange->file_name); | ||
360 | 2534 | return -1; | ||
361 | 2535 | } | ||
362 | 2520 | } | 2536 | } |
367 | 2521 | /* Create the file world readable */ | 2537 | else |
368 | 2522 | if ((file= mysql_file_create(key_select_to_file, | 2538 | { |
369 | 2523 | path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0) | 2539 | /* Create the file world readable */ |
370 | 2524 | return file; | 2540 | if ((file= mysql_file_create(key_select_to_file, |
371 | 2541 | path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0) | ||
372 | 2542 | return file; | ||
373 | 2543 | new_file_created= true; | ||
374 | 2525 | #ifdef HAVE_FCHMOD | 2544 | #ifdef HAVE_FCHMOD |
376 | 2526 | (void) fchmod(file, 0666); // Because of umask() | 2545 | (void) fchmod(file, 0666); // Because of umask() |
377 | 2527 | #else | 2546 | #else |
379 | 2528 | (void) chmod(path, 0666); | 2547 | (void) chmod(path, 0666); |
380 | 2529 | #endif | 2548 | #endif |
381 | 2549 | } | ||
382 | 2530 | if (init_io_cache(cache, file, 0L, WRITE_CACHE, 0L, 1, MYF(MY_WME))) | 2550 | if (init_io_cache(cache, file, 0L, WRITE_CACHE, 0L, 1, MYF(MY_WME))) |
383 | 2531 | { | 2551 | { |
384 | 2532 | mysql_file_close(file, MYF(0)); | 2552 | mysql_file_close(file, MYF(0)); |
387 | 2533 | /* Delete file on error, it was just created */ | 2553 | /* Delete file on error, if it was just created */ |
388 | 2534 | mysql_file_delete(key_select_to_file, path, MYF(0)); | 2554 | if (new_file_created) |
389 | 2555 | mysql_file_delete(key_select_to_file, path, MYF(0)); | ||
390 | 2535 | return -1; | 2556 | return -1; |
391 | 2536 | } | 2557 | } |
392 | 2537 | return file; | 2558 | return file; |
Jenkins run is here: http:// jenkins. percona. com/view/ PS%205. 5/job/percona- server- 5.5-param/ 822/