~ubuntu-branches/ubuntu/precise/network-manager/precise

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-02-09 16:45:41 UTC
  • mfrom: (1.1.53)
  • Revision ID: package-import@ubuntu.com-20120209164541-4h90zknlsfdb7x35
Tags: 0.9.2.0+git201202091925.c721477-0ubuntu1
* upstream snapshot 2012-02-09 19:25:59 (GMT)
  + c721477d11d4fe144111d6d2eec8f93f2e9186c9
* debian/patches/avoid-periodic-disk-wakeups.patch: refreshed.
* debian/patches/nl3-default-ip6-route.patch: refreshed.
* debian/libnm-glib4.symbols: add symbols:
  + nm_active_connection_get_master@Base
  + nm_client_new_async@Base
  + nm_client_new_finish@Base
  + nm_remote_settings_new_async@Base
  + nm_remote_settings_new_finish@Base
  + nm_device_get_state_reason@Base
* debian/libnm-util2.symbols: add symbols:
  + nm_setting_802_1x_get_pac_file@Base
  + nm_setting_infiniband_get_transport_mode@Base

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 * with this program; if not, write to the Free Software Foundation, Inc.,
16
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
17
 *
18
 
 * Copyright (C) 2004 - 2011 Red Hat, Inc.
 
18
 * Copyright (C) 2004 - 2012 Red Hat, Inc.
19
19
 * Copyright (C) 2005 - 2008 Novell, Inc.
20
20
 */
21
21
 
25
25
#include <dbus/dbus-glib-lowlevel.h>
26
26
#include <dbus/dbus-glib.h>
27
27
#include <getopt.h>
 
28
#include <locale.h>
28
29
#include <errno.h>
29
30
#include <stdlib.h>
30
31
#include <signal.h>
139
140
 
140
141
        /* Set up our quit pipe */
141
142
        if (pipe (quit_pipe) < 0) {
142
 
                fprintf (stderr, "Failed to initialze SIGTERM pipe: %d", errno);
 
143
                fprintf (stderr, _("Failed to initialize SIGTERM pipe: %d"), errno);
143
144
                exit (1);
144
145
        }
145
146
        fcntl (quit_pipe[1], F_SETFL, O_NONBLOCK | fcntl (quit_pipe[1], F_GETFL));
165
166
        gboolean success = FALSE;
166
167
 
167
168
        if ((fd = open (pidfile, O_CREAT|O_WRONLY|O_TRUNC, 00644)) < 0) {
168
 
                fprintf (stderr, "Opening %s failed: %s\n", pidfile, strerror (errno));
 
169
                fprintf (stderr, _("Opening %s failed: %s\n"), pidfile, strerror (errno));
169
170
                return FALSE;
170
171
        }
171
172
 
172
173
        snprintf (pid, sizeof (pid), "%d", getpid ());
173
174
        if (write (fd, pid, strlen (pid)) < 0)
174
 
                fprintf (stderr, "Writing to %s failed: %s\n", pidfile, strerror (errno));
 
175
                fprintf (stderr, _("Writing to %s failed: %s\n"), pidfile, strerror (errno));
175
176
        else
176
177
                success = TRUE;
177
178
 
178
179
        if (close (fd))
179
 
                fprintf (stderr, "Closing %s failed: %s\n", pidfile, strerror (errno));
 
180
                fprintf (stderr, _("Closing %s failed: %s\n"), pidfile, strerror (errno));
180
181
 
181
182
        return success;
182
183
}
219
220
        if (strcmp (process_name, "NetworkManager") == 0) {
220
221
                /* Check that the process exists */
221
222
                if (kill (pid, 0) == 0) {
222
 
                        fprintf (stderr, "NetworkManager is already running (pid %ld)\n", pid);
 
223
                        fprintf (stderr, _("NetworkManager is already running (pid %ld)\n"), pid);
223
224
                        nm_running = TRUE;
224
225
                }
225
226
        }
356
357
        gboolean wrote_pidfile = FALSE;
357
358
 
