Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
3486675e
Commit
3486675e
authored
Apr 28, 2020
by
Uchio Kondo
Committed by
Hiroshi Mimaki
May 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test mruby-io in tmpdir when AF_UNIX cannot be created on cwd
parent
3d46f1b6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
mrbgems/mruby-io/test/mruby_io_test.c
mrbgems/mruby-io/test/mruby_io_test.c
+46
-0
No files found.
mrbgems/mruby-io/test/mruby_io_test.c
View file @
3486675e
#include <mruby/common.h>
#include <mruby/common.h>
#include <sys/types.h>
#include <sys/types.h>
#include <errno.h>
#include <errno.h>
#include <assert.h>
#if defined(_WIN32) || defined(_WIN64)
#if defined(_WIN32) || defined(_WIN64)
...
@@ -57,6 +58,7 @@ mkdtemp(char *temp)
...
@@ -57,6 +58,7 @@ mkdtemp(char *temp)
#include <sys/stat.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdlib.h>
#include <fcntl.h>
#include "mruby.h"
#include "mruby.h"
#include "mruby/array.h"
#include "mruby/array.h"
...
@@ -65,9 +67,48 @@ mkdtemp(char *temp)
...
@@ -65,9 +67,48 @@ mkdtemp(char *temp)
#include "mruby/variable.h"
#include "mruby/variable.h"
#include <mruby/ext/io.h>
#include <mruby/ext/io.h>
int
wd_save
;
int
socket_available_p
;
static
int
mrb_io_socket_abailable
()
{
int
fd
,
retval
=
1
;
struct
sockaddr_un
sun0
;
char
socketname
[]
=
"tmp.mruby-io-socket-ok.XXXXXXXX"
;
if
(
!
(
fd
=
mkstemp
(
socketname
)))
{
retval
=
0
;
goto
sock_test_out
;
}
unlink
(
socketname
);
close
(
fd
);
fd
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
0
);
if
(
fd
==
-
1
)
{
retval
=
0
;
goto
sock_test_out
;
}
sun0
.
sun_family
=
AF_UNIX
;
snprintf
(
sun0
.
sun_path
,
sizeof
(
sun0
.
sun_path
),
"%s"
,
socketname
);
if
(
bind
(
fd
,
(
struct
sockaddr
*
)
&
sun0
,
sizeof
(
sun0
))
==
-
1
)
{
retval
=
0
;
}
sock_test_out:
close
(
fd
);
return
retval
;
}
static
mrb_value
static
mrb_value
mrb_io_test_io_setup
(
mrb_state
*
mrb
,
mrb_value
self
)
mrb_io_test_io_setup
(
mrb_state
*
mrb
,
mrb_value
self
)
{
{
if
(
!
(
socket_available_p
=
mrb_io_socket_abailable
()))
{
char
*
tmpdir
;
wd_save
=
open
(
"."
,
O_DIRECTORY
);
tmpdir
=
getenv
(
"TMPDIR"
);
if
(
tmpdir
)
assert
(
!
chdir
(
tmpdir
));
else
assert
(
!
chdir
(
"/tmp"
));
}
char
rfname
[]
=
"tmp.mruby-io-test-r.XXXXXXXX"
;
char
rfname
[]
=
"tmp.mruby-io-test-r.XXXXXXXX"
;
char
wfname
[]
=
"tmp.mruby-io-test-w.XXXXXXXX"
;
char
wfname
[]
=
"tmp.mruby-io-test-w.XXXXXXXX"
;
char
symlinkname
[]
=
"tmp.mruby-io-test-l.XXXXXXXX"
;
char
symlinkname
[]
=
"tmp.mruby-io-test-l.XXXXXXXX"
;
...
@@ -176,6 +217,11 @@ mrb_io_test_io_cleanup(mrb_state *mrb, mrb_value self)
...
@@ -176,6 +217,11 @@ mrb_io_test_io_cleanup(mrb_state *mrb, mrb_value self)
mrb_gv_set
(
mrb
,
mrb_intern_cstr
(
mrb
,
"$mrbtest_io_socketname"
),
mrb_nil_value
());
mrb_gv_set
(
mrb
,
mrb_intern_cstr
(
mrb
,
"$mrbtest_io_socketname"
),
mrb_nil_value
());
mrb_gv_set
(
mrb
,
mrb_intern_cstr
(
mrb
,
"$mrbtest_io_msg"
),
mrb_nil_value
());
mrb_gv_set
(
mrb
,
mrb_intern_cstr
(
mrb
,
"$mrbtest_io_msg"
),
mrb_nil_value
());
if
(
!
socket_available_p
)
{
assert
(
!
fchdir
(
wd_save
));
close
(
wd_save
);
}
return
mrb_nil_value
();
return
mrb_nil_value
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment