@@ -80,7 +80,8 @@ static bool opt_new_session = false;
8080static bool opt_die_with_parent = false;
8181static uid_t opt_sandbox_uid = -1 ;
8282static gid_t opt_sandbox_gid = -1 ;
83- static int opt_sync_fd = -1 ;
83+ static int * opt_sync_fd = NULL ;
84+ static int opt_sync_fd_count = 0 ;
8485static int opt_block_fd = -1 ;
8586static int opt_userns_block_fd = -1 ;
8687static int opt_info_fd = -1 ;
@@ -2311,14 +2312,12 @@ parse_args_recurse (int *argcp,
23112312 if (argc < 2 )
23122313 die ("--sync-fd takes an argument" );
23132314
2314- if (opt_sync_fd != -1 )
2315- warn_only_last_option ("--sync-fd" );
2316-
23172315 the_fd = strtol (argv [1 ], & endptr , 10 );
23182316 if (argv [1 ][0 ] == 0 || endptr [0 ] != 0 || the_fd < 0 )
23192317 die ("Invalid fd: %s" , argv [1 ]);
23202318
2321- opt_sync_fd = the_fd ;
2319+ opt_sync_fd = xrealloc (opt_sync_fd , sizeof (& opt_sync_fd [0 ]) * (opt_sync_fd_count + 1 ));
2320+ opt_sync_fd [opt_sync_fd_count ++ ] = the_fd ;
23222321
23232322 argv += 1 ;
23242323 argc -= 1 ;
@@ -3542,7 +3541,7 @@ main (int argc,
35423541
35433542 debug ("forking for child" );
35443543
3545- if (!opt_as_pid_1 && (opt_unshare_pid || lock_files != NULL || opt_sync_fd != -1 ))
3544+ if (!opt_as_pid_1 && (opt_unshare_pid || lock_files != NULL || opt_sync_fd_count > 0 ))
35463545 {
35473546 /* We have to have a pid 1 in the pid namespace, because
35483547 * otherwise we'll get a bunch of zombies as nothing reaps
@@ -3566,10 +3565,11 @@ main (int argc,
35663565 {
35673566 int dont_close [3 ];
35683567 int j = 0 ;
3568+ int k ;
35693569 if (event_fd != -1 )
35703570 dont_close [j ++ ] = event_fd ;
3571- if ( opt_sync_fd != -1 )
3572- dont_close [j ++ ] = opt_sync_fd ;
3571+ for ( k = 0 ; k < opt_sync_fd_count ; k ++ )
3572+ dont_close [j ++ ] = opt_sync_fd [ k ] ;
35733573 dont_close [j ++ ] = -1 ;
35743574 fdwalk (proc_fd , close_extra_fds , dont_close );
35753575 }
@@ -3587,8 +3587,9 @@ main (int argc,
35873587 --sync-fd will still work unless the container process doesn't close this file. */
35883588 if (!opt_as_pid_1 )
35893589 {
3590- if (opt_sync_fd != -1 )
3591- close (opt_sync_fd );
3590+ int k ;
3591+ for (k = 0 ; k < opt_sync_fd_count ; k ++ )
3592+ close (opt_sync_fd [k ]);
35923593 }
35933594
35943595 /* We want sigchild in the child */
0 commit comments