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.
(finish_server): New, factored out of termination code. Fixes two
places in service_main() that lacked close_files().
(close_files, loc_NTTerm): Static linkage.
(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.
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
(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.
(disassoc): src/lib/player/accept.c rev. 1.18.2.1 broke the server
when it runs as daemon, because it relies on player_socket remaining
open across disassoc(). Change disassoc() to only close file
descriptors 0..2 instead of 0..9. By the way, it should really
redirect 0..2 to /dev/null instead.
(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.
(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.
(player_init, player_accept): Move socket bind and listen from
player_accept() to player_init(). Acquiring resources during
initialization allows to exit unsuccessfully on errors. Previously,
the daemon detached itself (exiting successfully), then failed in the
background.
(player_socket): New.
Ron Koenderink [Sun, 6 Mar 2005 20:58:48 +0000 (20:58 +0000)]
(service_main) [_WIN32]: Remove the command line processing.
The secondary command line processing was adding significant
complexity for minimial gain. Now all the command line arguments
can be prequalified during the installation of the service.
(service_main) [_WIN32]: Move the initialization (init_server())
so logerror() will go to the file instead of stderr.
Ron Koenderink [Sun, 6 Mar 2005 20:08:52 +0000 (20:08 +0000)]
(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.
Ron Koenderink [Sun, 6 Mar 2005 19:53:14 +0000 (19:53 +0000)]
(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).
(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.
Ron Koenderink [Wed, 2 Mar 2005 23:53:10 +0000 (23:53 +0000)]
(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.
Ron Koenderink [Wed, 2 Mar 2005 12:47:15 +0000 (12:47 +0000)]
(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.
First step towards generalizing NSC_TYPEID to arbitrary dictionaries.
(nsc_cat) New category NSC_ID.
(nstr_comp): Resolve identifiers instead of relying on nstr_comp_val()
and nstr_coerce_val().
(valstr, nstr_coerce_val): Remove valstr member val_as_type.
(nstr_parse_val, nstr_match_ca, nstr_match_val, nstr_resolve_id)
(nstr_resolve_sel, nstr_mkselval): New.
(nstr_comp_val): Rewrite using the above.
(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.
Ron Koenderink [Mon, 21 Feb 2005 18:17:11 +0000 (18:17 +0000)]
(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.
Marc Olzheim [Mon, 21 Feb 2005 17:17:16 +0000 (17:17 +0000)]
Update patch for include/prototypes.h:1.66
src/lib/commands/mfir.c:1.21 src/lib/commands/sabo.c:1.10
src/lib/update/human.c:1.15 No functional changes.
(total_work): Remove redundant conversion to int.
(total_work): New parameter maxpop. Callers changed.
(newe, prod): Use total_work(). Old code failed to limit military
workers, thus didn't match the update.
(do_feed): Simplify.
(prod): Several columns were too narrow, and didn't align properly for
large values. Remove column wkfc to make space, widen other columns.
Columns use2, use3 and max2, max3 lack separating space on the left
for large values, which don't occur in normal game configurations.
(max_population): New, factored out of max_pop().
(max_pop): Use it. Don't support null argument anymore.
(nati, gen_power): Use max_population() instead of max_pop() with null
argument.
(show_sect_stats): Use max_population() to simplify the code.
(prod, upd_buildeff): Use max_population() to get correct new maximum
population for limiting work when tearing down a big city.
Previously, this was broken in upd_buildeff(). In prod(), it was
broken when the new designation had odd maximum population, which
should not occur.
`make depend' attempts to make dependencies for *.c. This is plain
evil, and ought to be fixed. In particular, it chokes on this file,
because it includes Windows specific headers. Which is fine, as the
file is compiled only under Windows.
Quick band-aid: wrap the file contents in #ifdef _WIN32.
(multifire): If firing at a submarine with something that can't drop
depth charges, don't disclose the target is a submarine. Old code
allowed players to find all submarine uids.
From Ray Hyatt:
(dchrstr): New member d_maxpop.
(dchr): Initialize it.
(max_pop): Use it. Use dchr[SCT_MINE].d_maxpop when called with null
argument. RES_POP now affects mountains and plains as well.
Ron Koenderink [Fri, 31 Dec 2004 20:14:10 +0000 (20:14 +0000)]
(tend_nxtitem,nxtitem,sarg_type,snxtitem,snxtitem_all,snxtsct,nxtitemp):
change NS_ALL to NS_EVERYTHING in ns_seltype because of a
conflict with winsock2.h which is used in the WIN32 build.
Ron Koenderink [Thu, 30 Dec 2004 13:53:46 +0000 (13:53 +0000)]
(multifire) [_WIN32]: Rely on misc.h to provide BSD random functions.
(multifire): switch the random seeding with the current random
value to seeding with the current time. Seeding with the
current random value does not actually improve the randomness.
Ron Koenderink [Thu, 30 Dec 2004 02:19:44 +0000 (02:19 +0000)]
(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.