@@ -26,6 +26,8 @@ struct reckless {
26
26
char * stderrbuf ;
27
27
size_t stdout_read ; /* running total */
28
28
size_t stdout_new ; /* new since last read */
29
+ size_t stderr_read ;
30
+ size_t stderr_new ;
29
31
pid_t pid ;
30
32
};
31
33
@@ -35,6 +37,17 @@ struct lconfig {
35
37
char * network ;
36
38
} lconfig ;
37
39
40
+ static struct io_plan * reckless_in_init (struct io_conn * conn ,
41
+ struct reckless * reckless )
42
+ {
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
+
38
51
static struct io_plan * read_more (struct io_conn * conn , struct reckless * rkls )
39
52
{
40
53
rkls -> stdout_read += rkls -> stdout_new ;
@@ -114,6 +127,33 @@ static struct io_plan *conn_init(struct io_conn *conn, struct reckless *rkls)
114
127
return read_more (conn , rkls );
115
128
}
116
129
130
+ static void stderr_conn_finish (struct io_conn * conn , void * reckless UNUSED )
131
+ {
132
+ io_close (conn );
133
+ }
134
+
135
+ static struct io_plan * stderr_read_more (struct io_conn * conn ,
136
+ struct reckless * rkls )
137
+ {
138
+ rkls -> stderr_read += rkls -> stderr_new ;
139
+ if (rkls -> stderr_read == tal_count (rkls -> stderrbuf ))
140
+ tal_resize (& rkls -> stderrbuf , rkls -> stderr_read * 2 );
141
+ if (strends (rkls -> stderrbuf , "[Y] to create one now.\n" )) {
142
+ plugin_log (plugin , LOG_DBG , "confirming config creation" );
143
+ reckless_send_yes (rkls );
144
+ }
145
+ return io_read_partial (conn , rkls -> stderrbuf + rkls -> stderr_read ,
146
+ tal_count (rkls -> stderrbuf ) - rkls -> stderr_read ,
147
+ & rkls -> stderr_new , stderr_read_more , rkls );
148
+ }
149
+
150
+ static struct io_plan * stderr_conn_init (struct io_conn * conn ,
151
+ struct reckless * reckless )
152
+ {
153
+ io_set_finish (conn , stderr_conn_finish , NULL );
154
+ return stderr_read_more (conn , reckless );
155
+ }
156
+
117
157
static struct command_result * reckless_call (struct command * cmd ,
118
158
const char * call )
119
159
{
@@ -142,6 +182,8 @@ static struct command_result *reckless_call(struct command *cmd,
142
182
reckless -> stderrbuf = tal_arrz (reckless , char , 1024 );
143
183
reckless -> stdout_read = 0 ;
144
184
reckless -> stdout_new = 0 ;
185
+ reckless -> stderr_read = 0 ;
186
+ reckless -> stderr_new = 0 ;
145
187
char * full_cmd ;
146
188
full_cmd = tal_fmt (tmpctx , "calling:" );
147
189
for (int i = 0 ; i < tal_count (my_call ); i ++ )
@@ -154,6 +196,7 @@ static struct command_result *reckless_call(struct command *cmd,
154
196
155
197
/* FIXME: fail if invalid pid*/
156
198
io_new_conn (reckless , reckless -> stdoutfd , conn_init , reckless );
199
+ io_new_conn (reckless , reckless -> stderrfd , stderr_conn_init , reckless );
157
200
tal_free (my_call );
158
201
return command_still_pending (cmd );
159
202
}
0 commit comments