forked from Telodendria/Telodendria
[FIX] Fix SEGV, notify syncers on exit
This commit is contained in:
parent
ebbca383cb
commit
6b39b3eb74
4 changed files with 35 additions and 11 deletions
|
@ -56,6 +56,7 @@
|
|||
|
||||
static Array *httpServers;
|
||||
static volatile int restart;
|
||||
static MatrixHttpHandlerArgs matrixArgs;
|
||||
|
||||
static void
|
||||
SignalHandler(int signal)
|
||||
|
@ -76,6 +77,7 @@ SignalHandler(int signal)
|
|||
return;
|
||||
}
|
||||
|
||||
UserNotifyAll(matrixArgs.db);
|
||||
for (i = 0; i < ArraySize(httpServers); i++)
|
||||
{
|
||||
HttpServer *server = ArrayGet(httpServers, i);
|
||||
|
@ -143,7 +145,6 @@ Main(Array * args)
|
|||
/* Signal handling */
|
||||
struct sigaction sigAction;
|
||||
|
||||
MatrixHttpHandlerArgs matrixArgs;
|
||||
Cron *cron;
|
||||
|
||||
char startDir[PATH_MAX];
|
||||
|
|
|
@ -323,7 +323,7 @@ RoomAddEventV1(Room *room, PduV1 pdu, PduV1Status status)
|
|||
|
||||
/* If we have a membership change, then add it to the
|
||||
* proper table. */
|
||||
if (RelationFromJson(relates_to, &rel, NULL))
|
||||
if (relates_to && RelationFromJson(relates_to, &rel, NULL))
|
||||
{
|
||||
DbRef *relate = DbLock(
|
||||
room->db,
|
||||
|
|
32
src/User.c
32
src/User.c
|
@ -1152,7 +1152,7 @@ UserAddJoin(User *user, char *roomId)
|
|||
data = DbJson(user->joinRef);
|
||||
|
||||
JsonValueFree(HashMapSet(data, roomId, JsonValueObject(HashMapCreate())));
|
||||
UserNotifyUser(user);
|
||||
UserNotifyUser(user->name);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1176,7 +1176,7 @@ UserRemoveJoin(User *user, char *roomId)
|
|||
data = DbJson(user->joinRef);
|
||||
|
||||
JsonValueFree(HashMapDelete(data, roomId));
|
||||
UserNotifyUser(user);
|
||||
UserNotifyUser(user->name);
|
||||
}
|
||||
Array *
|
||||
UserListJoins(User *user)
|
||||
|
@ -1285,7 +1285,7 @@ UserPushInviteSync(User *user, char *roomId)
|
|||
DbUnlock(user->db, syncRef);
|
||||
}
|
||||
DbListFree(entries);
|
||||
UserNotifyUser(user);
|
||||
UserNotifyUser(user->name);
|
||||
}
|
||||
void
|
||||
UserPushJoinSync(User *user, char *roomId)
|
||||
|
@ -1327,7 +1327,7 @@ UserPushJoinSync(User *user, char *roomId)
|
|||
DbUnlock(user->db, syncRef);
|
||||
}
|
||||
DbListFree(entries);
|
||||
UserNotifyUser(user);
|
||||
UserNotifyUser(user->name);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1368,7 +1368,7 @@ UserPushEvent(User *user, HashMap *event)
|
|||
}
|
||||
DbListFree(entries);
|
||||
|
||||
UserNotifyUser(user);
|
||||
UserNotifyUser(user->name);
|
||||
}
|
||||
void
|
||||
UserDropSync(User *user, char *batch)
|
||||
|
@ -1810,7 +1810,7 @@ UserInitialisePushTable(void)
|
|||
}
|
||||
|
||||
void
|
||||
UserNotifyUser(User *user)
|
||||
UserNotifyUser(char *user)
|
||||
{
|
||||
NotificationEntry *entry;
|
||||
Array *entries;
|
||||
|
@ -1820,7 +1820,7 @@ UserNotifyUser(User *user)
|
|||
return;
|
||||
}
|
||||
pthread_mutex_lock(&pushLock);
|
||||
entries = HashMapGet(pushTable, user->name);
|
||||
entries = HashMapGet(pushTable, user);
|
||||
size = ArraySize(entries);
|
||||
entry = ArrayGet(entries, 0);
|
||||
if (entry && entry->type == NOTIF_AWAIT)
|
||||
|
@ -1850,7 +1850,7 @@ UserNotifyUser(User *user)
|
|||
entry->type = NOTIF_GOTTEN;
|
||||
ArrayAdd(entries, entry);
|
||||
|
||||
HashMapSet(pushTable, user->name, entries);
|
||||
HashMapSet(pushTable, user, entries);
|
||||
pthread_mutex_unlock(&pushLock);
|
||||
return;
|
||||
}
|
||||
|
@ -1998,3 +1998,19 @@ UserAwaitNotification(char *user, int await)
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -476,7 +476,14 @@ extern void UserInitialisePushTable(void);
|
|||
/**
|
||||
* 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
|
||||
|
|
Loading…
Reference in a new issue