Commit graph

80 commits

Author SHA1 Message Date
19953e6c22 (prd_maxno): Variable's value is well-known constant P_MDUST + 2.
Useless, remove.  Users changed to check pchr's sentinel, because
that's clearer than comparing the index to P_MDUST or sizeof(pchr) /
sizeof(*pchr).

(pchr): Change sentinel's p_name and p_sname to NULL.  Sentinel
checks changed.
2005-11-06 18:06:38 +00:00
bee3f4aa88 (nullify_objects): Fix option NO_OIL. The attempt to remove ships
with capability M_OIL from mchr[] actually replaced them with
sentinels.  Just clear the capability instead.
2005-11-06 12:06:10 +00:00
b19c2a6c03 (nullify_objects): Patch intrchr[] according to opt_NO_LCMS,
opt_NO_HCMS.  This fixes output of `show se b', which used not to
reflect these options.
(improve): Simplify.
2005-11-04 18:09:08 +00:00
ae81dade53 (ef_init, ef_init_srv): Rename old ef_init() ef_init_srv(), call new
ef_init().  Move initialization of map sizes to ef_init().
(main): Don't initialize map sizes by hand, call ef_init().

(fileinit): Internal linkage.
2005-10-29 15:16:50 +00:00
a6a87af6ed (disassoc): Rewrite for POSIX, return status. Caller changed.
Problems with the old code:
* Insufficient error checking.
* It used TIOCNOTTY (obsolete BSDism) to get rid of the controlling
  tty, except for hpux || Rel4, where it attempted to use the POSIX
  way, but screwed up.
* It left file descriptors 0, 1, 2 in a somewhat weird state.
2005-10-25 18:42:03 +00:00
64d8f6babe (ef_open, EFF_RDONLY, EFF_CREATE, EFF_OPEN): Replace mode parameter
(really open flags, not mode) by new flags EFF_RDONLY, EFF_CREATE.
Open flags were needlessly general.  Callers changed.
(empfile): Member mode now unused, remove.
2005-10-24 18:18:59 +00:00
f519de81d6 (create_pidfile): Silence compiler warning on printing pid_t with %d. 2005-06-25 16:41:34 +00:00
060df4ec8f Document Empire's thread abstraction. Minor cleanups:
(empth_init): Change first parameter to void **.
(empth_sleep): Change parameter to time_t.
2005-06-25 16:37:59 +00:00
980c3ca8c6 (debug): Move to log.c, so other programs don't have to define debug
themselves just to use logerror().
2005-05-28 15:34:21 +00:00
Ron Koenderink
921fba6532 (main,install_service) [_WIN32]: Move the construction of full path names
for program file and econfig file for installing a service to main()
instead of install_service(). This is because current directory
information is lost because of the use of chdir() to move the current
directory to the datadir.  This change also fixed the setting of a
relative directory for the econfig file.  The service starts in an
arbitrary directory so a relative path can not used by the service.
2005-05-03 00:06:10 +00:00
Ron Koenderink
f826221a58 [_WIN32]: Add #define WIN32 whereever winsock2.h is used. There is bug
in the VC7 version of winsock2.h.  In version VC7, the #pragma
pack(push) and pack(pop) have an #ifdef !WIN32 add to them.  However,
if WIN32 is not defined at the beginning, the push is done but by the
time the pop is reach something else has set WIN32 define so the pop
is not done, and it changes the default pack from /Zp2 to /Zp4, which
makes the data structures incompatible between objects with winsock2.h
and without winsock2.h.  By adding the WIN32 both the push and pop are
not done.
2005-03-20 11:07:45 +00:00
345ad3dfe0 Update copyright notice. 2005-03-16 22:03:16 +00:00
90e1ac57df Fix the previous rev. 2005-03-16 20:57:21 +00:00
147cf97224 (main): Rev. 1.43 broke option -D. Its meaning in presence of -e is
unclear.  Other programs only support -e.  Remove -D.
(install_service): Remove argument datadir_set.

(main): New option -v.

(main): Exit successfully after -h.

(main): Don't print usage on unknown options, just point to -h.

(print_usage): Rewrite.  Deprecate use of non-option arguments.
2005-03-16 20:53:27 +00:00
3939741d65 (main): Fix -p to imply -d as documented, not just !daemonize.
(main): -s no longer implies -p.
(main) [_WIN32]: Recognize -s.  ntthread.c ignores it.
2005-03-16 18:41:44 +00:00
Ron Koenderink
1af2a6fc8b (main) [_WIN32]: Remove second break from -i option. 2005-03-16 02:01:34 +00:00
Ron Koenderink
706e124e82 (main) [_WIN32]: Add check to command line checks to ensure
-p is not used with install or remove sevice options.

(main) [_WIN32]: Improve error messages for errors found
duing the command line checks.
2005-03-16 01:51:22 +00:00
c95fcc7dfb (shutdwn): Rev. 1.51 broke the Linux pthread hack. It is unclear what
this hack is trying to achieve.  It never worked without -d, because
mainpid got assigned the wrong pid.  It doesn't make sense with recent
versions of Linux pthreads, which use the same PID for all threads, as
required by POSIX.  Remove.  Closes #1161397.
2005-03-15 20:58:00 +00:00
Ron Koenderink
1bbd7e5342 (main,print_usage) [_WIN32]: Add the ability to enable
empire thread debugging for Windows build.

(empth_select) [_WIN32]: Fix empth_select() so can be aborted.
The bug was that a command would not be aborted during an update.
The problem was select() was not interrupt by the setting of the
signalling wakeup event.  Fix by replacing the select() with
WSAEventSelect().

(empth_exit) [_WIN32]:
Fix the shutdown sequence for Windows build to be running in
empth_t context.  Add a loc_RunThisThread() in empth_exit()
before starting the shutdown() sequence.
2005-03-13 21:53:23 +00:00
f12649c3da Write pid file, like a good daemon. Thanks to Daniel O'Connor for the
initial patch.
(create_pidfile, pidfname): New.
(start_server): Create pid file.
(finish_server): Remove pid file.

(main) [__linux__ && _EMPTH_POSIX]: Don't hack pid into argv[0].
Recent versions of Linux pthreads no longer show multiple PIDs, and
deities can get the PID fro the pid file anyway.
2005-03-12 16:45:43 +00:00
3f472fc729 (finish_server): New, factored out of termination code. Fixes two
places in service_main() that lacked close_files().
(close_files, loc_NTTerm): Static linkage.
2005-03-12 16:28:28 +00:00
Ron Koenderink
b915edd13c (start_server) [_WIN32]: Put #ifndef _WIN32 around act.
This was missed with the [!POSIXSIGNALS]: changes.
2005-03-12 16:10:49 +00:00
d8daa5f67d (init_server, start_server): Move start log message to start_server(),
where it belongs.
2005-03-12 15:04:37 +00:00
0e68d68390 (main, empth_start): Don't bother to catch SIGUSR1. Use SIGINT or
SIGTERM to shutdown the server.
2005-03-12 12:30:58 +00:00
09b481b30a [!POSIXSIGNALS]: Thoroughly obsolete, remove. This also gets rid of
an odd case where signals were not catched when debugging.

(main, empth_start): Using sa_handler with SA_SIGINFO is wrong.
Simply don't set SA_SIGINFO; the additional signal information is not
used anyway.
2005-03-12 12:20:50 +00:00
Ron Koenderink
014d005c69 (service_main,main,shutdown) [_WIN32]: Add missing loc_NTTerm().
(service_main,main,shutdown,empth_exit,service_stopped) [_WIN32]:
Add shutdown Event to allow the service to shutdown.
When SERVICE_STOPPED is passed to SetServiceStatus() all
threads are kills this prevents shutdown() from executing.
The shutdown Event is used to block the service_main thread until
the stopping of the service is started.  After the shutdown() is
complete then the SetServiceStatus() is called.
2005-03-12 04:35:09 +00:00
9cd463f8bc (main): Fix seeding of PRNG broken in rev. 1.22. 2005-03-11 17:03:07 +00:00
5b57f4c222 Merge pre-4-2-20-invasive. Summary of changes:
* Acquire resources before daemonizing, fail in foreground
* Initialize threads and signals after daemonizing
* Make most file names relative to data directory
* emp_server and files make it their working directory
* emp_config() no longer screws up some file names
* Missing or incorrect econfig is now fatal
* Don't log to default log file when econfig changes it
2005-03-10 18:35:27 +00:00
Ron Koenderink
98f3d6efca (main,service_main) [_WIN32]: Change startup errors to stderr from
logerror() as log file is not open yet.
2005-03-10 18:00:40 +00:00
Ron Koenderink
b961414862 (main) [_WIN32]: Add extern file for chdir().
(main) [_WIN32]: Add #ifdef for tbuf as it is only used in LINUX and
EMPTH_POSIX.
2005-03-10 16:13:51 +00:00
d20fb6ba39 (init_server, start_server): Move signal and thread initialization
from init_server() to start_server(), and service startup next to its
Unix equivalent disassoc().  This way, threading is always initialized
after daemonizing, which is simpler and more portable.
2005-03-09 19:37:48 +00:00
fcf064625d (main): Non-zero flags imply !daemonize. Make explicit. 2005-03-09 18:57:53 +00:00
29da4b6cf4 (empfile, teldir, motdfil, downfil, disablefil, telfil, annfil)
(banfil, authfil, timestampfil): Make file names relative to DATADIR.
(main): emp_server and files change to the data directory.  fairland
has to write newcap_script to the initial current directory, so it
keeps it and makes file names relative to DATADIR absolute.
(fixup_files): Nothing to do, remove.  This fixes the following bug:
fixup_files() formed file names by appending ep->name instead of the
base name of ep->file to datadir.  Thus, fixup_files() changed file
names even when datadir had the compiled-in value.  When emp_config()
couldn't open econfig, it failed to call fixup_files(), and different
file names got used.  Note that with this revision the file names
revert to the names used before fixup_files() was introduced.  Closes
#1146080.
(print_config): Printing file names as comments is not really useful,
remove.
(otherfiles, ofiles): Unused, remove.
(emp_config, main): Previously, pconfig had to call emp_config() even
when it didn't want to read econfig, just to run fixup_files().  This
is no longer necessary.  Simplify.
2005-03-09 18:44:50 +00:00
1583d0c6a2 (dflt_econfig): New.
(emp_config): Use it when argument is NULL.  This simplifies callers
except pconfig's main(), which now has to suppress reading the default
file.  Also fix callers to check the return value.  Previously, a typo
could easily start a grossly misconfigured program, with potentially
disastrous results.
2005-03-09 17:11:58 +00:00
84b8189c13 (daemon, daemonize): Rename to avoid name clash with BSD's daemon().
(daemonize): Supply missing declaration.
2005-03-09 14:45:41 +00:00
Ron Koenderink
0b172c6553 (NS_ALL) [_WIN32]: Change NS_EVERYTHING back to NS_ALL, #undef NS_ALL to prevent conflict with winsock2.h 2005-03-08 00:04:43 +00:00
Ron Koenderink
46a11d0d93 (main) [_WIN32]: Move install_service() so the config_file
can be verified before installing.
2005-03-06 20:54:30 +00:00
Ron Koenderink
0ba025cb4b (main,service_main) [_WIN32]: Remove printf for errors
during startup, as logerror will print to stderr or to log file.
Remove logerror for successful installation and removal.
2005-03-06 20:08:52 +00:00
Ron Koenderink
d1d7028fc7 (main,service_main) [_WIN32]: Fix config_file for WIN32.
(main,service_main,empth_exit) [_WIN32]: Add daemon flag.
Separate the debug_flag into two separate flags, one for
debugging (debug) and controlling the daemon processing
(daemon).
2005-03-06 19:53:14 +00:00
830c171dd2 (start_server, main, service_main): Call emp_config() earlier.
(main): Call loginit() later, after emp_config().  Previously, the
program logged to the default datadir until emp_config().
(init_server, start_sever): Split start_server() into initialization
and actual startup.  Move initialization before disassoc().
(main, init_server): Log server startup only after initialization is
complete.
2005-03-05 20:38:01 +00:00
e215af5ac5 (init_files): Exit unsuccessfully when a file can't be opened. 2005-03-03 19:54:25 +00:00
Ron Koenderink
3d3d6755aa (nreport, filereport, ncache, addfree, findfree, delete_old_news)
(init_nreport, update_main, start_server): Switch news to be sorted
list with all new news items added at the end of the list.  The
removal of expired news items is done at update time.  Closes #766755.
2005-03-02 23:53:10 +00:00
Ron Koenderink
55e6aca9e0 (wrmakesrc,wripglob,wrgamesdef,info,apro,mobupdate,rea,turn
upda,ef_open,logerror,emp_config,match_user,show_motd,gamedown,
typed_wu,delete_old_announcements,mobility_check,mobility_init,
allocate_memory,write_newcap_script,main,files,fairland,doconfig,)
[_WIN32]: Switchback to default mode of text.
"t" (text) is not included the ISO/ANSI C standard but "b" (binary)
is included.
2005-03-02 12:47:15 +00:00
8bb79caa87 global.h does nothing but include prototypes.h, remove. 2005-02-24 17:54:14 +00:00
552467dc08 (nullify_objects): Simply use all of bigcity_dchr. Using only parts
is confusing.
(bigcity_dchr): Fix initializer for d_maxpop.

(dchr): The previous revision accidentally changed maximum population
of sanctuaries, plains, sea and wasteland.  Revert the former two.
The latter are not used, but the new max population of zero makes more
sense, so keep it.
2005-02-21 19:52:25 +00:00
Ron Koenderink
6e9a69241e (main): Move loginit() to after the getopt(), so the -D option will
take affect for the log file.  Otherwise the server.log will be in
default data directory compiled into the server.
2005-02-21 18:17:11 +00:00
Ron Koenderink
aabed1b346 [_WIN32]: Upgrade to Windows Sockets 2. 2004-12-31 20:40:39 +00:00
Ron Koenderink
b3ec8c14da The previous rev. was committed accidentally, revert. 2004-12-30 02:51:12 +00:00
Ron Koenderink
70fcb70707 (main,install_service,remove_service,service_main) [_WIN32]:
Add the ability to specify the service name, to install
multiple services and to set -D and -e options during install.
2004-12-30 02:19:44 +00:00
Ron Koenderink
1a8488bc45 (main,mobility_check,upda,turn,rea,mobupdate,ef_open,logerror,
emp_config,gamedown,show_motd,match_user,typed_wu,
delete_old_announcements) [_WIN32]: switch the default file mode to
binary to match POSIX.  Remove the now unneccessary ifdef for
the open/fopen. Add text mode for user files (econfig/auth).
2004-12-30 01:31:03 +00:00