From 4800bf1e4a3706b6829ccc875d040a64a8d17aad Mon Sep 17 00:00:00 2001 From: "S.Çağlar Onur" Date: Tue, 13 Feb 2007 07:03:50 -0500 Subject: create and delete pid file While try to play with ConsoleKit i realize it cannot create its pid file, so if needed attached patch adds that with copy/paste from PolicyKit :). --- src/main.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 0856e85..461318e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- * - * Copyright (C) 2006 William Jon McCann + * Copyright (C) 2006-2007 William Jon McCann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include #include #include @@ -172,6 +175,12 @@ bus_proxy_destroyed_cb (DBusGProxy *bus_proxy, g_timeout_add (3000, (GSourceFunc)bus_reconnect, manager); } +static void +delete_pid (void) +{ + unlink (CONSOLE_KIT_PID_FILE); +} + int main (int argc, char **argv) @@ -182,6 +191,9 @@ main (int argc, DBusGProxy *bus_proxy; DBusGConnection *connection; int ret; + int pf; + ssize_t written; + char pid[9]; static gboolean debug = FALSE; static gboolean no_daemon = FALSE; @@ -224,6 +236,17 @@ main (int argc, g_error ("Could not daemonize: %s", g_strerror (errno)); } + /* remove old pid file */ + unlink (CONSOLE_KIT_PID_FILE); + + /* make a new pid file */ + if ((pf = open (CONSOLE_KIT_PID_FILE, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644)) > 0) { + snprintf (pid, sizeof (pid), "%lu\n", (long unsigned) getpid ()); + written = write (pf, pid, strlen (pid)); + close (pf); + g_atexit (delete_pid); + } + manager = ck_manager_new (); if (manager == NULL) { -- cgit