2007-10-08  Scott James Remnant  <scott@netsplit.com>

	* configure.ac (AM_GNU_GETTEXT_VERSION): Bump to 0.16.1 since this
	version of gettext is needed for compatibility with Automake 1.10
	* HACKING: Bump version in the docs too.

	* compat/sysv/Makefile.am: Only create symlinks if COMPAT_SYSV is
	enabled, otherwise we leave dangling ones.

	* Makefile.am (ACLOCAL_AMFLAGS): Specify that aclocal install
	ordinarily system-wide macros into m4 (libtool.m4, specifically).
	This makes it easier for packagers to modify autoconfery since
	aclocal is no longer a destructive event.
	* configure.ac (AM_INIT_AUTOMAKE): Increase Automake requirement to
	1.10 to ensure we have aclocal --instal
	* HACKING: Increase Automake version in the docs.

2007-09-21  Scott James Remnant  <scott@netsplit.com>

	* init/job.c (job_detect_stalled, job_free_deleted): Call job_init()
	on entry, since we don't have a Job pointer passed to us, we need
	to make sure we don't dereference a potentially NULL list.

2007-06-22  Scott James Remnant  <scott@netsplit.com>

	* init/tests/test_process.c (test_kill): Make sure that all processes
	in the process group are killed, rather than just the lone one.
	* init/process.c (process_kill): Send the signal to all processes
	in the same process group as the pid.
	* init/tests/test_job.c (test_change_state, test_kill_process):
	After spawning a child, call setpgid() to put it in its own process
	group otherwise we could end up TERMing ourselves.

2007-06-12  Scott James Remnant  <scott@netsplit.com>

	* compat/sysv/shutdown.c: Use nih pidfile functions since they're
	more reliable than doing it ourselves.

2007-06-04  Scott James Remnant  <scott@netsplit.com>

	* upstart/Makefile.am (libupstart_la_LIBADD): Add $(LTLIBINTL)
	* init/Makefile.am (init_LDADD): Reorder and add $(LTLIBINTL)
	* util/Makefile.am (initctl_LDADD): Reorder and add $(LTLIBINTL)
	* compat/sysv/Makefile.am (reboot_LDADD): Reorder and add $(LTLIBINTL)
	(runlevel_LDADD): add $(LTLIBINTL)
	(shutdown_LDADD): Reorder and add $(LTLIBINTL)
	(telinit_LDADD): Reorder and add $(LTLIBINTL)
	* logd/Makefile.am (logd_LDADD): Add $(LTLIBINTL)

2007-06-03  Scott James Remnant  <scott@netsplit.com>

	* init/tests/test_job.c (test_run_process): Add a test case for a
	crasher when the event has no arguments.
	* init/job.c (job_run_process): Fix the bug, we need to check the
	arguments before trying to append them.

2007-05-27  Scott James Remnant  <scott@netsplit.com>

	* init/cfgfile.h (CFG_DIR): Drop this define, since it's in paths.h
	(CfgDirectory): 

2007-05-18  Scott James Remnant  <scott@netsplit.com>

	* init/event.c (event_copy): Use nih_str_array_copy here, to make the
	code somewhat simpler.
	(event_finished): Copy the arguments and environment from the old
	event, rather than stealing and reparenting.
	* init/job.c (job_copy): Use nih_str_array_copy here too.
	(job_run_process): Use nih_str_array_append to add the arguments from
	the emission onto the command run.

	* TODO: Update.

2007-04-24  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Add AM_PROG_CC_C_O since we use per-target flags
	for one of the test cases.

2007-03-16  Scott James Remnant  <scott@netsplit.com>

	* upstart/message.c (upstart_message_newv): Add va_end to match
	va_copy because the standard says so.
	* upstart/wire.c (upstart_push_packv, upstart_pop_packv): Add
	va_end here as well.

2007-03-13  Scott James Remnant  <scott@netsplit.com>

	* init/main.c: Wait until we've closed inherited standard file
	descriptors and opened the console instead before trying to open the
	control socket; otherwise we end up closing it by accident if we
	weren't opened with sufficient descriptors in the first place.
	Also wait until we've set up the logger before trying to parse the
	configuration.  In fact both of these things need to be pretty low
	down the main() function.

	* init/tests/test_job.c (test_run_process): Skip /dev/fd test cases
	if that's not available.

	* init/tests/test_control.c (test_log_priority): Make sure we know
	that the message has been sent before calling the watcher.

	* init/cfgfile.c (cfg_watch_dir): We get ENOSYS for missing inotify
	support, not EOPNOTSUPP.
	* init/tests/test_cfgfile.c (test_watch_dir): Actually make the
	directory tree before testing for inotify, since we use the same
	tree there too.

	* util/initctl.c (job_info_output): Restructure so gcc doesn't think
	name can be used uninitialised.
	* init/tests/test_cfgfile.c (test_watch_dir): Correct an error where
	i wouldn't be initialised if we skipped the inotify tests.

	* util/initctl.c (job_info_output): Restructure so gcc doesn't think
	* init/process.c (process_setup_environment): job id fits inside
	a %u now

	* upstart/message.h: Style; always refer to "unsigned int" as
	"unsigned int", and never "unsigned.
	* upstart/tests/test_message.c (my_handler): Catch a stray couple
	of "unsigned"s

	* init/control.c (control_job_query, control_job_start) 
	(control_job_stop): Change type of id argument to unsigned int,
	and call printf with %u to output it.
	* init/tests/test_control.c (check_job, check_job_instance) 
	(check_job_instance_end, check_job_status__waiting) 
	(check_job_status_end__waiting, check_job_status__starting) 
	(check_job_status_end__starting, check_job_status__running) 
	(check_job_status_end__running, check_job_status__pre_stop) 
	(check_job_status_end__pre_stop, check_job_status__stopping) 
	(check_job_status_end__stopping, check_job_status__deleted) 
	(check_job_status_end__deleted, check_job_unknown) 
	(check_job_invalid, check_job_unchanged, check_event): Change
	type of id arguments to unsigned int.
	(check_list): Change type of id to unsigned int.
	* init/tests/test_notify.c (check_job_status) 
	(check_job_status_end, check_job_finished, check_event) 
	(check_event_caused, check_event_finished): Change type of id
	arguments to unsigned int.

	* init/job.h (Job): Change the type of the id to unsigned int.
	* init/job.c (job_next_id): Change ids to be unsigned ints, and now
	we can just use %u in the nih_error call.
	(job_find_by_id): Change argument to be unsigned int
	* init/tests/test_job.c (test_find_by_id): Change id type to unsigned
	int.
	* init/event.h (Event): Change the type of the id to unsigned int.
	* init/event.c (event_emit_next_id): Change ids to be unsigned ints,
	and now we can just use %u in the nih_error call.
	(event_emit_find_by_id): Change argument to be unsigned int
	* init/tests/test_event.c (test_emit, test_emit_find_by_id) 
	(check_event, check_event_finished): Change id type to unsigned int.

	* util/initctl.c (output_name): Use an unsigned int for the job id,
	which means we can use ordinary %u for the printf argument.
	(handle_job, handle_job_finished, handle_job_instance) 
	(handle_job_instance_end, handle_job_status) 
	(handle_job_status_end, handle_job_unknown, handle_job_invalid) 
	(handle_job_unchanged, handle_event, handle_event_caused) 
	(handle_event_finished): Change argument type of id from uint32_t
	to unsigned int.
	(job_info_output): Change output type of id from %zu to %u

	* upstart/message.c (upstart_message_handle): Use unsigned int for
	ids, rather than a fixed-width type.
	* upstart/tests/test_message.c (my_handler): Use unsigned int for
	the ids, and give "unsigned int" instead of "unsigned" to va_arg as
	a matter of style.

	* upstart/wire.c (upstart_push_int, upstart_pop_int): Send over the
	wire using a plain old integer type, instead of a fixed width type;
	there's no advantage to using the fixed-width type and we could hurt
	ourselves if we tried running on ILP64.
	(upstart_push_unsigned, upstart_pop_unsigned): Likewise use a plain
	unsigned int over the wire.
	(upstart_push_string, upstart_pop_string): Use an unsigned int for
	the length of the string, technically this means that we silently
	truncate any string that's greater than 4GB on 64-bit platforms;
	it's either that or make the test cases harder (we did this before
	anyway).
	(upstart_push_header, upstart_pop_header): Type is always an unsigned
	int (best conversion from an enum)

2007-03-11  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Bump version to 0.3.9

	* NEWS: Update.

	* util/man/initctl.8: Document the new commands.

	* TODO: Update.

	* init/job.c (job_handle_event): Correct the function so we don't
	try and stop the master of an instance, and cause an assertion error.

	* util/initctl.c: Oops, correct function pointers in command table

	* util/tests/test_initctl.c (test_version_action): 

	* util/initctl.c (handle_version): Handle receipt of the version
	reply.
	(version_action): Send the version-query message to the server and
	expect one response.
	(log_priority_action): Parse the single argument into an NihLogLevel
	and send it to the server.

	* init/control.c (control_version_query, control_log_priority):
	Functions to handle the new messages from the server pov
	* init/tests/test_control.c (test_version_query) 
	(test_log_priority): Test the new messages are handled properly.
	(check_version): Check the version string matches.
	* upstart/message.h: Add messages for querying the version of the
	init daemon and changing the log priority.
	* upstart/message.c (upstart_message_newv)
	(upstart_message_handle): Marshal the new messages.
	* upstart/tests/test_message.c (test_new, my_handler) 
	(test_handle): Test the marshalling of the new messages,

	* upstart/libupstart.ver: Add enum functions to the global list.

	* util/initctl.c (start_action, stop_action): Imply --no-wait if
	we take the job id or name from an environment variable, since we'd
	end up waiting for ourselves otherwise
	* util/tests/test_initctl.c (test_start_action, test_stop_action):
	Update test cases to make sure no-wait is implied.

2007-03-09  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Bump version to 0.3.8

	* NEWS: Updated.
	* configure.ac: Increase version to 0.3.7

	* init/tests/test_job.c (test_change_state): Add a test case for
	deleting the last instance of a replaced job.
	* init/job.c (job_change_state): When moving a instance of a job into
	the deleted state, check whether we should replace the job it's an
	instance of, and if so, change that job's state too.
	* TODO: Update.

	* util/initctl.c (handle_job_list): Always allocate current_list,
	since we need it to be the parent of pointers we attach to it.
	(handle_job_list_end): Always free the current list, only suppress
	output if there aren't any entries in it.
	(initctl_recv): Check the current_list pointer, no need for in_list
	(handle_job_instance, handle_job_instance_end, handle_job_status):
	Check current_list not in_list.
	* util/tests/test_initctl.c: Correct some memory leaks.

	* init/process.c (process_setup_environment): Set the UPSTART_JOB_ID
	environment variable to the job's unique id.
	* init/tests/test_process.c (test_spawn): Make sure it's set.

	* util/man/initctl.8: Update the initctl manpage.
	* compat/sysv/man/reboot.8: Correct a minor grammar error.
	* compat/sysv/man/shutdown.8: Fix reference from runlevel to telinit.

	* README: Add a README that copies the text from the web page and
	adds some notes about recommended operating system versions.

	* util/initctl.c: Completely rewrite initctl, top to bottom; handling
	of the new messages is done natively, meaning that the commands just
	vary the requests send and number of responses expected.
	* util/tests/test_initctl.c: Test all of the new code.

	* init/main.c: Improve restarting and rescuing a little; store the
	program path in a static variable so we can always access it, and
	use the exported loglevel to pass the same to the new process.
	* TODO: Update.

	* compat/sysv/shutdown.c: More error/fatal adjustments.
	* compat/sysv/telinit.c: More error/fatal adjustments.

2007-03-08  Scott James Remnant  <scott@netsplit.com>

	* init/main.c (main, crash_handler): Promote deadly errors to nih_fatal
	* logd/main.c (main): Promote deadly errors to nih_fatal
	* compat/sysv/reboot.c (main): Promote deadly errors to nih_fatal
	* compat/sysv/shutdown.c (main, shutdown_now): Promote deadly errors
	to nih_fatal
	* compat/sysv/telinit.c (main): Promote deadly errors to nih_fatal

	* init/event.c (event_pending): The message that we're handling an
	event should be logged with --verbose.

	* init/cfgfile.c (cfg_parse_script): Remove the unnecessary check for
	a token inside a script block.

	* TODO: Update.

	* init/control.c (control_watch_jobs): Rename to control_subscribe_jobs
	and update to handle new event name.
	(control_unwatch_jobs): Rename to control_unsubscribe_jobs and update
	to handle the new event name.
	(control_watch_events): Rename to control_subscribe_events and update
	to handle the new event name.
	(control_unwatch_events): Rename to control_unsubscribe_events and
	update to handle the new event name.
	* init/tests/test_control.c (test_watch_jobs): Rename to
	test_subscribe_jobs and update to new event name.
	(test_unwatch_jobs): Rename to test_unsubscribe_jobs and update to 
	new event name.
	(test_watch_events): Rename to test_subscribe_events and update to
	new event name.
	(test_unwatch_events): Rename to test_unsubscribe events and update
	to new event name.

	* upstart/message.h: Rename the watch commands to subscribe/unsubscribe
	and regroup with new message numbers.
	* upstart/message.c (upstart_message_newv) 
	(upstart_message_handle): Marshal the updated subscription messages.
	* upstart/tests/test_message.c (test_new, my_handler) 
	(test_handle): Update tests to new names and numbers.
	* TODO: Update.

	* upstart/message.c (upstart_message_handle): Raise a the unknown
	message error if the type is unknown, rather than the invalid message
	error.
	* upstart/tests/test_message.c (test_handle): Correct test case.

	* init/job.c (job_change_state): Correct a problem here too, when
	moving from pre-stop to running, we don't want to emit a started event
	since we never emitted a stopping event and never killed the process
	anyway.  We do need to notify the job as finished, since the process
	that tried to stop it will need to be told not to wait any longer.
	* init/tests/test_job.c (test_change_state): Add a test for pre-stop
	back to running.

	* doc/states.dot: Fix an error in the state diagram; when moving from
	starting back to waiting, due to a failed respawn, we need to emit
	the stopped event otherwise it will never happen.
	* doc/states.png: Update.

2007-03-05  Scott James Remnant  <scott@netsplit.com>

	* upstart/message.c (upstart_message_new): Make this a wrapper around
	(upstart_message_newv): which has all the old code, but accepts a
	va_list instead of making its own.
	* upstart/message.h: Add prototype.

	* init/main.c (crash_handler): Simply trying to leave a SEGV handler
	doesn't work so well, we end up repeating the problem instruction.
	We really can't resume from this point, and can't even jump elsewhere
	since our state is probably buggered up.  Only thing for it is to
	re-exec ourselves with a clean state.

	* init/cfgfile.c (cfg_read_job, cfg_delete_handler): Don't try and
	free the magic (void *)-1 replacement (delete).

	* util/events.c, util/events.c, util/jobs.c, util/jobs.h: With the
	new message responses, that intermix event and job information freely,
	it no longer makes sense to distinguish between them.  So fold these
	files back into the main initctl.c
	* util/initctl.h: Drop unused header.
	* util/Makefile.am (initctl_SOURCES): Update sources list.
	(TESTS): Change which tests we build
	(test_initctl_SOURCES, test_initctl_CFLAGS, test_initctl_LDFLAGS) 
	(test_initctl_LDADD): Build the new combined test case binary, use
	an automake feature to rebuild initctl.c with -DTEST and a different
	.o file, and thus be able to define out main()

	* util/tests/test_events.c, util/tests/test_jobs.c: Collapse the two
	test case files into one single
	* util/tests/test_initctl.c

	* init/control.c (control_job_find): And implement the find function
	that returns a list of jobs matching an optional pattern.
	* init/tests/test_control.c: Make sure we do send all messages.
	(check_list): Complex function to check the responses to a job list
	(test_job_find): Test a couple of job lists.
	* init/tests/test_notify.c: Make sure we do send all messages.

	* init/control.c (control_job_query): Implement the query message,
	this just needs to return the status or instance set.
	* init/tests/test_control.c (test_job_query): Test the query command.
	(check_job_status__deleted, check_job_status_end__deleted): Pair of
	functions to check we can query deleted jobs directly.

	* init/control.c (control_send_instance): Function to send an instance
	job, collating all of its instances together.
	* init/control.h: Update.
	* init/tests/test_control.c (test_send_instance): Check we receive
	the right messages.
	(check_job_instance, check_job_instance_end): Pair of functions to
	check the instance messages.

	* upstart/message.h: Add new UPSTART_JOB_INSTANCE and
	UPSTART_JOB_INSTANCE_END messages which we'll use to communicate that
	a job is an instance, and group the instances of it together.
	* upstart/message.c (upstart_message_new, upstart_message_handle):
	Marshal the new instance messages.
	* upstart/tests/test_message.c (test_new, my_handler) 
	(test_handle): Test the new message types.

	* upstart/message.h: Restore arguments to JOB_LIST, but rename to
	pattern since that's what it is.
	* upstart/message.c (upstart_message_handle): Restore arguments
	with updated name.
	* upstart/tests/test_message.c (test_new, my_handler) 
	(test_handle): Restore tests for arguments, rename and make sure we
	include a wildcard.

