diff --git a/extra/service/legiond/legiond-ctl.c b/extra/service/legiond/legiond-ctl.c index dde0226..60048c2 100644 --- a/extra/service/legiond/legiond-ctl.c +++ b/extra/service/legiond/legiond-ctl.c @@ -7,15 +7,6 @@ int main(int argc, char *argv[]) exit(1); } - // init socket - int fd = socket(AF_UNIX, SOCK_STREAM, 0); - struct sockaddr_un addr; - addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, socket_path); - int ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr)); - if (ret == -1) { - exit(-1); - } char request[20] = ""; if (argc > 1) { @@ -32,8 +23,25 @@ int main(int argc, char *argv[]) sprintf(request, "B"); // B means cpuset } else if (strcmp(argv[1], "reload") == 0) { sprintf(request, "R"); // R means reload config + } else { + printf("unknown arguments\n"); + exit(1); } } - send(fd, request, strlen(request), 0); + + // init socket + int fd = socket(AF_UNIX, SOCK_STREAM, 0); + struct sockaddr_un addr; + addr.sun_family = AF_UNIX; + strcpy(addr.sun_path, socket_path); + + if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + exit(2); + } + + if (send(fd, request, strlen(request), 0) != -1) { + printf("successfully sent cmd\n"); + } + close(fd); } diff --git a/extra/service/legiond/legiond.c b/extra/service/legiond/legiond.c index 590f6c7..0d2e750 100644 --- a/extra/service/legiond/legiond.c +++ b/extra/service/legiond/legiond.c @@ -76,9 +76,8 @@ int main() struct sockaddr_un addr; addr.sun_family = AF_UNIX; strcpy(addr.sun_path, socket_path); - int ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); - if (ret == -1) { + if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { exit(1); }