bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gawk's inet hanging?


From: Jeff Chua
Subject: Re: gawk's inet hanging?
Date: Fri, 6 Nov 2009 11:27:24 +0800 (SGT)



Arnold,

I'm trying put gawk inet connection to the local smtp port and would like it to detect error conditions, but don't know how.


I looked into the source code and it seems the code is testing "unsigned long" for negative value ... and that won't work.

I've also modify the code to return ERRNO to user instead of exiting with a fatal error in case the socket is no available, and also modified sleep() to usleep() and allow GAWK_MSEC_SLEEP to retry in milliseconds interval instead of the default 1 second.

Tested with this script.


export GAWK_SOCK_RETRIES=3;
export GAWK_MSEC_SLEEP=200;
gawk 'BEGIN {
        serv = "/inet/tcp/0/localhost/25";
        status = (serv |& getline);
        printf("(%s) (%s) [%s]\n", ERRNO, status, $0);
}'


Patch below. Please consider.


Thanks,
Jeff.


--- gawk-stable/io.c    2009-10-30 21:46:43.000000000 +0800
+++ a/io.c      2009-11-06 10:55:01.000000000 +0800
@@ -708,10 +708,12 @@
                        if (! two_way_open(str, rp)) {
 #ifdef HAVE_SOCKETS
                                /* multiple messages make life easier for 
translators */
-                               if (STREQN(str, "/inet/", 6))
-                                       fatal(_("can't open two way socket `%s' for 
input/output (%s)"),
-                                               str, strerror(errno));
-                               else
+                               if (STREQN(str, "/inet/", 6)) {
+                                       *errflg = errno;
+                                       free_temp(tmp);
+                                       free_rp(rp);
+                                       return NULL;
+                               } else
 #endif
                                        fatal(_("can't open two way pipe `%s' for 
input/output (%s)"),
                                                str, strerror(errno));
@@ -1457,27 +1459,41 @@

                {
 #define DEFAULT_RETRIES 20
-                       static unsigned long def_retries = DEFAULT_RETRIES;
+                       static long def_retries = DEFAULT_RETRIES;
                        static int first_time = TRUE;
-                       unsigned long retries = 0;
+                       long retries = 0;
+                       static long msleep = 1000;

                        if (first_time) {
                                char *cp, *end;
-                               unsigned long count = 0;
+                               long count = 0;
+                               char *ms2;

                                first_time = FALSE;
-                               if ((cp = getenv("GAWK_SOCK_RETRIES")) != NULL) 
{
+
+                               if((cp = getenv("GAWK_SOCK_RETRIES")) != NULL) {
                                        count = strtoul(cp, &end, 10);
                                        if (end != cp && count > 0)
                                                def_retries = count;
+                                       //warning(_("retries %d %d"), 
def_retries, count);
+                               }
+
+                               if((ms2 = getenv("GAWK_MSEC_SLEEP")) != NULL) {
+                                       msleep = atoi(ms2);
+                                       if(msleep < 0)
+                                               msleep = 1000;
+                                       //warning(_("msleep %d"), msleep);
                                }
                        }
                        retries = def_retries;

+                       msleep *= 1000;
+
                        do {
                                openfd = socketopen(protocol, localpname, cp, 
hostname);
+                               //warning(_("retries %d"), retries);
                                retries--;
-                       } while (openfd == INVALID_HANDLE && retries >= 0 && 
sleep(1) == 0);
+                       } while (openfd == INVALID_HANDLE && retries >= 0 && 
usleep(msleep) == 0);
                }

                *localpnamelastcharp = '/';






reply via email to

[Prev in Thread] Current Thread [Next in Thread]