Commit graph

143 commits

Author SHA1 Message Date
644817993b Fix up a few identifier references in comments
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +02:00
afe5001a23 Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 09:38:32 +02:00
bae3f5447e Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-07-02 17:45:44 +02:00
eba87789ab Fix and clean up some comments
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-12-05 12:31:08 +01:00
9f25de3dce Change comment style to use @foo rather than FOO
... when referring to a function's parameter or a struct/union's
member.

The idea of using FOO comes from the GNU coding standards:

    The comment on a function is much clearer if you use the argument
    names to speak about the argument values.  The variable name
    itself should be lower case, but write it in upper case when you
    are speaking about the value rather than the variable itself.
    Thus, "the inode number NODE_NUM" rather than "an inode".

Upcasing names is problematic for a case-sensitive language like C,
because it can create ambiguity.  Moreover, it's too much shouting for
my taste.

GTK-Doc's convention to prefix the identifier with @ makes references
to variables stand out nicely.  The rest of the GTK-Doc conventions
make no sense for us, however.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-12-05 12:13:17 +01:00
b14f5276ab Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-28 16:21:34 +01:00
7d3a3df283 file: New ef_typedstr_eq(), factored out of obj_changed()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:00 +01:00
e70d8f07f9 file: Rename struct emptypedstr to ef_typedstr
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:00 +01:00
bb467c335d Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-02 14:33:48 +01:00
bc14b41c65 Fix crash on edit s, p, u key 'U' with negative argument
ef_ensure_space() oopses on negative ID, but succeeds anyway.  edit()
proceeds to ef_write(), which neglects to check for negative ID.
Since the ID isn't in the cache, it then passes a NULL old element to
callback prewrite(), which crashes.

Fix ef_ensure_space() to fail on negative ID.  Commit 5173f8cd
(v4.3.0) made it oops, but neglected to make it fail.

Fix ef_write() to oops and fail on negative ID.

ef_write() still passes NULL old element to prewrite() when the ID
isn't in the cache.  Doesn't actually happen, because we use
prewrite() callbacks only with fully cached tables.  Fragile.  Make
ef_open() fail when that assumption is violated.
2013-05-08 06:55:21 +02:00
df4925d696 Update copyright notice 2013-01-12 17:45:01 +01:00
e25ff14f0c New ef_nameof_pretty() 2012-07-13 20:15:33 +02:00
1118f1c0ca Update copyright notice 2012-06-10 10:52:22 +02:00
786e2a99d5 Clean up superfluous includes 2012-04-26 19:57:19 +02:00
79f289c365 Refuse to grow or truncate files with fixed size
Make ef_write() treat it like any other invalid write beyond the file
size: oops.  Be less harsh in ef_extend() and ef_truncate(): log an
error.
2011-06-25 16:50:20 +02:00
7d2269b5ae Make ef_open() extend files with fixed size automatically
Turns the fixed size into an invariant.  Before, the files utility
created them empty, then extended them.
2011-06-25 16:50:06 +02:00
58ed1d1b9e Fix empdump not to grow game state files with fixed size
empdump -i now complains about extra rows instead of silently growing
the file to a size the server will reject.  Affects tables sector,
nation, realms, game.

Bonus fix: better error message on I/O error or insufficient memory.
2011-06-25 16:50:06 +02:00
0fcd935999 Clean up how game state file sizes are checked
New struct empfile member nent replaces ef_open() parameter nelt.
Cleaner, because the expected size is a property of the file, not of
how it's used.  Also fixes empdump to check file sizes.

Complication: with EFF_CREATE, ef_open() creates an empty file, to be
extended to the correct size.  Callers passed nelt argument -1 along
with EFF_CREATE, to make ef_open() accept the empty file.  Can't do
the same for empfile member nent.  Instead, make ef_open() not check
the (zero) size then.

Replaces commit 5750107b, v4.3.15.
2011-06-25 16:50:06 +02:00
44f97c3297 Clean up how a view's base table is defined
New struct empfile member base replaces ef_open_view() parameter base.
Cleaner, because the base table is a property of the view, not of how
it's used.

Use it to clean up verify_fail()'s base table access, and for extra
sanity checks in ef_open() and ef_open_view().
2011-06-25 16:50:06 +02:00
2b0b53992f Simplify how ef_write() handles write beyond end of file 2011-06-25 16:50:06 +02:00
f50fc19aab Make ef_close() set fids later, so it's cleaned up on error
Just for cleanliness.
2011-06-25 16:50:06 +02:00
5d54e424df Clean up ef_close() to zap csize along with cache 2011-06-25 16:50:06 +02:00
a485084777 Change struct empfile callback onresize() to return void
ef_open() handles onresize() failing incorrectly.  Instead of fixing
that, drop the failure mode.  It's not really used: unit_onresize()
fails only when used incorrectly.  It isn't.  If it ever is, ignoring
the failure is safe.
2011-06-25 16:50:05 +02:00
45c7337e70 Fix clearing mutable flags on ef_close()
Make ef_close() clear them always, even for views.  Harmless, as
ef_open_view() always sets the same flags.

Drop redundant assignment to ep->flags in ef_open().  ef_close()
clears mutable flags, no need to clear them some more right before
calling it.  Missed in commit 3eb3607f, v4.3.0.
2011-06-25 16:50:05 +02:00
5703bdd61c Fix ef_open()'s error message for file larger than static cache
The message claims the file is larger than it actually is.  Broken
since commit 71908018 (v4.3.0) implemented static cache in ef_open().
Harmless, because no file-backed table has a statically allocated
cache.
2011-06-25 16:50:05 +02:00
6e4772b175 A few comment fixes for nsc.[ch] file.[ch] 2011-06-25 16:45:31 +02:00
47b68a1c1f Document sequence numbers and generation numbers better 2011-04-14 20:21:23 +02:00
7e2008e7f4 License upgrade to GPL version 3 or later
Why upgrade?  I'm not a lawyer, but here's my take on the differences
to version 2:

* Software patents: better protection against abuse of patents to
  prevent users from exercising the rights under the GPL.  I doubt
  we'll get hit with a patent suit, but it's a good move just on
  general principles.

* License compatibility: compatible with more free licenses, i.e. can
  "steal" more free software for use in Empire.  I don't expect to steal
  much, but it's nice to have the option.

* Definition of "source code": modernization of some details for today's
  networked world, to make it easier to distribute the software.  Not
  really relevant to us now, as we normally distribute full source code.

* Tivoization: this is about putting GPL-licensed software in hardware,
  then make the hardware refuse to run modified software.  "Neat" trick
  to effectively deny its users their rights under the GPL.  Abuse was
  "pioneered" by TiVo (popular digital video recorders).  GPLv3 forbids
  it.  Unlikely to become a problem for us.

* Internationalization: more careful wording, to harden the license
  outside the US.  The lawyers tell us it better be done that way.

* License violations: friendlier way to deal with license violations.
  This has come out of past experience enforcing the GPL.

* Additional permissions: Probably not relevant to us.

Also include myself in the list of principal authors.
2011-04-12 21:20:58 +02:00
73e25ff21e Update copyright notice 2010-01-19 08:40:17 +01:00
2fa5f65257 Generation numbers to catch write back of stale copies
Oops when a stale copy is written back, i.e. the processor was yielded
since the copy was made.  Such bugs are difficult to spot.  Sequence
numbers catch them when they do actual harm (they also catch different
bugs).  Generation numbers catch them even when they don't.

New ef_generation to count generations.  Call new ef_make_stale() to
increment it whenever the processor may be yielded.

New struct emptypedstr member generation.  To conserve space, make it
a bit-field of twelve bits, i.e. generations are only recorded modulo
2^12.  Make sure all members of unit empobj_storage share it.  It is
only used in copies; its value on disk and in the cache is
meaningless.  Copies with generation other than ef_generation are
stale.  Stale copies that are a multiple of 2^12 generations old can't
be detected, but that is sufficiently improbable.

Set generation to ef_generation by calling new ef_mark_fresh() when
making copies in ef_read() and ef_blank().  nav_ship() and
fltp_to_list() make copies without going through ef_read(), and
therefore need to call ef_mark_fresh() as well.  Also call it in
obj_changed() to make check_sect_ok() & friends freshen their argument
when it is unchanged.

New must_be_fresh() oopses when its argument is stale.  Call it in
ef_write() to catch write back of stale copies.
2010-01-19 08:36:01 +01:00
18148f03fa Fix new_seqno()'s recovery from seqno mismatch
A sequence number mismatch occurs when an invalid copy (with a stale
sequence number) gets written.  To continue after the error, we need
to use the current sequence number.  But new_seqno() used the larger
one of the two, which is correct only as long as sequence numbers do
not overflow.  Overflow is rather unlikely, though.
2010-01-19 08:26:39 +01:00
c528fcbe3e Update known contributors comments 2009-12-13 17:34:28 +01:00
dbef646f5d Don't fake open() and fcntl() just for ef_open()
Put the Windows code into new open_locked() instead.  It's ugly having
that in file.c, but the fakes are ugly too, and somewhat brittle.
Remove posix_open(), F_SETLK, F_RDLCK, F_WRLCK, struct flock, and
simplify fcntl().
2009-11-30 19:45:27 +01:00
c665c83ba4 Remove macro S_IRWUG
Use its expansion instead.
2009-11-30 19:45:27 +01:00
35ef345ecb Update copyright notice 2009-02-08 09:33:18 +01:00
d702068457 Fix trailing whitespace 2008-09-17 21:31:40 -04:00
f21cb48f69 New struct empfile callback onresize 2008-09-08 21:30:37 -04:00
a1f20efd02 Revive struct empfile callback init as oninit
Commit a71f0158 removed unused callback init.  Bring it back renamed
to oninit, and without the redundant first argument.
2008-09-08 21:30:37 -04:00
c5482e4bfb Pass old element to empfile callback prewrite()
Change sct_prewrite(), shp_prewrite(), pln_prewrite(), lnd_prewrite(),
nuk_prewrite() accordingly.  New argument isn't used for anything,
yet.
2008-09-08 21:26:40 -04:00
afcde86ca3 Make ef_close() clear baseid, cids and fids 2008-09-03 21:17:46 -04:00
62076fbed7 Move view open/close into src/lib/common/file.c
Really belongs there, because it manipulates empfile[].

New ef_open_view() to replace ef_init_view().  Make ef_close() cope
with views, and remove ef_fina_view().  Make ef_extend() and
ef_truncate() oops on views.
2008-09-03 21:17:46 -04:00
50cfdcb5a7 Check argument of ef_cadef(), ef_nelem(), ef_flags(), ef_mtime()
This removes any need for calling ef_check() outside of file.c.
Remove its only occurence, from symval(), and give it internal
linkage.
2008-09-03 20:43:13 -04:00
1492845c12 Clean up maintenance of config table sentinels
Xundump had special hackery to maintain configuration tables'
sentinels: xubody() and getobj() added a sentinel element when
initializing or growing a table, which xubody() stripped off again
before returning.  The latter was an unclean hack.

Replace this by building knowledge of sentinels into struct empfile:
new flag EFF_SENTINEL, set for the appropriate members of empfile[],
obeyed by ef_extend() and ef_truncate().
2008-09-03 20:43:13 -04:00
e438f6b4cd Fix/improve logging in ef_close(), ef_extend(), ef_truncate()
Change ef_close() to log ep->file instead of ep->name, to match
ef_open().

Fix ef_extend() to log ep->name instead of ep->file, which could be
null.  Also fix ef_ensure_space()'s function comment.  Both broken in
commit 2eb8672b.

ef_truncate()'s error logging lacked detail when ef_realloc_cache()
failed, fix.
2008-09-03 20:43:13 -04:00
536ef0b0a2 Add sequence numbers to game state
This oopses on output dependency violations, e.g. two threads doing a
read-modify-write without synchronization, or the one thread nesting
several read-modify-writes.  Such bugs are difficult to spot, and tend
to be abusable.  I figure we have quite a few of them.

New struct emptypedstr member seqno.  Make sure all members of unit
empobj_storage share it.  Initialize it in files: main() and
file_sct_init().  Set it in ef_blank() and new ef_set_uid() by calling
new get_seqno().  Use ef_set_uid() when copying objects: swaps(),
doland(), doship(), doplane(), dounit(), delete_old_news().  Step it
in ef_write() by calling new new_seqno().

Factor do_read() out of fillcache() to make it available for
get_seqno().
2008-05-17 22:50:30 +02:00
967122ae0b Fix files utility not to set timestamps
Commit f33b96b1 (v4.3.12) made files again set timestamps.  That was
intentionally suppressed in commit 990eb46b (v4.3.10), because it
facilitates attacks against the PRNG.  Commit 8f98e53a (v4.3.0) had
added it as a feature.

Fix by making files's main() pass new flag EFF_NOTIME to ef_open().
Implement the flag in do_write().
2008-05-17 19:35:22 +02:00
2a125c5463 Simplify empfile timestamping
do_write() sets the timestamp from a parameter.  All callers pass
time(), and don't use that value themselves.  Call time() in do_write
and remove the parameter.
2008-05-17 19:01:59 +02:00
d39a1f11cc Update timestamps in privately mapped tables, too
Commit f33b96b1 made ef_flush(), ef_write() and ef_extend() update
timestamps automatically.  Change ef_write() and ef_extend() to do
that even when table is privately mapped, by making do_write() cope
with privately mapped tables.  Current users don't care, but it's a
saner interface.
2008-05-17 18:56:38 +02:00
c3d5771054 Fix ef_write() for privately mapped non-file-backed table
Commit f8dcb7b0 promised that combination to work, but got it wrong.
It hasn't been used, so no real harm done.
2008-05-17 18:48:48 +02:00
5750107b65 Make server check game state file sizes on startup
Certain tables have a fixed size depending on configuration: EF_SECTOR
has WORLD_SZ() elements, EF_NATION, EF_MAP and EF_BMAP have MAXNOC
elements, and EF_REALM has MAXNOC * MAXNOR elements.  Bad things
happen if the files backing them are shorter.

Pass expected size to ef_open(), and make it fail when the actual size
differs.
2008-05-17 17:00:57 +02:00