Commit ca67cee5 authored by Pavan Balaji's avatar Pavan Balaji
Browse files

[svn-r7490] Fixes to the stdin reading code. Only when stdin is attached to a

terminal, and the process is running in the background, discard stdin.
parent c37df8b6
......@@ -10,6 +10,22 @@
int HYDT_dmxu_num_cb_fds = 0;
struct HYDT_dmxu_callback *HYDT_dmxu_cb_list = NULL;
struct HYDT_dmxu_fns HYDT_dmxu_fns = { 0 };
int HYDT_dmxu_got_sigttin = 0;
#if defined(SIGTTIN) && defined(HAVE_ISATTY)
static void signal_cb(int sig)
{
HYDU_FUNC_ENTER();
if (sig == SIGTTIN) {
HYDT_dmxu_got_sigttin = 1;
}
/* Ignore all other signals */
HYDU_FUNC_EXIT();
return;
}
#endif /* SIGTTIN and HAVE_ISATTY */
HYD_status HYDT_dmx_init(char **demux)
{
......@@ -47,6 +63,13 @@ HYD_status HYDT_dmx_init(char **demux)
"cannot find an appropriate demux engine\n");
}
#if defined(SIGTTIN) && defined(HAVE_ISATTY)
if (isatty(STDIN_FILENO)) {
status = HYDU_set_signal(SIGTTIN, signal_cb);
HYDU_ERR_POP(status, "unable to set SIGTTIN\n");
}
#endif /* SIGTTIN and HAVE_ISATTY */
fn_exit:
HYDU_FUNC_EXIT();
return status;
......
......@@ -22,6 +22,7 @@ struct HYDT_dmxu_callback {
extern int HYDT_dmxu_num_cb_fds;
extern struct HYDT_dmxu_callback *HYDT_dmxu_cb_list;
extern int HYDT_dmxu_got_sigttin;
struct HYDT_dmxu_fns {
HYD_status(*wait_for_event) (int wtime);
......
......@@ -127,7 +127,7 @@ HYD_status HYDT_dmxu_poll_stdin_valid(int *out)
* read() call to return an error (with errno == EINTR) when we
* are not attached to the terminal. */
ret = read(STDIN_FILENO, NULL, 0);
if (ret < 0 && errno == EINTR)
if (ret < 0 && errno == EINTR && HYDT_dmxu_got_sigttin)
*out = 0;
fn_exit:
......
......@@ -120,7 +120,7 @@ HYD_status HYDT_dmxu_select_stdin_valid(int *out)
* read() call to return an error (with errno == EINTR) when we
* are not attached to the terminal. */
ret = read(STDIN_FILENO, NULL, 0);
if (ret < 0 && errno == EINTR)
if (ret < 0 && errno == EINTR && HYDT_dmxu_got_sigttin)
*out = 0;
fn_exit:
......
......@@ -143,7 +143,7 @@ static void signal_cb(int sig)
cmd = HYD_CKPOINT;
HYDU_sock_write(HYD_handle.cleanup_pipe[1], &cmd, sizeof(cmd), &sent, &closed);
}
/* Ignore all other signals, including SIGTTIN */
/* Ignore all other signals */
HYDU_FUNC_EXIT();
return;
......
......@@ -59,11 +59,6 @@ HYD_status HYDU_set_common_signals(void (*handler) (int))
status = HYDU_set_signal(SIGALRM, handler);
HYDU_ERR_POP(status, "unable to set SIGALRM\n");
#ifdef SIGTTIN
status = HYDU_set_signal(SIGTTIN, handler);
HYDU_ERR_POP(status, "unable to set SIGTTIN\n");
#endif /* SIGTTIN */
fn_exit:
HYDU_FUNC_EXIT();
return status;
......
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