| 149 | |
| 150 | |
| 151 | void SHUT_database(thread_db* tdbb, SSHORT flag, SSHORT delay, Sync* guard) |
| 152 | { |
| 153 | /************************************** |
| 154 | * |
| 155 | * S H U T _ d a t a b a s e |
| 156 | * |
| 157 | ************************************** |
| 158 | * |
| 159 | * Functional description |
| 160 | * Schedule database for shutdown |
| 161 | * |
| 162 | **************************************/ |
| 163 | SET_TDBB(tdbb); |
| 164 | Database* const dbb = tdbb->getDatabase(); |
| 165 | Jrd::Attachment* const attachment = tdbb->getAttachment(); |
| 166 | |
| 167 | // Only platform's user locksmith can shutdown or bring online a database |
| 168 | |
| 169 | if (!attachment->locksmith(tdbb, CHANGE_SHUTDOWN_MODE)) |
| 170 | { |
| 171 | ERR_post_nothrow(Arg::Gds(isc_no_priv) << "shutdown" << "database" << dbb->dbb_filename); |
| 172 | if (attachment->att_user && attachment->att_user->testFlag(USR_mapdown)) |
| 173 | ERR_post_nothrow(Arg::Gds(isc_map_down)); |
| 174 | ERR_punt(); |
| 175 | } |
| 176 | |
| 177 | const int shut_mode = flag & isc_dpb_shut_mode_mask; |
| 178 | |
| 179 | // Check if requested shutdown mode is valid |
| 180 | // Note that if we are already in requested mode we just return true. |
| 181 | // This is required to ensure backward compatible behavior (gbak relies on that, |
| 182 | // user-written scripts may rely on this behaviour too) |
| 183 | switch (shut_mode) |
| 184 | { |
| 185 | case isc_dpb_shut_full: |
| 186 | if (dbb->dbb_ast_flags & DBB_shutdown_full) |
| 187 | { |
| 188 | same_mode(dbb); |
| 189 | return; |
| 190 | } |
| 191 | break; |
| 192 | case isc_dpb_shut_multi: |
| 193 | if (dbb->dbb_ast_flags & (DBB_shutdown_full | DBB_shutdown_single)) |
| 194 | { |
| 195 | bad_mode(dbb); |
| 196 | } |
| 197 | if (dbb->dbb_ast_flags & DBB_shutdown) |
| 198 | { |
| 199 | same_mode(dbb); |
| 200 | return; |
| 201 | } |
| 202 | break; |
| 203 | case isc_dpb_shut_single: |
| 204 | if (dbb->dbb_ast_flags & DBB_shutdown_full) |
| 205 | { |
| 206 | bad_mode(dbb); |
| 207 | } |
| 208 | if (dbb->dbb_ast_flags & DBB_shutdown_single) |
no test coverage detected