File tree 1 file changed +17
-2
lines changed
mod_notionflux/notionflux
1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,15 @@ bool unix_send_fds(int unix, int fd) {
109
109
return true;
110
110
}
111
111
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
+
112
121
FILE * sock_connect (void )
113
122
{
114
123
struct sockaddr_un serv ;
@@ -118,8 +127,14 @@ FILE *sock_connect(void)
118
127
119
128
serv .sun_family = AF_UNIX ;
120
129
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
+ }
123
138
124
139
if (!unix_send_fds (sock , STDOUT_FILENO )) /* used for lua's print() */
125
140
die ("Failed to send stdout to notion.\n" );
You can’t perform that action at this time.
0 commit comments