~ubuntu-branches/ubuntu/quantal/libbonobo/quantal-201207170711

« back to all changes in this revision

Viewing changes to activation-server/activation-server-main.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2009-03-06 18:53:16 UTC
  • mfrom: (1.1.25 upstream) (3.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090306185316-uf09r30g7cvf67xi
Tags: 2.24.1-1
* New upstream bugfix release.
* debian/control.in:
  + Build depend on GLib >= 2.14.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
#include <dbus/dbus-glib-lowlevel.h>
59
59
#endif
60
60
 
 
61
#ifdef G_OS_WIN32
 
62
#include <io.h>
 
63
#include <conio.h>
 
64
#define _WIN32_WINNT 0x0500 
 
65
#include <windows.h>
 
66
 
 
67
static gboolean allocated_new_console = FALSE;
 
68
 
 
69
#endif
 
70
 
61
71
static gboolean        server_threaded = FALSE;
62
72
static glong           server_guard_depth = 0;
63
73
static GStaticRecMutex server_guard = G_STATIC_REC_MUTEX_INIT;
245
255
        return real_od_source_dir;
246
256
}
247
257
 
 
258
#ifdef G_OS_WIN32
 
259
 
 
260
static void
 
261
wait_console_key (void)
 
262
{
 
263
        SetConsoleTitle ("Bonobo activation server exiting. Type any character to close this window.");
 
264
        printf ("\n"
 
265
                "(Bonobo activation server exiting. Type any character to close this window)\n");
 
266
        _getch ();
 
267
}
 
268
 
 
269
#endif
 
270
 
248
271
static void
249
272
log_handler (const gchar *log_domain,
250
273
             GLogLevelFlags log_level,
299
322
        if (log_level & G_LOG_FLAG_FATAL) {
300
323
                fprintf (stderr, "%s%s", message,
301
324
                         (message[strlen (message) - 1] == '\n' ? "" : "\n"));
 
325
#ifdef G_OS_WIN32
 
326
                if (allocated_new_console)
 
327
                        wait_console_key ();
 
328
#endif
302
329
                _exit (1);
303
330
        }
304
331
 
411
438
 
412
439
#endif
413
440
 
 
441
#ifdef G_OS_WIN32
 
442
 
 
443
static void
 
444
ensure_output_visible (gboolean asked_for_it)
 
445
{
 
446
        if (fileno (stdout) != -1 &&
 
447
            _get_osfhandle (fileno (stdout)) != -1)
 
448
                return;
 
449
 
 
450
        typedef BOOL (* WINAPI AttachConsole_t) (DWORD);
 
451
 
 
452
        AttachConsole_t p_AttachConsole =
 
453
                (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole");
 
454
 
 
455
        if (p_AttachConsole != NULL) {
 
456
                if (!AttachConsole (ATTACH_PARENT_PROCESS)) {
 
457
                        if (AllocConsole ())
 
458
                                allocated_new_console = TRUE;
 
459
                }
 
460
 
 
461
                freopen ("CONOUT$", "w", stdout);
 
462
                dup2 (fileno (stdout), 1);
 
463
                freopen ("CONOUT$", "w", stderr);
 
464
                dup2 (fileno (stderr), 2);
 
465
 
 
466
                if (allocated_new_console) {
 
467
                        SetConsoleTitle ("Bonobo activation server output. You can minimize this window, but don't close it.");
 
468
                        if (asked_for_it)
 
469
                                printf ("You asked for debugging output by setting the BONOBO_ACTIVATION_DEBUG_OUTPUT\n"
 
470
                                        "environment variable, so here it is.\n"
 
471
                                        "\n");
 
472
                        atexit (wait_console_key);
 
473
                }
 
474
        }
 
475
}
 
476
 
 
477
#endif
 
478
 
414
479
int
415
480
main (int argc, char *argv[])
416
481
{
464
529
 
465
530
        g_thread_init (NULL);
466
531
 
 
532
#ifdef BONOBO_ACTIVATION_DEBUG
 
533
        debug_output_env = g_getenv ("BONOBO_ACTIVATION_DEBUG_OUTPUT");
 
534
        if (debug_output_env && debug_output_env[0] != '\0') {
 
535
                output_debug = TRUE;
 
536
#ifdef G_OS_WIN32
 
537
                ensure_output_visible (TRUE);
 
538
#endif
 
539
        }
 
540
#endif
 
541
 
467
542
        g_set_prgname ("bonobo-activation-server");
468
543
        ctx = g_option_context_new (NULL);
469
544
        g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
477
552
        LIBXML_TEST_VERSION;
478
553
        xmlKeepBlanksDefault(0);
479
554
 
480
 
#if 0
481
 
        while (!g_file_test ("/tmp/orbit-go", G_FILE_TEST_EXISTS))
482
 
                sleep (1);
483
 
#endif
484
 
 
485
555
#ifdef HAVE_SYSLOG_H
486
556
        syslog_ident = g_strdup_printf ("bonobo-activation-server (%s-%u)", g_get_user_name (), (guint) getpid ());
487
557
 
489
559
        openlog (syslog_ident, 0, LOG_USER);
490
560
#endif
491
561
 
492
 
#ifdef BONOBO_ACTIVATION_DEBUG
493
 
        debug_output_env = g_getenv ("BONOBO_ACTIVATION_DEBUG_OUTPUT");
494
 
        if (debug_output_env && debug_output_env[0] != '\0')
495
 
                output_debug = TRUE;
496
 
#endif
497
562
        if (server_reg)
498
563
                output_debug = TRUE;
499
564
 
554
619
        if (existing != CORBA_OBJECT_NIL)
555
620
                CORBA_Object_release (existing, NULL);
556
621
 
557
 
        if (ior_fd < 0 && !server_ac && !server_reg)
558
 
                g_critical ("\n\n-- \nThe bonobo-activation-server must be forked by\n"
559
 
                            "libbonobo-activation, and cannot be run itself.\n"
 
622
        if (ior_fd < 0 && !server_ac && !server_reg) {
 
623
#ifdef G_OS_WIN32
 
624
                ensure_output_visible (FALSE);
 
625
#endif
 
626
                g_critical ("\n\n-- \nThe bonobo-activation-server must be started by\n"
 
627
                            "libbonobo-activation, and cannot be run by itself.\n"
560
628
                            "This is due to us doing client side locking.\n-- \n");
 
629
        }
561
630
 
562
631
        if (server_reg) {
563
632
                g_warning ("Running in user-forked debugging mode");