From 84c0c8b0ba7148f604ae205834ffed391389fdb0 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 8 Aug 2011 15:03:04 -0400 Subject: Simplify and improve the C hotplug handler. Hotplug tests pass. All regression tests pass. Codebase splints clean. --- gpsdctl.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'gpsdctl.c') diff --git a/gpsdctl.c b/gpsdctl.c index 5b943c57..59214bfb 100644 --- a/gpsdctl.c +++ b/gpsdctl.c @@ -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"); -- cgit v1.2.1