if (daemon) {
/* loop and wait for the pid file.. There is a potential race
* condition that the server just created the file but isn't
- * finished writing the content, but I'll take the chance....
- */
+ * finished writing the content, so we loop a few times
+ * reading as well */
while (access(pid_file, F_OK) == -1) {
usleep(10);
}
strerror(errno));
assert(false);
}
- assert(fgets(buffer, sizeof(buffer), fp) != NULL);
+
+ /* Avoid race by retrying 20 times */
+ for (int x = 0; x < 20 && fgets(buffer, sizeof(buffer), fp) == NULL; x++) {
+ usleep(10);
+ }
fclose(fp);
int32_t val;