JS_EXPORT_API 
void installer_set_timezone (const gchar *timezone)
{
    gboolean ret = FALSE;
    GError *error = NULL;
    gchar *timezone_file = NULL;
    gchar *zoneinfo_path = NULL;
    gchar *localtime_path = NULL;
    GFile *zoneinfo_file = NULL;
    GFile *localtime_file = NULL;
    gchar *timezone_content = NULL;

    if (timezone == NULL) {
        g_warning ("set timezone:timezone NULL\n");
        goto out;
    }
    timezone_file = g_strdup ("/etc/timezone");
    timezone_content = g_strdup_printf ("%s\n", timezone);
    g_file_set_contents (timezone_file, timezone_content, -1, &error);
    if (error != NULL) {
        g_warning ("set timezone:write timezone %s\n", error->message);
        goto out;
    }
    zoneinfo_path = g_strdup_printf ("/usr/share/zoneinfo/%s", timezone);
    localtime_path = g_strdup ("/etc/localtime");
    zoneinfo_file = g_file_new_for_path (zoneinfo_path);
    localtime_file = g_file_new_for_path (localtime_path);
    g_file_copy (zoneinfo_file, localtime_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error);
    if (error != NULL) {
        g_warning ("set timezone:cp %s to /etc/localtime %s\n", zoneinfo_path, error->message);
        goto out;
    }
    ret = TRUE;
    goto out;

out:
    g_free (timezone_content);
    g_free (timezone_file);
    g_free (zoneinfo_path);
    g_free (localtime_path);
    if (error != NULL) {
        g_error_free (error);
        error = NULL;
    }
    if (zoneinfo_file != NULL) {
        g_object_unref (zoneinfo_file);
    }
    if (localtime_file != NULL) {
        g_object_unref (localtime_file);
    }
    if (ret) {
        emit_progress ("timezone", "finish");
    } else {
        g_warning ("set timezone failed, just skip this step");
        emit_progress ("timezone", "finish");
    }
}
Exemple #2
0
static void
do_transfer (RBRemovableMediaManager *manager)
{
	RBRemovableMediaManagerPrivate *priv = GET_PRIVATE (manager);
	TransferData *data;
	RBEncoder *encoder;

	g_assert (rb_is_main_thread ());

	emit_progress (manager);

	if (priv->transfer_running) {
		rb_debug ("already transferring something");
		return;
	}

	data = g_async_queue_try_pop (priv->transfer_queue);
	if (data == NULL) {
		rb_debug ("transfer queue is empty");
		priv->transfer_total = 0;
		priv->transfer_done = 0;
		emit_progress (manager);
		return;
	}

	priv->transfer_running = TRUE;
	priv->transfer_fraction = 0.0;

	encoder = rb_encoder_new ();
	g_signal_connect (G_OBJECT (encoder),
			  "error", G_CALLBACK (error_cb),
			  data);
	g_signal_connect (G_OBJECT (encoder),
			  "progress", G_CALLBACK (progress_cb),
			  data);
	g_signal_connect (G_OBJECT (encoder),
			  "completed", G_CALLBACK (completed_cb),
			  data);
	rb_debug ("starting transfer of %s to %s",
		  rhythmdb_entry_get_string (data->entry, RHYTHMDB_PROP_LOCATION),
		  data->dest);
	if (rb_encoder_encode (encoder, data->entry, data->dest, data->mime_types) == FALSE) {
		rb_debug ("unable to start transfer");
	}
}
static void
watch_passwd_child (GPid pid, gint status, struct PasswdHandler *handler)
{
    g_debug ("watch password child:set password finish\n");
    free_passwd_handler (handler);
    if (status == -1) {
        emit_progress ("user", "terminate");
    }
}
Exemple #4
0
static void
progress_cb (RBEncoder *encoder, double fraction, TransferData *data)
{
	RBRemovableMediaManagerPrivate *priv = GET_PRIVATE (data->manager);

	rb_debug ("transfer progress %f", (float)fraction);
	priv->transfer_fraction = fraction;
	emit_progress (data->manager);
}
JS_EXPORT_API
gboolean installer_chroot_target ()
{
    gboolean ret = FALSE;
    if (!mount_procfs ()) {
        goto out;
    }

    extern const gchar* target;
    if (target == NULL) {
        g_warning ("chroot:target is NULL\n");
        goto out;
    }
    extern int chroot_fd;
    if ((chroot_fd = open (".", O_RDONLY)) < 0) {
        g_warning ("chroot:set chroot fd failed\n");
        goto out;
    }

    extern gboolean in_chroot;
    if (chroot (target) == 0) {
        in_chroot = TRUE;
        ret = TRUE;
    } else {
        g_warning ("chroot:chroot to %s falied:%s\n", target, strerror (errno));
    }
    goto out;

out:
    if (ret) {
        emit_progress ("chroot", "finish");
    } else {
        emit_progress ("chroot", "terminate");
    }
    return ret;
}
JS_EXPORT_API 
void installer_create_user (const gchar *username, const gchar *hostname, const gchar *password)
{
    if (username == NULL || hostname == NULL || password == NULL) {
        g_warning ("create user:invalid username-> %s or hostname->%s or password->%s\n", username, hostname, password);
        emit_progress ("user", "terminate");
        return;
    }
    struct PasswdHandler *handler = g_new0 (struct PasswdHandler, 1);
    handler->username = g_strdup (username);
    handler->password = g_strdup (password);
    handler->hostname = g_strdup (hostname);
    handler->pid = -1;
    handler->in_channel = NULL;
    handler->out_channel = NULL;
    handler->child_watch_id = 0;
    handler->stdout_watch_id = 0;

    GThread *user_thread = g_thread_new ("user", (GThreadFunc) thread_create_user, handler);
    g_thread_unref (user_thread);
}
void
Optimization::updateCoeff(Method_Coefficients & coeff, float dist, float minRadius)
{
    QMutexLocker locker(&lock);
    _current_seeds++;
    int i = 0;
    if(_max_seeds>0)
    {
        i = (_current_seeds*100)/_max_seeds;
    }
    if(std::abs(dist) < std::abs(current_dist))
    {
        coefficients_end = coeff;
        current_dist = dist;
        coefficients_end.minRad = minRadius;
        this->min_rad = minRadius;
    }
    if(i!=0)
    {
        emit emit_progress(i);
        QCoreApplication::processEvents();
    }

}
static gpointer
thread_create_user (gpointer data)
{
    struct PasswdHandler *handler = (struct PasswdHandler *) data;
    
    if (!add_user (handler->username)) {
        g_warning ("create user:add user failed\n");
        emit_progress ("user", "terminate");
        return NULL;
    }

    if (!set_user_home (handler->username)) {
        g_warning ("create user:set user home failed\n");
        emit_progress ("user", "terminate");
        return NULL;
    }

    if (!set_group (handler->username)) {
        g_warning ("create user:set group failed\n");
        emit_progress ("user", "terminate");
        return NULL;
    }
    
    if (!write_hostname (handler->hostname)) {
        g_warning ("create user:write hostname failed\n");
        emit_progress ("user", "terminate");
        return NULL;
    }
    if (!set_user_password (handler)) {
        g_warning ("create user:set user password failed\n");
        emit_progress ("user", "terminate");
        return NULL;
    }
    emit_progress ("user", "finish");
    return NULL;
}
static void
encoder_progress_cb (RBEncoder *encoder, double fraction, RBTrackTransferBatch *batch)
{
	batch->priv->current_fraction = fraction;
	emit_progress (batch);
}