2021-06-01 Fred Gleason <fredg@paravelsystems.com>

* Removed 'IncrementIndex()', 'GetLock()' and 'ClearLock()' functions
	from 'lib/rdconf.[cpp|h]'.
	* Cleaned up compile warning in 'lib/rdconf.cpp'.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2021-06-01 11:15:35 -04:00
parent bbe965126d
commit 489c42cb29
3 changed files with 10 additions and 103 deletions

View File

@ -21764,3 +21764,7 @@
* Added 'RDCheckExitCode()' functions in 'lib/rdconf.[cpp|h].
2021-06-01 Fred Gleason <fredg@paravelsystems.com>
* Cleaned up compile warnings in 'lib/rdcdplayer.cpp'.
2021-06-01 Fred Gleason <fredg@paravelsystems.com>
* Removed 'IncrementIndex()', 'GetLock()' and 'ClearLock()' functions
from 'lib/rdconf.[cpp|h]'.
* Cleaned up compile warning in 'lib/rdconf.cpp'.

View File

@ -211,72 +211,6 @@ void Prepend(char *sPathname,char *sFilename)
}
int IncrementIndex(char *sPathname,int dMaxIndex)
{
int dLockname=-1;
FILE *hPathname;
int i;
char sLockname[256];
char sAccum[256];
int dIndex,dNewIndex;
/* Lock the index */
strcpy(sLockname,sPathname);
strcat(sLockname,".LCK");
i=0;
while(dLockname<0 && i<MAX_RETRIES) {
dLockname=open(sLockname,O_WRONLY|O_EXCL|O_CREAT,S_IRUSR|S_IWUSR);
i++;
}
if(dLockname<0) {
return -1;
}
sprintf(sAccum,"%d",getpid());
write(dLockname,sAccum,strlen(sAccum));
close(dLockname);
/* We've got the lock, so read the index */
hPathname=fopen(sPathname,"r");
if(hPathname==NULL) {
unlink(sLockname);
return -1;
}
if(fscanf(hPathname,"%d",&dIndex)!=1) {
fclose(hPathname);
unlink(sLockname);
return -1;
}
fclose(hPathname);
/* Update the index */
if((dIndex<dMaxIndex) || (dMaxIndex==0)) {
dNewIndex=dIndex+1;
}
else {
dNewIndex=1;
}
/* Write it back */
hPathname=fopen(sPathname,"w");
if(hPathname==NULL) {
unlink(sLockname);
return -1;
}
fprintf(hPathname,"%d",dNewIndex);
fclose(hPathname);
/* Release the lock */
unlink(sLockname);
/* Ensure a sane value to return and then exit */
if((dIndex>dMaxIndex)&&(dMaxIndex!=0)) {
dIndex=1;
}
return dIndex;
}
/*
* int StripLevel(char *sString)
*
@ -299,36 +233,6 @@ void StripLevel(char *sString)
}
bool GetLock(const char *sLockname)
{
int fd;
char sAccum[256];
if((fd=open(sLockname,O_WRONLY|O_EXCL|O_CREAT,S_IRUSR|S_IWUSR))<0) {
printf("failed!\n");
if(RDCheckPid(RDGetPathPart(sLockname),RDGetBasePart(sLockname))) {
return false;
}
ClearLock(sLockname);
if((fd=open(sLockname,O_WRONLY|O_EXCL|O_CREAT,S_IRUSR|S_IWUSR))<0) {
return false;
}
}
sprintf(sAccum,"%d",getpid());
write(fd,sAccum,strlen(sAccum));
close(fd);
return true;
}
void ClearLock(const char *sLockname)
{
unlink(sLockname);
}
QString RDGetPathPart(QString path)
{
int c;
@ -408,7 +312,7 @@ QFont::Weight RDGetFontWeight(QString string)
bool RDDetach(const QString &coredir)
{
if(!coredir.isEmpty()) {
chdir(coredir.toUtf8());
RDCheckExitCode("RDDetach chdir",chdir(coredir.toUtf8()));
}
if(daemon(coredir.isEmpty(),0)) {
return false;
@ -803,9 +707,9 @@ bool RDCopy(int src_fd,int dest_fd)
}
buf=(char *)malloc(dest_stat.st_blksize);
while((n=read(src_fd,buf,dest_stat.st_blksize))==dest_stat.st_blksize) {
write(dest_fd,buf,dest_stat.st_blksize);
RDCheckExitCode("RDCopy write",write(dest_fd,buf,dest_stat.st_blksize));
}
write(dest_fd,buf,n);
RDCheckExitCode("RDCopy write",write(dest_fd,buf,n));
free(buf);
return true;
@ -827,7 +731,7 @@ bool RDWritePid(const QString &dirname,const QString &filename,int owner,
}
fprintf(file,"%d",getpid());
fclose(file);
chown(pathname.toUtf8(),owner,group);
RDCheckExitCode("RDWritePid chown",chown(pathname.toUtf8(),owner,group));
return true;
}
@ -1195,6 +1099,7 @@ int RDCheckExitCode(const QString &msg,int exit_code)
rda->syslog(LOG_WARNING,"%s returned non-zero exit code %d [%s]",
msg.toUtf8().constData(),exit_code,strerror(errno));
}
return exit_code;
}
@ -1205,4 +1110,5 @@ int RDCheckExitCode(RDConfig *config,const QString &msg,int exit_code)
"%s returned non-zero exit code %d [%s]",
msg.toUtf8().constData(),exit_code,strerror(errno));
}
return exit_code;
}

View File

@ -48,10 +48,7 @@ double GetPrivateProfileDouble(const char *,const char *,const char *,double);
int GetIni(const char *,const char *,const char *,char *,int);
int GetIniLine(FILE *,char *);
void Prepend(char *,char *);
int IncrementIndex(char *,int);
void StripLevel(char *);
bool GetLock(const char *);
void ClearLock(const char *);
QString RDGetPathPart(QString path);
QString RDGetBasePart(QString path);
QString RDGetShortDate(QDate);