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.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>
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{
104 if (!u_mkdir (tmppath)) 215 if (!u_mkdir (tmppath))
105 return; 216 return;
106 } 217 }
107} 218}
108 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;
298}
299
109static void 300static void
110systemv (const char *const argv[], int dowait) 301systemv (const char *const argv[])
111{ 302{
112#ifdef _WIN32 303#ifdef _WIN32
113 _spawnv (P_WAIT, argv [0], argv); 304 _spawnv (P_WAIT, argv [0], argv);
114#else 305#else
115 pid_t pid = dowait ? fork () : 0; 306 pid_t pid = fork ();
116 307
117 if (pid < 0) 308 if (pid < 0)
118 fatal ("fork failure"); 309 fatal ("fork failure");
119 310
120 if (!pid) 311 if (!pid)
136 const char *argv[] = { getenv ("COMSPEC"), "/c", "rd", "/s", "/q", buf, 0 }; 327 const char *argv[] = { getenv ("COMSPEC"), "/c", "rd", "/s", "/q", buf, 0 };
137 sprintf (buf, "\"%s\"", path); 328 sprintf (buf, "\"%s\"", path);
138 #else 329 #else
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, 1); 332 systemv (argv);
142} 333}
143 334
144enum 335enum
145{ 336{
146 T_NULL, // 5 337 T_NULL, // 5
147 T_META, // 1 : exe_id, exe_ver 338 T_META, // 1 : exe_id, exe_ver
148 T_ARG, // 2 : arg
149 T_ENV, // 3 : name, value 339 T_ENV, // 2 : name, value
340 T_ARG, // 3 : arg
150 T_DIR, // 4+: path 341 T_DIR, // 4+: path
151 T_FILE, // 4+: path, data 342 T_FILE, // 4+: path, data
152 T_NUM 343 T_NUM
153}; 344};
154 345
174}; 365};
175 366
176static char *pack_base, *pack_end; 367static char *pack_base, *pack_end;
177static struct hdr *pack_cur; 368static struct hdr *pack_cur;
178static char *scratch; 369static char *scratch;
179static unsigned int scratch_len; 370static unsigned int scratch_size;
180 371
181#define PACK_NAME ((char *)(pack_cur + 1)) 372#define PACK_NAME ((char *)(pack_cur + 1))
182#define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1) 373#define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1)
183#define PACK_VALID pack_cur->type 374#define PACK_VALID pack_cur->type
184 375
191} 382}
192 383
193static void 384static void
194pack_unmap (void) 385pack_unmap (void)
195{ 386{
196 if (!pack_base) 387 if (pack_base)
197 return; 388 {
198
199 free (scratch);
200
201#ifdef _WIN32
202 UnmapViewOfFile (pack_base);
203#else
204 munmap (pack_base, pack_end - pack_base); 389 u_munmap (pack_base, pack_end - pack_base);
205#endif 390 pack_base = 0;
391 }
392
393 if (scratch)
394 {
395 u_free (scratch, scratch_size);
396 scratch = 0;
397 }
206} 398}
207 399
208static int 400static int
209pack_map (void) 401pack_map (void)
210{ 402{
403 char *addr;
404 unsigned int size;
405
211#ifdef _WIN32 406#ifdef _WIN32
212 BY_HANDLE_FILE_INFORMATION fi; 407 BY_HANDLE_FILE_INFORMATION fi;
213 408
214 if (!GetFileInformationByHandle (pack_handle, &fi)) 409 if (!GetFileInformationByHandle (pack_handle, &fi))
215 return 0; 410 return 0;
216 411
217 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)
218 return 0; 419 return 0;
219 420
220 HANDLE handle = CreateFileMapping (pack_handle, 0, PAGE_READONLY, 0, fi.nFileSizeLow, NULL);
221
222 if (!handle)
223 return 0;
224
225 pack_unmap (); 421 pack_unmap ();
226 422
227 pack_base = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, fi.nFileSizeLow);
228
229 CloseHandle (handle);
230
231 pack_end = pack_base + fi.nFileSizeLow;
232#else
233 off_t len = lseek (pack_handle - 1, 0, SEEK_END);
234
235 pack_unmap ();
236
237 pack_base = mmap (0, len, PROT_READ, MAP_SHARED, pack_handle - 1, 0);
238 if (pack_base == (void *)-1)
239 pack_base = 0; 423 pack_base = addr;
240
241 pack_end = pack_base + len; 424 pack_end = pack_base + size;
242#endif
243
244 if (!pack_base)
245 return 0;
246 425
247 struct tail *tail; 426 struct tail *tail;
248 427
249 tail = (void *)(pack_end - sizeof (*tail)); 428 tail = (void *)(pack_end - sizeof (*tail));
250 429
251 if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1)) 430 if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1))
252 return 0; 431 return 0;
253 432
254 pack_cur = (struct hdr *)(pack_end - u_32 (tail->size)); 433 pack_cur = (struct hdr *)(pack_end - u_32 (tail->size));
255 434
256 free (scratch);
257 scratch = malloc (scratch_len = u_32 (tail->max_filesize)); 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);
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 dlen, len = u_32 (pack_cur->datalen); 533 unsigned int dlen, len = u_32 (pack_cur->datalen);
343 char *data = PACK_DATA; 534 char *data = PACK_DATA;
344 535
345 if (pack_cur->flags & F_LZF) 536 if (pack_cur->flags & F_LZF)
346 if (dlen = lzf_decompress (data, len, scratch, scratch_len)) 537 if (dlen = lzf_decompress (data, len, scratch, scratch_size))
347 { 538 {
348 data = scratch; 539 data = scratch;
349 len = dlen; 540 len = dlen;
350 } 541 }
351 else 542 else
352 fatal ("unable to uncompress file data - pack corrupted?"); 543 fatal ("unable to uncompress file data - pack corrupted?");
353 544
354 if (!h) 545 if (!u_valid (h))
355 fatal ("unable to unpack file from packfile - disk full?"); 546 fatal ("unable to unpack file from packfile - disk full?");
356 547
357 if (u_write (h, data, len) != len) 548 if (u_write (h, data, len) != len)
358 fatal ("unable to unpack file from packfile - disk full?"); 549 fatal ("unable to unpack file from packfile - disk full?");
359 550
551 u_fsync (h);
360 u_close (h); 552 u_close (h);
361 } 553 }
362 break; 554 break;
363 555
364 case T_NULL: 556 case T_NULL:
369 } 561 }
370 562
371done: 563done:
372 if (u_chdir (datadir)) 564 if (u_chdir (datadir))
373 fatal ("unable to change to data directory"); 565 fatal ("unable to change to data directory");
566
567 u_sync ();
374 568
375 if (u_rename (tmppath, execdir)) 569 if (u_rename (tmppath, execdir))
376 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
377 } 571 }
378 572
387 u_setenv ("URLADER_EXECDIR", execdir); 581 u_setenv ("URLADER_EXECDIR", execdir);
388 u_setenv ("URLADER_EXE_ID" , exe_id); 582 u_setenv ("URLADER_EXE_ID" , exe_id);
389 u_setenv ("URLADER_EXE_DIR", exe_dir); 583 u_setenv ("URLADER_EXE_DIR", exe_dir);
390 u_setenv ("URLADER_EXE_VER", exe_ver); 584 u_setenv ("URLADER_EXE_VER", exe_ver);
391 585
586#if 0
392 // yes, this is overkill 587 // yes, this is overkill
393 u_setenv ("SHLIB_PATH" , execdir); // hpux 588 u_setenv ("SHLIB_PATH" , execdir); // hpux
394 u_setenv ("LIBPATH" , execdir); // aix 589 u_setenv ("LIBPATH" , execdir); // aix
395 u_setenv ("LD_LIBRARY_PATH" , execdir); // most elf systems 590 u_setenv ("LD_LIBRARY_PATH" , execdir); // most elf systems
396 u_setenv ("LD_LIBRARY_PATH_32", execdir); // solaris 591 u_setenv ("LD_LIBRARY_PATH_32", execdir); // solaris
397 u_setenv ("LD_LIBRARY_PATH_64", execdir); // solaris 592 u_setenv ("LD_LIBRARY_PATH_64", execdir); // solaris
398 u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix 593 u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix
399 u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix 594 u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix
400 u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple 595 u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple
596#endif
401} 597}
402 598
403static void 599static void
404execute (void) 600execute (void)
405{ 601{
406 exe_argv [exe_argc] = 0; 602 exe_argv [exe_argc] = 0;
407 systemv (exe_argv, 0); 603 systemv (exe_argv);
408} 604}
409 605
410#ifdef _WIN32 606#ifdef _WIN32
411 607
412int APIENTRY 608int APIENTRY
413WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show) 609WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show)
414{ 610{
415 if (!GetModuleFileName (hI, tmppath, sizeof (tmppath))) 611 if (!GetModuleFileName (hI, tmppath, sizeof (tmppath)))
416 fatal ("unable to find executable pack"); 612 fatal ("unable to find executable pack");
417 613
418 if (!(pack_handle = u_open (tmppath))) 614 pack_handle = u_open (tmppath);
615 if (!u_valid (pack_handle))
419 fatal ("unable to open executable pack"); 616 fatal ("unable to open executable pack");
420 617
421 exe_info (); 618 exe_info ();
422 619
423 if (!GetCurrentDirectory (sizeof (currdir), currdir)) 620 if (!GetCurrentDirectory (sizeof (currdir), currdir))
440int 637int
441main (int argc, char *argv[]) 638main (int argc, char *argv[])
442{ 639{
443 char *home = getenv ("HOME"); 640 char *home = getenv ("HOME");
444 641
445 // we assume fd 0 and 2 are "normal"
446
447 if (!(pack_handle = u_open (argv [0]))) 642 pack_handle = u_open (argv [0]);
643 if (!u_valid (pack_handle))
448 fatal ("unable to open executable pack"); 644 fatal ("unable to open executable pack");
449 645
450 exe_info (); 646 exe_info ();
451 647
452 if (!home) 648 if (!home)
461 657
462 if (!getcwd (currdir, sizeof (currdir))) 658 if (!getcwd (currdir, sizeof (currdir)))
463 strcpy (currdir, "."); 659 strcpy (currdir, ".");
464 660
465 u_mkdir (home); 661 u_mkdir (home);
662 //strcat (strcat (strcpy (datadir, home), "/."), URLADER);
466 sprintf (datadir, "%s/.%s", home, URLADER); 663 sprintf (datadir, "%s/.%s", home, URLADER);
467 u_mkdir (datadir); 664 u_mkdir (datadir);
468 665
666#if 0
469 if (gethostname (tmppath, sizeof (tmppath))) 667 if (gethostname (tmppath, sizeof (tmppath)))
470 strcpy (tmppath, "default"); 668 strcpy (tmppath, "default");
471 669
472 u_append (datadir, tmppath); 670 u_append (datadir, tmppath);
671#endif
473 672
474 load (); 673 load ();
475 execute (); 674 execute ();
476 675
477 return 0; 676 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines