[FIX] Fix SEGV, notify syncers on exit

This commit is contained in:
LDA 2024-11-09 17:56:42 +01:00
parent ebbca383cb
commit 6b39b3eb74
4 changed files with 35 additions and 11 deletions

View file

@ -56,6 +56,7 @@
static Array *httpServers; static Array *httpServers;
static volatile int restart; static volatile int restart;
static MatrixHttpHandlerArgs matrixArgs;
static void static void
SignalHandler(int signal) SignalHandler(int signal)
@ -76,6 +77,7 @@ SignalHandler(int signal)
return; return;
} }
UserNotifyAll(matrixArgs.db);
for (i = 0; i < ArraySize(httpServers); i++) for (i = 0; i < ArraySize(httpServers); i++)
{ {
HttpServer *server = ArrayGet(httpServers, i); HttpServer *server = ArrayGet(httpServers, i);
@ -143,7 +145,6 @@ Main(Array * args)
/* Signal handling */ /* Signal handling */
struct sigaction sigAction; struct sigaction sigAction;
MatrixHttpHandlerArgs matrixArgs;
Cron *cron; Cron *cron;
char startDir[PATH_MAX]; char startDir[PATH_MAX];

View file

@ -323,7 +323,7 @@ RoomAddEventV1(Room *room, PduV1 pdu, PduV1Status status)
/* If we have a membership change, then add it to the /* If we have a membership change, then add it to the
* proper table. */ * proper table. */
if (RelationFromJson(relates_to, &rel, NULL)) if (relates_to && RelationFromJson(relates_to, &rel, NULL))
{ {
DbRef *relate = DbLock( DbRef *relate = DbLock(
room->db, room->db,

View file

@ -1152,7 +1152,7 @@ UserAddJoin(User *user, char *roomId)
data = DbJson(user->joinRef); data = DbJson(user->joinRef);
JsonValueFree(HashMapSet(data, roomId, JsonValueObject(HashMapCreate()))); JsonValueFree(HashMapSet(data, roomId, JsonValueObject(HashMapCreate())));
UserNotifyUser(user); UserNotifyUser(user->name);
} }
void void
@ -1176,7 +1176,7 @@ UserRemoveJoin(User *user, char *roomId)
data = DbJson(user->joinRef); data = DbJson(user->joinRef);
JsonValueFree(HashMapDelete(data, roomId)); JsonValueFree(HashMapDelete(data, roomId));
UserNotifyUser(user); UserNotifyUser(user->name);
} }
Array * Array *
UserListJoins(User *user) UserListJoins(User *user)
@ -1285,7 +1285,7 @@ UserPushInviteSync(User *user, char *roomId)
DbUnlock(user->db, syncRef); DbUnlock(user->db, syncRef);
} }
DbListFree(entries); DbListFree(entries);
UserNotifyUser(user); UserNotifyUser(user->name);
} }
void void
UserPushJoinSync(User *user, char *roomId) UserPushJoinSync(User *user, char *roomId)
@ -1327,7 +1327,7 @@ UserPushJoinSync(User *user, char *roomId)
DbUnlock(user->db, syncRef); DbUnlock(user->db, syncRef);
} }
DbListFree(entries); DbListFree(entries);
UserNotifyUser(user); UserNotifyUser(user->name);
} }
void void
@ -1368,7 +1368,7 @@ UserPushEvent(User *user, HashMap *event)
} }
DbListFree(entries); DbListFree(entries);
UserNotifyUser(user); UserNotifyUser(user->name);
} }
void void
UserDropSync(User *user, char *batch) UserDropSync(User *user, char *batch)
@ -1810,7 +1810,7 @@ UserInitialisePushTable(void)
} }
void void
UserNotifyUser(User *user) UserNotifyUser(char *user)
{ {
NotificationEntry *entry; NotificationEntry *entry;
Array *entries; Array *entries;
@ -1820,7 +1820,7 @@ UserNotifyUser(User *user)
return; return;
} }
pthread_mutex_lock(&pushLock); pthread_mutex_lock(&pushLock);
entries = HashMapGet(pushTable, user->name); entries = HashMapGet(pushTable, user);
size = ArraySize(entries); size = ArraySize(entries);
entry = ArrayGet(entries, 0); entry = ArrayGet(entries, 0);
if (entry && entry->type == NOTIF_AWAIT) if (entry && entry->type == NOTIF_AWAIT)
@ -1850,7 +1850,7 @@ UserNotifyUser(User *user)
entry->type = NOTIF_GOTTEN; entry->type = NOTIF_GOTTEN;
ArrayAdd(entries, entry); ArrayAdd(entries, entry);
HashMapSet(pushTable, user->name, entries); HashMapSet(pushTable, user, entries);
pthread_mutex_unlock(&pushLock); pthread_mutex_unlock(&pushLock);
return; return;
} }
@ -1998,3 +1998,19 @@ UserAwaitNotification(char *user, int await)
return notified; return notified;
} }
void
UserNotifyAll(Db *db)
{
Array *list;
size_t i, len;
if (!db)
{
return;
}
list = DbList(db, 1, "users");
for (i = 0, len = ArraySize(list); i < len; i++)
{
UserNotifyUser(ArrayGet(list, i));
}
DbListFree(list);
}

View file

@ -476,7 +476,14 @@ extern void UserInitialisePushTable(void);
/** /**
* Notifies the user of a sync update. * Notifies the user of a sync update.
*/ */
extern void UserNotifyUser(User *); extern void UserNotifyUser(char *);
/**
* Notifies *all* users of a sync update. This is meant to be used
* in cases where Telodendria needs to gracefully close any longrunning
* /sync requests.
*/
extern void UserNotifyAll(Db *);
/** /**
* Waits for a notification for a specific user for a specific * Waits for a notification for a specific user for a specific