Skip to content

Commit d418c9c

Browse files
committed
Fix an old bug with pollpip outputting nulls. Don't output carriage returns if
outputting to a file. Arrange that FPRINTF will pre4pend a newline if following pollpip output. Add logging for turning on SIGIO and for setsockopt via the primitive.
1 parent 9b4d957 commit d418c9c

File tree

3 files changed

+46
-32
lines changed

3 files changed

+46
-32
lines changed

platforms/unix/plugins/SocketPlugin/sqUnixSocket.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,21 @@ typedef struct privateSocketStruct
180180
int acceptedSock; /* a connection that has been accepted */
181181
} privateSocketStruct;
182182

183-
#define CONN_NOTIFY (1<<0)
184-
#define READ_NOTIFY (1<<1)
183+
#define CONN_NOTIFY (1<<0)
184+
#define READ_NOTIFY (1<<1)
185185
#define WRITE_NOTIFY (1<<2)
186186

187-
#define PING(S,EVT) \
188-
{ \
189-
FPRINTF((stderr, "notify %d %s\n", (S)->s, #EVT)); \
187+
#define PING(S,EVT) \
188+
{ \
189+
FPRINTF((stderr, "notify %d %s\n", (S)->s, #EVT)); \
190190
interpreterProxy->signalSemaphoreWithIndex((S)->EVT##Sema); \
191191
}
192192

193193
#define notify(SOCK,MASK) \
194-
{ \
195-
if ((MASK) & CONN_NOTIFY) PING(SOCK,conn); \
196-
if ((MASK) & READ_NOTIFY) PING(SOCK,read); \
197-
if ((MASK) & WRITE_NOTIFY) PING(SOCK,write); \
194+
{ \
195+
if ((MASK) & CONN_NOTIFY) PING(SOCK,conn); \
196+
if ((MASK) & READ_NOTIFY) PING(SOCK,read); \
197+
if ((MASK) & WRITE_NOTIFY) PING(SOCK,write); \
198198
}
199199

200200

@@ -203,7 +203,7 @@ typedef struct privateSocketStruct
203203
#define _PSP(S) (((S)->privateSocketPtr))
204204
#define PSP(S) ((privateSocketStruct *)((S)->privateSocketPtr))
205205

206-
#define SOCKET(S) (PSP(S)->s)
206+
#define SOCKET(S) (PSP(S)->s)
207207
#define SOCKETSTATE(S) (PSP(S)->sockState)
208208
#define SOCKETERROR(S) (PSP(S)->sockError)
209209
#define SOCKETPEER(S) (PSP(S)->peer)
@@ -1419,9 +1419,11 @@ sqSocketSetOptionsoptionNameStartoptionNameSizeoptionValueStartoptionValueSizere
14191419
endptr - buf == optionValueSize)) /* are all option chars digits? */
14201420
{
14211421
val= strtol(buf, &endptr, 0);
1422-
memcpy((void *)buf, (void *)&val, sizeof(val));
1423-
optionValueSize= sizeof(val);
1422+
memcpy((void *)buf, (void *)&val, sizeof(val));
1423+
optionValueSize= sizeof(val);
14241424
}
1425+
FPRINTF((stderr,"setsockopt(%d,%.*s)\n",
1426+
SOCKET(s), optionNameSize, optionName));
14251427
if ((setsockopt(PSP(s)->s, opt->optlevel, opt->optname,
14261428
(const void *)buf, optionValueSize)) < 0)
14271429
{

platforms/unix/vm/aio.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ static stack_t signal_stack;
187187

188188
/* initialise asynchronous i/o */
189189

190+
static int stderrIsAFile = 0; // for pollpip to avoid cluttering logs
191+
190192
void
191193
aioInit(void)
192194
{
@@ -199,6 +201,8 @@ aioInit(void)
199201
FD_ZERO(&xdMask);
200202
maxFd = 0;
201203

204+
stderrIsAFile = !isatty(fileno(stderr));
205+
202206
signal(SIGPIPE, SIG_IGN);
203207
#if !USE_SIGALTSTACK
204208
signal(SIGIO, forceInterruptCheck);
@@ -275,12 +279,14 @@ extern long disownCount;
275279
static char *ticks = "-\\|/";
276280
static char *ticker = "";
277281
static int tickCount = 0;
282+
long pollpipOutput = 0;
278283

279284
#define TICKS_PER_CHAR 10
280-
#define DO_TICK(bool) \
281-
do if ((bool) && !(++tickCount % TICKS_PER_CHAR)) { \
282-
fprintf(stderr, "\r%c\r", *ticker); \
283-
if (!*ticker++) ticker= ticks; \
285+
#define DO_TICK(bool) \
286+
do if ((bool) && !(++tickCount % TICKS_PER_CHAR)) { \
287+
if (!*ticker) ticker = ticks; \
288+
fprintf(stderr, stderrIsAFile ? "%c" : "\r%c\r", *ticker++);\
289+
pollpipOutput = 1; \
284290
} while (0)
285291

286292
long
@@ -294,18 +300,17 @@ aioPoll(long microSeconds)
294300
extern void forceInterruptCheck(int); /* not really, but hey */
295301
#endif
296302

297-
#if defined(AIO_DEBUG) && AIO_DEBUG >= 2
298-
FPRINTF((stderr, "aioPoll(%ld)\n", microSeconds));
299-
#endif
303+
DO_TICK(SHOULD_TICK());
300304

305+
#if defined(AIO_DEBUG)
306+
# if AIO_DEBUG >= 2
307+
FPRINTF((stderr, "aioPoll(%ld)\n", microSeconds));
308+
# endif
301309
// check that our signal handler is in place.
302310
// If it isn't, things aren't right.
303-
#if AIO_DEBUG
304311
sigaction(SIGIO, NULL, &current_sigio_action);
305312
assert(current_sigio_action.sa_handler == forceInterruptCheck);
306313
#endif
307-
DO_TICK(SHOULD_TICK());
308-
309314
/*
310315
* get out early if there is no pending i/o and no need to relinquish
311316
* cpu
@@ -315,7 +320,7 @@ aioPoll(long microSeconds)
315320
if (maxFd == 0)
316321
return 0;
317322
#else
318-
if ((maxFd == 0) && (microSeconds == 0))
323+
if (maxFd == 0 && microSeconds == 0)
319324
return 0;
320325
#endif
321326

@@ -403,7 +408,6 @@ aioSleepForUsecs(long microSeconds)
403408
void
404409
aioEnable(int fd, void *data, int flags)
405410
{
406-
FPRINTF((stderr, "aioEnable(%d)\n", fd));
407411
if (fd < 0) {
408412
FPRINTF((stderr, "aioEnable(%d): IGNORED\n", fd));
409413
return;
@@ -423,6 +427,7 @@ aioEnable(int fd, void *data, int flags)
423427
if (flags & AIO_EXT) {
424428
FD_SET(fd, &xdMask);
425429
/* we should not set NBIO ourselves on external descriptors! */
430+
FPRINTF((stderr, "aioEnable(%d): external\n", fd));
426431
}
427432
else {
428433
/*
@@ -440,6 +445,7 @@ aioEnable(int fd, void *data, int flags)
440445
perror("fcntl(F_GETFL)");
441446
if (fcntl(fd, F_SETFL, arg | O_NONBLOCK | O_ASYNC) < 0)
442447
perror("fcntl(F_SETFL, O_ASYNC)");
448+
FPRINTF((stderr, "aioEnable(%d): Elicit SIGIO via O_ASYNC/fcntl\n", fd));
443449

444450
#elif defined(FASYNC)
445451
if (fcntl(fd, F_SETOWN, getpid()) < 0)
@@ -448,6 +454,7 @@ aioEnable(int fd, void *data, int flags)
448454
perror("fcntl(F_GETFL)");
449455
if (fcntl(fd, F_SETFL, arg | O_NONBLOCK | FASYNC) < 0)
450456
perror("fcntl(F_SETFL, FASYNC)");
457+
FPRINTF((stderr, "aioEnable(%d): Elicit SIGIO via FASYNC/fcntl\n", fd));
451458

452459
#elif defined(FIOASYNC)
453460
arg = getpid();
@@ -456,6 +463,9 @@ aioEnable(int fd, void *data, int flags)
456463
arg = 1;
457464
if (ioctl(fd, FIOASYNC, &arg) < 0)
458465
perror("ioctl(FIOASYNC, 1)");
466+
FPRINTF((stderr, "aioEnable(%d): Elicit SIGIO via FIOASYNC/fcntl\n", fd));
467+
#else
468+
FPRINTF((stderr, "aioEnable(%d): UNABLE TO ELICIT SIGIO!!\n", fd));
459469
#endif
460470
}
461471
}

platforms/unix/vm/sqaio.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,17 @@ extern char *(*handlerNameChain)(aioHandler h);
111111
platReportError((os_error *)&privateErr); \
112112
} while (0)
113113
# else /* !ACORN */
114-
extern long aioLastTick, aioThisTick, aioDebugLogging, ioMSecs(void);
114+
extern long aioLastTick, aioThisTick, aioDebugLogging, pollpipOutput;
115+
extern long ioMSecs(void);
115116
extern const char *__shortFileName(const char *);
116-
# define FPRINTF(X) do { if (aioDebugLogging) { \
117-
aioThisTick = ioMSecs(); \
118-
fprintf(stderr, "%8ld %4ld %s:%d ", \
119-
aioThisTick, aioThisTick - aioLastTick, \
120-
__shortFileName(__FILE__),__LINE__); \
121-
aioLastTick = aioThisTick; \
122-
fprintf X; } } while (0)
117+
# define FPRINTF(X) do if (aioDebugLogging) { \
118+
aioThisTick = ioMSecs(); \
119+
if (pollpipOutput) fputc('\n',stderr); \
120+
fprintf(stderr, "%8ld %4ld %s:%d ", \
121+
aioThisTick, aioThisTick - aioLastTick, \
122+
__shortFileName(__FILE__),__LINE__); \
123+
aioLastTick = aioThisTick; \
124+
fprintf X; pollpipOutput = 0; } while (0)
123125
# endif /* ACORN */
124126
#else /* !AIO_DEBUG */
125127
# define FPRINTF(X)

0 commit comments

Comments
 (0)