Patch to remove segfault on the exiting of a service.
[openais.git] / test / ckpt-wr.c
blobf9515609fbd074de4909e2367ecbf2b161ec684d
1 /*
2 * Copyright (c) 2002-2005 MontaVista Software, Inc.
4 * All rights reserved.
6 * Author: Steven Dake (sdake@mvista.com)
8 * This software licensed under BSD license, the text of which follows:
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * - Neither the name of the MontaVista Software, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <errno.h>
39 #include <unistd.h>
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <sys/select.h>
43 #include <sys/un.h>
44 #include <time.h>
46 #include "saAis.h"
47 #include "saCkpt.h"
48 #include "sa_error.h"
50 #define SECONDS_TO_EXPIRE 500
52 int ckptinv;
53 void printSaNameT (SaNameT *name)
55 int i;
57 for (i = 0; i < name->length; i++) {
58 printf ("%c", name->value[i]);
62 SaVersionT version = { 'B', 1, 1 };
64 SaNameT checkpointName = { 16, "checkpoint-sync\0" };
66 SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
67 .creationFlags = SA_CKPT_WR_ALL_REPLICAS,
68 .checkpointSize = 250000,
69 .retentionDuration = SA_TIME_ONE_SECOND * 60,
70 .maxSections = 5,
71 .maxSectionSize = 250000,
72 .maxSectionIdSize = 10
75 char readBuffer1[1025];
77 SaCkptIOVectorElementT ReadVectorElements[] = {
79 SA_CKPT_DEFAULT_SECTION_ID,
80 readBuffer1,
81 sizeof (readBuffer1),
82 0,
87 #define DATASIZE 127000
88 char data[DATASIZE];
89 SaCkptIOVectorElementT WriteVectorElements[] = {
91 SA_CKPT_DEFAULT_SECTION_ID,
92 data, /*"written data #1, this should extend past end of old section data", */
93 DATASIZE, /*sizeof ("data #1, this should extend past end of old section data") + 1, */
94 0, //5,
99 SaCkptCallbacksT callbacks = {
104 #define MAX_DATA_SIZE 100
106 int main (void) {
107 SaCkptHandleT ckptHandle;
108 SaCkptCheckpointHandleT checkpointHandle;
109 SaAisErrorT error;
110 char data[MAX_DATA_SIZE];
111 struct timespec delay;
112 struct timespec delay2;
113 SaCkptIOVectorElementT writeElement;
114 long count = 0;
115 SaUint32T erroroneousVectorIndex = 0;
117 delay.tv_sec = 1;
118 delay.tv_nsec = 0;
120 error = saCkptInitialize (&ckptHandle, &callbacks, &version);
122 error = saCkptCheckpointOpen (ckptHandle,
123 &checkpointName,
124 &checkpointCreationAttributes,
125 SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
127 &checkpointHandle);
128 printf ("%s: initial open of checkpoint\n",
129 get_test_output (error, SA_AIS_OK));
133 error = saCkptCheckpointRead (checkpointHandle,
134 ReadVectorElements,
136 &erroroneousVectorIndex);
137 if (error != SA_AIS_OK) {
138 if (error == SA_AIS_ERR_TRY_AGAIN) {
139 continue;
141 printf ("error is %d\n", error);
142 return (0);
145 if (ReadVectorElements->dataBuffer == 0) {
146 printf ("Default Checkpoint has no data\n");
147 } else {
148 count = atol((char *)ReadVectorElements->dataBuffer);
151 count++;
152 sprintf((char*)&data, "%d",(int)count);
153 writeElement.sectionId = (SaCkptSectionIdT)SA_CKPT_DEFAULT_SECTION_ID;
154 writeElement.dataBuffer = data;
155 writeElement.dataSize = strlen (data) + 1;
156 writeElement.dataOffset = 0;
157 writeElement.readSize = 0;
159 do {
160 error = saCkptCheckpointWrite (checkpointHandle,
161 &writeElement,
163 &erroroneousVectorIndex);
165 printf ("%s: checkpoint write with data %s\n",
166 get_test_output (error, SA_AIS_OK), (char*)data);
167 }while (error == SA_AIS_ERR_TRY_AGAIN);
169 nanosleep(&delay,&delay2);
170 }while (1);
172 return (0);