Commit 6c6025fd authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

add lock to userlog

parent 62846b89
......@@ -533,8 +533,10 @@ void *Gradsdes(void *argument)
gdp = fopen(ctlfile, "w");
if ( gdp == NULL ) cdoAbort("Open failed on %s", ctlfile);
#if defined (VERSION)
fprintf(gdp, "* Generated automatically by CDO version %s\n", VERSION);
fprintf(gdp, "*\n");
#endif
/* DSET */
......
......@@ -224,8 +224,10 @@ void *Outputgmt(void *argument)
decode_date(vdate, &year, &month, &day);
decode_time(vtime, &hour, &minute);
#if defined (VERSION)
fprintf(stdout, "# Generated by CDO version %s\n", VERSION);
fprintf(stdout, "#\n");
#endif
fprintf(stdout, "# Operator = %s\n", cdoOperatorName(operatorID));
if ( operatorID == OUTPUTVECTOR )
fprintf(stdout, "# Increment = %d\n", ninc);
......
......@@ -36,6 +36,8 @@ void userlog(const char *prompt, double cputime)
int len, slen, olen, pos;
int loper;
char logstring[MAX_LEN];
int status;
struct flock mylock;
memset(logstring, 0, MAX_LEN);
......@@ -90,8 +92,19 @@ void userlog(const char *prompt, double cputime)
return;
}
fcntl(logfileno, F_WRLCK);
write(logfileno, logstring, slen);
mylock.l_type = F_WRLCK;
mylock.l_whence = SEEK_SET;
mylock.l_start = 0;
mylock.l_len = 0;
status = fcntl(logfileno, F_SETLKW, &mylock);
if ( status == 0 )
{
write(logfileno, logstring, slen);
mylock.l_type = F_UNLCK;
status = fcntl(logfileno, F_SETLKW, &mylock);
}
close(logfileno);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment