@@ -4,6 +4,7 @@ use std::{
44} ;
55
66use tokio:: process:: { Child , Command } ;
7+ use win32job:: { Job , JobError } ;
78
89use crate :: ConnParams ;
910
@@ -12,6 +13,7 @@ pub struct PostgresDaemon {
1213 data_path : PathBuf ,
1314 pg_proc : Result < Child , std:: io:: Error > ,
1415 silent : bool ,
16+ _job_obj : Job ,
1517}
1618impl PostgresDaemon {
1719 pub fn new (
@@ -23,6 +25,8 @@ impl PostgresDaemon {
2325 let pg_bin_dir = pg_bin_dir. into ( ) ;
2426 let data_path = data_path. into ( ) ;
2527
28+ let job = Self :: create_job_object ( ) . expect ( "failed to create job object" ) ;
29+
2630 tracing:: info!( ?pg_bin_dir, ?data_path, "starting" ) ;
2731 let postgres_bin_path = Self :: pg_bin_path ( & pg_bin_dir, "postgres" ) ;
2832
@@ -51,13 +55,22 @@ impl PostgresDaemon {
5155 data_path,
5256 pg_proc : proc,
5357 silent,
58+ _job_obj : job,
5459 }
5560 }
5661 fn pg_bin_path ( pg_bin_dir : impl AsRef < Path > , name : impl Into < PathBuf > ) -> PathBuf {
5762 let mut bin = name. into ( ) ;
5863 bin. set_extension ( std:: env:: consts:: EXE_EXTENSION ) ;
5964 pg_bin_dir. as_ref ( ) . join ( bin)
6065 }
66+ fn create_job_object ( ) -> Result < Job , JobError > {
67+ let job = Job :: create ( ) ?;
68+ let mut info = job. query_extended_limit_info ( ) ?;
69+ info. limit_kill_on_job_close ( ) ;
70+ job. set_extended_limit_info ( & info) ?;
71+ job. assign_current_process ( ) ?;
72+ Ok ( job)
73+ }
6174}
6275impl Drop for PostgresDaemon {
6376 fn drop ( & mut self ) {
0 commit comments