1
1
2
- /*
2
+ /*
3
3
* rename_device.c: udev helper to rename ethernet devices.
4
4
*
5
5
* Copyright (C) 2006-2009 Red Hat, Inc. All rights reserved.
9
9
* GNU General Public License v.2.
10
10
*
11
11
* This program is distributed in the hope that it will be useful, but WITHOUT
12
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
14
* more details.
15
15
*
16
16
* You should have received a copy of the GNU General Public License along
@@ -64,7 +64,7 @@ struct tmp *tmplist = NULL;
64
64
#if defined(__s390__ ) || defined(__s390x__ )
65
65
static int is_cdev (const struct dirent * dent ) {
66
66
char * end = NULL ;
67
-
67
+
68
68
if (strncmp (dent -> d_name ,"cdev" ,4 ))
69
69
return 0 ;
70
70
strtoul (dent -> d_name + 4 ,& end , 10 );
@@ -75,7 +75,7 @@ static int is_cdev(const struct dirent *dent) {
75
75
76
76
static inline char * getdev (char * path , char * ent ) {
77
77
char * a , * b , * ret ;
78
-
78
+
79
79
asprintf (& a ,"%s/%s" ,path ,ent );
80
80
b = canonicalize_file_name (a );
81
81
ret = strdup (basename (b ));
@@ -88,13 +88,13 @@ char *read_subchannels(char *path) {
88
88
char * tmp , * ret ;
89
89
int n , x ;
90
90
struct dirent * * cdevs ;
91
-
91
+
92
92
if ((n = scandir (path , & cdevs , is_cdev , alphasort )) <= 0 )
93
93
return NULL ;
94
-
94
+
95
95
ret = getdev (path ,cdevs [0 ]-> d_name );
96
- for (x = 1 ; x < n ; x ++ ) {
97
- if (asprintf (& tmp , "%s,%s" , ret , getdev (path , cdevs [x ]-> d_name )) == -1 )
96
+ for (x = 1 ; x < n ; x ++ ) {
97
+ if (asprintf (& tmp , "%s,%s" , ret , getdev (path , cdevs [x ]-> d_name )) == -1 )
98
98
return NULL ;
99
99
free (ret );
100
100
ret = tmp ;
@@ -172,9 +172,9 @@ struct netdev *get_configs() {
172
172
struct netdev * ret , * tmpdev ;
173
173
struct dirent * * cfgs ;
174
174
int x ;
175
-
175
+
176
176
ret = NULL ;
177
-
177
+
178
178
if ((ncfgs = scandir ("/etc/sysconfig/network-scripts" ,& cfgs ,
179
179
isCfg , alphasort )) == -1 ) {
180
180
return ret ;
@@ -185,7 +185,7 @@ struct netdev *get_configs() {
185
185
int vlan ;
186
186
gchar * contents , * * lines ;
187
187
int i ;
188
-
188
+
189
189
devname = hwaddr = contents = NULL ;
190
190
lines = NULL ;
191
191
vlan = 0 ;
@@ -235,7 +235,7 @@ struct netdev *get_configs() {
235
235
free (cfgs );
236
236
return ret ;
237
237
}
238
-
238
+
239
239
char * get_hwaddr (char * device ) {
240
240
char * path = NULL ;
241
241
char * contents = NULL ;
@@ -260,13 +260,13 @@ char *get_hwaddr(char *device) {
260
260
261
261
return g_strstrip (contents );
262
262
}
263
-
263
+
264
264
char * get_config_by_hwaddr (char * hwaddr , char * current ) {
265
265
struct netdev * config ;
266
266
char * first = NULL ;
267
-
267
+
268
268
if (!hwaddr ) return NULL ;
269
-
269
+
270
270
for (config = configs ; config ; config = config -> next ) {
271
271
if (strcasecmp (config -> hwaddr , hwaddr ) != 0 )
272
272
continue ;
@@ -322,7 +322,7 @@ void take_lock() {
322
322
int count = 0 ;
323
323
int lockfd ;
324
324
ssize_t ignored_retval __attribute__((unused ));
325
-
325
+
326
326
while (1 ) {
327
327
lockfd = open (LOCKFILE , O_RDWR |O_CREAT |O_EXCL , 0644 );
328
328
if (lockfd != -1 ) {
@@ -341,7 +341,7 @@ void take_lock() {
341
341
int fd ;
342
342
char buf [32 ];
343
343
int pid ;
344
-
344
+
345
345
fd = open (LOCKFILE , O_RDONLY );
346
346
if (fd == -1 )
347
347
break ;
@@ -364,16 +364,16 @@ int main(int argc, char **argv) {
364
364
struct timeval tv ;
365
365
366
366
gettimeofday (& tv , NULL );
367
- srand (tv .tv_usec );
367
+ srand (tv .tv_usec );
368
368
take_lock ();
369
-
369
+
370
370
signal (SIGSEGV ,sighandler );
371
371
signal (SIGKILL ,sighandler );
372
372
signal (SIGTERM ,sighandler );
373
373
signal (SIGSEGV ,sighandler );
374
374
signal (SIGALRM ,sighandler );
375
375
alarm (10 );
376
-
376
+
377
377
src = getenv ("INTERFACE" );
378
378
if (!src )
379
379
goto out_unlock ;
@@ -390,7 +390,7 @@ int main(int argc, char **argv) {
390
390
goto out_unlock ;
391
391
392
392
printf ("%s" , target );
393
-
393
+
394
394
out_unlock :
395
395
unlink (LOCKFILE );
396
396
exit (0 );
0 commit comments