Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions asApp/src/asVerify.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ int main(int argc, char **argv)
{
FILE *fp = NULL, *ftmp = NULL;
char s[BUF_SIZE], filename[PATH_SIZE], restoreFileName[PATH_SIZE];
char *tempname;
int n;
int numDifferences;
int status;
Expand Down Expand Up @@ -86,28 +85,24 @@ int main(int argc, char **argv)
printf("Can't open %s\n", filename);
return (-1);
}
tempname = tmpnam(NULL);
ftmp = fopen(tempname, "w");
ftmp = tmpfile();
if (ftmp == NULL) {
printf("Can't open temp file.\n");
fclose(fp);
return (-1);
}
while (!feof(fp) && (n = fread(s, 1, BUF_SIZE, fp))) { fwrite(s, 1, n, ftmp); }
while (!feof(fp) && (n = (int)fread(s, 1, BUF_SIZE, fp))) { fwrite(s, 1, n, ftmp); }
fclose(fp);
fp = NULL;
fclose(ftmp);
ftmp = NULL;

if (write_restore_file) {
strcpy(restoreFileName, filename);
strcat(restoreFileName, ".asVerify");
} else {
strcpy(restoreFileName, "");
}
numDifferences = do_asVerify(tempname, verbose, debug, write_restore_file, restoreFileName);
numDifferences = do_asVerify_fp(ftmp, verbose, debug, write_restore_file, restoreFileName);

remove(tempname);
ca_context_destroy();
return (numDifferences);
}
16 changes: 12 additions & 4 deletions asApp/src/dbrestore.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ int restoreFileListsInitialized = 0;
ELLLIST pass0List;
ELLLIST pass1List;

extern char SR_STATUS_STR[5][10];

void myPrintErrno(char *s, char *file, int line)
{
errlogPrintf("%s(%d): [0x%x]=%s:%s\n", file, line, errno, s, strerror(errno));
Expand All @@ -124,7 +126,7 @@ float mySafeDoubleToFloat(double d)
if (d > 0.0) f = FLT_MIN;
else f = -FLT_MIN;
} else {
f = d;
f = (float)d;
}
return (f);
}
Expand Down Expand Up @@ -290,7 +292,7 @@ STATIC long scalar_restore(int pass, DBENTRY *pdbentry, char *PVname, char *valu
status = dbNameToAddr(PVname, paddr);
if (!status) {
if (is_long_string && paddr->field_type == DBF_CHAR) {
status = dbPut(paddr, DBF_CHAR, value_string, strlen(value_string) + 1);
status = dbPut(paddr, DBF_CHAR, value_string, (long)strlen(value_string) + 1);
} else {
status = dbPut(paddr, DBF_STRING, value_string, 1);
}
Expand Down Expand Up @@ -397,11 +399,15 @@ long SR_array_restore(int pass, FILE *inp_fd, char *PVname, char *value_string,
char *p_char = NULL;
short *p_short = NULL;
epicsInt32 *p_long = NULL;
#ifdef DBR_INT64
epicsInt64 *p_int64 = NULL;
#endif
unsigned char *p_uchar = NULL;
unsigned short *p_ushort = NULL;
epicsUInt32 *p_ulong = NULL;
#ifdef DBR_INT64
epicsUInt64 *p_uint64 = NULL;
#endif
float *p_float = NULL;
double *p_double = NULL;

Expand Down Expand Up @@ -943,8 +949,10 @@ int reboot_restore(char *filename, initHookState init_state)
printf(" ebuffer='%s'\n", ebuffer);
}
}
n = BUF_SIZE - strlen(value_string) - 1;
n = BUF_SIZE - (int)strlen(value_string) - 1;
strncat(value_string, bp, n);
/* make sure value_string is properly null-terminated */
value_string[BUF_SIZE - 1] = '\0';
/* we don't want that '\n' in the string */
if (value_string[strlen(value_string) - 1] == '\n') value_string[strlen(value_string) - 1] = '\0';
}
Expand Down Expand Up @@ -1502,7 +1510,7 @@ void makeAutosaveFileFromDbInfo(char *fileBaseName, char *info_name)
for (pend = pbegin; *pend && !isspace((int)*pend); pend++) {}
/* pend points to whitespace or \0 */

flen = pend - pbegin;
flen = (int)(pend - pbegin);
if (flen >= sizeof(field) - 1) flen = sizeof(field) - 1;
memcpy(field, pbegin, flen);
field[flen] = '\0';
Expand Down
1 change: 1 addition & 0 deletions asApp/src/os/WIN32/osdNfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

/* definition except for vxWorks */
#define OK 0
#undef ERROR /* ERROR is defined by Windows in wingdi.h */
#define ERROR -1
#define logMsg errlogPrintf

Expand Down
16 changes: 10 additions & 6 deletions asApp/src/save_restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
#define SET_FILE_PERMISSIONS 1

#ifdef _WIN32
#undef SET_FILE_PERMISSIONS
#define SET_FILE_PERMISSIONS 0
#endif

Expand Down Expand Up @@ -342,6 +343,9 @@ STATIC epicsThreadId taskID = 0; /* save_restore task ID */
/*** stuff for reporting status to EPICS client ***/
STATIC char status_prefix[30] = "";

/* Make sure to leave room for trailing null */
char SR_STATUS_STR[5][10] = {"No Status", " Failure ", " Warning ", " Warning ", " Ok "};

STATIC long SR_status = SR_STATUS_INIT;
STATIC unsigned short SR_heartbeat = 0;
STATIC char SR_statusStr[STATUS_STR_LEN] = "", SR_recentlyStr[STATUS_STR_LEN] = "";
Expand Down Expand Up @@ -598,7 +602,7 @@ STATIC void on_change_timer(CALLBACK *pcallback)
STATIC void on_change_save(struct event_handler_args event)
{
struct chlist *plist;
if (save_restoreDebug >= 10) { logMsg("on_change_save: event.usr=0x%lx\n", (unsigned long)event.usr); }
if (save_restoreDebug >= 10) { logMsg("on_change_save: event.usr=0x%llx\n", (unsigned long long)event.usr); }
plist = (struct chlist *)event.usr;

if (plist) {
Expand Down Expand Up @@ -2362,7 +2366,7 @@ STATIC int create_data_set(char *filename, /* save set request file
while ((plist->save_file[inx] != 0) && (plist->save_file[inx] != '.') && (inx < (FN_LEN-6))) inx++;
#else
/* fix bfr 2007-10-01: need to search for last '.', not first */
inx = strlen(plist->save_file) - 1;
inx = (int)strlen(plist->save_file) - 1;
while (inx > 0 && plist->save_file[inx] != '.') inx--;
#endif
plist->save_file[inx] = 0; /* truncate if necessary to leave room for ".sav" + null */
Expand Down Expand Up @@ -2502,8 +2506,8 @@ int set_requestfile_path(char *path, char *pathsub)
char fullpath[MAX_PATH_LEN + 1] = "";
int path_len = 0, pathsub_len = 0;

if (path && *path) path_len = strlen(path);
if (pathsub && *pathsub) pathsub_len = strlen(pathsub);
if (path && *path) path_len = (int)strlen(path);
if (pathsub && *pathsub) pathsub_len = (int)strlen(pathsub);
if (path_len + pathsub_len > (MAX_PATH_LEN - 1)) { /* may have to add '/' */
printf("save_restore:set_requestfile_path: 'path'+'pathsub' is too long\n");
return (ERROR);
Expand Down Expand Up @@ -3294,7 +3298,7 @@ STATIC int do_manual_restore(char *filename, int file_type, char *macrostring)
if (bp[strlen(bp) - 1] != '\n') {
/* No, we didn't. One more read will certainly accumulate a value string of length BUF_SIZE */
bp = fgets(buffer, BUF_SIZE, inp_fd);
n = BUF_SIZE - strlen(value_string) - 1;
n = BUF_SIZE - (int)strlen(value_string) - 1;
strncat(value_string, bp, n);
if (value_string[strlen(value_string) - 1] == '\n')
value_string[strlen(value_string) - 1] = '\0';
Expand All @@ -3308,7 +3312,7 @@ STATIC int do_manual_restore(char *filename, int file_type, char *macrostring)
} else if (ca_pend_io(0.5) != ECA_NORMAL) {
num_errs++;
/* Don't forget trailing null character: "strlen(value_string)+1" below */
} else if (ca_array_put(DBR_CHAR, strlen(value_string) + 1, chanid, value_string) != ECA_NORMAL) {
} else if (ca_array_put(DBR_CHAR, (unsigned long)strlen(value_string) + 1, chanid, value_string) != ECA_NORMAL) {
printf("save_restore:do_manual_restore: ca_array_put of '%s' to '%s' failed\n", value_string,
PVname);
num_errs++;
Expand Down
4 changes: 1 addition & 3 deletions asApp/src/save_restore.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

/* Make sure to leave room for trailing null */
static char SR_STATUS_STR[5][10] = {"No Status", " Failure ", " Warning ", " Warning ", " Ok "};

#define SR_STATUS_OK 4
#define SR_STATUS_SEQ_WARN 3
#define SR_STATUS_WARN 2
Expand Down Expand Up @@ -90,6 +87,7 @@ extern struct restoreList restoreFileList;
extern int myFileCopy(const char *source, const char *dest);
extern void dbrestoreShow(void);
extern int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file, char *restoreFileName);
extern int do_asVerify_fp(FILE *fp, int verbose, int debug, int write_restore_file, char *restoreFileName);

extern volatile int save_restoreRemountThreshold;

Expand Down
36 changes: 21 additions & 15 deletions asApp/src/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,28 @@

long read_array(FILE *fp, char *PVname, char *value_string, short field_type, long element_count, char *read_buffer,
int debug);
int do_asVerify_fp(FILE *fp, int verbose, int debug, int write_restore_file, char *restoreFileName);

/* verbose==-1 means don't say anything unless there's a problem. */
int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file, char *restoreFileName)
{
FILE *fp = NULL;
fp = fopen(fileName, "r");
if (fp == NULL) {
printf("asVerify: Can't open '%s'.\n", fileName);
return (-1);
}
return do_asVerify_fp(fp, verbose, debug, write_restore_file, restoreFileName);
}

int do_asVerify_fp(FILE *fp, int verbose, int debug, int write_restore_file, char *restoreFileName)
{
float *pfvalue, *pf_read;
double *pdvalue, *pd_read, diff, max_diff = 0.;
short *penum_value, *penum_value_read;
char *svalue, *svalue_read;
chid chid;
FILE *fp = NULL, *fr = NULL, *fr1 = NULL;
FILE *fr = NULL, *fr1 = NULL;
char c, s[BUF_SIZE], *bp, PVname[PV_NAME_LEN + 1], value_string[BUF_SIZE];
char trial_restoreFileName[PATH_SIZE];
char *CA_buffer = NULL, *read_buffer = NULL, *pc = NULL;
Expand All @@ -54,12 +66,6 @@ int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file,
int different, wrote_head = 0, status, file_ok = 0;
long element_count = 0, storageBytes = 0, alloc_CA_buffer = 0;

fp = fopen(fileName, "r");
if (fp == NULL) {
printf("asVerify: Can't open '%s'.\n", fileName);
return (-1);
}

if (write_restore_file) {
strcpy(trial_restoreFileName, restoreFileName);
strcat(trial_restoreFileName, "B");
Expand All @@ -74,11 +80,11 @@ int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file,
}
/* check that (copy of) .sav file is good */
status = fseek(fp, -6, SEEK_END);
fgets(s, 6, fp);
if (fgets(s, 6, fp) == NULL) file_ok = 0;
if (strncmp(s, "<END>", 5) == 0) file_ok = 1;
if (!file_ok) {
status = fseek(fp, -7, SEEK_END);
fgets(s, 7, fp);
if (fgets(s, 7, fp) == NULL) file_ok = 0;
if (strncmp(s, "<END>", 5) == 0) file_ok = 1;
}
if (status || !file_ok) {
Expand Down Expand Up @@ -328,13 +334,13 @@ int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file,
/* No, we didn't. One more read will certainly accumulate a value string of length BUF_SIZE */
if (debug > 3) printf("did not reach end of line for long-string PV\n");
bp = fgets(s, BUF_SIZE, fp);
n = BUF_SIZE - strlen(value_string) - 1;
n = BUF_SIZE - (int)strlen(value_string) - 1;
strncat(value_string, bp, n);
if (value_string[strlen(value_string) - 1] == '\n')
value_string[strlen(value_string) - 1] = '\0';
}
/* Discard additional characters until end of line */
while (bp[strlen(bp) - 1] != '\n') fgets(s, BUF_SIZE, fp);
while (bp[strlen(bp) - 1] != '\n' && fgets(s, BUF_SIZE, fp) != NULL);

status = ca_array_get(DBR_CHAR, element_count, chid, (void *)svalue);
} else {
Expand Down Expand Up @@ -370,7 +376,7 @@ int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file,
if (different || (verbose > 0)) {
WRITE_HEADER;
if (is_scalar || is_long_string) {
nspace = 24 - strlen(value_string);
nspace = 24 - (int)strlen(value_string);
if (nspace < 1) nspace = 1;
printf("%s%-24s '%s'%*s'%s'\n", different ? "*** " : " ", PVname, value_string,
nspace, "", svalue);
Expand Down Expand Up @@ -455,7 +461,7 @@ static float safeDoubleToFloat(double d)
if (d > 0.0) f = FLT_MIN;
else f = -FLT_MIN;
} else {
f = d;
f = (float)d;
}
return (f);
}
Expand Down Expand Up @@ -536,7 +542,7 @@ long read_array(FILE *fp, char *PVname, char *value_string, short field_type, lo
* If there are more characters than we can handle, just pretend we read them.
*/
/* *bp == ELEMENT_END ,*/
if (debug > 1) printf("array_read: looking for element-end: '%s'\n", bp);
if (debug > 1) printf("array_read: looking for element-end: '%s'\n", bp ? bp : "(null)");
for (found = 0; (found == 0) && !end_of_file;) {
while (*bp && (*bp != ELEMENT_END) && (*bp != ESCAPE)) bp++;
switch (*bp) {
Expand Down Expand Up @@ -613,7 +619,7 @@ long read_array(FILE *fp, char *PVname, char *value_string, short field_type, lo
if ((bp = fgets(buffer, BUF_SIZE, fp)) == NULL) end_of_file = 1;
}
}
if (debug > 1) printf("array_read: positioned for next PV '%s'\n", bp);
if (debug > 1) printf("array_read: positioned for next PV '%s'\n", bp ? bp : "(null)");
if (!status && end_of_file) status = end_of_file;

return (status);
Expand Down
Loading