Skip to content

Commit 5391d8b

Browse files
committed
Merged pull request #1049
* pr/1049: Reorder xdfree(name) and removing trailing whitespace Tweak comments to use /* .. */ style Reuse created \\.\pipe name Change log level for failing SetNamedPipeHandleState Store the control_socket_path internally without the platform specific prefix, but do report the full path to logs. Fix wrong usage of SetNamedPipeHandleState and log possible errors when switching between PIPE_WAIT and PIPE_NO_WAIT. Indicate logged values are hex not decimal. Fix wrong file handler for response write
2 parents eb6378f + 5eb3394 commit 5391d8b

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/base/ctrl_socket.c

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -309,20 +309,20 @@ static void xdebug_control_socket_handle(void)
309309
int bytes_read;
310310

311311
if (XG_BASE(control_socket_h) <= 0) {
312-
// no NP
312+
/* No Named Pipe */
313313
return;
314314
}
315315

316316
if (ConnectNamedPipe(XG_BASE(control_socket_h), NULL)) {
317-
// previous disconnect
317+
/* Previous disconnect */
318318
DisconnectNamedPipe(XG_BASE(control_socket_h));
319319
return;
320320
}
321321

322322
result = GetLastError();
323323

324324
if (result == ERROR_PIPE_LISTENING) {
325-
// no clients
325+
/* No clients */
326326
return;
327327
}
328328

@@ -332,10 +332,12 @@ static void xdebug_control_socket_handle(void)
332332
}
333333

334334
if (result == ERROR_PIPE_CONNECTED) {
335-
// got new client!
335+
/* Got new client */
336336
DWORD lpMode;
337-
lpMode = PIPE_TYPE_BYTE | PIPE_REJECT_REMOTE_CLIENTS;
338-
SetNamedPipeHandleState(XG_BASE(control_socket_h), &lpMode, NULL, NULL);
337+
lpMode = PIPE_TYPE_BYTE | PIPE_WAIT;
338+
if (!SetNamedPipeHandleState(XG_BASE(control_socket_h), &lpMode, NULL, NULL)) {
339+
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_ERR, "CTRL-RECV", "Can't set NP handle state to 0x%x: 0x%x", lpMode, GetLastError());
340+
}
339341

340342
memset(buffer, 0, sizeof(buffer));
341343
bytes_read = 0;
@@ -346,18 +348,20 @@ static void xdebug_control_socket_handle(void)
346348
&bytes_read,
347349
NULL
348350
)) {
349-
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "CTRL-RECV", "Can't receive from NP: %x", GetLastError());
351+
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "CTRL-RECV", "Can't receive from NP: 0x%x", GetLastError());
350352
} else {
351353
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_INFO, "CTRL-RECV", "Received: '%s'", buffer);
352-
handle_command(0, buffer);
354+
handle_command(XG_BASE(control_socket_h), buffer);
353355
FlushFileBuffers(XG_BASE(control_socket_h));
354356
}
355357

356-
lpMode = PIPE_TYPE_BYTE | PIPE_NOWAIT | PIPE_REJECT_REMOTE_CLIENTS;
357-
SetNamedPipeHandleState(XG_BASE(control_socket_h), &lpMode, NULL, NULL);
358+
lpMode = PIPE_TYPE_BYTE | PIPE_NOWAIT;
359+
if (!SetNamedPipeHandleState(XG_BASE(control_socket_h), &lpMode, NULL, NULL)) {
360+
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_ERR, "CTRL-RECV", "Can't (post)set NP handle state to 0x%x: 0x%x", lpMode, GetLastError());
361+
}
358362
}
359363

360-
// All other errors and completed reading should close the socket
364+
/* All other errors and completed reading should close the socket */
361365
DisconnectNamedPipe(XG_BASE(control_socket_h));
362366
}
363367
#endif
@@ -471,13 +475,16 @@ void xdebug_control_socket_teardown(void)
471475
#elif WIN32
472476
void xdebug_control_socket_setup(void)
473477
{
478+
char *name = NULL;
479+
474480
XG_BASE(control_socket_last_trigger) = xdebug_get_nanotime();
475481

476-
XG_BASE(control_socket_path) = xdebug_sprintf("\\\\.\\pipe\\xdebug-ctrl." ZEND_ULONG_FMT, xdebug_get_pid());
482+
XG_BASE(control_socket_path) = xdebug_sprintf("xdebug-ctrl." ZEND_ULONG_FMT, xdebug_get_pid());
483+
name = xdebug_sprintf("\\\\.\\pipe\\%s", XG_BASE(control_socket_path));
477484

478485
/* Part 1 – create Named Pipe */
479486
XG_BASE(control_socket_h) = CreateNamedPipeA(
480-
XG_BASE(control_socket_path),
487+
name,
481488
PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE,
482489
PIPE_TYPE_BYTE | PIPE_NOWAIT | PIPE_REJECT_REMOTE_CLIENTS,
483490
1,
@@ -489,13 +496,16 @@ void xdebug_control_socket_setup(void)
489496

490497
if (XG_BASE(control_socket_h) == INVALID_HANDLE_VALUE) {
491498
errno = WSAGetLastError();
492-
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "CTRL-SOCKET", "Can't create control Named Pipe (%x)", errno);
499+
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "CTRL-SOCKET", "Can't create control Named Pipe (0x%x)", errno);
493500
xdfree(XG_BASE(control_socket_path));
494501
XG_BASE(control_socket_path) = NULL;
502+
503+
xdfree(name);
495504
return;
496505
}
497506

498-
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_INFO, "CTRL-OK", "Control socket set up successfully: '%s'", XG_BASE(control_socket_path));
507+
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_INFO, "CTRL-OK", "Control socket set up successfully: '%s'", name);
508+
xdfree(name);
499509
}
500510

501511
void xdebug_control_socket_teardown(void)

tests/debugger/bug02261-002-win.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ echo file_get_contents( $xdebugLogFileName );
2424
?>
2525
--EXPECTF--
2626
<?xml version="1.0" encoding="iso-8859-1"?>
27-
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://bug01949.inc" language="PHP" xdebug:language_version="" protocol_version="1.0" appid="" xdebug:ctrl_socket="%sxdebug-ctrl.%s"><engine version=""><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2099 by Derick Rethans]]></copyright></init>
27+
<init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file://bug01949.inc" language="PHP" xdebug:language_version="" protocol_version="1.0" appid="" xdebug:ctrl_socket="xdebug-ctrl.%s"><engine version=""><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2099 by Derick Rethans]]></copyright></init>
2828

2929
-> detach -i 1
3030
<?xml version="1.0" encoding="iso-8859-1"?>

0 commit comments

Comments
 (0)