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

Comparing Urlader/urlader.c (file contents):
Revision 1.1 by root, Thu Dec 29 00:44:21 2011 UTC vs.
Revision 1.7 by root, Fri Dec 30 14:51:45 2011 UTC

1#ifndef URLADER 1#ifndef URLADER
2# define URLADER "urlader" 2# define URLADER "urlader"
3#endif 3#endif
4#define URLADER_VERSION "1.0" 4#define URLADER_VERSION "1.0" // a decimal number, not a version string
5
6#define MAX_ARGC 32
7#define MAX_ARGS 256
5 8
6#include <stdio.h> 9#include <stdio.h>
7#include <stdlib.h> 10#include <stdlib.h>
8#include <unistd.h> 11#include <unistd.h>
9#include <errno.h> 12#include <errno.h>
10#include <string.h> 13#include <string.h>
11#include <time.h> 14#include <time.h>
12#include <fcntl.h> 15#include <fcntl.h>
13 16
14#include "lzf_d.c" 17#include "liblzf/lzf_d.c"
15 18
16#define TAIL_MAGIC "SCHMORPPACK0" 19#define TAIL_MAGIC "SCHMORPPACK0"
17 20
18#ifdef _WIN32 21#ifdef _WIN32
19 22
20 #include <windows.h> 23 #include <windows.h>
21 //#include <winbase.h> 24 //#include <winbase.h>
22 #include <shlobj.h> 25 #include <shlobj.h>
23 #include <shlwapi.h> 26 #include <shlwapi.h>
24 #include <wininet.h> 27 #include <wininet.h>
25 28
26 static DWORD dword; 29 static DWORD dword;
27 30
28 #define u_handle HANDLE 31 #define u_handle HANDLE
32 #define u_invalid_handle 0
33 #define u_valid(handle) (!!handle)
34
29 #define u_setenv(name,value) SetEnvironmentVariable (name, value) 35 #define u_setenv(name,value) SetEnvironmentVariable (name, value)
30 #define u_mkdir(path) !CreateDirectory (path, NULL) 36 #define u_mkdir(path) !CreateDirectory (path, NULL)
31 #define u_chdir(path) !SetCurrentDirectory (path) 37 #define u_chdir(path) !SetCurrentDirectory (path)
32 #define u_rename(fr,to) !MoveFile (fr, to) 38 #define u_rename(fr,to) !MoveFile (fr, to)
33 #define u_open(path) CreateFile (path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL) 39 #define u_open(path) CreateFile (path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 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) 40 #define u_creat(path,exec) CreateFile (path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL)
41 #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) 42 #define u_close(handle) CloseHandle (handle)
36 #define u_append(path,add) PathAppend (path, add) 43 #define u_append(path,add) PathAppend (path, add)
37 #define u_write(handle,data,len) (WriteFile (handle, data, len, &dword, 0) ? dword : -1) 44 #define u_write(handle,data,len) (WriteFile (handle, data, len, &dword, 0) ? dword : -1)
38 45
39#else 46 #define u_fsync(handle) FlushFileBuffers (handle)
47 #define u_sync()
40 48
49 #define u_lockfile(path) CreateFile (path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)
50 #define u_cloexec(handle)
51
52#else
53
54 #define _GNU_SOURCE 1
55 #define _BSD_SOURCE 1
56 // the above increases our chances of getting MAP_ANONYMOUS
57
41 #include <sys/mman.h> 58 #include <sys/mman.h>
42 #include <sys/types.h> 59 #include <sys/types.h>
60 #include <sys/stat.h>
61 #include <unistd.h>
43 #include <pwd.h> 62 #include <pwd.h>
44 63
64 #if defined (MAP_ANON) && !defined (MAP_ANONYMOUS)
65 #define MAP_ANONYMOUS MAP_ANON
66 #endif
67
45 #ifdef PATH_MAX 68 #ifdef PATH_MAX
46 #define MAX_PATH (PATH_MAX < 4096 ? 4096 : PATH_MAX) 69 #define MAX_PATH (PATH_MAX < 4096 ? 4096 : PATH_MAX)
47 #else 70 #else
48 #define MAX_PATH 4096 71 #define MAX_PATH 4096
49 #endif 72 #endif
50 73
51 #define u_handle int 74 #define u_handle int
75 #define u_invalid_handle -1
76 #define u_valid(fd) ((fd) >= 0)
77
52 #define u_setenv(name,value) setenv (name, value, 1) 78 #define u_setenv(name,value) setenv (name, value, 1)
53 #define u_mkdir(path) mkdir (path, 0777) 79 #define u_mkdir(path) mkdir (path, 0777)
54 #define u_chdir(path) chdir (path) 80 #define u_chdir(path) chdir (path)
55 #define u_rename(fr,to) rename (fr, to) 81 #define u_rename(fr,to) rename (fr, to)
56 #define u_open(path) open (path, O_RDONLY) + 1 82 #define u_open(path) open (path, O_RDONLY)
57 #define u_creat(path,exec) open (path, O_WRONLY | O_CREAT | O_TRUNC, (exec) ? 0777 : 0666) + 1 83 #define u_creat(path,exec) open (path, O_WRONLY | O_CREAT | O_TRUNC, (exec) ? 0777 : 0666)
58 #define u_close(handle) close (handle - 1) 84 #define u_close(handle) close (handle)
59 #define u_append(path,add) strcat (strcat (path, "/"), add) 85 #define u_append(path,add) strcat (strcat (path, "/"), add)
60 #define u_write(handle,data,len) write ((handle) - 1, data, len) 86 #define u_write(handle,data,len) write (handle, data, len)
87
88 // on a mostly idle system, a sync at the end is certainly faster, hope for the best
89 #define u_fsync(handle)
90 #define u_sync() sync ()
91
92 #define u_lockfile(path) open (path, O_RDWR | O_CREAT, 0666)
93 #define u_cloexec(handle) fcntl (handle, F_SETFD, FD_CLOEXEC)
61 94
62#endif 95#endif
63 96
64#define u_16(ptr) (((ptr)[0] << 8) | (ptr)[1]) 97#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]) 98#define u_32(ptr) (((ptr)[0] << 24) | ((ptr)[1] << 16) | ((ptr)[2] << 8) | (ptr)[3])
66 99
100/* some simple? dynamic memory management for paths might save ltos of ram */
67static u_handle pack_handle; 101static u_handle pack_handle;
102static u_handle lock_handle;
68static char tmppath[MAX_PATH]; 103static char tmppath[MAX_PATH];
69static char currdir[MAX_PATH]; 104static char currdir[MAX_PATH];
70static char datadir[MAX_PATH]; // %AppData%/urlader 105static char datadir[MAX_PATH]; // %AppData%/urlader
71static char exe_dir[MAX_PATH]; // %AppData%/urlader/EXE_ID 106static char exe_dir[MAX_PATH]; // %AppData%/urlader/EXE_ID
72static char execdir[MAX_PATH]; // %AppData%/urlader/EXE_ID/EXE_VER 107static char execdir[MAX_PATH]; // %AppData%/urlader/EXE_ID/EXE_VER
73static char exe_id[MAX_PATH]; 108static char exe_id[MAX_PATH];
74static char exe_ver[MAX_PATH]; 109static char exe_ver[MAX_PATH];
75 110
76static int exe_argc; 111static int exe_argc;
77static const char *exe_argv[32]; 112static const char *exe_argv[MAX_ARGC];
113static char exe_args[MAX_ARGS]; /* actual arguments strings copied here */
114static unsigned int exe_argo;
78 115
79static void 116static void
80fatal (const char *msg) 117fatal (const char *msg)
81{ 118{
82#ifdef _WIN32 119#ifdef _WIN32
83 MessageBox (0, msg, URLADER, 0); 120 MessageBox (0, msg, URLADER, 0);
84#else 121#else
85 fprintf (stderr, "%s: %s\n", URLADER, msg); 122 write (2, URLADER ": ", sizeof (URLADER ": ") - 1);
123 write (2, msg, strlen (msg));
124 write (2, "\n", 1);
86#endif 125#endif
87 126
88 _exit (1); 127 _exit (1);
128}
129
130static void *
131u_malloc (unsigned int size)
132{
133 void *addr;
134
135#ifdef _WIN32
136 HANDLE handle = CreateFileMapping (0, 0, PAGE_READWRITE, 0, size, NULL);
137
138 if (!handle)
139 return 0;
140
141 addr = MapViewOfFile (handle, FILE_MAP_WRITE, 0, 0, size);
142
143 CloseHandle (handle);
144#elif defined (MAP_ANONYMOUS)
145 addr = mmap (0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
146
147 if (addr == (void *)-1)
148 addr = 0;
149#else
150 addr = malloc (size);
151#endif
152
153 return addr;
154}
155
156static void
157u_free (void *addr, unsigned int size)
158{
159#ifdef _WIN32
160 UnmapViewOfFile (addr);
161#elif defined (MAP_ANONYMOUS)
162 munmap (addr, size);
163#else
164 free (addr);
165#endif
166}
167
168static void *
169u_mmap (u_handle h, unsigned int size)
170{
171 void *addr;
172
173#ifdef _WIN32
174 HANDLE handle = CreateFileMapping (h, 0, PAGE_READONLY, 0, size, NULL);
175
176 if (!handle)
177 return 0;
178
179 addr = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, size);
180
181 CloseHandle (handle);
182#else
183 addr = mmap (0, size, PROT_READ, MAP_SHARED, h, 0);
184
185 if (addr == (void *)-1)
186 addr = 0;
187#endif
188
189 return addr;
190}
191
192static void
193u_munmap (void *addr, unsigned int len)
194{
195#ifdef _WIN32
196 UnmapViewOfFile (addr);
197#else
198 munmap (addr, len);
199#endif
89} 200}
90 201
91static void 202static void
92tmpdir (const char *dir) 203tmpdir (const char *dir)
93{ 204{
102// #endif 213// #endif
103 214
104 if (!u_mkdir (tmppath)) 215 if (!u_mkdir (tmppath))
105 return; 216 return;
106 } 217 }
218}
219
220static u_handle
221u_lock (const char *path, int excl, int dowait)
222{
223 u_handle h;
224
225 h = u_lockfile (path);
226 if (!u_valid (h))
227 return h;
228
229 u_cloexec (h);
230
231 for (;;)
232 {
233 int success;
234
235 // acquire the lock
236#ifdef _WIN32
237 OVERLAPPED ov = { 0 };
238
239 success = LockFileEx (h,
240 (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0)
241 | (dowait ? 0 : LOCKFILE_FAIL_IMMEDIATELY),
242 0,
243 1, 0,
244 &ov);
245#else
246 struct flock lck = { 0 };
247
248 lck.l_type = excl ? F_WRLCK : F_RDLCK;
249 lck.l_whence = SEEK_SET;
250 lck.l_len = 1;
251
252 success = !fcntl (h, dowait ? F_SETLKW : F_SETLK, &lck);
253#endif
254
255 if (!success)
256 break;
257
258 // we have the lock, now verify that the lockfile still exists
259
260#ifdef _WIN32
261 // apparently, we have to open the file to get its info :(
262 BY_HANDLE_FILE_INFORMATION s1, s2;
263 u_handle h2 = u_lockfile (path);
264 if (!u_valid (h))
265 break;
266
267 success = GetFileInformationByHandle (h, &s1)
268 && GetFileInformationByHandle (h2, &s2);
269
270 u_close (h2);
271
272 if (!success)
273 break;
274
275 success = s1.dwVolumeSerialNumber == s2.dwVolumeSerialNumber
276 && s1.nFileIndexHigh == s2.nFileIndexHigh
277 && s1.nFileIndexLow == s2.nFileIndexLow;
278#else
279 struct stat s1, s2;
280
281 if (fstat (h, &s1) || stat (path, &s2))
282 break;
283
284 success = s1.st_dev == s2.st_dev
285 && s1.st_ino == s2.st_ino;
286#endif
287
288 if (success)
289 return h; // lock successfully acquired
290
291 // files differ, close and retry - should be very rare
292 u_close (h);
293 }
294
295 // failure
296 u_close (h);
297 return u_invalid_handle;
107} 298}
108 299
109static void 300static void
110systemv (const char *const argv[]) 301systemv (const char *const argv[])
111{ 302{
139 const char *argv[] = { "/bin/rm", "-rf", path, 0 }; 330 const char *argv[] = { "/bin/rm", "-rf", path, 0 };
140 #endif 331 #endif
141 systemv (argv); 332 systemv (argv);
142} 333}
143 334
144static void
145execute (void)
146{
147 exe_argv [exe_argc] = 0;
148 systemv (exe_argv);
149}
150
151enum 335enum
152{ 336{
153 T_NULL, // 5 337 T_NULL, // 5
154 T_META, // 1 : exe_id, exe_ver 338 T_META, // 1 : exe_id, exe_ver
155 T_ARG, // 2 : arg
156 T_ENV, // 3 : name, value 339 T_ENV, // 2 : name, value
340 T_ARG, // 3 : arg
157 T_DIR, // 4+: path 341 T_DIR, // 4+: path
158 T_FILE, // 4+: path, data 342 T_FILE, // 4+: path, data
159 T_NUM 343 T_NUM
160}; 344};
161 345
180 char magic[12]; 364 char magic[12];
181}; 365};
182 366
183static char *pack_base, *pack_end; 367static char *pack_base, *pack_end;
184static struct hdr *pack_cur; 368static struct hdr *pack_cur;
369static char *scratch;
370static unsigned int scratch_size;
185 371
186#define PACK_NAME ((char *)(pack_cur + 1)) 372#define PACK_NAME ((char *)(pack_cur + 1))
187#define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1) 373#define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1)
188#define PACK_VALID pack_cur->type 374#define PACK_VALID pack_cur->type
189 375
196} 382}
197 383
198static void 384static void
199pack_unmap (void) 385pack_unmap (void)
200{ 386{
201 if (!pack_base) 387 if (pack_base)
202 return; 388 {
203
204#ifdef _WIN32
205 UnmapViewOfFile (pack_base);
206#else
207 munmap (pack_base, pack_end - pack_base); 389 u_munmap (pack_base, pack_end - pack_base);
208#endif 390 pack_base = 0;
391 }
392
393 if (scratch)
394 {
395 u_free (scratch, scratch_size);
396 scratch = 0;
397 }
209} 398}
210 399
211static int 400static int
212pack_map (void) 401pack_map (void)
213{ 402{
403 char *addr;
404 unsigned int size;
405
214#ifdef _WIN32 406#ifdef _WIN32
215 BY_HANDLE_FILE_INFORMATION fi; 407 BY_HANDLE_FILE_INFORMATION fi;
216 408
217 if (!GetFileInformationByHandle (pack_handle, &fi)) 409 if (!GetFileInformationByHandle (pack_handle, &fi))
218 return 0; 410 return 0;
219 411
220 if (fi.nFileSizeHigh) // too big 412 size = fi.nFileSizeLow;
413#else
414 size = lseek (pack_handle, 0, SEEK_END);
415#endif
416
417 addr = u_mmap (pack_handle, size);
418 if (!addr)
221 return 0; 419 return 0;
222 420
223 HANDLE handle = CreateFileMapping (pack_handle, 0, PAGE_READONLY, 0, fi.nFileSizeLow, NULL);
224
225 if (!handle)
226 return 0;
227
228 pack_unmap (); 421 pack_unmap ();
229 422
230 pack_base = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, fi.nFileSizeLow);
231
232 CloseHandle (handle);
233
234 pack_end = pack_base + fi.nFileSizeLow;
235#else
236 off_t len = lseek (pack_handle - 1, 0, SEEK_END);
237
238 pack_unmap ();
239
240 pack_base = mmap (0, len, PROT_READ, MAP_SHARED, pack_handle - 1, 0);
241 if (pack_base == (void *)-1)
242 pack_base = 0; 423 pack_base = addr;
243
244 pack_end = pack_base + len; 424 pack_end = pack_base + size;
245#endif
246
247 if (!pack_base)
248 return 0;
249 425
250 struct tail *tail; 426 struct tail *tail;
251 427
252 tail = (void *)(pack_end - sizeof (*tail)); 428 tail = (void *)(pack_end - sizeof (*tail));
253 429
254 if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1)) 430 if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1))
255 return 0; 431 return 0;
256 432
257 pack_cur = (struct hdr *)(pack_end - u_32 (tail->size)); 433 pack_cur = (struct hdr *)(pack_end - u_32 (tail->size));
434
435 scratch = u_malloc (scratch_size = u_32 (tail->max_filesize));
436 if (!scratch)
437 return 0;
258 438
259 return 1; 439 return 1;
260} 440}
261 441
262static void 442static void
282 462
283 if (u_chdir (exe_dir)) 463 if (u_chdir (exe_dir))
284 fatal ("unable to change to application data directory"); 464 fatal ("unable to change to application data directory");
285 465
286 u_handle h = u_open ("override"); 466 u_handle h = u_open ("override");
287 if (h) 467 if (u_valid (h))
288 { 468 {
289 u_handle oh = pack_handle; 469 u_handle oh = pack_handle;
290 470
291 pack_handle = h; 471 pack_handle = h;
292 if (!pack_map ()) 472 if (!pack_map ())
302 fatal ("unable to locate override metadata"); 482 fatal ("unable to locate override metadata");
303 483
304 strcpy (exe_ver, PACK_DATA); 484 strcpy (exe_ver, PACK_DATA);
305 pack_next (); 485 pack_next ();
306 486
487 for (;;)
488 {
489 if (pack_cur->type == T_ENV)
490 u_setenv (PACK_NAME, PACK_DATA);
307 while (pack_cur->type == T_ARG) 491 else if (pack_cur->type == T_ARG)
308 { 492 {
309 exe_argv [exe_argc++] = strdup (PACK_NAME); 493 int len = u_16 (pack_cur->namelen) + 1;
494 exe_argv [exe_argc++] = exe_args + exe_argo;
495 memcpy (exe_args + exe_argo, PACK_NAME, len);
496 exe_argo += len;
497 }
498 else
499 break;
500
310 pack_next (); 501 pack_next ();
311 } 502 }
312 503
313 while (pack_cur->type == T_ENV) 504done_env_arg:
314 {
315 u_setenv (PACK_NAME, PACK_DATA);
316 pack_next ();
317 }
318
319 strcpy (execdir, exe_dir); 505 strcpy (execdir, exe_dir);
320 u_append (execdir, "i-"); 506 u_append (execdir, "i-");
321 strcat (execdir, exe_ver); 507 strcat (execdir, exe_ver);
508
509 strcat (strcpy (tmppath, execdir), ".lck");
510 lock_handle = u_lock (tmppath, 0, 1);
511 if (!lock_handle)
512 fatal ("unable to lock application instance");
322 513
323 if (access (execdir, F_OK)) 514 if (access (execdir, F_OK))
324 { 515 {
325 // does not exist yet, so unpack and move 516 // does not exist yet, so unpack and move
326 tmpdir (exe_dir); 517 tmpdir (exe_dir);
337 break; 528 break;
338 529
339 case T_FILE: 530 case T_FILE:
340 { 531 {
341 u_handle h = u_creat (PACK_NAME, pack_cur->flags & F_EXEC); 532 u_handle h = u_creat (PACK_NAME, pack_cur->flags & F_EXEC);
342 unsigned int len = u_32 (pack_cur->datalen); 533 unsigned int dlen, len = u_32 (pack_cur->datalen);
534 char *data = PACK_DATA;
343 535
536 if (pack_cur->flags & F_LZF)
537 if (dlen = lzf_decompress (data, len, scratch, scratch_size))
538 {
539 data = scratch;
540 len = dlen;
541 }
542 else
543 fatal ("unable to uncompress file data - pack corrupted?");
544
344 if (!h) 545 if (!u_valid (h))
345 fatal ("unable to unpack file from packfile - disk full?"); 546 fatal ("unable to unpack file from packfile - disk full?");
346 547
347 if (u_write (h, PACK_DATA, len) != len) 548 if (u_write (h, data, len) != len)
348 fatal ("unable to unpack file from packfile - disk full?"); 549 fatal ("unable to unpack file from packfile - disk full?");
349 550
551 u_fsync (h);
350 u_close (h); 552 u_close (h);
351 } 553 }
352 break; 554 break;
353 555
354 case T_NULL: 556 case T_NULL:
360 562
361done: 563done:
362 if (u_chdir (datadir)) 564 if (u_chdir (datadir))
363 fatal ("unable to change to data directory"); 565 fatal ("unable to change to data directory");
364 566
567 u_sync ();
568
365 if (u_rename (tmppath, execdir)) 569 if (u_rename (tmppath, execdir))
366 deltree (tmppath); // if move fails, delete new, assume other process created it independently 570 deltree (tmppath); // if move fails, delete new, assume other process created it independently
367
368 if (u_chdir (execdir))
369 fatal ("unable to change to application instance directory");
370 } 571 }
371 572
372 pack_unmap (); 573 pack_unmap ();
373 u_close (pack_handle); 574 u_close (pack_handle);
575
576 if (u_chdir (execdir))
577 fatal ("unable to change to application instance directory");
374 578
375 u_setenv ("URLADER_VERSION", URLADER_VERSION); 579 u_setenv ("URLADER_VERSION", URLADER_VERSION);
376 u_setenv ("URLADER_DATADIR", datadir); 580 u_setenv ("URLADER_DATADIR", datadir);
377 u_setenv ("URLADER_EXECDIR", execdir); 581 u_setenv ("URLADER_EXECDIR", execdir);
378 u_setenv ("URLADER_EXE_ID" , exe_id); 582 u_setenv ("URLADER_EXE_ID" , exe_id);
379 u_setenv ("URLADER_EXE_DIR", exe_dir); 583 u_setenv ("URLADER_EXE_DIR", exe_dir);
380 u_setenv ("URLADER_EXE_VER", exe_ver); 584 u_setenv ("URLADER_EXE_VER", exe_ver);
381 585
586#if 0
382 // yes, this is overkill 587 // yes, this is overkill
383 u_setenv ("SHLIB_PATH" , execdir); // hpux 588 u_setenv ("SHLIB_PATH" , execdir); // hpux
384 u_setenv ("LIBPATH" , execdir); // aix 589 u_setenv ("LIBPATH" , execdir); // aix
385 u_setenv ("LD_LIBRARY_PATH" , execdir); // most elf systems 590 u_setenv ("LD_LIBRARY_PATH" , execdir); // most elf systems
386 u_setenv ("LD_LIBRARY_PATH_32", execdir); // solaris 591 u_setenv ("LD_LIBRARY_PATH_32", execdir); // solaris
387 u_setenv ("LD_LIBRARY_PATH_64", execdir); // solaris 592 u_setenv ("LD_LIBRARY_PATH_64", execdir); // solaris
388 u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix 593 u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix
389 u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix 594 u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix
390 u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple 595 u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple
596#endif
597}
598
599static void
600execute (void)
601{
602 exe_argv [exe_argc] = 0;
603 systemv (exe_argv);
391} 604}
392 605
393#ifdef _WIN32 606#ifdef _WIN32
394 607
395int APIENTRY 608int APIENTRY
396WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show) 609WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show)
397{ 610{
398 if (!GetModuleFileName (hI, tmppath, sizeof (tmppath))) 611 if (!GetModuleFileName (hI, tmppath, sizeof (tmppath)))
399 fatal ("unable to find executable pack"); 612 fatal ("unable to find executable pack");
400 613
401 if (!(pack_handle = u_open (tmppath))) 614 pack_handle = u_open (tmppath);
615 if (!u_valid (pack_handle))
402 fatal ("unable to open executable pack"); 616 fatal ("unable to open executable pack");
403 617
404 exe_info (); 618 exe_info ();
405 619
406 if (!GetCurrentDirectory (sizeof (currdir), currdir)) 620 if (!GetCurrentDirectory (sizeof (currdir), currdir))
423int 637int
424main (int argc, char *argv[]) 638main (int argc, char *argv[])
425{ 639{
426 char *home = getenv ("HOME"); 640 char *home = getenv ("HOME");
427 641
428 // we assume fd 0 and 2 are "normal"
429
430 if (!(pack_handle = u_open (argv [0]))) 642 pack_handle = u_open (argv [0]);
643 if (!u_valid (pack_handle))
431 fatal ("unable to open executable pack"); 644 fatal ("unable to open executable pack");
432 645
433 exe_info (); 646 exe_info ();
434 647
435 if (!home) 648 if (!home)
444 657
445 if (!getcwd (currdir, sizeof (currdir))) 658 if (!getcwd (currdir, sizeof (currdir)))
446 strcpy (currdir, "."); 659 strcpy (currdir, ".");
447 660
448 u_mkdir (home); 661 u_mkdir (home);
662 //strcat (strcat (strcpy (datadir, home), "/."), URLADER);
449 sprintf (datadir, "%s/.%s", home, URLADER); 663 sprintf (datadir, "%s/.%s", home, URLADER);
450 u_mkdir (datadir); 664 u_mkdir (datadir);
451 665
666#if 0
452 if (gethostname (tmppath, sizeof (tmppath))) 667 if (gethostname (tmppath, sizeof (tmppath)))
453 strcpy (tmppath, "default"); 668 strcpy (tmppath, "default");
454 669
455 u_append (datadir, tmppath); 670 u_append (datadir, tmppath);
671#endif
456 672
457 load (); 673 load ();
458 execute (); 674 execute ();
459 675
460 return 0; 676 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines