Merge lp:~sergei.glushchenko/percona-server/5.5-BT34246-ps-blueprint-into-outfile-pipe-and-socket into lp:percona-server/5.5

Proposed by Sergei Glushchenko on 2013-08-20
Status: Merged
Approved by: Alexey Kopytov on 2013-09-20
Approved revision: 559
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
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve on 2013-09-20
George Ormond Lorch III g2 2013-08-20 Approve on 2013-09-05
Review via email: mp+181115@code.launchpad.net

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.

To post a comment you must log in.
review: Approve (g2)
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-related code should be wrapped into #ifndef __WIN__

   - 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_socket_connect() return
     -1, create_file() assumes the file was neither a FIFO nor a socket
     and raises the ER_FILE_EXISTS_ERROR. Instead, it should not raise
     any errors (because it was already raised by one of those
     functions) and return -1.

   - if connect() fails in my_unix_socket_connect(), we return without
     closing the socket.

   - instead of doing:


  if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
    if (MyFlags & (MY_FAE | MY_WME))
      my_error(EE_CONNECT, MYF(0), FileName, errno);
    DBUG_RETURN(-1);
  }

  DBUG_RETURN(my_register_filename((File) sd, FileName, FILE_BY_OPEN,
           EE_FILENOTFOUND, MyFlags));

you could do:


  if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
    close(sd);
    sd= -1;
  }

  DBUG_RETURN(my_register_filename((File) sd, FileName, FILE_BY_OPEN,
           EE_CONNECT, MyFlags));

  - 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{'MYSQL_TMP_DIR'}/outfile";
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_TMP_DIR/fifo'

perl;
my $fn = "$ENV{'MYSQL_TMP_DIR'}/fifo";
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(LOAD_FILE('$MYSQL_TMP_DIR/trigger')) DO SELECT SLEEP(1); END WHILE; SELECT 1,2,3 INTO OUTFILE '$MYSQL_TMP_DIR/socket'

    2) In Perl create that file before the listen() call:

open(FILE, '>', "$ENV{'MYSQL_TMP_DIR'}/trigger");
close(FILE);

review: Needs Fixing
Download full text (3.7 KiB)

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_socket_connect() return
> -1, create_file() assumes the file was neither a FIFO nor a socket
> and raises the ER_FILE_EXISTS_ERROR. Instead, it should not raise
> any errors (because it was already raised by one of those
> functions) and return -1.
>

We need to raise ER_FILE_EXISTS_ERROR, in case when file exists and is not socket/fifo, but you're right that we did it also in the case of other errors. Fixed.

