Commit 660096fa 660096faef31d6534dd7796234900aac10ea1d27 by Sergey Poznyakoff

(default_imap4d_start): Save imap4d spawn id in the global variable.

(default_imap4d_stop): Moved functionality from imap4d_exit
(imap4d_stop): Call default_imap4d_stop unless it has already
been called.
(imap4d_exit): Call imap4d_stop
1 parent d95188f6
...@@ -60,6 +60,7 @@ proc default_imap4d_start {args} { ...@@ -60,6 +60,7 @@ proc default_imap4d_start {args} {
60 global MU_TOOL 60 global MU_TOOL
61 global MU_TOOL_FLAGS 61 global MU_TOOL_FLAGS
62 global expect_out 62 global expect_out
63 global imap4d_spawn_id
63 64
64 mu_version 65 mu_version
65 66
...@@ -83,8 +84,8 @@ proc default_imap4d_start {args} { ...@@ -83,8 +84,8 @@ proc default_imap4d_start {args} {
83 set imap4d_cmd "$MU_TOOL $sw" 84 set imap4d_cmd "$MU_TOOL $sw"
84 verbose "Spawning $imap4d_cmd" 85 verbose "Spawning $imap4d_cmd"
85 86
86 set res [remote_spawn host $imap4d_cmd] 87 set imap4d_spawn_id [remote_spawn host $imap4d_cmd]
87 if { $res < 0 || $res == "" } { 88 if { $imap4d_spawn_id < 0 || $imap4d_spawn_id == "" } {
88 perror "Spawning $imap4d_cmd failed." 89 perror "Spawning $imap4d_cmd failed."
89 return 1; 90 return 1;
90 } 91 }
...@@ -102,9 +103,14 @@ proc default_imap4d_start {args} { ...@@ -102,9 +103,14 @@ proc default_imap4d_start {args} {
102 } 103 }
103 104
104 proc default_imap4d_stop {} { 105 proc default_imap4d_stop {} {
105
106 verbose "Stopping imap4d" 106 verbose "Stopping imap4d"
107 107 if [imap4d_test "LOGOUT"\
108 "BYE Session terminating." \
109 "OK LOGOUT Completed"] {
110 perror "LOGOUT failed"
111 exit 1
112 }
113 return 0
108 } 114 }
109 115
110 proc imap4d_start {args} { 116 proc imap4d_start {args} {
...@@ -135,7 +141,11 @@ proc imap4d_start {args} { ...@@ -135,7 +141,11 @@ proc imap4d_start {args} {
135 } 141 }
136 142
137 proc imap4d_stop {} { 143 proc imap4d_stop {} {
138 return [default_imap4d_stop]; 144 global imap4d_spawn_id
145 if {[info exists imap4d_spawn_id] && $imap4d_spawn_id > 0} {
146 default_imap4d_stop
147 unset imap4d_spawn_id
148 }
139 } 149 }
140 150
141 ## 151 ##
...@@ -156,18 +166,12 @@ proc imap4d_command { cmd } { ...@@ -156,18 +166,12 @@ proc imap4d_command { cmd } {
156 } 166 }
157 167
158 proc imap4d_uidvalidity {} { 168 proc imap4d_uidvalidity {} {
159 regsub "(\[0-9\]*)\[0-9\]" "[clock seconds]" "\\1\[0-9\]" val 169 regsub "(\[0-9\]*)\[0-9\]" "[clock seconds]" "\\1\[0-9\]" val
160 return $val 170 return $val
161 } 171 }
162 172
163 proc imap4d_exit {} { 173 proc imap4d_exit {} {
164 if [imap4d_test "LOGOUT"\ 174 imap4d_stop
165 "BYE Session terminating." \
166 "OK LOGOUT Completed"] {
167 perror "LOGOUT failed"
168 exit 1
169 }
170 return 0
171 } 175 }
172 176
173 proc imap4d_auth {args} { 177 proc imap4d_auth {args} {
......