diff -Nurp old/main.cpp new/main.cpp --- old/main.cpp 2007-03-26 20:35:21.000000000 +0200 +++ new/main.cpp 2007-04-05 20:18:51.000000000 +0200 @@ -103,6 +103,8 @@ static struct option const long_options[ }; #endif +static char finish_last_countfile_lock[]="/tmp/partimageXXXXXX.lock"; +static char finish_last_countfile[]="/tmp/partimageXXXXXX"; static char optstring[]="z:oV:ecmdhf:s:p:bwg:vynSMa:iU:P:XB:"; FILE * g_fDebug; // debug file FILE * g_fLocalDebug; // debug file @@ -760,29 +762,41 @@ int main(int argc, char *argv[]) else if (options.dwFinish == FINISH_LAST) { showDebug(1, "option FINISH_LAST\n"); - int nLockFile; + int fd_lock, fd_countfile; FILE * nCountFile; + FILE * nLockFile; char szValue[11]; int nValue, nRetries; ssize_t nRes; nRetries = 5; do { - nLockFile = open(FINISH_LAST_COUNTFILE_LOCK, O_CREAT|O_EXCL, - O_RDONLY); - if (nLockFile == -1) + if ((fd_lock = mkstemp(finish_last_countfile_lock)) == -1) + { + delete g_interface; + fprintf(stderr, i18n("Error: Cannot create lock for countfile")); + return EXIT_FAILURE; + } + nLockFile = fdopen(fd_lock, "r"); + if (nLockFile == NULL) { --nRetries; sleep(2); } - } while (nLockFile == -1 && nRetries); + } while (nLockFile == NULL && nRetries); if (!nRetries) { - delete g_interface; + delete g_interface; fprintf(stderr, i18n("Error: Cannot count remaining partimages")); return EXIT_SUCCESS; } - nCountFile = fopen(FINISH_LAST_COUNTFILE, "r"); + if ((fd_countfile = mkstemp(finish_last_countfile)) == -1) + { + delete g_interface; + fprintf(stderr, i18n("Error: Cannot create countfile")); + return EXIT_FAILURE; + } + nCountFile = fdopen(fd_countfile, "r"); if (nCountFile == NULL) { delete g_interface; @@ -795,9 +809,11 @@ int main(int argc, char *argv[]) { // we are the last running partimage -> shutdown delete g_interface; fclose(nCountFile); - close(nLockFile); - unlink(FINISH_LAST_COUNTFILE_LOCK); - unlink(FINISH_LAST_COUNTFILE); + fclose(nLockFile); + close(fd_lock); + close(fd_countfile); + unlink(finish_last_countfile_lock); + unlink(finish_last_countfile); // nRes = system("/sbin/shutdown -r now"); // nRes = system("/sbin/reboot"); // if we reach this point, it's because shutdown failed @@ -808,7 +824,7 @@ int main(int argc, char *argv[]) { --nValue; fclose(nCountFile); - nCountFile = fopen(FINISH_LAST_COUNTFILE, "w"); + nCountFile = fdopen(fd_countfile, "w"); if (nCountFile == NULL) { delete g_interface; @@ -818,8 +834,10 @@ int main(int argc, char *argv[]) } fprintf(nCountFile, "%d\n", nValue); fclose(nCountFile); - close(nLockFile); - unlink(FINISH_LAST_COUNTFILE_LOCK); + fclose(nLockFile); + close(fd_lock); + close(fd_countfile); + unlink(finish_last_countfile_lock); delete g_interface; return EXIT_SUCCESS; } diff -Nurp old/partimage.h new/partimage.h --- old/partimage.h 2007-03-26 20:35:21.000000000 +0200 +++ new/partimage.h 2007-03-26 20:37:45.000000000 +0200 @@ -152,9 +152,6 @@ extern bool g_bSigKill; #define FINISH_QUIT 3 #define FINISH_LAST 4 -#define FINISH_LAST_COUNTFILE "/tmp/partimage.count" -#define FINISH_LAST_COUNTFILE_LOCK "/tmp/partimage.count.lock" - // ===================== MAGIC STRINGS ============================ #define MAGIC_BEGIN_LOCALHEADER "MAGIC-BEGIN-LOCALHEADER" #define MAGIC_BEGIN_DATABLOCKS "MAGIC-BEGIN-DATABLOCKS"