From: krakjoe Date: Sat, 30 Nov 2013 14:34:16 +0000 (+0000) Subject: phpdbg_rlog for logging while in remote mode (only) X-Git-Tag: php-5.6.0alpha1~110^2~30^2~23 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=df0091c445aeabcab96d6238c54d7e8eb9fe2abb;p=php phpdbg_rlog for logging while in remote mode (only) --- diff --git a/phpdbg.c b/phpdbg.c index af3a1179ad..3ac0b09e88 100644 --- a/phpdbg.c +++ b/phpdbg.c @@ -600,8 +600,9 @@ int phpdbg_open_socket(const char *interface, short port) /* {{{ */ static inline void phpdbg_close_sockets(int (*socket)[2], FILE *streams[2]) /* {{{ */ { - if ((*socket)[0]) { - shutdown((*socket)[0], SHUT_RDWR); + if ((*socket)[0] >= 0) { + shutdown( + (*socket)[0], SHUT_RDWR); close((*socket)[0]); } @@ -609,8 +610,9 @@ static inline void phpdbg_close_sockets(int (*socket)[2], FILE *streams[2]) /* { fclose(streams[0]); } - if ((*socket)[1]) { - shutdown((*socket)[1], SHUT_RDWR); + if ((*socket)[1] >= 0) { + shutdown( + (*socket)[1], SHUT_RDWR); close((*socket)[1]); } @@ -633,13 +635,13 @@ int phpdbg_open_sockets(char *address, int port[2], int (*listen)[2], int (*sock if ((*listen)[0] < 0 || (*listen)[1] < 0) { if ((*listen)[0] < 0) { - fprintf(stderr, - "Failed to start remote console (stdin) on port %d\n", port[0]); + phpdbg_rlog(stderr, + "console failed to initialize (stdin) on %s:%d", address, port[0]); } if ((*listen)[1] < 0) { - fprintf(stderr, - "Failed to open remote console (stdout) on port %d\n", port[1]); + phpdbg_rlog(stderr, + "console failed to initialize (stdout) on %s:%d", address, port[1]); } if ((*listen)[0] >= 0) { @@ -655,8 +657,8 @@ int phpdbg_open_sockets(char *address, int port[2], int (*listen)[2], int (*sock phpdbg_close_sockets(socket, streams); - fprintf(stderr, - "Remote console accepting (stdin/stdout) on ports %d/%d\n", port[0], port[1]); + phpdbg_rlog(stderr, + "accepting connections on %s:%d/%d", address, port[0], port[1]); { struct sockaddr_in address; socklen_t size = sizeof(address); @@ -668,8 +670,7 @@ int phpdbg_open_sockets(char *address, int port[2], int (*listen)[2], int (*sock (*listen)[0], (struct sockaddr *) &address, &size); inet_ntop(AF_INET, &address.sin_addr, buffer, sizeof(buffer)); - fprintf(stderr, - "Remote console (stdin) connection from %s\n", buffer); + phpdbg_rlog(stderr, "connection (stdin) from %s", buffer); } { @@ -678,8 +679,7 @@ int phpdbg_open_sockets(char *address, int port[2], int (*listen)[2], int (*sock (*listen)[1], (struct sockaddr *) &address, &size); inet_ntop(AF_INET, &address.sin_addr, buffer, sizeof(buffer)); - fprintf(stderr, - "Remote console (stdout) connection from %s\n", buffer); + phpdbg_rlog(stderr, "connection (stdout) from %s", buffer); } } diff --git a/phpdbg_utils.c b/phpdbg_utils.c index 33ead6034c..5232f31747 100644 --- a/phpdbg_utils.c +++ b/phpdbg_utils.c @@ -242,6 +242,35 @@ PHPDBG_API int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, .. return rc; } /* }}} */ +PHPDBG_API int phpdbg_rlog(FILE *fp, const char *fmt, ...) { /* {{{ */ + int rc = 0; + + va_list args; + time_t now; + struct timeval tp; + + va_start(args, fmt); + if (gettimeofday(&tp, NULL) == SUCCESS) + { + char friendly[100]; + char *format = NULL, *buffer = NULL; + + strftime(friendly, 100, "%a %b %d %T.%%04d %Y", localtime(&tp.tv_sec)); + asprintf( + &buffer, friendly, tp.tv_usec/1000); + asprintf( + &format, "[%s]: %s\n", buffer, fmt); + rc = vfprintf( + fp, format, args); + + free(format); + free(buffer); + } + va_end(args); + + return rc; +} /* }}} */ + PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length TSRMLS_DC) /* {{{ */ { const phpdbg_color_t *color = colors; diff --git a/phpdbg_utils.h b/phpdbg_utils.h index eb44d7c8f8..e934467653 100644 --- a/phpdbg_utils.h +++ b/phpdbg_utils.h @@ -32,7 +32,7 @@ PHPDBG_API char *phpdbg_resolve_path(const char* TSRMLS_DC); PHPDBG_API char *phpdbg_trim(const char*, size_t, size_t*); /** - * Error/notice/formatting helper + * Error/notice/formatting helpers */ enum { P_ERROR = 1, @@ -48,6 +48,8 @@ PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUT PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4); #endif +PHPDBG_API int phpdbg_rlog(FILE *stream, const char *fmt, ...); + #define phpdbg_error(fmt, ...) phpdbg_print(P_ERROR TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__) #define phpdbg_notice(fmt, ...) phpdbg_print(P_NOTICE TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__) #define phpdbg_writeln(fmt, ...) phpdbg_print(P_WRITELN TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__) diff --git a/tutorials/java/dist/phpdbg-ui.jar b/tutorials/java/dist/phpdbg-ui.jar index b02e649c52..f1d9f9fddb 100644 Binary files a/tutorials/java/dist/phpdbg-ui.jar and b/tutorials/java/dist/phpdbg-ui.jar differ