2007-03-04  Scott James Remnant  <scott@netsplit.com>

	* upstart/message.h: Drop arguments to JOB_LIST.
	* upstart/message.c (upstart_message_new, upstart_message_handle):
	Drop arguments to JOB_LIST.
	* upstart/tests/test_message.c (test_new, my_handler) 
	(test_handle): Drop the arguments from the test.

	* init/control.c (control_job_start): Update to return INVALID for
	instances and replacements; add the forgotten UPSTART_JOB message.
	(control_job_stop): Update to return INVALID for replacements; add
	the forgotten UPSTART_JOB message.  Deal with instance masters
	magically by iterating all instances and stopping those instead.
	* init/tests/test_control.c (check_job_deleted): Rename to 
	check_job_invalid and check that message.
	(check_job): Function to check the job we've acted upon.
	(test_job_start): Check that we get the UPSTART_JOB message first,
	restore the check on deleted jobs causing an error and add checks
	that instance and replacement jobs also cause an error.
	(test_job_stop): Check that we get the UPSTART_JOB message first,
	restore the check on deleted jobs causing an error.  Make sure
	instances are handled.

	* upstart/message.h: More message changes; add a JOB_FIND message
	and replace UPSTART_JOB_DELETED with UPSTART_JOB_INVALID since there's
	a few more problem conditions.
	* upstart/message.c (upstart_message_new, upstart_message_handle):
	Marshal the new message and update names.
	* upstart/tests/test_message.c (test_new, my_handler) 
	(test_handle): Update tests to check the new message and update the
	values and names of the existing ones.

	* init/job.h (Job): Remove the delete flag, add replacement and
	replacement_for pointers instead.
	* init/job.c (job_new): Initialise replacement and replacement_for
	pointers to NULL.
	(job_find_by_name): Update to return what job the one we found is
	a replacement for, and to skip DELETED jobs.
	(job_instance): Make it simply illegal to call this for deleted jobs,
	instances or replacements.
	(job_change_goal): Make it illegal to change the goal of a replacement
	job.
	(job_free_deleted): Remove the previous code to handle deleted instance
	masters, because it's now bogus.
	(job_should_replace): New function to determine whether a job is
	replaceable.
	* init/tests/test_job.c (test_new): Check pointers are set.
	(test_copy): Check that replacement and replacement_for are not
	copied, since their state of an individual job.
	(test_find_by_name): Update tests to make sure we ignore deleted jobs,
	instances and replacements.
	(test_instance): Remove test that will now cause an assertion,
	and no longer check delete is set.
	(test_change_goal): Remove test that will now cause an assertion.
	(test_free_deleted): Remove test cases for deleted masters.
	(test_should_replace): Test the new check function.
	(test_change_state): Make sure that we end up in deleted for instances
	and replaced jobs, and that replacements become the real job.
	* init/cfgfile.c (cfg_read_job): Update to handle replacement jobs;
	the old job's previous replacement is discarded, and set to the
	current job; and then if the job should be replaced, it's moved
	to deleted (which should promote the new job).
	(cfg_delete_handler): Handle deletion of a job in a similar manner,
	except we sent the replacement pointer to the special -1 value since
	we have no actual replacement.
	* init/tests/test_cfgfile.c (test_watch_dir): Update tests to make
	sure that deletion and modification are handled wrt replacement.
	(test_read_job): Make sure that reparsing an existing file is handled.
	* init/tests/test_control.c (test_job_start): Remove checks that
	delete gets set to true for instances.
	(test_job_stop, test_job_start): Temporarily comment out deleted
	job behaviour, since that's been somewhat changed.

	* upstart/message.h: We're not going to return JOB_LIST for JOB_STOP
	since that's just awkward for the client; just act on the master,
	and return JOB_UNCHANGED.

	* init/notify.c (notify_job_status): Move this function to
	* init/control.c (control_send_job_status): here, since we need it for
	the new control responses.
	(control_job_query): New single function to list all jobs or a
	particular job.
	* init/control.h: Add prototype.
	* init/tests/test_control.c (test_error_handler): Simplify this a
	little to just sending a NO_OP message, since we can send an entire
	stream of messages and leave them in the queue.
	(check_job_status__stopping, check_job_process) 
	(check_job_status_end__stopping): Trio of check functions for a job
	status that's stopping, with an active main process.
	(test_send_job_status): Test the now global status function.
	(check_job_status__starting, check_job_status_end__starting): Pair
	of check functions for a starting job with no process yet.
	(test_watch_jobs, test_unwatch_jobs): Update to expect the full new
	job status messages, with an optional process part as well.
	(check_event): Function to check an event.
	(test_watch_events): Minor update to use above function.
	(check_job_status__waiting, check_job_status_end__waiting): Pair of
	check functions for the first step in starting a job (goal change only)
	(check_job_unknown, check_job_deleted, check_job_unchanged): Trio
	of functions to check common error responses.
	(test_job_start): Update tests to newer behaviour.
	(check_job_status__running, check_job_status_end__running) 
	(check_job_status__pre_stop, check_job_status_end__pre_stop): Checks
	for the states we go through when stopping a job.
	(test_job_stop): Update tests to newer behaviour.
	* init/notify.c (notify_job, notify_job_event, notify_job_finished):
	Update to call the newly exported function.
	* init/job.c: Make job_id and job_id_wrapped externally available.
	* init/job.h: Update.
	* init/event.c: Make emission_id and emission_id_wrapped externally
	available.
	* init/event.h: Update.

	* upstart/message.h: Rename UPSTART_JOB_INVALID to
	UPSTART_JOB_UNCHANGED, as it's not really invalid just a no-op
	* upstart/message.c (upstart_message_new, upstart_message_handle):
	Update the constant, fields are unchanged,
	* upstart/tests/test_message.c (test_new, my_handler) 
	(test_handle): Rename constants/messages.

	* upstart/message.h: Turns out we need extra errors to indicate that
	the job was deleted or already at that goal, otherwise the client
	would sit there waiting for the finished event.	
	* upstart/message.c (upstart_message_new, upstart_message_handle):
	Marshal the new error messages.
	* upstart/tests/test_message.c (test_new, my_handler) 
	(test_handle): Test the handling of the new messages.

	* init/tests/test_job.c (test_free_deleted): Found a bug; because
	master instances never change state, they never end up in the deleted
	state so are never reaped.  Add some test cases for cleaning them up,
	but not while they have remaining instances.
	* init/job.c (job_free_deleted): Implement the bug fix.

	* init/job.c (job_instance): Split out the instance spawning code
	into its own function, as we'll frequently need a pointer to the
	instance before we try and change the goal.
	(job_change_goal): Clean this function back up again, it no longer
	needs to return values and can assert that it's never called for
	deleted jobs or instance mastersr.
	(job_handle_event): Spawn an instance when we get a start event.
	* init/job.h: Update.
	* init/tests/test_job.c (test_instance): Check instance creation.
	(test_change_goal): Update tests now that it doesn't return a value
	again, and doesn't spawn instances itself.
	(test_handle_event): Make sure instances are spawned.

	* init/tests/test_event.c (test_poll): Needs a slight fix now that
	we generate more events than we check, and that subscriptions go
	away automatically.

	* init/notify.c (notify_job_status): Static function to handle
	sending the more complicated job status message series 
	(notify_job): Call notify_job_status() to send the new-style message
	(notify_job_event): Send the new UPSTART_EVENT_CAUSED message with
	the emission id, then call notify_job_status() to send the new-style
	common status message.
	(notify_job_finished): New function to be called when we reach the
	job rest state, notifies and unsubscribes directly subscribed
	processes, and includes failed information.
	(notify_event_finished): Unsubscribe processes after sending the
	finished event, since the event has gone away.  Also don't send
	this to processes subscribed to all events, since it's not useful
	for them.
	* init/notify.h: Add prototype.
	* init/tests/test_notify.c: Update all test cases and helper
	functions to the new message types.
	(test_job_finished): Check the new finished message is sent with
	a status message preceeding it.
	* init/job.c (job_change_state, job_change_state): Notify subscribed
	processes with notify_job_finished() when in the running (for service)
	or waiting states, just before we drop the cause.

	* upstart/message.h: Add failed, failed_process and exit_status
	arguments to UPSTART_JOB_FINISHED.
	* upstart/message.c (upstart_message_new, upstart_message_handle): 
	Marshal the new arguments.
	* upstart/tests/test_message.c (test_new, my_handler) 
	(test_handle): Test the new arguments.

	* upstart/message.h: Update the message types, introducing a more
	structured job message set and replacing the UPSTART_EVENT_JOB_STATUS
	message with UPSTART_EVENT_CAUSED which will be immediately followed
	by an ordinary UPSTART_JOB_STATUS message.
	* upstart/message.c (upstart_message_new, upstart_message_handle):
	Marshal the new messages.
	* upstart/tests/test_message.c (test_new, my_handler) 
	(test_handle): Test the new message types.
	* TODO: Update.

2007-03-03  Scott James Remnant  <scott@netsplit.com>

	* TODO: Update.

	* init/cfgfile.c (cfg_parse_exec, cfg_parse_script): Separate out
	the parsing of an exec or script stanza into separate functions,
	seeing as this is quite a common operation.  This also means we
	just need to change them in one place now.
	(cfg_parse_process): Function to call either of the above depending
	on the next argument.
	(cfg_stanza_exec): Call cfg_parse_exec instead.
	(cfg_stanza_script): Call cfg_parse_script instead.
	(cfg_stanza_pre_start, cfg_stanza_post_start) 
	(cfg_stanza_pre_stop, cfg_stanza_post_stop): Call cfg_parse_process
	with the right arguments instead of doing by hand in each function.

	* init/event.c (event_emit_next_id): Split the id assigning code into
	a static inline function for easier modification.
	* init/job.c (job_next_id): Use the same style function here too.

2007-03-02  Scott James Remnant  <scott@netsplit.com>

	* init/event.c (event_emit): Port the slightly more efficient in the
	early case code from job_new.

	* init/job.h (Job): Add a unique id to the job structure.
	* init/job.c (job_new): Assign an incrementing id to each new job
	allocated.
	(job_find_by_id): Locate a job by its unique id, sadly not very
	efficient in a hash table ;-)
	(job_name): New hash key function since name isn't the first entry
	anymore.
	(job_init): Change hash key function.
	* init/tests/test_job.c (test_find_by_id): Make sure we can find a
	job by its id.

	* init/job.c (job_change_goal): Return the new instance in that
	circumstance, and clean up a little bit.
	* init/job.h: Update prototype.
	* init/tests/test_job.c (test_change_goal): Update tests.

	* init/job.c (job_find_by_name): Skip jobs marked for deletion too.
	* init/tests/test_job.c (test_find_by_name): Update test case.

	* init/event.h, init/notify.h, upstart/message.h: Provide C-level names
	for enums, this makes the compiler generate things that gdb can get.

	* init/job.c (job_run_process, job_kill_process, job_kill_timer):
	Change process argument to be a plain ProcessType, this means we
	know exactly which process we're trying to run or kill.
	(job_change_state): Update calls to job_run_process
	and job_kill_process
	* init/tests/test_job.c (test_run_process, test_kill_process): Update
	function calls to just pass a ProcessType in.

	* upstart/enum.h: Rename JobAction to ProcessType.
	* upstart/enum.c (job_action_name): Rename to process_name.
	(job_action_from_name): Rename to process_from_name.
	* upstart/tests/test_enum.c (test_action_name, test_action_from_name):
	Rename and update to match.
	* init/job.c (job_new, job_copy, job_change_state) 
	(job_next_state): Change JOB_*_ACTION constants to PROCESS_*.
	(job_find_by_pid): Change JobAction argument to ProcessType.
	(job_emit_event): Call process_name on the failed process.
	(job_child_reaper): Update to use ProcessType instead of JobAction.
	* init/job.h (Job): Change type of failed_process to ProcessType.
	* init/tests/test_job.c (test_find_by_pid): Update to use ProcessType
	instead of JobAction in tests.
	(test_new, test_copy, test_change_goal, test_change_state) 
	(test_next_state, test_run_process, test_kill_process) 
	(test_child_reaper, test_handle_event_finished): Change JOB_*_ACTION
	constants to PROCESS_*
	* init/cfgfile.c (cfg_stanza_exec, cfg_stanza_script) 
	(cfg_stanza_pre_start, cfg_stanza_post_start) 
	(cfg_stanza_pre_stop, cfg_stanza_post_stop): Change JOB_*_ACTION
	constants to PROCESS_*
	* init/tests/test_cfgfile.c (test_stanza_exec) 
	(test_stanza_script, test_stanza_pre_start) 
	(test_stanza_post_start, test_stanza_pre_stop) 
	(test_stanza_post_stop, test_read_job, test_watch_dir): Change
	JOB_*_ACTION constants to PROCESS_*
	* init/tests/test_event.c (test_poll): Change JOB_*_ACTION constants
	to PROCESS_*
	* init/tests/test_control.c (test_job_start, test_job_stop): Change
	JOB_*_ACTION constants to PROCESS_*

	* init/cfgfile.c (cfg_watch_dir): Restore the prefix argument; pass
	as the data pointer to the inotify callbacks and visitor function.
	Change the return value to be the watch structure.
	(cfg_job_name): Add prefix argument and prepend to relative path.
	(cfg_create_modify_handler, cfg_delete_handler, cfg_visitor): Get
	the prefix for the job names from the data pointer and pass to
	cfg_job_name().
	* init/cfgfile.h: Update prototypes.
	* init/tests/test_cfgfile.c (test_watch_dir): Actually test the
	watch functions.
	* init/main.c (main): Pass NULL for the prefix for the global job
	directory, compare the return value against (void *)-1.
	* TODO: Update.

	* init/cfgfile.c (cfg_stanza_on): Drop the simple on stanza.
	* init/tests/test_cfgfile.c (test_stanza_on): Remove test case.

	* TODO: Update.

2007-03-01  Scott James Remnant  <scott@netsplit.com>

	* util/jobs.c (handle_job_status): Drop the process field from the
	output for now.
	* util/events.c (handle_event_job_status): Likewise
	* util/tests/test_jobs.c (test_start_action, test_list_action) 
	(test_jobs_action): Drop pid from messages we simulate.
	* util/tests/test_events.c (test_emit_action): Likewise.

	* upstart/message.c (upstart_message_new, upstart_message_handle):
	Remove the pid field from the job status and event job status
	messages.
	* upstart/message.h: Update description of job status and event
	job status message to remove the pid field.
	* upstart/tests/test_message.c (test_new, my_handler) 
	(test_handle): Remove checks using the pid field.

	* init/control.c (control_job_start, control_job_stop) 
	(control_job_query, control_job_list): Remove the pid field from
	the messages, it'll come back later when we get better message
	formats.
	* init/tests/test_control.c (check_job_status, check_job_waiting) 
	(check_job_started, check_job_stopped): Remove checks on the process
	id, since that field is gone from the message.
	(test_job_stop): Use the pid field of the main process.
	(test_job_start): Initialise the main action process.

	* init/notify.c (notify_job, notify_job_event): Remove the pid field
	from the message, it'll come back later when we get better message
	formats.
	* init/tests/test_notify.c (check_job_status) 
	(check_event_job_status): Remove checks on the pid, since that field
	is no longer present.

	* init/job.c (job_process_copy): Use job_process_new here, oops.

	* init/cfgfile.c (cfg_stanza_exec, cfg_stanza_script) 
	(cfg_stanza_pre_start, cfg_stanza_post_start) 
	(cfg_stanza_pre_stop, cfg_stanza_post_stop): Use job_process_new
	to allocate process structures and store in the process array.
	* init/tests/test_cfgfile.c (test_read_job, test_stanza_exec) 
	(test_stanza_script, test_stanza_pre_start) 
	(test_stanza_post_start, test_stanza_pre_stop) 
	(test_stanza_post_stop): Update test cases to use process array
	member information.

	* init/tests/test_event.c (test_poll): Update to use newer job process
	array and find the pid under there.

	* init/job.h (Job): Remove the pid and aux_pid fields; replace the
	individual JobProcess pointers with an array of them of a fixed
	minimum size; replace failed_state with failed_process.
	(JobProcess): add a pid field here, so now we can obtain the pid on
	an individual process/action basis rather than global.
	* init/job.c (job_process_new): Function to create a JobProcess
	structure, setting the initial values to FALSE/NULL/0.
	(job_process_copy): Function to copy a JobProcess.
	(job_new): Don't initialise the pid or aux_pid members, initialise
	the process array to a fixed initial size and set the members to NULL,
	initialise the failed_process member to -1.
	(job_copy): Update to use job_process_copy and copy the process array.
	(job_find_by_pid): Look through the process structures in the job's
	process array to find the pid, and optionally return which action it
	was.
	(job_change_state): Call job_kill_process in the JOB_KILLED state if
	we have a main process and that has a pid, pass in the main process.
	(job_next_state): Check the process id of the main process when
	deciding what the next state is for running.
	(job_run_process): Store the process id in the process structure
	(job_kill_process): Accept a process structure and use that to obtain
	the process id we need to send TERM too.  Remove the code that forced
	a state change if kill() failed, since we will get a child signal
	anyway and should do it there.
	(job_kill_timer): Likewise, accept a process structure and don't
	forcibly change the state anymore.
	(job_child_reaper): Rewrite to switch based on the action that died,
	rather than the state we were in; assert that the state is what we
	expected.
	(job_emit_event): The argument to the failed event is now the action
	name, rather than the state name; an action of -1 indicates that
	respawn failed.
	* init/tests/test_job.c (test_process_new, test_process_copy): Make
	sure the structure is created and copied properly.
	(test_new, test_copy): Drop checks on the pid and aux_pid members,
	add checks for the process array and pid members of processes.
	(test_find_by_pid): Update test case to make sure we can find the pid
	of any process, returning the action index rather than the process
	pointer.
	(test_run_process, test_kill_process, test_change_goal)
	(test_change_state, test_next_state, test_child_reaper): Update test
	cases to use pid fields inside process structures rather than the
	pid or aux_pid members.
	(test_handle_event, test_handle_event_finished) 
	(test_free_deleted): Update to avoid pid field checks.

	* upstart/enum.h (JobAction): Enumeration of different actions.
	* upstart/enum.c (job_action_name, job_action_from_name): Enumeration
	to string conversion functions.
	* upstart/tests/test_enum.c (test_action_name) 
	(test_action_from_name): Tests for the new functions.

	* init/cfgfile.c (cfg_read_job): Instead of trying to copy over an
	old job's state and instances into the new one, mark the old job
	as deleted.  This ensures we never end up applying a new post-stop
	script to a job started with an old pre-start script, etc.  It also
	makes life so much simpler.
	* init/tests/test_cfgfile.c (test_read_job): Update tests to make
	sure the old job is marked for deletion, instead of freed.
	* TODO: Update.

	* init/notify.c (notify_job): Split out notification to processes
	subscribed to the cause event into a new function
	(notify_job_event): We can call this when we change cause.
	* init/job.c (job_change_state): Notify anyone subscribed to the
	job after we've changed the state, rather than before, otherwise
	we won't know the new pids or anything.
	(job_change_cause): Call notify_job_event before changing the cause
	so that subscribers get a final status update.
	* init/tests/test_notify.c (test_job_event): Check the new function.
	* TODO: Update.

	* init/cfgfile.c (cfg_stanza_respawn): Remove the shortcut that
	lets you specify "respawn COMMAND".  It was confusing as it hid
	the common "[when] exec"/"[when] script" syntax, made it non-obvious
	that "exec" and "respawn" were the same flag, etc.
	* init/tests/test_cfgfile.c (test_stanza_respawn): Update tests.
	(test_stanza_service): Fix test case to not use shortcut.
	* logd/event.d/logd.in: Update to not use respawn shortcut.

2007-02-25  Scott James Remnant  <scott@netsplit.com>

	* init/job.c (job_child_reaper): Shift the signal value into the
	higher byte to make it easier to detect, and not stamp over exit
	statuses between 128 and 255.
	(job_emit_event): Detect the signal stored in the new way.
	* init/cfgfile.c (cfg_stanza_normal): Store signal in the higher bytes.
	* init/tests/test_job.c (test_copy, test_change_state) 
	(test_child_reaper): Update test cases.
	* init/tests/test_cfgfile.c (test_stanza_normal): Update test.

	* TODO: Update.

	* init/event.h (PWRSTATUS_EVENT): Add new power-status-changed event.
	* init/main.c (pwd_handler): Handle the SIGPWR signal by generating
	the new event, leave it up to a job to parse the file and do
	whatever it likes.

	* TODO: Update.

2007-02-13  Scott James Remnant  <scott@netsplit.com>

	* upstart/tests/test_message.c (test_reader, test_handle_using)
	(test_handle); Usual fix for gcc optimiser thinking that fixed
	for loops might not be.
	* init/tests/test_job.c (test_run_process, test_kill_process):
	Likewise.
	* init/tests/test_notify.c (test_subscription_find): I still don't
	know what a type-punned pointer is, nor why dereferencing such a
	thing would break strict-aliasing rules.
	* init/tests/test_cfgfile.c (test_read_job): More type-punning.
	* util/tests/test_jobs.c (test_start_action): More for-loop action.
	* util/tests/test_events.c (test_emit_action): And again.

2007-02-11  Scott James Remnant  <scott@netsplit.com>

	* init/job.c (job_change_goal): We need to be able to stop a running
	job without a process, because that's what a job-as-state is!  The
	check was added because job_child_reaper calls job_change_goal and
	then job_change_state immediately after, we should fix that instead.
	(job_child_reaper): If we call job_change_goal while in the running
	state, it will call job_change_state for us; so check for that first
	and don't change the state!
	* init/tests/test_job.c (test_change_goal): Update the test to ensure
	that we can stop a job with no running process.

	* init/cfgfile.c (cfg_stanza_normalexit): normalexit is inconsistent,
	change to "normal exit"
	* init/tests/test_cfgfile.c (test_stanza_normalexit): Update.

	* init/cfgfile.c (cfg_stanza_start, cfg_stanza_stop) 
	(cfg_stanza_pre_start, cfg_stanza_post_start) 
	(cfg_stanza_pre_stop, cfg_stanza_post_stop, cfg_stanza_respawn):
	We're not going to allow stanza keywords to be quoted, since this
	gives us an easy way to allow users to make something explicitly
	not a keyword.

2007-02-10  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Bump version to 0.3.6

	* configure.ac: Increase version to 0.3.5
	* NEWS: Update.
	* TODO: Update.

	* TODO: More notes.

	* TODO: Note an issue with using JobProcess->pid

	* init/cfgfile.c (cfg_stanza_pre_start, cfg_stanza_post_start) 
	(cfg_stanza_pre_stop, cfg_stanza_post_stop): Add a needed check
	for a token when parsing "exec".  Correct line number we expect
	to see the duplicated value on.  Correct expected error for missing
	argument from "Unexpected token" to "Expected token".

	* init/tests/test_cfgfile.c (main): Actually invoke the tests for
	the scripts.

	* init/cfgfile.c (cfg_read_job): Correct type of lineno in error.

	* TOOD: Minor notify bug

	* TODO: Big update.

	* init/tests/test_job.c (test_child_reaper): Make sure that we can
	reap post-start and pre-stop processes, and have only the aux_pid
	changed.  Also make sure that if the running process dies while
	in these states, with or without an aux process, that we don't
	transition badly.

	* init/job.c (job_find_by_pid): Check aux_pid as well.
	* init/tests/test_job.c (test_find_by_pid): Make sure we can find it.

	* init/job.h (Job): Add an auxiliary pid member.
	* init/job.c (job_new): Initialise the aux_pid member.
	(job_change_state): Run the post-start and pre-stop scripts when we
	enter the state with the same name (assuming they exist).
	(job_run_process): Store the pid in aux_pid when starting the
	post-start or pre-stop processes.
	* init/tests/test_job.c (test_change_state): Add tests for running
	the new post-start and pre-stop scripts; which get their process ids
	stored in aux_pid instead of pid.
	(test_new): Make sure the aux_pid member is initialised properly.
	(test_copy): Make sure the aux_pid member is not copied.

	* TODO: Update.

	* init/tests/test_job.c (test_change_state): Add a check for the
	daemon stanza holding the job in spawned; we snuck this in a while
	back and never tested it (there's no support to get it out of
	spawned yet).

	* init/job.h (Job): Add new post_start and pre_stop scripts.
	* init/job.c (job_new): Initialise new scripts to NULL.
	(job_copy): Copy the information from the new scripts over as well.
	* init/tests/test_job.c (test_new): Check they're initialised.
	(test_copy): Check that the information is copied properly.
	* init/cfgfile.c (cfg_stanza_post_start, cfg_stanza_pre_stop): Add
	new script stanza functions for the additional two scripts that
	we want.
	* init/tests/test_cfgfile.c (test_stanza_post_start) 
	(test_stanza_pre_stop): Add tests for the new stanzas.

	* init/cfgfile.c (cfg_stanza_exec, cfg_stanza_script): Rewrite to
	allocate a JobProcess and parse the command or script into it.
	(cfg_read_job): Fix the long broken assumption that pid_file and
	pid_binary are required for respawn, when they're actually required
	for daemon.
	(cfg_stanza_start, cfg_stanza_stop): Remove script second-level.
	(cfg_stanza_respawn): Parse into the job's process.
	(cfg_stanza_pre_start, cfg_stanza_post_stop): New stanzas for the
	processes alone.
	* init/tests/test_cfgfile.c (test_read_job): Update a few test
	cases to match reality.
	(test_stanza_start, test_stanza_stop): Remove script-related checks.

