Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
LSH
lsh
Commits
261d4fba
Commit
261d4fba
authored
Oct 30, 1998
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set the close-on-exec flag on all fd:s.
Rev: src/io.c:1.21 Rev: src/io.h:1.15
parent
58f38a1a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
14 deletions
+40
-14
src/io.c
src/io.c
+34
-9
src/io.h
src/io.h
+6
-5
No files found.
src/io.c
View file @
261d4fba
...
@@ -99,7 +99,11 @@ static void close_fd(struct io_fd *fd)
...
@@ -99,7 +99,11 @@ static void close_fd(struct io_fd *fd)
(
void
)
CLOSE_CALLBACK
(
fd
->
close_callback
,
fd
->
close_reason
);
(
void
)
CLOSE_CALLBACK
(
fd
->
close_callback
,
fd
->
close_reason
);
close
(
fd
->
fd
);
close
(
fd
->
fd
);
/* Make sure writing to the buffer fails. */
if
(
fd
->
buffer
)
write_buffer_close
(
fd
->
buffer
);
/* There can be other objects around that may still
/* There can be other objects around that may still
* attempt to write to the buffer. So let gc handle it
* attempt to write to the buffer. So let gc handle it
* instead of freeing it explicitly */
* instead of freeing it explicitly */
...
@@ -532,6 +536,22 @@ void io_set_nonblocking(int fd)
...
@@ -532,6 +536,22 @@ void io_set_nonblocking(int fd)
fatal
(
"io_set_nonblocking: fcntl() failed, %s"
,
strerror
(
errno
));
fatal
(
"io_set_nonblocking: fcntl() failed, %s"
,
strerror
(
errno
));
}
}
void
io_set_close_on_exec
(
int
fd
)
{
if
(
fcntl
(
fd
,
F_SETFD
,
1
)
<
0
)
fatal
(
"Can't set close-on-exec flag for fd %d: %s
\n
"
,
fd
,
strerror
(
errno
));
}
/* ALL file descripters handled by the backend should use non-blocking mode,
* and have the close-on-exec flag set. */
void
io_init_fd
(
int
fd
)
{
io_set_nonblocking
(
fd
);
io_set_close_on_exec
(
fd
);
}
/* Some code is taken from bellman's tcputils. */
/* Some code is taken from bellman's tcputils. */
struct
connect_fd
*
io_connect
(
struct
io_backend
*
b
,
struct
connect_fd
*
io_connect
(
struct
io_backend
*
b
,
struct
sockaddr_in
*
remote
,
struct
sockaddr_in
*
remote
,
...
@@ -544,7 +564,7 @@ struct connect_fd *io_connect(struct io_backend *b,
...
@@ -544,7 +564,7 @@ struct connect_fd *io_connect(struct io_backend *b,
if
(
s
<
0
)
if
(
s
<
0
)
return
NULL
;
return
NULL
;
io_
set_nonblocking
(
s
);
io_
init_fd
(
s
);
if
(
local
&&
bind
(
s
,
(
struct
sockaddr
*
)
local
,
sizeof
*
local
)
<
0
)
if
(
local
&&
bind
(
s
,
(
struct
sockaddr
*
)
local
,
sizeof
*
local
)
<
0
)
{
{
...
@@ -585,7 +605,7 @@ struct listen_fd *io_listen(struct io_backend *b,
...
@@ -585,7 +605,7 @@ struct listen_fd *io_listen(struct io_backend *b,
if
(
s
<
0
)
if
(
s
<
0
)
return
NULL
;
return
NULL
;
io_
set_nonblocking
(
s
);
io_
init_fd
(
s
);
{
{
int
yes
=
1
;
int
yes
=
1
;
...
@@ -625,6 +645,8 @@ struct abstract_write *io_read_write(struct io_backend *b,
...
@@ -625,6 +645,8 @@ struct abstract_write *io_read_write(struct io_backend *b,
struct
io_fd
*
f
;
struct
io_fd
*
f
;
struct
write_buffer
*
buffer
=
write_buffer_alloc
(
block_size
);
struct
write_buffer
*
buffer
=
write_buffer_alloc
(
block_size
);
io_init_fd
(
fd
);
NEW
(
f
);
NEW
(
f
);
f
->
fd
=
fd
;
f
->
fd
=
fd
;
...
@@ -653,6 +675,8 @@ struct io_fd *io_read(struct io_backend *b,
...
@@ -653,6 +675,8 @@ struct io_fd *io_read(struct io_backend *b,
{
{
struct
io_fd
*
f
;
struct
io_fd
*
f
;
io_init_fd
(
fd
);
NEW
(
f
);
NEW
(
f
);
f
->
fd
=
fd
;
f
->
fd
=
fd
;
...
@@ -675,14 +699,16 @@ struct io_fd *io_read(struct io_backend *b,
...
@@ -675,14 +699,16 @@ struct io_fd *io_read(struct io_backend *b,
return
f
;
return
f
;
}
}
struct
abstract_write
*
io_write
(
struct
io_backend
*
b
,
struct
io_fd
*
io_write
(
struct
io_backend
*
b
,
int
fd
,
int
fd
,
UINT32
block_size
,
UINT32
block_size
,
struct
close_callback
*
close_callback
)
struct
close_callback
*
close_callback
)
{
{
struct
io_fd
*
f
;
struct
io_fd
*
f
;
struct
write_buffer
*
buffer
=
write_buffer_alloc
(
block_size
);
struct
write_buffer
*
buffer
=
write_buffer_alloc
(
block_size
);
io_init_fd
(
fd
);
NEW
(
f
);
NEW
(
f
);
f
->
fd
=
fd
;
f
->
fd
=
fd
;
...
@@ -700,6 +726,5 @@ struct abstract_write *io_write(struct io_backend *b,
...
@@ -700,6 +726,5 @@ struct abstract_write *io_write(struct io_backend *b,
b
->
io
=
f
;
b
->
io
=
f
;
b
->
nio
++
;
b
->
nio
++
;
return
&
buffer
->
super
;
return
f
;
}
}
src/io.h
View file @
261d4fba
...
@@ -128,6 +128,8 @@ int get_inaddr(struct sockaddr_in * addr,
...
@@ -128,6 +128,8 @@ int get_inaddr(struct sockaddr_in * addr,
const
char
*
protocol
);
const
char
*
protocol
);
void
io_set_nonblocking
(
int
fd
);
void
io_set_nonblocking
(
int
fd
);
void
io_set_close_on_exec
(
int
fd
);
void
io_init_fd
(
int
fd
);
struct
connect_fd
*
io_connect
(
struct
io_backend
*
b
,
struct
connect_fd
*
io_connect
(
struct
io_backend
*
b
,
struct
sockaddr_in
*
remote
,
struct
sockaddr_in
*
remote
,
...
@@ -150,10 +152,9 @@ struct io_fd *io_read(struct io_backend *b,
...
@@ -150,10 +152,9 @@ struct io_fd *io_read(struct io_backend *b,
struct
read_handler
*
read_callback
,
struct
read_handler
*
read_callback
,
struct
close_callback
*
close_callback
);
struct
close_callback
*
close_callback
);
struct
abstract_write
*
io_write
(
struct
io_backend
*
b
,
struct
io_fd
*
io_write
(
struct
io_backend
*
b
,
int
fd
,
int
fd
,
UINT32
block_size
,
UINT32
block_size
,
struct
close_callback
*
close_callback
);
struct
close_callback
*
close_callback
);
#endif
/* LSH_IO_H_INCLUDED */
#endif
/* LSH_IO_H_INCLUDED */
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