66
66
#define PHY_DELAY_MB_TX_I20 1044 // 100M delay
67
67
#define PHY_DELAY_MB_RX_I20 2133 // 100M delay
68
68
69
+ #define CLEANUP ()\
70
+ do { \
71
+ delete pPort; \
72
+ delete pClock; \
73
+ delete ifname; \
74
+ delete timestamper; \
75
+ delete ipc; \
76
+ delete condition_factory; \
77
+ delete timer_factory; \
78
+ delete lock_factory; \
79
+ delete timerq_factory; \
80
+ delete default_factory; \
81
+ delete thread_factory; \
82
+ delete watchdog; \
83
+ GPTP_LOG_INFO (" Clean up" ); \
84
+ GPTP_LOG_UNREGISTER (); \
85
+ } while (0 )
86
+
69
87
void gPTPPersistWriteCB (char *bufPtr, uint32_t bufSize);
70
88
71
89
void print_usage ( char *arg0 ) {
@@ -108,7 +126,7 @@ int main(int argc, char **argv)
108
126
PortInit_t portInit;
109
127
110
128
sigset_t set;
111
- InterfaceName *ifname;
129
+ InterfaceName *ifname = NULL ;
112
130
int sig;
113
131
114
132
bool syntonize = false ;
@@ -183,19 +201,26 @@ int main(int argc, char **argv)
183
201
portInit.neighborPropDelayThreshold =
184
202
CommonPort::NEIGHBOR_PROP_DELAY_THRESH;
185
203
186
- LinuxNetworkInterfaceFactory *default_factory =
187
- new LinuxNetworkInterfaceFactory;
204
+ LinuxNetworkInterfaceFactory *default_factory = new LinuxNetworkInterfaceFactory;
188
205
OSNetworkInterfaceFactory::registerFactory
189
206
(factory_name_t (" default" ), default_factory);
190
207
LinuxTimerQueueFactory *timerq_factory = new LinuxTimerQueueFactory ();
191
208
LinuxLockFactory *lock_factory = new LinuxLockFactory ();
192
209
LinuxTimerFactory *timer_factory = new LinuxTimerFactory ();
193
210
LinuxConditionFactory *condition_factory = new LinuxConditionFactory ();
194
211
LinuxSharedMemoryIPC *ipc = new LinuxSharedMemoryIPC ();
212
+
213
+ #ifdef ARCH_INTELCE
214
+ EtherTimestamper *timestamper = new LinuxTimestamperIntelCE ();
215
+ #else
216
+ EtherTimestamper *timestamper = new LinuxTimestamperGeneric ();
217
+ #endif
218
+
195
219
/* Create Low level network interface object */
196
220
if ( argc < 2 ) {
197
- printf ( " Interface name required\n " );
221
+ GPTP_LOG_ERROR ( " Interface name required" );
198
222
print_usage ( argv[0 ] );
223
+ CLEANUP ();
199
224
return -1 ;
200
225
}
201
226
ifname = new InterfaceName ( argv[1 ], strlen (argv[1 ]) );
@@ -241,7 +266,7 @@ int main(int argc, char **argv)
241
266
}
242
267
else if ( strcmp (argv[i] + 1 , " H" ) == 0 ) {
243
268
print_usage ( argv[0 ] );
244
- GPTP_LOG_UNREGISTER ();
269
+ CLEANUP ();
245
270
return 0 ;
246
271
}
247
272
else if ( strcmp (argv[i] + 1 , " R" ) == 0 ) {
@@ -269,7 +294,7 @@ int main(int argc, char **argv)
269
294
{
270
295
printf (" Too many values\n " );
271
296
print_usage ( argv[0 ] );
272
- GPTP_LOG_UNREGISTER ();
297
+ CLEANUP ();
273
298
return 0 ;
274
299
}
275
300
phy_delay[delay_count]=atoi (cli_inp_delay);
@@ -280,7 +305,7 @@ int main(int argc, char **argv)
280
305
{
281
306
printf (" All four delay values must be specified\n " );
282
307
print_usage ( argv[0 ] );
283
- GPTP_LOG_UNREGISTER ();
308
+ CLEANUP ();
284
309
return 0 ;
285
310
}
286
311
ether_phy_delay[LINKSPEED_1G].set_delay
@@ -348,11 +373,6 @@ int main(int argc, char **argv)
348
373
restoredataptr = (char *)restoredata;
349
374
}
350
375
351
- #ifdef ARCH_INTELCE
352
- EtherTimestamper *timestamper = new LinuxTimestamperIntelCE ();
353
- #else
354
- EtherTimestamper *timestamper = new LinuxTimestamperGeneric ();
355
- #endif
356
376
357
377
sigemptyset (&set);
358
378
sigaddset (&set, SIGINT);
@@ -361,7 +381,7 @@ int main(int argc, char **argv)
361
381
sigaddset (&set, SIGUSR2);
362
382
if (pthread_sigmask (SIG_BLOCK, &set, NULL ) != 0 ) {
363
383
perror (" pthread_sigmask()" );
364
- GPTP_LOG_UNREGISTER ();
384
+ CLEANUP ();
365
385
return -1 ;
366
386
}
367
387
@@ -431,7 +451,7 @@ int main(int argc, char **argv)
431
451
432
452
if (!pPort->init_port ()) {
433
453
GPTP_LOG_ERROR (" failed to initialize port" );
434
- GPTP_LOG_UNREGISTER ();
454
+ CLEANUP ();
435
455
return -1 ;
436
456
}
437
457
@@ -484,7 +504,7 @@ int main(int argc, char **argv)
484
504
485
505
if (sigwait (&set, &sig) != 0 ) {
486
506
perror (" sigwait()" );
487
- GPTP_LOG_UNREGISTER ();
507
+ CLEANUP ();
488
508
return -1 ;
489
509
}
490
510
@@ -522,9 +542,7 @@ int main(int argc, char **argv)
522
542
pPort->joinLinkWatchThread (linkExitCode);
523
543
GPTP_LOG_INFO (" All threads terminated" );
524
544
525
- if ( ipc ) delete ipc;
526
-
527
- GPTP_LOG_UNREGISTER ();
545
+ CLEANUP ();
528
546
return 0 ;
529
547
}
530
548
0 commit comments