2007-02-09  Scott James Remnant  <scott@netsplit.com>

	* init/tests/test_job.c (test_kill_process): Poll the event queue
	after each test to get rid of the allocated events and make valgrind
	happy.
	* init/tests/test_control.c (test_job_start, test_job_stop)
	(test_event_emit): Poll the event queue after each test to get rid
	of the allocated events, as they make valgrind complain.
	(test_event_emit): Free args and env when done.

	* init/job.h (JobName): Drop obsolete structure
	(JobProcess): Add a new structure to represent a single process
	within the job, instead of using two variables to pick either the
	script or command.
	(Job): Change command and script to a single JobProcess called process;
	change start_script and stop_script to a JobProcess called pre_start
	and post_stop respectively.
	* init/job.c (job_new): Initialise new members to NULL.
	(job_copy): Copy the process structures across, including contents.
	(job_change_state): Call job_run_process passing in the structure;
	rather than fiddling with if statements.
	(job_run_script, job_run_command, job_run_process): Combine all of
	these three functions into a single new job_run_process function.
	* init/tests/test_job.c (test_new, test_copy, test_change_goal) 
	(test_change_state, test_child_reaper) 
	(test_handle_event_finished): Change to using JobProcess for when
	we need to construct a command.
	(test_run_script, test_run_command): Merge into single new
	(test_run_process) function.
	* init/tests/test_event.c (test_poll): Replace command with process.
	* init/tests/test_control.c (test_job_start): Change to using
	JobProcess to specify the command.

	* init/main.c (main): Run job_free_deleted each time through the
	main loop.

	* init/job.c (job_change_goal): Minor tweak to the logic; we may
	have just made the job an instance, that should still let us stop
	the one underneath.

	* TODO: Update.

	* util/jobs.c (do_job): Always expect a list of replies.

	* init/control.c (control_job_status, control_job_stop)
	(control_job_query): Reply with information about all instances of
	the job.
	* init/tests/test_control.c (test_job_status, test_job_stop)
	(test_job_query): Make sure we get the list end even for a single job;
	and make sure we get details of all instances attached to the job.

	* init/tests/test_job.c (test_change_goal): Check that starting
	an instance job actually starts a new instance of it.

	* init/cfgfile.c (cfg_stanza_limit): Support the word "unlimited" in
	limit arguments for both the soft and hard values.
	* init/tests/test_cfgfile.c (test_stanza_limit): Make sure that we
	can make limits be unlimited.

	* init/event.c (event_copy): Function to copy an event structure.
	* init/event.h: Add prototype.
	* init/tests/test_event.c (test_copy): Make sure we copy the event
	correctly, with or without arguments and/or environment.
	* init/job.c (job_copy): Function to copy a job structure, leaving
	the state as it is.
	* init/job.h: Add prototype.
	* init/tests/test_job.c (test_copy): Make sure that we copy the
	job details whether they are NULL or non-NULL, but don't copy the
	state.
	* init/init.supp: Update supression.
	* init/job.c (job_find_by_name): If we get a job that's an instance,
	return what it's an instance of.
	* init/tests/test_job.c (test_find_by_name): Restore accidentally
	deleted test function; test that we get the real job, not an instance.

	* init/job.c (job_new): instance_of is initialised to NULL.
	* init/job.h: Add a new instance_of pointer, pointing to the parent
	that we're an instance of.
	* init/tests/test_job.c (test_new): Check that.
	* init/tests/test_cfgfile.c (test_read_job): Make sure instance_of
	pointers are updated.

	* init/job.c (jobs): Store jobs in a hash table.
	(job_new): Add to hash table, not to a list.
	(job_handle_event, job_handle_event_finished, job_detect_stalled) 
	(job_free_deleted): Iterate across the hash table, rather than list.
	(job_find_by_name): Use nih_hash_lookup, we keep this function because
	we'll add "is instance or not" smarts soon!
	(job_find_by_pid): Iterate across the entire hash table.
	* init/tests/test_job.c (test_find_by_name): Drop test since this
	function is now gone.
	(test_free_deleted): Can't assume things are in a line now.
	* init/control.c (control_job_list): Iterate the hash table.

	* init/event.c: Don't hide the events list anymore
	* init/event.h: Publish it and the init function.
	* init/job.c: Don't hide the jobs list anymore.
	(job_list): Since we don't hide it, we can drop this.
	* init/job.h: Publish it and the init function.
	* init/notify.c: Don't hide the subscriptions list anymore.
	* init/notify.h: Publish it and the init function.
	* init/control.c (control_job_list): Iterate the job list directly
	* init/tests/test_control.c (test_event_emit): Use the events list
	available to us.
	* init/tests/test_event.c (test_poll): Call job_init directly and
	just use the events list available to us.
	* init/tests/test_job.c (test_new): Call job_init directly.
	(test_change_state): Use the events list available to us.
	* init/tests/test_notify.c (test_unsubscribe): Use the subscriptions
	list available to us.

	* doc/states.dot: Add updated state graph.
	* doc/Makefile.am (EXTRA_DIST): Ship the states diagram.
	(states.png): Include rules to build the png, we'll put it in bzr
	anyway, but this is useful.

	* init/cfgfile.c (cfg_delete_handler): Handle deleted jobs; mark
	the job as deleted, and if it's dormant, invoke a state change.

	* upstart/enum.h: Add a new JOB_DELETED state.
	* upstart/enum.c (job_state_name, job_state_from_name): Add the new
	state to the string functions.
	* upstart/tests/test_enum.c (test_state_name) 
	(test_state_from_name): Check the enum works.
	* init/job.c (job_change_goal): New decision; we can start a waiting
	job if it's marked delete (it might be a new instance) -- we'll use
	the new deleted state to decide that we shouldn't.
	(job_change_state): Once we reach waiting, if the job is to be deleted,
	move to the next state.
	(job_next_state): The next state for a waiting job if the goal is stop
	is deleted.  We should never call job_next_state () for a deleted job.
	(job_free_deleted): Very simple function, just detects
	deleted jobs and frees them.
	* init/job.h: Add prototype for new function.
	* init/tests/test_job.c (test_change_goal): Update test to use new
	deleted state; and don't even change the goal.
	(test_change_state): Add a check to make sure we end up in deleted.
	(test_next_state): Make sure waiting goes to deleted.
	(test_free_deleted): Check the function.

	* init/job.c (job_change_goal): Don't try and start a job if it's
	marked to be deleted and is just waiting for cleanup.
	* init/tests/test_job.c (test_change_state): Make sure that the cause
	is released when we reach waiting.

	* init/tests/test_cfgfile.c (test_read_job): Make sure that a deleted
	job gets resurrected.

	* init/cfgfile.c (cfg_visitor): Correct number of arguments and call
	to cfg_job_name.

	* TODO: Update.

	* init/cfgfile.c (cfg_stanza_daemon): Don't allow arguments anymore.
	* init/tests/test_cfgfile.c (test_stanza_daemon): Update tests.

	* init/job.c (job_handle_event_finished): Function to unblock all
	jobs blocked on a given event emission.
	(job_new, job_emit_event): Rename blocker to blocked; it's useful for
	testing for truth.
	* init/job.h: Add prototype, rename member.
	* init/tests/test_job.c (test_handle_event_finished): Test it.
	(test_new, test_change_state): Update name here too.
	* init/event.c (event_finished): Call job_handle_event_finished
	function to unblock jobs.
	* init/tests/test_event.c (test_poll): Make sure the job gets
	unblocked; a few other tests have to change since running event_poll
	always unblocks the job if nothing listens to it.

	* init/job.c (job_child_reaper): Set failed back to FALSE if
	we're respawning, since we don't want to be failing.
	* init/tests/test_job.c (test_child_reaper): cause will be NULL.
	also free and poll events when done.
	(test_handle_event): pid can never be -1
	(test_change_state): poll events when done

	* init/tests/test_job.c (test_child_reaper): Process will always
	be zero on return from reaper.

	* init/tests/test_job.c (test_child_reaper): Killed doesn't go past
	stopping; it goes to waiting, which will clear the cause.

	* init/tests/test_job.c (test_child_reaper): Fill in values before
	we test against them.

	* init/tests/test_job.c (test_kill_process): Fix violated assertion

	* init/tests/test_job.c (test_change_state): This should be failed
	because nothing cleared it.

	* init/tests/test_job.c (test_change_state): Fix a couple of array
	index problems.

	* init/tests/test_job.c (test_change_state): Why set that which
	does not change?

	* init/tests/test_job.c (test_change_state): Add newline to test.

	* init/job.c (job_emit_event): Add the job name as an argument;
	oops.

	* init/tests/test_control.c (test_job_stop): Need to kill the process
	ourselves, as we're blocked on an event.
	(test_job_query): Fix wrong value in test.
	(check_job_stopped, test_job_stop, test_unwatch_jobs): Change job
	name to match the test.

	* init/job.c (job_change_state): Must only not enter some states
	with no process now; others like killed actually usually want one!

	* init/tests/test_cfgfile.c (test_read_job): Fix test case.

	* init/tests/test_job.c (test_handle_event): Clean up tests.
	(test_detect_stalled): Clean up.

	* init/job.c (job_child_reaper): Update the reaping of the child
	processes; there's a much larger state range for the main process
	now, so that needs to be taken into account.
	* init/tests/test_job.c (test_child_reaper): New test cases.

	* init/job.c (job_next_state): Encapsulate the slightly odd three
	exit states of running in this function, otherwise we'll end up
	special-casing it in places I'd rather not think about.
	(job_change_goal): Only change the state of a running job if it
	has a process.
	* init/tests/test_job.c (test_next_state): Add a test case for the
	dead running job
	(test_change_goal): Add test case for the dead running job

	* init/tests/test_job.c (test_change_state): Add test cases for
	the forgotten stopping to killed transition.

	* init/job.c (job_kill_process, job_kill_timer): Just check the pid
	and state, and no longer any need to notify jobs since we're just
	called from one state amongst many.
	(job_change_state): Skip over the killed state if there's no process.
	* init/tests/test_job.c (test_kill_process): Update test cases.

	* init/job.c (job_run_process): Simplify a little bit, no need to
	do the state assertions here, just make sure there's no already
	a process running.
	* init/tests/test_job.c (test_run_command, test_run_script): Run
	tests in the spawned state, since that's where we run the primary
	command or script.  Drop check for process state since that's no
	longer set.

	* init/job.c (job_change_state, job_next_state): Ok, here's the big
	one ... rewrite this to use the new state transitions.  This has
	suddenly got a lot simpler and easier to read, this was definitely a
	good idea.
	(job_emit_event): Function to make emission of events easier.
	(job_failed_event): replaces this one which wasn't so easy.
	* init/tests/test_job.c (test_change_state): I can't say how much I
	wasn't looking forwards to rewriting these test cases; anyway, it's
	done now and I hope they're all right;
	(test_next_state): Make sure the state transitions are correct too.

	* init/job.h: Rename is_instance to delete and spawns_instance to
	just instance.
	* init/job.c (job_new): Update.
	* init/tests/test_job.c (test_new): Update.
	* init/cfgfile.c (cfg_stanza_instance): Update.
	* init/tests/test_cfgfile.c (test_stanza_instance): Update.

	* init/event.h: Correct the event names.

	* init/job.h: Add blocker event member.
	* init/job.c (job_new): Initialise it to NULL.
	* init/tests/test_job.c (test_new): Check it.

	* init/job.c (job_change_goal): Have a stab at this function with the
	new state machine; it gets somewhat simpler (until we introduce the
	second scripts), now we just induce things by a state change.
	* init/tests/test_job.c (test_change_goal): Made easier (for now)
	because we don't need to deal with processes and can just wait to
	be blocked on an event.

2007-02-08  Scott James Remnant  <scott@netsplit.com>

	* init/cfgfile.c (cfg_read_job): Drop check for useless respawn script
	(cfg_stanza_respawn): Drop handling of "respawn script"
	* init/tests/test_cfgfile.c (test_stanza_respawn): Drop the checks
	for "respawn script"

	* init/job.h: Move things about a bit more; remove respawn_script
	since that state is going away.
	* init/job.c (job_new): Drop initialisation of process_state.
	* init/tests/test_job.c (test_new): Improve the tests.

	* init/main.c (STATE_FD): Remove this define, not used anymore.

	* init/tests/test_event.c (test_poll): Update the event checking
	to match what's likely to happen.

	* init/event.h: Remove commented out bit.

	* init/tests/test_notify.c (check_job_status, test_job): Correct
	state usage to match a possible state.

	* init/control.c (control_job_start, control_job_stop) 
	(control_job_query, control_job_list): Drop process state and
	description from the job status messages we send back.
	* init/tests/test_control.c (test_error_handler) 
	(check_job_started, test_job_start, check_job_stopped) 
	(check_job_stopping, test_job_query, check_job_starting) 
	(test_job_list, test_watch_jobs, test_unwatch_jobs): Remove
	process_state and description, and update usage of job states.

	* init/notify.c (notify_job): Don't include process state or
	description in the job status message anymore.
	* init/tests/test_notify.c (check_job_status, test_job): Update tests

	* init/cfgfile.c (cfg_read_job): Drop the copying of the process_state
	member, since it doesn't exist anymore.
	* init/tests/test_cfgfile.c (test_read_job): Drop the check too.

	* init/job.h (Job): Drop the process_state member.

	* util/jobs.c (handle_job_status): Drop the process_state and
	description arguments; output a process id only if it's greater
	than zero.
	* util/tests/test_jobs.c (test_start_action, test_list_action) 
	(test_jobs_action): Update tests to use newer states and arguments.
	* util/events.c (handle_event_job_status): Simplify in the same way

	* upstart/message.h: Remove process_state and description from the
	job status event (we already had the foresight to not put them in
	the event job status event).
	* upstart/message.c (upstart_message_new, upstart_message_handle):
	Update handling of the messages to reduce the arguments.
	* upstart/tests/test_message.c (test_new, my_handler) 
	(test_handle): Update the tests for the new job status message.

	* upstart/enum.h (JobState): Change the job states to the new set
	of states that we've planned.
	(ProcessState): Drop process state entirely; this information is now
	contained in the single JobState field.
	* upstart/enum.c (job_state_name, job_state_from_name): Update
	strings to match the new state names.
	(process_state_name, process_state_from_name): Drop these functions.
	* upstart/tests/test_enum.c (test_state_name) 
	(test_state_from_name): Update test cases to match new names.
	(test_process_state_name, test_process_state_from_name): Drop.

	* init/main.c (main): Remove the logd hack for now.
	* init/job.c (job_new): Change the default console to none for now.
	* init/tests/test_job.c (test_new): Update test.
	* init/cfgfile.c (cfg_stanza_console): Can't guard against duplicates
	for a while.
	* init/tests/test_cfgfile.c (test_stanza_console): Comment out dup test

	* init/cfgfile.c (cfg_read_job): Remove the restriction that there
	must be either an 'exec' or 'script' for a job; jobs without either
	define states others can use.
	* init/tests/test_cfgfile.c (test_read_job): Convert the test to
	a "must work".
	* init/job.c (job_change_state): Remove restriction that we must
	have either a script or a command; having neither should just wedge
	the job at the running rest state.  Note that there's no way to get
	it out yet, because we don't force that particular state change.
	* init/tests/test_job.c (test_change_state): Make sure that works.

	* init/job.c (job_change_cause): Put the knowledge about how to
	change the cause into a separate function, since it's slightly
	tricky.
	(job_change_goal, job_change_state): Set the cause using the above
	function.

	* init/job.h (Job): Rename goal_event to cause, also shuffle things
	around so that the state is mostly together.
	* init/job.c, init/process.c, init/notify.c, init/cfgfile.c: Update
	references (and comments) to match the new name.
	* init/tests/test_job.c, init/tests/test_event.c,
	init/tests/test_process.c, init/tests/test_cfgfile.c,
	init/tests/test_notify.c: Likewise.

	* init/job.c (job_child_reaper): Don't change the goal event; the
	state changes will handle this.
	(job_change_goal): Only dereference/reference the goal event if we're
	actually changing it.
	* init/tests/test_job.c (test_change_state, test_child_reaper):
	Update tests to not assume that the goal event gets changed.
	(test_kill_process): Eliminate race condition.

	* init/job.c (job_child_reaper): Correct some problems with job and
	event failure; we now don't overwrite an existing failure record,
	and don't record failure if the main process failed and the goal was
	stop; since we likely caused it.
	* init/tests/test_job.c (test_child_reaper): More test cases.

	* logd/event.d/logd.in: Stop on the new runlevel events, not the
	shutdown event.

	* compat/sysv/shutdown.c (shutdown_now): Emit an ordinary runlevel
	change event now; including the INIT_HALT environment variable
	* compat/sysv/man/shutdown.8: Update the manual

	* compat/sysv/telinit.c: Now just sends out a runlevel event with
	an argument giving the new runlevel.
	* compat/sysv/man/telinit.8: Update description of the command.

	* upstart/message.h: Remove the UPSTART_SHUTDOWN message.
	* upstart/message.c (upstart_message_new, upstart_message_handle):
	Remove handling for the shutdown message.
	* upstart/tests/test_message.c (test_new, test_handle): Remove
	tests against the shutdown message.
	* init/control.c (control_shutdown): Remove the shutdown command
	from the server.
	* init/tests/test_control.c (test_shutdown): Remove tests for it.
	* init/event.h: Remove the shutdown event.
	* util/initctl.c: Remove the shutdown command reference.
	* util/events.c (shutdown_action): Remove the command.
	* util/events.h: Update.
	* util/tests/test_events.c (test_shutdown_action): Remove tests.

	* init/job.c (job_detect_idle): Rename to job_detect_stalled
	(job_detect_stalled): Remove the idle state detection
	(job_set_idle_event): Idle event has been removed.
	* init/job.h: Update.
	* init/tests/test_job.c (test_detect_idle): Rename to
	(test_detect_stalled): and remove idle detection tests.
	* init/main.c (main): Replace job_detect_idle with job_detect_stalled
	* init/control.c (control_shutdown): Don't set the idle event.
	* init/tests/test_control.c (test_shutdown): Don't detect the idle
	event (and thus the second event)

	* init/cfgfile.c (cfg_stanza_service): Parser for service stanza.
	* init/tests/test_cfgfile.c (test_stanza_service): Test the service
	stanza.
	(test_stanza_respawn): Check that respawn implies service.
	* TODO: Update.

	* init/job.h (Job): Add a new service member.
	* init/job.c (job_new): Service starts off as false.
	(job_change_state): Check service instead of respawn.
	* init/tests/test_job.c (test_change_state): Check with service
	instead of respawn, since that's what we really mean.

	* init/cfgfile.c (cfg_read_job): Copy a whole bunch more state
	into the newly parsed job.
	* init/job.c (job_run_process): Only output the first error.
	* init/tests/test_cfgfile.c (test_read_job): Make sure important
	things are copied.
	* TODO: Update.

	* init/main.c: Restore a much simplified version of the term
	handler that doesn't try and copy across any state.

	* compat/sysv/telinit.c: Update call to event_emit; we'll revisit
	this shortly when we get rid of the shutdown event.

	* util/events.c (handle_event): Add new id field (but ignore it)
	Functio
	(handle_event_job_status): New function to handle the new event.
	(handle_event_finished): Function to handle the end of the event.
	(emit_action): Send the newer event, and loop over replies until
	we get a finished one.
	* util/tests/test_events.c (test_emit_action): Update tests cases.

	* init/control.c (control_event_emit): New function to handle the
	new-style emit message.
	* init/tests/test_control.c (test_event_emit): Make sure the new
	message function behaves.

	* init/event.c, init/job.c, init/main.c, init/tests/test_event.c,
	init/tests/test_job.c: Completely drop the serialisation code, it's
	getting out of date and in the way.

	* init/event.h: Remove compatibility macros.
	(EventEmission): Drop the callback function; it was too error prone
	to try and do it this way, and we only ever wanted to release a job
	anyway as control requests are better handled through the notify
	interface.
	(EventEmissionCb): Drop unused typedef.
	* init/event.c (event_emit): Drop callback argument.
	(event_finished): Don't call the callback
	* init/tests/test_event.c: Update to avoid callbacks.
	* init/job.c (job_change_state): Convert to using event_emit and
	EventEmission.
	(job_detect_idle): Drop extra arguments to event_emit.
	* init/main.c (main, cad_handler, kbd_handler): Drop extra arguments
	to event_emit.
	* init/control.c (control_shutdown): Use event_emit instead of
	event_queue.
	* init/tests/test_control.c (test_shutdown): Convert to using
	EventEmission.
	(test_watch_events, test_unwatch_events): Drop extra arguments to
	event_emit.
	* init/tests/test_notify.c (test_subscribe_event, test_job) 
	(test_event, test_event_finished): Drop extra arguments to event_emit
	* init/tests/test_job.c (test_change_goal, test_change_state) 
	(test_run_script, test_child_reaper, test_detect_idle): Drop
	extra arguments to event_emit.
	* init/tests/test_process.c (test_spawn): Drop extra arguments to
	event_emit.

	* TODO: Update.

	Rewrite the notification subsystem quite significantly; now we
	have individual functions to subscribe to different types of
	notification, and can even subscribe to individual jobs or events.

	* init/notify.c (notify_subscribe_job, notify_subscribe_event) 
	(notify_unsubscribe): New subscription and unsubscription functions
	that assume one record per subscription, not process.
	(notify_subscription_find): Function to find a subscription.
	(notify_job): Send a message to anything subscribed to the goal event
	as well.
	(notify_event): Use EventEmission and include the id in the event.
	(notify_event_finished): New function, sends a finished message and
	includes both the id and whether the event failed.
	* init/notify.h (NotifySubscribe): New notify structure that is
	once per subscription, rather than per-process; and allows
	subscription to individual jobs or events.
	* init/tests/test_notify.c (test_subscribe_job) 
	(test_subscribe_event, test_unsubscribe): Test the new subscription
	functions, replacing the old
	(test_subscribe): tests.
	(test_subscription_find): Check finding works
	(check_event, test_event): Update to use emissions, and check that the
	id is correct.
	(test_event_finished): Check this one works too
	(check_event_job_status, test_job): Make sure processes subscribed
	via the goal event are notified too.
	* init/event.c (event_pending): Pass the emission directly.
	(event_finished): Notify subscribers that the event has finished.
	* init/control.c (control_error_handler): Call notify_unsubscribe
	(control_watch_jobs, control_unwatch_jobs, control_watch_events) 
	(control_unwatch_events): Update to the new subscription API.
	* init/tests/test_control.c (test_error_handler): Use new API
	(test_watch_jobs, test_unwatch_jobs, test_watch_events)
	(test_unwatch_events): Also update these to the new API; use a
	destructor to make sure the subscription is freed.

	* init/tests/test_process.c: Don't use printf, use TEST_FUNCTION

