From 4fdea28f752555a4be6f2c47bbba8dc39aa928a9 Mon Sep 17 00:00:00 2001 From: Robert Love Date: Mon, 27 Feb 2006 20:00:25 +0000 Subject: [PATCH] 2006-02-27 Robert Love * dispatcher-daemon/NetworkManagerDispatcher.c, src/NetworkManager.c: Open the pid file O_TRUNC, so if it already exists we truncate it to zero length. Also, be more verbose about warnings generated during writing out the pid file. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1508 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 7 +++++ dispatcher-daemon/NetworkManagerDispatcher.c | 29 ++++++++++---------- src/NetworkManager.c | 29 ++++++++++---------- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 842cfb58e..f66571c1f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-02-27 Robert Love + + * dispatcher-daemon/NetworkManagerDispatcher.c, src/NetworkManager.c: + Open the pid file O_TRUNC, so if it already exists we truncate it to + zero length. Also, be more verbose about warnings generated during + writing out the pid file. + 2006-02-27 Robert Love Patch by R. Vinay : diff --git a/dispatcher-daemon/NetworkManagerDispatcher.c b/dispatcher-daemon/NetworkManagerDispatcher.c index 5a83e29b7..37491b806 100644 --- a/dispatcher-daemon/NetworkManagerDispatcher.c +++ b/dispatcher-daemon/NetworkManagerDispatcher.c @@ -280,19 +280,22 @@ static void nmd_print_usage (void) } -static gboolean +static void write_pidfile (const char *pidfile) { + char pid[16]; int fd; - int ignored; - char pid[16]; - - if ((fd = open (pidfile, O_CREAT | O_WRONLY, 00644)) < 0) - return FALSE; - snprintf (pid, sizeof (pid), "%d", getpid ()); - ignored = write (fd, pid, strlen (pid)); - close (fd); - return TRUE; + + if ((fd = open (pidfile, O_CREAT|O_WRONLY|O_TRUNC, 00644)) < 0) + { + nm_warning ("Opening %s failed: %s", pidfile, strerror (errno)); + return; + } + snprintf (pid, sizeof (pid), "%d", getpid ()); + if (write (fd, pid, strlen (pid)) < 0) + nm_warning ("Writing to %s failed: %s", pidfile, strerror (errno)); + if (close (fd)) + nm_warning ("Closing %s failed: %s", pidfile, strerror (errno)); } @@ -365,11 +368,7 @@ int main (int argc, char *argv[]) g_thread_init (NULL); if (pidfile) - { - if (!write_pidfile (pidfile)) - nm_warning ("Couldn't write pid file %s! errno: %s", pidfile, - strerror (errno)); - } + write_pidfile (pidfile); /* Connect to the NetworkManager dbus service and run the main loop */ if ((connection = nmd_dbus_init ())) diff --git a/src/NetworkManager.c b/src/NetworkManager.c index 92e0bffbc..c9a31139c 100644 --- a/src/NetworkManager.c +++ b/src/NetworkManager.c @@ -664,19 +664,22 @@ void nm_hal_deinit (NMData *data) } -static gboolean +static void write_pidfile (const char *pidfile) { + char pid[16]; int fd; - int ignored; - char pid[16]; - - if ((fd = open (pidfile, O_CREAT | O_WRONLY, 00644)) < 0) - return FALSE; - snprintf (pid, sizeof (pid), "%d", getpid ()); - ignored = write (fd, pid, strlen (pid)); - close (fd); - return TRUE; + + if ((fd = open (pidfile, O_CREAT|O_WRONLY|O_TRUNC, 00644)) < 0) + { + nm_warning ("Opening %s failed: %s", pidfile, strerror (errno)); + return; + } + snprintf (pid, sizeof (pid), "%d", getpid ()); + if (write (fd, pid, strlen (pid)) < 0) + nm_warning ("Writing to %s failed: %s", pidfile, strerror (errno)); + if (close (fd)) + nm_warning ("Closing %s failed: %s", pidfile, strerror (errno)); } @@ -780,11 +783,7 @@ int main( int argc, char *argv[] ) dbus_g_thread_init (); if (pidfile) - { - if (!write_pidfile (pidfile)) - nm_warning ("Couldn't write pid file %s! errno: %s", pidfile, - strerror (errno)); - } + write_pidfile (pidfile); nm_logging_setup (become_daemon); nm_info ("starting...");