> - if connect() fails in my_unix_socket_connect(), we return without
> closing the socket.
>
> - instead of doing:
>
> —
> if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
> if (MyFlags & (MY_FAE | MY_WME))
> my_error(EE_CONNECT, MYF(0), FileName, errno);
> DBUG_RETURN(-1);
> }
>
> DBUG_RETURN(my_register_filename((File) sd, FileName, FILE_BY_OPEN,
> EE_FILENOTFOUND, MyFlags));
> —
>
> you could do:
>
> —
> if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
> close(sd);
> sd= -1;
> }
>
> DBUG_RETURN(my_register_filename((File) sd, FileName, FILE_BY_OPEN,
> 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{'MYSQL_TMP_DIR'}/outfile";
> 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_TMP_DIR/fifo'
>
> perl;
> my $fn = "$ENV{'MYSQL_TMP_DIR'}/fifo";
> 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...

Read more...

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.

review: Needs Fixing
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.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Percona-Server/include/my_dir.h'
--- Percona-Server/include/my_dir.h 2013-03-19 12:36:34 +0000
+++ Percona-Server/include/my_dir.h 2013-09-19 16:14:11 +0000
@@ -32,6 +32,7 @@
32#define MY_S_IFBLK S_IFBLK /* block special */32#define MY_S_IFBLK S_IFBLK /* block special */
33#define MY_S_IFREG S_IFREG /* regular */33#define MY_S_IFREG S_IFREG /* regular */
34#define MY_S_IFIFO S_IFIFO /* fifo */34#define MY_S_IFIFO S_IFIFO /* fifo */
35#define MY_S_IFSOCK S_IFSOCK /* socket */
35#define MY_S_ISUID S_ISUID /* set user id on execution */36#define MY_S_ISUID S_ISUID /* set user id on execution */
36#define MY_S_ISGID S_ISGID /* set group id on execution */37#define MY_S_ISGID S_ISGID /* set group id on execution */
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 */
@@ -44,6 +45,7 @@
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)
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)
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)
48#define MY_S_ISSOCK(m) (((m) & MY_S_IFMT) == MY_S_IFSOCK)
4749
48#define MY_DONT_SORT 512 /* my_lib; Don't sort files */50#define MY_DONT_SORT 512 /* my_lib; Don't sort files */
49#define MY_WANT_STAT 1024 /* my_lib; stat files */51#define MY_WANT_STAT 1024 /* my_lib; stat files */
5052
=== modified file 'Percona-Server/include/my_sys.h'
--- Percona-Server/include/my_sys.h 2013-06-27 15:35:20 +0000
+++ Percona-Server/include/my_sys.h 2013-09-19 16:14:11 +0000
@@ -562,6 +562,9 @@
562extern char *my_once_strdup(const char *src,myf myflags);562extern char *my_once_strdup(const char *src,myf myflags);
563extern void *my_once_memdup(const void *src, size_t len, myf myflags);563extern void *my_once_memdup(const void *src, size_t len, myf myflags);
564extern File my_open(const char *FileName,int Flags,myf MyFlags);564extern File my_open(const char *FileName,int Flags,myf MyFlags);
565#ifndef __WIN__
566extern File my_unix_socket_connect(const char *FileName,myf MyFlags);
567#endif
565extern File my_register_filename(File fd, const char *FileName,568extern File my_register_filename(File fd, const char *FileName,
566 enum file_type type_of_file,569 enum file_type type_of_file,
567 uint error_message_number, myf MyFlags);570 uint error_message_number, myf MyFlags);
568571
=== modified file 'Percona-Server/include/mysql/psi/mysql_file.h'
--- Percona-Server/include/mysql/psi/mysql_file.h 2010-12-21 12:00:26 +0000
+++ Percona-Server/include/mysql/psi/mysql_file.h 2013-09-19 16:14:11 +0000
@@ -303,6 +303,21 @@
303#endif303#endif
304304
305/**305/**
306 @def mysql_unix_socket_connect(K, N, F)
307 Instrumented open.
308 @c mysql_unix_socket_connect connects to the unix domain socket.
309*/
310#ifndef __WIN__
311#ifdef HAVE_PSI_INTERFACE
312 #define mysql_unix_socket_connect(K, N, F) \
313 inline_mysql_unix_socket_connect(K, __FILE__, __LINE__, N, F)
314#else
315 #define mysql_unix_socket_connect(K, N, F) \
316 inline_mysql_unix_socket_connect(N, F)
317#endif
318#endif
319
320/**
306 @def mysql_file_close(FD, F)321 @def mysql_file_close(FD, F)
307 Instrumented close.322 Instrumented close.
308 @c mysql_file_close is a replacement for @c my_close.323 @c mysql_file_close is a replacement for @c my_close.
@@ -1051,6 +1066,35 @@
1051 return file;1066 return file;
1052}1067}
10531068
1069#ifndef __WIN__
1070static inline File
1071inline_mysql_unix_socket_connect(
1072#ifdef HAVE_PSI_INTERFACE
1073 PSI_file_key key, const char *src_file, uint src_line,
1074#endif
1075 const char *filename, myf myFlags)
1076{
1077 File file;
1078#ifdef HAVE_PSI_INTERFACE
1079 struct PSI_file_locker *locker= NULL;
1080 PSI_file_locker_state state;
1081 if (likely(PSI_server != NULL))
1082 {
1083 locker= PSI_server->get_thread_file_name_locker(&state, key, PSI_FILE_OPEN,
1084 filename, &locker);
1085 if (likely(locker != NULL))
1086 PSI_server->start_file_open_wait(locker, src_file, src_line);
1087 }
1088#endif
1089 file = my_unix_socket_connect(filename, myFlags);
1090#ifdef HAVE_PSI_INTERFACE
1091 if (likely(locker != NULL))
1092 PSI_server->end_file_open_wait_and_bind_to_descriptor(locker, file);
1093#endif
1094 return file;
1095}
1096#endif
1097
1054static inline int1098static inline int
1055inline_mysql_file_close(1099inline_mysql_file_close(
1056#ifdef HAVE_PSI_INTERFACE1100#ifdef HAVE_PSI_INTERFACE
10571101
=== modified file 'Percona-Server/include/mysys_err.h'
--- Percona-Server/include/mysys_err.h 2011-06-30 15:46:53 +0000
+++ Percona-Server/include/mysys_err.h 2013-09-19 16:14:11 +0000
@@ -66,7 +66,10 @@
66#define EE_CHANGE_OWNERSHIP 3166#define EE_CHANGE_OWNERSHIP 31
67#define EE_CHANGE_PERMISSIONS 3267#define EE_CHANGE_PERMISSIONS 32
68#define EE_CANT_SEEK 3368#define EE_CANT_SEEK 33
69#define EE_ERROR_LAST 33 /* Copy last error nr */69#define EE_SOCKET 34
70#define EE_CONNECT 35
71#define EE_TOOLONGFILENAME 36
72#define EE_ERROR_LAST 36 /* Copy last error nr */
70/* Add error numbers before EE_ERROR_LAST and change it accordingly. */73/* Add error numbers before EE_ERROR_LAST and change it accordingly. */
7174
72 /* exit codes for all MySQL programs */75 /* exit codes for all MySQL programs */
7376
=== added file 'Percona-Server/mysql-test/include/outfile_fifosocket.inc'
--- Percona-Server/mysql-test/include/outfile_fifosocket.inc 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/include/outfile_fifosocket.inc 2013-09-19 16:14:11 +0000
@@ -0,0 +1,68 @@
1#
2# Test SELECT INTO OUTFILE/DUMPFILE with fifo and unix socket as destination
3#
4
5perl;
6my $fn = "$ENV{'MYSQL_TMP_DIR'}/regular";
7unlink($fn);
8open(FILE, ">$fn");
9print(FILE "1\n");
10close(FILE);
11EOF
12
13--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
14--error 1086
15--eval SELECT 1,2,3 INTO $select_into '$MYSQL_TMP_DIR/regular'
16
17perl;
18use POSIX qw(mkfifo);
19my $fn = "$ENV{'MYSQL_TMP_DIR'}/fifo";
20unlink($fn);
21mkfifo($fn, 0666) or die("mkfifo: $!");
22EOF
23
24--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
25--send_eval SELECT 1,2,3 INTO $select_into '$MYSQL_TMP_DIR/fifo'
26
27--cat_file $MYSQL_TMP_DIR/fifo
28
29--reap
30
31DELIMITER //;
32# procedure spin waiting when file 'trigger' appears
33--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
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
35DELIMITER ;//
36
37--send CALL p1()
38
39perl;
40use Socket;
41use IO::Handle;
42
43my $fn = "$ENV{'MYSQL_TMP_DIR'}/socket";
44my $trigger = "$ENV{'MYSQL_TMP_DIR'}/trigger";
45
46unlink($fn);
47socket(SERV, PF_UNIX, SOCK_STREAM, 0) or die("socket: $!");
48bind(SERV, sockaddr_un($fn)) or die("bind $fn: $!");
49
50# tell the p1 that we created the socket
51open(FILE, ">$trigger");
52close(FILE);
53
54listen(SERV, 1) or die("listen: $!");
55
56accept(CLIENT, SERV);
57$content = <CLIENT>;
58close(CLIENT);
59close(SERV);
60unlink($fn);
61unlink($trigger);
62
63EOF
64
65--disable_result_log
66--reap
67
68DROP PROCEDURE p1;
069
=== added file 'Percona-Server/mysql-test/r/percona_outfile_fifosocket.result'
--- Percona-Server/mysql-test/r/percona_outfile_fifosocket.result 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/r/percona_outfile_fifosocket.result 2013-09-19 16:14:11 +0000
@@ -0,0 +1,12 @@
1SELECT 1,2,3 INTO OUTFILE 'MYSQL_TMP_DIR/regular';
2ERROR HY000: File 'MYSQL_TMP_DIR/regular' already exists
3SELECT 1,2,3 INTO OUTFILE 'MYSQL_TMP_DIR/fifo';
41 2 3
5CREATE 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//
6CALL p1();
7DROP PROCEDURE p1;
8SELECT 1,2,3 INTO DUMPFILE 'MYSQL_TMP_DIR/regular';
9SELECT 1,2,3 INTO DUMPFILE 'MYSQL_TMP_DIR/fifo';
10123CREATE 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//
11CALL p1();
12DROP PROCEDURE p1;
013
=== added file 'Percona-Server/mysql-test/t/percona_outfile_fifosocket-master.opt'
--- Percona-Server/mysql-test/t/percona_outfile_fifosocket-master.opt 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/t/percona_outfile_fifosocket-master.opt 2013-09-19 16:14:11 +0000
@@ -0,0 +1,1 @@
1--secure_file_priv=$MYSQL_TMP_DIR
02
=== added file 'Percona-Server/mysql-test/t/percona_outfile_fifosocket.test'
--- Percona-Server/mysql-test/t/percona_outfile_fifosocket.test 1970-01-01 00:00:00 +0000
+++ Percona-Server/mysql-test/t/percona_outfile_fifosocket.test 2013-09-19 16:14:11 +0000
@@ -0,0 +1,12 @@
1#
2# Test that it is possible to specify fifos and unix sockets as
3# an outfile
4#
5
6--source include/not_windows.inc
7
8--let $select_into=OUTFILE
9--source include/outfile_fifosocket.inc
10
11--let $select_into=DUMPFILE
12--source include/outfile_fifosocket.inc
013
=== modified file 'Percona-Server/mysys/errors.c'
--- Percona-Server/mysys/errors.c 2013-03-01 09:31:32 +0000
+++ Percona-Server/mysys/errors.c 2013-09-19 16:14:11 +0000
@@ -52,7 +52,10 @@
52 "File '%s' (fileno: %d) was not closed",52 "File '%s' (fileno: %d) was not closed",
53 "Can't change ownership of the file '%s' (Errcode: %d)",53 "Can't change ownership of the file '%s' (Errcode: %d)",
54 "Can't change permissions of the file '%s' (Errcode: %d)",54 "Can't change permissions of the file '%s' (Errcode: %d)",
55 "Can't seek in file '%s' (Errcode: %d)"55 "Can't seek in file '%s' (Errcode: %d)",
56 "Can't create socket '%s' (Errcode: %d)",
57 "Can't connect to '%s' (Errcode: %d)",
58 "File name '%s' is too long (max: %d)"
56};59};
5760
58void init_glob_errs(void)61void init_glob_errs(void)
@@ -96,6 +99,9 @@
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)";
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)";
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)";
102 EE(EE_SOCKET) = "Can't create socket '%s' (Errcode: %d)";
103 EE(EE_CONNECT) = "Can't connect to '%s' (Errcode: %d)";
104 EE(EE_TOOLONGFILENAME) = "File name '%s' is too long (max: %d)";
99}105}
100#endif106#endif
101107
102108
=== modified file 'Percona-Server/mysys/my_open.c'
--- Percona-Server/mysys/my_open.c 2013-03-19 12:36:34 +0000
+++ Percona-Server/mysys/my_open.c 2013-09-19 16:14:11 +0000
@@ -17,6 +17,9 @@
17#include "mysys_err.h"17#include "mysys_err.h"
18#include <my_dir.h>18#include <my_dir.h>
19#include <errno.h>19#include <errno.h>
20#ifdef HAVE_SYS_UN_H
21#include <sys/un.h>
22#endif
2023
2124
22/*25/*
@@ -55,6 +58,56 @@
5558
5659
57/*60/*
61 Connect to unix domain socket
62
63 SYNOPSIS
64 my_unix_socket_connect()
65 FileName Fully qualified file name
66 MyFlags Special flags
67
68 RETURN VALUE
69 File descriptor
70*/
71
72#ifndef __WIN__
73File my_unix_socket_connect(const char *FileName, myf MyFlags)
74 /* Path-name of file */
75 /* Read | write .. */
76 /* Special flags */
77{
78 my_socket sd;
79 struct sockaddr_un addr;
80 DBUG_ENTER("my_unix_socket_connect");
81 DBUG_PRINT("my",("Name: '%s' MyFlags: %d",
82 FileName, MyFlags));
83
84 if (strlen(FileName) > (sizeof(addr.sun_path) - 1))
85 {
86 if (MyFlags & (MY_FAE | MY_WME))
87 my_error(EE_TOOLONGFILENAME, MYF(0), FileName, sizeof(addr.sun_path) - 1);
88 DBUG_RETURN(-1);
89 }
90 if ((sd= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
91 {
92 if (MyFlags & (MY_FAE | MY_WME))
93 my_error(EE_SOCKET, MYF(0), FileName, errno);
94 DBUG_RETURN(-1);
95 }
96 memset(&addr, 0, sizeof(addr));
97 addr.sun_family = AF_UNIX;
98 strcpy(addr.sun_path, FileName);
99 if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
100 close(sd);
101 sd= -1;
102 }
103
104 DBUG_RETURN(my_register_filename((File) sd, FileName, FILE_BY_OPEN,
105 EE_FILENOTFOUND, MyFlags));
106} /* my_unix_socket_connect */
107#endif
108
109
110/*
58 Close a file111 Close a file
59112
60 SYNOPSIS113 SYNOPSIS
61114
=== modified file 'Percona-Server/sql/sql_class.cc'
--- Percona-Server/sql/sql_class.cc 2013-08-02 09:40:55 +0000
+++ Percona-Server/sql/sql_class.cc 2013-09-19 16:14:11 +0000
@@ -2490,7 +2490,10 @@
2490static File create_file(THD *thd, char *path, sql_exchange *exchange,2490static File create_file(THD *thd, char *path, sql_exchange *exchange,
2491 IO_CACHE *cache)2491 IO_CACHE *cache)
2492{2492{
2493 File file;2493 File file= -1;
2494 bool new_file_created= false;
2495 MY_STAT stat_arg;
2496
2494 uint option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH;2497 uint option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH;
24952498
2496#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS2499#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
@@ -2513,25 +2516,43 @@
2513 return -1;2516 return -1;
2514 }2517 }
25152518
2516 if (!access(path, F_OK))2519 if (my_stat(path, &stat_arg, MYF(0)))
2517 {2520 {
2518 my_error(ER_FILE_EXISTS_ERROR, MYF(0), exchange->file_name);2521 /* Check if file is named pipe or unix socket */
2519 return -1;2522 if (MY_S_ISFIFO(stat_arg.st_mode))
2523 file= mysql_file_open(key_select_to_file,
2524 path, O_WRONLY, MYF(MY_WME));
2525#ifndef __WIN__
2526 if (MY_S_ISSOCK(stat_arg.st_mode))
2527 file= mysql_unix_socket_connect(key_select_to_file,
2528 path, MYF(MY_WME));
2529#endif
2530 if (file < 0)
2531 {
2532 if (!(MY_S_ISFIFO(stat_arg.st_mode) || MY_S_ISSOCK(stat_arg.st_mode)))
2533 my_error(ER_FILE_EXISTS_ERROR, MYF(0), exchange->file_name);
2534 return -1;
2535 }
2520 }2536 }
2521 /* Create the file world readable */2537 else
2522 if ((file= mysql_file_create(key_select_to_file,2538 {
2523 path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)2539 /* Create the file world readable */
2524 return file;2540 if ((file= mysql_file_create(key_select_to_file,
2541 path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)
2542 return file;
2543 new_file_created= true;
2525#ifdef HAVE_FCHMOD2544#ifdef HAVE_FCHMOD
2526 (void) fchmod(file, 0666); // Because of umask()2545 (void) fchmod(file, 0666); // Because of umask()
2527#else2546#else
2528 (void) chmod(path, 0666);2547 (void) chmod(path, 0666);
2529#endif2548#endif
2549 }
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)))
2531 {2551 {
2532 mysql_file_close(file, MYF(0));2552 mysql_file_close(file, MYF(0));
2533 /* Delete file on error, it was just created */2553 /* Delete file on error, if it was just created */
2534 mysql_file_delete(key_select_to_file, path, MYF(0));2554 if (new_file_created)
2555 mysql_file_delete(key_select_to_file, path, MYF(0));
2535 return -1;2556 return -1;
2536 }2557 }
2537 return file;2558 return file;

Subscribers

People subscribed via source and target branches