mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-05-21 07:13:06 +02:00
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:
parent
bbe965126d
commit
489c42cb29
@ -21764,3 +21764,7 @@
|
|||||||
* Added 'RDCheckExitCode()' functions in 'lib/rdconf.[cpp|h].
|
* Added 'RDCheckExitCode()' functions in 'lib/rdconf.[cpp|h].
|
||||||
2021-06-01 Fred Gleason <fredg@paravelsystems.com>
|
2021-06-01 Fred Gleason <fredg@paravelsystems.com>
|
||||||
* Cleaned up compile warnings in 'lib/rdcdplayer.cpp'.
|
* 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'.
|
||||||
|
106
lib/rdconf.cpp
106
lib/rdconf.cpp
@ -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)
|
* 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)
|
QString RDGetPathPart(QString path)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
@ -408,7 +312,7 @@ QFont::Weight RDGetFontWeight(QString string)
|
|||||||
bool RDDetach(const QString &coredir)
|
bool RDDetach(const QString &coredir)
|
||||||
{
|
{
|
||||||
if(!coredir.isEmpty()) {
|
if(!coredir.isEmpty()) {
|
||||||
chdir(coredir.toUtf8());
|
RDCheckExitCode("RDDetach chdir",chdir(coredir.toUtf8()));
|
||||||
}
|
}
|
||||||
if(daemon(coredir.isEmpty(),0)) {
|
if(daemon(coredir.isEmpty(),0)) {
|
||||||
return false;
|
return false;
|
||||||
@ -803,9 +707,9 @@ bool RDCopy(int src_fd,int dest_fd)
|
|||||||
}
|
}
|
||||||
buf=(char *)malloc(dest_stat.st_blksize);
|
buf=(char *)malloc(dest_stat.st_blksize);
|
||||||
while((n=read(src_fd,buf,dest_stat.st_blksize))==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);
|
free(buf);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -827,7 +731,7 @@ bool RDWritePid(const QString &dirname,const QString &filename,int owner,
|
|||||||
}
|
}
|
||||||
fprintf(file,"%d",getpid());
|
fprintf(file,"%d",getpid());
|
||||||
fclose(file);
|
fclose(file);
|
||||||
chown(pathname.toUtf8(),owner,group);
|
RDCheckExitCode("RDWritePid chown",chown(pathname.toUtf8(),owner,group));
|
||||||
|
|
||||||
return true;
|
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]",
|
rda->syslog(LOG_WARNING,"%s returned non-zero exit code %d [%s]",
|
||||||
msg.toUtf8().constData(),exit_code,strerror(errno));
|
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]",
|
"%s returned non-zero exit code %d [%s]",
|
||||||
msg.toUtf8().constData(),exit_code,strerror(errno));
|
msg.toUtf8().constData(),exit_code,strerror(errno));
|
||||||
}
|
}
|
||||||
|
return exit_code;
|
||||||
}
|
}
|
||||||
|
@ -48,10 +48,7 @@ double GetPrivateProfileDouble(const char *,const char *,const char *,double);
|
|||||||
int GetIni(const char *,const char *,const char *,char *,int);
|
int GetIni(const char *,const char *,const char *,char *,int);
|
||||||
int GetIniLine(FILE *,char *);
|
int GetIniLine(FILE *,char *);
|
||||||
void Prepend(char *,char *);
|
void Prepend(char *,char *);
|
||||||
int IncrementIndex(char *,int);
|
|
||||||
void StripLevel(char *);
|
void StripLevel(char *);
|
||||||
bool GetLock(const char *);
|
|
||||||
void ClearLock(const char *);
|
|
||||||
QString RDGetPathPart(QString path);
|
QString RDGetPathPart(QString path);
|
||||||
QString RDGetBasePart(QString path);
|
QString RDGetBasePart(QString path);
|
||||||
QString RDGetShortDate(QDate);
|
QString RDGetShortDate(QDate);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user