@@ -25,6 +25,8 @@ struct reckless {
25
25
char * stderrbuf ;
26
26
size_t stdout_read ; /* running total */
27
27
size_t stdout_new ; /* new since last read */
28
+ size_t stderr_read ;
29
+ size_t stderr_new ;
28
30
pid_t pid ;
29
31
};
30
32
@@ -34,6 +36,18 @@ struct lconfig {
34
36
char * network ;
35
37
} lconfig ;
36
38
39
+ static struct io_plan * reckless_in_init (struct io_conn * conn ,
40
+ struct reckless * reckless )
41
+ {
42
+ plugin_log (plugin , LOG_DBG , "Reckless stdin initialized. Writing Y." );
43
+ return io_write (conn , "Y" , 1 , io_close_cb , NULL );
44
+ }
45
+
46
+ static void reckless_send_yes (struct reckless * reckless )
47
+ {
48
+ io_new_conn (reckless , reckless -> stdinfd , reckless_in_init , reckless );
49
+ }
50
+
37
51
static struct io_plan * read_more (struct io_conn * conn , struct reckless * rkls )
38
52
{
39
53
plugin_log (plugin , LOG_DBG , "reckless-stdout:%s\n" , rkls -> stdoutbuf );
@@ -117,6 +131,37 @@ static struct io_plan *conn_init(struct io_conn *conn, struct reckless *rkls)
117
131
return read_more (conn , rkls );
118
132
}
119
133
134
+ static void stderr_conn_finish (struct io_conn * conn , void * reckless UNUSED )
135
+ {
136
+ io_close (conn );
137
+ }
138
+
139
+ static struct io_plan * stderr_read_more (struct io_conn * conn ,
140
+ struct reckless * rkls )
141
+ {
142
+ plugin_log (plugin , LOG_DBG , "reckless-stderr:%s\n" ,
143
+ rkls -> stderrbuf );
144
+ rkls -> stderr_read += rkls -> stderr_new ;
145
+ if (rkls -> stderr_read == tal_count (rkls -> stderrbuf ))
146
+ tal_resize (& rkls -> stderrbuf , rkls -> stderr_read * 2 );
147
+ if (strends (rkls -> stderrbuf , "[Y] to create one now.\n" )) {
148
+ plugin_log (plugin , LOG_DBG , "inputting Y" );
149
+ reckless_send_yes (rkls );
150
+ plugin_log (plugin , LOG_DBG , "wrote Y to stdin" );
151
+ }
152
+ return io_read_partial (conn , rkls -> stderrbuf + rkls -> stderr_read ,
153
+ tal_count (rkls -> stderrbuf ) - rkls -> stderr_read ,
154
+ & rkls -> stderr_new , stderr_read_more , rkls );
155
+ }
156
+
157
+ static struct io_plan * stderr_conn_init (struct io_conn * conn ,
158
+ struct reckless * reckless )
159
+ {
160
+ plugin_log (plugin , LOG_DBG , "new stderr connection to reckless" );
161
+ io_set_finish (conn , stderr_conn_finish , NULL );
162
+ return stderr_read_more (conn , reckless );
163
+ }
164
+
120
165
static struct command_result * reckless_call (struct command * cmd ,
121
166
const char * call )
122
167
{
@@ -145,6 +190,8 @@ static struct command_result *reckless_call(struct command *cmd,
145
190
reckless -> stderrbuf = tal_arrz (reckless , char , 1024 );
146
191
reckless -> stdout_read = 0 ;
147
192
reckless -> stdout_new = 0 ;
193
+ reckless -> stderr_read = 0 ;
194
+ reckless -> stderr_new = 0 ;
148
195
plugin_log (plugin , LOG_DBG , "calling reckless" );
149
196
char * full_cmd ;
150
197
full_cmd = tal_fmt (tmpctx , "calling: [" );
@@ -160,6 +207,7 @@ static struct command_result *reckless_call(struct command *cmd,
160
207
161
208
/* FIXME: fail if invalid pid*/
162
209
io_new_conn (reckless , reckless -> stdoutfd , conn_init , reckless );
210
+ io_new_conn (reckless , reckless -> stderrfd , stderr_conn_init , reckless );
163
211
tal_free (my_call );
164
212
return command_still_pending (cmd );
165
213
}
0 commit comments