}
ply_daemon_handle_t *
-ply_create_daemon (const char *pid_file)
+ply_create_daemon (void)
{
pid_t pid;
int sender_fd, receiver_fd;
_exit (1);
}
- if ((byte == 0) && (pid_file != NULL))
- {
- FILE *pidf;
-
- pidf = fopen (pid_file, "w");
- if (!pidf)
- {
- ply_error ("could not write pid file %s: %m", pid_file);
- }
- else
- {
- fprintf (pidf, "%d\n", (int)pid);
- fclose (pidf);
- }
- }
-
_exit ((int) byte);
}
close (receiver_fd);
const char *destination);
void ply_show_new_kernel_messages (bool should_show);
-ply_daemon_handle_t *ply_create_daemon (const char *pid_file);
+ply_daemon_handle_t *ply_create_daemon (void);
bool ply_detach_daemon (ply_daemon_handle_t *handle,
int exit_code);
raise(signum);
}
+static void
+write_pid_file (const char *filename)
+{
+ FILE *fp;
+
+ fp = fopen (filename, "w");
+ if (fp == NULL)
+ {
+ ply_error ("could not write pid file %s: %m", filename);
+ }
+ else
+ {
+ fprintf (fp, "%d\n", (int) getpid ());
+ fclose (fp);
+ }
+}
+
int
main (int argc,
char **argv)
if (! no_daemon)
{
- daemon_handle = ply_create_daemon (pid_file);
+ daemon_handle = ply_create_daemon ();
if (daemon_handle == NULL)
{
return EX_UNAVAILABLE;
}
+ if (pid_file != NULL)
+ write_pid_file (pid_file);
+
if (daemon_handle != NULL
&& !ply_detach_daemon (daemon_handle, 0))
{