mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-09-06 17:14:02 +00:00
2008-04-24 Dan Williams <dcbw@redhat.com>
* dispatcher-daemon/NetworkManagerDispatcher.c - (nmd_execute_scripts): execute scripts in order as sorted by strcmp() git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3593 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
aa6a160443
commit
f774d202a8
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2008-04-24 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* dispatcher-daemon/NetworkManagerDispatcher.c
|
||||
- (nmd_execute_scripts): execute scripts in order as sorted by strcmp()
|
||||
|
||||
2008-04-24 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* initscript/RedHat/NetworkManager.in
|
||||
initscript/RedHat/NetworkManagerDispatcher.in
|
||||
- Be active at runlevel 2
|
||||
- Adjust priorities earlier
|
||||
|
||||
2008-04-22 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* src/NetworkManagerPolicy.c
|
||||
|
|
|
@ -102,6 +102,28 @@ nmd_is_valid_filename (const char *file_name)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_files (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
char *a_base = NULL, *b_base = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if (a && !b)
|
||||
return 1;
|
||||
if (!a && !b)
|
||||
return 0;
|
||||
if (!a && b)
|
||||
return -1;
|
||||
|
||||
a_base = g_path_get_basename (a);
|
||||
b_base = g_path_get_basename (b);
|
||||
|
||||
ret = strcmp (a_base, b_base);
|
||||
|
||||
g_free (a_base);
|
||||
g_free (b_base);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* nmd_execute_scripts
|
||||
|
@ -113,48 +135,51 @@ static void
|
|||
nmd_execute_scripts (NMDeviceState state, const char *iface_name)
|
||||
{
|
||||
GDir *dir;
|
||||
const char * file_name;
|
||||
const char * char_act;
|
||||
const char *filename;
|
||||
char *act = NULL;
|
||||
GSList *scripts = NULL, *iter;
|
||||
GError *error = NULL;
|
||||
|
||||
if (state == NM_DEVICE_STATE_ACTIVATED)
|
||||
char_act = "up";
|
||||
act = "up";
|
||||
else if (state == NM_DEVICE_STATE_DISCONNECTED)
|
||||
char_act = "down";
|
||||
act = "down";
|
||||
else
|
||||
return;
|
||||
|
||||
nm_info ("Device %s is now %s.", iface_name, char_act);
|
||||
nm_info ("Device %s is now %s.", iface_name, act);
|
||||
|
||||
if (!(dir = g_dir_open (NM_SCRIPT_DIR, 0, NULL)))
|
||||
{
|
||||
nm_warning ("nmd_execute_scripts(): opendir() could not open '" NM_SCRIPT_DIR "'. errno = %d", errno);
|
||||
if (!(dir = g_dir_open (NM_SCRIPT_DIR, 0, &error))) {
|
||||
nm_warning ("g_dir_open() could not open '" NM_SCRIPT_DIR "'. '%s'",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
while ((file_name = g_dir_read_name (dir)))
|
||||
{
|
||||
char *file_path = g_build_filename (NM_SCRIPT_DIR, file_name, NULL);
|
||||
while ((filename = g_dir_read_name (dir))) {
|
||||
char *file_path = g_build_filename (NM_SCRIPT_DIR, filename, NULL);
|
||||
struct stat s;
|
||||
|
||||
if (nmd_is_valid_filename(file_name) && (stat (file_path, &s) == 0))
|
||||
{
|
||||
if (nmd_permission_check (&s))
|
||||
{
|
||||
if (nmd_is_valid_filename(filename) && !stat (file_path, &s) && nmd_permission_check (&s))
|
||||
scripts = g_slist_insert_sorted (scripts, file_path, sort_files);
|
||||
else
|
||||
g_free (file_path);
|
||||
}
|
||||
g_dir_close (dir);
|
||||
|
||||
for (iter = scripts; iter; iter = g_slist_next (iter)) {
|
||||
char *cmd;
|
||||
int ret;
|
||||
|
||||
cmd = g_strdup_printf ("%s %s %s", file_path, iface_name, char_act);
|
||||
cmd = g_strdup_printf ("%s %s %s", (char *) iter->data, iface_name, act);
|
||||
ret = system (cmd);
|
||||
if (ret == -1)
|
||||
nm_warning ("nmd_execute_scripts(): system() failed with errno = %d", errno);
|
||||
nm_warning ("system() failed with errno = %d", errno);
|
||||
g_free (cmd);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (file_path);
|
||||
}
|
||||
|
||||
g_dir_close (dir);
|
||||
g_slist_foreach (scripts, (GFunc) g_free, NULL);
|
||||
g_slist_free (scripts);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue