Пример #1
0
static gboolean
handle_create_plain_volume (LvmVolumeGroup *group,
                            GDBusMethodInvocation *invocation,
                            const gchar *arg_name,
                            guint64 arg_size,
                            GVariant *options)
{
  StorageVolumeGroup *self = STORAGE_VOLUME_GROUP (group);
  CompleteClosure *complete;
  StorageJob *job;
  StorageDaemon *daemon;
  GPtrArray *argv;

  daemon = storage_daemon_get ();

  arg_size -= arg_size % 512;

  argv = g_ptr_array_new_with_free_func (g_free);
  g_ptr_array_add (argv, g_strdup ("lvcreate"));
  g_ptr_array_add (argv, g_strdup (storage_volume_group_get_name (self)));
  g_ptr_array_add (argv, g_strdup_printf ("-L%" G_GUINT64_FORMAT "b", arg_size));
  g_ptr_array_add (argv, g_strdup ("-n"));
  g_ptr_array_add (argv, g_strdup (arg_name));
  g_ptr_array_add (argv, NULL);

  job = storage_daemon_launch_spawned_jobv (daemon, self,
                                            "lvm-vg-create-volume",
                                            storage_invocation_get_caller_uid (invocation),
                                            NULL, /* GCancellable */
                                            0,    /* uid_t run_as_uid */
                                            0,    /* uid_t run_as_euid */
                                            NULL,  /* input_string */
                                            (const gchar **)argv->pdata);

  complete = g_new0 (CompleteClosure, 1);
  complete->invocation = g_object_ref (invocation);
  complete->wait_thing = g_object_ref (self);
  complete->wait_name = g_strdup (arg_name);

  /* Wait for the job to finish */
  g_signal_connect (job, "completed", G_CALLBACK (on_create_complete), complete);

  /* Wait for the object to appear */
  complete->wait_sig = g_signal_connect_data (daemon,
                                              "published::StorageLogicalVolume",
                                              G_CALLBACK (on_create_logical_volume),
                                              complete, complete_closure_free, 0);

  g_ptr_array_free (argv, TRUE);
  return TRUE;
}
Пример #2
0
/**
 * storage_daemon_launch_spawned_job:
 * @self: A #StorageDaemon.
 * @object: (allow-none): A #LvmObject to add to the job or %NULL.
 * @job_operation: The operation for the job.
 * @job_started_by_uid: The user who started the job.
 * @cancellable: A #GCancellable or %NULL.
 * @run_as_uid: The #uid_t to run the command as.
 * @run_as_euid: The effective #uid_t to run the command as.
 * @input_string: A string to write to stdin of the spawned program or %NULL.
 * @command_line_format: printf()-style format for the command line to spawn.
 * @...: Arguments for @command_line_format.
 *
 * Launches a new job for @command_line_format.
 *
 * The job is started immediately - connect to the
 * #UDisksSpawnedJob::spawned-job-completed or #UDisksJob::completed
 * signals to get notified when the job is done.
 *
 * The returned object will be exported on the bus until the
 * #UDisksJob::completed signal is emitted on the object. It is not
 * valid to use the returned object after this signal fires.
 *
 * Returns: A #UDisksSpawnedJob object. Do not free, the object
 * belongs to @manager.
 */
StorageJob *
storage_daemon_launch_spawned_job (StorageDaemon *self,
                                   gpointer object_or_interface,
                                   const gchar *job_operation,
                                   uid_t job_started_by_uid,
                                   GCancellable *cancellable,
                                   uid_t run_as_uid,
                                   uid_t run_as_euid,
                                   const gchar *input_string,
                                   const gchar *first_arg,
                                   ...)
{
  GPtrArray *args;
  StorageJob *job;
  va_list var_args;

  g_return_val_if_fail (STORAGE_IS_DAEMON (self), NULL);
  g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
  g_return_val_if_fail (first_arg != NULL, NULL);

  args = g_ptr_array_new ();
  va_start (var_args, first_arg);
  while (first_arg != NULL)
    {
      g_ptr_array_add (args, g_strdup (first_arg));
      first_arg = va_arg (var_args, gchar *);
    }
  va_end (var_args);
  g_ptr_array_add (args, NULL);

  job = storage_daemon_launch_spawned_jobv (self, object_or_interface, job_operation,
                                            job_started_by_uid, cancellable, run_as_uid,
                                            run_as_euid, input_string,
                                            (const gchar **)args->pdata);

  g_ptr_array_free (args, TRUE);

  return job;
}