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:
@@ -3,7 +3,8 @@
|
|||||||
* dispatcher-daemon/NetworkManagerDispatcher.c, src/NetworkManager.c:
|
* dispatcher-daemon/NetworkManagerDispatcher.c, src/NetworkManager.c:
|
||||||
Open the pid file O_TRUNC, so if it already exists we truncate it to
|
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
|
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>
|
2006-02-27 Robert Love <rml@novell.com>
|
||||||
|
|
||||||
|
@@ -12,6 +12,7 @@ NetworkManagerDispatcher_CPPFLAGS = \
|
|||||||
-DBINDIR=\"$(bindir)\" \
|
-DBINDIR=\"$(bindir)\" \
|
||||||
-DDATADIR=\"$(datadir)\" \
|
-DDATADIR=\"$(datadir)\" \
|
||||||
-DSYSCONFDIR=\"$(sysconfdir)\" \
|
-DSYSCONFDIR=\"$(sysconfdir)\" \
|
||||||
|
-DLOCALSTATEDIR=\"$(localstatedir)\" \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
NetworkManagerDispatcher_SOURCES = NetworkManagerDispatcher.c
|
NetworkManagerDispatcher_SOURCES = NetworkManagerDispatcher.c
|
||||||
|
@@ -50,6 +50,8 @@ 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"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nmd_permission_check
|
* nmd_permission_check
|
||||||
@@ -309,6 +311,7 @@ int main (int argc, char *argv[])
|
|||||||
GMainLoop * loop = NULL;
|
GMainLoop * loop = NULL;
|
||||||
DBusConnection *connection = NULL;
|
DBusConnection *connection = NULL;
|
||||||
char * pidfile = NULL;
|
char * pidfile = NULL;
|
||||||
|
char * user_pidfile = NULL;
|
||||||
|
|
||||||
/* Parse options */
|
/* Parse options */
|
||||||
while (1)
|
while (1)
|
||||||
@@ -340,7 +343,7 @@ int main (int argc, char *argv[])
|
|||||||
else if (strcmp (opt, "no-daemon") == 0)
|
else if (strcmp (opt, "no-daemon") == 0)
|
||||||
become_daemon = FALSE;
|
become_daemon = FALSE;
|
||||||
else if (strcmp (opt, "pid-file") == 0)
|
else if (strcmp (opt, "pid-file") == 0)
|
||||||
pidfile = g_strdup (optarg);
|
user_pidfile = g_strdup (optarg);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nmd_print_usage ();
|
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);
|
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)
|
||||||
|
{
|
||||||
|
if (daemon (FALSE, FALSE) < 0)
|
||||||
{
|
{
|
||||||
nm_warning ("NetworkManagerDispatcher could not daemonize: %s", strerror (errno));
|
nm_warning ("NetworkManagerDispatcher could not daemonize: %s", strerror (errno));
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pidfile = user_pidfile ? user_pidfile : NMD_DEFAULT_PID_FILE;
|
||||||
|
write_pidfile (pidfile);
|
||||||
|
}
|
||||||
|
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
if (!g_thread_supported ())
|
if (!g_thread_supported ())
|
||||||
g_thread_init (NULL);
|
g_thread_init (NULL);
|
||||||
|
|
||||||
if (pidfile)
|
|
||||||
write_pidfile (pidfile);
|
|
||||||
|
|
||||||
/* Connect to the NetworkManager dbus service and run the main loop */
|
/* Connect to the NetworkManager dbus service and run the main loop */
|
||||||
if ((connection = nmd_dbus_init ()))
|
if ((connection = nmd_dbus_init ()))
|
||||||
{
|
{
|
||||||
@@ -380,7 +386,7 @@ int main (int argc, char *argv[])
|
|||||||
/* Clean up pidfile */
|
/* Clean up pidfile */
|
||||||
if (pidfile)
|
if (pidfile)
|
||||||
unlink (pidfile);
|
unlink (pidfile);
|
||||||
g_free (pidfile);
|
g_free (user_pidfile);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -53,6 +53,8 @@
|
|||||||
|
|
||||||
#define NM_WIRELESS_LINK_STATE_POLL_INTERVAL (5 * 1000)
|
#define NM_WIRELESS_LINK_STATE_POLL_INTERVAL (5 * 1000)
|
||||||
|
|
||||||
|
#define NM_DEFAULT_PID_FILE LOCALSTATEDIR"/run/NetworkManager.pid"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Globals
|
* Globals
|
||||||
*/
|
*/
|
||||||
@@ -717,6 +719,7 @@ int main( int argc, char *argv[] )
|
|||||||
gboolean enable_test_devices = FALSE;
|
gboolean enable_test_devices = FALSE;
|
||||||
char * owner;
|
char * owner;
|
||||||
char * pidfile = NULL;
|
char * pidfile = NULL;
|
||||||
|
char * user_pidfile = NULL;
|
||||||
|
|
||||||
if (getuid () != 0)
|
if (getuid () != 0)
|
||||||
{
|
{
|
||||||
@@ -757,7 +760,7 @@ int main( int argc, char *argv[] )
|
|||||||
else if (strcmp (opt, "enable-test-devices") == 0)
|
else if (strcmp (opt, "enable-test-devices") == 0)
|
||||||
enable_test_devices = TRUE;
|
enable_test_devices = TRUE;
|
||||||
else if (strcmp (opt, "pid-file") == 0)
|
else if (strcmp (opt, "pid-file") == 0)
|
||||||
pidfile = g_strdup (optarg);
|
user_pidfile = g_strdup (optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -767,7 +770,9 @@ int main( int argc, char *argv[] )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (become_daemon && daemon (0, 0) < 0)
|
if (become_daemon)
|
||||||
|
{
|
||||||
|
if (daemon (0, 0) < 0)
|
||||||
{
|
{
|
||||||
int saved_errno;
|
int saved_errno;
|
||||||
|
|
||||||
@@ -777,14 +782,15 @@ int main( int argc, char *argv[] )
|
|||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pidfile = user_pidfile ? user_pidfile : NM_DEFAULT_PID_FILE;
|
||||||
|
write_pidfile (pidfile);
|
||||||
|
}
|
||||||
|
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
if (!g_thread_supported ())
|
if (!g_thread_supported ())
|
||||||
g_thread_init (NULL);
|
g_thread_init (NULL);
|
||||||
dbus_g_thread_init ();
|
dbus_g_thread_init ();
|
||||||
|
|
||||||
if (pidfile)
|
|
||||||
write_pidfile (pidfile);
|
|
||||||
|
|
||||||
nm_logging_setup (become_daemon);
|
nm_logging_setup (become_daemon);
|
||||||
nm_info ("starting...");
|
nm_info ("starting...");
|
||||||
|
|
||||||
@@ -858,7 +864,7 @@ int main( int argc, char *argv[] )
|
|||||||
/* Clean up pidfile */
|
/* Clean up pidfile */
|
||||||
if (pidfile)
|
if (pidfile)
|
||||||
unlink (pidfile);
|
unlink (pidfile);
|
||||||
g_free (pidfile);
|
g_free (user_pidfile);
|
||||||
|
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user