@@ -69,6 +69,12 @@ For example, if the container id is "ubuntu01" the following will send a "KILL"
6969signal to the init process of the "ubuntu01" container:
7070
7171 # runv kill ubuntu01 KILL` ,
72+ Flags : []cli.Flag {
73+ cli.BoolFlag {
74+ Name : "all, a" ,
75+ Usage : "send the signal to all processes in the container" ,
76+ },
77+ },
7278 Action : func (context * cli.Context ) error {
7379 container := context .Args ().First ()
7480 if container == "" {
@@ -88,17 +94,50 @@ signal to the init process of the "ubuntu01" container:
8894 if err != nil {
8995 return cli .NewExitError (fmt .Sprintf ("failed to get client: %v" , err ), - 1 )
9096 }
91- if _ , err = c .Signal (netcontext .Background (), & types.SignalRequest {
92- Id : container ,
93- Pid : "init" ,
94- Signal : uint32 (signal ),
95- }); err != nil {
96- return cli .NewExitError (fmt .Sprintf ("kill signal failed, %v" , err ), - 1 )
97+
98+ plist := make ([]string , 0 )
99+
100+ if context .Bool ("all" ) {
101+ if plist , err = getProcessList (c , container ); err != nil {
102+ return cli .NewExitError (fmt .Sprintf ("can't get process list, %v" , err ), - 1 )
103+ }
104+ } else {
105+ plist = append (plist , "init" )
106+ }
107+
108+ for _ , p := range plist {
109+ if _ , err = c .Signal (netcontext .Background (), & types.SignalRequest {
110+ Id : container ,
111+ Pid : p ,
112+ Signal : uint32 (signal ),
113+ }); err != nil {
114+ return cli .NewExitError (fmt .Sprintf ("kill signal failed, %v" , err ), - 1 )
115+ }
97116 }
98117 return nil
99118 },
100119}
101120
121+ func getProcessList (c types.APIClient , container string ) ([]string , error ) {
122+ s , err := c .State (netcontext .Background (), & types.StateRequest {Id : container })
123+ if err != nil {
124+ return nil , fmt .Errorf ("get container state failed, %v" , err )
125+ }
126+
127+ for _ , cc := range s .Containers {
128+ if cc .Id == container {
129+ plist := make ([]string , 0 )
130+ for _ , p := range cc .Processes {
131+ plist = append (plist , p .Pid )
132+ }
133+
134+ return plist , nil
135+ }
136+ }
137+
138+ return nil , fmt .Errorf ("container %s not found" , container )
139+ }
140+
102141func parseSignal (rawSignal string ) (syscall.Signal , error ) {
103142 s , err := strconv .Atoi (rawSignal )
104143 if err == nil {
0 commit comments