1 #ifndef foodaemonpidhfoo
2 #define foodaemonpidhfoo
3 
4 /***
5   This file is part of libdaemon.
6 
7   Copyright 2003-2008 Lennart Poettering
8 
9   Permission is hereby granted, free of charge, to any person obtaining a copy
10   of this software and associated documentation files (the "Software"), to deal
11   in the Software without restriction, including without limitation the rights
12   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13   copies of the Software, and to permit persons to whom the Software is
14   furnished to do so, subject to the following conditions:
15 
16   The above copyright notice and this permission notice shall be included in
17   all copies or substantial portions of the Software.
18 
19   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25   SOFTWARE.
26 
27 ***/
28 
29 #include <sys/types.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /** \file
36  *
37  * Contains an API for manipulating PID files.
38  */
39 
40 /** Prototype of a function for generating the name of a PID file.
41  */
42 typedef const char* (*daemon_pid_file_proc_t)(void);
43 
44 /** Identification string for the PID file name, only used when
45  * daemon_pid_file_proc is set to daemon_pid_file_proc_default(). Use
46  * daemon_ident_from_argv0() to generate an identification string from
47  * argv[0]
48  */
49 extern const char *daemon_pid_file_ident;
50 
51 /** A function pointer which is used to generate the name of the PID
52  * file to manipulate. Points to daemon_pid_file_proc_default() by
53  * default.
54  */
55 extern daemon_pid_file_proc_t daemon_pid_file_proc;
56 
57 /** A function for creating a pid file name from
58  * daemon_pid_file_ident
59  * @return The PID file path
60  */
61 const char *daemon_pid_file_proc_default(void);
62 
63 /** Creates PID pid file for the current process
64  * @return zero on success, nonzero on failure
65  */
66 int daemon_pid_file_create(void);
67 
68 /** Removes the PID file of the current process
69  * @return zero on success, nonzero on failure
70  */
71 int daemon_pid_file_remove(void);
72 
73 /** Returns the PID file of a running daemon, if available
74  * @return The PID or negative on failure
75  */
76 pid_t daemon_pid_file_is_running(void);
77 
78 /** Kills a running daemon, if available
79  * @param s The signal to send
80  * @return zero on success, nonzero on failure
81  */
82 int daemon_pid_file_kill(int s);
83 
84 /** This variable is defined to 1 iff daemon_pid_file_kill_wait() is supported.
85  * @since 0.3
86  * @see daemon_pid_file_kill_wait() */
87 #define DAEMON_PID_FILE_KILL_WAIT_AVAILABLE 1
88 
89 /** Similar to daemon_pid_file_kill() but waits until the process
90  * died.  This functions is new in libdaemon 0.3. The macro
91  * DAEMON_PID_FILE_KILL_WAIT_AVAILABLE is defined iff libdaemon
92  * supports this function.
93  *
94  * @param s The signal to send
95  * @param m Seconds to wait at maximum
96  * @return zero on success, nonzero on failure (timeout condition is considered a failure)
97  * @since 0.3
98  * @see DAEMON_PID_FILE_KILL_WAIT_AVAILABLE
99  */
100 int daemon_pid_file_kill_wait(int s, int m);
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #endif
107