2007-02-07  Scott James Remnant  <scott@netsplit.com>

	* upstart/message.h: Allocate new grouped event messages.
	* upstart/message.c (upstart_message_new, upstart_message_handle):
	Add support for the new grouped event messages.
	* upstart/tests/test_message.c (test_new, test_handle) 
	(my_handler): Make sure the new messages are passed correctly.

	* init/job.c (job_change_state): Clear the goal event whenever we
	reach the final rest state of a job (waiting for all jobs, running
	for services).
	* init/tests/test_job.c (test_change_state): Check that the goal
	event goes away at the right times.
	* TODO: Update.

	* init/tests/test_job.c (test_child_reaper): Make sure that the
	event is marked failed properly

	* init/job.c (job_start_event, job_stop_event): There's no reason
	for these to exist as seperate functions anymore, especially since
	we want to eventually have some kind of match table.
	(job_handle_event): Perform the iterations and match calls here
	instead, since we just call job_change_goal now.
	* init/job.h: Remove prototypes.
	* init/tests/test_job.c (test_start_event, test_stop_event): Fold into
	(test_handle_event): which now handles all the cases.

	* init/job.c (job_detect_idle): Call event_emit
	* init/main.c (main, cad_handler, kbd_handler): Call event_emit
	instead of event_queue.
	* init/tests/test_event.c (test_new): Call event_poll
	* init/tests/test_job.c (test_change_state, test_child_reaper) 
	(test_detect_idle, test_change_state): Update to use newer event API.
	* TODO: Update.

	* init/job.c (job_start, job_stop): Drop these functions; call
	job_change_goal instead (which is now public).
	(job_change_state, job_child_reaper): Call job_change_goal instead.
	* init/job.h: Update.
	* init/tests/test_job.c (test_start, test_stop): Merge into new
	(test_change_goal): function.
	* init/main.c (main): Call job_change_goal instead of job_start.
	* init/control.c (control_job_start, control_job_stop): Call
	job_change_goal instead.

	* init/tests/test_job.c (test_new, test_change_state) 
	(test_run_script, test_start, test_stop, test_start_event): 

	* init/job.h (Job): goal_event is now an EventEmission, and is
	a direct pointer to the one in the events queue, rather than a copy.
	* init/process.c (process_setup_environment): Reference the event
	name and environment through the goal event, not directly.
	* init/job.c (job_run_script): Reference the event name and
	environment through the goal event, not directly.
	(job_change_state, job_child_reaper): Replace direct setting of the
	job goal with a call to job_stop; the process state is always
	PROCESS_NONE in all three cases, so this is completely safe.
	(_job_start, _job_stop): Merge these two functions together into
	(job_change_goal): which behaves a lot more like job_change_state,
	except that it doesn't loop.  This handles the changing of the
	emission.
	(job_start, job_start_event, job_stop, job_stop_event): Simplify
	these functions, now they just call job_change_goal passing in
	the emission pointer (or NULL).

	* init/main.c, init/job.c, init/job.h, init/event.c, init/event.h,
	init/tests/test_job.c, init/tests/test_event.c: Remove state
	serialisation code for the time being; maintaining it is getting
	increasingly harder, and it introduces some major bugs.  It will
	get rewritten shortly.

	* init/event.c (event_pending): Pass the emission directly to
	job_handle_event now.
	* init/job.c (job_handle_event, job_start_event, job_stop_event):
	Deal with event emissions rather than just plain events, the change
	so far doesn't do anything else other than take the structure change.
	* init/job.h: Change prototypes.
	* init/tests/test_job.c (test_start_event, test_stop_event)
	(test_handle_event): Update tests to use emissions.

	* init/tests/test_event.c (test_read_state, test_write_state): Check
	the passing of the progress information.
	* init/event.c (event_read_state, event_write_state): Add progress
	field to the serialisation (oops).

	* init/event.h: Add missing attribute for event_read_state.
	* init/cfgfile.h: Add missing attributes.
	* init/main.c (read_state): Don't discard return value.
	* TODO: Update.

	* init/main.c (read_state): Handle the Emission keyword; also handle
	Event really being an EventEmission.
	* init/event.c (event_emit): Make the next emission id a static global
	(event_read_state, event_write_state): Serialise event emission
	structures, not plain events; also send over the last id we used so
	it appears seamless.  This doesn't yet handle the callback/data bit
	of the serialisation, which turns out to be a little tricky ... oops
	* init/event.h: Update.
	* init/tests/test_event.c (test_read_state, test_write_state): Check
	that serialisation is done with EventEmissions instead, and all the
	fields are passed (except callback and data which are ... tricky).

	* init/main.c (main): Call event_poll instead of event_queue_run.

	* init/event.c (event_poll): Add the new function that replaces
	event_queue_run(); handles the new-style event emission structures
	in the list and only returns when there are no non-handling events.
	(event_pending, event_finished): Handling of particular event states
	during poll; split out for readability.
	(event_queue, event_queue_run): Drop these obsolete functions.
	(event_read_state): Force type from event_queue.
	* init/event.h: Add event_poll prototype; remove prototypes of old
	functions, replacing with #defines for now so things still compile.
	* init/tests/test_event.c (test_queue): Drop tests.
	(test_read_state, test_write_state): Force type from event_queue
	Change type we check size of.
	(test_poll): Pretty thoroughly test the new poll function.
	* init/job.c (job_change_state): Force type from event_queue
	* init/control.c (control_event_queue): Force type from event queue
	* init/tests/test_job.c (test_detect_idle): Force type from event_queue
	* init/tests/test_control.c (test_event_queue, test_shutdown):
	Force type from event_queue

	* init/event.c: Revert to a single list of events with an enum
	(event_emit): Set the progress to pending initially.
	(event_emit_find_by_id): Simplify now it just checks one list
	(event_emit_finished): Function for jobs to call once they've done
	with an event; just sets the progress to finished for the event
	queue to pick up.
	* init/tests/test_event.c (test_emit_finished): Check it.

	* init/event.h: Add prototype.
	(EventProgress): Add new enum	
	(EventEmission): And add progress member to this structure
	* init/tests/test_event.c (test_emit): Make sure the event is pending

	* init/event.c (event_emit_find_by_id): Locate an event emission
	by its id in either the pending or handling queue.
	* init/event.h: Add prototype
	* init/tests/test_event.c (test_emit): Make sure that the emission
	id is unique each time.
	(test_emit_find_by_id): Test the function.

	* init/event.c (event_emit): New function to replace event_queue();
	returns an EventEmission structure with the details filled in as
	given.
	* init/event.h: Add prototype.

	* init/event.c (event_init): Rename the single events queue to
	pending and add a new handling list.

	* init/event.h (EventEmission, EventEmissionCb): Add a new emission
	structure that wraps an event, for use in the queue.

	* util/tests/test_events.c (test_events_action): Update test now
	that nih_message is more sensible.
	* util/tests/test_jobs.c (test_start_action, test_list_action) 
	(test_jobs_action): Update test

	* util/events.c (emit_action): Actually pass the emit_env array
	* util/tests/test_events.c (test_emit_action): Make sure it does.

	* util/initctl.c (main): Catch nih_command_parser() returning a
	negative value to indicate an internal error, and always exit 1.

	* util/events.c (handle_event): Build up multiple lines to describe
	the event, including its arguments and environment.
	* util/tests/test_events.c (test_events_action): Check the new output
	format is right.

	* init/main.c (main): Take out inadvertantly leaked debugging code;
	sorry about that.

	* init/job.c (job_child_reaper): Rewrite this to make the logic a
	little easier to follow, and support signals in normalexit.  This
	also now applies to deciding whether the job failed, if it did, we
	store that information in the job so the stop and stopped events
	can get it.
	* init/tests/test_job.c (test_child_reaper): Add new test cases for
	the setting of the failed flags.

	* init/cfgfile.c (cfg_stanza_normalexit): Allow signal names in the
	arguments, which are added to the normalexit array or'd with 0x80
	* init/tests/test_cfgfile.c (test_stanza_normalexit): Check that we
	can now parse signal names correctly.

	* init/job.c (job_failed_event): Change add to addp to fix leak.

	* init/job.c (job_failed_event): Function to turn an event into one
	that includes all the necessary arguments and environment.
	(job_change_state): Call job_failed_event for the stop and stopped
	events (bit hacky at the moment, will improve later).
	* init/tests/test_job.c (test_change_state): Check that the failed
	events are generated properly.

2007-02-06  Scott James Remnant  <scott@netsplit.com>

	* init/job.c (job_change_state): Reset the failed member when
	we enter the starting state.
	* init/tests/test_job.c (test_change_state): Make sure that the
	failed member is reset when we enter the starting state.

	* init/job.h (Job): Add failed, failed_state and exit_status members.
	* init/job.c (job_new): Initialise new members.

	* init/job.c (job_child_reaper): Convert signals to names when
	outputting status messages.
	* init/tests/test_job.c (test_child_reaper): Check that the signal
	name gets converted over.

	* init/event.h (CTRLALTDEL_EVENT): Now we've broken the shared
	namespace of events and jobs, rename the control-alt-delete event
	back to control-alt-delete.

	* init/job.c (job_change_state): Replace the events generated as
	part of the job state, named for the job and state, with new state
	events that have the job name as an argument.
	* init/event.h: Define new job event names.
	* init/tests/test_job.c (test_change_state): Make sure the new
	events are correct, with the job name as an argument.

	* init/job.c (job_change_state): Remove the job event; this has
	been repeatedly proved to be confusing.
	* init/tests/test_job.c (test_change_state): Remove checks for the
	job event.

	* util/events.c (emit_action): Pass in extra arguments.
	(env_option): Function to parse an option given an environment
	variable.
	* util/events.h: Add prototype.
	* util/tests/test_events.c (test_emit_action): Make sure that the
	emit action works with no arguments and with arguments.
	(test_events_action): Send back events with the right number of args.
	(test_env_option): Check the env option parser works.
	* util/initctl.c: Give shutdown its own command and options, give
	emit a new -e option.

	* util/events.c (shutdown_action): Split out from emit, seeing as
	these are going to be different from now on.
	* util/events.h: Add prototype.
	* util/tests/test_events.c (test_shutdown_action): Copy test cases.

	* init/control.c (control_event_queue): Take the arguments and
	environment from the event queue request; and reparent into the
	event.
	* init/tests/test_control.c (test_event_queue): Check that arguments
	and environment are copied across properly.

	* init/notify.c (notify_event): Pass in the arguments and environment
	for the event.
	* init/tests/test_notify.c (check_event): Check for event arguments
	and environment from the notify process.
	(test_event): Add arguments and environment to the event we test with

	* upstart/tests/test_message.c (test_new, test_handle): Send
	arguments and environment with the UPSTART_EVENT_QUEUE and
	UPSTART_EVENT messages.
	* upstart/wire.c (upstart_pop_int, upstart_pop_unsigned): Shrink
	only once.
	(upstart_pop_string): Check the length is at least one first, as
	we may just have an 'S'.

	* upstart/message.c (upstart_message_new, upstart_message_handle):
	The UPSTART_EVENT and UPSTART_EVENT_QUEUE messages gain new array
	arguments containing the arguments and environment for the event.
	* upstart/message.h: Document the new arguments.

	* util/tests/test_events.c, util/tests/test_jobs.c: Update the
	message format checks here too.

	* upstart/tests/test_wire.c (test_pop_pack): Free the array.

	* upstart/tests/test_message.c (test_new, test_handle)
	(test_handle_using, test_reader): Update tests to include and
	expect new type markers between each field.

	* upstart/wire.c (upstart_push_int, upstart_push_unsigned):
	Take out silly asserts; it must have room!

	* upstart/wire.c (upstart_push_string, upstart_pop_string): Rewrite
	to use a type like the rest of the functions; this removes the strange
	length restriction and allows us to make the pop function
	non-destructive.
	* upstart/tests/test_wire.c (test_push_string): Update.
	(test_pop_string): Update, adding in non-destructive, wrong type
	and insufficient space for type test cases.
	(test_push_array, test_pop_array): These needed updated too,
	changing the string format changed the array format.
	(test_push_pack, test_pop_pack): And obviously the pack format changed.

	* upstart/wire.c (upstart_pop_header): Make the function
	non-destructive in the face of errors.
	* upstart/tests/test_wire.c (test_pop_header): Make sure that
	invalid headers are non-destructive on error.

	* upstart/tests/test_wire.c (test_pop_int, test_pop_unsigned):
	Make sure that insufficient space is non-destructive.

	* upstart/wire.c (upstart_push_int, upstart_pop_int) 
	(upstart_push_unsigned, upstart_pop_unsigned): Convert to array-style
	type first format.
	(upstart_push_string, upstart_push_header): Write the length and
	type fields out by hand so they don't get an 'i' prefix.
	(upstart_pop_string, upstart_pop_header): Read the length and type
	fields by hand so they don't get an 'i' prefix.
	* upstart/tests/test_wire.c (test_push_int, test_pop_int) 
	(test_push_unsigned, test_pop_unsigned): Update test cases to match.
	(test_push_pack, test_pop_pack): Pack format was changed too.

	* upstart/wire.c (upstart_push_packv, upstart_pop_packv): Add calls
	to push and pop array.
	* upstart/tests/test_wire.c (test_push_pack, test_pop_pack): Test
	support for arrays.

	* upstart/wire.c (upstart_push_array, upstart_pop_array): Implement
	new array functions; note that these use a newer format that allows
	us to transmit NULL without needing to limit the size of the array.
	* upstart/wire.h: Add prototypes.
	* upstart/tests/test_wire.c (test_push_array, test_pop_array):
	Test the new array functions.

	* init/job.c (job_run_script): Build up the argument list, appending
	those from the goal event if one is set.
	(job_run_command): Use nih_str_array_add to build up the arguments,
	but don't append those from the goal event (use script).
	* init/tests/test_job.c (test_run_script): Make sure the arguments get
	passed to the running shell scripts.

	* init/job.c (job_run_script): Only use the /dev/fd trick if we can
	actually stat /dev/fd; also don't hardcode that path ...
	* init/paths.h (DEV_FD): Add here.

	* init/process.c (process_setup_environment): Copy environment
	variables from the goal event into the job's process.
	* init/tests/test_process.c (test_spawn): Make sure the environment
	reaches the job, but doesn't override that in the job already.

	* init/tests/test_job.c (test_start_event): 

	* init/job.c (job_start_event, job_stop_event): Copy the arguments
	and environment from the event into the goal event.

	* init/job.c (job_read_state, job_write_state): Read and write
	arguments and environment for goal event.
	* init/tests/test_job.c (test_read_state, test_write_state): Test
	with arguments and environment to the goal event.

	* init/event.c (event_read_state, event_write_state): Read and write
	the arguments and environment of the event.
	* init/tests/test_event.c (test_read_state, test_write_state): Make
	sure arguments and environment are correctly serialised.

	* init/cfgfile.c (cfg_stanza_console): Fix a leak of the console
	argument in the case of duplicated options.
	(cfg_stanza_env): Drop the counting now nih_str_array_addp does it;
	and be sure to use that function.
	(cfg_stanza_umask): Fix leak of umask argument
	(cfg_stanza_nice): Fix leak of nice argument
	* init/tests/test_event.c (test_new): Call event_queue_run so init
	is called outside of a TEST_ALLOC_FAIL block.

	* init/event.c (event_new): Start off with NULL args and env, to
	match job (saves a few bytes).
	(event_match): Watch for NULL arguments!
	* init/tests/test_event.c (test_new): Check for NULL not alloc'd

	* init/cfgfile.c (cfg_stanza_on, cfg_stanza_start) 
	(cfg_stanza_stop): Parse arguments to the on stanza and store them
	directly in the event.
	* init/tests/test_cfgfile.c (test_stanza_on, test_stanza_start) 
	(test_stanza_stop): Make sure arguments are parsed into the event.

	* init/event.c (event_new): Use nih_str_array_new.
	* init/cfgfile.c (cfg_stanza_env): Rewrite to use nih_str_array.

	* init/job.c (job_run_script): Check the error returned from
	nih_io_reopen; don't just loop.  We only ever expect ENOMEM (the
	other error, EBADF, is impossible).

	* init/job.c (job_change_state): Reset the goal_event to NULL when
	we catch a run-away job (as it's not stopping for the same event
	it started with).
	(job_child_reaper): Reset the goal_event to NULL after setting the
	goal to STOP.
	* init/tests/test_job.c (test_change_state, test_child_reaper):
	Check that the goal event gets reset whenever the goal gets changed.

	* init/tests/test_event.c: Use TEST_ALLOC_FAIL

	* init/event.c (event_match): Match arguments using fnmatch() and
	allow more arguments in event1 than event2 (but not the other way
	around).
	* init/tests/test_event.c (test_match): Check the new permitted
	combinations.

	* init/event.h (Event): Add args and env members to Event.
	* init/event.c (event_new): Initialise args and env members to
	zero-length arrays.
	* init/tests/test_event.c (test_new): Use TEST_ALLOC_FAIL and
	make sure args and env are both initialised to a list containing
	just NULL.

	* util/jobs.c (start_action): Get the UPSTART_JOB environment variable
	and use that if we don't have any arguments passed to us.
	(do_job): Code split from the above function that handles a named job
	* util/tests/test_jobs.c (test_start_action): Make sure UPSTART_JOB
	is picked up.

	* init/process.h: Add necessary attributes.

	* init/process.c (process_setup_environment): Set the UPSTART_JOB
	environment variable from the job, and the UPSTART_EVENT environment
	variable from the job's goal_event member (if set).
	* init/tests/test_process.c (test_spawn): Make sure we get the
	environment in the job.

	* init/job.h: Add attributes to job_new and job_read_state.
	* init/tests/test_job.c: Use CHECK_ALLOC_FAIL on the functions we
	didn't get around to touching while we were in here.

	* init/job.c (job_start_event, job_stop_event): Set the goal_event
	member to a copy of the event we found.
	(job_read_state): Use event_new instead of trying to do it by hand.
	* init/tests/test_job.c (test_start_event, test_stop_event): Use 
	CHECK_ALLOC_FAIL; and make sure the goal_event is set properly.
	(test_start, test_stop, test_write_new): Use event_new here too

	* init/job.c (job_write_state): Output a goal_event field containing
	the event name or nothing for NULL.
	(job_read_state): Parse the goal_event field
	* init/tests/test_job.c (test_write_state): Make sure the state is
	written out properly.
	(test_read_state): Make sure that the state is parsed correctly too.

	* init/job.c (job_start, job_stop): Split all of the code except
	the goal_event setting into two new static functions that this calls
	(_job_start, _job_stop): New static functions
	(job_start_event, job_stop_event): Call _job_start and _job_stop
	instead of job_start and job_stop

	* init/job.c (job_catch_runaway): Move this function up a bit.

	* init/job.c (job_start, job_stop): Clear the goal_event member,
	these functions are called for a manual start.
	* init/tests/test_job.c (test_start, test_stop): Make sure the
	goal_event member is freed and set to NULL.

	* init/job.h (Job): Add a new goal_event member
	* init/job.c (job_new): Initialise the goal_event member to NULL.
	* init/tests/test_job.c (test_new): Check with TEST_ALLOC_FAIL;
	also make sure goal_event is initialised to NULL.

2007-02-05  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Bump version to 0.3.3

	* NEWS: Update.

	* init/process.c (process_spawn): Exit with 255 so we don't clash
	with anything that uses 1 as a normal exit code.  Note why we only
	close 0..2 (everything else is FD_CLOEXEC).
	* init/cfgfile.c (cfg_watch_dir): Mark the inotify watch descriptor
	as FD_CLOEXEC.
	* init/control.c (control_open): nih_io_set_cloexec can only ever
	return EINVAL, so no point checking it.

2007-02-04  Scott James Remnant  <scott@netsplit.com>

	* init/tests/test_control.c: Remove strange old code.

