diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-08-08 15:03:04 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-08-08 15:03:04 -0400 |
commit | 84c0c8b0ba7148f604ae205834ffed391389fdb0 (patch) | |
tree | 2798358f5e48815c71089bea65f4de28a78d5308 /gpsdctl.c | |
parent | bf0ff033c670bf6f54f5d6f3a55185a6a1ce4d64 (diff) | |
download | gpsd-84c0c8b0ba7148f604ae205834ffed391389fdb0.tar.gz |
Simplify and improve the C hotplug handler.
Hotplug tests pass. All regression tests pass. Codebase splints clean.
Diffstat (limited to 'gpsdctl.c')
-rw-r--r-- | gpsdctl.c | 13 |
1 files changed, 5 insertions, 8 deletions
@@ -27,16 +27,12 @@ static char *gpsd_options = ""; static int gpsd_control(char *action, char *argument) /* pass a command to gpsd; start the daemon if not already running */ { - int connect; + int connect = -1; char buf[512]; (void)syslog(LOG_ERR, "gpsd_control(action=%s, arg=%s)", action, argument); - if (access(control_socket, F_OK) != 0) { - (void)syslog(LOG_ERR, "socket %s doesn't exist", control_socket); - return -1; - } - connect = netlib_localsocket(control_socket, SOCK_STREAM); - if (connect >= 0) + if (access(control_socket, F_OK) == 0 && + (connect = netlib_localsocket(control_socket, SOCK_STREAM)) >= 0) syslog(LOG_INFO, "reached a running gpsd"); else if (strcmp(action, "add") == 0) { (void)snprintf(buf, sizeof(buf), @@ -46,7 +42,8 @@ static int gpsd_control(char *action, char *argument) (void)syslog(LOG_ERR, "launch of gpsd failed"); return -1; } - connect = netlib_localsocket(control_socket, SOCK_STREAM); + if (access(control_socket, F_OK) == 0) + connect = netlib_localsocket(control_socket, SOCK_STREAM); } if (connect < 0) { syslog(LOG_ERR, "can't reach gpsd"); |