Here I go, changing the interface. Again.
I continue to refactor wordptr.libpwd.
The following methods have been added to or changed in the wp_configuration_t interface:
Name Changed: get_daemon_on_start_method Name Changed: set_daemon_on_start_method Signature Changed: populate_from_file Added: set_config_file_path Added: set_lock_file_path typedef struct wp_configuration { wp_status_t (*populate_from_file)(struct wp_configuration *self, const char *file_path); void (*set_config_file_path)(const [...]
Here I go, changing the interface. Again.
I continue to refactor wordptr.libpwd.
The following methods have been added to or changed in the wp_configuration_t interface:
- Name Changed:
get_daemon_on_start_method - Name Changed:
set_daemon_on_start_method - Signature Changed:
populate_from_file - Added:
set_config_file_path - Added:
set_lock_file_path
typedef struct wp_configuration {
wp_status_t (*populate_from_file)(struct wp_configuration *self, const char *file_path);
void (*set_config_file_path)(const struct wp_configuration *self, const char *value);
void (*set_lock_file_path)(const struct wp_configuration *self, const char *value);
wp_daemon_on_start_method_fn (*get_daemon_on_start_method)(const struct wp_configuration *self);
void (*set_daemon_on_start_method)(const struct wp_configuration *self, wp_daemon_on_start_method_fn fn);
/* additional methods left out */} wp_configuration_t, *wp_configuration_pt;
I made a decision to (re)name all events following an “on” semantic, such as “on_event.” For example, see the method name change for “get_daemon_on_start_method.”
Additionally, I’m still cleaning up the cruft left over from converting the project from the original stand-alone Linux daemon tutorial. There’s a lot of worthless code in the library at the moment, but it’s being stripped out.
Finally, I’m beginning to add documentation.
Have fun.
It’s (slowly) getting somewhere.
I updated the libwpd configuration settings in wordptr.libwpd to support a client override of the default daemon loop. This method gets injected into the daemon start method on reconfiguration.
There’s a little more work to do in this space, but here’s a brief outline:
First, the [...]
It’s (slowly) getting somewhere.
I updated the libwpd configuration settings in wordptr.libwpd to support a client override of the default daemon loop. This method gets injected into the daemon start method on reconfiguration.
There’s a little more work to do in this space, but here’s a brief outline:
First, the following typedef was added for the hook signature:
/* start method hook signature */typedef void (*wp_daemon_start_method_fn)(const struct wp_daemonizer *);
/* Example in client code */void daemon_start(const wp_daemonizer_t *self);
The wp_daemon_start_method_fn typedef is utilized by the internal configuration class with the following getters and setters:
wp_daemon_start_method_fn (*get_daemon_start_method)(const struct wp_configuration *self);
void (*set_daemon_start_method)(const struct wp_configuration *self, wp_daemon_start_method_fn fn);
Finally, the hook is installed within the client reconfiguration method like so:
static void reconfigure_daemon(const struct wp_daemonizer *daemon, const wp_configuration_pt config) {
config->set_daemon_start_method(config, &daemon_start);
}
If the hook is not installed, the daemon creates its own loop: It sits in a perpetual wait state, listening for signals. By overriding the main loop with your own daemon_start method, you can alter the default run loop.
The current default run loop looks something like this (see the latest commit on GitHub for wp_daemonizer.c, method wp_daemonizer_start):
static wp_status_t wp_daemonizer_start(const wp_daemonizer_t *self) {
assert(self); /* make compiler happy */
sigset_t mask, oldmask;
wp_daemon_start_method_fn start_fn = self->data->config->get_daemon_start_method(self->data->config);
if(start_fn != NULL) {
start_fn(self);
} else {
sigemptyset(&mask);
sigaddset(&mask, SIGUSR1);
sigprocmask(SIG_BLOCK, &mask, &oldmask);
while(true) {
sigsuspend(&oldmask);
}sigprocmask(SIG_UNBLOCK, &mask, NULL);
}return WP_SUCCESS;
}
Note that in the override case, the sigsuspend method is never called. Consider a similar pattern in your own main loop or you’ll eat CPU cycles.
Have fun.
What would the world be like without Captain Hook?
– Dustin Hoffman as Captain Hook, Hook, 1991
I spent a fair bit of time this week converting an ugly bit of code written exclusively for a tutorial into a more useful static library. And I stated several times that the code has a [...]
What would the world be like without Captain Hook?
I spent a fair bit of time this week converting an ugly bit of code written exclusively for a tutorial into a more useful static library. And I stated several times that the code has a long way to go before it can be considered mature.
Does it ever!
This morning I added one hook (of many planned hooks) and removed some now-useless configuration code. It’s always nice to blow away huge swaths of useless code.
I’m trying to make libwpd more library-like.
I added a callback to support configuration changes. Originally, the daemon code looked at a configuration file followed by command line parameters. I don’t like this idea in a library, though: It doesn’t makes sense to override an application’s parameters for use in this library, so I nixed the command line argument code entirely. Instead, I added a reconfiguration hook which is called immediately after the daemon object is instantiated, but before any signal handlers are installed.
The callback looks something like this:
static void reconfigure_daemon(
const struct wp_daemonizer *daemon,
const wp_configuration_pt config) {
/* Configure each option; this occurs prior to any daemonization work */config->set_enable_verbose_logging(config, true);
}
Ultimately, this is a lot more flexible. The callback is now passed directly to the wp_daemonizer_initialize method rather than a whole configuration object. This simplifies the external API considerably, since the configuration object methods are now wrapped entirely within the callback handler and the user no longer needs to worry about configuration initialization and cleanup.
tl;dr wordptr.libwpd can now be linked as a static library.
I spent a few cycles this morning updating wordptr.libwpd to be an actual static library, not an executable. The static library libwpd.la gets built under ./src.
Get the latest.
$ git clone git://github.com/jgshort/wordptr.libwpd.git
First, I changed the configuration for autotools. I had [...]
tl;dr wordptr.libwpd can now be linked as a static library.
I spent a few cycles this morning updating wordptr.libwpd to be an actual static library, not an executable. The static library libwpd.la gets built under ./src.
Get the latest.
$ git clone git://github.com/jgshort/wordptr.libwpd.git
First, I changed the configuration for autotools. I had to update ./src/Makefile.am to build a library rather than a bin, something like this:
lib_LTLIBRARIES = libwpd.la
libwpd_la_SOURCES = wp_common.c wp_pool.c wp_string.c wp_configuration.c wp_daemonizer.c
bin_PROGRAMS = wpdwpd_SOURCES = wpd.c tests/libwpd_tests.c
wpd_LDADD = libwpd.la
… where lib_LTLIBRARIES indicates the output library and libwpd_la_SOURCES indicates the files used to build libwpd.la. I kept an executable around to demonstrate the interface, which I renamed wpd.
Finally, I had to execute libtoolize and autoreconf -i once I made the appropriate changes to the various configuration files. Here’s a rough sketch of the steps I had to take to create the updated library build. I didn’t have libtool, so I had to yum install it, first.
$ sudo yum install libtool
$ aclocal$ libtoolize
$ autoreconf -i$ ./configure$ make
You should now be able to ./configure && make from the wordptr.libwpd folder, link against the libwpd.la static library and daemonize away. There’s yet a lot of work to do to really create a robust library from the sample Linux daemon code from which wordptr.libwpd descends, but the library works, the daemonizer works and it’s (somewhat) pretty clean.
Have fun.
Two years ago I created an example Linux daemon service. Why not turn it into a library?
I just created wordptr.libwpd.
NOTE! As of 2012-11-28 it’s not a library, yet! I took the code I created for the exsvcd project and created a brand new project on [...]
Two years ago I created an example Linux daemon service. Why not turn it into a library?
I just created wordptr.libwpd.
NOTE! As of 2012-11-28 it’s not a library, yet! I took the code I created for the exsvcd project and created a brand new project on GitHub:
git clone https://github.com/jgshort/wordptr.libwpd
Over the next few days, I’ll turn it into a simple, configurable daemon library project.
There’s lots of work to do, yet, and it’s pretty rough around the edges.
But there it is.
Why?
Why not simply use daemon(3)? Go for it. Seriously. Eventually, I’ll extend the wordptr.libwpd library with additional configuration and extensibility hooks. But it’s a long, long way from mature. Use daemon(3) if you need a mature solution.
Have fun.
Latest Posts
- GeForce GTX 660Ti, NVidia, Nouveau and Updating from CentOS 6.3 to 6.4 (2013/03/10)
- One time, at work… (2013/01/17)
- My Family Doesn’t Care About Security (2013/01/09)
- Programmer Competency Matrix – Education and Experience (2012/12/21)
- Your Code Is The Only Meaningful Project Documentation (2012/12/19)
- I’m Not Arguing With You Over Your Terms of Service (2012/12/18)
- Embracing Change (2012/12/18)
- Finding Quality Developers is No Easy Task (2012/12/14)
- From Avid Gamer to Architect (2012/12/10)
- It’s Bugs All The Way Down (2012/12/07)
- wordptr.libwpd – Expanding Configuration, Changing the Interface (2012/12/07)
- On Tightening Focus (2012/12/06)
- 20 Days With the Google Nexus 10 (2012/12/05)
- wordptr.libwpd – Hooking the Main Loop (2012/12/04)
- I Didn’t Read The Docs – MDADM and Hostname (2012/12/02)
- My Developer Toolbox (2012/12/01)
- wordptr.libwpd – Making it More Library-Like (2012/11/30)
- wordptr.libwpd – Now a Static Library (2012/11/29)
- A Linux Daemon Library – Introducing wordptr.libwpd (2012/11/28)
- CentOS, VMware Workstation, Development and Piece of Mind (2012/11/27)

