Fossil SCM
Make sure temporary files are well-named and are deleted after use in the win32 fossil server command.
Commit
24f336c9ae5e3ea3fe292ea974a77cbd9f45a0d6
Parent
e2e016c31f8b7ff…
1 file changed
+10
-5
+10
-5
| --- src/winhttp.c | ||
| +++ src/winhttp.c | ||
| @@ -38,10 +38,15 @@ | ||
| 38 | 38 | int id; /* ID counter */ |
| 39 | 39 | SOCKET s; /* Socket on which to receive data */ |
| 40 | 40 | SOCKADDR_IN addr; /* Address from which data is coming */ |
| 41 | 41 | }; |
| 42 | 42 | |
| 43 | +/* | |
| 44 | +** Prefix for a temporary file. | |
| 45 | +*/ | |
| 46 | +static char *zTempPrefix; | |
| 47 | + | |
| 43 | 48 | /* |
| 44 | 49 | ** Look at the HTTP header contained in zHdr. Find the content |
| 45 | 50 | ** length and return it. Return 0 if there is no Content-Length: |
| 46 | 51 | ** header line. |
| 47 | 52 | */ |
| @@ -70,12 +75,12 @@ | ||
| 70 | 75 | char zRequestFName[100]; |
| 71 | 76 | char zReplyFName[100]; |
| 72 | 77 | char zCmd[2000]; /* Command-line to process the request */ |
| 73 | 78 | char zHdr[2000]; /* The HTTP request header */ |
| 74 | 79 | |
| 75 | - sprintf(zRequestFName, "win32_http_in%d.txt", p->id); | |
| 76 | - sprintf(zReplyFName, "win32_http_out%d.txt", p->id); | |
| 80 | + sprintf(zRequestFName, "%s_in%d.txt", zTempPrefix, p->id); | |
| 81 | + sprintf(zReplyFName, "%s_out%d.txt", zTempPrefix, p->id); | |
| 77 | 82 | amt = 0; |
| 78 | 83 | while( amt<sizeof(zHdr) ){ |
| 79 | 84 | got = recv(p->s, &zHdr[amt], sizeof(zHdr)-1-amt, 0); |
| 80 | 85 | if( got==SOCKET_ERROR ) goto end_request; |
| 81 | 86 | if( got==0 ){ |
| @@ -117,15 +122,15 @@ | ||
| 117 | 122 | send(p->s, zHdr, got, 0); |
| 118 | 123 | } |
| 119 | 124 | } |
| 120 | 125 | |
| 121 | 126 | end_request: |
| 122 | - unlink(zRequestFName); | |
| 123 | - unlink(zReplyFName); | |
| 124 | 127 | if( out ) fclose(out); |
| 125 | 128 | if( in ) fclose(in); |
| 126 | 129 | closesocket(p->s); |
| 130 | + unlink(zRequestFName); | |
| 131 | + unlink(zReplyFName); | |
| 127 | 132 | free(p); |
| 128 | 133 | } |
| 129 | 134 | |
| 130 | 135 | /* |
| 131 | 136 | ** Start a listening socket and process incoming HTTP requests on |
| @@ -138,11 +143,11 @@ | ||
| 138 | 143 | int idCnt = 0; |
| 139 | 144 | |
| 140 | 145 | if( WSAStartup(MAKEWORD(1,1), &wd) ){ |
| 141 | 146 | fossil_fatal("unable to initialize winsock"); |
| 142 | 147 | } |
| 143 | - | |
| 148 | + zTempPrefix = mprintf("fossil_server_P%d_", iPort); | |
| 144 | 149 | s = socket(AF_INET, SOCK_STREAM, 0); |
| 145 | 150 | if( s==INVALID_SOCKET ){ |
| 146 | 151 | fossil_fatal("unable to create a socket"); |
| 147 | 152 | } |
| 148 | 153 | addr.sin_family = AF_INET; |
| 149 | 154 |
| --- src/winhttp.c | |
| +++ src/winhttp.c | |
| @@ -38,10 +38,15 @@ | |
| 38 | int id; /* ID counter */ |
| 39 | SOCKET s; /* Socket on which to receive data */ |
| 40 | SOCKADDR_IN addr; /* Address from which data is coming */ |
| 41 | }; |
| 42 | |
| 43 | /* |
| 44 | ** Look at the HTTP header contained in zHdr. Find the content |
| 45 | ** length and return it. Return 0 if there is no Content-Length: |
| 46 | ** header line. |
| 47 | */ |
| @@ -70,12 +75,12 @@ | |
| 70 | char zRequestFName[100]; |
| 71 | char zReplyFName[100]; |
| 72 | char zCmd[2000]; /* Command-line to process the request */ |
| 73 | char zHdr[2000]; /* The HTTP request header */ |
| 74 | |
| 75 | sprintf(zRequestFName, "win32_http_in%d.txt", p->id); |
| 76 | sprintf(zReplyFName, "win32_http_out%d.txt", p->id); |
| 77 | amt = 0; |
| 78 | while( amt<sizeof(zHdr) ){ |
| 79 | got = recv(p->s, &zHdr[amt], sizeof(zHdr)-1-amt, 0); |
| 80 | if( got==SOCKET_ERROR ) goto end_request; |
| 81 | if( got==0 ){ |
| @@ -117,15 +122,15 @@ | |
| 117 | send(p->s, zHdr, got, 0); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | end_request: |
| 122 | unlink(zRequestFName); |
| 123 | unlink(zReplyFName); |
| 124 | if( out ) fclose(out); |
| 125 | if( in ) fclose(in); |
| 126 | closesocket(p->s); |
| 127 | free(p); |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | ** Start a listening socket and process incoming HTTP requests on |
| @@ -138,11 +143,11 @@ | |
| 138 | int idCnt = 0; |
| 139 | |
| 140 | if( WSAStartup(MAKEWORD(1,1), &wd) ){ |
| 141 | fossil_fatal("unable to initialize winsock"); |
| 142 | } |
| 143 | |
| 144 | s = socket(AF_INET, SOCK_STREAM, 0); |
| 145 | if( s==INVALID_SOCKET ){ |
| 146 | fossil_fatal("unable to create a socket"); |
| 147 | } |
| 148 | addr.sin_family = AF_INET; |
| 149 |
| --- src/winhttp.c | |
| +++ src/winhttp.c | |
| @@ -38,10 +38,15 @@ | |
| 38 | int id; /* ID counter */ |
| 39 | SOCKET s; /* Socket on which to receive data */ |
| 40 | SOCKADDR_IN addr; /* Address from which data is coming */ |
| 41 | }; |
| 42 | |
| 43 | /* |
| 44 | ** Prefix for a temporary file. |
| 45 | */ |
| 46 | static char *zTempPrefix; |
| 47 | |
| 48 | /* |
| 49 | ** Look at the HTTP header contained in zHdr. Find the content |
| 50 | ** length and return it. Return 0 if there is no Content-Length: |
| 51 | ** header line. |
| 52 | */ |
| @@ -70,12 +75,12 @@ | |
| 75 | char zRequestFName[100]; |
| 76 | char zReplyFName[100]; |
| 77 | char zCmd[2000]; /* Command-line to process the request */ |
| 78 | char zHdr[2000]; /* The HTTP request header */ |
| 79 | |
| 80 | sprintf(zRequestFName, "%s_in%d.txt", zTempPrefix, p->id); |
| 81 | sprintf(zReplyFName, "%s_out%d.txt", zTempPrefix, p->id); |
| 82 | amt = 0; |
| 83 | while( amt<sizeof(zHdr) ){ |
| 84 | got = recv(p->s, &zHdr[amt], sizeof(zHdr)-1-amt, 0); |
| 85 | if( got==SOCKET_ERROR ) goto end_request; |
| 86 | if( got==0 ){ |
| @@ -117,15 +122,15 @@ | |
| 122 | send(p->s, zHdr, got, 0); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | end_request: |
| 127 | if( out ) fclose(out); |
| 128 | if( in ) fclose(in); |
| 129 | closesocket(p->s); |
| 130 | unlink(zRequestFName); |
| 131 | unlink(zReplyFName); |
| 132 | free(p); |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | ** Start a listening socket and process incoming HTTP requests on |
| @@ -138,11 +143,11 @@ | |
| 143 | int idCnt = 0; |
| 144 | |
| 145 | if( WSAStartup(MAKEWORD(1,1), &wd) ){ |
| 146 | fossil_fatal("unable to initialize winsock"); |
| 147 | } |
| 148 | zTempPrefix = mprintf("fossil_server_P%d_", iPort); |
| 149 | s = socket(AF_INET, SOCK_STREAM, 0); |
| 150 | if( s==INVALID_SOCKET ){ |
| 151 | fossil_fatal("unable to create a socket"); |
| 152 | } |
| 153 | addr.sin_family = AF_INET; |
| 154 |