File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change 2222
2323#include <limits.h>
2424#include <sys/ioctl.h>
25+ #include <signal.h>
26+ #include <errno.h>
2527#include <arpa/telnet.h>
2628
2729#include "microcom.h"
@@ -178,15 +180,18 @@ struct ios_ops * serial_init(char *device)
178180 }
179181
180182 fd = open (lockfile , O_RDONLY );
181- if (fd >= 0 && !opt_force ) {
183+ if (fd >= 0 ) {
184+ read (fd , & pid , sizeof (long ));
182185 close (fd );
183- main_usage (3 , "lockfile for port exists" , device );
184- }
185-
186- if (fd >= 0 && opt_force ) {
187- close (fd );
188- printf ("lockfile for port exists, ignoring\n" );
189- serial_unlock ();
186+ if (kill (pid , 0 ) < 0 && errno == ESRCH ) {
187+ printf ("lockfile contains stale pid, ignoring\n" );
188+ serial_unlock ();
189+ } else if (opt_force ) {
190+ printf ("lockfile for port exists, ignoring\n" );
191+ serial_unlock ();
192+ } else {
193+ main_usage (3 , "lockfile for port exists" , device );
194+ }
190195 }
191196
192197 fd = open (lockfile , O_RDWR | O_CREAT , 0444 );
You can’t perform that action at this time.
0 commit comments