geoherna / libudaemon

libμdaemon is a small C/C++ library to make writing Unix daemons simple

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

libμdaemon

A small C/C++ library to make writing Unix daemons simple

Building

libμdaemon is standalone, you don't need to link it with anything strange or download a tar file and stick it in the source directory, if you have a decent unix-like system, FreeBSD, Arch Linux, for example, CMake, and a decent compiler then you can build the library.

$ git clone https://github.com/xampp/libudaemon.git
$ cd libudaemon
$ mkdir build
$ cd !$ && cmake ../
$ make && sudo make install

Example

#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <udaemon.h>

int main(int argc, char* argv[]) {
	// We need options damn it!~
	lud_opt opts = {
		true,				// Use syslog
		"udaemonTest",		// The daemon name
		"/tmp/udtest.lwk",	// The lock file location
		"/tmp/udtest.pid",	// The PID file location
		NULL,				// The user to switch to
		NULL				// The working dir to switch to
	};
	// Ensure we daemonize correctly
	int err;
	if((err = lud_daemonize(&opts)) < 0) {
		printf("libudaemon error: %d (%s)", err, lud_strerror(err));
		exit(err);
	}

	// DO WORK
	syslog(LOG_INFO, "Rarw! I'm a scawwy daemon!");

	lud_status* stat = lud_querystatus();
	syslog(LOG_INFO, "PID: %d PPID: %d SID: %d", stat->pid, stat->ppid, stat->sid);

	// Job's done
	lud_cleanup();
	return err;
}

License

libμdaemon is licensed under the BSD 3-clause license, see LICENSE.md

About

libμdaemon is a small C/C++ library to make writing Unix daemons simple

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:C 100.0%