| 1257 | } |
| 1258 | |
| 1259 | cs_error_t sam_register ( |
| 1260 | unsigned int *instance_id) |
| 1261 | { |
| 1262 | pid_t pid; |
| 1263 | int pipe_error; |
| 1264 | int pipe_fd_out[2], pipe_fd_in[2]; |
| 1265 | enum sam_parent_action_t action, old_action; |
| 1266 | int child_status; |
| 1267 | sam_recovery_policy_t recpol; |
| 1268 | cs_error_t ret; |
| 1269 | |
| 1270 | ret = CS_OK; |
| 1271 | |
| 1272 | if (sam_internal_data.internal_status != SAM_INTERNAL_STATUS_INITIALIZED) { |
| 1273 | ret = CS_ERR_BAD_HANDLE; |
| 1274 | goto exit_error; |
| 1275 | } |
| 1276 | |
| 1277 | recpol = sam_internal_data.recovery_policy; |
| 1278 | |
| 1279 | if (recpol & SAM_RECOVERY_POLICY_CMAP) { |
| 1280 | /* |
| 1281 | * Register to cmap |
| 1282 | */ |
| 1283 | if ((ret = sam_cmap_register ()) != CS_OK) { |
| 1284 | ret = CS_ERR_BAD_HANDLE; |
| 1285 | goto exit_error; |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | while (1) { |
| 1290 | if ((pipe_error = pipe (pipe_fd_out)) != 0) { |
| 1291 | ret = CS_ERR_LIBRARY; |
| 1292 | goto exit_error; |
| 1293 | } |
| 1294 | |
| 1295 | if ((pipe_error = pipe (pipe_fd_in)) != 0) { |
| 1296 | close (pipe_fd_out[0]); |
| 1297 | close (pipe_fd_out[1]); |
| 1298 | |
| 1299 | ret = CS_ERR_BAD_HANDLE; |
| 1300 | goto exit_error; |
| 1301 | } |
| 1302 | |
| 1303 | if (recpol & SAM_RECOVERY_POLICY_CMAP) { |
| 1304 | if ((ret = sam_cmap_update_key (SAM_CMAP_KEY_STATE, SAM_CMAP_S_REGISTERED)) != CS_OK) { |
| 1305 | goto exit_error; |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | sam_internal_data.instance_id++; |
| 1310 | |
| 1311 | sam_internal_data.term_send = 0; |
| 1312 | |
| 1313 | pid = fork (); |
| 1314 | |
| 1315 | if (pid == -1) { |
| 1316 | /* |