2006-02-27 Robert Love <rml@novell.com>

* 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.  Finally, always write out the pid file if
	  in daemon mode.  Use "--pid-file" to override the default.


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1509 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Robert Love
2006-02-27 20:06:24 +00:00
committed by Robert Love
parent 4fdea28f75
commit 598dda0255
4 changed files with 43 additions and 29 deletions

View File

@@ -3,7 +3,8 @@
* 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.
writing out the pid file. Finally, always write out the pid file if
in daemon mode. Use "--pid-file" to override the default.
2006-02-27 Robert Love <rml@novell.com>

View File

@@ -4,14 +4,15 @@ NULL=
sbin_PROGRAMS = NetworkManagerDispatcher
NetworkManagerDispatcher_CPPFLAGS = \
$(DBUS_CFLAGS) \
$(GTHREAD_CFLAGS) \
-Wall \
-DDBUS_API_SUBJECT_TO_CHANGE \
-DBINDIR=\"$(bindir)\" \
-DDATADIR=\"$(datadir)\" \
-DSYSCONFDIR=\"$(sysconfdir)\" \
NetworkManagerDispatcher_CPPFLAGS = \
$(DBUS_CFLAGS) \
$(GTHREAD_CFLAGS) \
-Wall \
-DDBUS_API_SUBJECT_TO_CHANGE \
-DBINDIR=\"$(bindir)\" \
-DDATADIR=\"$(datadir)\" \
-DSYSCONFDIR=\"$(sysconfdir)\" \
-DLOCALSTATEDIR=\"$(localstatedir)\" \
$(NULL)
NetworkManagerDispatcher_SOURCES = NetworkManagerDispatcher.c

View File

@@ -48,7 +48,9 @@ enum NMDAction
typedef enum NMDAction NMDAction;
#define NM_SCRIPT_DIR SYSCONFDIR"/NetworkManager/dispatcher.d"
#define NM_SCRIPT_DIR SYSCONFDIR"/NetworkManager/dispatcher.d"
#define NMD_DEFAULT_PID_FILE LOCALSTATEDIR"/run/NetworkManagerDispatcher.pid"
/*
@@ -309,6 +311,7 @@ int main (int argc, char *argv[])
GMainLoop * loop = NULL;
DBusConnection *connection = NULL;
char * pidfile = NULL;
char * user_pidfile = NULL;
/* Parse options */
while (1)
@@ -340,7 +343,7 @@ int main (int argc, char *argv[])
else if (strcmp (opt, "no-daemon") == 0)
become_daemon = FALSE;
else if (strcmp (opt, "pid-file") == 0)
pidfile = g_strdup (optarg);
user_pidfile = g_strdup (optarg);
else
{
nmd_print_usage ();
@@ -357,19 +360,22 @@ int main (int argc, char *argv[])
openlog("NetworkManagerDispatcher", (become_daemon) ? LOG_CONS : LOG_CONS | LOG_PERROR, (become_daemon) ? LOG_DAEMON : LOG_USER);
if (become_daemon && daemon (FALSE, FALSE) < 0)
if (become_daemon)
{
nm_warning ("NetworkManagerDispatcher could not daemonize: %s", strerror (errno));
exit (1);
if (daemon (FALSE, FALSE) < 0)
{
nm_warning ("NetworkManagerDispatcher could not daemonize: %s", strerror (errno));
exit (1);
}
pidfile = user_pidfile ? user_pidfile : NMD_DEFAULT_PID_FILE;
write_pidfile (pidfile);
}
g_type_init ();
if (!g_thread_supported ())
g_thread_init (NULL);
if (pidfile)
write_pidfile (pidfile);
/* Connect to the NetworkManager dbus service and run the main loop */
if ((connection = nmd_dbus_init ()))
{
@@ -380,7 +386,7 @@ int main (int argc, char *argv[])
/* Clean up pidfile */
if (pidfile)
unlink (pidfile);
g_free (pidfile);
g_free (user_pidfile);
return 0;
}

View File

@@ -53,6 +53,8 @@
#define NM_WIRELESS_LINK_STATE_POLL_INTERVAL (5 * 1000)
#define NM_DEFAULT_PID_FILE LOCALSTATEDIR"/run/NetworkManager.pid"
/*
* Globals
*/
@@ -717,6 +719,7 @@ int main( int argc, char *argv[] )
gboolean enable_test_devices = FALSE;
char * owner;
char * pidfile = NULL;
char * user_pidfile = NULL;
if (getuid () != 0)
{
@@ -757,7 +760,7 @@ int main( int argc, char *argv[] )
else if (strcmp (opt, "enable-test-devices") == 0)
enable_test_devices = TRUE;
else if (strcmp (opt, "pid-file") == 0)
pidfile = g_strdup (optarg);
user_pidfile = g_strdup (optarg);
break;
default:
@@ -767,14 +770,20 @@ int main( int argc, char *argv[] )
}
}
if (become_daemon && daemon (0, 0) < 0)
if (become_daemon)
{
int saved_errno;
if (daemon (0, 0) < 0)
{
int saved_errno;
saved_errno = errno;
nm_error ("NetworkManager could not daemonize: %s [error %u]",
g_strerror (saved_errno), saved_errno);
exit (EXIT_FAILURE);
saved_errno = errno;
nm_error ("NetworkManager could not daemonize: %s [error %u]",
g_strerror (saved_errno), saved_errno);
exit (EXIT_FAILURE);
}
pidfile = user_pidfile ? user_pidfile : NM_DEFAULT_PID_FILE;
write_pidfile (pidfile);
}
g_type_init ();
@@ -782,9 +791,6 @@ int main( int argc, char *argv[] )
g_thread_init (NULL);
dbus_g_thread_init ();
if (pidfile)
write_pidfile (pidfile);
nm_logging_setup (become_daemon);
nm_info ("starting...");
@@ -858,7 +864,7 @@ int main( int argc, char *argv[] )
/* Clean up pidfile */
if (pidfile)
unlink (pidfile);
g_free (pidfile);
g_free (user_pidfile);
exit (0);
}