2007-02-03  Scott James Remnant  <scott@netsplit.com>

	* init/control.c (control_open_sock, control_reopen)
	(control_close_handler): Drop these functions; unconnected datagram
	sockets don't close -- so why try dealing with it?
	(control_error_handler): Don't reopen the socket on error, just log
	it -- the socket should be fine, there's no remote end to be lost,
	after all.
	* init/tests/test_control.c (test_close_handler): Drop.
	(test_error_handler): Drop the reopen tests.

	* init/tests/test_job.c (test_run_script): Control socket doesn't
	get unexpectedly opened anymore; so no need to close it.

	* init/control.c (control_open): Remove the strange behaviour that
	this can be called to get the socket.  Instead make control_io
	global; we're all adults after all.
	* init/tests/test_control.c (test_open): Remove the test for the
	silly behaviour.
	* init/notify.c (notify_job, notify_event): Use the control_io
	pointer directly, and just do nothing if we lost it somehow.

	* init/main.c (main): Being unable tp open the control socket, or
	parse the configuration, should be a fatal error; stop being so
	damned liberal! <g>   Don't reset the signal state if we're
	being restarted, as this loses any pending signals -- be happy
	that our parent left them in a good state.  Set SIGCHLD to the
	standard handler, otherwise we might lose this before we start
	the main loop (which does the same anyway).
	(term_handler): Rework so we don't need to close and open the
	control socket; instead we just close it in the child that's
	going to send the state, and notify the parent that it's safe to
	exec (which will cause it to be closed so the new init can open it).

	* init/tests/test_control.c (test_open): Fix valgrind error
	* init/tests/test_notify.c (test_subscribe): Fix valgrind error

	* init/notify.c (notify_subscribe): Make safe against ENOMEM.
	* init/tests/test_notify.c (test_subscribe): Use TEST_ALLOC_FAIL

	* init/control.c: Add needed attributes; tidy up formatting.
	(control_open): Don't let ENOMEM fail opening the control socket.
	* init/control.h: Add needed attributes.
	* init/tests/test_control.c (test_open): Test for failed allocation.
	* init/main.c (term_handler): Make sure we catch failure to open
	the control socket again.

	* TODO: Update

	* init/cfgfile.c (cfg_watch_dir): Clean this up a bit; now we only
	output a warning if inotify failed for any reason other than not
	being supported AND walking worked.

	* init/cfgfile.c (cfg_watch_dir): Update to even newer watch API;
	our create_handler is now always called if inotify is successful,
	so we just need to fall back to walking the directory when it
	isn't -- if inotify isn't supported, don't even bother complaining.
	(cfg_create_modify_handler): Check the stat of the file visited to
	make sure it's a regular file.
	(cfg_visitor): Check the stat of the file visited to make sure it's
	a regular file.

	* init/cfgfile.c: Update include to upstart/enum.h
	* init/job.c: Update include to upstart/enum.h
	* init/job.h: Update include to upstart/enum.h

	* logd/main.c: Add attribute to open_logging

	* util/initctl.c: Split out the command functions into new files;
	* util/jobs.c: This gets the job-related commands
	* util/events.h: This gets the event-related commands
	* util/initctl.h, util/jobs.h, util/events.h: Headers
	* util/tests/test_jobs.c: Test suite for job-related commands.
	* util/tests/test_events.c: Test suite for event-related commands.
	* util/Makefile.am (initctl_SOURCES): Add new files.
	(TESTS): Build new test suites.
	(test_jobs_SOURCES, test_jobs_LDFLAGS, test_jobs_LDADD):
	Details for job-related commands test suite binary.
	(test_events_SOURCES, test_events_LDFLAGS, test_events_LDADD):
	Details for event-related commands test suite binary.
	* TODO: Remove item about splitting initctl now we've done it.

	* TODO: Big update; strip anything we have a spec for.

	* upstart/message.c (upstart_message_handle): Make sure that if we
	fail to parse a message, we don't leave strings around in memory.
	* upstart/tests/test_message.c (test_open): Check that we get a
	raised EADDRINUSE if we try an open a socket twice.
	(test_handle): Add lots of checks for things like NULL names and
	incomplete messages; as well as the obvious unknown message.
	(test_reader): Make sure that errors while handling messages are
	dealt with by logging it.

	* upstart/job.c, upstart/job.h, upstart/tests/test_job.c: Rename to
	enum.c, enum.h and tests/test_enum.c; since this just includes enums
	and convert functions really.
	* upstart/Makefile.am: Update.
	* upstart/libupstart.h: Update include.
	* upstart/tests/test_message.c: Update include.

2007-02-01  Scott James Remnant  <scott@netsplit.com>

	* logd/main.c (main): Ensure we error if daemonise fails.

	* compat/sysv/shutdown.c (main): Ensure that signals and timers
	are added, even if we run out of memory.

	* upstart/tests/test_message.c: Change from assert to assert0 
	* upstart/tests/test_wire.c: Change from assert to assert0
	* init/tests/test_notify.c: Change from assert to assert0
	* init/tests/test_control.c: nih_io_message_send should always return
	a value greater than zero.

	* upstart/tests/test_wire.c: Change to use assert instead of NIH_ZERO;
	the rationale here is that in test cases we just want to fail, not
	try again repeatedly.
	* upstart/tests/test_message.c: Likewise.

	* init/tests/test_control.c: Use assert to ensure we get the expected
	return values of functions that raise errors.
	* init/tests/test_notify.c: Use assert to ensure we get the expected
	return values of functions that raise errors.

	* init/cfgfile.c (cfg_watch_dir): Port to the new NihWatch API and
	use nih_dir_walk().  This also fixes the long-standing bug where we
	wouldn't watch the configuration directory if inotify was disabled.
	Drop both the parent and prefix members for now, until we clean this
	up later.
	(cfg_create_modify_handler): Wrap cfg_read_job after figuring out
	the job name.
	(cfg_job_name): Function to figure out the job name from a path.
	(cfg_visitor): Visitor function to handle initial parsing, figuring
	out the job name; otherwise identical to the standard handler.
	* init/cfgfile.h: Update prototype for cfg_watch_dir.
	* init/main.c (main): Update call to cfg_watch_dir.

2007-01-31  Scott James Remnant  <scott@netsplit.com>

	* upstart/tests/test_message.c: Use TEST_ALLOC_FAIL to make sure
	allocations are handled properly.

2007-01-30  Scott James Remnant  <scott@netsplit.com>

	* upstart/wire.c: Note that if any of the push functions fail, the
	entire buffer should be discarded.
	* upstart/tests/test_wire.c (test_push_int, test_push_unsigned) 
	(test_push_string, test_push_header, test_push_pack): Us
	TEST_ALLOC_FAIL to ensure that failing to allocate memory is caught.

	* upstart/tests/test_message.c (my_handler): Free the name and
	description after checking; they aren't otherwise.

	* upstart/wire.c (upstart_push_packv, upstart_pop_packv): Consume
	a copy of the va_list, so these can be called multiple times on the
	same list without ill effect.

	* upstart/message.h: Add warn_unused_result attributes to
	upstart_message_handle and upstart_message_handle_using as they raise
	errors.

	* upstart/wire.c: push functions return negative values to indicate
	insufficient memory.
	* upstart/wire.h: Add warn_unused_result attributes to push functions

	* upstart/tests/test_message.c: Guard calls to nih_io_buffer_push and
	nih_io_message_add_control with NIH_ZERO to ensure they succeed.
	* upstart/tests/test_wire.c: Guard calls to nih_io_buffer_push

	* HACKING: Update from libnih with new Documentation,
	Function Attributes and Test Cases sections.

2007-01-10  Scott James Remnant  <scott@netsplit.com>

	* init/main.c (crash_handler): s/SEGV/SIGSEGV/

	* init/main.c (main): Rename variable

	* TODO: Update.

	* init/main.c (main): Change the way we clear the arguments; by
	deleting just the final NULL terminator, we fool the kernel into
	only returning one argument in cmdline.

	* init/main.c (segv_handler): Rename to crash_handler and handle
	SIGABRT as well, so we can catch assertion errors.  Of course, in
	theory, with our high test converage this should never happen in
	practice <chortle>

2007-01-09  Scott James Remnant  <scott@netsplit.com>

	* init/main.c (main): Clear arguments so that upstart only ever
	appears as /sbin/init in ps, top, etc.

	* TODO: Update.

	* util/initctl.c: Add data pointer to functions and handle calls.

	* init/control.c: Add data pointer to all functions.
	* init/tests/test_control.c: Pass data pointer to
	upstart_message_handle_using()
	* init/tests/test_notify.c: Pass data pointer to
	upstart_message_handle_using()

	* upstart/message.c (upstart_message_handle) 
	(upstart_message_handle_using): Add a data pointer argument to these
	functions and pass it to the handler.
	(upstart_message_reader): Pass the io structure's data pointer.
	* upstart/message.h (UpstartMessageHandler): Add a data pointer to
	the message handler.
	* upstart/tests/test_message.c (test_handle, test_handle_using):
	Pass a data pointer to the function call and check it's passed
	to the handler correctly.
	(test_reader): Check that the io data pointer gets passed.

	* init/tests/test_cfgfile.c (test_stanza_console, test_stanza_env) 
	(test_stanza_umask, test_stanza_nice, test_stanza_limit): Finish off
	the newer style test cases.

	* init/cfgfile.c (cfg_stanza_console, cfg_stanza_umask)
	(cfg_stanza_nice, cfg_stanza_limit, cfg_stanza_chroot)
	(cfg_stanza_chdir): Guard against duplicate uses of the stanzas.
	* init/tests/test_cfgfile.c (test_stanza_daemon) 
	(test_stanza_respawn): Check that neither daemon or respawn override
	exec if they have no arguments.
	(test_stanza_script): Add missing function
	(test_stanza_chroot, test_stanza_chdir): Add tests for these simple
	stanzas.

	* init/cfgfile.c: Change remaining uses of nih_error_raise and
	return to just nih_return_error.

	* init/cfgfile.c (cfg_stanza_exec, cfg_stanza_daemon)
	(cfg_stanza_respawn, cfg_stanza_script): Disallow duplicates,
	both of command strings, scripts, limits and of just the flags.
	* init/tests/test_cfgfile.c (test_stanza_exec) 
	(test_stanza_daemon, test_stanza_respawn, test_stanza_instance):
	Check the behaviour of these stanzas.
	
	* init/cfgfile.c (cfg_stanza_start, cfg_stanza_stop): Disallow
	duplicate values for the script.
	* init/tests/test_cfgfile.c (test_stanza_start, test_stanza_stop):
	Test cases for those two functions.

	* init/cfgfile.c (cfg_stanza_description, cfg_stanza_author) 
	(cfg_stanza_version): Don't allow stanza to be duplicated anymore.
	* init/tests/test_cfgfile.c (test_stanza_description) 
	(test_stanza_author, test_stanza_version): Test cases for these
	simple stanza; making sure duplication is not permitted.
	(test_stanza_on): Add a test case for this stanza too.

	* init/cfgfile.c (cfg_stanza_kill): Guard against duplicate uses
	of the kill timeout stanza.
	* init/tests/test_cfgfile.c (test_stanza_kill): Test the complex
	kill stanza.
	(test_stanza_pid): Check duplicate usage results in an error.

	* init/job.h (Job): Rename pidfile to pid_file and binary to pid_binary
	* init/job.c (job_new): Update names here too.
	* init/errors.h: Add a new "duplicate value" error.
	* init/cfgfile.c (cfg_read_job): Change name of variables, and catch
	the duplicate value error to add the line number.
	(cfg_stanza_pid): Change variable names, and clean this function up
	a little.  Make it an error to use a stanza more than once.
	* init/tests/test_cfgfile.c (test_stanza_pid): Write a newer test
	case function for the pid stanza.

	* init/cfgfile.c (cfg_stanza_normalexit): Use do/while instead of
	while, that we don't have to test has_token first as next_arg does
	that for us.

	* init/cfgfile.c (cfg_stanza_normalexit): Change to peek at the next
	token to see whether it's missing or not, and then just fetch each
	next argument at a time.  This is more efficient than parsing them
	all in one go, and also means we can report the error in the right
	place!
	* init/tests/test_cfgfile.c (test_stanza_normalexit): Since we've
	changed the function that parses the stanza, add a proper test case
	function for it, covering all the behaviours.

	* init/job.c (job_new): Initialise the emits member to an empty list.
	* init/job.h (Job): Add the emits member as a list.
	* init/tests/test_job.c (test_new): Check the emits list starts off
	empty.
	* init/tests/test_cfgfile.c (test_stanza_emits): Test the new emits
	stanza; this function will also serve as a prototype for cleaning up
	the config tests.

	* init/cfgfile.c (cfg_stanza_emits): Add function to parse the new
	emits stanza.

	* init/cfgfile.c (cfg_stanza_depends): Remove the depends stanza
	from the configuration file.  Dependency support has never been used,
	and is to be replaced by a more flexible event/state configuration
	and blocking on the starting/stopping events.
	* init/tests/test_cfgfile.c: Remove references and tests for the
	depends stanza.
	* init/job.h: Remove the depends list from the job structure.
	* init/job.c (job_new): No depends list to initialise.
	(job_change_state): No dependencies to release
	(job_start): No dependencies to iterate; this removes a particularly
	hairy and complex interaction between state changes.  Remove the
	dependency event.
	(job_release_depends): Drop this function.
	* init/tests/test_job.c (test_start, test_stop): Massively simplify
	these tests cases now we don't have dependencies to worry about.
	(test_release_depends): Drop tests

2007-01-08  Scott James Remnant  <scott@netsplit.com>

	* init/cfgfile.c: Rewrite using the nih_config API, rather than one
	huge function we now just have seperate handler functions for each
	stanza.  We can also use more fine-grained parsing than slurping
	all args in and counting them.
	(cfg_read_job): Catch exceptions from the configuration parser and
	add the line number where the problem occurred to an output message.
	Parser errors are now fatal, and not ignored.
	* init/errors.h: Add a file containing errors raised within the init
	daemon codebase.
	* init/Makefile.am (init_SOURCES): Build with errors.h
	* init/tests/test_cfgfile.c: Update test cases now we don't expect
	a job to be returned if there's a parser error.

	* TODO: Update

2007-01-06  Scott James Remnant  <scott@netsplit.com>

	* logd/main.c (logging_reader): Fix inadvertent shadowing of the
	len parameter.

	* compat/sysv/telinit.c: Oops, nearly forgot to port this to send
	the messages in the new way.
	* compat/sysv/shutdown.c (shutdown_now): Likewise, port this too.

	* TODO: Update.

	* util/initctl.c (handle_job_status): Output the process argument,
	not the pid argument which contains the origin of the message.

	* upstart/message.c (upstart_message_handle): Raise a new unknown
	message error if we don't have a handler  and a new illegal message
	error if the source is illegal.
	* upstart/tests/test_message.c (test_handle): Adjust tests to check
	for the new errors that we raise.
	* upstart/errors.h: Define strings for new errors.

	* util/initctl.c: Yet another makeover for this little program,
	port it to the new message/control framework using handler functions
	and NihIoMessage.  This starts to make each action function look
	very similar, so there's method to this madness.

2007-01-05  Scott James Remnant  <scott@netsplit.com>

	* logd/main.c (main): Make sure that we add the SIGTERM handler.

	* init/tests/test_job.c (test_run_script): This test case relies
	on there only being one file descriptor watch, which won't be true
	if the control socket has been opened because there's a message to
	go out.  Make sure it's closed first.

	* init/init.supp: Update supressions file now that control_init
	has been renamed to notify_init

	* init/Makefile.am: Include notify.o from all tests.
	* init/job.c (job_change_state, job_kill_process, job_start) 
	(job_stop): Use the new notify_job function name.
	* init/event.c (event_queue_run): Use the new notify_event function
	name.

	* init/control.c (control_error_handler): Handle ECONNREFUSED now
	that the process id is available to us.
	* init/tests/test_control.c (test_error_handler): Make sure children
	going away is handled properly.

	* upstart/message.c (upstart_message_new): Store the process id in
	the int_data message field.
	* upstart/tests/test_message.c (test_new): Check the int_data field
	is filled in.

	* init/main.c (main): Guard against various things returning an error
	that we weren't catching.

	* init/tests/test_notify.c: Whitespace fix.

	* init/control.c (control_watch_jobs, control_unwatch_jobs) 
	(control_watch_events, control_unwatch_events): Restore functionality
	to subscribe and unsubscribe from job and event notifications.	
	* init/tests/test_control.c (test_watch_jobs, test_unwatch_jobs) 
	(test_watch_events, test_unwatch_events): Check that the subscription
	and unsubscription messages work.
	* init/Makefile.am (test_control_LDADD): Link to notify.o

	* init/control.c: Drop unused include of upstart/errors.h

	* init/notify.c: Move functions that handle subscription and
	notification from control.c.  Other than changing the names, we're
	keeping the API the same for now; expect it to change later when we
	add the ability to subscribe to individual jobs or events.
	(notify_init): initialise the subscriptions list; we don't have a
	separate send queue now that the control I/O is always asynchronous.
	* init/notify.h: Moved notification enum, structure and prototypes
	from control.h, changing the names so they match notify_* in the
	process.
	* init/Makefile.am (init_SOURCES): Build and link notify.c using
	notify.h
	(TESTS): Build the notify test suite binary.
	(test_notify_SOURCES, test_notify_LDFLAGS, test_notify_LDADD): Details
	for notify test suite binary.
	* init/tests/test_notify.c: Rewrite test cases in the manner of
	test_control.c so that we have one function for notify_job and
	one for notify_event, each of which contains the child process that
	receives the notification,

	* init/control.c (control_open): Allow this to be called to obtain
	the control socket, which means we can make it static.
	* init/tests/test_control.c (test_open): Check that it works.

	* init/control.c, init/control.h, init/tests/test_control.c: Move
	functions that handle subscription and notification to new notify.c
	(control_init): Drop completely, no need to maintain a send queue now
	(control_open): Change to return an NihIo that uses the default
	control watcher, and our error handler.  Split socket opening into
	(control_open_sock): which can be called from other functions.
	(control_close): Use nih_io_close() to close the socket and free the
	structure in one go.
	(control_reopen): Close the open control socket and open it again
	without destroying the NihIo structure, its queues or state.
	(control_close_handler): Handle the control socket going away
	(control_error_handler): Handle errors on the control socket,
	including the connection refused error that indicates a client went
	away.
	(control_handle): Split this into a miriad of small functions with
	a table to link them to the message type; this will make expanding
	each message handler much easier in future.
	* init/control.h: Update.
	* init/tests/test_control.c: Rewrite test cases to check the new
	handler functions; as a side-effect, this gets rid of the evil giant
	child/parent functions in favour of one test function per handler
	function.

	* upstart/message.c (upstart_message_handle_using): Wrapper function
	around upstart_message_handle that ensures all messages as passed to
	a single function.
	* upstart/message.h: Update.
	* upstart/tests/test_message.c (test_handle_using): Make sure it
	calls the single function.

2007-01-04  Scott James Remnant  <scott@netsplit.com>

	* upstart/message.c (upstart_message_reader): Handle any errors
	that occurred while handling the message.

2007-01-02  Scott James Remnant  <scott@netsplit.com>

	* upstart/message.c (upstart_message_handle): Check that the name
	argument is never NULL.
	(upstart_message_reader): Simple message reader function that can
	be associated with an I/O watch and handles each message received.
	* upstart/message.h: Add prototype.
	* upstart/tests/test_message.c (test_reader): Test the reader function.

	* upstart/control.c: Rename to upstart/message.c
	* upstart/control.h: Rename to upstart/message.h
	* upstart/tests/test_control.c: Rename to upstart/tests/test_message.c
	* upstart/libupstart.h: Update includes.
	* upstart/wire.c: Include message.h
	* upstart/wire.h: Update includes.
	* upstart/tests/test_wire.c: Update includes.
	* upstart/errors.h: Rename UPSTART_INVALID_MESSAGE to
	UPSTART_MESSAGE_INVALID so that it's prefixed.
	* upstart/Makefile.am (libupstart_la_SOURCES) 
	(upstartinclude_HEADERS, TESTS): Update filenames.

	* upstart/control.c (upstart_message_new): New function that
	creates an NihIoMessage directly from its arguments, which are a type
	followed by a variable number of args depending on that type.
	(upstart_message_handler): Function to find a handler function for
	a particular message type and origin process.
	(upstart_message_handle): New function that takes an NihIoMessage
	and invokes a handler function with a variable number of args
	depending on the message type.
	(upstart_send_msg, upstart_send_msg_to, upstart_recv_msg): Drop these
	functions, leave it up to the caller to decide whether to send and
	receive the messages synchronously or asynchronously; now that the
	capability is in nih_io_*.
	* upstart/control.h (UpstartMsgType): Rename to UpstartMessageType.
	(UpstartMessageHandler): Function with variable number of arguments
	that handles a message received.
	(UpstartMsg): Drop this structure entirely, we'll encode or decode
	the wire format directly from or into a function call, rather than
	use an intermediate structure to marshal it.
	(UpstartMessage): New structure to make a table that can be passed
	to upstart_message_handle to determine which handler should be called.
	* upstart/tests/test_control.c: Test new behaviour.
	* upstart/wire.c (upstart_push_header, upstart_pop_header): Change
	structure name for type parameter.
	* upstart/wire.h: Update.
	* upstart/tests/test_wire.c: Update.

	* configure.ac (AC_COPYRIGHT): Update copyright to 2007.

2006-12-29  Scott James Remnant  <scott@netsplit.com>

	* upstart/wire.c (upstart_write_int, upstart_write_unsigned) 
	(upstart_write_string, upstart_write_header, upstart_write_packv) 
	(upstart_write_pack): Rename to *_push_*
	(upstart_read_int, upstart_read_unsigned, upstart_read_string) 
	(upstart_read_header, upstart_read_packv, upstart_read_pack): Rename
	to *_pop_*.
	All of the above modified to modify an NihIoMessage structure,
	instead of trying to carry around buffers ourself.
	* upstart/wire.h: Update to match above.
	* upstart/tests/test_wire.c: Update all tests to match the above
	changes.

