1
/* NetworkManager -- Network link manager
3
* Dan Williams <dcbw@redhat.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
* (C) Copyright 2004 Red Hat, Inc.
24
#include <sys/types.h>
25
#include <sys/socket.h>
27
#include "NetworkManager.h"
28
#include "NetworkManagerUtils.h"
30
extern gboolean debug;
34
* nm_try_acquire_mutex
36
* Tries to acquire a given mutex, sleeping a bit between tries.
38
* Returns: FALSE if mutex was not acquired
39
* TRUE if mutex was successfully acquired
41
gboolean nm_try_acquire_mutex (GMutex *mutex, const char *func)
45
g_return_val_if_fail (mutex != NULL, FALSE);
49
if (g_mutex_trylock (mutex))
53
NM_DEBUG_PRINT_1 ("MUTEX: %s got mutex\n", func);
68
* Simply unlocks a mutex, balances nm_try_acquire_mutex()
71
void nm_unlock_mutex (GMutex *mutex, const char *func)
73
g_return_if_fail (mutex != NULL);
77
NM_DEBUG_PRINT_1 ("MUTEX: %s released mutex\n", func);
79
g_mutex_unlock (mutex);
86
* Doesn't freaking segfault if s1/s2 are NULL
89
int nm_null_safe_strcmp (const char *s1, const char *s2)
98
return (strcmp (s1, s2));
104
* nm_get_network_control_socket
106
* Get a control socket for network operations.
109
int nm_get_network_control_socket (void)
113
/* Try to grab a control socket */
114
fd = socket(PF_INET, SOCK_DGRAM, 0);
117
fd = socket(PF_PACKET, SOCK_DGRAM, 0);
120
fd = socket(PF_INET6, SOCK_DGRAM, 0);
124
NM_DEBUG_PRINT ("nm_get_network_control_socket() could not get network control socket.\n");
131
* nm_dispose_scan_results
133
* Free memory used by the wireless scan results structure
136
void nm_dispose_scan_results (wireless_scan *result_list)
138
wireless_scan *tmp = result_list;
142
wireless_scan *tmp2 = tmp;