-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
hi to all. yes, my hd ran out of space and i loose my users.conf. as CICQDaemon::SaveUserList don't use the CIniFile to save the users.conf the user.conf was opened directly for writing damaging the file in this case. i rewrote the function using a temporary file, using system calls. Cheers, Juan. -----BEGIN PGP SIGNATURE----- iD8DBQE9jQ5KUMlRieHkprgRAuVtAJ4oZrCuTAbNXVfbEvN9LNWqKVKQTwCeNL+t 7wNTDj7PZNyOrOD1BBNpLf4= =DZNz -----END PGP SIGNATURE-----
Index: src/icqd.cpp =================================================================== RCS file: /cvsroot/licq/licq/src/icqd.cpp,v retrieving revision 1.51 diff -u -d -p -r1.51 icqd.cpp --- src/icqd.cpp 16 Sep 2002 23:24:03 -0000 1.51 +++ src/icqd.cpp 22 Sep 2002 00:14:51 -0000 @@ -761,21 +761,54 @@ unsigned short VersionToUse(unsigned sho //-----SaveUserList------------------------------------------------------------- void CICQDaemon::SaveUserList() { - char filename[MAX_FILENAME_LEN]; - snprintf(filename, MAX_FILENAME_LEN, "%s/users.conf", BASE_DIR); - FILE *usersConf = fopen(filename, "w"); + static const char suffix[] = ".new"; + static const char file[] = "users.conf"; + + size_t len = strlen(BASE_DIR) + sizeof(file) + sizeof(suffix) + 2; + char tmpname[len], filename[len], buff[128]; + int nRet,n,fd; - fprintf(usersConf, "[users]\nNumOfUsers = %d\n", gUserManager.NumUsers()); + snprintf(filename, len, "%s/%s", BASE_DIR,file); + strcpy(tmpname,filename); + strcat(tmpname,suffix); - unsigned short i = 1; - FOR_EACH_UIN_START - { - fprintf(usersConf, "User%d = %ld\n", i, nUin); - i++; - } - FOR_EACH_UIN_END + fd = open(tmpname, O_WRONLY | O_CREAT | O_TRUNC, 00664); + if( fd == -1 ) + { /* avoid popup a msgbox if we are shutting down + * (there is a race in qt-gui ) + */ + if( !m_bShuttingDown ) + gLog.Error("%s Failed updating %s: `%s'",L_ERRORxSTR, + filename,strerror(errno)); + return; + } - fclose(usersConf); + n = sprintf(buff,"[users]\nNumOfUsers = %d\n", gUserManager.NumUsers()); + nRet = write(fd, buff, n); + + unsigned short i = 1; + + FOR_EACH_UIN_START + { + n = sprintf(buff, "User%d = %ld\n", i, nUin); + nRet = write(fd,buff,n); + if( nRet == -1 ) + FOR_EACH_UIN_BREAK + + i++; + } + FOR_EACH_UIN_END + + close(fd); + + if( nRet != -1 ) + { + if( rename(tmpname,filename)) + unlink(tmpname); + } + else if( !m_bShuttingDown ) + gLog.Error("%s Failed updating %s: `%s'",L_WARNxSTR, + filename,strerror(errno)); } void CICQDaemon::SetIgnore(unsigned short n, bool b)