gboolean gsd_datetime_mechanism_set_using_ntp (GsdDatetimeMechanism *mechanism, gboolean using_ntp, DBusGMethodInvocation *context) { GError *error; gboolean ret; error = NULL; if (!_check_polkit_for_action (mechanism, context)) return FALSE; if (g_file_test ("/etc/fedora-release", G_FILE_TEST_EXISTS)) /* Fedora */ ret = _set_using_ntp_fedora (context, using_ntp); else if (g_file_test ("/usr/sbin/update-rc.d", G_FILE_TEST_EXISTS)) /* Debian */ ret = _set_using_ntp_debian (context, using_ntp); else if (g_file_test ("/etc/SuSE-release", G_FILE_TEST_EXISTS)) /* SUSE variant */ ret = _set_using_ntp_suse (context, using_ntp); else { error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, GSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error enabling NTP: OS variant not supported"); dbus_g_method_return_error (context, error); g_error_free (error); return FALSE; } return ret; }
static gboolean _set_time (GsdDatetimeMechanism *mechanism, const struct timeval *tv, DBusGMethodInvocation *context) { GError *error; if (!_check_polkit_for_action (mechanism, context)) return FALSE; if (settimeofday (tv, NULL) != 0) { error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, GSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error calling settimeofday({%lld,%lld}): %s", (gint64) tv->tv_sec, (gint64) tv->tv_usec, strerror (errno)); dbus_g_method_return_error (context, error); g_error_free (error); return FALSE; } if (!_sync_hwclock (context)) return FALSE; dbus_g_method_return (context); return TRUE; }
gboolean gsd_datetime_mechanism_set_hardware_clock_using_utc (GsdDatetimeMechanism *mechanism, gboolean using_utc, DBusGMethodInvocation *context) { GError *error; error = NULL; if (!_check_polkit_for_action (mechanism, context)) return FALSE; if (g_file_test ("/sbin/hwclock", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_EXECUTABLE)) { int exit_status; char *cmd; cmd = g_strdup_printf ("/sbin/hwclock %s --systohc", using_utc ? "--utc" : "--localtime"); if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &error)) { GError *error2; error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR, GSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error spawning /sbin/hwclock: %s", error->message); g_error_free (error); dbus_g_method_return_error (context, error2); g_error_free (error2); g_free (cmd); return FALSE; } g_free (cmd); if (WEXITSTATUS (exit_status) != 0) { error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, GSD_DATETIME_MECHANISM_ERROR_GENERAL, "/sbin/hwclock returned %d", exit_status); dbus_g_method_return_error (context, error); g_error_free (error); return FALSE; } if (g_file_test ("/etc/fedora-release", G_FILE_TEST_EXISTS)) { /* Fedora */ if (!_update_etc_sysconfig_clock_fedora (context, "UTC=", using_utc ? "true" : "false")) return FALSE; } else if (g_file_test ("/etc/SuSE-release", G_FILE_TEST_EXISTS)) { /* SUSE variant */ if (!_update_etc_sysconfig_clock_suse (context, "HWCLOCK=", using_utc ? "-u" : "--localtime")) return FALSE; } } dbus_g_method_return (context); return TRUE; }
static gboolean _set_time (GnomeClockAppletMechanism *mechanism, const struct timeval *tv, DBusGMethodInvocation *context) { GError *error; if (!_check_polkit_for_action (mechanism, context, "org.gnome.clockapplet.mechanism.settime")) return FALSE; if (settimeofday (tv, NULL) != 0) { error = g_error_new (GNOME_CLOCK_APPLET_MECHANISM_ERROR, GNOME_CLOCK_APPLET_MECHANISM_ERROR_GENERAL, "Error calling settimeofday({%lld,%lld}): %s", (gint64) tv->tv_sec, (gint64) tv->tv_usec, strerror (errno)); dbus_g_method_return_error (context, error); g_error_free (error); return FALSE; } if (g_file_test ("/sbin/hwclock", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_EXECUTABLE)) { int exit_status; if (!g_spawn_command_line_sync ("/sbin/hwclock --systohc", NULL, NULL, &exit_status, &error)) { GError *error2; error2 = g_error_new (GNOME_CLOCK_APPLET_MECHANISM_ERROR, GNOME_CLOCK_APPLET_MECHANISM_ERROR_GENERAL, "Error spawning /sbin/hwclock: %s", error->message); g_error_free (error); dbus_g_method_return_error (context, error2); g_error_free (error2); return FALSE; } if (WEXITSTATUS (exit_status) != 0) { error = g_error_new (GNOME_CLOCK_APPLET_MECHANISM_ERROR, GNOME_CLOCK_APPLET_MECHANISM_ERROR_GENERAL, "/sbin/hwclock returned %d", exit_status); dbus_g_method_return_error (context, error); g_error_free (error); return FALSE; } } dbus_g_method_return (context); return TRUE; }
gboolean gnome_clock_applet_mechanism_set_hardware_clock_using_utc (GnomeClockAppletMechanism *mechanism, gboolean using_utc, DBusGMethodInvocation *context) { GError *error; error = NULL; if (!_check_polkit_for_action (mechanism, context, "org.gnome.clockapplet.mechanism.configurehwclock")) return FALSE; if (g_file_test ("/sbin/hwclock", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_EXECUTABLE)) { int exit_status; char *cmd; cmd = g_strdup_printf ("/sbin/hwclock %s --systohc", using_utc ? "--utc" : "--localtime"); if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &error)) { GError *error2; error2 = g_error_new (GNOME_CLOCK_APPLET_MECHANISM_ERROR, GNOME_CLOCK_APPLET_MECHANISM_ERROR_GENERAL, "Error spawning /sbin/hwclock: %s", error->message); g_error_free (error); dbus_g_method_return_error (context, error2); g_error_free (error2); g_free (cmd); return FALSE; } g_free (cmd); if (WEXITSTATUS (exit_status) != 0) { error = g_error_new (GNOME_CLOCK_APPLET_MECHANISM_ERROR, GNOME_CLOCK_APPLET_MECHANISM_ERROR_GENERAL, "/sbin/hwclock returned %d", exit_status); dbus_g_method_return_error (context, error); g_error_free (error); return FALSE; } if (!_rh_update_etc_sysconfig_clock (context, "UTC=", using_utc ? "true" : "false")) return FALSE; } dbus_g_method_return (context); return TRUE; }
gboolean csd_datetime_mechanism_set_hardware_clock_using_utc (CsdDatetimeMechanism *mechanism, gboolean using_utc, DBusGMethodInvocation *context) { GError *error; error = NULL; if (!_check_polkit_for_action (mechanism, context)) return FALSE; if (g_file_test ("/sbin/hwclock", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_EXECUTABLE)) { int exit_status; char *cmd; cmd = g_strdup_printf ("/sbin/hwclock %s --systohc", using_utc ? "--utc" : "--localtime"); if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &error)) { GError *error2; error2 = g_error_new (CSD_DATETIME_MECHANISM_ERROR, CSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error spawning /sbin/hwclock: %s", error->message); g_error_free (error); dbus_g_method_return_error (context, error2); g_error_free (error2); g_free (cmd); return FALSE; } g_free (cmd); if (WEXITSTATUS (exit_status) != 0) { error = g_error_new (CSD_DATETIME_MECHANISM_ERROR, CSD_DATETIME_MECHANISM_ERROR_GENERAL, "/sbin/hwclock returned %d", exit_status); dbus_g_method_return_error (context, error); g_error_free (error); return FALSE; } } dbus_g_method_return (context); return TRUE; }
gboolean gsd_datetime_mechanism_set_timezone (GsdDatetimeMechanism *mechanism, const char *tz, DBusGMethodInvocation *context) { GError *error; reset_killtimer (); g_debug ("SetTimezone('%s') called", tz); if (!_check_polkit_for_action (mechanism, context)) return FALSE; error = NULL; if (!gsd_datetime_check_tz_name (tz, &error)) return FALSE; if (!system_timezone_set (tz, &error)) { GError *error2; int code; if (error->code == SYSTEM_TIMEZONE_ERROR_INVALID_TIMEZONE_FILE) code = GSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE; else code = GSD_DATETIME_MECHANISM_ERROR_GENERAL; error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR, code, "%s", error->message); g_error_free (error); dbus_g_method_return_error (context, error2); g_error_free (error2); return FALSE; } dbus_g_method_return (context); return TRUE; }
gboolean gnome_clock_applet_mechanism_set_timezone (GnomeClockAppletMechanism *mechanism, const char *zone_file, DBusGMethodInvocation *context) { GError *error; reset_killtimer (); g_debug ("SetTimezone('%s') called", zone_file); if (!_check_polkit_for_action (mechanism, context, "org.gnome.clockapplet.mechanism.settimezone")) return FALSE; error = NULL; if (!system_timezone_set_from_file (zone_file, &error)) { GError *error2; int code; if (error->code == SYSTEM_TIMEZONE_ERROR_INVALID_TIMEZONE_FILE) code = GNOME_CLOCK_APPLET_MECHANISM_ERROR_INVALID_TIMEZONE_FILE; else code = GNOME_CLOCK_APPLET_MECHANISM_ERROR_GENERAL; error2 = g_error_new (GNOME_CLOCK_APPLET_MECHANISM_ERROR, code, error->message); g_error_free (error); dbus_g_method_return_error (context, error2); g_error_free (error2); return FALSE; } dbus_g_method_return (context); return TRUE; }