Skip to content

Commit cf3bf0a

Browse files
wilhelmyraboof
authored andcommitted
notionflux: reconnect if notion was restarted (fixes #157) (#159)
1 parent 0fd90a2 commit cf3bf0a

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

mod_notionflux/notionflux/notionflux.c

+17-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ bool unix_send_fds(int unix, int fd) {
109109
return true;
110110
}
111111

112+
bool notion_restarted(void)
113+
{
114+
char const *newsock = get_socket_filename();
115+
bool ret = strcmp(sockfilename, newsock) != 0;
116+
free((void*)sockfilename);
117+
sockfilename = newsock;
118+
return ret;
119+
}
120+
112121
FILE *sock_connect(void)
113122
{
114123
struct sockaddr_un serv;
@@ -118,8 +127,14 @@ FILE *sock_connect(void)
118127

119128
serv.sun_family = AF_UNIX;
120129
strcpy(serv.sun_path, sockfilename);
121-
if (connect(sock, (struct sockaddr*)&serv, sizeof(serv)) == -1)
122-
die("Failed to connect to socket %s\n", sockfilename);
130+
if (connect(sock, (struct sockaddr*)&serv, sizeof(serv)) == -1) {
131+
if (notion_restarted()) {
132+
fputs("Notion was restarted, connecting to new instance.\n", stderr);
133+
return sock_connect();
134+
} else {
135+
die("Failed to connect to socket %s\n", sockfilename);
136+
}
137+
}
123138

124139
if (!unix_send_fds(sock, STDOUT_FILENO)) /* used for lua's print() */
125140
die("Failed to send stdout to notion.\n");

0 commit comments

Comments
 (0)