2006-12-21  Scott James Remnant  <scott@netsplit.com>

	* upstart/wire.c (upstart_read_packv, upstart_write_packv): Change
	nih_assert_notreached to nih_assert_not_reached.

	* init/job.c (job_run_script): Open the NihIo structure in stream mode.
	* logd/main.c (logging_watcher): Open the NihIo structure in
	stream mode.
	(logging_reader): Need to pass the length of the size_t as a pointer
	so that it can be modified if less is read.

2006-12-17  Scott James Remnant  <scott@netsplit.com>

	* upstart/wire.c (upstart_write_packv, upstart_write_pack) 
	(upstart_read_packv, upstart_read_pack): Functions to write a pack
	of different variables to the stream, or read them from it
	* upstart/wire.h: Add prototypes.
	* upstart/tests/test_wire.c (test_write_pack, test_read_pack):
	Check we can read and write a pack of variables at once.

	* upstart/wire.c (upstart_write_header, upstart_read_header): Drop
	the version from the header, we'll just keep the protocol always
	backwards compatible.
	* upstart/wire.h: Update.
	* upstart/tests/test_wire.c (test_write_header, test_read_header):
	Check that everything works.

	* upstart/wire.c (upstart_write_string, upstart_read_string):
	Transmit the length as an unsigned, and use 0xffffffff to mean NULL
	instead of zero so we can still transmit the empty string.
	* upstart/wire.h: Update.
	* upstart/tests/test_wire.c (test_write_string, test_read_string):
	Tests for the functions to make sure the wire is at it should be.

	* upstart/wire.c (upstart_read_str, upstart_write_str): Rename to
	upstart_read_string and upstart_write_string.
	* upstart/wire.h: Update.
	
	* upstart/wire.c (upstart_write_unsigned, upstart_read_unsigned):
	Functions to send unsigned values over the wire, which we'll use
	to get a bit extra for the string lengths.
	* upstart/wire.h: Update.
	* upstart/tests/test_wire.c (test_write_unsigned) 
	(test_read_unsigned): Test the new functions.

	* upstart/wire.c (upstart_write_ints, upstart_read_ints): Drop
	these functions, we'll go with something far more generic and
	useful.
	* upstart/wire.h: Remove prototypes.

	* upstart/wire.c (upstart_write_int, upstart_read_int): Transmit
	integers as signed 32-bit values in network byte order.
	* upstart/tests/test_wire.c (test_write_int, test_read_int): Test
	the functions to make sure the wire is at it should be,

	* upstart/control.c (upstart_read_int, upstart_write_int) 
	(upstart_read_ints, upstart_write_ints, upstart_read_str) 
	(upstart_write_str, upstart_read_header, upstart_write_header): Move
	functions to new wire.c file.
	* upstart/wire.c: Source file to hold wire protocol functions.
	* upstart/wire.h: Prototypes.
	* upstart/tests/test_wire.c: (empty) test suite.
	* upstart/libupstart.h: Include wire.h
	* upstart/Makefile.am (libupstart_la_SOURCES): Build and link wire.c
	(upstartinclude_HEADERS): Install wire.h
	(TESTS): Build and run wire test suite.
	(test_wire_SOURCES, test_wire_LDFLAGS, test_wire_LDADD): Details for
	wire test suite binary.

	* upstart/control.c (MAGIC): Change to "upstart\n", the final
	character was originally \0 and then was a " " for the 0.2 series.
	* upstart/tests/test_control.c (test_recv_msg): Change to match.

2006-12-15  Scott James Remnant  <scott@netsplit.com>

	* util/initctl.c, compat/sysv/telinit.c, compat/sysv/shutdown.c:
	Update all uses of the UpstartMsg structure to avoid the
	intermediate union that no longer exists.	

	* init/control.c, init/tests/test_control.c: Update all uses of
	the UpstartMsg structure to avoid the intermediate union that no
	longer exists.	

	* upstart/control.h: Combine all the previous message structures
	into just one that has all of the fields anyway.
	* upstart/control.c, upstart/tests/test_control.c: Update all uses of
	the UpstartMsg structure to avoid the intermediate union that no
	longer exists.

	* upstart/control.h (UPSTART_API_VERSION): Define API version macro
	to be public.
	* upstart/control.c (MSG_VERSION, upstart_send_msg_to): Replacing the
	previous MSG_VERSION macro here.

	* upstart/control.c (upstart_read_int, upstart_write_int) 
	(upstart_read_ints, upstart_write_ints, upstart_read_str) 
	(upstart_write_str, upstart_read_header, upstart_write_header):
	New functions to replace the old "write a struct" protocol with
	something a little more regimented and supportable.
	(IOVEC_ADD, IOVEC_READ, WireHdr, WireJobPayload, WireJobStatusPayload)
	(WireEventPayload): Remove these structures, use the functions
	instead.
	(upstart_send_msg_to): Call write functions intead of using macros,
	this makes the code somewhat neater.
	(upstart_recv_msg): Call read functions instead of using macros,
	again making the code somewhat neater.
	* upstart/tests/test_control.c (test_recv_msg): Change wire
	tests to match new protocol, and thus actually work properly,
	previously these were endian sensitive.

2006-12-14  Scott James Remnant  <scott@netsplit.com>

	* compat/sysv/shutdown.c (wall): Construct the wall message so that
	we don't put \r into a po file; for some reason, gettext hates that
	and bitches about it.  Someone's confusing internationalisation with
	operating system portability, I expect.

	* util/man/initctl.8: Drop reference to start(8), as that's just
	a symlink to initctl now.

	* init/man/init.8: Link to initctl.

	* compat/sysv/reboot.c (main): Clear up help text a little.

	* HACKING: Correct some typos.

	* configure.ac (AC_INIT): Correct bug reporting address.

2006-12-13  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Bump version to 0.3.2

	* NEWS: Update.

	* util/initctl.c (print_job_status): Drop the newline from the
	output.

2006-12-13  Alex Smith  <alex@alex-smith.me.uk>

	* util/initctl.c (print_job_status): Clean up initctl job status
	output, which was badly converted from printf to nih_message.

2006-12-13  Scott James Remnant  <scott@netsplit.com>

	* compat/sysv/man/shutdown.8: Add missing documentation on the
	format of TIME by copying it from --help output.

2006-12-13  Alex Smith  <alex@alex-smith.me.uk>

	* init/process.c (process_setup_console): Actually send output to
	/dev/null instead of /dev/console, when CONSOLE_NONE.

2006-12-13  Scott James Remnant  <scott@netsplit.com>

	* Makefile.am (EXTRA_DIST): Distribute the nih ChangeLog as well.

	* init/tests/test_job.c: Port to the new test framework.
	* init/job.c (job_set_idle_event): Fix a slight memory leak,
	repeated setting of the idle event never freed the previous one set.

2006-12-12  Scott James Remnant  <scott@netsplit.com>

	* init/tests/test_cfgfile.c: Port to the new test framework.

	* init/tests/test_control.c: Port to the new test framework.
	* init/init.supp: Suppress the list head allocated within control_init.

	* init/control.c (control_watcher): Need to save the pid when we
	get ECONNREFUSED, otherwise we lose it when we free the message.

	* init/tests/test_process.c: Port to the new test framework.
	* init/init.supp: Suppress the list head allocated within job_init.

	* init/init.supp: Include a valgrind suppressions file.
	* init/Makefile.am (EXTRA_DIST): Distribute the suppressions file.

	* init/tests/test_event.c: Port to the new test framework.

	* logd/Makefile.am, util/Makefile.am, compat/sys/Makefile.am
	(AM_CPPFLAGS): Add -I$(srcdir), necessary for testing "programs"
	that don't have usual library path semantics.

	* upstart/tests/test_control.c: Port to the new test framework.
	* upstart/control.c (upstart_free): Drop this function, while not
	exposing libnih is a valiant effort, it already slips out because
	of the error handling.

	* upstart/tests/test_job.c: Add missing include.

	* upstart/tests/test_job.c: Port to the new test framework.
	(test_process_state_name): Check that this returns NULL.

	* HACKING: Update location of download directory.  Document
	requirement that all code have test cases.

	* logd/main.c (open_logging): Likewise.

	* init/control.c (control_open): No need to set ENOMEM, errno is
	always set anyway.

	* configure.ac (AM_INIT_AUTOMAKE): Include nostdinc so we don't get
	Automake's broken default includes.
	* upstart/Makefile.am (DEFAULT_INCLUDES): Drop override now that
	we don't need it.
	(DEFS, INCLUDES): Replace these variables with the combined
	(AM_CPPFLAGS): variable that declares everything.
	* init/Makefile.am (DEFAULT_INCLUDES): Drop override now that
	we don't need it.
	(DEFS, INCLUDES): Replace these variables with the combined
	(AM_CPPFLAGS): variable that declares everything.
	* util/Makefile.am (DEFAULT_INCLUDES): Drop override now that
	we don't need it.
	(DEFS, INCLUDES): Replace these variables with the combined
	(AM_CPPFLAGS): variable that declares everything.
	* compat/sysv/Makefile.am (DEFAULT_INCLUDES): Drop override now that
	we don't need it.
	(DEFS, INCLUDES): Replace these variables with the combined
	(AM_CPPFLAGS): variable that declares everything.
	* logd/Makefile.am (DEFAULT_INCLUDES): Drop override now that
	we don't need it.
	(DEFS, INCLUDES): Replace these variables with the combined
	(AM_CPPFLAGS): variable that declares everything.

2006-11-02  Scott James Remnant  <scott@netsplit.com>

	* util/initctl.c (start_action): Remove break calls which shouldn't
	be there.

2006-10-18  Sean E. Russell  <ser@ser1.net>

	* init/main.c: Include sys/time.h
	* init/cfgfile.c: Include sys/time.h and sys/resource.h
	* init/job.c: Include sys/time.h and sys/resource.h

2006-10-17  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Bump version to 0.3.1

	* NEWS: Update.
	* TODO: Update.

	* configure.ac (AM_GNU_GETTEXT_VERSION): Quote version number.

	* logd/Makefile.am (event.d/logd): Make the event.d sub-directory
	in case we're building outside of the source tree.

	* compat/sysv/runlevel.c (store): Don't break strict-aliasing rules
	by avoiding dereferencing type-punned pointer.  Answers on a
	postcard, please.

2006-10-13  Scott James Remnant  <scott@netsplit.com>

	* util/initctl.c (start_action, emit_action): Add missing \n

	* util/initctl.c: Rewrite using nih_command_parser.
	* util/man/initctl.8: Improve.

	* util/start.c: Remove, replaced by initctl.
	* util/man/start.8: Remove, replaced by initctl.
	* util/Makefile.am (sbin_PROGRAMS): Drop start, now just a symlink
	to initctl.
	(dist_man_MANS): Drop start.8, now a symlink to initctl.8
	(install-exec-hook): Make symlinks to initctl, add start
	(install-data-hook): Make symlinks to initctl.8, add start.8

	* initctl: Rename to util again, I don't want a separate directory
	for every single little tool; and we'll be shipping more than just
	initctl (e.g. a non-compat reboot).
	* configure.ac (AC_CONFIG_FILES): Make util/Makefile instead of
	initctl/Makefile.
	* Makefile.am (SUBDIRS): Descend into util, not initctl.

	* compat/sysv/reboot.c: Remove long options where they didn't exist
	before.  Write help text.
	* compat/sysv/man/reboot.8: Update.

	* init/main.c (main): Formatting.
	* logd/main.c (main): Formatting.
	* logd/man/logd.8: Formatting.
	* compat/sysv/runlevel.c (main): Formatting.
	* compat/sysv/telinit.c (main): Formatting.
	* compat/sysv/man/shutdown.8: Remove long options.

	* compat/sysv/shutdown.c: Remove -e/--event, it has no place in a
	compatibility tool.  Get rid of long options that never existed
	before.  Specify help text to describe the options.
	* compat/sysv/man/shutdown.8: Spruce up a bit.

	* compat/sysv/telinit.c (main): Set help text to list the valid
	runlevels.
	* compat/sysv/man/telinit.8: Refine the notes to mention runlevel(8).

	* compat/sysv/runlevel.c (main): Make the help text describe the
	options, rather than the behaviour.
	* compat/sysv/man/runlevel.8: Flesh out a little more.

	* configure.ac (AC_INIT): Change bug reporting address to the
	mailing list, since Launchpad doesn't accept random bugs without
	accounts and complicated control messages.
	* init/main.c, logd/main.c: Add a period to the synopsis.

	* init/main.c (main): Set the synopsis, and direct people to look
	at telinit in the --help output.
	* init/man/init.8: Flesh this out a little more, still a lot of
	explaining to do about jobs and events, but we'll wait until we've
	changed that code before documentating the behaviour.

	* logd/main.c (main): Correct help text to describe the options,
	rather than what the program does.  As per standard style.
	Don't become a daemon until the logging socket is open, and make
	that exclusive with waiting for SIGCONT.
	* logd/man/logd.8: Write some more extensive documentation,
	including describing the startup interlock and the socket protocol.
	* TODO: Plan to get rid of the signal interlock from  logd.

2006-10-12  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Expand AC_GNU_SOURCE so we get _GNU_SOURCE and so
	that gettext doesn't complain.
	(AM_GNU_GETTEXT_VERSION): Increase to 0.15
	(AC_PREREQ): Increase to 2.60
	* HACKING: Update autoconf and gettext requirements.

2006-10-11  Scott James Remnant  <scott@netsplit.com>

	* init/control.c (control_init): Pass NULL to nih_list_new.
	Clarify list item types.
	* init/event.c (event_init): Pass NULL to nih_list_new.
	* init/job.c (job_init): Pass NULL to nih_list_new.

	* init/main.c: Change nih_signal_add_callback to nih_signal_add_handler
	and NihSignalCb to NihSignalHandler.

	* init/cfgfile.c, init/cfgfile.h, init/control.c, init/control.h,
	init/event.c, init/event.h, init/job.c, init/job.h, init/main.c,
	init/process.c: Clean up documentation strings and parent pointer
	types.

	* compat/sysv/shutdown.c: Change nih_signal_add_callback to
	nih_signal_add_handler.

	* compat/sysv/reboot.c: Set synopsis text depending on command
	used (probably should use nih_command_parser?)
	* compat/sysv/runlevel.c: Set synopsis and help text, and correct
	usage.
	* compat/sysv/shutdown.c: Set synopsis text.
	* compat/sysv/telinit.c: Set synopsis text.

	* compat/sysv/runlevel.c, compat/sysv/shutdown.c: Clean up
	documentation strings.

	* logd/main.c: Set synopsis and help text.

	* logd/main.c: Clean up documentation strings.
	Change nih_signal_add_callback to nih_signal_add_handler.

	* upstart/control.c, upstart/control.h, upstart/job.c: Clean up
	documentation strings and correct parent pointer type.

	* HACKING: Detail function documentation requirement and format.

2006-10-10  Scott James Remnant  <scott@netsplit.com>

	* event.d/logd.in: Move to logd/event.d
	* event.d/Makefile.am: Remove
	* logd/Makefile.am: Create the logd job definition and install
	* Makefile.am (SUBDIRS): event.d directory has been removed.
	* configure.ac (AC_CONFIG_FILES): No longer make event.d/Makefile

	* configure.ac: Check for --enable-compat, default to sysv if given
	or no compat if not given.
	* compat/sysv/Makefile.am: Don't build binaries or install manpages
	unless COMPAT_SYSV is defined.

2006-10-06  Scott James Remnant  <scott@netsplit.com>

	* doc/upstart-logo.svg: Include the logo Alexandre designed.
	* doc/Makefile.am (EXTRA_DIST): Ship the logo in the tarball.
	* Makefile.am (SUBDIRS): Install under doc
	* configure.ac: Generate doc/Makefile
	* AUTHORS: Ensure he's credited fully.

2006-09-27  Scott James Remnant  <scott@netsplit.com>

	* event.d/Makefile.am (do_subst): Eliminate duplicate /s

	* man/init.8: Move to init/man
	* init/Makefile.am: Update to install man page.
	* man/logd.8: Move to logd/man
	* logd/Makefile.am: Update to install man page.
	* man/initctl.8, man/start.8: Move to initctl/man
	* initctl/Makefile.am: Update to install man pages.
	* man/reboot.8, man/runlevel.8, man/shutdown.8, man/telinit.8:
	Move to compat/sysv/man
	* compat/sysv/Makefile.am: Update to install man pages.
	* man/Makefile.am: Remove
	* configure.ac (AC_CONFIG_FILES): Remove man/Makefile
	* Makefile.am (SUBDIRS): Don't build in man

	* util: Rename to initctl
	* configure.ac (AC_CONFIG_FILES): Update.
	* Makefile.am (SUBDIRS): Update.

	* util/reboot.c: Move to compat/sysv
	* util/shutdown.c: Move to compat/sysv
	* util/Makefile.am: Update.
	* compat/sysv/Makefile.am: Update.

	* configure.ac: Replace macros with single call to NIH_INIT.
	Bump version to 0.3.0 to begin new development cycle.

2006-09-21  Scott James Remnant  <scott@netsplit.com>

	* logd/main.c: Revert the change that logged to the console, in
	practice this doesn't work so well.  I want to get rid of logd
	in the long term, or at least just have it as a simple logging
	proxy, so giving it features seems wrong.

2006-09-20  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Bump version to 0.2.8
	* NEWS: Updated.

	* logd/main.c (main): Check the kernel command-line for "quiet"
	(line_reader): Write to console unless silent or a daemon

	* man/Makefile.am (dist_man_MANS): Drop sulogin.8
	* man/sulogin.8: Drop, we don't include an sulogin

2006-09-19  Michael Biebl  <mbiebl@gmail.com>

	* event.d/Makefile.am (logd): Drop $(srcdir)
	* init/Makefile.am (init_SOURCES): Distribute paths.h

2006-09-18  Michael Biebl  <mbiebl@gmail.com>

	* configure.ac: Check for sys/inotify.h

2006-09-18  Scott James Remnant  <scott@netsplit.com>

	* util/shutdown.c (warning_message): Adjust method of constructing
	the message to not confuse poor translators who think \r and \n are
	the same thing!

2006-09-14  Scott James Remnant  <scott@netsplit.com>

	* init/job.c (job_change_state): Catch runaway respawns when we
	enter the running state, so we catch stop/start loops too.
	* init/tests/test_job.c (test_change_state): Update test.

	* event.d/logd: Rename to logd.in
	* event.d/logd.in: Replace /sbin with @sbindir@ so we can transform
	* event.d/Makefile.am: Generate logd from logd.in

	* util/reboot.c: Don't hardcode the location of /sbin/shutdown
	* util/Makefile.am (DEFS): Use autoconf to seed it
	* util/shutdown.c (sysvinit_shutdown): Don't hardcode the location
	of /dev/initctl

	* init/paths.h: Create a new configuration file that can contain
	all of the path definitions, and in particular, allow them to be
	overidden elsewhere.
	* init/Makefile.am (DEFS): Override definitions of CFG_DIR and
	TELINIT using autoconf
	* init/main.c: Include paths.h.  Don't hardcode location of telinit
	* init/job.c: Include paths.h
	* init/process.c: Include paths.h
	* init/process.h: Remove definitions from here.

	* configure.ac: Bump version to 0.2.7

2006-09-13  Scott James Remnant  <scott@netsplit.com>

	* NEWS: Updated.

	* TODO: More TODO.

2006-09-10  Scott James Remnant  <scott@netsplit.com>

	* util/reboot.c (main): Don't give -H with "halt".

2006-09-09  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Bump version to 0.2.6

	* NEWS: Update.
	* TODO: Update.

	* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Change
	the magic to be the package string.
	* upstart/tests/test_control.c (test_recv_msg): Update tests.

	* util/initctl.c (main): Set the usage string.
	* util/shutdown.c (main): Set the usage string.
	* util/start.c (main): Set the usage string.
	* compat/sysv/runlevel.c (main): Set the usage string.
	* compat/sysv/telinit.c (main): Set the usage string.

	* man/Makefile.am: Use install-data-hook and $(man8dir)
	* util/Makefile.am: Also use install-exec-hook

	* Makefile.am (SUBDIRS): Install contents of the man directory
	* configure.ac (AC_CONFIG_FILES): Generate man/Makefile
	* man/Makefile.am: Install manpages in the appropriate places.
	* man/init.8, man/logd.8, man/initctl.8, man/reboot.8,
	* man/shutdown.8, man/start.8, man/sulogin.8, man/runlevel.8,
	* man/telinit.8: Include some basic manpages so we at least have
	some level of documentation.

	* init/job.c (job_child_reaper): Don't check the exit status of
	a respawning job if the goal is to stop it.

	* compat/sysv/telinit.c (main): Generate events rather than
	starting and stopping jobs directly, the events are named
	"runlevel-X".  0, 1, 6 and s/S are shutdown events.

	* logd/main.c (main): Raise SIGSTOP before entering the main loop.
	* init/main.c (main): Interlock with logd.

	* event.d/logd: Should not be a console owner, but should stop
	on shutdown.

	* init/process.c (process_setup_console): Revert part of the previous
	change, should just output to /dev/null if we don't have logd.

	* configure.ac: Bump version to 0.2.5

	* init/main.c (main): Start the logd job if it exists.

	* init/process.c (process_setup_console): Ignore ECONNREFUSED as
	that just means that logd isn't around, handle errors by falling
	back to opening the console.

	* init/process.c (process_setup_console): Implement handling for
	CONSOLE_LOGGED and generally clean up the other handling.
	* init/process.h: Update.
	* init/main.c (main): Pass NULL for the job to setup console.
	* TODO: Update.

	* logd/main.c: Implement the logging daemon, it accepts connections
	on a unix stream socket with the abstract name
	"/com/ubuntu/upstart/logd", expects the length of the name and the
	name to follow; then sequences of lines which are logged to
	/var/log/boot, or memory until that file can be opened.

