ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Urlader/urlader.c
(Generate patch)

Comparing Urlader/urlader.c (file contents):
Revision 1.2 by root, Thu Dec 29 10:20:56 2011 UTC vs.
Revision 1.4 by root, Fri Dec 30 05:27:32 2011 UTC

34 #define u_creat(path,exec) CreateFile (path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL) 34 #define u_creat(path,exec) CreateFile (path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL)
35 #define u_close(handle) CloseHandle (handle) 35 #define u_close(handle) CloseHandle (handle)
36 #define u_append(path,add) PathAppend (path, add) 36 #define u_append(path,add) PathAppend (path, add)
37 #define u_write(handle,data,len) (WriteFile (handle, data, len, &dword, 0) ? dword : -1) 37 #define u_write(handle,data,len) (WriteFile (handle, data, len, &dword, 0) ? dword : -1)
38 38
39 #define u_fsync(handle) FlushFileBuffers (handle)
40 #define u_sync()
41
39#else 42#else
40 43
41 #include <sys/mman.h> 44 #include <sys/mman.h>
42 #include <sys/types.h> 45 #include <sys/types.h>
43 #include <pwd.h> 46 #include <pwd.h>
57 #define u_creat(path,exec) open (path, O_WRONLY | O_CREAT | O_TRUNC, (exec) ? 0777 : 0666) + 1 60 #define u_creat(path,exec) open (path, O_WRONLY | O_CREAT | O_TRUNC, (exec) ? 0777 : 0666) + 1
58 #define u_close(handle) close (handle - 1) 61 #define u_close(handle) close (handle - 1)
59 #define u_append(path,add) strcat (strcat (path, "/"), add) 62 #define u_append(path,add) strcat (strcat (path, "/"), add)
60 #define u_write(handle,data,len) write ((handle) - 1, data, len) 63 #define u_write(handle,data,len) write ((handle) - 1, data, len)
61 64
65 // on a mostly idle system, a sync at the end is certainly faster, hope for the best
66 #define u_fsync(handle)
67 #define u_sync() sync ()
68
62#endif 69#endif
63 70
64#define u_16(ptr) (((ptr)[0] << 8) | (ptr)[1]) 71#define u_16(ptr) (((ptr)[0] << 8) | (ptr)[1])
65#define u_32(ptr) (((ptr)[0] << 24) | ((ptr)[1] << 16) | ((ptr)[2] << 8) | (ptr)[3]) 72#define u_32(ptr) (((ptr)[0] << 24) | ((ptr)[1] << 16) | ((ptr)[2] << 8) | (ptr)[3])
66 73
143 150
144enum 151enum
145{ 152{
146 T_NULL, // 5 153 T_NULL, // 5
147 T_META, // 1 : exe_id, exe_ver 154 T_META, // 1 : exe_id, exe_ver
148 T_ARG, // 2 : arg
149 T_ENV, // 3 : name, value 155 T_ENV, // 2 : name, value
156 T_ARG, // 3 : arg
150 T_DIR, // 4+: path 157 T_DIR, // 4+: path
151 T_FILE, // 4+: path, data 158 T_FILE, // 4+: path, data
152 T_NUM 159 T_NUM
153}; 160};
154 161
302 fatal ("unable to locate override metadata"); 309 fatal ("unable to locate override metadata");
303 310
304 strcpy (exe_ver, PACK_DATA); 311 strcpy (exe_ver, PACK_DATA);
305 pack_next (); 312 pack_next ();
306 313
314 for (;;)
315 {
316 if (pack_cur->type == T_ENV)
317 u_setenv (PACK_NAME, PACK_DATA);
307 while (pack_cur->type == T_ARG) 318 else if (pack_cur->type == T_ARG)
308 {
309 exe_argv [exe_argc++] = strdup (PACK_NAME); 319 exe_argv [exe_argc++] = strdup (PACK_NAME);
320 else
321 break;
322
310 pack_next (); 323 pack_next ();
311 } 324 }
312 325
313 while (pack_cur->type == T_ENV) 326done_env_arg:
314 {
315 u_setenv (PACK_NAME, PACK_DATA);
316 pack_next ();
317 }
318
319 strcpy (execdir, exe_dir); 327 strcpy (execdir, exe_dir);
320 u_append (execdir, "i-"); 328 u_append (execdir, "i-");
321 strcat (execdir, exe_ver); 329 strcat (execdir, exe_ver);
322 330
323 if (access (execdir, F_OK)) 331 if (access (execdir, F_OK))
355 fatal ("unable to unpack file from packfile - disk full?"); 363 fatal ("unable to unpack file from packfile - disk full?");
356 364
357 if (u_write (h, data, len) != len) 365 if (u_write (h, data, len) != len)
358 fatal ("unable to unpack file from packfile - disk full?"); 366 fatal ("unable to unpack file from packfile - disk full?");
359 367
368 u_fsync (h);
360 u_close (h); 369 u_close (h);
361 } 370 }
362 break; 371 break;
363 372
364 case T_NULL: 373 case T_NULL:
369 } 378 }
370 379
371done: 380done:
372 if (u_chdir (datadir)) 381 if (u_chdir (datadir))
373 fatal ("unable to change to data directory"); 382 fatal ("unable to change to data directory");
383
384 u_sync ();
374 385
375 if (u_rename (tmppath, execdir)) 386 if (u_rename (tmppath, execdir))
376 deltree (tmppath); // if move fails, delete new, assume other process created it independently 387 deltree (tmppath); // if move fails, delete new, assume other process created it independently
377 } 388 }
378 389

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines