tests/servers: use our platform-aware pid for server verification

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
This commit is contained in:
Marc Hoersken 2021-07-23 20:33:40 +02:00
parent 893f39c596
commit d9d26a6b2c
No known key found for this signature in database
GPG Key ID: 61E03CBED7BC859E
5 changed files with 22 additions and 12 deletions

View 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",

View 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);

View 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);

View 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);

View 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);