Return NULL if the location id is NULL (archive_get_current_location_id):
2001-06-22 Bradford Hovinen <hovinen@ximian.com> * archive.c (archive_get_current_location): Return NULL if the location id is NULL (archive_get_current_location_id): Return NULL if storing the snapshot results in an error * location.c (location_store): Add return values for error conditions; remove g_warning's and g_critical's (location_store_full_snapshot): Folded in store_snapshot_cb; don't call location_foreach_backend (location_store_full_snapshot): Return error condition; 0 on success, -1 if any backend failed * location-manager-dialog.c (location_manager_dialog_set_arg): Add a check to inform the user if the location manager was unable to form an initial configuration snapshot
This commit is contained in:
parent
47d682e446
commit
a18fd85bba
4 changed files with 81 additions and 39 deletions
|
@ -1,5 +1,24 @@
|
|||
2001-06-22 Bradford Hovinen <hovinen@ximian.com>
|
||||
|
||||
* archive.c (archive_get_current_location): Return NULL if the
|
||||
location id is NULL
|
||||
(archive_get_current_location_id): Return NULL if storing the
|
||||
snapshot results in an error
|
||||
|
||||
* location.c (location_store): Add return values for error
|
||||
conditions; remove g_warning's and g_critical's
|
||||
(location_store_full_snapshot): Folded in store_snapshot_cb; don't
|
||||
call location_foreach_backend
|
||||
(location_store_full_snapshot): Return error condition; 0 on
|
||||
success, -1 if any backend failed
|
||||
|
||||
2001-06-21 Bradford Hovinen <hovinen@ximian.com>
|
||||
|
||||
* location.c (location_do_rollback): Wait for child process to
|
||||
terminate
|
||||
(run_backend_proc): Take an extra argument -- where to store the
|
||||
PID of the child process
|
||||
|
||||
* archive.c (archive_set_current_location): Use
|
||||
location_get_changed_backends
|
||||
|
||||
|
|
|
@ -405,18 +405,24 @@ archive_unregister_location (Archive *archive, Location *location)
|
|||
*
|
||||
* Convenience function to get a pointer to the current location
|
||||
*
|
||||
* Return value: Pointer to current location
|
||||
* Return value: Pointer to current location, or NULL if the current location
|
||||
* does not exist and a default location could not be created
|
||||
**/
|
||||
|
||||
Location *
|
||||
archive_get_current_location (Archive *archive)
|
||||
{
|
||||
gchar *locid;
|
||||
|
||||
g_return_val_if_fail (archive != NULL, NULL);
|
||||
g_return_val_if_fail (IS_ARCHIVE (archive), NULL);
|
||||
|
||||
return archive_get_location (archive,
|
||||
archive_get_current_location_id
|
||||
(archive));
|
||||
locid = archive_get_current_location_id (archive);
|
||||
|
||||
if (locid == NULL)
|
||||
return NULL;
|
||||
else
|
||||
return archive_get_location (archive, locid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -484,7 +490,9 @@ archive_set_current_location_id (Archive *archive, const gchar *locid)
|
|||
*
|
||||
* Get the name of the current location
|
||||
*
|
||||
* Return value: String containing current location, should not be freed
|
||||
* Return value: String containing current location, should not be freed, or
|
||||
* NULL if no current location exists and the default location could not be
|
||||
* created
|
||||
**/
|
||||
|
||||
const gchar *
|
||||
|
@ -514,7 +522,10 @@ archive_get_current_location_id (Archive *archive)
|
|||
(location_new (archive,
|
||||
archive->current_location_id,
|
||||
NULL));
|
||||
location_store_full_snapshot (loc);
|
||||
if (location_store_full_snapshot (loc) < 0) {
|
||||
location_delete (loc);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <tree.h>
|
||||
|
@ -91,9 +92,6 @@ static gboolean location_do_rollback (Location *location,
|
|||
gchar *backend_id,
|
||||
xmlDocPtr xml_doc);
|
||||
|
||||
static gint store_snapshot_cb (Location *location,
|
||||
gchar *backend_id);
|
||||
|
||||
static gint get_backends_cb (BackendList *backend_list,
|
||||
gchar *backend_id,
|
||||
Location *location);
|
||||
|
@ -109,7 +107,8 @@ static void write_metadata_file (Location *location,
|
|||
|
||||
static xmlDocPtr load_xml_data (gchar *fullpath, gint id);
|
||||
static gint run_backend_proc (gchar *backend_id,
|
||||
gboolean do_get);
|
||||
gboolean do_get,
|
||||
pid_t *pid);
|
||||
|
||||
static BackendNote *backend_note_new (gchar *backend_id,
|
||||
ContainmentType type);
|
||||
|
@ -398,8 +397,9 @@ location_finalize (GtkObject *object)
|
|||
static gboolean
|
||||
location_do_rollback (Location *location, gchar *backend_id, xmlDocPtr doc)
|
||||
{
|
||||
int fd;
|
||||
int fd, status;
|
||||
FILE *output;
|
||||
pid_t pid;
|
||||
|
||||
g_return_val_if_fail (location != NULL, FALSE);
|
||||
g_return_val_if_fail (IS_LOCATION (location), FALSE);
|
||||
|
@ -411,7 +411,7 @@ location_do_rollback (Location *location, gchar *backend_id, xmlDocPtr doc)
|
|||
*/
|
||||
if (doc == NULL) return FALSE;
|
||||
|
||||
fd = run_backend_proc (backend_id, FALSE);
|
||||
fd = run_backend_proc (backend_id, FALSE, &pid);
|
||||
if (fd == -1) return FALSE;
|
||||
|
||||
output = fdopen (fd, "w");
|
||||
|
@ -430,6 +430,8 @@ location_do_rollback (Location *location, gchar *backend_id, xmlDocPtr doc)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
waitpid (pid, &status, 0);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -503,9 +505,12 @@ location_delete (Location *location)
|
|||
*
|
||||
* Store configuration data from the given stream in the location under the
|
||||
* given backend id
|
||||
*
|
||||
* Return value: 0 on success, -1 if it cannot parse the XML, and -2 if no
|
||||
* data were supplied
|
||||
**/
|
||||
|
||||
void
|
||||
gint
|
||||
location_store (Location *location, gchar *backend_id, FILE *input,
|
||||
StoreType store_type)
|
||||
{
|
||||
|
@ -532,18 +537,18 @@ location_store (Location *location, gchar *backend_id, FILE *input,
|
|||
doc = xmlParseDoc (doc_str->str);
|
||||
|
||||
if (doc == NULL) {
|
||||
g_warning ("Could not parse XML");
|
||||
g_string_free (doc_str, TRUE);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
location_store_xml (location, backend_id, doc, store_type);
|
||||
xmlFreeDoc (doc);
|
||||
} else {
|
||||
g_critical ("No data to store");
|
||||
return -2;
|
||||
}
|
||||
|
||||
g_string_free (doc_str, TRUE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1173,17 +1178,37 @@ location_set_id (Location *location, const gchar *locid)
|
|||
*
|
||||
* Gets XML snapshot data from all the backends contained in this location and
|
||||
* archives those data
|
||||
*
|
||||
* Return value: 0 on success and -1 if any of the backends failed
|
||||
**/
|
||||
|
||||
void
|
||||
gint
|
||||
location_store_full_snapshot (Location *location)
|
||||
{
|
||||
int fd;
|
||||
gint ret;
|
||||
FILE *pipe;
|
||||
GList *c;
|
||||
BackendNote *note;
|
||||
|
||||
g_return_if_fail (location != NULL);
|
||||
g_return_if_fail (IS_LOCATION (location));
|
||||
|
||||
location_foreach_backend (location,
|
||||
(LocationBackendCB) store_snapshot_cb,
|
||||
NULL);
|
||||
for (c = location->p->contains_list; c; c = c->next) {
|
||||
note = c->data;
|
||||
DEBUG_MSG ("Storing %s", note->backend_id);
|
||||
|
||||
fd = run_backend_proc (note->backend_id, TRUE, NULL);
|
||||
pipe = fdopen (fd, "r");
|
||||
ret = location_store (location, note->backend_id,
|
||||
pipe, STORE_DEFAULT);
|
||||
fclose (pipe);
|
||||
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1241,22 +1266,6 @@ location_does_backend_change (Location *location, Location *location1,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static gint
|
||||
store_snapshot_cb (Location *location, gchar *backend_id)
|
||||
{
|
||||
int fd;
|
||||
FILE *pipe;
|
||||
|
||||
DEBUG_MSG ("Storing %s", backend_id);
|
||||
|
||||
fd = run_backend_proc (backend_id, TRUE);
|
||||
pipe = fdopen (fd, "r");
|
||||
location_store (location, backend_id, pipe, STORE_DEFAULT);
|
||||
fclose (pipe);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gint
|
||||
get_backends_cb (BackendList *backend_list, gchar *backend_id,
|
||||
Location *location)
|
||||
|
@ -1530,7 +1539,7 @@ load_xml_data (gchar *fullpath, gint id)
|
|||
*/
|
||||
|
||||
static gint
|
||||
run_backend_proc (gchar *backend_id, gboolean do_get)
|
||||
run_backend_proc (gchar *backend_id, gboolean do_get, pid_t *pid_r)
|
||||
{
|
||||
char *args[3];
|
||||
int fd[2];
|
||||
|
@ -1577,6 +1586,9 @@ run_backend_proc (gchar *backend_id, gboolean do_get)
|
|||
exit (-1);
|
||||
return 0;
|
||||
} else {
|
||||
if (pid_r != NULL)
|
||||
*pid_r = pid;
|
||||
|
||||
close (fd[c_fd]);
|
||||
return fd[p_fd];
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ GtkObject *location_open (Archive *archive,
|
|||
void location_close (Location *location);
|
||||
void location_delete (Location *location);
|
||||
|
||||
void location_store (Location *location,
|
||||
gint location_store (Location *location,
|
||||
gchar *backend_id,
|
||||
FILE *input,
|
||||
StoreType store_type);
|
||||
|
@ -139,7 +139,7 @@ const gchar *location_get_id (Location *location);
|
|||
|
||||
void location_set_id (Location *location, const gchar *locid);
|
||||
|
||||
void location_store_full_snapshot (Location *location);
|
||||
gint location_store_full_snapshot (Location *location);
|
||||
|
||||
GList *location_get_changed_backends (Location *location,
|
||||
Location *location1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue