Lines 103-108
static struct option const long_options[
Link Here
|
103 |
}; |
103 |
}; |
104 |
#endif |
104 |
#endif |
105 |
|
105 |
|
|
|
106 |
static char finish_last_countfile_lock[]="/tmp/partimageXXXXXX.lock"; |
107 |
static char finish_last_countfile[]="/tmp/partimageXXXXXX"; |
106 |
static char optstring[]="z:oV:ecmdhf:s:p:bwg:vynSMa:iU:P:XB:"; |
108 |
static char optstring[]="z:oV:ecmdhf:s:p:bwg:vynSMa:iU:P:XB:"; |
107 |
FILE * g_fDebug; // debug file |
109 |
FILE * g_fDebug; // debug file |
108 |
FILE * g_fLocalDebug; // debug file |
110 |
FILE * g_fLocalDebug; // debug file |
Lines 760-788
int main(int argc, char *argv[])
Link Here
|
760 |
else if (options.dwFinish == FINISH_LAST) |
762 |
else if (options.dwFinish == FINISH_LAST) |
761 |
{ |
763 |
{ |
762 |
showDebug(1, "option FINISH_LAST\n"); |
764 |
showDebug(1, "option FINISH_LAST\n"); |
763 |
int nLockFile; |
765 |
int fd_lock, fd_countfile; |
764 |
FILE * nCountFile; |
766 |
FILE * nCountFile; |
|
|
767 |
FILE * nLockFile; |
765 |
char szValue[11]; |
768 |
char szValue[11]; |
766 |
int nValue, nRetries; |
769 |
int nValue, nRetries; |
767 |
ssize_t nRes; |
770 |
ssize_t nRes; |
768 |
|
771 |
|
769 |
nRetries = 5; |
772 |
nRetries = 5; |
770 |
do { |
773 |
do { |
771 |
nLockFile = open(FINISH_LAST_COUNTFILE_LOCK, O_CREAT|O_EXCL, |
774 |
if ((fd_lock = mkstemp(finish_last_countfile_lock)) == -1) |
772 |
O_RDONLY); |
775 |
{ |
773 |
if (nLockFile == -1) |
776 |
delete g_interface; |
|
|
777 |
fprintf(stderr, i18n("Error: Cannot create lock for countfile")); |
778 |
return EXIT_FAILURE; |
779 |
} |
780 |
nLockFile = fdopen(fd_lock, "r"); |
781 |
if (nLockFile == NULL) |
774 |
{ |
782 |
{ |
775 |
--nRetries; |
783 |
--nRetries; |
776 |
sleep(2); |
784 |
sleep(2); |
777 |
} |
785 |
} |
778 |
} while (nLockFile == -1 && nRetries); |
786 |
} while (nLockFile == NULL && nRetries); |
779 |
if (!nRetries) |
787 |
if (!nRetries) |
780 |
{ |
788 |
{ |
781 |
delete g_interface; |
789 |
delete g_interface; |
782 |
fprintf(stderr, i18n("Error: Cannot count remaining partimages")); |
790 |
fprintf(stderr, i18n("Error: Cannot count remaining partimages")); |
783 |
return EXIT_SUCCESS; |
791 |
return EXIT_SUCCESS; |
784 |
} |
792 |
} |
785 |
nCountFile = fopen(FINISH_LAST_COUNTFILE, "r"); |
793 |
if ((fd_countfile = mkstemp(finish_last_countfile)) == -1) |
|
|
794 |
{ |
795 |
delete g_interface; |
796 |
fprintf(stderr, i18n("Error: Cannot create countfile")); |
797 |
return EXIT_FAILURE; |
798 |
} |
799 |
nCountFile = fdopen(fd_countfile, "r"); |
786 |
if (nCountFile == NULL) |
800 |
if (nCountFile == NULL) |
787 |
{ |
801 |
{ |
788 |
delete g_interface; |
802 |
delete g_interface; |
Lines 795-803
int main(int argc, char *argv[])
Link Here
|
795 |
{ // we are the last running partimage -> shutdown |
809 |
{ // we are the last running partimage -> shutdown |
796 |
delete g_interface; |
810 |
delete g_interface; |
797 |
fclose(nCountFile); |
811 |
fclose(nCountFile); |
798 |
close(nLockFile); |
812 |
fclose(nLockFile); |
799 |
unlink(FINISH_LAST_COUNTFILE_LOCK); |
813 |
close(fd_lock); |
800 |
unlink(FINISH_LAST_COUNTFILE); |
814 |
close(fd_countfile); |
|
|
815 |
unlink(finish_last_countfile_lock); |
816 |
unlink(finish_last_countfile); |
801 |
// nRes = system("/sbin/shutdown -r now"); |
817 |
// nRes = system("/sbin/shutdown -r now"); |
802 |
// nRes = system("/sbin/reboot"); |
818 |
// nRes = system("/sbin/reboot"); |
803 |
// if we reach this point, it's because shutdown failed |
819 |
// if we reach this point, it's because shutdown failed |
Lines 808-814
int main(int argc, char *argv[])
Link Here
|
808 |
{ |
824 |
{ |
809 |
--nValue; |
825 |
--nValue; |
810 |
fclose(nCountFile); |
826 |
fclose(nCountFile); |
811 |
nCountFile = fopen(FINISH_LAST_COUNTFILE, "w"); |
827 |
nCountFile = fdopen(fd_countfile, "w"); |
812 |
if (nCountFile == NULL) |
828 |
if (nCountFile == NULL) |
813 |
{ |
829 |
{ |
814 |
delete g_interface; |
830 |
delete g_interface; |
Lines 818-825
int main(int argc, char *argv[])
Link Here
|
818 |
} |
834 |
} |
819 |
fprintf(nCountFile, "%d\n", nValue); |
835 |
fprintf(nCountFile, "%d\n", nValue); |
820 |
fclose(nCountFile); |
836 |
fclose(nCountFile); |
821 |
close(nLockFile); |
837 |
fclose(nLockFile); |
822 |
unlink(FINISH_LAST_COUNTFILE_LOCK); |
838 |
close(fd_lock); |
|
|
839 |
close(fd_countfile); |
840 |
unlink(finish_last_countfile_lock); |
823 |
delete g_interface; |
841 |
delete g_interface; |
824 |
return EXIT_SUCCESS; |
842 |
return EXIT_SUCCESS; |
825 |
} |
843 |
} |