2006-09-08  Scott James Remnant  <scott@netsplit.com>

	* util/shutdown.c (event_setter): Change the event names to
	distinguish between "shutdown -h" and "shutdown -h -H".

	* init/job.c (job_handle_event): Allow jobs to react to their own
	events, this is how we'll do respawn eventually.
	* init/tests/test_job.c (test_handle_event): Remove test.

	* init/main.c (cad_handler, kbd_handler): Generate the new event
	names.
	* init/event.h (CTRLALTDEL_EVENT, KBDREQUEST_EVENT): Add definitions
	of these event names, change the ctrlaltdel event to just that.

	* logd/main.c (main): Add the code to daemonise, etc.

2006-09-07  Scott James Remnant  <scott@netsplit.com>

	* TODO: Long discussion today on #upstart, many improvements to the
	job and event model that make it more elegant.
	* AUTHORS: Include a list of thanks.

	* util/shutdown.c (shutdown_now): If we get ECONNREFUSED when we
	try and send the shutdown event to init, it probably means we're
	still in sysvinit.  So try that instead.
	(sysvinit_shutdown): Function to send a hand-crafted runlevel
	change message across /dev/initctl.

	* util/initctl.c (main): Add a shutdown command that takes an
	arbitrary event name to be issued after "shutdown".  You'll
	nearly always want the /sbin/shutdown tool instead.

	* init/job.c (job_detect_idle): Only generate the stalled event
	if at least one job handles it in its start_events list.
	* init/tests/test_job.c (test_detect_idle): Make sure that works.

	* init/event.h (STARTUP_EVENT, SHUTDOWN_EVENT, STALLED_EVENT):
	Macros to define the standard event names.
	* init/main.c (main): Use STARTUP_EVENT macro instead of "startup"
	* init/control.c (control_handle): Use SHUTDOWN_EVENT macro
	instead of "shutdown".
	* init/job.c (job_detect_idle): Use STALLED_EVENT macro instead
	of "stalled".

	* init/job.c (job_detect_idle): Add some log messages for when we
	detect the idle or stalled states.
	(job_kill_process, job_kill_timer): Increase log verbosity.
	* init/event.c (event_queue_run): Log which events we're handling
	if --debug is given.

	* compat/sysv/telinit.c (main): Send a shutdown command when
	requesting to enter runlevel 0 or runlevel 6, likewise for
	runlevel 1, s or S which all run "rc1" not "rcS".
	* init/main.c (main): When called directory (pid != 1) try and
	run telinit before complaining that we're not init.  Make sure
	errors aren't lost.

2006-09-04  Johan Kiviniemi  <johan@kiviniemi.name>

	* upstart/control.c (upstart_addr): Replace use of __builtin_offsetof
	with offsetof.
	* upstart/tests/test_control.c (test_recv_msg): Likewise.

2006-09-04  Scott James Remnant  <scott@netsplit.com>
	
	* util/shutdown.c (main): Exit normally after sending the warning
	message if -k is given.

2006-09-01  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Bump version to 0.2.2

	* NEWS: Update.
	* configure.ac: Bump version to 0.2.1

	* init/process.c (process_setup_console): Ensure that the console
	is always initialised to at least /dev/null
	* init/job.c (job_change_state): Initialise event to NULL.
	* init/event.c (event_read_state): Don't mask initialisation of
	other variable.
	* init/cfgfile.c (cfg_job_stanza, cfg_parse_script, cfg_next_token): 
	Print lineno using %zi not %d
	* compat/sysv/runlevel.c (store): Cast pointer type of timeval.

	* init/main.c: Move the kernel headers include beneath the C
	library ones, so that compilation doesn't fail on !i386.
	* util/reboot.c: Likewise.

	* init/main.c (term_handler): Close the control connection if we
	re-exec init, otherwise it won't be able to bind.  Drop debugging.

	* init/main.c (term_handler): It always helps if we dup2 the
	right file descriptor.

	* init/main.c: Use the TERM signal instead of USR1, as old init
	used that for something else.  Also rather than passing across
	file descriptor numbers, use a fixed descriptor and just pass
	"--restart".  When we get that option we need to unmask signals
	otherwise we sit there looking like a lemon.

	* init/job.c (job_change_state): Don't free the event unless we
	generate one.

	* NEWS: Update.

	* init/cfgfile.c (cfg_watcher): Ignore any file with '.' or '~'

	* TODO: Update.

	* init/main.c (main): Parse command-line arguments, specifically
	look for --state-fd which we'll use for reexec.  Don't do a couple
	of things if we're passed this.
	(read_state): Parse the line-buffered state.
	* init/job.c (job_read_state, job_write_state): Job state
	serialisation so that we can re-exec ourselves.
	* init/job.h: Update.
	* init/tests/test_job.c: Test the serialisation.
	* init/event.c (event_read_state, event_write_state): And similar
	functions for serialising the event queue.
	* init/event.h: Update.
	* init/tests/test_event.c: Test the serialisation.
	* init/cfgfile.c (cfg_read_job): Fix a bug, need to subtract current
	time to get due time.

	* upstart/job.c (job_goal_from_name, job_state_from_name) 
	(process_state_from_name): Add opposite numbers that convert a
	string back into an enumeration.
	* upstart/job.h: Update.
	* upstart/tests/test_job.c: Test the new functions.

2006-08-31  Scott James Remnant  <scott@netsplit.com>

	* init/job.h (Job): Add respawn_limit, respawn_interval,
	respawn_count and respawn_time members so that we can keep track of
	runaway processes.
	* init/job.c (job_catch_runaway): Increment the respawn_count
	within respawn_interval, or reset it if we go over.
	(job_new): Initialise respawn_limit and respawn_interval to sensible
	defaults.
	* init/tests/test_job.c (test_new): Check the defaults are set.
	(test_change_state): Check the respawning code works.
	* init/cfgfile.c (cfg_job_stanza): Parse the "respawn limit" stanza.
	* init/tests/test_cfgfile.c (test_read_job): Test the new stanza.

	* init/process.c (process_setup_console): Remove the console reset
	code, it tends to just crash X and seems to do nothing interesting.
	* init/main.c (reset_console): Instead put it here and just do it
	on startup.

	* configure.ac: Bump version to 0.2.0

	* util/Makefile.am (install-exec-local): Create symbolic links,
	not hard links.

	* init/main.c: Can't catch STOP.

	* util/reboot.c: Pause init while shutting down or rebooting.

	* init/main.c (stop_handler): Catch STOP/TSTP and CONT.
	* init/event.c (event_queue_run): Don't run the event queue while
	paused.
	* init/job.c (job_detect_idle): Don't detect idle jobs while paused.

	* util/reboot.c: if we get the -w argument ("only write to wtmp")
	we need to exit, and not behave as halt normally would.

	* compat/sysv/runlevel.c (main): Add missing newline.
	* compat/sysv/telinit.c (main): And here too.

	* init/main.c (main): Check for idle after the startup event queue
	has been run, otherwise we may just sit there.

	* compat/sysv/Makefile.am (sbin_PROGRAMS): Build and install telinit
	(telinit_SOURCES, telinit_LDFLAGS, telinit_LDADD): Details for
	telinit binary.
	* compat/sysv/telinit.c: Trivial telinit program that just runs
	the appropriate rcX job.
	* compat/sysv/runlevel.c (main): Suggest help on illegal runlevel.

	* util/Makefile.am: Tidy up.

	* configure.ac (AC_CONFIG_FILES): Create compat/sysv/Makefile
	* Makefile.am (SUBDIRS): Build things found in compat/sysv
	* compat/sysv/Makefile.am (sbin_PROGRAMS): Build and install runlevel
	(runlevel_SOURCES, runlevel_LDFLAGS, runlevel_LDADD): Details for
	runlevel binary.
	* compat/sysv/runlevel.c: Helper to store and retrieve the current
	"runlevel" from utmp/wtmp; as well as the reboot time.

	* init/main.c (main): Drop debugging set.

	* init/job.c (job_change_state): As well as the job/state events,
	send the job event when a service is running or a task is stopping.
	* init/tests/test_job.c (test_change_state): Check the events get
	sent properly.

	* util/start.c: Write a simple utility to start, stop, or query
	the status of the named jobs.
	* util/Makefile.am (sbin_PROGRAMS): Build and install start
	(start_SOURCES, start_LDFLAGS, start_LDADD): Details for start
	(install-exec-local): Also install as stop and status.
	* util/reboot.c (main): Drop the debugging set.

	* init/cfgfile.c (cfg_job_stanza): Correct nih_alloc error.

	* init/process.c (process_setup_environment): Guard memory alloc.
	* init/job.c (job_set_idle_event): Likewise.
	(job_change_state): And here too.
	(job_run_command): Likewise.
	* init/control.c (control_send): Likewise.
	* init/cfgfile.c: And throughout this file.
	* upstart/control.c (upstart_recv_msg): And once here too.

	* upstart/control.h: Abolish the separate halt, reboot and poweroff
	messages and replace with a single shutdown message that takes
	an event name (for the idle event issued afterwards).
	* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Handle
	the new shutdown event type by just treating it as an event.
	* upstart/tests/test_control.c (test_messages): Update tests.
	* init/job.c (job_set_idle_event): Store a copy of the idle event
	name.
	* init/control.c (control_send): Copy the shutdown event name.
	(control_handle): Replace individual handling with the new
	single event.
	* init/tests/test_control.c (test_watcher): Update.
	* util/initctl.c: Drop handling for things that shutdown does now.
	* util/shutdown.c: Send the UPSTART_SHUTDOWN event and let the user
	specify anything they want, just give defaults.

	This is quite a big change and abolishes level events entirely,
	along with the event history.  We now just treat events as a
	transient queue of strings that go past, may cause things to change,
	but are otherwise forgotten.  This turns out to be much easier to
	understand and has no real loss of power.

	* init/event.c: Vastly simplify; gone are the separate notions of
	edge and level events, instead we just treat them as one-shot
	things that go past and are forgotten about.
	* init/event.h (Event): Remove value member.
	Update prototypes.
	* init/tests/test_event.c: Update.
	* init/job.c (job_change_state): Change the event pattern to be
	one that includes the job name and a description of the transition
	instead of the new state.
	(job_detect_idle): Call event_queue rather than event_queue_edge.
	* init/tests/test_job.c: Update.
	* init/cfgfile.c (cfg_job_stanza): Drop "when" and "while".
	* init/tests/test_cfgfile.c (test_read_job): Drop mentions of
	"when" and "while".
	* init/control.c (control_send, control_handle): Drop cases for
	level events.
	(control_handle_event): Don't include a level in the event.
	* init/tests/test_control.c: Update
	* init/main.c: Call event_queue rather than event_queue_edge.
	* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Change
	event handling so that only a name is read.
	* upstart/control.h: Remove value/level event structures.
	* upstart/tests/test_control.c (test_messages): Update.
	* upstart/job.c (process_state_name): Not used for events, adjust
	documentation so it doesn't lie.
	* util/initctl.c (main): Drop the set function, simplify trigger.
	* util/shutdown.c (shutdown_now): Call UPSTART_EVENT_QUEUE for
	shutdown into maintenance mode.

	* init/control.c (control_handle): Place a message in the syslog
	before halting, powering off or rebooting.

	* util/shutdown.c: Adjust so that the warning message is sent out
	if shutdown is immediate, and when it actually happens.  Include
	the hostname as wall does.

2006-08-30  Scott James Remnant  <scott@netsplit.com>

	* TODO: Update.

	* util/shutdown.c: Implement shutdown utility along the same lines
	as the sysvinit one, but with rather different code.

	* util/initctl.c (main): Call setuid on the effective user id so
	that we can be made setuid root and executable by a special group.
	* util/reboot.c (main): Likewise.

	* util/initctl.c (main): Check the effective rather than the real
	user id, if we're effectively root, that's good enough.

	* util/reboot.c: Implement reboot/halt/poweroff utility.
	* util/Makefile.am (sbin_PROGRAMS): Build and install reboot
	(reboot_SOURCES, reboot_LDFLAGS, reboot_LDADD): Details for reboot
	(install-exec-local): Create hardlinks to reboot for halt and poweroff.

2006-08-29  Scott James Remnant  <scott@netsplit.com>

	* init/main.c (main): Actually run the idle-detect function.
	* init/job.c (job_detect_idle): Interrupt the main loop, otherwise
	we may end up waiting for a signal before we process the event
	we just issued.

2006-08-27  Scott James Remnant  <scott@netsplit.com>

	* util/shutdown.c: Template main function.
	* util/Makefile.am (sbin_PROGRAMS): Build and install the
	shutdown binary.
	(shutdown_SOURCES, shutdown_LDFLAGS, shutdown_LDADD): Details for
	the shutdown binary

	* util/initctl.c (main): Add commands for halt, poweroff and reboot.

	* init/event.c (event_queue_run): Remove the parameters.
	* init/event.h: Update.
	* init/main.c (main): Update.
	* init/tests/test_control.c (test_watcher): Update.
	* init/tests/test_job.c (test_detect_idle): Update.

	* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Deal
	with halting, rebooting and powering off; or at least the appropriate
	messages.
	* upstart/control.h: Add control message structures for halting,
	powering off and rebooting the machine.
	* upstart/tests/test_control.c (test_messages): Run the tests.
	* init/control.c (control_handle): Add handling for halt, power off
	and reboot that issue the shutdown event and arrange for the halt,
	poweroff or reboot to be issued the next time the system is idle.
	* init/tests/test_control.c (test_watcher): Test the events.

	* TODO: Update.

	* init/job.c (job_detect_idle): Function to detect when the system is
	stalled or idle.
	* init/job.h: Update
	* init/tests/test_job.c (test_detect_idle): Test the new function.

	* util/initctl.c (main): Handle the list command.

	* TODO: Update.

	* upstart/control.c (WireJobStatusPayload): add description to the
	job status payload.
	(upstart_send_msg_to, upstart_recv_msg): Send and receieve the
	description over the wire.
	* upstart/control.h (UpstartJobStatusMsg): add a description field
	* upstart/tests/test_control.c: Update test cases.
	* init/control.c (control_handle): Include the job description in
	the message.
	(control_send): Copy the description when we put the message on
	the queue.
	(control_handle_job): Copy the description here too
	* init/tests/test_control.c: Update test cases.

	* init/job.c (job_list): Add a function to return the job list.
	* init/job.h: Update.
	* init/control.c (control_handle): Handle the JOB_LIST message
	by sending back a list of job status messages followed by the
	JOB_LIST_END message.
	* init/tests/test_control.c (test_watcher_child): Check the
	JOB_LIST message works properly.

	* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Handle
	the JOB_LIST and JOB_LIST_END messages which have no payload.
	* upstart/control.h: Add enums and structures for job list messages.
	* upstart/tests/test_control.c (test_messages): Update tests.

	* init/main.c (main): Check that we're both uid and process #1

	* init/main.c (main): Stop handling SIGTERM, we never want people
	to kill init.  Handle SIGINT and SIGWINCH through the ordinary
	handler and SIGSEGV through a direct handler.
	(segv_handler): Write a sensible core dump handler, we use a child
	to dump core while we carry on in the parent hopefully stepping over
	the bad instruction.
	(cad_handler): Generate the control-alt-delete event.
	(kbd_handler): Generate the kbdrequest event.

2006-08-25  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Bump version to 0.1.2
	* NEWS: Update.

	* TODO: Update.

	* init/process.c (process_setup_environment): Inherit the PATH
	and TERM environment variables from the init process, so the
	console works properly.
	* init/process.h (PATH): Declare a default value for this variable
	* init/main.c (main): Set the value of PATH to the default.
	* init/tests/test_process.c (child): Update test case.

	* NEWS: Update.
	* configure.ac: Bump version to 0.1.1

2006-08-24  Scott James Remnant  <scott@netsplit.com>

	* init/cfgfile.h (CFG_DIR): Change configuration directory to
	/etc/event.d -- it's not been used by anyone, but is similar to
	other directories that have which is a good precedent.
	* event.d/Makefile.am (eventdir, dist_event_DATA): Install files
	into the new directory name.
	* Makefile.am (SUBDIRS): Rename sub directory
	* configure.ac (AC_CONFIG_FILES): Rename generated Makefile

	* init/Makefile.am (DEFAULT_INCLUDES): Set to include the right
	directories so out of tree builds work.
	* logd/Makefile.am (DEFAULT_INCLUDES): Set to include the right
	directories so out of tree builds work.
	* upstart/Makefile.am (DEFAULT_INCLUDES): Set to include the right
	directories so out of tree builds work.
	(upstartinclude_HEADERS): Install errors.h
	* util/Makefile.am (DEFAULT_INCLUDES): Set to include the right
	directories so out of tree builds work.

	* Makefile.am (SUBDIRS): Add m4 to the list
	* configure.ac (AC_CONFIG_FILES): Generate m4/Makefile
	* upstart/Makefile.am (upstartinclude_HEADERS): Add errors.h

	* upstart/control.c (upstart_open): 

	* init/control.c (control_open): Raise the error before
	performing other actions so errno is not lost.

	* TODO: Update.o
	* init/cfgfile.c (cfg_next_token): Don't count quote characters
	unless we're actually planning to dequote the file, otherwise we
	end up allocating short.

	* init/control.c (control_close): Free the io_watch using list_free
	in case a destructor has been set.
	* init/tests/test_control.c: Initialise the type of the message, and
	free job correctly.

	* upstart/tests/test_control.c: Fix overwrite of buffer.
	* init/tests/test_job.c: Clean up not-freed job.

2006-08-23  Scott James Remnant  <scott@netsplit.com>

	* init/tests/test_event.c: free the entry allocated and initialise
	the return values.

	* init/cfgfile.c (cfg_skip_token): Drop this function; we'll
	make sure *pos is pointing at the start of the thing we want
	to parse, not the first token.  Update the other functions
	accordingly.
	(cfg_read_job): Implement function to look over a job file and
	parse all of the stanzas that are found.  Also sanity checks the
	job afterwards and deals with reloading existing jobs.
	(cfg_job_stanza): Function that parses an individual stanza,
	calling out to the other parse functions; this is the main config
	file parser!
	(cfg_parse_args, cfg_parse_command): Drop requirement that filename
	and lineno be passed, so we can be called to reparse arguments after
	we've already done so.
	(cfg_parse_script): Remove requirement that it be called at the
	start of the entire stanza, and instead at the start of the script.
	When hitting EOF, return the script so far, not NULL.
	(cfg_parse_args): Correct bug where we didn't check sufficient
	characters while skipping whitespace.
	(cfg_next_token): Correct bug where we didn't copy the character
	after a slash into the text, instead of just not copying the slash.
	Adjust line numbers to match the fact that it's zero based now.
	* init/cfgfile.h: Define prototype.
	* init/tests/test_cfgfile.c (test_read_job): Pretty thoroughly
	test the config file parser code.

2006-08-22  Scott James Remnant  <scott@netsplit.com>

	* init/cfgfile.c (cfg_tokenise): Rename to cfg_next_token.
	(cfg_skip_token): Code to skip whitespace, token and whitespace.
	(cfg_parse_args): Function to parse an argument list.
	(cfg_next_token): Extend to support the removal of quotes and
	slashes from the token.

	* init/cfgfile.c (cfg_parse_script): Pass filename and lineno and
	increment the latter as we go.
	(cfg_script_end): Pass and increment lineno.

	* init/cfgfile.c: Correct a missing semi-colon in prototypes.
	(cfg_parse_command): Function to parse any stanza that requires
	a command and arguments list, e.g. exec/respawn/daemon.  We don't
	want to require that the list be quoted, etc. and do want to allow
	it to be folded over lines.
	(cfg_tokenise): Function used by the above to tokenise the file,
	handling things like \, quoted strings and newlines, etc.  Can be
	used both to determine the length of the token and to copy it.

	* init/cfgfile.c (cfg_read_script): Rename to cfg_parse_script.

	* init/cfgfile.c (cfg_read_script): Function to parse a script
	fragment ("foo script\n....end script\n") from the job file, which
	is the most complex form we can find.  Write it assuming the file is
	in a character array which may not be NULL terminated (ie. a mmap'd
	file).
	(cfg_script_end): Used by the above to detect the end of the
	fragment.
	* init/cfgfile.h: Empty header file.
	* init/Makefile.am (init_SOURCES): Build and link cfgfile.c
	using the cfgfile.h header
	(TESTS): Build and run the config file test cases.
	(test_cfgfile_SOURCES, test_cfgfile_LDFLAGS, test_cfgfile_LDADD):
	Details for config file test case binary.

	* init/main.c (main): Remove the calls to the unfinished config
	file code.

2006-08-21  Scott James Remnant  <scott@netsplit.com>

	* init/main.c: Add missing include for unistd.h
	* init/process.c (process_setup_console): Drop use of job.
	* util/initctl.c (main): Check that we're run as root.

	* init/main.c (main): Write the main function

	* init/event.c (event_queue_cb): Rename to event_queue_run.
	* init/event.h: Update.

	* init/process.c (process_setup_console): Become an exported
	function that includes the code to reset a console.

