// Copyright (c) 1999-2000 David Muse
// See the COPYING file for more information.

#ifndef DAEMONPROCESS_H
#define DAEMONPROCESS_H

#include <sys/types.h>
#include <signalclasses.h>

// Daemons are long running processes which often detach themselves from
// the controlling terminal and run in the background.  They are frequently
// started at boot time and run until the machine is shut down.
//
// Daemons typically perform "housecleaning" tasks or serve data to client
// programs.  See the server class.

class daemonprocess {
        public:
                                daemonprocess();
                        virtual ~daemonprocess();

                        void    detach();
                                // Detach from the controlling terminal and
                                // process and run in the background.

                        // These methods allow the daemon to run as a different
                        // user or group than the one that started the process.
                        // They have no effect unless the process is started
                        // by the root user.
                        int     runAsUser(char *username);
                        int     runAsGroup(char *groupname);
                        int     runAsUserId(uid_t uid);
                        int     runAsGroupId(gid_t gid);

                static  void    handleShutDown(void *shutdownfunction);
                                // This method allows you to designate a
                                // function to run when the daemon is killed.

        private:
                #include <private/daemonprocess.h>

};

#endif