@@ -102,7 +102,9 @@ static int in_de_collect(struct flb_input_instance *ins,
102102 size_t out_size = 0 ;
103103 struct flb_time out_time ;
104104
105- if ((ret = read (ctx -> fd , ctx -> buf , ctx -> buf_size - 1 )) > 0 ) {
105+ ret = read (ctx -> fd , ctx -> buf , ctx -> buf_size - 1 );
106+
107+ if (ret > 0 ) {
106108 str_len = ret ;
107109 ctx -> buf [str_len ] = '\0' ;
108110
@@ -153,6 +155,39 @@ static int in_de_collect(struct flb_input_instance *ins,
153155 }
154156 }
155157 }
158+ else if (ret == 0 ) {
159+ /* EOF */
160+ /* docker service may be restarted */
161+ flb_plg_info (ctx -> ins , "EOF detected. Re-initialize" );
162+ /* remove old socket collector */
163+ ret = flb_input_collector_delete (ctx -> coll_id , ins );
164+ close (ctx -> fd );
165+ if (ret < 0 ) {
166+ flb_plg_error (ctx -> ins , "failed to pause event" );
167+ return -1 ;
168+ }
169+ ctx -> fd = -1 ;
170+ /* create socket again */
171+ if (de_unix_create (ctx ) < 0 ) {
172+ flb_plg_error (ctx -> ins , "failed to re-initialize socket" );
173+ return -1 ;
174+ }
175+ /* set event */
176+ ctx -> coll_id = flb_input_set_collector_event (ins ,
177+ in_de_collect ,
178+ ctx -> fd , config );
179+ if (ctx -> coll_id < 0 ) {
180+ flb_plg_error (ctx -> ins ,
181+ "could not set collector for IN_DOCKER_EVENTS plugin" );
182+ return -1 ;
183+ }
184+ ret = flb_input_collector_start (ctx -> coll_id , ins );
185+ if (ret < 0 ) {
186+ flb_plg_error (ctx -> ins ,
187+ "could not start collector for IN_DOCKER_EVENTS plugin" );
188+ return -1 ;
189+ }
190+ }
156191 else {
157192 error = errno ;
158193 flb_plg_error (ctx -> ins , "read returned error: %d, %s" , error ,
@@ -194,8 +229,9 @@ static int in_de_init(struct flb_input_instance *ins,
194229 return -1 ;
195230 }
196231
197- if (flb_input_set_collector_event (ins , in_de_collect ,
198- ctx -> fd , config ) == -1 ) {
232+ ctx -> coll_id = flb_input_set_collector_event (ins , in_de_collect ,
233+ ctx -> fd , config );
234+ if (ctx -> coll_id < 0 ){
199235 flb_plg_error (ctx -> ins ,
200236 "could not set collector for IN_DOCKER_EVENTS plugin" );
201237 de_config_destroy (ctx );
0 commit comments