#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
+#include <signal.h>
+#include <time.h>
#ifdef IGNORE_SOME_GCC_WARNINGS
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
return 0;
}
+/*
+ * Primitive replacement for using sigtimedwait(). Just see if 'signo' is
+ * pending, and if it's not, wait 100ms and try again. Try this for
+ * approximately as many times as it takes to wait for 'nsecs' seconds.
+ */
+static int
+waitforsig(int signo, int nsecs)
+{
+ int nsleeps;
+
+ for (nsleeps = 0; nsleeps < nsecs * 10; nsleeps++) {
+ sigset_t set;
+ struct timespec timeo;
+
+ opr_Verify(sigpending(&set) == 0);
+ if (sigismember(&set, signo)) {
+ return 0;
+ }
+
+ /* Sleep for 100ms */
+ timeo.tv_sec = 0;
+ timeo.tv_nsec = 100 * 1000 * 1000;
+ opr_Verify(nanosleep(&timeo, NULL) == 0);
+ }
+
+ return -1;
+}
+
int main(int argc, char **argv)
{
struct afsconf_dir *dir;
int serverPid, clientPid, waited, stat;
int code;
int ret = 0;
+ sigset_t set;
char *argv0 = afstest_GetProgname(argv);
afstest_SkipTestsIfBadHostname();
if (argc == 3 ) {
if (strcmp(argv[1], "-server") == 0) {
globalDir = afsconf_Open(argv[2]);
- afstest_StartTestRPCService(argv[2], TEST_PORT, TEST_SERVICE_ID,
- TEST_ExecuteRequest);
+ afstest_StartTestRPCService(argv[2], getppid(), TEST_PORT,
+ TEST_SERVICE_ID, TEST_ExecuteRequest);
exit(0);
} else if (strcmp(argv[1], "-client") == 0) {
startClient(argv[2]);
/* Otherwise, do the basic configuration, then start the client and
* server */
+ sigemptyset(&set);
+ sigaddset(&set, SIGUSR1);
+ opr_Verify(sigprocmask(SIG_BLOCK, &set, NULL) == 0);
+
dirname = afstest_BuildTestConfig();
dir = afsconf_Open(dirname);
ret = 1;
goto out;
}
+
+ /* Our server child pid will send us a SIGUSR1 when it's started listening
+ * on its port. Wait for up to 5 seconds to get the USR1. */
+ if (waitforsig(SIGUSR1, 5) != 0) {
+ fprintf(stderr, "%s: Timed out waiting for SIGUSR1 from server child\n",
+ argv0);
+ kill(serverPid, SIGTERM);
+ ret = 1;
+ goto out;
+ }
+
clientPid = fork();
if (clientPid == -1) {
kill(serverPid, SIGTERM);
struct rx_call;
extern int afstest_StartVLServer(char *dirname, pid_t *serverPid);
extern int afstest_StopServer(pid_t serverPid);
-extern int afstest_StartTestRPCService(const char *, u_short, u_short,
+extern int afstest_StartTestRPCService(const char *, pid_t, u_short, u_short,
afs_int32 (*proc)(struct rx_call *));
/* ubik.c */
int
afstest_StartTestRPCService(const char *configPath,
+ pid_t signal_pid,
u_short port,
u_short serviceId,
afs_int32 (*proc) (struct rx_call *))
return -1;
}
+ if (signal_pid != 0) {
+ kill(signal_pid, SIGUSR1);
+ }
+
afsconf_BuildServerSecurityObjects(dir, &classes, &numClasses);
service = rx_NewService(0, serviceId, "test", classes, numClasses,
proc);