358
359
        GOptionEntry options[] = {
359
 
                { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, "Print NetworkManager version and exit", NULL },
360
 
                { "no-daemon", 0, 0, G_OPTION_ARG_NONE, &become_daemon, "Don't become a daemon", NULL },
361
 
                { "g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, "Make all warnings fatal", NULL },
362
 
                { "pid-file", 0, 0, G_OPTION_ARG_FILENAME, &pidfile, "Specify the location of a PID file", "filename" },
363
 
                { "state-file", 0, 0, G_OPTION_ARG_FILENAME, &state_file, "State file location", "/path/to/state.file" },
364
 
                { "config", 0, 0, G_OPTION_ARG_FILENAME, &config_path, "Config file location", "/path/to/config.file" },
365
 
                { "plugins", 0, 0, G_OPTION_ARG_STRING, &plugins, "List of plugins separated by ','", "plugin1,plugin2" },
366
 
                { "log-level", 0, 0, G_OPTION_ARG_STRING, &log_level, "Log level: one of [ERR, WARN, INFO, DEBUG]", "INFO" },
 
360
                { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Print NetworkManager version and exit"), NULL },
 
361
                { "no-daemon", 0, 0, G_OPTION_ARG_NONE, &become_daemon, N_("Don't become a daemon"), NULL },
 
362
                { "g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, N_("Make all warnings fatal"), NULL },
 
363
                { "pid-file", 0, 0, G_OPTION_ARG_FILENAME, &pidfile, N_("Specify the location of a PID file"), N_("filename") },
 
364
                { "state-file", 0, 0, G_OPTION_ARG_FILENAME, &state_file, N_("State file location"), N_("/path/to/state.file") },
 
365
                { "config", 0, 0, G_OPTION_ARG_FILENAME, &config_path, N_("Config file location"), N_("/path/to/config.file") },
 
366
                { "plugins", 0, 0, G_OPTION_ARG_STRING, &plugins, N_("List of plugins separated by ','"), N_("plugin1,plugin2") },
 
367
                /* Translators: Do not translate the values in the square brackets */
 
368
                { "log-level", 0, 0, G_OPTION_ARG_STRING, &log_level, N_("Log level: one of [ERR, WARN, INFO, DEBUG]"), "INFO" },
367
369
                { "log-domains", 0, 0, G_OPTION_ARG_STRING, &log_domains,
368
 
                        "Log domains separated by ',': any combination of\n"
 
370
                        /* Translators: Do not translate the values in the square brackets */
 
371
                        N_("Log domains separated by ',': any combination of\n"
369
372
                        "                                          [NONE,HW,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,\n"
370
373
                        "                                           WIFI_SCAN,IP4,IP6,AUTOIP4,DNS,VPN,SHARING,SUPPLICANT,\n"
371
374
                        "                                           AGENTS,SETTINGS,SUSPEND,CORE,DEVICE,OLPC,WIMAX,\n"
372
 
                        "                                           INFINIBAND,FIREWALL]",
 
375
                        "                                           INFINIBAND,FIREWALL]"),
373
376
                        "HW,RFKILL,WIFI" },
374
377
                {NULL}
375
378
        };
376
379
 
377
380
        if (!g_module_supported ()) {
378
 
                fprintf (stderr, "GModules are not supported on your platform!\n");
 
381
                fprintf (stderr, _("GModules are not supported on your platform!\n"));
379
382
                exit (1);
380
383
        }
381
384
 
 
385
        /* Set locale to be able to use environment variables */
 
386
        setlocale (LC_ALL, "");
 
387
 
382
388
        bindtextdomain (GETTEXT_PACKAGE, NMLOCALEDIR);
383
389
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
384
390
        textdomain (GETTEXT_PACKAGE);
385
391
 
386
392
        /* Parse options */
387
 
        opt_ctx = g_option_context_new ("");
388
 
        g_option_context_set_translation_domain (opt_ctx, "UTF-8");
 
393
        opt_ctx = g_option_context_new (NULL);
 
394
        g_option_context_set_translation_domain (opt_ctx, GETTEXT_PACKAGE);
389
395
        g_option_context_set_ignore_unknown_options (opt_ctx, FALSE);
390
396
        g_option_context_set_help_enabled (opt_ctx, TRUE);
391
397
        g_option_context_add_main_entries (opt_ctx, options, NULL);
392
398
 
393
399
        g_option_context_set_summary (opt_ctx,
394
 
                "NetworkManager monitors all network connections and automatically\nchooses the best connection to use.  It also allows the user to\nspecify wireless access points which wireless cards in the computer\nshould associate with.");
 
400
                _("NetworkManager monitors all network connections and automatically\nchooses the best connection to use.  It also allows the user to\nspecify wireless access points which wireless cards in the computer\nshould associate with."));
395
401
 
396
402
        success = g_option_context_parse (opt_ctx, &argc, &argv, NULL);
397
403
        g_option_context_free (opt_ctx);
407
413
        }
408
414
 
409
415
        if (getuid () != 0) {
410
 
                fprintf (stderr, "You must be root to run NetworkManager!\n");
 
416
                fprintf (stderr, _("You must be root to run NetworkManager!\n"));
411
417
                exit (1);
412
418
        }
413
419
 
427
433
        /* Read the config file and CLI overrides */
428
434
        config = nm_config_new (config_path, plugins, log_level, log_domains, &error);
429
435
        if (config == NULL) {
430
 
                fprintf (stderr, "Failed to read configuration: (%d) %s\n",
 
436
                fprintf (stderr, _("Failed to read configuration: (%d) %s\n"),
431
437
                         error ? error->code : -1,
432
 
                         (error && error->message) ? error->message : "unknown");
 
438
                         (error && error->message) ? error->message : _("unknown"));
433
439
                exit (1);
434
440
        }
435
441
 
445
451
 
446
452
        /* Parse the state file */
447
453
        if (!parse_state_file (state_file, &net_enabled, &wifi_enabled, &wwan_enabled, &wimax_enabled, &error)) {
448
 
                fprintf (stderr, "State file %s parsing failed: (%d) %s\n",
 
454
                fprintf (stderr, _("State file %s parsing failed: (%d) %s\n"),
449
455
                         state_file,
450
456
                         error ? error->code : -1,
451
 
                         (error && error->message) ? error->message : "unknown");
 
457
                         (error && error->message) ? error->message : _("unknown"));
452
458
                /* Not a hard failure */
453
459
        }
454
460
        g_clear_error (&error);
462
468
                        int saved_errno;
463
469
 
464
470
                        saved_errno = errno;
465
 
                        fprintf (stderr, "Could not daemonize: %s [error %u]\n",
 
471
                        fprintf (stderr, _("Could not daemonize: %s [error %u]\n"),
466
472
                                 g_strerror (saved_errno),
467
473
                                 saved_errno);
468
474
                        exit (1);