]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests/servers: use our platform-aware pid for server verification
authorMarc Hoersken <info@marc-hoersken.de>
Fri, 23 Jul 2021 18:33:40 +0000 (20:33 +0200)
committerMarc Hoersken <info@marc-hoersken.de>
Sun, 25 Jul 2021 17:59:58 +0000 (19:59 +0200)
The pid used for server verification is later stored as pid2 in
the hash of running test servers and therefore used for shutdown.

The pid used for shutdown must be the platform-aware (Win32) pid
to avoid leaking test servers while running them using Cygwin/msys.

Reviewed-by: Jay Satiro
Closes #7481

tests/server/rtspd.c
tests/server/sws.c
tests/server/tftpd.c
tests/server/util.c
tests/server/util.h

index 97aad7a76c1eec5707e61c5c455832fd4aa53de0..4edaeb86a88ccc9ac60d7a41a9964003bb6e50e9 100644 (file)
@@ -810,8 +810,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
     case DOCNUMBER_WERULEZ:
       /* we got a "friends?" question, reply back that we sure are */
       logmsg("Identifying ourselves as friends");
-      msnprintf(msgbuf, sizeof(msgbuf), "RTSP_SERVER WE ROOLZ: %ld\r\n",
-                (long)getpid());
+      msnprintf(msgbuf, sizeof(msgbuf), "RTSP_SERVER WE ROOLZ: %"
+                CURL_FORMAT_CURL_OFF_T "\r\n", our_getpid());
       msglen = strlen(msgbuf);
       msnprintf(weare, sizeof(weare),
                 "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s",
index 010e5ae1d05697e252667c7ad17b0368b781bbe5..3fc913b3f8883a7aba03183e20f26d2c9a1d978f 100644 (file)
@@ -994,7 +994,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
     case DOCNUMBER_WERULEZ:
       /* we got a "friends?" question, reply back that we sure are */
       logmsg("Identifying ourselves as friends");
-      msnprintf(msgbuf, sizeof(msgbuf), "WE ROOLZ: %ld\r\n", (long)getpid());
+      msnprintf(msgbuf, sizeof(msgbuf), "WE ROOLZ: %"
+                CURL_FORMAT_CURL_OFF_T "\r\n", our_getpid());
       msglen = strlen(msgbuf);
       if(use_gopher)
         msnprintf(weare, sizeof(weare), "%s", msgbuf);
index 92d584918f5d149bbe380f92b0da63ec41554d8c..8caa3491f0d48d1992f22151150898cfdedb42ba 100644 (file)
@@ -1065,8 +1065,8 @@ static int validate_access(struct testcase *test,
 
   if(!strncmp("verifiedserver", filename, 14)) {
     char weare[128];
-    size_t count = msnprintf(weare, sizeof(weare),
-                             "WE ROOLZ: %ld\r\n", (long)getpid());
+    size_t count = msnprintf(weare, sizeof(weare), "WE ROOLZ: %"
+                             CURL_FORMAT_CURL_OFF_T "\r\n", our_getpid());
 
     logmsg("Are-we-friendly question received");
     test->buffer = strdup(weare);
index 38d6395c59329cb94c87096f061b3b125eeb3812..284f347cfd858c5963dcd023def884813fee9340 100644 (file)
@@ -269,17 +269,11 @@ int wait_ms(int timeout_ms)
   return r;
 }
 
-int write_pidfile(const char *filename)
+curl_off_t our_getpid(void)
 {
-  FILE *pidfile;
   curl_off_t pid;
 
   pid = (curl_off_t)getpid();
-  pidfile = fopen(filename, "wb");
-  if(!pidfile) {
-    logmsg("Couldn't write pid file: %s %s", filename, strerror(errno));
-    return 0; /* fail */
-  }
 #if defined(WIN32) || defined(_WIN32)
   /* store pid + 65536 to avoid conflict with Cygwin/msys PIDs, see also:
    * - https://cygwin.com/git/?p=newlib-cygwin.git;a=commit; ↵
@@ -289,6 +283,20 @@ int write_pidfile(const char *filename)
    */
   pid += 65536;
 #endif
+  return pid;
+}
+
+int write_pidfile(const char *filename)
+{
+  FILE *pidfile;
+  curl_off_t pid;
+
+  pid = our_getpid();
+  pidfile = fopen(filename, "wb");
+  if(!pidfile) {
+    logmsg("Couldn't write pid file: %s %s", filename, strerror(errno));
+    return 0; /* fail */
+  }
   fprintf(pidfile, "%" CURL_FORMAT_CURL_OFF_T "\n", pid);
   fclose(pidfile);
   logmsg("Wrote pid %" CURL_FORMAT_CURL_OFF_T " to %s", pid, filename);
index 68473f28f29804e5f47d1e7135c0a965edf781f3..4c93611178e426e14addf59b942fdd827bea9f3f 100644 (file)
@@ -60,6 +60,7 @@ void win32_cleanup(void);
 FILE *test2fopen(long testno);
 
 int wait_ms(int timeout_ms);
+curl_off_t our_getpid(void);
 int write_pidfile(const char *filename);
 int write_portfile(const char *filename, int port);
 void set_advisor_read_lock(const char *filename);