summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--data.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/data.c b/data.c
index 1533305..5c72184 100644
--- a/data.c
+++ b/data.c
@@ -112,6 +112,9 @@ int srv_open(const char *basedir, int auto_upgrade)
112 xs *tmpdir = xs_fmt("%s/tmp", srv_basedir); 112 xs *tmpdir = xs_fmt("%s/tmp", srv_basedir);
113 mkdirx(tmpdir); 113 mkdirx(tmpdir);
114 114
115 xs *faildir = xs_fmt("%s/failure", srv_basedir);
116 mkdirx(faildir);
117
115#ifdef __APPLE__ 118#ifdef __APPLE__
116/* Apple uses st_atimespec instead of st_atim etc */ 119/* Apple uses st_atimespec instead of st_atim etc */
117#define st_atim st_atimespec 120#define st_atim st_atimespec
@@ -3039,6 +3042,56 @@ xs_list *content_search(snac *user, const char *regex,
3039} 3042}
3040 3043
3041 3044
3045int instance_failure(const char *url, int op)
3046/* do some checks and accounting on instance failures */
3047{
3048 int ret = 0;
3049 xs *l = xs_split(url, "/");
3050 const char *hostname = xs_list_get(l, 2);
3051 double mt;
3052
3053 if (!xs_is_string(hostname))
3054 return 0;
3055
3056 xs *md5 = xs_md5_hex(hostname, strlen(hostname));
3057 xs *fn = xs_fmt("%s/%s", srv_basedir, md5);
3058
3059 switch (op) {
3060 case 0: /** check **/
3061 if ((mt = mtime(fn)) != 0.0) {
3062 /* grace time */
3063 double seconds_failing = 30 * (24 * 60 * 60);
3064
3065 if ((double)time(NULL) - mt > seconds_failing)
3066 ret = -1;
3067 }
3068
3069 break;
3070
3071 case 1: /** register a failure **/
3072 if (mtime(fn) == 0.0) {
3073 FILE *f;
3074
3075 /* only create once, as the date will be used */
3076 if ((f = fopen(fn, "w")) != NULL) {
3077 fprintf(f, "%s\n", hostname);
3078 fclose(f);
3079 }
3080 }
3081
3082 break;
3083
3084 case 2: /** clear a failure **/
3085 /* called whenever a message comes from this instance */
3086 unlink(fn);
3087
3088 break;
3089 }
3090
3091 return ret;
3092}
3093
3094
3042/** notifications **/ 3095/** notifications **/
3043 3096
3044xs_str *notify_check_time(snac *snac, int reset) 3097xs_str *notify_check_time(snac *snac, int reset)