|
Lines 17-22
Link Here
|
| 17 |
static int sane(const char *); |
17 |
static int sane(const char *); |
| 18 |
static int wildmatch(const char *, const char *); |
18 |
static int wildmatch(const char *, const char *); |
| 19 |
|
19 |
|
|
|
20 |
static struct conn * the_connection; |
| 21 |
|
| 22 |
int |
| 23 |
rsm_connect(void) |
| 24 |
{ |
| 25 |
if (the_connection) |
| 26 |
rsm_disconnect(); |
| 27 |
the_connection = rsm_connect_to(_PATH_RESMGR_SOCKET); |
| 28 |
return the_connection? 0 : -1; |
| 29 |
} |
| 30 |
|
| 31 |
int |
| 32 |
rsm_disconnect(void) |
| 33 |
{ |
| 34 |
if (the_connection) { |
| 35 |
rsm_close(the_connection); |
| 36 |
the_connection = NULL; |
| 37 |
} |
| 38 |
return 0; |
| 39 |
} |
| 20 |
|
40 |
|
| 21 |
static int |
41 |
static int |
| 22 |
rsm_command(int *code, const char *fmt, ...) |
42 |
rsm_command(int *code, const char *fmt, ...) |
|
Lines 30-37
Link Here
|
| 30 |
*code = 0; |
50 |
*code = 0; |
| 31 |
|
51 |
|
| 32 |
va_start(ap, fmt); |
52 |
va_start(ap, fmt); |
| 33 |
if (!(conn = rsm_connect(_PATH_RESMGR_SOCKET)) |
53 |
|
| 34 |
|| rsm_vprintf(conn, fmt, ap) < 0 |
54 |
if (!(conn = the_connection) |
|
|
55 |
&& !(conn = rsm_connect_to(_PATH_RESMGR_SOCKET))) { |
| 56 |
syslog(LOG_NOTICE, "resmgr: unable to connect to resmgrd: %m"); |
| 57 |
goto out; |
| 58 |
} |
| 59 |
|
| 60 |
if (rsm_vprintf(conn, fmt, ap) < 0 |
| 35 |
|| (*code = rsm_recv_response(conn)) < 0) { |
61 |
|| (*code = rsm_recv_response(conn)) < 0) { |
| 36 |
syslog(LOG_NOTICE, "resmgr: communication failure: %m"); |
62 |
syslog(LOG_NOTICE, "resmgr: communication failure: %m"); |
| 37 |
goto out; |
63 |
goto out; |
|
Lines 45-51
Link Here
|
| 45 |
else |
71 |
else |
| 46 |
fd = 0; |
72 |
fd = 0; |
| 47 |
|
73 |
|
| 48 |
out: rsm_close(conn); |
74 |
out: if (conn != the_connection) |
|
|
75 |
rsm_close(conn); |
| 49 |
va_end(ap); |
76 |
va_end(ap); |
| 50 |
return fd; |
77 |
return fd; |
| 51 |
} |
78 |
} |
|
Lines 138-144
Link Here
|
| 138 |
wildcard = s; |
165 |
wildcard = s; |
| 139 |
} |
166 |
} |
| 140 |
|
167 |
|
| 141 |
if ((conn = rsm_connect(_PATH_RESMGR_SOCKET)) |
168 |
if ((conn = rsm_connect_to(_PATH_RESMGR_SOCKET)) |
| 142 |
&& rsm_printf(conn, "list %s", family) >= 0) |
169 |
&& rsm_printf(conn, "list %s", family) >= 0) |
| 143 |
result = rsm_recv_multiline(conn, rsm_frob_device, wildcard); |
170 |
result = rsm_recv_multiline(conn, rsm_frob_device, wildcard); |
| 144 |
|
171 |
|
|
Lines 152-158
Link Here
|
| 152 |
struct conn *conn; |
179 |
struct conn *conn; |
| 153 |
char **result = NULL; |
180 |
char **result = NULL; |
| 154 |
|
181 |
|
| 155 |
if ((conn = rsm_connect(_PATH_RESMGR_SOCKET)) |
182 |
if ((conn = rsm_connect_to(_PATH_RESMGR_SOCKET)) |
| 156 |
&& rsm_printf(conn, "sessions") >= 0) |
183 |
&& rsm_printf(conn, "sessions") >= 0) |
| 157 |
result = rsm_recv_multiline(conn, NULL, NULL); |
184 |
result = rsm_recv_multiline(conn, NULL, NULL); |
| 158 |
|
185 |
|
|
Lines 204-209
Link Here
|
| 204 |
rsm_open_device(const char *pathname, int flags) |
231 |
rsm_open_device(const char *pathname, int flags) |
| 205 |
{ |
232 |
{ |
| 206 |
return rsm_open_device_as(NULL, pathname, flags); |
233 |
return rsm_open_device_as(NULL, pathname, flags); |
|
|
234 |
} |
| 235 |
|
| 236 |
int |
| 237 |
rsm_open_socket(const char *pathname) |
| 238 |
{ |
| 239 |
return rsm_open_device_as("socket", pathname, O_RDWR); |
| 207 |
} |
240 |
} |
| 208 |
|
241 |
|
| 209 |
|
242 |
|