-void np_attach_to_server(void)
-{
- char hostbuf[SIZ], portbuf[SIZ];
- char buf[SIZ];
- char *args[] =
- {"sendcommand", NULL};
- int r;
-
- strcpy(hostbuf, UDS); /* Only run on a unix domain socket */
- strcpy(portbuf, "."); /* IPGM will refuse to run on the network */
- fprintf(stderr, "Attaching to server...\n");
- ipc = CtdlIPC_new(1, args, hostbuf, portbuf);
- CtdlIPC_getline(ipc, buf);
- fprintf(stderr, "%s\n", &buf[4]);
- snprintf(buf, sizeof buf, "IPGM %d", config.c_ipgm_secret);
- r = CtdlIPCInternalProgram(ipc, config.c_ipgm_secret, buf);
- fprintf(stderr, "%s\n", buf);
- if (r / 100 != 2) {
- cleanup(2);
+void serv_gets(char *buf) {
+ int i;
+
+ /* Read one character at a time.
+ */
+ for (i = 0;; i++) {
+ serv_read(&buf[i], 1);
+ if (buf[i] == '\n' || i == (SIZ-1))
+ break;
+ }
+
+ /* If we got a long line, discard characters until the newline.
+ */
+ if (i == (SIZ-1)) {
+ while (buf[i] != '\n') {
+ serv_read(&buf[i], 1);
+ }