@@ -156,12 +156,12 @@ static void unlink_qrexec_socket(void)
156
156
char link_to_socket_name [strlen (remote_domain_name ) + sizeof (socket_address )];
157
157
158
158
int v = snprintf (socket_address , sizeof (socket_address ),
159
- "%s/ qrexec.%d" , socket_dir , remote_domain_id );
160
- if (v < (int )sizeof ("/ qrexec.1" ) || v >= (int )sizeof (socket_address ))
159
+ "qrexec.%d" , remote_domain_id );
160
+ if (v < (int )sizeof ("qrexec.1" ) - 1 || v >= (int )sizeof (socket_address ))
161
161
abort ();
162
162
v = snprintf (link_to_socket_name , sizeof (link_to_socket_name ),
163
- "%s/ qrexec.%s" , socket_dir , remote_domain_name );
164
- if (v < (int )sizeof ("/ qrexec." ) || v >= (int )sizeof (link_to_socket_name ))
163
+ "qrexec.%s" , remote_domain_name );
164
+ if (v < (int )sizeof ("qrexec." ) - 1 || v >= (int )sizeof (link_to_socket_name ))
165
165
abort ();
166
166
v = unlink (socket_address );
167
167
if (v != 0 && !(v == -1 && errno == ENOENT ))
@@ -185,20 +185,19 @@ static int create_qrexec_socket(int domid, const char *domname)
185
185
int res ;
186
186
187
187
if ((unsigned )snprintf (socket_address , sizeof (socket_address ),
188
- "%s/ qrexec.%d" , socket_dir , domid ) >= sizeof (socket_address ))
188
+ "qrexec.%d" , domid ) >= sizeof (socket_address ))
189
189
errx (1 , "socket name too long" );
190
190
if ((unsigned )snprintf (link_to_socket_name , sizeof link_to_socket_name ,
191
- "%s/ qrexec.%s" , socket_dir , domname ) >= sizeof link_to_socket_name )
191
+ "qrexec.%s" , domname ) >= sizeof link_to_socket_name )
192
192
errx (1 , "socket link name too long" );
193
193
res = unlink (link_to_socket_name );
194
194
if (res != 0 && !(res == -1 && errno == ENOENT ))
195
195
err (1 , "unlink(%s)" , link_to_socket_name );
196
- const char * symlink_target = socket_address + strlen (socket_dir ) + 1 ;
197
196
198
197
/* When running as root, make the socket accessible; perms on /var/run/qubes still apply */
199
198
umask (0 );
200
- if (symlink (symlink_target , link_to_socket_name )) {
201
- PERROR ("symlink(%s,%s)" , symlink_target , link_to_socket_name );
199
+ if (symlink (socket_address , link_to_socket_name )) {
200
+ PERROR ("symlink(%s,%s)" , socket_address , link_to_socket_name );
202
201
}
203
202
int fd = get_server_socket (socket_address );
204
203
umask (0077 );
@@ -339,9 +338,14 @@ static void init(int xid)
339
338
340
339
close (0 );
341
340
341
+ if (chdir (socket_dir ) < 0 ) {
342
+ PERROR ("chdir %s failed" , socket_dir );
343
+ exit (1 );
344
+ }
345
+
342
346
if (!opt_direct ) {
343
347
if ((unsigned )snprintf (qrexec_error_log_name , sizeof (qrexec_error_log_name ),
344
- "/var/log/qubes/ qrexec.%s.log" , remote_domain_name ) >=
348
+ "qrexec.%s.log" , remote_domain_name ) >=
345
349
sizeof (qrexec_error_log_name ))
346
350
errx (1 , "remote domain name too long" );
347
351
umask (0007 ); // make the log readable by the "qubes" group
@@ -357,10 +361,6 @@ static void init(int xid)
357
361
dup2 (logfd , 1 );
358
362
dup2 (logfd , 2 );
359
363
360
- if (chdir ("/var/run/qubes" ) < 0 ) {
361
- PERROR ("chdir /var/run/qubes failed" );
362
- exit (1 );
363
- }
364
364
if (setsid () < 0 ) {
365
365
PERROR ("setsid()" );
366
366
exit (1 );
0 commit comments