+/*
+ * Check to see if our server really works. Returns 0 on success.
+ */
+int test_server(void) {
+ char cmd[256];
+ char cookie[256];
+ FILE *fp;
+ char buf[4096];
+ int found_it = 0;
+
+ /* Generate a silly little cookie. We're going to write it out
+ * to the server and try to get it back. The cookie does not
+ * have to be secret ... just unique.
+ */
+ sprintf(cookie, "%ld.%d", time(NULL), getpid());
+
+ sprintf(cmd, "%s/sendcommand -h%s ECHO %s 2>&1",
+ setup_directory,
+ setup_directory,
+ cookie);
+
+ fp = popen(cmd, "r");
+ if (fp == NULL) return(errno);
+
+ while (fgets(buf, sizeof buf, fp) != NULL) {
+ if ( (buf[0]=='2')
+ && (strstr(buf, cookie) != NULL) ) {
+ ++found_it;
+ }
+ }
+ pclose(fp);
+
+ if (found_it) {
+ return(0);
+ }
+ return(-1);
+}
+
+
+
+
+
+