[gnome-nibbles] Remove ENABLE_SETGID support.. scores were broken on some other commit and we won't be fixing using
- From: Bryan Quigley <bryanquigs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles] Remove ENABLE_SETGID support.. scores were broken on some other commit and we won't be fixing using
- Date: Sat, 20 Apr 2013 21:45:34 +0000 (UTC)
commit fa46a1d93906383c943e2fb953f4f01502a1a0ca
Author: Bryan Quigley <bryanquigs src gnome org>
Date: Sat Apr 20 17:36:46 2013 -0400
Remove ENABLE_SETGID support.. scores were broken on some other commit
and we won't be fixing using this (see comments in setgid for a reason..)
src/Makefile.am | 6 -
src/games-scores-backend.c | 223 +-----------------
src/games-scores-backend.h | 4 -
src/games-setgid-io.c | 558 ---------------------------------------------
src/games-setgid-io.h | 38 ---
5 files changed, 2 insertions(+), 827 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index da8f2d5..825d1ad 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,12 +42,6 @@ gnome_nibbles_SOURCES = \
worm.c \
worm.h
-if ENABLE_SETGID
-gnome_nibbles_SOURCES += \
- games-setgid-io.c \
- games-setgid-io.h
-endif # ENABLE_SETGID
-
gnome_nibbles_CPPFLAGS = \
-I$(top_srcdir) \
$(AM_CPPFLAGS)
diff --git a/src/games-scores-backend.c b/src/games-scores-backend.c
index f574713..6d138a9 100644
--- a/src/games-scores-backend.c
+++ b/src/games-scores-backend.c
@@ -30,14 +30,7 @@
#include "games-scores.h"
#include "games-scores-backend.h"
-#ifdef ENABLE_SETGID
-#include "games-setgid-io.h"
-#endif
-
struct GamesScoresBackendPrivate {
-#ifdef ENABLE_SETGID
- gboolean setgid_io_initialized;
-#endif
GList *scores_list;
GamesScoreStyle style;
time_t timestamp;
@@ -50,9 +43,7 @@ G_DEFINE_TYPE (GamesScoresBackend, games_scores_backend, G_TYPE_OBJECT);
void
games_scores_backend_startup (void)
{
-#ifdef ENABLE_SETGID
- setgid_io_init ();
-#endif
+
}
static void
@@ -111,56 +102,7 @@ games_scores_backend_new (GamesScoreStyle style,
return backend;
}
-#ifdef ENABLE_SETGID
-
-/* Get a lock on the scores file. Block until it is available.
- * This also supplies the file descriptor we need. The return value
- * is whether we were succesful or not. */
-static gboolean
-games_scores_backend_get_lock (GamesScoresBackend * self)
-{
- gint error;
-
- if (self->priv->fd != -1) {
- /* Assume we already have the lock and rewind the file to
- * the beginning. */
- setgid_io_seek (self->priv->fd, 0, SEEK_SET);
- return TRUE; /* Assume we already have the lock. */
- }
-
- self->priv->fd = setgid_io_open (self->priv->filename, O_RDWR);
- if (self->priv->fd == -1) {
- return FALSE;
- }
-
- error = setgid_io_lock (self->priv->fd);
-
- if (error == -1) {
- setgid_io_close (self->priv->fd);
- self->priv->fd = -1;
- return FALSE;
- }
-
- return TRUE;
-}
-
-/* Release the lock on the scores file and dispose of the fd. */
-/* We ignore errors, there is nothing we can do about them. */
-static void
-games_scores_backend_release_lock (GamesScoresBackend * self)
-{
- /* We don't have a lock, ignore this call. */
- if (self->priv->fd == -1)
- return;
-
- setgid_io_unlock (self->priv->fd);
-
- setgid_io_close (self->priv->fd);
- self->priv->fd = -1;
-}
-
-#endif /* ENABLE_SETGID */
/**
* games_scores_backend_get_scores:
@@ -175,178 +117,17 @@ games_scores_backend_release_lock (GamesScoresBackend * self)
GList *
games_scores_backend_get_scores (GamesScoresBackend * self)
{
-#ifdef ENABLE_SETGID
- gchar *buffer;
- gchar *eol;
- gchar *scorestr;
- gchar *timestr;
- gchar *namestr;
- GamesScore *newscore;
- struct stat info;
- int error;
- ssize_t length, target;
- GList *t;
-
- /* Check for a change in the scores file and update if necessary. */
- error = setgid_io_stat (self->priv->filename, &info);
-
- /* If an error occurs then we give up on the file and return NULL. */
- if (error != 0)
- return NULL;
-
- if ((info.st_mtime > self->priv->timestamp) || (self->priv->scores_list == NULL)) {
- self->priv->timestamp = info.st_mtime;
-
- /* Dump the old list of scores. */
- t = self->priv->scores_list;
- while (t != NULL) {
- g_object_unref (t->data);
- t = g_list_next (t);
- }
- g_list_free (self->priv->scores_list);
- self->priv->scores_list = NULL;
-
- /* Lock the file and get the list. */
- if (!games_scores_backend_get_lock (self))
- return NULL;
-
- buffer = g_malloc (info.st_size + 1);
- if (buffer == NULL) {
- games_scores_backend_release_lock (self);
- return NULL;
- }
-
- target = info.st_size;
- length = 0;
- do {
- target -= length;
- length = setgid_io_read (self->priv->fd, buffer, info.st_size);
- if (length == -1) {
- games_scores_backend_release_lock (self);
- g_free (buffer);
- return NULL;
- }
- } while (length < target);
-
- buffer[info.st_size] = '\0';
-
- /* FIXME: These details should be in a sub-class. */
-
- /* Parse the list. We start by breaking it into lines. */
- /* Since the buffer is null-terminated
- * we can do the string stuff reasonably safely. */
- eol = strchr (buffer, '\n');
- scorestr = buffer;
- while (eol != NULL) {
- *eol++ = '\0';
- timestr = strchr (scorestr, ' ');
- if (timestr == NULL)
- break;
- *timestr++ = '\0';
- namestr = strchr (timestr, ' ');
- if (namestr == NULL)
- break;
- *namestr++ = '\0';
- /* At this point we have three strings, all null terminated. All
- * part of the original buffer. */
- switch (self->priv->style) {
- case GAMES_SCORES_STYLE_PLAIN_DESCENDING:
- case GAMES_SCORES_STYLE_PLAIN_ASCENDING:
- newscore = games_score_new_plain (g_ascii_strtod (scorestr, NULL));
- break;
- case GAMES_SCORES_STYLE_TIME_DESCENDING:
- case GAMES_SCORES_STYLE_TIME_ASCENDING:
- newscore = games_score_new_time (g_ascii_strtod (scorestr, NULL));
- break;
- default:
- g_assert_not_reached ();
- }
- games_score_set_name (newscore, namestr);
- games_score_set_time (newscore, g_ascii_strtoull (timestr, NULL, 10));
- self->priv->scores_list = g_list_append (self->priv->scores_list, newscore);
- /* Setup again for the next time around. */
- scorestr = eol;
- eol = strchr (eol, '\n');
- }
-
- g_free (buffer);
- }
-
- /* FIXME: Sort the scores! We shouldn't rely on the file being sorted. */
-
- return self->priv->scores_list;
-#else
return NULL;
-#endif /* ENABLE_SETGID */
}
gboolean
games_scores_backend_set_scores (GamesScoresBackend * self, GList * list)
{
-#ifdef ENABLE_SETGID
- GList *s;
- GamesScore *d;
- gchar *buffer;
- gint output_length = 0;
- gchar dtostrbuf[G_ASCII_DTOSTR_BUF_SIZE];
-
- if (!games_scores_backend_get_lock (self))
- return FALSE;
-
- self->priv->scores_list = list;
-
- s = list;
- while (s != NULL) {
- gdouble rscore;
- guint64 rtime;
- const gchar *rname;
-
- d = (GamesScore *) s->data;
- rscore = 0.0;
- switch (self->priv->style) {
- case GAMES_SCORES_STYLE_PLAIN_DESCENDING:
- case GAMES_SCORES_STYLE_PLAIN_ASCENDING:
- rscore = games_score_get_value_as_plain (d);
- break;
- case GAMES_SCORES_STYLE_TIME_DESCENDING:
- case GAMES_SCORES_STYLE_TIME_ASCENDING:
- rscore = games_score_get_value_as_time(d);
- break;
- default:
- g_assert_not_reached ();
- }
- rtime = games_score_get_time (d);
- rname = games_score_get_name(d);
-
- buffer = g_strdup_printf ("%s %"G_GUINT64_FORMAT" %s\n",
- g_ascii_dtostr (dtostrbuf, sizeof (dtostrbuf),
- rscore), rtime, rname);
- setgid_io_write (self->priv->fd, buffer, strlen (buffer));
- output_length += strlen (buffer);
- /* Ignore any errors and blunder on. */
- g_free (buffer);
-
- s = g_list_next (s);
- }
-
- /* Remove any content in the file that hasn't yet been overwritten. */
- setgid_io_truncate (self->priv->fd, output_length--);
-
- /* Update the timestamp so we don't reread the scores unnecessarily. */
- self->priv->timestamp = time (NULL);
-
- games_scores_backend_release_lock (self);
-
- return TRUE;
-#else
return FALSE;
-#endif /* ENABLE_SETGID */
}
void
games_scores_backend_discard_scores (GamesScoresBackend * self)
{
-#ifdef ENABLE_SETGID
- games_scores_backend_release_lock (self);
-#endif
+
}
diff --git a/src/games-scores-backend.h b/src/games-scores-backend.h
index 131fb4b..c094431 100644
--- a/src/games-scores-backend.h
+++ b/src/games-scores-backend.h
@@ -28,10 +28,6 @@
#include "games-score.h"
-#ifdef ENABLE_SETGID
-#include "games-setgid-io.h"
-#endif
-
G_BEGIN_DECLS
#define GAMES_TYPE_SCORES_BACKEND (games_scores_backend_get_type ())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]