]> git.pond.sub.org Git - empserver/commitdiff
edit: Detect concurrent updates during interactive nation edit
authorMarkus Armbruster <armbru@pond.sub.org>
Fri, 29 Mar 2013 17:19:40 +0000 (18:19 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 6 Jun 2013 17:55:03 +0000 (19:55 +0200)
Unlike other edits, editing a country modifies the object in-place.
It has to, because editing may send bulletins, which updates nat_tgms,
and writing back a copy would clobber these updates, triggering a
seqno mismatch oops.

However, the in-place editing neglects to detect concurrent updates.
Fix that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/commands/edit.c

index 5a65782b742f91c751e800fa326c7fcb0f32794c..6f85648530d8bedf74d1d7f30128639a045f212e 100644 (file)
@@ -93,6 +93,7 @@ edit(void)
        np = natargp(player->argp[2], "Country? ");
        if (!np)
            return RET_SYN;
+       item.nat = *np;
        break;
     case 'p':
        if ((num = onearg(player->argp[2], "Plane number? ")) < 0)
@@ -158,11 +159,19 @@ edit(void)
 
        switch (ewhat) {
        case 'c':
+           if (!check_obj_ok(&item.gen))
+               return RET_FAIL;
+           /*
+            * edit_nat() may update the edited country by sending it
+            * bulletins.  Writing back item.nat would trigger a seqno
+            * mismatch oops.  Workaround: edit in-place.
+            */
            ret = edit_nat(np, key, ptr);
            if (ret != RET_OK)
                return ret;
            if (!putnat(np))
                return RET_FAIL;
+           item.nat = *np;
            break;
        case 'l':
            if (!check_sect_ok(&item.sect))