2006-08-19  Scott James Remnant  <scott@netsplit.com>

	* logd/main.c (main): Write the basic main function.

	* util/initctl.c (main): Fill in the details to give us a basic
	test client.

	* TODO: Update.

	* util/initctl.c (main): Provide the most basic main function.
	* util/Makefile.am (sbin_PROGRAMS): Build the initctl binary
	* Makefile.am (SUBDIRS): Build the utilities.
	* configure.ac (AC_CONFIG_FILES): Generate the util Makefile.

2006-08-18  Scott James Remnant  <scott@netsplit.com>

	* init/Makefile.am (test_job_LDADD): Remove the duplicate link.

	* TODO: Update.

	* init/job.c (job_handle_child): Rename to job_child_reaper.
	* init/job.h: Update.
	* init/tests/test_job.c: Update function names.

	* init/control.c (control_cb): Rename to control_watcher
	* init/tests/test_control.c: Update function names.

	* TODO: Update.

	* Makefile.am (SUBDIRS): Install the rc.d files.
	* configure.ac (AC_CONFIG_FILES): Generate the rc.d Makefile.
	* rc.d/Makefile.am (rcdir): Define rcdir to be /etc/rc.d
	(dist_rc_DATA): Install the logd file into that directory.
	* rc.d/logd: Write a simple service definition for the log daemon,
	this saves us hardcoding any information about it into init; it'll
	just need to know the name.

	* Makefile.am (SUBDIRS): Build the logd daemon
	* configure.ac (AC_CONFIG_FILES): Generate the logd Makefile.
	* logd/Makefile.am (sbin_PROGRAMS): Install the logd binary into
	the sbin directory by default.
	(logd_SOURCES): Build and link main.c
	* logd/main.c (main): Add basic main function for testing purposes.

2006-08-16  Scott James Remnant  <scott@netsplit.com>

	* init/job.c (job_start): Ignore self-dependencies; over-document
	why the dependency event prodding has a surprise in its tail.
	(job_change_state): Move the job_release_depends call to here.

	* init/event.c (event_queue_cb): Add event consumer/dispatcher.
	* init/event.h: Update.

	* init/control.c (control_send): Make the event code clearer.
	(control_handle): Handle the changed event semantics.
	(control_handle_event): Issue the new event type.
	* init/tests/test_control.c: Update tests.

	* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Adjust
	marshal code to match.
	* upstart/control.h: Update all structures appropriately to the
	previous changes.
	* upstart/tests/test_control.c: Update.

	* init/job.c (job_change_state): Change call to event_trigger_level
	to event_queue_level.

	* init/event.c (event_trigger_edge, event_trigger_level): Place
	the event on the event_queue rather than directly triggering it.
	Rename to event_queue_edge and event_queue_level respectively.
	* init/event.h: Update.
	* init/tests/test_event.c: Update test cases.

	* init/job.c (job_handle_event): Add another sanity check, jobs
	should not be able to react to their own events; that's just silly.
	* init/tests/test_job.c (test_handle_event): Check that the new
	condition does the right thing.
	
	* init/job.c (job_change_state): Make it illegal for a job to exist
	without either a command or script or both.  This is for sanity
	reasons, allowing no primary process makes no sense and can lead
	to event loops if someone is feeling nefarious.
	* init/tests/test_job.c (test_change_state): Drop test on behaviour
	we've just outlawed.

	* init/job.c (job_start): Only announce the change if we're still
	in the waiting state, we could have moved on to running already.

	* init/job.c (job_start): If holding the job, at least announce
	the goal change to subscribed clients.

	* TODO: Update.

	* init/job.c (job_start): Check for dependencies before starting
	the process, if we have any that aren't running we stay in waiting
	until they are.  Any that aren't even starting get poked with a
	dependency event to see whether that wakes them up.
	* init/tests/test_job.c (test_start): Test paths through new
	dependency code.

	* init/job.c (job_run_process): Once we've got an active process
	in the running state, release our dependencies.

	* init/job.c (job_release_depends): Function to release any waiting
	dependencies on the given job.
	* init/job.h: Update.
	* init/tests/test_job.c (test_release_depends): Test the behaviour
	of the function on its own.

	* init/job.h (Job): Add depends list field
	(JobName): New structure to hold the name of a job.
	* init/job.c (job_new): Initialise the depends list.
	* init/tests/test_job.c (test_new): Make sure the depends list is
	initialised properly.

	* init/job.c (job_next_state): Return JOB_STARTING if we're in
	JOB_WAITING and the goal is JOB_START.  This is only called when
	there's some change, and I don't want to hard-code the goal there.
	(job_start): Don't hardcode JOB_STARTING, instead just use the next
	state.
	* init/tests/test_job.c (test_next_state): Adjust test case.

	* init/control.c (control_subscribe): Allow the current
	subscription to be found by passing NOTIFY_NONE.
	(control_handle): Don't remove an existing subscription to jobs,
	a GUI will probably want a permanent one to keep the status up to
	date.

	* init/job.c (job_kill_process, job_kill_timer): Don't hardcode
	JOB_STOPPING here, instead move to the next logical state. 
	(job_kill_process): Notify subscribed processes that we killed
	the job.
	(job_start, job_stop): Notify subscribed processes of a change of
	goal that doesn't result in an immediate state change.

	* init/event.c (event_trigger_edge, event_trigger_level): Swap
	order so that events are announced before processed.

	* init/control.c (control_handle): Handle requests to watch and
	unwatch jobs and events.
	* init/tests/test_control.c (test_cb_child, test_cb): Check that
	subscriptions work.

	* init/tests/test_control.c (test_cb_child): Add a sleep to avoid
	a race that upsets gdb, have tried this with a STOP/CONT interlock
	but can't seem to find where the child should reach first.

	* init/job.c (job_change_state): Notify the control handler.
	* init/event.c (event_trigger_edge, event_trigger_level): Pass
	event to the control handler.
	* init/tests/test_control.c (test_cb_child): Expect to receive
	job status events as well.
	* init/Makefile.am (test_event_LDADD, test_process_LDADD) 
	(test_job_LDADD): Add control.o to the linkage.

	* init/control.c (control_cb): Don't display an error for
	ECONNREFUSED, just remove any subscriptions.
	* init/tests/test_control.c (test_handle_job, test_handle_error):
	Clean up our subscriptions properly.

	* init/control.c (control_handle_job): Function to send out an
	UPSTART_JOB_STATUS message to subscribed processes whenever a
	job state changes.
	(control_handle_event): Function to send out an
	UPSTART_EVENT_TRIGGERED message to subscribed processes whenever
	an event is triggered.
	* init/control.h: Update.
	* init/tests/test_control.c (test_handle_job, test_handle_event):
	Check that the functions work properly.

	* init/control.c (control_handle): Handle messages that trigger
	edge and level events; subscribe the process to receive notification
	of job changes during the event.
	* init/tests/test_control.c (test_cb_child): Check that the messages
	are handled properly (without subscription check).

	* init/control.c (control_cb): Unsubscribe a process if it stops
	listening.

	* init/control.c (control_send): Copy the pointers in the new
	event messages.
	* init/tests/test_control.c (test_send): Check the pointers are
	copied across correctly.

	* init/control.c (control_subscribe): Add function to handle
	processes that want to subscribe to changes.
	(control_init): Initialise the subscriptions list.
	* init/control.h: Add structures and prototypes.
	* init/tests/test_control.c (test_subscribe): Test the function.

	* upstart/control.h (UpstartMsgType): add messages for triggering
	edge and level events, receiving the trigger for an event and for
	watching jobs and events.
	(UpstartEventTriggerEdgeMsg, UpstartEventTriggerLevelMsg)
	(UpstartEventTriggeredMsg, UpstartWatchJobsMsg)
	(UpstartUnwatchJobsMsg, UpstartWatchEventsMsg):
	(UpstartUnwatchEventsMsg): Add structures for the new messages.
	(UpstartMsg): And add them to the union.
	* upstart/control.c (WireEventPayload): The event messages can all
	share a wire payload type; the watch messages don't need any special
	payload.
	(upstart_send_msg_to): Add the payloads onto the wire.
	(upstart_recv_msg): And take the payloads back off the wire.
	* upstart/tests/test_control.c (test_messages): Test the new
	message types.

	* upstart/control.h (UpstartJobStatusMsg): add a process id.
	* upstart/control.c (WireJobStatusPayload): and here too.
	(upstart_send_msg_to): copy the process id onto the wire.
	(upstart_recv_msg): copy the process id from the wire.
	* init/control.c (control_handle): Fill in the pid from the job.
	* upstart/tests/test_control.c (test_messages): Check the pid gets
	passed across the wire properly.

	* init/control.c (control_cb): Disable the poll for write once the
	send queue becomes empty.

	* upstart/Makefile.am (libupstart_la_SOURCES): Correct ordering.

	* init/control.c (control_handle): Add missing break.

	* upstart/job.c (job_goal_name, process_state_name): For completeness
	add these two functions as well.
	* upstart/job.h: Update.
	* upstart/tests/test_job.c (test_goal_name) 
	(test_process_state_name): Test the new functions.

	* init/job.c (job_state_name): Move this utility function from here
	* upstart/job.c (job_state_name): to here so all clients can use
	it.
	* init/job.h: Update.
	* upstart/job.h: Update.
	* init/tests/test_job.c (test_state_name): Move the test case from here
	* upstart/tests/test_job.c: to here as well.
	* upstart/Makefile.am (libupstart_la_SOURCES): Build and link job.c
	(TESTS): Run the job test cases
	(test_job_SOURCES, test_job_LDFLAGS, test_job_LDADD): Details for
	job test case binary.
	* init/Makefile.am (test_job_LDADD, test_process_LDADD) 
	(test_event_LDADD): Link to libupstart.la

	* init/control.c: Code to handle the server end of the control
	socket, a bit more complex than a client as we want to avoid
	blocking on malcious clients.
	* init/control.h: Prototypes.
	* init/tests/test_control.c: Test the control code.
	* init/Makefile.am (init_SOURCES): Build and link control.c
	using the control.h header
	(init_LDADD): Link to libupstart as well
	(TESTS): Build and run the control test suite.
	(test_control_SOURCES, test_control_LDFLAGS, test_control_LDADD):
	Details for control test suite binary.

	* upstart/control.c: Add a way to disable the safety checks.
	* upstart/tests/test_control.c (test_free): Fix bad test case.

	* upstart/control.c (upstart_recv_msg): fixed bogus return type
	for recvmsg from size_t to ssize_t so we don't infiniloop on error.

	* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Avoid
	job_start as the short-cut for assigning name, as that might become
	a more complex message eventually.  Use job_query instead.

	* upstart/control.c (upstart_free): Add wrapper function around
	nih_free so we're a proper library and don't expose libnih too much
	(upstart_recv_msg): Stash the sender pid in an argument.
	* upstart/control.h: Update.
	* upstart/tests/test_control.c (test_recv_msg): Test pid is
	returned properly.
	(test_free): Test the nih_free wrapper.

	* init/job.c (job_run_script): Document future FIXME.

	* init/exent.h, init/job.h, init/process.h: Fix up headers.

	* upstart/control.c, upstart/control.h, upstart/errors.h,
	upstart/job.h, upstart/libupstart.h: Fix up headers.

	* upstart/control.c: Write the code to handle the control socket
	and communication over it; turns out this was possible to write so
	that both ends are handled in the same code.
	* upstart/control.h: Structures and prototypes.
	* upstart/tests/test_control.c: Test the new code.

	* upstart/Makefile.am (libupstart_la_LIBADD): Link to libnih

	* upstart/errors.h: Header file containing errors raised by
	libupstart.
	* upstart/libupstart.h: Include errors.h

2006-08-15  Scott James Remnant  <scott@netsplit.com>

	* init/event.h: Add missing attribute for event_new()

	* init/job.h (JobGoal, JobState, ProcessState, ConsoleType): Move
	the enums from here
	* upstart/job.h: into here so that we can use them across the
	control socket.

	* Makefile.am (SUBDIRS): Build the libupstart library
	* configure.ac (AC_CONFIG_FILES): Generate upstart/Makefile
	* upstart/Makefile.am: Makefile for sub-directory
	* upstart/libupstart.ver: Linker version script.
	* upstart/libupstart.h: "Include everything" header file.

	* TODO: Update.

	* init/job.c (job_handle_child): Warn when processes are killed
	or exit with an abnormal status.  Warn when respawning.

	* init/job.c (job_handle_child): Respawn processes that were not
	supposed to have died.
	* init/tests/test_job.c (test_handle_child): Test the respawn code.

	* TODO: Update.

	* init/event.c (event_trigger_edge, event_trigger_level): Call
	job_handle_event so that we actually do something useful.
	* init/Makefile.am (test_event_LDADD): Link to process.o and job.o
	now that event.c calls code from job.

	* init/job.c (job_start_event): Function to start a job if an event
	matches.
	(job_stop_event): Function to stop a job if an event matches.
	(job_handle_event): Iterate the job list and dispatch the given event,
	causing jobs to be stopped or started using the above two functions.
	* init/job.h: Update.
	* init/tests/test_job.c: Test the new functions.

	* init/job.c (job_new): Initialise start_events and stop_events to
	an empty list.
	* init/job.h (Job): Add start_events and stop_events list heads.
	* init/tests/test_job.c (test_new): Check the lists are initialised
	correctly to the empty list.

	* init/event.c (event_match): Function to check events for equality.
	* init/event.h: Update.
	* init/tests/test_event.c (test_match): Test function.

	* init/job.c (job_change_state): Trigger the level event with the
	same name as the job, with the value taken from the state.
	* init/tests/test_job.c (test_change_state): Check the event
	gets set to the right values as we go.
	* init/Makefile.am (test_job_LDADD, test_process_LDADD): Link to
	event.o now that job.c uses code from there.

	* init/event.c (event_change_value): Rename event_set_value to this
	as we intended in the first place; makes it more consistent with job.
	Always change the value.
	(event_trigger_edge): Add a high-level function to trigger an edge
	event.
	(event_trigger_level): And another to trigger a level event with
	a given value, this inherits the "don't change it" functionality
	that was in event_set_value.
	* init/event.h: Update.
	* init/tests/test_event.c: Test new behaviours and functions.

	* init/event.c: Add simple code to keep track of events, whether
	they have been recorded or not and their current value if any.
	* init/event.h: Structures and prototypes.
	* init/tests/test_event.c: Test cases for event code.
	* init/Makefile.am (init_SOURCES): Build and link event.c using event.h
	(TESTS): Run the event test suite.
	(test_event_SOURCES, test_event_LDFLAGS, test_event_LDADD): Details
	for event test suite binary.

	* init/job.c (job_run_process, job_kill_process, job_kill_timer):
	Downgrade error messages to warning as they're not fatal.
	(job_change_state): Change info message to be more regular.

	* init/job.c (job_start): A very simple, but very necessary, function.
	Set the goal of the given job to JOB_START and kick it off.
	(job_stop): And its companion, cause a running job to be stopped.
	* init/job.h: Update.
	* init/tests/test_job.c: Test the functions.

	* init/job.c (job_handle_child): Child handler to kick jobs into
	the next state when their process dies.
	* init/job.h: Update.
	* init/tests/test_job.c (test_handle_child): Test the handler
	directly by just invoking it with various job states.

2006-08-14  Scott James Remnant  <scott@netsplit.com>

	* init/tests/test_process.c (test_kill): Use select rather than
	poll for consistency with other test cases.

	* init/job.c (job_kill_process): Add function to send the active
	process of a job the TERM signal, and then set a timer to follow
	up with the KILL signal if the job doesn't get cleaned up in time.
	(job_kill_timer): Timer callback to send the KILL signal; this
	does the same job as the child handler and puts the job into the
	next state as there's no point waiting around now.
	* init/job.h: Update.
	* init/tests/test_job.c (test_kill_process): Test both functions
	in one test case (as one is just the bottom half of the other).

	* init/tests/test_process.c (test_spawn): Use the right thing in
	the test case filename and unlink it to make sure.

	* init/job.c (job_change_state): Write the principal state gate
	function, called once a state has been left to enter the given new
	state (which one should determine with job_next_state).  Spawns
	the necessary processes or moves to the next appropriate state.
	* init/job.h: Update.
	* init/tests/test_job.c: Test the state changes.

	* init/job.c (job_run_process): Internal function to call
	process_spawn and update the job structure.
	(job_run_command): Simple(ish) wrapper for the above to split
	a command by whitespace, or use a shell if it needs more complex
	argument processing.
	(job_run_script): More complex wrapper that uses a shell to execute
	verbatim script, either using -c or a /dev/fd/NN and feeding the
	shell down a pipe to it.
	* init/job.h: Update.
	* init/tests/test_job.c: Test the new functions.

	* init/Makefile.am (init_SOURCES, TESTS): Reorder so that process.c,
	which is arguably lower level, comes first.
	(test_job_LDADD): Link the process code.
	(test_process_LDADD): Swap the order.

	* TODO: Update.

	* init/process.c (process_spawn): Correct typo (progress -> process),
	thanks Johan.

2006-08-12  Scott James Remnant  <scott@netsplit.com>

	* init/process.c (process_spawn): Correct formatting of function.
	* init/process.h (SHELL): Define the location of the shell, all in
	the spirit of not hard-coding stuff like this.

	* init/job.c (job_new): Initialise all structure members to zero
	as this doesn't happen automatically.

2006-08-10  Scott James Remnant  <scott@netsplit.com>

	* init/job.h (job_state_name): Declare as a const function.

2006-08-09  Scott James Remnant  <scott@netsplit.com>

	* init/job.c (job_next_state): State transition logic; this uses
	our departure from the specification (the goal) so that the state
	can always be currently accurate rather than suggestive.
	(job_state_name): Cute function to convert enum into a name.
	* init/job.h: Update.
	* init/tests/test_job.c (test_next_state): Test the transitions.
	(test_state_name): And the return values.

	* TODO: Add file to keep track of things.

	* init/job.c: Include nih/macros.h and nih/list.h
	* init/process.c: Include order fixing, include nih/macros.h
	* init/tests/test_job.c: Include nih/macros.h and nih/list.h
	* init/tests/test_process.c: Include nih/list.h

	* init/job.c: Include order fixing.
	(job_find_by_name): Function to find a job by its (unique) name.
	(job_find_by_pid): Function to find a job by the pid of its process.
	* init/job.h: Update.
	* init/tests/test_job.c (test_find_by_name, test_find_by_pid): Test
	new functions.

	* init/process.c (process_spawn): Spawn a process using the job
	details to set up the environment, etc.
	(process_setup_console): Set up the console according to the job.
	(process_setup_limits): Set up the limits according to the job.
	(process_setup_environment): Set up the environment according to
	the job.
	(process_kill): Simple function to send a kill signal or raise an
	error; mostly just a wrapper without any particular logic.
	* init/process.h: Prototypes and macros.
	* init/tests/test_process.c: Test cases.
	* init/Makefile.am (init_SOURCES): Build and link process.c and
	its header file.
	(TESTS): Run the process test suite.
	(test_process_SOURCES, test_process_LDFLAGS, test_process_LDADD):
	Details for process test sutie binary.

2006-08-08  Scott James Remnant  <scott@netsplit.com>

	* init/job.c (job_new): nih_list_free is necessary.
	* init/tests/test_job.c (test_new): Free job when done.

	* init/job.h: Header file to contain the definition of the Job
	structure and associated typedefs, etc.
	(JobGoal): In a divergence from the specification, we introduced a
	"goal" for a job which tells us which way round the state machine
	we're going (towards start, or towards stop).
	(JobState): Which means this always holds the current state, even
	if we're trying to get out of this state (ie. if we've sent the TERM
	signal to the running process, we're still in the running state until
	it's actually been reaped).
	(ProcessState): And in another divergence, we keep the state of the
	process so we know whether we need to force a state transition or
	can just expect one because something transient is happening.
	* init/job.c (job_new): Function to allocate a Job structure, set
	the pointers to NULL and other important members to sensible
	defaults.
	(job_init): Initialise the list of jobs.
	* init/tests/test_job.c: Test suite.
	* init/Makefile.am (init_SOURCES): Compile and link job.c using
	its header file.
	(TESTS): Run the job test suite.
	(test_job_SOURCES, test_job_LDFLAGS, test_job_LDADD): Details for the
	job test suite binary.

2006-08-02  Scott James Remnant  <scott@netsplit.com>

	* configure.ac: Check for C99

	* HACKING: Document dependency on libnih.

2006-07-27  Scott James Remnant  <scott@netsplit.com>

	* init/Makefile.am (DEFS): Append to the default DEFS list, rather
	than overriding, otherwise we lose HAVE_CONFIG_H

2006-07-13  Scott James Remnant  <scott@netsplit.com>

	* HACKING: Correct incorrect Bazaar URL.

	* AUTHORS: Change e-mail address to ubuntu.com.
	* HACKING: Update Bazaar and Release URLS.
	* configure.ac (AC_COPYRIGHT): Change copyright to Canonical Ltd.
	(AC_INIT): Change bug submission address to Launchpad.
	* init/main.c: Update header to use Canonical copyright and
	credit me as author.

2006-05-16  Scott James Remnant  <scott@netsplit.com>

	* init/main.c: Add the simplest template main.c
	* init/Makefile.am: Add template Makefile.am that builds init from
	main.c and links to libnih statically
	* configure.ac (AC_CONFIG_FILES): Configure nih and init subdirs.
	* Makefile.am (SUBDIRS): Recurse into nih and init subdirs.

2006-05-14  Scott James Remnant  <scott@netsplit.com>

	* ChangeLog: Initial project infrastructure created.
