Renamed to NickelMenu
This commit is contained in:
@@ -10,49 +10,49 @@
|
||||
#include "failsafe.h"
|
||||
#include "util.h"
|
||||
|
||||
struct nmi_failsafe_t {
|
||||
struct nm_failsafe_t {
|
||||
char *orig;
|
||||
char *tmp;
|
||||
int delay;
|
||||
};
|
||||
|
||||
nmi_failsafe_t *nmi_failsafe_create(char **err_out) {
|
||||
#define NMI_ERR_RET NULL
|
||||
nm_failsafe_t *nm_failsafe_create(char **err_out) {
|
||||
#define NM_ERR_RET NULL
|
||||
|
||||
NMI_LOG("failsafe: allocating memory");
|
||||
nmi_failsafe_t *fs;
|
||||
NMI_ASSERT((fs = calloc(1, sizeof(nmi_failsafe_t))), "could not allocate memory");
|
||||
NM_LOG("failsafe: allocating memory");
|
||||
nm_failsafe_t *fs;
|
||||
NM_ASSERT((fs = calloc(1, sizeof(nm_failsafe_t))), "could not allocate memory");
|
||||
|
||||
NMI_LOG("failsafe: finding filenames");
|
||||
NM_LOG("failsafe: finding filenames");
|
||||
Dl_info info;
|
||||
NMI_ASSERT(dladdr(nmi_failsafe_create, &info), "could not find own path");
|
||||
NMI_ASSERT(info.dli_fname, "dladdr did not return a filename");
|
||||
NM_ASSERT(dladdr(nm_failsafe_create, &info), "could not find own path");
|
||||
NM_ASSERT(info.dli_fname, "dladdr did not return a filename");
|
||||
char *d = strrchr(info.dli_fname, '.');
|
||||
NMI_ASSERT(!(d && !strcmp(d, ".failsafe")), "lib was loaded from the failsafe for some reason");
|
||||
NMI_ASSERT((fs->orig = realpath(info.dli_fname, NULL)), "could not resolve %s", info.dli_fname);
|
||||
NMI_ASSERT(asprintf(&fs->tmp, "%s.failsafe", fs->orig) != -1, "could not generate temp filename");
|
||||
NM_ASSERT(!(d && !strcmp(d, ".failsafe")), "lib was loaded from the failsafe for some reason");
|
||||
NM_ASSERT((fs->orig = realpath(info.dli_fname, NULL)), "could not resolve %s", info.dli_fname);
|
||||
NM_ASSERT(asprintf(&fs->tmp, "%s.failsafe", fs->orig) != -1, "could not generate temp filename");
|
||||
|
||||
NMI_LOG("failsafe: ensuring own lib remains in memory even if it is dlclosed after being loaded with a dlopen");
|
||||
NMI_ASSERT(dlopen(fs->orig, RTLD_LAZY|RTLD_NODELETE), "could not dlopen self");
|
||||
NM_LOG("failsafe: ensuring own lib remains in memory even if it is dlclosed after being loaded with a dlopen");
|
||||
NM_ASSERT(dlopen(fs->orig, RTLD_LAZY|RTLD_NODELETE), "could not dlopen self");
|
||||
|
||||
NMI_LOG("failsafe: renaming %s to %s", fs->orig, fs->tmp);
|
||||
NMI_ASSERT(!rename(fs->orig, fs->tmp), "could not rename lib");
|
||||
NM_LOG("failsafe: renaming %s to %s", fs->orig, fs->tmp);
|
||||
NM_ASSERT(!rename(fs->orig, fs->tmp), "could not rename lib");
|
||||
|
||||
NMI_RETURN_OK(fs);
|
||||
#undef NMI_ERR_RET
|
||||
NM_RETURN_OK(fs);
|
||||
#undef NM_ERR_RET
|
||||
}
|
||||
|
||||
static void *_nmi_failsafe_destroy(void* _fs) {
|
||||
nmi_failsafe_t *fs = (nmi_failsafe_t*)(_fs);
|
||||
static void *_nm_failsafe_destroy(void* _fs) {
|
||||
nm_failsafe_t *fs = (nm_failsafe_t*)(_fs);
|
||||
|
||||
NMI_LOG("failsafe: restoring after %d seconds", fs->delay);
|
||||
NM_LOG("failsafe: restoring after %d seconds", fs->delay);
|
||||
sleep(fs->delay);
|
||||
|
||||
NMI_LOG("failsafe: renaming %s to %s", fs->tmp, fs->orig);
|
||||
NM_LOG("failsafe: renaming %s to %s", fs->tmp, fs->orig);
|
||||
if (rename(fs->tmp, fs->orig))
|
||||
NMI_LOG("error: could not rename lib");
|
||||
NM_LOG("error: could not rename lib");
|
||||
|
||||
NMI_LOG("failsafe: freeing memory");
|
||||
NM_LOG("failsafe: freeing memory");
|
||||
free(fs->orig);
|
||||
free(fs->tmp);
|
||||
free(fs);
|
||||
@@ -60,15 +60,15 @@ static void *_nmi_failsafe_destroy(void* _fs) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void nmi_failsafe_destroy(nmi_failsafe_t *fs, int delay) {
|
||||
void nm_failsafe_destroy(nm_failsafe_t *fs, int delay) {
|
||||
fs->delay = delay;
|
||||
|
||||
NMI_LOG("failsafe: scheduling restore");
|
||||
NM_LOG("failsafe: scheduling restore");
|
||||
pthread_t t;
|
||||
pthread_create(&t, NULL, _nmi_failsafe_destroy, fs);
|
||||
pthread_create(&t, NULL, _nm_failsafe_destroy, fs);
|
||||
}
|
||||
|
||||
void nmi_failsafe_uninstall(nmi_failsafe_t *fs) {
|
||||
NMI_LOG("failsafe: deleting %s", fs->tmp);
|
||||
void nm_failsafe_uninstall(nm_failsafe_t *fs) {
|
||||
NM_LOG("failsafe: deleting %s", fs->tmp);
|
||||
unlink(fs->tmp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user