+static void logcontrol(int fd, FILE *out, int level) {
+ sendline(fd, "%d %d %d", CONTROL, REQ_LOG, level);
+ char data[1024];
+ char line[32];
+
+ while(recvline(fd, line, sizeof line)) {
+ int code, req, len;
+ int n = sscanf(line, "%d %d %d", &code, &req, &len);
+ if(n != 3 || code != CONTROL || req != REQ_LOG || len < 0 || len > sizeof data)
+ break;
+ if(!recvdata(fd, data, len))
+ break;
+ fwrite(data, len, 1, out);
+ fputc('\n', out);
+ fflush(out);
+ }
+}
+
+#ifdef HAVE_MINGW
+static bool remove_service(void) {
+ SC_HANDLE manager = NULL;
+ SC_HANDLE service = NULL;
+ SERVICE_STATUS status = {0};
+
+ manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+ if(!manager) {
+ fprintf(stderr, "Could not open service manager: %s\n", winerror(GetLastError()));
+ return false;
+ }
+
+ service = OpenService(manager, identname, SERVICE_ALL_ACCESS);
+
+ if(!service) {
+ fprintf(stderr, "Could not open %s service: %s\n", identname, winerror(GetLastError()));
+ return false;
+ }
+
+ if(!ControlService(service, SERVICE_CONTROL_STOP, &status))
+ fprintf(stderr, "Could not stop %s service: %s\n", identname, winerror(GetLastError()));
+ else
+ fprintf(stderr, "%s service stopped\n", identname);
+
+ if(!DeleteService(service)) {
+ fprintf(stderr, "Could not remove %s service: %s\n", identname, winerror(GetLastError()));
+ return false;
+ }
+
+ fprintf(stderr, "%s service removed\n", identname);
+
+ return true;
+}
+#endif
+
+int main(int argc, char *argv[]) {