ry / ebb fork watch download tarball
public
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
Search Repo:
use mkstemp() for tmp filename
ryah (author)
Mon Mar 24 06:46:46 -0700 2008
commit  f278ac2badf0c6e3a8f7c2572217cd38e7780f44
tree    64ca3db90058b4e7bbe4047bbaa6acf041a32f94
parent  5fb8170d45ed424e73c51ad58874c99beb2ced76
...
120
121
122
123
124
 
125
126
127
...
132
133
134
135
136
137
 
 
 
 
 
 
 
 
 
 
 
 
138
139
140
...
341
342
343
 
344
345
346
...
547
548
549
550
 
551
552
 
 
553
554
555
...
120
121
122
 
123
124
125
126
127
...
132
133
134
 
 
 
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
...
350
351
352
353
354
355
356
...
557
558
559
 
560
561
562
563
564
565
566
567
0
@@ -120,8 +120,8 @@ static void on_timeout(struct ev_loop *loop, ev_timer *watcher, int revents)
0
 static void* read_body_into_file(void *_client)
0
 {
0
   ebb_client *client = (ebb_client*)_client;
0
- static unsigned int id;
0
   FILE *tmpfile;
0
+ char *filename = "/tmp/.ebb_upload.XXXXXX";
0
   
0
   assert(client->open);
0
   assert(client->server->open);
0
@@ -132,9 +132,18 @@ static void* read_body_into_file(void *_client)
0
   int flags = fcntl(client->fd, F_GETFL, 0);
0
   assert(0 <= fcntl(client->fd, F_SETFL, flags & ~O_NONBLOCK));
0
   
0
- sprintf(client->upload_filename, "/tmp/ebb_upload_%010d", id++);
0
- tmpfile = fopen(client->upload_filename, "w+");
0
- if(tmpfile == NULL) g_message("Cannot open tmpfile %s", client->upload_filename);
0
+ if(0 > mkstemp(filename)) {
0
+ perror("mkstemp()");
0
+ ebb_client_close(client);
0
+ return NULL;
0
+ }
0
+ client->upload_filename = strdup(filename);
0
+ tmpfile = fopen(filename, "w+");
0
+ if(tmpfile == NULL) {
0
+ perror("opening tempfile for uplaod");
0
+ ebb_client_close(client);
0
+ return NULL;
0
+ }
0
   client->upload_file = tmpfile;
0
   
0
   size_t body_head_length = client->read - client->parser.nread;
0
@@ -341,6 +350,7 @@ static void client_init(ebb_client *client)
0
    * because the backend is going to keep sending such long requests.
0
    */
0
   client->response_buffer->len = 0;
0
+ client->upload_filename = NULL;
0
   
0
   /* SETUP READ AND TIMEOUT WATCHERS */
0
   client->write_watcher.data = client;
0
@@ -547,9 +557,11 @@ void ebb_client_close(ebb_client *client)
0
     ev_io_stop(client->server->loop, &client->write_watcher);
0
     ev_timer_stop(client->server->loop, &client->timeout_watcher);
0
     
0
- if(client->upload_file) {
0
+ if(client->upload_filename) {
0
       fclose(client->upload_file);
0
       unlink(client->upload_filename);
0
+ client->upload_file = NULL;
0
+ client->upload_filename = NULL;
0
     }
0
     
0
     close(client->fd);
...
52
53
54
55
 
56
57
58
...
52
53
54
 
55
56
57
58
0
@@ -52,7 +52,7 @@ struct ebb_client {
0
   ev_io read_watcher;
0
   size_t read, nread_from_body;
0
   
0
- char upload_filename[200];
0
+ char *upload_filename;
0
   FILE *upload_file;
0
   
0
   ev_io write_watcher;

Comments

    No one has commented yet.