diff options
| author | 2009-08-19 01:37:38 +0200 | |
|---|---|---|
| committer | 2009-08-19 03:56:09 +0200 | |
| commit | 3a6f72edfb352ab57f58fb4fe4b6314daaddb362 (patch) | |
| tree | c9fc4ae663e0bf38ea411a31587b021bc4464442 /usbmuxd | |
| parent | 2c5b67950a2a7257d03c57ae6cbc7d8e3f6bcaee (diff) | |
| download | usbmuxd-3a6f72edfb352ab57f58fb4fe4b6314daaddb362.tar.gz usbmuxd-3a6f72edfb352ab57f58fb4fe4b6314daaddb362.tar.bz2 | |
Reorder stuff in main() to be saner
Diffstat (limited to 'usbmuxd')
| -rw-r--r-- | usbmuxd/main.c | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/usbmuxd/main.c b/usbmuxd/main.c index 525e095..182178f 100644 --- a/usbmuxd/main.c +++ b/usbmuxd/main.c | |||
| @@ -373,29 +373,6 @@ int main(int argc, char *argv[]) | |||
| 373 | goto terminate; | 373 | goto terminate; |
| 374 | } | 374 | } |
| 375 | 375 | ||
| 376 | usbmuxd_log(LL_INFO, "Creating socket"); | ||
| 377 | listenfd = create_socket(); | ||
| 378 | if(listenfd < 0) | ||
| 379 | return 1; | ||
| 380 | |||
| 381 | client_init(); | ||
| 382 | device_init(); | ||
| 383 | usbmuxd_log(LL_INFO, "Initializing USB"); | ||
| 384 | if((res = usb_init()) < 0) | ||
| 385 | return 2; | ||
| 386 | usbmuxd_log(LL_INFO, "%d device%s detected", res, (res==1)?"":"s"); | ||
| 387 | |||
| 388 | usbmuxd_log(LL_NOTICE, "Initialization complete"); | ||
| 389 | |||
| 390 | if (!foreground) { | ||
| 391 | if (daemonize() < 0) { | ||
| 392 | fprintf(stderr, "usbmuxd: FATAL: Could not daemonize!\n"); | ||
| 393 | usbmuxd_log(LL_ERROR, "FATAL: Could not daemonize!"); | ||
| 394 | log_disable_syslog(); | ||
| 395 | exit(EXIT_FAILURE); | ||
| 396 | } | ||
| 397 | } | ||
| 398 | |||
| 399 | // now open the lockfile and place the lock | 376 | // now open the lockfile and place the lock |
| 400 | lfd = fopen(lockfile, "w"); | 377 | lfd = fopen(lockfile, "w"); |
| 401 | if (lfd) { | 378 | if (lfd) { |
| @@ -403,13 +380,21 @@ int main(int argc, char *argv[]) | |||
| 403 | lock.l_whence = SEEK_SET; | 380 | lock.l_whence = SEEK_SET; |
| 404 | lock.l_start = 0; | 381 | lock.l_start = 0; |
| 405 | lock.l_len = 0; | 382 | lock.l_len = 0; |
| 406 | if (fcntl(fileno(lfd), F_SETLK, &lock) == -1) { | 383 | if ((res = fcntl(fileno(lfd), F_SETLK, &lock)) < 0) { |
| 407 | usbmuxd_log(LL_FATAL, "Lockfile locking failed!"); | 384 | usbmuxd_log(LL_FATAL, "Lockfile locking failed!"); |
| 408 | log_disable_syslog(); | 385 | goto terminate; |
| 409 | exit(EXIT_FAILURE); | ||
| 410 | } | 386 | } |
| 387 | } else { | ||
| 388 | usbmuxd_log(LL_FATAL, "Lockfile open failed!"); | ||
| 389 | res = -1; | ||
| 390 | goto terminate; | ||
| 411 | } | 391 | } |
| 412 | 392 | ||
| 393 | usbmuxd_log(LL_INFO, "Creating socket"); | ||
| 394 | res = listenfd = create_socket(); | ||
| 395 | if(listenfd < 0) | ||
| 396 | goto terminate; | ||
| 397 | |||
| 413 | // drop elevated privileges | 398 | // drop elevated privileges |
| 414 | if (drop_privileges && (getuid() == 0 || geteuid() == 0)) { | 399 | if (drop_privileges && (getuid() == 0 || geteuid() == 0)) { |
| 415 | struct passwd *pw = getpwnam(drop_user); | 400 | struct passwd *pw = getpwnam(drop_user); |
| @@ -446,6 +431,24 @@ int main(int argc, char *argv[]) | |||
| 446 | usbmuxd_log(LL_NOTICE, "Successfully dropped privileges to '%s'", drop_user); | 431 | usbmuxd_log(LL_NOTICE, "Successfully dropped privileges to '%s'", drop_user); |
| 447 | } | 432 | } |
| 448 | 433 | ||
| 434 | client_init(); | ||
| 435 | device_init(); | ||
| 436 | usbmuxd_log(LL_INFO, "Initializing USB"); | ||
| 437 | if((res = usb_init()) < 0) | ||
| 438 | goto terminate; | ||
| 439 | |||
| 440 | usbmuxd_log(LL_INFO, "%d device%s detected", res, (res==1)?"":"s"); | ||
| 441 | |||
| 442 | usbmuxd_log(LL_NOTICE, "Initialization complete"); | ||
| 443 | |||
| 444 | if (!foreground) { | ||
| 445 | if ((res = daemonize()) < 0) { | ||
| 446 | fprintf(stderr, "usbmuxd: FATAL: Could not daemonize!\n"); | ||
| 447 | usbmuxd_log(LL_FATAL, "Could not daemonize!"); | ||
| 448 | goto terminate; | ||
| 449 | } | ||
| 450 | } | ||
| 451 | |||
| 449 | res = main_loop(listenfd); | 452 | res = main_loop(listenfd); |
| 450 | if(res < 0) | 453 | if(res < 0) |
| 451 | usbmuxd_log(LL_FATAL, "main_loop failed"); | 454 | usbmuxd_log(LL_FATAL, "main_loop failed"); |
