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

Comparing Urlader/urlader.c (file contents):
Revision 1.7 by root, Fri Dec 30 14:51:45 2011 UTC vs.
Revision 1.12 by root, Fri Jan 6 07:56:36 2012 UTC

1#ifndef URLADER 1#include "urlib.h"
2# define URLADER "urlader" 2#include "urlib.c"
3#endif
4#define URLADER_VERSION "1.0" // a decimal number, not a version string
5
6#define MAX_ARGC 32
7#define MAX_ARGS 256
8 3
9#include <stdio.h> 4#include <stdio.h>
10#include <stdlib.h> 5#include <stdlib.h>
11#include <unistd.h> 6#include <unistd.h>
12#include <errno.h> 7#include <errno.h>
13#include <string.h> 8#include <string.h>
14#include <time.h> 9#include <time.h>
15#include <fcntl.h>
16 10
17#include "liblzf/lzf_d.c" 11#include "liblzf/lzf_d.c"
18
19#define TAIL_MAGIC "SCHMORPPACK0"
20
21#ifdef _WIN32
22
23 #include <windows.h>
24 //#include <winbase.h>
25 #include <shlobj.h>
26 #include <shlwapi.h>
27 #include <wininet.h>
28
29 static DWORD dword;
30
31 #define u_handle HANDLE
32 #define u_invalid_handle 0
33 #define u_valid(handle) (!!handle)
34
35 #define u_setenv(name,value) SetEnvironmentVariable (name, value)
36 #define u_mkdir(path) !CreateDirectory (path, NULL)
37 #define u_chdir(path) !SetCurrentDirectory (path)
38 #define u_rename(fr,to) !MoveFile (fr, to)
39 #define u_open(path) CreateFile (path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 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)
42 #define u_close(handle) CloseHandle (handle)
43 #define u_append(path,add) PathAppend (path, add)
44 #define u_write(handle,data,len) (WriteFile (handle, data, len, &dword, 0) ? dword : -1)
45
46 #define u_fsync(handle) FlushFileBuffers (handle)
47 #define u_sync()
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
58 #include <sys/mman.h>
59 #include <sys/types.h>
60 #include <sys/stat.h>
61 #include <unistd.h>
62 #include <pwd.h>
63
64 #if defined (MAP_ANON) && !defined (MAP_ANONYMOUS)
65 #define MAP_ANONYMOUS MAP_ANON
66 #endif
67
68 #ifdef PATH_MAX
69 #define MAX_PATH (PATH_MAX < 4096 ? 4096 : PATH_MAX)
70 #else
71 #define MAX_PATH 4096
72 #endif
73
74 #define u_handle int
75 #define u_invalid_handle -1
76 #define u_valid(fd) ((fd) >= 0)
77
78 #define u_setenv(name,value) setenv (name, value, 1)
79 #define u_mkdir(path) mkdir (path, 0777)
80 #define u_chdir(path) chdir (path)
81 #define u_rename(fr,to) rename (fr, to)
82 #define u_open(path) open (path, O_RDONLY)
83 #define u_creat(path,exec) open (path, O_WRONLY | O_CREAT | O_TRUNC, (exec) ? 0777 : 0666)
84 #define u_close(handle) close (handle)
85 #define u_append(path,add) strcat (strcat (path, "/"), add)
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)
94
95#endif
96
97#define u_16(ptr) (((ptr)[0] << 8) | (ptr)[1])
98#define u_32(ptr) (((ptr)[0] << 24) | ((ptr)[1] << 16) | ((ptr)[2] << 8) | (ptr)[3])
99 12
100/* some simple? dynamic memory management for paths might save ltos of ram */ 13/* some simple? dynamic memory management for paths might save ltos of ram */
101static u_handle pack_handle; 14static u_handle pack_handle;
102static u_handle lock_handle; 15static u_handle lock_handle;
103static char tmppath[MAX_PATH]; 16static char tmppath[MAX_PATH];
104static char currdir[MAX_PATH];
105static char datadir[MAX_PATH]; // %AppData%/urlader
106static char exe_dir[MAX_PATH]; // %AppData%/urlader/EXE_ID
107static char execdir[MAX_PATH]; // %AppData%/urlader/EXE_ID/EXE_VER
108static char exe_id[MAX_PATH];
109static char exe_ver[MAX_PATH];
110 17
111static int exe_argc; 18static int exe_argc;
112static const char *exe_argv[MAX_ARGC]; 19static u_dynbuf exe_argv;
113static char exe_args[MAX_ARGS]; /* actual arguments strings copied here */ 20static u_dynbuf exe_args; /* actual arguments strings copied here */
114static unsigned int exe_argo;
115
116static void
117fatal (const char *msg)
118{
119#ifdef _WIN32
120 MessageBox (0, msg, URLADER, 0);
121#else
122 write (2, URLADER ": ", sizeof (URLADER ": ") - 1);
123 write (2, msg, strlen (msg));
124 write (2, "\n", 1);
125#endif
126
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
200}
201 21
202static void 22static void
203tmpdir (const char *dir) 23tmpdir (const char *dir)
204{ 24{
205 static int cnt; 25 static int cnt;
215 if (!u_mkdir (tmppath)) 35 if (!u_mkdir (tmppath))
216 return; 36 return;
217 } 37 }
218} 38}
219 39
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
300static void 40static void
301systemv (const char *const argv[]) 41systemv (const char *const argv[])
302{ 42{
303#ifdef _WIN32 43#ifdef _WIN32
304 _spawnv (P_WAIT, argv [0], argv); 44 _spawnv (P_WAIT, argv [0], argv);
305#else 45#else
306 pid_t pid = fork (); 46 pid_t pid = fork ();
307 47
308 if (pid < 0) 48 if (pid < 0)
309 fatal ("fork failure"); 49 u_fatal ("fork failure");
310 50
311 if (!pid) 51 if (!pid)
312 { 52 {
313 execv (argv [0], (void *)argv); 53 execv (argv [0], (void *)argv);
314 _exit (124); 54 _exit (124);
330 const char *argv[] = { "/bin/rm", "-rf", path, 0 }; 70 const char *argv[] = { "/bin/rm", "-rf", path, 0 };
331 #endif 71 #endif
332 systemv (argv); 72 systemv (argv);
333} 73}
334 74
335enum
336{
337 T_NULL, // 5
338 T_META, // 1 : exe_id, exe_ver
339 T_ENV, // 2 : name, value
340 T_ARG, // 3 : arg
341 T_DIR, // 4+: path
342 T_FILE, // 4+: path, data
343 T_NUM
344};
345
346enum
347{
348 F_EXEC = 1,
349 F_LZF = 2,
350 F_NULL = 0
351};
352
353struct hdr
354{
355 unsigned char type;
356 unsigned char flags;
357 unsigned char namelen[2];
358 unsigned char datalen[4];
359};
360
361struct tail {
362 unsigned char max_filesize[4];
363 unsigned char size[4];
364 char magic[12];
365};
366
367static char *pack_base, *pack_end; 75static char *pack_base, *pack_end;
76static struct u_pack_tail *pack_tail;
368static struct hdr *pack_cur; 77static struct u_pack_hdr *pack_cur;
369static char *scratch; 78static char *scratch;
370static unsigned int scratch_size; 79static unsigned int scratch_size;
371 80
372#define PACK_NAME ((char *)(pack_cur + 1)) 81#define PACK_NAME ((char *)(pack_cur + 1))
373#define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1) 82#define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1)
376static void 85static void
377pack_next (void) 86pack_next (void)
378{ 87{
379 unsigned int d = u_32 (pack_cur->datalen); 88 unsigned int d = u_32 (pack_cur->datalen);
380 89
381 pack_cur = (struct hdr *)(PACK_DATA + d); 90 pack_cur = (struct u_pack_hdr *)(PACK_DATA + d);
382} 91}
383 92
384static void 93static void
385pack_unmap (void) 94pack_unmap (void)
386{ 95{
416 125
417 addr = u_mmap (pack_handle, size); 126 addr = u_mmap (pack_handle, size);
418 if (!addr) 127 if (!addr)
419 return 0; 128 return 0;
420 129
421 pack_unmap (); 130 /*pack_unmap ();*/
422 131
423 pack_base = addr; 132 pack_base = addr;
424 pack_end = pack_base + size; 133 pack_end = pack_base + size;
425 134
426 struct tail *tail;
427
428 tail = (void *)(pack_end - sizeof (*tail)); 135 pack_tail = (void *)(pack_end - sizeof (*pack_tail));
429 136
430 if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1)) 137 if (memcmp (pack_tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1))
431 return 0; 138 return 0;
432 139
433 pack_cur = (struct hdr *)(pack_end - u_32 (tail->size)); 140 pack_cur = (struct u_pack_hdr *)(pack_end - u_32 (pack_tail->size));
434 141
142 if (pack_cur->type != T_META)
143 return 0;
144
435 scratch = u_malloc (scratch_size = u_32 (tail->max_filesize)); 145 scratch = u_malloc (scratch_size = u_32 (pack_tail->max_uncompressed));
436 if (!scratch) 146 if (!scratch)
437 return 0; 147 return 0;
438 148
439 return 1; 149 return 1;
440} 150}
441 151
442static void 152static void
443exe_info (void) 153add_arg (char *arg, unsigned int len)
444{ 154{
445 if (!pack_map ()) 155 char *addr = u_dynbuf_append (&exe_args, arg, len);
446 fatal ("unable to locate packfile in executable - executable corrupted?"); 156 u_dynbuf_append (&exe_argv, &addr, sizeof (addr));
447
448 if (pack_cur->type != T_META)
449 fatal ("unable to locate executable metadata - executable corrupted?");
450
451 strcpy (exe_id, PACK_NAME);
452} 157}
453 158
454static void 159static void
455load (void) 160load (void)
456{ 161{
457 u_mkdir (datadir); 162 strcpy (exe_id , PACK_NAME);
458 163 strcpy (exe_ver, PACK_DATA);
459 strcpy (exe_dir, datadir); 164 u_set_exe_info ();
460 u_append (exe_dir, exe_id);
461 u_mkdir (exe_dir);
462 165
463 if (u_chdir (exe_dir)) 166 if (u_chdir (exe_dir))
464 fatal ("unable to change to application data directory"); 167 u_fatal ("unable to change to application data directory");
465 168
466 u_handle h = u_open ("override"); 169 u_handle h = u_open ("override");
467 if (u_valid (h)) 170 if (u_valid (h))
468 { 171 {
469 u_handle oh = pack_handle; 172 u_handle oh = pack_handle;
470 173
174 pack_unmap ();
471 pack_handle = h; 175 pack_handle = h;
176
472 if (!pack_map ()) 177 if (pack_map ()
178 && strcmp (exe_id , PACK_NAME) == 0
179 && strcmp (exe_ver, PACK_DATA) <= 0)
180 u_setenv ("URLADER_OVERRIDE", "override");
181 else
473 { 182 {
183 pack_unmap ();
474 pack_handle = oh; 184 pack_handle = oh;
475 oh = h; 185 oh = h;
186 pack_map ();
476 } 187 }
477 188
478 u_close (oh); 189 u_close (oh);
479 } 190 }
480 191
481 if (pack_cur->type != T_META)
482 fatal ("unable to locate override metadata");
483
484 strcpy (exe_ver, PACK_DATA); 192 strcpy (exe_ver, PACK_DATA);
193 u_set_exe_info ();
485 pack_next (); 194 pack_next ();
486 195
487 for (;;) 196 for (;;)
488 { 197 {
489 if (pack_cur->type == T_ENV) 198 if (pack_cur->type == T_ENV)
490 u_setenv (PACK_NAME, PACK_DATA); 199 u_setenv (PACK_NAME, PACK_DATA);
491 else if (pack_cur->type == T_ARG) 200 else if (pack_cur->type == T_ARG)
492 { 201 add_arg (PACK_NAME, u_16 (pack_cur->namelen) + 1);
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 202 else
499 break; 203 break;
500 204
501 pack_next (); 205 pack_next ();
502 } 206 }
503 207
504done_env_arg: 208done_env_arg:
505 strcpy (execdir, exe_dir);
506 u_append (execdir, "i-");
507 strcat (execdir, exe_ver);
508 209
509 strcat (strcpy (tmppath, execdir), ".lck"); 210 strcat (strcpy (tmppath, execdir), ".lck");
510 lock_handle = u_lock (tmppath, 0, 1); 211 lock_handle = u_lock (tmppath, 0, 1);
511 if (!lock_handle) 212 if (!lock_handle)
512 fatal ("unable to lock application instance"); 213 u_fatal ("unable to lock application instance");
513 214
514 if (access (execdir, F_OK)) 215 if (access (execdir, F_OK))
515 { 216 {
516 // does not exist yet, so unpack and move 217 // does not exist yet, so unpack and move
517 tmpdir (exe_dir); 218 tmpdir (exe_dir);
518 219
519 if (u_chdir (tmppath)) 220 if (u_chdir (tmppath))
520 fatal ("unable to change to new instance directory"); 221 u_fatal ("unable to change to new instance directory");
521 222
522 for (;;) 223 for (;;)
523 { 224 {
524 switch (pack_cur->type) 225 switch (pack_cur->type)
525 { 226 {
538 { 239 {
539 data = scratch; 240 data = scratch;
540 len = dlen; 241 len = dlen;
541 } 242 }
542 else 243 else
543 fatal ("unable to uncompress file data - pack corrupted?"); 244 u_fatal ("unable to uncompress file data - pack corrupted?");
544 245
545 if (!u_valid (h)) 246 if (!u_valid (h))
546 fatal ("unable to unpack file from packfile - disk full?"); 247 u_fatal ("unable to unpack file from packfile - disk full?");
547 248
548 if (u_write (h, data, len) != len) 249 if (u_write (h, data, len) != len)
549 fatal ("unable to unpack file from packfile - disk full?"); 250 u_fatal ("unable to unpack file from packfile - disk full?");
550 251
551 u_fsync (h); 252 u_fsync (h);
552 u_close (h); 253 u_close (h);
553 } 254 }
554 break; 255 break;
560 pack_next (); 261 pack_next ();
561 } 262 }
562 263
563done: 264done:
564 if (u_chdir (datadir)) 265 if (u_chdir (datadir))
565 fatal ("unable to change to data directory"); 266 u_fatal ("unable to change to data directory");
566 267
567 u_sync (); 268 u_sync ();
568 269
569 if (u_rename (tmppath, execdir)) 270 if (u_rename (tmppath, execdir))
570 deltree (tmppath); // if move fails, delete new, assume other process created it independently 271 deltree (tmppath); // if move fails, delete new, assume other process created it independently
572 273
573 pack_unmap (); 274 pack_unmap ();
574 u_close (pack_handle); 275 u_close (pack_handle);
575 276
576 if (u_chdir (execdir)) 277 if (u_chdir (execdir))
577 fatal ("unable to change to application instance directory"); 278 u_fatal ("unable to change to application instance directory");
578 279
579 u_setenv ("URLADER_VERSION", URLADER_VERSION); 280 u_setenv ("URLADER_VERSION", URLADER_VERSION);
580 u_setenv ("URLADER_DATADIR", datadir);
581 u_setenv ("URLADER_EXECDIR", execdir);
582 u_setenv ("URLADER_EXE_ID" , exe_id);
583 u_setenv ("URLADER_EXE_DIR", exe_dir);
584 u_setenv ("URLADER_EXE_VER", exe_ver);
585 281
586#if 0 282#if 0
587 // yes, this is overkill 283 // yes, this is overkill
588 u_setenv ("SHLIB_PATH" , execdir); // hpux 284 u_setenv ("SHLIB_PATH" , execdir); // hpux
589 u_setenv ("LIBPATH" , execdir); // aix 285 u_setenv ("LIBPATH" , execdir); // aix
597} 293}
598 294
599static void 295static void
600execute (void) 296execute (void)
601{ 297{
602 exe_argv [exe_argc] = 0; 298 char *null = 0;
603 systemv (exe_argv); 299 u_dynbuf_append (&exe_argv, &null, sizeof (null));
300 systemv ((const char *const *)exe_argv.addr);
301}
302
303// this argc/argv is without argv [0]
304static void
305doit (int argc, char *argv[])
306{
307 int i;
308
309 u_setenv ("URLADER_CURRDIR", currdir);
310
311 u_set_datadir ();
312 u_mkdir (datadir);
313
314 if (!pack_map ())
315 u_fatal ("unable to map pack file - executable corrupted?");
316
317 load ();
318
319 while (argc--)
320 {
321 add_arg (*argv, strlen (*argv) + 1);
322 ++argv;
323 }
324
325 execute ();
604} 326}
605 327
606#ifdef _WIN32 328#ifdef _WIN32
607 329
608int APIENTRY 330int APIENTRY
609WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show) 331WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show)
610{ 332{
611 if (!GetModuleFileName (hI, tmppath, sizeof (tmppath))) 333 if (!GetModuleFileName (hI, tmppath, sizeof (tmppath)))
612 fatal ("unable to find executable pack"); 334 u_fatal ("unable to find executable pack");
335
336 u_setenv ("URLADER_EXEPATH", tmppath);
613 337
614 pack_handle = u_open (tmppath); 338 pack_handle = u_open (tmppath);
615 if (!u_valid (pack_handle)) 339 if (!u_valid (pack_handle))
616 fatal ("unable to open executable pack"); 340 u_fatal ("unable to open executable pack");
617
618 exe_info ();
619 341
620 if (!GetCurrentDirectory (sizeof (currdir), currdir)) 342 if (!GetCurrentDirectory (sizeof (currdir), currdir))
621 strcpy (currdir, "."); 343 strcpy (currdir, ".");
622 344
623 if (SHGetFolderPath (0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, datadir) != S_OK) 345 doit (1, &argv);
624 fatal ("unable to find application data directory");
625
626 u_mkdir (datadir);
627 u_append (datadir, URLADER);
628
629 load ();
630 execute ();
631 346
632 return 0; 347 return 0;
633} 348}
634 349
635#else 350#else
636 351
637int 352int
638main (int argc, char *argv[]) 353main (int argc, char *argv[])
639{ 354{
640 char *home = getenv ("HOME"); 355 u_setenv ("URLADER_EXEPATH", argv [0]);
641 356
642 pack_handle = u_open (argv [0]); 357 pack_handle = u_open (argv [0]);
643 if (!u_valid (pack_handle)) 358 if (!u_valid (pack_handle))
644 fatal ("unable to open executable pack"); 359 u_fatal ("unable to open executable pack");
645
646 exe_info ();
647
648 if (!home)
649 {
650 struct passwd *pw;
651
652 if ((pw = getpwuid (getuid ())))
653 home = pw->pw_dir;
654 else
655 home = "/tmp";
656 }
657 360
658 if (!getcwd (currdir, sizeof (currdir))) 361 if (!getcwd (currdir, sizeof (currdir)))
659 strcpy (currdir, "."); 362 strcpy (currdir, ".");
660 363
661 u_mkdir (home);
662 //strcat (strcat (strcpy (datadir, home), "/."), URLADER);
663 sprintf (datadir, "%s/.%s", home, URLADER);
664 u_mkdir (datadir);
665
666#if 0 364#if 0
365 /* intersperse hostname, for whatever reason */
366
667 if (gethostname (tmppath, sizeof (tmppath))) 367 if (gethostname (tmppath, sizeof (tmppath)))
668 strcpy (tmppath, "default"); 368 strcpy (tmppath, "default");
669 369
670 u_append (datadir, tmppath); 370 u_append (datadir, tmppath);
671#endif 371#endif
672 372
673 load (); 373 doit (argc - 1, argv + 1);
674 execute ();
675 374
676 return 0; 375 return 0;
677} 376}
678 377
679#endif 378#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines